Author Topic: Server to Lobby + Server to Server communication  (Read 4734 times)

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Server to Lobby + Server to Server communication
« on: August 01, 2016, 11:34:46 PM »
I have a decent sized mod in place that allows a stand-alone server to send/receive packets to/from a stand-alone lobby server.  Works great!  ...with the exception of when the lobby server goes offline.

  1. //TNLobbyLink.cs
  2. public virtual void SendPacket(Packet packet, params object[] objs)
  3. {
  4.         mLobby.SendPacket(packet, objs);
  5. }
  6.  

Along the same lines - I'd like a server (likely the lobby server) to send/receive packets to/from other servers.  I haven't coded this, but expect it to be dealt with by the lobby server.  Specific use for this would be a game-wide broadcast (Servers going down message - think 10+ servers - not going to deal with doing the same task 10+ times) or possibly server to server private chat.

I'm re-building using the latest TNet and would like to address these issues.

Perhaps I am setting this up wrong?  Requirements are simple and are outlined in "- client" below.  I have everything working at the moment - however, I'm not sure if things will clog in a production environment.  Alternatives or advise needed!



Current Setup:

- stand-alone lobby server
   - runs on a PHP/MYSQL server
   - read/write data via MYSQL
   - authenticate player login from all servers

- stand-alone servers
   - simple drone that relays encrypted packets to/from lobby server

- client
   - authenticate to "home" server
   - authenticate on "guest" server when playing server vs server match
   - send/receive pertinent data to/from MYSQL
      - request character list
      - record experience gain
      - other data related read/write

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #1 on: August 02, 2016, 10:09:13 AM »
How many players do you expect to be present concurrently? Windward was able to handle ~330 players on a single server on a home broadband connection and was at about 5% CPU usage, and it's a real time-game. A single TNet server should be able to handle a lot of traffic.

If I was doing a multi-server approach, I wouldn't use a third party (lobby server) as a middle man. Connect to a lobby server, authenticate, lobby server gives a server list. Either pick one automatically or let the player pick one. Use LAN broadcasts to communicate across multiple servers.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #2 on: August 02, 2016, 05:49:44 PM »
I would be happy with 300+ players on each server.  I'm starting with 3 servers.  Success would be having around 150 per at peak times.

I've set things up revolving around:  a player needs to authenticate to each server when playing a server vs server match. 

- Host server notifies players on multiple servers a match is ready. 
- Player disconnects from their home server and authenticates on the host server. 
- The host server sets up the match as players connect.
- When the match is complete the player re-authenticates on their home server.

Use LAN broadcasts to communicate across multiple servers.

I am strictly using TCP.  I am not sure what LAN broadcast is or how it could make a Redmond server communicate with an Orlando server.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #3 on: August 02, 2016, 06:12:19 PM »
You really don't need more than 1 server for only 150 peak players.

You can run your single server on a toaster of a computer, and it will still work fine. I've mentioned it before, I've had people run Windward servers on Raspberry Pi devices and they worked fine.

Don't complicate your life needlessly, keep it simple.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #4 on: August 03, 2016, 04:32:24 PM »
The amount of players isn't my question or concern...  we will assume that the server is at capacity and the need for 3 (or more) servers is required.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #5 on: September 25, 2016, 11:43:29 AM »
Would you be willing to expand on how you were able to accomplish this?  This functionality seems very useful.

I've been struggling to get communication going with the lobby server.  Custom packets are easy with the gameclient and gameserver. But, with the lobby, I can't seem to get it going. I was able to get some output on Debugs from the TNGameserver to TcpLobbyServer but I am not sure really if the direction I am going is the the right/efficent solution.

Would appreciate any feedback.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #6 on: September 25, 2016, 07:19:39 PM »
...and this thread wasnt worthy of a response...  i stopped working on this the following day.

anyways, I happened to do an incomplete write-up of how I achieved this.  beware:  not a ton of testing was done and the kicker is what to do if the lobby server goes offline.  ie  packet que?  idk

example usage:
(within TNGameServer.cs)

lobbyLink.SendPacket(Packet.LobbyLink_RequestAuth, user_id, player.id, username, password);

