private void ListFoundServers() { foreach (KeyValuePair <IPEndPoint, FoundGame> valuePair in gameServers) { FoundGame fs = valuePair.Value; System.Console.WriteLine($"Server {valuePair.Key}:"); System.Console.WriteLine($" Grid {fs.gridSizeX} * {fs.gridSizeY}"); System.Console.WriteLine($" {fs.maxPlayers} Max players, {fs.minPlayers} Min players"); System.Console.WriteLine($" {fs.currentPlayers} Current players"); } }
private void ReadMessages() { NetIncomingMessage inMsg; if ((inMsg = client.ReadMessage()) != null) { #if DEBUG System.Console.WriteLine($"msg: {inMsg.MessageType}"); #endif switch (inMsg.MessageType) { case NetIncomingMessageType.Data: // Handle custom messages Process(inMsg); break; case NetIncomingMessageType.DiscoveryResponse: // Check if server already is found if (gameServers.ContainsKey(inMsg.SenderEndPoint)) { break; } // Parse server status data FoundGame fs = ByteSerializer.ByteArrayToObject <FoundGame>(inMsg.Data); // Add server to list gameServers.Add(inMsg.SenderEndPoint, fs); System.Console.WriteLine($"Discovered server at: {inMsg.SenderEndPoint}"); break; case NetIncomingMessageType.StatusChanged: // handle connection status messages switch (inMsg.SenderConnection.Status) { case NetConnectionStatus.Connected: case NetConnectionStatus.Disconnecting: case NetConnectionStatus.Disconnected: System.Console.WriteLine($"{inMsg.SenderConnection.Status} from {inMsg.SenderConnection.RemoteEndPoint}"); break; } break; case NetIncomingMessageType.DebugMessage: // handle debug messages (only received when compiled in DEBUG mode) System.Console.WriteLine(inMsg.ReadString()); break; } } }