コード例 #1
0
ファイル: IRCBot.cs プロジェクト: Benedani/MCGalaxy
        bool HandleIRCCommand(string nick, string userNick, string cmdName, string cmdArgs)
        {
            Command cmd = Command.all.Find(cmdName);
            Player  p   = MakeIRCPlayer(nick, userNick);

            if (cmd == null)
            {
                Player.Message(p, "Unknown command!"); return(false);
            }

            string logCmd = cmdArgs == "" ? cmdName : cmdName + " " + cmdArgs;

            Server.s.Log("IRC Command: /" + logCmd + " (by " + userNick + ")");

            try {
                if (!p.group.CanExecute(cmd))
                {
                    cmd.MessageCannotUse(p); return(false);
                }
                cmd.Use(p, cmdArgs);
            } catch (Exception ex) {
                Player.Message(p, "CMD Error: " + ex);
            }
            return(true);
        }
コード例 #2
0
ファイル: Player.Handlers.cs プロジェクト: ProtheanGod/KingMC
        bool UseCommand(Command command, string message)
        {
            string cmd = command.name;

            if (!cmd.CaselessEq("pass") && !cmd.CaselessEq("lastcmd"))
            {
                lastCMD     = message.Length == 0 ? cmd : cmd + " " + message;
                lastCmdTime = DateTime.UtcNow;
                Logger.Log(LogType.CommandUsage, "{0} used /{1} {2}", name, cmd, message);
            }

            try { //opstats patch (since 5.5.11)
                if (Server.Opstats.CaselessContains(cmd) || (cmd.CaselessEq("review") && message.CaselessEq("next") && Server.reviewlist.Count > 0))
                {
                    Database.Backend.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
                                            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), name, cmd, message);
                }
            } catch { }

            try {
                command.Use(this, message);
            } catch (Exception e) {
                Logger.LogError(e);
                Player.Message(this, "An error occured when using the command!");
                Player.Message(this, e.GetType() + ": " + e.Message);
                return(false);
            }
            if (spamChecker != null && spamChecker.CheckCommandSpam())
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        bool UseCommand(Command command, string args, CommandData data)
        {
            string cmd = command.name;

            if (command.UpdatesLastCmd)
            {
                lastCMD     = args.Length == 0 ? cmd : cmd + " " + args;
                lastCmdTime = DateTime.UtcNow;
            }
            if (command.LogUsage)
            {
                Logger.Log(LogType.CommandUsage, "{0} used /{1} {2}", name, cmd, args);
            }

            try { //opstats patch (since 5.5.11)
                if (Server.Opstats.CaselessContains(cmd) || (cmd.CaselessEq("review") && args.CaselessEq("next") && Server.reviewlist.Count > 0))
                {
                    Database.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
                                    DateTime.Now.ToString(Database.DateFormat), name, cmd, args);
                }
            } catch { }

            try {
                command.Use(this, args, data);
            } catch (Exception e) {
                Logger.LogError(e);
                Message("&WAn error occured when using the command!");
                Message(e.GetType() + ": " + e.Message);
                return(false);
            }
            if (spamChecker != null)
            {
                if (data.Context == CommandContext.MessageBlock)
                {
                    int ms = spamChecker.ReadCommandSpam();
                    if (ms > 10)
                    {
                        Thread.Sleep(ms);
                    }

                    // If commands are blocked abort.
                    TimeSpan delta = cmdUnblocked - DateTime.UtcNow;
                    if (delta.TotalSeconds > 0)
                    {
                        return(false);
                    }
                }
                else
                if (spamChecker.CheckCommandSpam())
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
        void Listener_OnPrivate(UserInfo user, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts  = message.Split(trimChars, 2);
            string   ircCmd = parts[0].ToLower();

            if (ircCmd == ".who" || ircCmd == ".players")
            {
                try {
                    CmdPlayers.DisplayPlayers(null, "", text => Pm(user.Nick, text), false, false);
                } catch (Exception e) {
                    Server.ErrorLog(e);
                }
                return;
            }

            string error;

            if (!CheckUserAndCommand(user, ircCmd, message, out error))
            {
                if (error != null)
                {
                    Pm(user.Nick, error);
                }
                return;
            }

            Command cmd = Command.all.Find(ircCmd);

            if (cmd != null)
            {
                Server.s.Log("IRC Command: /" + message + " (by " + user.Nick + ")");
                usedCmd = user.Nick;
                string args = parts.Length > 1 ? parts[1] : "";
                try {
                    cmd.Use(new Player("IRC"), args);
                } catch (Exception e) {
                    Pm(user.Nick, "CMD Error: " + e.ToString());
                }
                usedCmd = "";
            }
            else
            {
                Pm(user.Nick, "Unknown command!");
            }
        }
コード例 #5
0
        bool UseCommand(Command command, string args, CommandData data)
        {
            string cmd = command.name;

            if (command.UpdatesLastCmd)
            {
                lastCMD     = args.Length == 0 ? cmd : cmd + " " + args;
                lastCmdTime = DateTime.UtcNow;
            }
            if (command.LogUsage)
            {
                Logger.Log(LogType.CommandUsage, "{0} used /{1} {2}", name, cmd, args);
            }

            try { //opstats patch (since 5.5.11)
                if (Server.Opstats.CaselessContains(cmd) || (cmd.CaselessEq("review") && args.CaselessEq("next") && Server.reviewlist.Count > 0))
                {
                    Database.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
                                    DateTime.Now.ToString(Database.DateFormat), name, cmd, args);
                }
            } catch { }

            try {
                command.Use(this, args, data);
            } catch (Exception e) {
                Logger.LogError(e);
                Message("&WAn error occured when using the command!");
                Message(e.GetType() + ": " + e.Message);
                return(false);
            }
            if (spamChecker != null && spamChecker.CheckCommandSpam())
            {
                return(false);
            }
            return(true);
        }
