Beispiel #1
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="player">The Player to send the command to.</param>
 /// <param name="command">The command to send.</param>
 public static void SendToClient(Player player, CommandBase command)
 {
     SendToClient(player.NetPeer, command);
 }
Beispiel #2
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;
            }
        }