Exemplo n.º 1
0
        /// <summary>
        /// Adds a available server command.
        /// </summary>
        public void AddCommand(Command Command)
        {
            if (Command.IsServerCommand)
            {
                ServerCommand RServerCommand = (ServerCommand)Command;

                if (this.AvailableServerCommands.TryGetValue(RServerCommand.Id, out Command ACommand))
                {
                    ServerCommand AServerCommand = (ServerCommand)ACommand;

                    ChecksumEncoder Encoder1 = new ChecksumEncoder(new ByteStream());
                    ChecksumEncoder Encoder2 = new ChecksumEncoder(new ByteStream());

                    AServerCommand.Encode(Encoder1);
                    RServerCommand.Encode(Encoder2);

                    if (Encoder1.Checksum != Encoder2.Checksum)
                    {
                        return;
                    }

                    if (this.AvailableServerCommands.Remove(RServerCommand.Id))
                    {
                        AServerCommand.ExecuteTick   = Command.ExecuteTick;
                        AServerCommand.TickWhenGiven = Command.TickWhenGiven;
                        AServerCommand.ExecutorId    = Command.ExecutorId;

                        Command = AServerCommand;
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "Unable to remove the server command of dictionary!");
                        return;
                    }
                }
                else
                {
                    Logging.Info(this.GetType(), "Server command id is invalid. (" + RServerCommand.Id + ")");
                    return;
                }
            }

            this.Queue.Add(Command);
        }