Exemplo n.º 1
0
        bool HandleWhoCommand(string nick, string ircCmd, bool opchat)
        {
            bool     whoCmd = ircCmd == ".who" || ircCmd == ".players" || ircCmd == "!players";
            DateTime last   = opchat ? lastOpWho : lastWho;

            if (!whoCmd || (DateTime.UtcNow - last).TotalSeconds <= 1)
            {
                return(false);
            }

            try {
                Player p = MakeIRCPlayer(nick, null);
                CmdPlayers.DisplayPlayers(p, "", false, false);
            } catch (Exception e) {
                Server.ErrorLog(e);
            }

            if (opchat)
            {
                lastOpWho = DateTime.UtcNow;
            }
            else
            {
                lastWho = DateTime.UtcNow;
            }
            return(true);
        }
Exemplo n.º 2
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!");
            }
        }
Exemplo n.º 3
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));
            }
        }