// Answers private void Send_Answer_GameServerDetails() { // Sends connectionId a selected GameServer's details string newMessage = "Answer_GameServerDetails|"; if (gameServers.Count > 0) { ConnectedGameServer highestPopGameServer = gameServers.Where(gs => gs.population < gameServerPopCap).ToList().OrderByDescending(gs => gs.population).ToList()[0]; // Get highest population gameServer that isn't full // Add the GameServer's ipAddress and port to the message newMessage += highestPopGameServer.ipAddress + "|" + highestPopGameServer.port; } else { newMessage += "NoServersFound"; } // Send to all clients awaiting a GameServer foreach (ConnectedClient client in clientsWaitingForGameServer) { Send(newMessage, connectionData.channelReliable, client.connectionId); } clientsWaitingForGameServer.Clear(); }
private void OnDisconnect(int connectionId) { // Check if the disconnect was a gameServer or a client; remove them from the lists // Remove if GameServer if (gameServers.Exists(gs => gs.connectionId == connectionId)) { ConnectedGameServer gameServerDisconnected = gameServers.Single(gs => gs.connectionId == connectionId); if (gameServerDisconnected != null) { UnityEngine.Debug.Log("GameServer Disconnected - Removing GameServer from gameServers list"); // Open this GameServer's port in the ports list gameServerPorts[gameServerDisconnected.port] = true; // Reopen port gameServers.Remove(gameServerDisconnected); return; } } // Remove if Client if (clients.Exists(gs => gs.connectionId == connectionId)) { ConnectedClient clientDisconnected = clients.Single(cl => cl.connectionId == connectionId); if (clientDisconnected != null) { UnityEngine.Debug.Log("Client Disconnected - Removing Client from clients list"); clients.Remove(clientDisconnected); return; } } }