Author Topic: Server Browser Question (For user self-hosted servers)  (Read 3349 times)

GabaLaba

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 11
    • View Profile
Server Browser Question (For user self-hosted servers)
« on: August 17, 2017, 05:33:01 PM »
Hello everyone,

My name is Gabe and I recently purchased TNet 3. I am getting ready to switch over my game's network system to TNet, and I have a question in regards to server discovery for user self-hosted servers.

I am interested in having the players host their own servers rather than me host my own. I wanted to know if it is possible to somehow discover the servers that are running for the game without having everyone connect to some sort of "master server" like you would if you hosted your own server and had people create their own rooms/channels instead of hosting their own.
I hope that makes sense.

Is this possible, or would everyone have to connect to the servers remotely?

Thank you,
Gabe

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #1 on: August 18, 2017, 07:23:00 PM »
You (the developer) would need to host a publicly-accessible lobby server. The user's self-hosted servers would then "register" with the lobby server. The players then connect to the lobby server to see all of the user self-hosted servers.

This functionality is all included in TNet. Additionally, if you're on LAN, I think there's another means of server discovery in the form of broadcast packets. This is also included with TNet.

GabaLaba

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #2 on: August 18, 2017, 10:34:21 PM »
Hi, thank you for the response.

How can I run a lobby server? I looked at some of the documentation and I can't seem to find a way to run it or set it up.


Thanks,
Gabe

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #3 on: August 19, 2017, 01:13:28 AM »
Unzip TNetServer.zip then start TNServer.exe with the tcpLobby switch.
Example bat file:
  1. @echo off
  2. start "TNet Test Lobby Server" "TNServer.exe" -name "TNet_TestLobbySrv" -tcpLobby 5129
  3.  

GabaLaba

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #4 on: August 19, 2017, 11:08:09 AM »
I set up the batch file and successfully ran the Lobby Server. To my understanding, what I must to in order for this to work correctly is for the player to first connect to the lobby server, then load all of the servers that are on the server list.
After the user has the information to connect to the user-hosted server he would like to connect to, he would automatically disconnect from the lobby server and connect to the user-hosted server instead? Then when he leaves that server, just connect back to the server lobby?

Thanks,
Gabe

GabaLaba

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #5 on: August 19, 2017, 11:15:44 AM »
Just as a follow-up to my previous message -

I looked up lobby server on the doc and found some sort of "Lobby Server Link": http://www.tasharen.com/tnet/docs/class_t_net_1_1_tcp_lobby_server_link.html#adfdc730d4f5f2f39a0791f90c8199986

Perhaps that is what I need to do. That seems like a much better solution that connecting back and forth from the lobby server and the game servers.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #6 on: August 20, 2017, 05:34:43 PM »
Sorry for the late response. It's even simpler than that! The game server will automatically handle the lobby link part if you launch it specifying a remote lobby address:
  1. @echo off
  2. start "TNet Test Server" "TNServer.exe" -name "TNet_TestSrv" -tcp 5127 -udp 5128 -tcpLobby "192.168.1.2" "5129"
  3.  

Then on the client, you just add a TcpLobbyClient component to any gameobject and specify the same remote lobby address. Then you'll have access to all the registered servers (along with name and player count):
  1. void Start()
  2. {
  3.         TNLobbyClient.onChange += OnLobbyClient_Changed;
  4. }
  5.  
  6. void OnLobbyClient_Changed()
  7. {
  8.         Debug.Log("OnLobbyClient_Changed (" + TNLobbyClient.knownServers.list.size + ")");
  9.         TNet.List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
  10.         for (int index = 0; index < list.size; index++)
  11.         {
  12.                 Debug.Log(name + " [ServerListManager][" + index + "]: " + list[index].name + " : " + list[index].playerCount);
  13.         }
  14. }
  15.  

GabaLaba

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Server Browser Question (For user self-hosted servers)
« Reply #7 on: August 20, 2017, 06:39:08 PM »
No worries on the response time :)

Thank you so much for the help, I really do appreciate it!
I will try this once I start converting my game to TNet.