public void On_CommandPermission(CommandPermissionEvent cpe)
 {
     if (debug)
     {
         if (!HasPermission(cpe.User.GameID, cpe.Cmd))
         {
             Debug.Log(cpe.User + " with steamid " + cpe.User.GameID + " attempted to executed command " + cpe.ChatCommand);
         }
         return;
     }
 }
Beispiel #2
0
        // chat.say().Hooks.Chat()
        public static void On_Command(ConsoleSystem.Arg arg)
        {
            Player player = Server.GetPlayer(arg.Player());

            string[] args = arg.ArgsStr.Substring(2, arg.ArgsStr.Length - 3).Replace("\\", "").Split(new string[] { " " }, StringSplitOptions.None);

            CommandEvent cmd = new CommandEvent(player, args);

            // TODO: do this part in a different function to be documented
            if (cmd.Cmd == "")
            {
                return;
            }

            foreach (KeyValuePair <string, BasePlugin> pl in PluginLoader.GetInstance().Plugins)
            {
                ChatCommand[] commands = pl.Value.chatCommands.getChatCommands(cmd.Cmd);
                foreach (ChatCommand chatCmd in commands)
                {
                    if (chatCmd.callback == null)
                    {
                        continue;
                    }

                    CommandPermissionEvent permission = new CommandPermissionEvent(player, args, chatCmd);
                    OnNext("On_CommandPermission", permission);
                    if (permission.Blocked)
                    {
                        player.Message(permission.Reply);
                        continue;
                    }

                    try {
                        chatCmd.callback(cmd.Args, player);
                    } catch (Exception ex) {
                        Logger.LogError(chatCmd.plugin.FormatException(ex));
                    }
                }
            }
            OnNext("On_Command", cmd);

            if (cmd.Reply != "")
            {
                arg.ReplyWith(cmd.Reply);
            }
        }
Beispiel #3
0
        public static void On_Command(ConsoleSystem.Arg arg)
        {
            Player player = Server.GetPlayer(arg.Player());
            string[] args = arg.ArgsStr.Substring(2, arg.ArgsStr.Length - 3).Replace("\\", "").Split(new string[] { " " },
                                                                                                     StringSplitOptions.None);

            var cmd = new CommandEvent(player, args);

            // TODO: do this part in a different function to be documented
            if (cmd.Cmd == "")
                return;

            foreach (KeyValuePair<string, BasePlugin> pl in PluginLoader.GetInstance().Plugins) {
                ChatCommand[] commands = ((ChatCommands)pl.Value.GetGlobalObject("Commands")).getChatCommands(cmd.Cmd);

                foreach (ChatCommand chatCmd in commands) {
                    if (chatCmd.callback != null) {
                        CommandPermissionEvent permission = new CommandPermissionEvent(player, args, chatCmd);

                        OnNext("On_CommandPermission", permission);

                        if (permission.Blocked) {
                            player.Message(permission.Reply);
                            continue;
                        }

                        try {
                            chatCmd.callback(cmd.Args, player);
                        } catch (Exception ex) {
                            Logger.LogError(chatCmd.plugin.FormatException(ex));
                        }
                    }
                }
            }

            OnNext("On_Command", cmd);

            if (cmd.Reply != "")
                arg.ReplyWith(cmd.Reply);
        }
Beispiel #4
0
 public void On_CommandPermission(CommandPermissionEvent cpe)
 {
     SetHookWorking("On_CommandPermission");
     Broadcast(cpe.User.Name + " is trying to use the command " + cpe.Cmd);
 }
Beispiel #5
0
 public void OnCommandPermission(CommandPermissionEvent perm)
 {
     this.Invoke("On_CommandPermission", perm);
 }
