Author Topic: TNLobbyClient.knownServers always empty when paired with remote lobby server  (Read 4480 times)

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
I have been trying to setup a lobby server but encountered a few issues along the way. I recently found a thread that was rather helpful (http://www.tasharen.com/forum/index.php?topic=15214.0) however there seems to be one more hurtle I can't get past.

The TNLobbyClient.knownServers list doesn't appear to ever have items. I added a breakpoints and debugging message to the TNTcpLobbyClient to check the content of the knownServers list in the Packet.ResponseServerList case, it is always empty on every call. I've verified the remote lobby server is recognizing the new server instance and the number of players:


I have attached a TNTcpLobbyClient to my network game object, which is enabled anytime a player is either trying to find a game (where my current problem lies) or host a game.

My server start/stop methods are below (when a player opts to host a server):
  1.     /// <summary>
  2.     /// Initialize a server instance
  3.     /// </summary>
  4.     public void StartServer()
  5.     {
  6.         if (!TNServerInstance.isActive)
  7.         {
  8.             Debug.Log("Starting server");
  9.             TNServerInstance.serverName = "Test Game Server";
  10.             TNServerInstance.Start(5127, 0, null, TNServerInstance.Type.Tcp, Tools.ResolveEndPoint(LobbyManager.GetIP(), LobbyManager.GetPort()));
  11.         }
  12.         else
  13.         {
  14.             Debug.Log("Server already started");
  15.         }
  16.         TNManager.Connect();
  17.     }
  18.  
  19.     /// <summary>
  20.     /// Close the current server instance
  21.     /// </summary>
  22.     public void CloseServer()
  23.     {
  24.         try
  25.         {
  26.             // Close the server
  27.             TNManager.Disconnect();
  28.         }
  29.         catch { }
  30.  
  31.         Debug.Log("Server stopped!");
  32.     }

The remote server is an AWS instance at 52.10.26.70:5129. I'm sure I am missing something - any help with identifying the issue would be greatly appreciated.

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
It looks like with an edit to the AddServer method in the TNTcpLobbyServer.cs, I changed

  1.         void AddServer (ServerList.Entry ent, TcpProtocol tcp)
  2.         {
  3.             ent.recordTime = mTime;
  4.             bool noChange = false;
  5.  
  6.             var old = tcp.Get<ServerList.Entry>("data");
  7.  
  8.             if (old != null)
  9.             {
  10.                 if (old.playerCount == ent.playerCount && old.name == ent.name)
  11.                     noChange = true;
  12.             }
  13.  
  14.             if (!noChange) mLastChange = mTime;
  15.  
  16. #if STANDALONE
  17.             if (tcp.Get<long>("lastSend") != 0)
  18.                 Tools.Print("[+] " + ent.name + " (" + ent.playerCount + ")");
  19. #endif
  20.             tcp.Set("data", ent);
  21.         }

to

  1.         void AddServer (ServerList.Entry ent, TcpProtocol tcp)
  2.         {
  3.             ent.recordTime = mTime;
  4.             bool noChange = false;
  5.  
  6.             var old = tcp.Get<ServerList.Entry>("data");
  7.  
  8.             if (old != null)
  9.             {
  10.                 if (old.playerCount == ent.playerCount && old.name == ent.name)
  11.                     noChange = true;
  12.             }
  13.  
  14.             if (!noChange) mLastChange = mTime;
  15.  
  16. #if STANDALONE
  17.             if (tcp.Get<long>("lastSend") != 0)
  18.                 Tools.Print("[+] " + ent.name + " (" + ent.playerCount + ")");
  19. #endif
  20.             tcp.Set("data", ent);
  21.  
  22.             if (ent != null)
  23.             {
  24.                 bool ExistsInList = false;
  25.                 foreach (ServerList.Entry entry in mList.list)
  26.                 {
  27.                     if (ent.externalAddress == entry.externalAddress && ent.internalAddress == entry.internalAddress) // This is the same entity
  28.                     {
  29.                         ExistsInList = true;
  30.                         break;
  31.                     }
  32.                 }
  33.  
  34.                 if (ExistsInList == false)
  35.                     mList.Add(ent.name, ent.playerCount, ent.internalAddress, ent.externalAddress, mTime);
  36.             }
  37.         }

After this change, I started receiving server listings to the UI. The servers, once added, hang in the list because they arent being removed correctly yet which is something I plan to add.

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
After a rewrite of a good portion of the TNTcpLobbyClient file, and compiling the server, I am successfully adding, updating, and removing servers from the lobby server. Looks like I solved the issue.

Might want to make note of this issue for future releases of TNet3:
There are two AddServer and RemoveServer methods in TNTcpLobbyClient, one is an override for the base class of TNLobbyClient, the other is a void method declaration. The overrides were the only methods to actually add and remove a server - but were never called when using TNServerInstance.Start(). The methods being called were the two void methods but the void methods didn't implement the use of mList.Add() or mList.Remove() - so the server's were never added.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Hmm... Looking at that part of the code I am not entirely sure why I wrote it the way I did. I changed the non-virtual functions to:
  1.         /// <summary>
  2.         /// Add a new server to the list.
  3.         /// </summary>
  4.  
  5.         void AddServer (ServerList.Entry ent, TcpProtocol tcp)
  6.         {
  7.                 tcp.Set("data", ent);
  8.                 AddServer(ent.name, ent.playerCount, ent.internalAddress, ent.externalAddress);
  9.         }
  10.  
  11.         /// <summary>
  12.         /// Remove all entries added by the specified client.
  13.         /// </summary>
  14.  
  15.         bool RemoveServer (TcpProtocol tcp)
  16.         {
  17.                 var ent = tcp.Get<ServerList.Entry>("data");
  18.                 if (ent != null) { RemoveServer(ent.internalAddress, ent.externalAddress); return true; }
  19.                 return false;
  20.         }

mythikos

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 18
    • View Profile
Thanks for the response. You'll wanna add
  1. ent.recordTime = mTime;
to the top of your non-virtual AddServer method. Otherwise, you encounter 'Time out detected' issues.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Thanks, I will do that too.

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 62
    • View Profile
Soooo.... did the bug found here by @mythikos recieve a fix in the official TNet build in the asset store? I'm running V3.0.9 and currently am unable to get any servers in the knownServers list. (My lobby server hosted on AWS does register a game when I host it).

I'm trying to resolve this with the code I've seen around on the forum but it doesn't match up with what I have in my TNTcpLobbyServer.cs. So has this been fixed in the asset store release @ArenMook?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
It should be, yes. At least I haven't heard anything else since the last build went live on April 22nd.