PS  i do not want to support this code - feel free to do what you like with it.  i was using a stand-alone lobby server with mysql and 3 stand-alone servers - if some snippets are missing from the lobby code let me know.



  1. -------------------------------
  2. -- STAND-ALONE SERVER --
  3. -------------------------------
  4.  
  5. //1:  TNLobbyLink.cs
  6. public virtual void SendPacket(Packet packet, params object[] objs)
  7. {
  8.         mLobby.SendPacket(packet, objs);
  9. }
  10.  
  11. //2:  TNLobbyServer.cs
  12. public abstract void SendPacket(Packet packet, params object[] objs);
  13.  
  14. //3:  TNTcpLobbyLink.cs
  15. else if (response == Packet.ResponsePacket)
  16. {
  17.         int player_id = reader.ReadInt32();
  18.         string s = reader.ReadString();
  19.  
  20.         mGameServer.LobbyLink_ResponsePacket(player_id, s);
  21. }
  22.  
  23. //4:  TNTcpLobbyServer.cs
  24. public override void SendPacket(Packet packet, params object[] objs)
  25. {
  26.         //
  27. }
  28.  
  29. //5:  TNUdpLobbyServer.cs
  30. public override void SendPacket(Packet packet, params object[] objs)
  31. {
  32.         //
  33. }
  34.  
  35. //6: TNTcpLobbyLink.cs
  36. public override void SendPacket(Packet packet, params object[] objs)
  37. {
  38.         BinaryWriter writer = mTcp.BeginSend(packet);
  39.  
  40.         foreach (object o in objs)
  41.         {
  42.                 if (o.GetType() == typeof(string))
  43.                 {
  44.                         writer.Write((string)o);
  45.                 }
  46.                 else if (o.GetType() == typeof(byte))
  47.                 {
  48.                         writer.Write((byte)o);
  49.                 }
  50.                 else if (o.GetType() == typeof(int))
  51.                 {
  52.                         writer.Write((int)o);
  53.                 }
  54.                 else if (o.GetType() == typeof(long))
  55.                 {
  56.                         writer.Write((long)o);
  57.                 }
  58.                 else if (o.GetType() == typeof(bool))
  59.                 {
  60.                         writer.Write((bool)o);
  61.                 }
  62.                 else
  63.                 {
  64.                         Console.WriteLine("unknown type: {0}", o.GetType());
  65.                 }
  66.         }
  67.        
  68.         mTcp.EndSend();
  69. }
  70.  
  71. //7:  TNGameServer.cs
  72.  
  73. internal void LobbyLink_ResponsePacket(int player_id, string s)
  74. {
  75.         TcpPlayer player = GetPlayer(player_id);
  76.  
  77.         if (player != null)
  78.         {
  79.                 BinaryWriter writer = BeginSend(Packet.WEPPN_ResponsePacket);
  80.                 writer.Write(s);
  81.                 EndSend(true, player);
  82.         }
  83. }
  84.  
  85.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #7 on: September 25, 2016, 08:23:51 PM »
I've been struggling to get communication going with the lobby server.  Custom packets are easy with the gameclient and gameserver. But, with the lobby, I can't seem to get it going. I was able to get some output on Debugs from the TNGameserver to TcpLobbyServer but I am not sure really if the direction I am going is the the right/efficent solution.
Lobby server is the same as game server, it just uses a different file -- TNTcpLobbyServer.cs for a TCP one, for example. When you modify this file, you will need to recompile the TNServer.exe and relaunch the lobby server using it.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: Server to Lobby + Server to Server communication
« Reply #8 on: September 25, 2016, 10:44:01 PM »
...and this thread wasnt worthy of a response...  i stopped working on this the following day.

anyways, I happened to do an incomplete write-up of how I achieved this.  beware:  not a ton of testing was done and the kicker is what to do if the lobby server goes offline.  ie  packet que?  idk

example usage:
(within TNGameServer.cs)

lobbyLink.SendPacket(Packet.LobbyLink_RequestAuth, user_id, player.id, username, password);

PS  i do not want to support this code - feel free to do what you like with it.  i was using a stand-alone lobby server with mysql and 3 stand-alone servers - if some snippets are missing from the lobby code let me know.



Thanks for putting the effort into that response. I actually got some output going on the lobbyserver from the gameserver based on this before I replied:

  1. //TNLobbyLink.cs
  2. public virtual void SendPacket(Packet packet, params object[] objs)
  3. {
  4.         mLobby.SendPacket(packet, objs);
  5. }
  6.  

Just to tack on to the earlier remarks, I could only hold about ~150 players per external server before things got bad. 10 players per channel. My stuff is likely not written as efficiently as Arens.  Also, it was a FPS game on mobiles, so processing, AI, and other logic runs a bit slower on your phone. Another footnote, some dedicated server providers share your server connection with other servers.  So, randomly at times ping got bad across the board.