Author Topic: Issues with KnownServers list  (Read 244 times)

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
Issues with KnownServers list
« on: April 16, 2017, 11:08:41 PM »
There appears to be an issue with the Lobby server again - beyond my previous thread about the known servers list being empty. After fixing that, there seems to be another issue. It is a bit hard to explain so I will do my best to explain, as well as attach a video outlining what is happening.

Instance 1) When a player initially goes to host a server, everything works perfectly as intended. The player presses the host button -> the server is created -> the player connects -> we grab the server listing from the known servers list as a reference -> player joins channel.

Instance 2) Now if the player closes the server they made in instance one, the second time around there is an error. Heres what happens. The player presses the host button -> the server is created -> the player connect -> the known server list is not yet updated to contain the server we just created -> failure.

Heres the fun part, this literally happens over and over perfectly. The known server list is always late the second time around and always on time the first time around. Video: http://mythicservers.com/images/mythic/2017-04-16_20-53-17.mp4

Here is the code that is causing the error:
  1. protected override void OnConnect(bool success, string message)
  2.     {
  3.         Debug.Log("Connected: " + success + " " + message + " (Player ID #" + TNManager.playerID + ")");
  4.  
  5.         // The host wont immediately have the server entry as they are creating it.
  6.         // This will allow us to capture that server entry (If someone has a more elegant way to get the server list entry for the host, please do tell)
  7.         if (NetworkManager.server == null)
  8.         {
  9.             float t = 0f;
  10.             while (t < 100f)
  11.             {
  12.                 for (int i = 0; i < TNLobbyClient.knownServers.list.size; ++i)
  13.                 {
  14.                     ServerList.Entry ent = TNLobbyClient.knownServers.list[i];
  15.                     if (ent.externalAddress.Address.ToString().Equals(Tools.externalAddress.ToString()))
  16.                     {
  17.                         NetworkManager.server = ent;
  18.                         break;
  19.                     }
  20.                 }
  21.  
  22.                 // Did we find the server?
  23.                 if (NetworkManager.server != null)
  24.                     break;
  25.                 else
  26.                     t += Time.deltaTime;
  27.             }
  28.         }
  29.  
  30.         if (NetworkManager.server == null)
  31.         {
  32.             Debug.LogError("Unable to determine server listing after 10 seconds.");
  33.         }
  34.         else
  35.         {
  36.             // What should we do?
  37.             if (IsHost()) // The host wont have the server refrenced at this point
  38.                 TNManagerExtension.CreateChannel(NetworkManager.ChannelId, null, false, MaxPlayers, _serverPassword, true); // Create the main channel
  39.             else if (server.isPasswordProtected == true)
  40.                 UIPasswordWindow.Show(NetworkManager.ChannelId, null); // The channel is password protected
  41.             else
  42.                 TNManager.JoinChannel(NetworkManager.ChannelId, null, false, MaxPlayers, null); // The channel is free to join
  43.         }
  44.     }


TLDR; In a rather consistent way, the lobby server is updating the knownServers list on time the first time and not in time the second time. Any idea how I could go about fixing this?

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
Re: Issues with KnownServers list
« Reply #1 on: April 16, 2017, 11:51:51 PM »
Ended up solving this by subscribing to the onChange event in TNLobbyClient. Still would like to know why there is a send receive difference that is so consistent.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 278
  • -Receive: 1133
  • Posts: 21,902
  • Toronto, Canada
    • View Profile
Re: Issues with KnownServers list
« Reply #2 on: April 22, 2017, 12:21:58 PM »
What did you have it subscribed to before? OnConnect for the lobby is different form OnConnect on TNManager. The order in which they execute is not guaranteed to be the same. Seems you fixed it properly.

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
Re: Issues with KnownServers list
« Reply #3 on: April 26, 2017, 11:54:45 AM »
It was subscribed to the TNManager.onConnect event as you indicated. I just found it strange the execution order was consistently flipflopping - the pattern indicated bug but the function seemed normal. Just wanted to bring it up for that reason.