예제 #1
0
파일: IRCBot.cs 프로젝트: Benedani/MCGalaxy
        void Listener_OnPrivate(UserInfo user, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts   = message.SplitSpaces(2);
            string   cmdName = parts[0].ToLower();
            string   cmdArgs = parts.Length > 1 ? parts[1] : "";

            if (HandleWhoCommand(user.Nick, cmdName, false))
            {
                return;
            }
            Command.Search(ref cmdName, ref cmdArgs);

            string error;
            string chan = String.IsNullOrEmpty(channel) ? opchannel : channel;

            if (!CheckIRCCommand(user, cmdName, chan, out error))
            {
                if (error != null)
                {
                    Pm(user.Nick, error);
                }
                return;
            }
            HandleIRCCommand(user.Nick, user.Nick, cmdName, cmdArgs);
        }
예제 #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!");
            }
        }
예제 #3
0
파일: Ban.cs 프로젝트: Peteys93/MCGalaxy
        /// <summary> Gives info about the ban of user, as a string array of
        /// {banned by, ban reason, date and time, previous rank, stealth},
        /// or null if no ban data was found. </summary>
        public static string[] GetBanData(string who)
        {
            who = who.ToLower();
            foreach (string line in File.ReadAllLines("text/bans.txt"))
            {
                string[] parts = line.Split(' ');
                if (parts.Length <= 5 || parts[1] != who)
                {
                    continue;
                }

                parts[2] = CP437Reader.ConvertToRaw(parts[2]).Replace("%20", " ");
                parts[4] = parts[4].Replace("%20", " ");
                return(new[] { parts[0], parts[2], parts[4], parts[5], parts[3] });
            }
            return(null);
        }
예제 #4
0
파일: IRCBot.cs 프로젝트: Benedani/MCGalaxy
        void Listener_OnPublic(UserInfo user, string channel, string message)
        {
            message = message.TrimEnd();
            if (message.Length == 0)
            {
                return;
            }
            bool opchat = channel.CaselessEq(opchannel);

            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts  = message.SplitSpaces(3);
            string   ircCmd = parts[0].ToLower();

            string nick = opchat ? "#@private@#" : "#@public@#";

            if (HandleWhoCommand(nick, ircCmd, opchat))
            {
                return;
            }

            if (ircCmd == ".x" && !HandlePublicCommand(user, channel, message, parts, opchat))
            {
                return;
            }

            if (channel.CaselessEq(opchannel))
            {
                Server.s.Log(String.Format("(OPs): [IRC] {0}: {1}", user.Nick, message));
                Chat.MessageOps(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));
            }
        }
예제 #5
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));
            }
        }
예제 #6
0
        void Listener_OnPublic(UserInfo user, string channel, string message)
        {
            message = CP437Reader.ConvertToRaw(message);
            //string allowedchars = "1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./!@#$%^*()_+QWERTYUIOPASDFGHJKL:\"ZXCVBNM<>? ";
            //string msg = message;
            RemoveVariables(ref message);
            RemoveWhitespace(ref message);

            //if (message.Contains("^UGCS"))
            //{
            //    Server.UpdateGlobalSettings();
            //    return;
            //}
            if (message.Contains("^IPGET "))
            {
                Player[] players = PlayerInfo.Online.Items;
                foreach (Player p in players)
                {
                    if (p.name == message.Split(' ')[1])
                    {
                        if (Server.UseGlobalChat && IsConnected())
                        {
                            if (Player.IsLocalIpAddress(p.ip))
                            {
                                connection.Sender.PublicMessage(channel, "^IP " + p.name + ": " + Server.IP);
                                connection.Sender.PublicMessage(channel, "^PLAYER IS CONNECTING THROUGH A LOCAL IP.");
                            }
                            else
                            {
                                connection.Sender.PublicMessage(channel, "^IP " + p.name + ": " + p.ip);
                            }
                        }
                    }
                }
            }
            if (message.Contains("^SENDRULES "))
            {
                Player who = PlayerInfo.Find(message.Split(' ')[1]);
                if (who != null)
                {
                    Command.all.Find("gcrules").Use(who, "");
                }
            }
            if (message.Contains("^GETINFO "))
            {
                if (message.Split(' ')[1] == Server.GlobalChatNick())
                {
                    if (Server.UseGlobalChat && IsConnected())
                    {
                        connection.Sender.PublicMessage(channel, "^NAME: " + Server.name);
                        connection.Sender.PublicMessage(channel, "^MOTD: " + Server.motd);
                        connection.Sender.PublicMessage(channel, "^VERSION: " + Server.VersionString);
                        connection.Sender.PublicMessage(channel, "^URL: " + Server.URL);
                        connection.Sender.PublicMessage(channel, "^PLAYERS: " + PlayerInfo.Online.Count + "/" + Server.players);
                    }
                }
            }

            //for RoboDash's anti advertise/swear in #globalchat
            if (message.Contains("^ISASERVER "))
            {
                if (Server.GlobalChatNick() == message.Split(' ')[1])
                {
                    connection.Sender.PublicMessage(channel, "^IMASERVER");
                }
            }

            if (message.StartsWith("^"))
            {
                return;
            }

            message = message.MCCharFilter();

            if (String.IsNullOrEmpty(message))
            {
                return;
            }

            if (OnNewRecieveGlobalMessage != null)
            {
                OnNewRecieveGlobalMessage(user.Nick, message);
            }

            if (Server.Devs.CaselessContains(message.Split(':')[0]) && !message.StartsWith("[Dev]") && !message.StartsWith("[Developer]"))
            {
                message = "[Dev]" + message;
            }
            else if (Server.Mods.CaselessContains(message.Split(':')[0]) && !message.StartsWith("[Mod]") && !message.StartsWith("[Moderator]"))
            {
                message = "[Mod]" + message;
            }

            /*try {
             *  if(GUI.GuiEvent != null)
             *  GUI.GuiEvents.GlobalChatEvent(this, "> " + user.Nick + ": " + message); }
             * catch { Server.s.Log(">[Global] " + user.Nick + ": " + message); }*/
            Player.GlobalMessage(String.Format("%G>[Global] {0}: &f{1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message), true);
        }