Пример #1
0
        private void HandleExecuteCommand(ExecuteCommandPacket packet)
        {
            if (!Authorized)
            {
                SendPacket(new AuthorizationDisconnectPacket {
                    Reason = "Not authorized!"
                });
                return;
            }

            Module.ExecuteClientCommand(this, packet.Command);
        }
        private void HandleExecuteCommand(ExecuteCommandPacket packet)
        {
            if (!Authorized)
            {
                SendPacket(new AuthorizationDisconnectPacket {
                    Reason = "Not authorized!"
                });
                return;
            }

            Package Package = new Package(Package.PackageTypes.ChatMessage, packet.Command, null);

            Core.Command.HandleAllCommand(Package);
        }
Пример #3
0
        private void OnExecuteCommand(ExecuteCommandPacket packet, NetPeer peer)
        {
            CommandType commandType = (CommandType)packet.Type;

            if (!Servers.TryGetValue(peer, out NPServer server))
            {
                return;
            }

            if (!server.PlayersDictionary.TryGetValue(packet.UserID, out NPPlayer player))
            {
                Logger.Error($"Player \"{packet.UserID}\" tried executing command \"{packet.CommandName.ToUpper()}\" but its offline.");
                return;
            }

            var addon = server.GetAddon(packet.AddonID);

            if (addon == null)
            {
                Logger.Error($"Player \"{packet.UserID}\" tried executing command \"{packet.CommandName.ToUpper()}\" but addon id is invalid!");
                return;
            }

            if (addon.Commands[commandType].TryGetValue(packet.CommandName.ToUpper(), out ICommand cmd))
            {
                Logger.Info($"[{addon.AddonName}] [{commandType}] Player \"{packet.UserID}\" executed command \"{packet.CommandName.ToUpper()}\" with arguments \"{string.Join(" ", packet.Arguments)}\".");
                try
                {
                    cmd.Invoke(player, packet.Arguments);
                }
                catch (Exception ex)
                {
                    Logger.Error($"[{addon.AddonName}] Player \"{packet.UserID}\" failed to execute command \"{packet.CommandName.ToUpper()}\",\n{ex}");
                }
            }
            else
            {
                Logger.Error($"[{addon.AddonName}] Player \"{packet.UserID}\" tried executing command \"{packet.CommandName.ToUpper()}\" but command not exists in targeted addon!");
            }
        }