Author Topic: SetHost() switches to their server instance?  (Read 3578 times)

Bill.Smock

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 19
    • View Profile
SetHost() switches to their server instance?
« on: June 09, 2016, 07:04:35 PM »
So when I use sethost to switch the channel host, will their server instance be the 'host' of the channel then?  This will be for whenever a player drops out of a lobby or in game.  Thanks!


edit for another question - I am having trouble setting up a server/channel list the way so that each list item contains data from the server's channel (each server will have only one channel, always).  I would like clients to be able to view the channel data without having to join that server instance - similar to any game that shows rows with descriptions including # of players, player limit, etc.  Very typical in multiplayer games.  However, I cannot find a way to refresh this information without the client being connected to the server in which the channels reside.  How can I do this?  Do I need to save the channel info and associated servers to a file on the lobby server (EC2) and then create the channel items list using that information? 
« Last Edit: June 10, 2016, 09:35:21 AM by Bill.Smock »

Bill.Smock

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 19
    • View Profile
Re: SetHost() switches to their server instance?
« Reply #1 on: June 11, 2016, 07:18:16 AM »
Actually, I'll just use EC2 as a dedicated server for hosting all channels.  Why bother with P2P right now when I have probably 2 years of development to go?  When I have 500,000 players connecting on my incredible game that blows everything else away, I'll worry about P2P.  /s  ;D

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: SetHost() switches to their server instance?
« Reply #2 on: June 11, 2016, 01:20:32 PM »
Host isn't actually who's hosting the server instance, it's more like "channel operator". The first player to join the channel is designated the host. There's a few ways to migrate from one server to another. You could have the current server send out an RFC designating which player is to start up the new server instance right before shutting down, but that wouldn't work if the current server host crashes, only if they gracefully exit. This is an easier problem to solve when it's fully p2p. Unfortunately TNet is not :p
Here's what I'd try doing (it's no small feat):
* Lobby Server keeps track of players connected to each registered game server
* When Lobby Server detects that a game server shuts down with players still connected:
    * Run some logic to determine which player should be the new server (ping-based, or entirely random)
    * Send packet to that player notifying them to start up the server instance
    * Wait until the new server instance from that player is registered
    * Send packet to every other player that was on the original game server, notifying them of the new server instance
* Other players receive the packet notifying them of the new server instance and connect as usual

As for your other question, you'd need to take a look at TNLobbyLink.cs, TNLobbyServer.cs, TNLobbyClient.cs, and TNServerList.cs
You're correct, you'd need to send the channel info from the game server to the lobby server and parse that on the lobby client.

Bill.Smock

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 19
    • View Profile
Re: SetHost() switches to their server instance?
« Reply #3 on: June 11, 2016, 06:50:18 PM »
Between your help, and ArenMook's and Starlink, I'm making a lot of progress.  In fact, the only problem I am having right now is GetChannelData is not working.  I am calling it from a player who is not in any channel, but is connected to the same remote server.  Is the no channel bit the problem?  I'm using TNManager.GetChannelData<string>(id, "CurrentLevel");  Pretty straight forward.  I've testing the SetChannelData using logger and get data on the host while host is in channel, but from outside of the channel I cannot seem to access it.  :-(

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: SetHost() switches to their server instance?
« Reply #4 on: June 11, 2016, 09:55:38 PM »
That function isn't in TNet2, so I can't answer definitively. If I were to guess, I'd say that you're right, you have to be in a channel to use it.

If you're trying to get channel values from the game server to display on the lobby server list, refer to ThreadFunction() in TNTcpLobbyLink.cs (assuming you're using TCP). At the bottom of this function you'll see a BinaryWriter being instantiated and a bunch of values being written. You can add something like:
  1. lock (mGameServer.mLock)
  2. {
  3.     writer.Write(mGameServer.mChannels[0].playerLimit);
  4.     // any other channel data
  5. }
  6.  
Then in TNServerList.cs you'll have to modify the Entry class's ReadFrom and WriteTo functions to include your newly written values.

Note: given code is only an example and isn't very safe.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SetHost() switches to their server instance?
« Reply #5 on: June 12, 2016, 03:58:42 AM »
Between your help, and ArenMook's and Starlink, I'm making a lot of progress.  In fact, the only problem I am having right now is GetChannelData is not working.  I am calling it from a player who is not in any channel, but is connected to the same remote server.  Is the no channel bit the problem?  I'm using TNManager.GetChannelData<string>(id, "CurrentLevel");  Pretty straight forward.  I've testing the SetChannelData using logger and get data on the host while host is in channel, but from outside of the channel I cannot seem to access it.  :-(
You either need to be inside the channel to access this data, or you need to retrieve it by doing a TNManager.GetChannelList(). Setting the channel data can only be done from within the channel.

Bill.Smock

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 19
    • View Profile
Re: SetHost() switches to their server instance?
« Reply #6 on: June 12, 2016, 06:07:04 AM »
You either need to be inside the channel to access this data, or you need to retrieve it by doing a TNManager.GetChannelList(). Setting the channel data can only be done from within the channel.

Access through the Channel.Info data node instead of GetChannelData. Need to keep in mind that your Starlink setup for everything is how it's supposed to be done.  Thank you!!