예제 #1
0
 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 });
 }
예제 #2
0
 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);
         }
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 public static void SetGame(ClientDescription sender, byte[] message)
 {
     throw new Exception("Clients should not be receiving this type of message.");
 }
예제 #5
0
 void UpdateServerState(ClientDescription sender, byte[] serverList)
 {
     throw new Exception("Servers should not be receing this type of message.");
 }