Exemple #1
0
        /// <summary>
        ///     This method is used to extract the command type from an incoming message
        ///     and return the matching handler object.
        /// </summary>
        /// <param name="reader">The incoming packet including the command type byte.</param>
        /// <param name="handler">This returns the command handler object. May be null if the command was not found.</param>
        /// <param name="cmd">This returns the command data object.</param>
        private static void Parse(NetPacketReader reader, out CommandHandler handler, out CommandBase cmd)
        {
            cmd = Deserialize(reader.GetRemainingBytes());
            _logger.Debug($"Received {cmd.GetType().Name} from {cmd.SenderId}");

            handler = Command.GetCommandHandler(cmd.GetType());
            if (handler == null)
            {
                _logger.Error($"Command {cmd.GetType().Name} not found!");
                return;
            }
        }
 /// <summary>
 /// Starts a transaction if the command is not a finish command.
 /// </summary>
 /// <param name="command">A received command</param>
 public static void StartTransaction(CommandBase command)
 {
     if (Command.GetCommandHandler(command.GetType()).TransactionCmd)
     {
         _sendStarted = true;
     }
 }
Exemple #3
0
        /// <summary>
        /// This method is used to send a command to a connected client.
        /// Does only work if the current game acts as a server.
        /// </summary>
        /// <param name="peer">The NetPeer to send the command to.</param>
        /// <param name="command">The command to send.</param>
        public static void SendToClient(NetPeer peer, CommandBase command)
        {
            if (MultiplayerManager.Instance.CurrentRole != MultiplayerRole.Server)
            {
                return;
            }

            byte id = _cmdMapping[command.GetType()];

            MultiplayerManager.Instance.CurrentServer.SendToClient(peer, id, command);
        }
Exemple #4
0
        /// <summary>
        /// This method is used to send a command to the server.
        /// Does only work if the current game acts as a client.
        /// </summary>
        /// <param name="command">The command to send.</param>
        public static void SendToServer(CommandBase command)
        {
            if (MultiplayerManager.Instance.CurrentClient.Status == ClientStatus.Disconnected)
            {
                return;
            }

            byte id = _cmdMapping[command.GetType()];

            MultiplayerManager.Instance.CurrentClient.SendToServer(id, command);
        }
        /// <summary>
        /// Starts a transaction if the given command is a transaction command
        /// and the transaction was not yet started.
        /// </summary>
        /// <param name="command">A received command</param>
        public static void CheckSendTransaction(CommandBase command)
        {
            CommandHandler  handler = Command.GetCommandHandler(command.GetType());
            TransactionType type    = handler.Transaction;

            if (type != TransactionType.NONE)
            {
                if (!_sendStarted.Contains(type))
                {
                    _sendStarted.Add(type);
                }
            }
        }