MasterServerClientConnection
public class MasterServerClientConnection: GameConnection
{
public int masterServerPort;
public string masterServerIP;
public NetPeer masterServerPeer;
public List<GameServerListing> gameServerListings = new List<GameServerListing>();
//this is just for GUI stuff. When new data comes in, set this to false. When generating data to show from it, set it true
public bool displayedGameServersToClient = true;
public bool connected = false;
public ServerConnection server;
//...
This connection is for either Clients or Servers connecting to a Master Server. Servers using this connection will likely want to tell the Master Server info to help clients connect to their game. Clients using this connection will likely ask for information about games publicly hosted and how to join them.
There a couple of attributes to help here, firstly we keep track of the Master Servers IP and Port and fill in a NetPeer once we connect so we can easily send packets to them.
There is a list of gameServerListings which starts empty but we can request this information via this connection, displayedGameServersToClient lets any UI elements know if we should show the game server listings in their current state or not as we may be getting a couple of packets worth of data that needs adding together.
There is a reference to ServerConnection too, but this is optional and just here for convenience for if we are the Server.
Methods
public MasterServerClientConnection(int masterServerPort, string masterServerIP)
A constructor where we pass it the Master Servers port and IP so we can attempt to connect to it. It then sets up a couple of events to listen to when network events happen
public void GetListOfGames()
Ask Master Server for details about the games listed on the server
public void HostGameOnMasterServer(string gameName)
Tell Master Server about the game server you are hosting so it can help list its details for clients to join (not applicable to clients)
public void UpdateGamePlayerCountOnMasterServer(int players, int maxPlayers)
Tell Master Server the current number of players in your game server (not applicable to clients)