void SetGame(ClientDescription sender, byte[] message) { sender.gameID = message[0]; Server.Game g; if (hostedGames.TryGetValue(sender.gameID, out g)) { if (!g.connectedClients.Contains(sender)) { g.connectedClients.Add(sender); } } UpdateGamesList(); Send(sender, UpdateServerState, new byte[] { (byte)ServerStateMessage.Join }); }
private void UpdateServerState(ClientDescription sender, byte[] buffer) { if (buffer[0] == (byte)ServerStateMessage.Join && JoinSuccess != null) { JoinSuccess(this, null); } else if (buffer[0] == (byte)ServerStateMessage.List) { hostedGames = DecodeServerList(buffer, 1); if (ServerListChanged != null) { ServerListChanged(this, null); } } }
public void Send(ClientDescription client, ReceiveMessage callback, byte[] buffer) { try { NetworkStream stream = client.client.GetStream(); stream.Write(BitConverter.GetBytes((short)buffer.Length), 0, 2); stream.WriteByte(ClientCallbackLookup[callback]); if (buffer.Length > 0) { stream.Write(buffer, 0, buffer.Length); } stream.Flush(); } catch { lock (clients) clients.Remove(client); } }
public static void SetGame(ClientDescription sender, byte[] message) { throw new Exception("Clients should not be receiving this type of message."); }
void UpdateServerState(ClientDescription sender, byte[] serverList) { throw new Exception("Servers should not be receing this type of message."); }