public static ReadFromMessage ( |
||
msg | ||
return |
public static void UpdateNetwork() { NetIncomingMessage msg; if (client == null) { return; } while ((msg = client.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine("{0}: {1}", msg.MessageType, msg.ReadString()); break; case NetIncomingMessageType.StatusChanged: { NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); string reason = msg.ReadString(); Console.WriteLine("StatusChanged: {0}: {1}", status, reason); switch (status) { case NetConnectionStatus.Connected: Console.WriteLine("Connected, sending ServerJoin packet!"); SendMessage(new ServerJoin(Name, Program.Version)); break; case NetConnectionStatus.Disconnected: Game.SetState(lastStatus == NetConnectionStatus.Connected ? new ErrorMessageScreen(reason) : new ErrorMessageScreen("Cannot connect to host!")); Console.WriteLine("Disconnected!"); break; } lastStatus = status; break; } case NetIncomingMessageType.Data: HandlePacket(Packet.ReadFromMessage(msg)); break; } client.Recycle(msg); } }
public static void UpdateNetwork() { NetIncomingMessage msg; if (server == null) { return; } while ((msg = server.ReadMessage()) != null) { switch (msg.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: Console.WriteLine("{0}: {1}", msg.MessageType, msg.ReadString()); break; case NetIncomingMessageType.StatusChanged: { if (msg.SenderConnection == null) { break; } NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); string reason = msg.ReadString(); Console.WriteLine("StatusChanged: {0} '{1}'", status, reason); switch (status) { case NetConnectionStatus.Connected: { if (State == States.InGame && !AllowLateJoins) { // F**k off, no visitors msg.SenderConnection.Disconnect("Already in game, f**k off."); break; } if (Clients.Count == Constants.MaxPlayerCount) { msg.SenderConnection.Disconnect("Too crowded, f**k off."); break; } ServerClient client = new ServerClient(msg.SenderConnection, GenerateId()); msg.SenderConnection.Tag = client; Clients.Add(client); if (State == States.Lobby) { ServerList.Update(); } break; } case NetConnectionStatus.Disconnected: { if (msg.SenderConnection.Tag == null) { break; } ServerClient serverClient = (ServerClient)msg.SenderConnection.Tag; if (serverClient.Verified) { SendMessageToAllExcept(new PlayerDelete(serverClient.Id), serverClient.Id); ServerClient client = (ServerClient)msg.SenderConnection.Tag; client.Disconnect(); Clients.Remove(client); // Card Czar left like the asshole he is if (serverClient.Id == currentCardCzar) { DeclareWinner(Clients[Random.Next(Clients.Count)].Id); } if (State == States.Lobby) { ServerList.Update(); } } else { Clients.Remove((ServerClient)msg.SenderConnection.Tag); } break; } } break; } case NetIncomingMessageType.Data: { if (msg.SenderConnection == null || msg.SenderConnection.Tag == null) { break; } ServerClient client = (ServerClient)msg.SenderConnection.Tag; Packet packet = Packet.ReadFromMessage(msg); client.HandleMessage(packet); break; } default: Console.WriteLine("Unhandled type: " + msg.MessageType); break; } server.Recycle(msg); } HandleGame(); }