コード例 #6
0
ファイル: Player.Handlers.cs プロジェクト: Benedani/MCGalaxy
        bool UseCommand(Command command, string message)
        {
            string cmd = command.name;

            if (cmd != "repeat" && cmd != "pass")
            {
                lastCMD     = message == "" ? cmd : cmd + " " + message;
                lastCmdTime = DateTime.UtcNow;
            }
            if (cmd != "pass")
            {
                Server.s.CommandUsed(name + " used /" + cmd + " " + message);
            }

            try { //opstats patch (since 5.5.11)
                if (Server.opstats.Contains(cmd) || (cmd == "review" && message.ToLower() == "next" && Server.reviewlist.Count > 0))
                {
                    Database.Backend.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
                                            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), name, cmd, message);
                }
            } catch { }

            try {
                command.Use(this, message);
            } catch (Exception e) {
                Server.ErrorLog(e);
                Player.Message(this, "An error occured when using the command!");
                Player.Message(this, e.GetType() + ": " + e.Message);
                return(false);
            }
            if (spamChecker.CheckCommandSpam())
            {
                return(false);
            }
            return(true);
        }
コード例 #7
0
        void Listener_OnPublic(UserInfo user, string channel, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts  = message.Split(trimChars, 3);
            string   ircCmd = parts[0].ToLower();

            if (ircCmd == ".who" || ircCmd == ".players")
            {
                try {
                    CmdPlayers.DisplayPlayers(null, "", text => Say(text, false, true), false, false);
                } catch (Exception e) {
                    Server.ErrorLog(e);
                }
            }

            if (ircCmd == ".x")
            {
                string cmdName = parts.Length > 1 ? parts[1].ToLower() : "";
                string error;
                if (!CheckUserAndCommand(user, cmdName, message, out error))
                {
                    if (error != null)
                    {
                        Server.IRC.Say(error);
                    }
                    return;
                }

                Command cmd = Command.all.Find(cmdName);
                if (cmdName != "" && cmd != null)
                {
                    Server.s.Log("IRC Command: /" + message.Replace(".x ", "") + " (by " + user.Nick + ")");
                    usedCmd = "";
                    string args = parts.Length > 2 ? parts[2] : "";
                    try {
                        cmd.Use(new Player("IRC"), args);
                    } catch (Exception e) {
                        Server.IRC.Say("CMD Error: " + e.ToString());
                    }
                    usedCmd = "";
                }
                else
                {
                    Server.IRC.Say("Unknown command!");
                }
            }

            if (String.IsNullOrEmpty(message.Trim()))
            {
                message = ".";
            }

            if (channel.CaselessEq(opchannel))
            {
                Server.s.Log(String.Format("(OPs): [IRC] {0}: {1}", user.Nick, message));
                Chat.GlobalMessageOps(String.Format("To Ops &f-%I[IRC] {0}&f- {1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message));
            }
            else
            {
                Server.s.Log(String.Format("[IRC] {0}: {1}", user.Nick, message));
                Player.GlobalIRCMessage(String.Format("%I[IRC] {0}: &f{1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message));
            }
        }