Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: nidhi_singh on May 18, 2015, 01:04:00 AM

Title: Profile Name Display or User Name Display
Post by: nidhi_singh on May 18, 2015, 01:04:00 AM
From Example Menu instead of displaying IP to other user I want to display user name which player sets in beginning of the game. is there anyway to do this or how to send a RFC if a user hasn't connected to server.
 
I will be displaying that user name with player's character, here hosts name is overriding other users name. I'm storing user name in TNManager.playerName and sending it via RFC.

I am using NGUI for game UI.
Title: Re: Profile Name Display or User Name Display
Post by: ArenMook on May 22, 2015, 05:46:35 PM
The name should be set prior to connecting. This way when a player connects, the name is already set.
Title: Re: Profile Name Display or User Name Display
Post by: nidhi_singh on May 24, 2015, 11:52:29 PM
Thanks for the reply, 2nd part of post I solved, still I'm not getting how to display user name of host instead of his IP when player searches for the server. I am able to store the user name but how to send it if the other player is not connected to the server only.
Title: Re: Profile Name Display or User Name Display
Post by: nidhi_singh on May 25, 2015, 03:18:18 AM
Alright I found out BroadcastToLAN so I am able to send user name to other player even if he's not connected to server but is on same network.

tno.BroadcastToLAN(GameConnectScript.udpPort,94,TNManager.playerName);

But now how will other player will receive it. is there any other function for that.
I want set Button's label to the name he received from broadcast message.

Button.transform.Find("LabelProfileName").GetComponent<UILabel>().text =TNManager.playerName;
Title: Re: Profile Name Display or User Name Display
Post by: ArenMook on May 26, 2015, 03:14:15 PM
To receive broadcast packets you need to have a UDP listener on the port you are sending data to. The example that comes with TNet does this to advertise the presence of game servers.
Title: Re: Profile Name Display or User Name Display
Post by: nidhi_singh on May 29, 2015, 01:47:38 AM
sorry, which example I didn't find it in any.
what I tried is this. Still its not working, maybe I am still missing something. When Other player searches for server he's able to see his TNmanager.playerName.

UdpProtocol Listener;
void Start()
{
   Listener = new UdpProtocol ();
   Listener.Start ();
}
public void OnHost()
{
   TNManager.playerName = PlayerPrefs.GetString ("PlayerName");
   tno.BroadcastToLAN(Listener.listeningPort,94,TNManager.playerName);
}
[RFC(94)]
public void SendName(string NameToSend)
{
   TNManager.playerName = NameToSend;
}


void OnFindServer()
{
   Button.transform.Find("LabelIP").GetComponent<UILabel>().text = ent.internalAddress.ToString();
   Button.transform.Find("LabelProfileName").GetComponent<UILabel>().text =TNManager.playerName;
}
Title: Re: Profile Name Display or User Name Display
Post by: ArenMook on June 01, 2015, 09:38:37 PM
The very first scene with TNet... the one that has a menu where you start / view / join servers. Servers announce themselves by using UDP broadcasts / multicasts.

BroadcastToLAN won't work unless you actually started a UDP listener, which I don't see you doing in your code. Just check the example scene, it does all of this using UdpLobby.

P.S. Don't use ports below 1000. Generally ports < 1000 are reserved for system use.