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.
Inheritance: 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
文件: LiveSession.cs 项目: rc183/igf
        /// <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
文件: LiveSession.cs 项目: rc183/igf
        /// <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
文件: LiveSession.cs 项目: rc183/igf
        /// <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);
        }