Пример #1
0
        void OnDataReceived(NetBuffer msg)
        {
            byte          code    = msg.ReadByte();
            ServerCommand command = (ServerCommand)code;

            CommandsToDo.AddLast(Utilities.MakePair <ServerCommand, NetBuffer>(command, msg));

            ExecuteCommands();
        }
Пример #2
0
        void ExecuteCommands()
        {
            List <KeyValuePair <ServerCommand, NetBuffer> > toRemove = new List <KeyValuePair <ServerCommand, NetBuffer> >();

            foreach (var command in CommandsToDo)
            {
                if (EventsForCommand.ContainsKey(command.Key))                   // if we have implemented the action to do when we receive this command type
                {
                    if (EventsForCommand[command.Key].Execute(command.Value))
                    {
                        toRemove.Add(command);                         // if we have executed the command properly, we can remove it
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            toRemove.ForEach(com => CommandsToDo.Remove(com));
        }