Beispiel #6
0
        // chat.say().Hooks.Chat()
        public static void Command(ConsoleSystem.Arg arg)
        {
            Player player = Server.GetPlayer(arg.Player());

            string[] args = arg.ArgsStr.Substring(2, arg.ArgsStr.Length - 3).Replace("\\", "").Split(new string[] { " " }, StringSplitOptions.None);

            CommandEvent cmd = new CommandEvent(player, args);

            if (cmd.cmd == "")
            {
                return;
            }

            foreach (KeyValuePair <string, BasePlugin> pl in PluginLoader.GetInstance().Plugins)
            {
                ChatCommand[] commands = pl.Value.chatCommands.getChatCommands(cmd.cmd);
                foreach (ChatCommand chatCmd in commands)
                {
                    if (chatCmd.callback == null)
                    {
                        continue;
                    }

                    CommandPermissionEvent permission = new CommandPermissionEvent(player, args, chatCmd);
                    OnCommandPermission.OnNext(permission);
                    if (permission.blocked)
                    {
                        player.Message(permission.Reply);
                        continue;
                    }

                    try {
                        chatCmd.callback(cmd.args, player);
                    } catch (Exception ex) {
                        Logger.LogError(chatCmd.plugin.FormatException(ex));
                    }
                }
            }

            if (Config.GetInstance().GetBoolValue("Commands", "enabled", true))
            {
                // TODO: make a plugin from these, no need to be in the core

                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "ShowMyStats", "mystats"))
                {
                    PlayerStats stats = player.Stats;
                    player.Message(String.Format("You have {0} kills and {1} deaths!", stats.Kills, stats.Deaths));
                    player.Message(String.Format("You have taken {0} dmg, and caused {1} in total!", stats.TotalDamageTaken, stats.TotalDamageDone));
                    return;
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "ShowStatsOther", "statsof"))
                {
                    Player pOther = Player.Find(String.Join(" ", cmd.args));
                    if (pOther != null)
                    {
                        PlayerStats stats2 = pOther.Stats;
                        player.Message(String.Format(pOther.Name + " has {0} kills and {1} deaths!", stats2.Kills, stats2.Deaths));
                        player.Message(String.Format(pOther.Name + " has taken {0} dmg, and caused {1} in total!", stats2.TotalDamageTaken, stats2.TotalDamageDone));
                        return;
                    }
                    player.Message("Can't find player: " + String.Join(" ", cmd.args));
                    return;
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "ShowLocation", "whereami"))
                {
                    player.Message(player.Location.ToString());
                    return;
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "ShowOnlinePlayers", "players"))
                {
                    string msg = Server.GetInstance().Players.Count == 1 ? "You are alone!" : String.Format("There are: {0} players online!", Server.GetInstance().Players.Count);
                    player.Message(msg);
                    return;
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Help", "help"))
                {
                    foreach (string key in Config.GetInstance().PlutonConfig.EnumSection("HelpMessage"))
                    {
                        player.Message(Config.GetInstance().GetValue("HelpMessage", key));
                    }
                }

                List <ChatCommands> cc = new List <ChatCommands>();
                foreach (KeyValuePair <string, BasePlugin> pl in PluginLoader.GetInstance().Plugins)
                {
                    cc.Add(pl.Value.chatCommands);
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Commands", "commands"))
                {
                    List <string> list = new List <string>();
                    foreach (ChatCommands cm in cc)
                    {
                        list.AddRange(cm.getCommands());
                    }
                    player.Message(String.Join(", ", list.ToArray()));
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Description", "whatis"))
                {
                    if (cmd.args.Length < 1)
                    {
                        player.Message("You must provide a command name");
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        foreach (ChatCommands cm in cc)
                        {
                            list.AddRange(cm.getDescriptions(cmd.args[0]));
                        }
                        if (list.Count > 0)
                        {
                            player.Message(String.Join("\r\n", list.ToArray()));
                        }
                    }
                }
                if (cmd.cmd == Config.GetInstance().GetValue("Commands", "Usage", "howto"))
                {
                    if (cmd.args.Length < 1)
                    {
                        player.Message("You must provide a command name");
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        foreach (ChatCommands cm in cc)
                        {
                            list.AddRange(cm.getUsages(cmd.args[0]));
                        }
                        foreach (var item in list)
                        {
                            player.Message(String.Format("/{0} {1}", cmd.args[0], item));
                        }
                    }
                }
            }
            OnCommand.OnNext(cmd);

            if (cmd.Reply != "")
            {
                arg.ReplyWith(cmd.Reply);
            }
        }