The Command class encapsulates methods that will be executed by the current session when necessary A Command instance contains a clientExecution delegate that is executed on the player machine when set to Local and LocalAndServer. The serverExecution gets called on the session host when set to Server. Finally, the ApplyServerResult is called back on all players when the ServerExecution delegate returns. Each Command is identified by its Id that is automatically generated by the Session so that Remote Command calls are always consistent.
Наследование: IDisposable
Пример #1
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the server and returned to all clients in the session
 /// </summary>
 /// <param name="serverExecution">The delegate to the code that will be executed by the server</param>
 /// <param name="applyServerResult">The delegate to the code that will be executed by all clients in the session when server returns</param>
 /// <param name="dataType">The Type of the data exchanged between the clients and server</param>
 /// <param name="dataTransferOptions">Tells how the command orders are transfered throught the network</param>
 protected void AddServerCommand(Command.ServerCommand serverExecution,
                              Command.ApplyServerCommand applyServerResult, Type dataType,
                              DataTransferOptions dataTransferOptions)
 {
     AddCommand(Command.CreateServerCommand(serverExecution, applyServerResult, dataType, dataTransferOptions));
 }
Пример #2
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the server and returned to all clients in the session
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="serverExecution">The delegate to the code that will be executed by the server</param>
 /// <param name="applyServerResult">The delegate to the code that will be executed by all clients in the session when server returns</param>
 /// <param name="dataType">The Type of the data exchanged between the clients and server</param>
 /// <param name="dataTransferOptions">Tells how the command orders are transfered throught the network</param>
 /// <param name="frequency"></param>
 protected void AddServerCommand(Condition condition, Command.ServerCommand serverExecution,
                              Command.ApplyServerCommand applyServerResult, Type dataType,
                              DataTransferOptions dataTransferOptions, ExecutionFrequency frequency)
 {
     AddCommand(Command.CreateServerCommand(condition, serverExecution, applyServerResult, dataType, dataTransferOptions, frequency));
 }
Пример #3
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the server and returned to all clients in the session
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="serverExecution">The delegate to the code that will be executed by the server</param>
 protected void AddServerCommand(Condition condition, Command.ServerCommand serverExecution)
 {
     AddCommand(Command.CreateServerCommand(condition, serverExecution));
 }
Пример #4
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the server and returned to all clients in the session
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="serverExecution">The delegate to the code that will be executed by the server</param>
 /// <param name="frequency"></param>
 protected void AddServerCommand(Condition condition, Command.ServerCommand serverExecution, ExecutionFrequency frequency)
 {
     AddCommand(Command.CreateServerCommand(condition, serverExecution, frequency));
 }
Пример #5
0
 /// <summary>
 /// Asks the Session to send a remote command call on all session clients
 /// </summary>
 /// <param name="command">The command that should be executed</param>
 public override void ExecuteServerCommandOnClients(Command command)
 {
     if (command.NetworkValue == null)
         _executeCommands.Add(command, Constants.ExecuteServerCommandOnClientsNoDataExchanged);
     else
         _executeCommands.Add(command, Constants.ExecuteServerCommandOnClientsDataExchanged);
 }
Пример #6
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the server and returned to all clients in the session
 /// </summary>
 /// <param name="serverExecution">The delegate to the code that will be executed by the server</param>
 protected void AddServerCommand(Command.ServerCommand serverExecution)
 {
     AddCommand(Command.CreateServerCommand(serverExecution));
 }
Пример #7
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the client
 /// </summary>
 /// <param name="clientCommand">The delegate to the code that will be executed by the client</param>
 /// <param name="condition"></param>
 protected void AddLocalCommand(Condition condition, Command.ClientCommand clientCommand)
 {
     AddCommand(Command.CreateLocalCommand(condition, clientCommand));
 }
Пример #8
0
        /// <summary>
        /// Asks the Session to send a remote command call on all session clients
        /// </summary>
        /// <param name="command">The command that should be executed</param>
        public override void ExecuteServerCommandOnClients(Command command)
        {
            if (!IsHost)
                throw new CoreException("Only the host can execute server commands on clients");

            if (command.NetworkValue != null)
                _packetWriter.Write(Constants.ExecuteServerCommandOnClientsDataExchanged);
            else
                _packetWriter.Write(Constants.ExecuteServerCommandOnClientsNoDataExchanged);

            _packetWriter.Write(command.Id);

            if (command.NetworkValue != null)
            {
                WriteNetworkValue(ref _packetWriter, command.NetworkValue);
            }

            ((LocalNetworkGamer) _networkSession.Host).SendData(_packetWriter,
                                                                ConvertToSendDataOptions(command.TransferOptions));
        }
Пример #9
0
        /// <summary>
        /// Asks the Session to send a remote command call on the session host
        /// </summary>
        /// <param name="command">The command that should be executed</param>
        public override void ExecuteCommandOnServer(Command command)
        {
            _outgoingMessage = LidgrenSessionManager.Client.CreateMessage();

            if (command.NetworkValue != null)
            {
                _outgoingMessage.Write((byte)LidgrenMessages.ExecuteCommandOnServerDataExchanged);
            }
            else
            {
                _outgoingMessage.Write((byte)LidgrenMessages.ExecuteCommandOnServerNoDataExchanged);
            }

            _outgoingMessage.Write(command.Id);

            if (command.NetworkValue != null)
                WriteNetworkValue(ref _outgoingMessage, command.NetworkValue);

            LidgrenSessionManager.Client.SendMessage(_outgoingMessage, ConvertToNetDeliveryMethod(command.TransferOptions));
        }
