public static Message Parse(string s) { var Type = Pop <MessageType>(ref s); var message = new Message(Type); switch (message.Type) { case MessageType.PlayerAction: message.Inner = MessagePlayerAction.Parse(s); break; case MessageType.PlayerActionAck: message.Inner = MessagePlayerActionAck.Parse(s); break; case MessageType.Bookend: message.Inner = MessageBookend.Parse(s); break; case MessageType.GameState: message.Inner = MessageGameState.Parse(s); break; case MessageType.StartingStep: message.Inner = MessageStartingStep.Parse(s); break; case MessageType.Hash: message.Inner = MessageHash.Parse(s); break; case MessageType.StringHash: message.Inner = MessageStringHash.Parse(s); break; } return(message); }
public void ProcessInbox() { Message message; while (Networking.Inbox.TryDequeue(out message)) { if (Log.Processing) { Console.WriteLine(" -In Game Processing {0}", message); } if (Program.Server) { if (message.Type == MessageType.PlayerAction) { var ack = new MessagePlayerActionAck(AckSimStep, message); var chat = message.Innermost as MessageChat; if (null != chat) { if (chat.Global) { Networking.ToClients(ack); } else { var chat_team = message.Source.Team; if (chat_team < 0) { continue; } foreach (var client in Server.Clients) { if (client.Team == chat_team) { Networking.ToClient(client, ack); } } } } else { if (message.Source.Index > 4) { Console.WriteLine("Warning! Action message from spectator, possibly malicious."); continue; } Networking.ToClients(ack); } } if (message.Type == MessageType.LeaveGame) { message.Source.HasLeft = true; } if (message.Type == MessageType.RequestPause) { message.Source.RequestingPause = true; } if (message.Type == MessageType.RequestUnpause) { message.Source.RequestingPause = false; // Cancel everyone's pause request. foreach (var client in Server.Clients) { client.RequestingPause = false; } } } // Messages from players if (message != null) { if (message.Type == MessageType.StartingStep || message.Type == MessageType.Hash || message.Type == MessageType.StringHash) { message.Innermost.Do(); } } // Messages from the server if (message.Source.IsServer) { if (message.Type == MessageType.Bookend) { message.Innermost.Do(); } if (message.Type == MessageType.PlayerActionAck) { message.Inner.Do(); } if (message.Type == MessageType.Pause) { if (!ServerPaused) { ServerPaused = true; GameClass.Game.Send("setScreen", "game-paused", new { canUnpause = true }); } } if (message.Type == MessageType.Unpause) { if (ServerPaused) { ServerPaused = false; GameClass.Game.Send("back"); } } if (message.Type == MessageType.ServerLeft) { if (!Program.Server && !GameOver) { GameClass.Game.Send("setScreen", "disconnected", new { message = "The server has quit. Tell them they suck." }); } } if (message.Type == MessageType.NetworkDesync) { DesyncPause = true; if (!Program.Server) { // The server has already put up its desync UI, // so only do this for clients. GameClass.Game.Send("setScreen", "desync"); } } if (message.Type == MessageType.GameState) { message.Innermost.Do(); } } } }