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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: LocalSession.cs プロジェクト: Indiefreaks/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 (command.NetworkValue == null)
         _executeCommands.Add(command, Constants.ExecuteServerCommandOnClientsNoDataExchanged);
     else
         _executeCommands.Add(command, Constants.ExecuteServerCommandOnClientsDataExchanged);
 }
コード例 #6
0
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: LidgrenSession.Server.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");
            
            _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
ファイル: LidgrenSession.Server.cs プロジェクト: rc183/igf
        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
ファイル: LocalSession.cs プロジェクト: Indiefreaks/igf
 public override void SynchronizeCommandOnClients(Command command)
 {
 }
コード例 #14
0
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
        /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: Behavior.cs プロジェクト: Indiefreaks/igf
 /// <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
ファイル: LocalSession.cs プロジェクト: Indiefreaks/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)
        {
            command.WaitingForServerReply = true;

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