示例#1
0
        /// <summary> Sends a chat message from the given player (e.g. regular player chat or /me) </summary>
        /// <remarks> Chat messages will increase player's total messages sent in /info,
        /// and count towards triggering automute for chat spamming </remarks>
        /// <remarks> Only players not ignoring the given player will see this message. </remarks>
        public static void MessageChat(ChatScope scope, Player source, string msg, object arg,
                                       ChatMessageFilter filter, bool relay = false)
        {
            Player[]          players     = PlayerInfo.Online.Items;
            ChatMessageFilter scopeFilter = scopeFilters[(int)scope];
            bool counted = false;

            // Filter out bad words
            if (Server.Config.ProfanityFiltering)
            {
                msg = ProfanityFilter.Parse(msg);
            }

            OnChatEvent.Call(scope, source, msg, arg, ref filter, relay);
            foreach (Player pl in players)
            {
                if (Ignoring(pl, source))
                {
                    continue;
                }
                // Always show message to self too (unless ignoring self)

                if (pl != source)
                {
                    if (!scopeFilter(pl, arg))
                    {
                        continue;
                    }
                    if (filter != null && !filter(pl, arg))
                    {
                        continue;
                    }

                    if (!counted)
                    {
                        source.TotalMessagesSent++; counted = true;
                    }
                }
                else
                {
                    // don't send PM back to self
                    if (scope == ChatScope.PM)
                    {
                        continue;
                    }
                }

                pl.Message(UnescapeMessage(pl, source, msg));
            }
            source.CheckForMessageSpam();
        }
示例#2
0
        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));
            }
        }
示例#3
0
        void HandleChat(byte[] buffer, int offset)
        {
            if (!loggedIn)
            {
                return;
            }
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            // Typing //Command appears in chat as /command
            // Suggested by McMrCat
            if (text.StartsWith("//"))
            {
                text = text.Remove(0, 1);
            }
            else if (DoCommand(text))
            {
                return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                SendMessage("You are muted."); return;
            }                                                     //Muted: Only allow commands

            // Lava Survival map vote recorder
            if (Server.lava.HasPlayer(this) && Server.lava.HasVote(text.ToLower()))
            {
                if (Server.lava.AddVote(this, text.ToLower()))
                {
                    SendMessage("Your vote for &5" + text.ToLower().Capitalize() + " %Shas been placed. Thanks!");
                    Server.lava.map.ChatLevelOps(name + " voted for &5" + text.ToLower().Capitalize() + "%S.");
                    return;
                }
                else
                {
                    SendMessage("&cYou already voted!");
                    return;
                }
            }
            // Filter out bad words
            if (ServerConfig.ProfanityFiltering)
            {
                text = ProfanityFilter.Parse(text);
            }

            if (IsHandledMessage(text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (Server.chatmod && !voice)
            {
                SendMessage("Chat moderation is on, you cannot speak."); return;
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }

            if (text[0] == ':' && PlayingTntWars)
            {
                string      newtext = text.Remove(0, 1).Trim();
                TntWarsGame it      = TntWarsGame.GameIn(this);
                if (it.GameMode == TntWarsGame.TntWarsGameMode.TDM)
                {
                    TntWarsGame.player pl = it.FindPlayer(this);
                    foreach (TntWarsGame.player p in it.Players)
                    {
                        if (pl.Red && p.Red)
                        {
                            SendMessage(p.p, "To Team " + Colors.red + "-" + color + name + Colors.red + "- %S" + newtext);
                        }
                        if (pl.Blue && p.Blue)
                        {
                            SendMessage(p.p, "To Team " + Colors.blue + "-" + color + name + Colors.blue + "- %S" + newtext);
                        }
                    }

                    Logger.Log(LogType.GameActivity, "[TNT Wars] [TeamChat (" + (pl.Red ? "Red" : "Blue") + ") " + name + " " + newtext);
                    return;
                }
            }

            text = HandleJoker(text);
            if (Chatroom != null)
            {
                Chat.MessageChatRoom(this, text, true, Chatroom); return;
            }

            bool   levelOnly = !level.SeesServerWideChat;
            string format    = levelOnly ? "<{0}>[level] {1}" : "<{0}> {1}";

            Logger.Log(LogType.PlayerChat, format, name, text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }

            if (levelOnly)
            {
                Chat.MessageLevel(this, text, true, level);
            }
            else
            {
                SendChatFrom(this, text);
            }
            CheckForMessageSpam();
        }
示例#4
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));
            }
        }
示例#5
0
        void HandleChat(byte[] buffer, int offset)
        {
            if (!loggedIn)
            {
                return;
            }
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            // Typing //Command appears in chat as /command
            // Suggested by McMrCat
            if (text.StartsWith("//"))
            {
                text = text.Remove(0, 1);
            }
            else if (DoCommand(text))
            {
                return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                Message("You are muted."); return;
            }                                                 //Muted: Only allow commands

            if (Server.voting)
            {
                if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
                    CheckVote(text, this, "n", "no", ref Server.NoVotes))
                {
                    return;
                }
            }

            if (LSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }
            if (ZSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (Server.chatmod && !voice)
            {
                Message("Chat moderation is on, you cannot speak."); return;
            }

            // Filter out bad words
            if (ServerConfig.ProfanityFiltering)
            {
                text = ProfanityFilter.Parse(text);
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }
            text = HandleJoker(text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }

            if (Chatroom != null)
            {
                string roomPrefix = "<ChatRoom: " + Chatroom + "> λNICK: &f";
                Chat.MessageChat(ChatScope.Chatroom, this, roomPrefix + text, Chatroom, null);
            }
            else
            {
                Chat.MessageChat(this, "λFULL: &f" + text, null, true);
            }
        }
示例#6
0
        void HandleChat(byte[] buffer, int offset)
        {
            if (!loggedIn)
            {
                return;
            }
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            bool isCommand;

            text = Chat.ParseInput(text, out isCommand);
            if (isCommand)
            {
                DoCommand(text); return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                Message("You are muted."); return;
            }                                                 //Muted: Only allow commands

            if (Server.voting)
            {
                if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
                    CheckVote(text, this, "n", "no", ref Server.NoVotes))
                {
                    return;
                }
            }

            if (LSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }
            if (ZSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (!CheckCanSpeak("speak"))
            {
                return;
            }

            // Filter out bad words
            if (Server.Config.ProfanityFiltering)
            {
                text = ProfanityFilter.Parse(text);
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }
            text = HandleJoker(text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }
            Chat.MessageChat(this, "λFULL: &f" + text, null, true);
        }
示例#7
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);
        }