Пример #10
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the client
 /// </summary>
 /// <param name="clientCommand">The delegate to the code that will be executed by the client</param>
 protected void AddLocalCommand(Command.ClientCommand clientCommand)
 {
     AddCommand(Command.CreateLocalCommand(clientCommand));
 }
Пример #11
0
        /// <summary>
        /// Asks the Session to send a remote command call on all session clients
        /// </summary>
        /// <param name="command">The command that should be executed</param>
        public override void ExecuteServerCommandOnClients(Command command)
        {
            if (!IsHost)
                throw new CoreException("Only the host can execute server commands on clients");
            
            _outgoingMessage = LidgrenSessionManager.Server.CreateMessage();

            if (command.NetworkValue != null)
            {
                _outgoingMessage.Write((byte)LidgrenMessages.ExecuteServerCommandOnClientsDataExchanged);
            }
            else
            {
                _outgoingMessage.Write((byte) LidgrenMessages.ExecuteServerCommandOnClientsNoDataExchanged);
            }

            _outgoingMessage.Write(command.Id);

            if (command.NetworkValue != null)
            {
                WriteNetworkValue(ref _outgoingMessage, command.NetworkValue);
            }

            LidgrenSessionManager.Server.SendToAll(_outgoingMessage, ConvertToNetDeliveryMethod(command.TransferOptions));
        }
Пример #12
0
        public override void SynchronizeCommandOnClients(Command command)
        {
            _outgoingMessage = LidgrenSessionManager.Server.CreateMessage();

            _outgoingMessage.Write((byte)LidgrenMessages.SendCommandsToClients);
            _outgoingMessage.Write(command.Id);

            LidgrenSessionManager.Server.SendToAll(_outgoingMessage, NetDeliveryMethod.ReliableOrdered);
        }
Пример #13
0
 public override void SynchronizeCommandOnClients(Command command)
 {
 }
Пример #14
0
        /// <summary>
        /// Adds a new Command to the Behavior
        /// </summary>
        private void AddCommand(Command command)
        {
            command.Behavior = this;

            Commands.Add(command);

            // We register the command so that it can be executed in all player machines part of the current session
            SessionManager.CurrentSession.RegisterCommand(command);
        }
Пример #15
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed solely on the client
 /// </summary>
 /// <param name="clientCommand">The delegate to the code that will be executed by the client</param>
 /// <param name="condition"></param>
 /// <param name="frequency"></param>
 protected void AddLocalCommand(Condition condition, Command.ClientCommand clientCommand, ExecutionFrequency frequency)
 {
     AddCommand(Command.CreateLocalCommand(condition, clientCommand, frequency));
 }
Пример #16
0
        /// <summary>
        /// Sends a request to clients to synchronize commands created on Server
        /// </summary>
        /// <param name="command"></param>
        public override void SynchronizeCommandOnClients(Command command)
        {
            _packetWriter.Write(Constants.SynchronizeCommandOnClient);
            _packetWriter.Write(command.Id);

            ((LocalNetworkGamer) _networkSession.Host).SendData(_packetWriter, SendDataOptions.ReliableInOrder);
        }
Пример #17
0
 /// <summary>
 /// Adds a Command to this behavior that will be executed on the client and on the server
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="clientExecution">The delegate to the code that will be executed by the client</param>
 /// <param name="serverExecution">The delegate to the code that will be executed by the server</param>
 /// <param name="applyServerResult">The delegate to the code that will be executed by all clients in the session when server returns</param>
 /// <param name="dataType">The Type of the data exchanged between the clients and server</param>
 /// <param name="dataTransferOptions">Tells how the command orders are transfered throught the network</param>
 protected void AddLocalAndServerCommand(Condition condition, Command.ClientCommand clientExecution,
                                      Command.ServerCommand serverExecution,
                                      Command.ApplyServerCommand applyServerResult, Type dataType,
                                      DataTransferOptions dataTransferOptions)
 {
     AddCommand(Command.CreateLocalAndServerCommand(condition, clientExecution, serverExecution, applyServerResult, dataType, dataTransferOptions));
 }
Пример #18
0
        /// <summary>
        /// Asks the Session to send a remote command call on the session host
        /// </summary>
        /// <param name="command">The command that should be executed</param>
        public override void ExecuteCommandOnServer(Command command)
        {
            if (command.NetworkValue != null)
                _packetWriter.Write(Constants.ExecuteCommandOnServerDataExchanged);
            else
                _packetWriter.Write(Constants.ExecuteCommandOnServerNoDataExchanged);

            _packetWriter.Write(command.Id);

            if (command.NetworkValue != null)
                WriteNetworkValue(ref _packetWriter, command.NetworkValue);

            if (command.Behavior.Agent is PlayerAgent)
            {
                ((LocalNetworkGamer)
                 ((LiveIdentifiedPlayer) ((PlayerAgent) command.Behavior.Agent).IdentifiedPlayer).LiveGamer).SendData(
                     _packetWriter, ConvertToSendDataOptions(command.TransferOptions), _networkSession.Host);
            }
            else
            {
                ((LocalNetworkGamer) ((LiveIdentifiedPlayer) LocalPlayers[0]).LiveGamer).
                    SendData(_packetWriter, ConvertToSendDataOptions(command.TransferOptions), _networkSession.Host);
            }

            command.WaitingForServerReply = true;
        }
Пример #19
0
        /// <summary>
        /// Asks the Session to send a remote command call on the session host
        /// </summary>
        /// <param name="command">The command that should be executed</param>
        public override void ExecuteCommandOnServer(Command command)
        {
            command.WaitingForServerReply = true;

            if (command.NetworkValue == null)
                _executeCommands.Add(command, Constants.ExecuteCommandOnServerNoDataExchanged);
            else
                _executeCommands.Add(command, Constants.ExecuteCommandOnServerDataExchanged);
        }