Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Dennis59 on September 08, 2013, 04:45:12 PM

Title: TNManager.Connect automatically joins server level
Post by: Dennis59 on September 08, 2013, 04:45:12 PM
I am having a problem with a game using TNET.  A TNET server / lobby server is being used.  One client starts a game server, creates a channel with a level and enters the game.  The intent is for the second client to join the server, retrieve a list of channels and then enter the channel of their choice after they make a choice.  Currently when the second client joins the server they immediately enter the channel that the first client (who created the server) entered.

The first client is creating the server as follows:
  1.         void OnClick ()
  2.         {
  3.                 TNServerInstance.Start (5127, 5128, "myServer",
  4.                         TNServerInstance.Type.Udp, Tools.ResolveEndPoint("127.0.0.1", 5129));
  5.                 TNManager.Connect ("127.0.0.1:5127");
  6.                 TNManager.CreateChannel ("Game",true,2,"");
  7.         }
  8.  
  9.         void OnNetworkConnect(bool success, string message)
  10.         {
  11.                 if(success)
  12.                 {
  13.                         TNManager.JoinChannel(1, "Game");      
  14.                 }
  15.         }
  16.  

The second client uses the following code to connect to the server:

  1. TNManager.Connect ("127.0.0.1:5127");
  2.  


Any suggestions appreciated. Thanks.
Title: Re: TNManager.Connect automatically joins server level
Post by: ArenMook on September 09, 2013, 12:52:44 AM
Do you have the same exact OnNetworkConnect function in your client? If so, that's what's causing you to join the same channel. Keep in mind, OnNetworkConnect is a global broadcast. Every script that has it will receive this notification.
Title: Re: TNManager.Connect automatically joins server level
Post by: Dennis59 on September 10, 2013, 05:52:31 PM
The player who is running the server uses the OnNetworkConnect() shown above.  The other computers, who are clients joining the game hosted by the server, have the following OnNetworkConnect function.

  1. void OnNetworkConnect(bool success, string message)
  2.         {
  3.                 //if connect successful then display channel selector dragpanel
  4.                 if(success)
  5.                 {
  6.                         NGUITools.SetActive (ServerGrid.ChannelList, true);
  7.                 }
  8.         }
  9.  

Once the client connects to the server it will request a channel list on the ChannelList dialog.  The only code on the channel list is to create the packet handler and create a button for each.  The JoinChannel command would be attached to those buttons, but that doesn't exist yet.  I don't see anything in there to cause it to join the same channel.

Title: Re: TNManager.Connect automatically joins server level
Post by: Dennis59 on September 10, 2013, 06:34:11 PM
Ok, it turns out that the first OnNetworkConnect function is the only one being called.  As you said that explains why the second client enters the game created by the host.