コード例 #1
0
        internal static void OnClientCommand(Message packet)
        {
            string command = packet.read.String();

            if (packet.connection == null || !packet.connection.connected)
            {
                ConsoleSystem.LogWarning(string.Concat("Client without connection tried to run command: ", command));
                return;
            }
            Arg arg = Arg.FromClient(command, packet.connection);

            if (arg.Invalid)
            {
                ConsoleSystem.LogWarning($"Invalid console command from [{packet.ToPlayer().SteamID}/{packet.ToPlayer().Username}]: {command}");
                return;
            }

            if (ListCommandMethods.TryGetValue(arg.Command, out CommandMethod cmdMethod) == false)
            {
                ConsoleSystem.LogWarning($"Unknown console command from [{packet.ToPlayer().SteamID}/{packet.ToPlayer().Username}]: {arg.Command}");
                return;
            }

            if (cmdMethod.Attribute.IsAdmin && arg.IsAdmin == false)
            {
                SendClientReply(packet.connection, "You don't have permission to run this command");
                return;
            }

            cmdMethod.Call.Invoke(null, arg);

            if (string.IsNullOrEmpty(arg.Reply) == false)
            {
                SendClientReply(packet.connection, arg.Reply);
            }
        }