public override void OnUnConnectedData(NetIncomingMessage incMsg) { NetDataType type = (NetDataType)incMsg.ReadByte(); switch (type) { case NetDataType.eDATA_REGISTER_HOST: { long serverUUID = incMsg.ReadInt64(); F3_NetServerInfo serverInfo = new F3_NetServerInfo(); serverInfo.PopulateFromMsg(incMsg); RegisterServer(serverUUID, serverInfo); break; } case NetDataType.eDATA_UNREGISTER_HOST: { long serverUUID = incMsg.ReadInt64(); UnregisterServer(serverUUID); break; } case NetDataType.eDATA_REQUEST_INTRODUCTION: { IntroduceServer(incMsg); break; } case NetDataType.eDATA_REQUEST_SERVER_LIST: { SendServerList(incMsg.SenderEndPoint); break; } } }
public override void FromNetMsg(NetIncomingMessage netMsg) { // Here we assume that typeID was read before to determine which kind of message it was. string jsonData = netMsg.ReadString(); JsonData data = JsonMapper.ToObject(jsonData); if (data["servers"] != null && data["servers"].IsArray) { for (int i = 0; i < data["servers"].Count; i++) { JsonData server = data["servers"][i]; long serverUUID = (long)server["UUID"]; string serverName = (string)server["serverName"]; NetServerType serverType = (NetServerType)(int)server["type"]; string internalIP = (string)server["internal_ip"]; int internalPort = (int)server["internal_port"]; string externalIP = (string)server["external_ip"]; int externalPort = (int)server["external_port"]; int maxPlayers = (int)server["maxPlayers"]; int currentPlayers = (int)server["currentPlayers"]; string NATToken = (string)server["token"]; F3_NetServerInfo newServer = new F3_NetServerInfo(); newServer.m_serverName = serverName; newServer.m_serverType = serverType; newServer.m_currentNbPlayers = currentPlayers; newServer.m_maxPlayers = maxPlayers; newServer.m_serverInternalAdress = NetUtility.Resolve(internalIP, internalPort); newServer.m_serverExternalAdress = NetUtility.Resolve(externalIP, externalPort); newServer.m_NATtoken = NATToken; m_servers[serverUUID] = newServer; } } }
public void RegisterServer(long serverUUID, F3_NetServerInfo serverInfo) { if (!m_registeredServers.ContainsKey(serverUUID)) { m_registeredServers.Add(serverUUID, serverInfo); QueueConsoleMsg(serverInfo.m_serverName + " server (" + serverInfo.m_serverExternalAdress.ToString() + ") " + "has registered."); } else { //Update current Informations. m_registeredServers[serverUUID] = serverInfo; QueueConsoleMsg(serverInfo.m_serverName + " server (" + serverInfo.m_serverExternalAdress.ToString() + ") " + "has updated his information."); } m_bServerListIsDirty = true; }