/* void HandleFly(Player p, ushort x, ushort y, ushort z) {
        FlyPos pos;

        ushort xx; ushort yy; ushort zz;

        TempFly.Clear();

        if (!flyGlass) y = (ushort)(y + 1);

        for (yy = y; yy >= (ushort)(y - 1); --yy)
        for (xx = (ushort)(x - 2); xx <= (ushort)(x + 2); ++xx)
        for (zz = (ushort)(z - 2); zz <= (ushort)(z + 2); ++zz)
        if (p.level.GetTile(xx, yy, zz) == Block.air) {
        pos.x = xx; pos.y = yy; pos.z = zz;
        TempFly.Add(pos);
        }

        FlyBuffer.ForEach(delegate(FlyPos pos2) {
        try { if (!TempFly.Contains(pos2)) SendBlockchange(pos2.x, pos2.y, pos2.z, Block.air); } catch { }
        });

        FlyBuffer.Clear();

        TempFly.ForEach(delegate(FlyPos pos3){
        FlyBuffer.Add(pos3);
        });

        if (flyGlass) {
        FlyBuffer.ForEach(delegate(FlyPos pos1) {
        try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.glass); } catch { }
        });
        } else {
        FlyBuffer.ForEach(delegate(FlyPos pos1) {
        try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { }
        });
        }
        } */
        void HandleChat(byte[] message)
        {
            try {
                if (!loggedIn) return;

                //byte[] message = (byte[])m;
                string text = enc.GetString(message, 1, 64).Trim();
                // removing nulls (matters for the /womid messages)
                text = text.Trim('\0');

                // handles the /womid client message, which displays the WoM version
                if (text.Truncate(6) == "/womid") {
                    Server.s.Log(name + " is using " + text.Substring(7));
                    UsingWom = true;
                    WoMVersion = text.Substring(7, 15);
                    Player.GlobalMessageOps(color + name + "%4is using WoM. Version: " + text.Substring(7, 15));
                    Server.s.Log(name + " is using WoM. Version " + text.Substring(7, 15));
                    return;
                }

                if (MessageHasBadColorCodes(this, text)) return;
                if (storedMessage != "") {
                    if (!text.EndsWith(">") && !text.EndsWith("<")) {
                        text = storedMessage.Replace("|>|", " ").Replace("|<|", "") + text;
                        storedMessage = "";
                    }
                }
                if (text.EndsWith(">")) {
                    storedMessage += text.Replace(">", "|>|");
                    SendMessage("Message appended!");
                    return;
                }
                else if (text.EndsWith("<")) {
                    storedMessage += text.Replace("<", "|<|");
                    SendMessage("Message appended!");
                    return;
                }
                else if (text.Contains("%/"))//This causes all players to crash!
                {
                    Player.SendMessage(this, "You're not allowed to send that message!");
                    return;
                }

                text = Regex.Replace(text, @"\s\s+", " ");
                foreach (char ch in text) {
                    if (ch < 32 || ch >= 127 || ch == '&') {
                        Kick("Illegal character in chat message!");
                        return;
                    }
                }
                if (text.Length == 0)
                    return;
                afkCount = 0;

                if (text != "/afk") {
                    if (Server.afkset.Contains(this.name)) {
                        Server.afkset.Remove(this.name);
                        Player.GlobalMessage("-" + this.color + this.name + Server.DefaultColor + "- is no longer AFK");
                        //IRCBot.Say(this.name + " is no longer AFK");
                    }
                }
                // This will allow people to type
                // //Command
                // and in chat it will appear as
                // /Command
                // Suggested by McMrCat
                if (text.StartsWith("//")) {
                    text = text.Remove(0, 1);
                    goto hello;
                }
                //This will make / = /repeat
                //For lazy people :P
                if (text == "/") {
                    HandleCommand("repeat", "");
                    return;
                }
                if (text[0] == '/' || text[0] == '!') {
                    text = text.Remove(0, 1);

                    int pos = text.IndexOf(' ');
                    if (pos == -1) {
                        HandleCommand(text.ToLower(), "");
                        return;
                    }
                    string cmd = text.Substring(0, pos).ToLower();
                    string msg = text.Substring(pos + 1);
                    HandleCommand(cmd, msg);
                    return;
                }
                hello:
                // People who are muted can't speak or vote
                if (muted) { this.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() + Server.DefaultColor + " has been placed. Thanks!");
                        Server.lava.map.ChatLevelOps(name + " voted for &5" + text.ToLower().Capitalize() + Server.DefaultColor + ".");
                        return;
                    }
                    else {
                        SendMessage("&cYou already voted!");
                        return;
                    }
                }

                //CmdVoteKick core vote recorder
                if (Server.voteKickInProgress && text.Length == 1) {
                    if (text.ToLower() == "y") {
                        this.voteKickChoice = VoteKickChoice.Yes;
                        SendMessage("Thanks for voting!");
                        return;
                    }
                    if (text.ToLower() == "n") {
                        this.voteKickChoice = VoteKickChoice.No;
                        SendMessage("Thanks for voting!");
                        return;
                    }
                }

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

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

                if (Server.checkspam == true) {
                    //if (consecutivemessages == 0)
                    //{
                    // consecutivemessages++;
                    //}
                    if (Player.lastMSG == this.name) {
                        consecutivemessages++;
                    }
                    else {
                        consecutivemessages--;
                    }

                    if (this.consecutivemessages >= Server.spamcounter) {
                        int total = Server.mutespamtime;
                        Command.all.Find("mute").Use(null, this.name);
                        Player.GlobalMessage(this.name + " has been &0muted &efor spamming!");
                        muteTimer.Elapsed += delegate {
                            total--;
                            if (total <= 0) {
                                muteTimer.Stop();
                                if (this.muted == true) {
                                    Command.all.Find("mute").Use(null, this.name);
                                }
                                this.consecutivemessages = 0;
                                Player.SendMessage(this, "Remember, no &cspamming &e" + "next time!");
                            }
                        };
                        muteTimer.Start();
                        return;
                    }
                }
                Player.lastMSG = this.name;

                if (text.Length >= 2 && text[0] == '@' && text[1] == '@') {
                    text = text.Remove(0, 2);
                    if (text.Length < 1) { SendMessage("No message entered"); return; }
                    SendChat(this, Server.DefaultColor + "[<] Console: &f" + text);
                    Server.s.Log("[>] " + this.name + ": " + text);
                    return;
                }
                if (text[0] == '@' || whisper) {
                    string newtext = text;
                    if (text[0] == '@') newtext = text.Remove(0, 1).Trim();

                    if (whisperTo == "") {
                        int pos = newtext.IndexOf(' ');
                        if (pos != -1) {
                            string to = newtext.Substring(0, pos);
                            string msg = newtext.Substring(pos + 1);
                            HandleQuery(to, msg); return;
                        }
                        else {
                            SendMessage("No message entered");
                            return;
                        }
                    }
                    else {
                        HandleQuery(whisperTo, newtext);
                        return;
                    }
                }
                if (text[0] == '#' || opchat) {
                    string newtext = text;
                    if (text[0] == '#') newtext = text.Remove(0, 1).Trim();

                    GlobalMessageOps("To Ops &f-" + color + name + "&f- " + newtext);
                    if (group.Permission < Server.opchatperm && !Server.devs.Contains(name.ToLower()))
                        SendMessage("To Ops &f-" + color + name + "&f- " + newtext);
                    Server.s.Log("(OPs): " + name + ": " + newtext);
                    //Server.s.OpLog("(OPs): " + name + ": " + newtext);
                    //IRCBot.Say(name + ": " + newtext, true);
                    Server.IRC.Say(name + ": " + newtext, true);
                    return;
                }
                if (text[0] == '+' || adminchat) {
                    string newtext = text;
                    if (text[0] == '+') newtext = text.Remove(0, 1).Trim();

                    GlobalMessageAdmins("To Admins &f-" + color + name + "&f- " + newtext); //to make it easy on remote
                    if (group.Permission < Server.adminchatperm && !Server.devs.Contains(name.ToLower()))
                        SendMessage("To Admins &f-" + color + name + "&f- " + newtext);
                    Server.s.Log("(Admins): " + name + ": " + newtext);
                    //Server.s.AdminLog("(Admins): " + name + ": " + newtext);
                    //IRCBot.Say(name + ": " + newtext, true);
                    Server.IRC.Say(name + ": " + newtext, true);
                    return;
                }
                if (text[0] == ':') {
                    if (PlayingTntWars) {
                        string newtext = text;
                        if (text[0] == ':') newtext = text.Remove(0, 1).Trim();
                        TntWarsGame it = TntWarsGame.GetTntWarsGame(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 " + c.red + "-" + color + name + c.red + "- " + Server.DefaultColor + newtext);
                                if (pl.Blue && p.Blue) SendMessage(p.p, "To Team " + c.blue + "-" + color + name + c.blue + "- " + Server.DefaultColor + newtext);
                            }
                            Server.s.Log("[TNT Wars] [TeamChat (" + (pl.Red ? "Red" : "Blue") + ") " + name + " " + newtext);
                            return;
                        }
                    }
                }

                /*if (this.teamchat)
            {
            if (team == null)
            {
            Player.SendMessage(this, "You are not on a team.");
            return;
            }
            foreach (Player p in team.players)
            {
            Player.SendMessage(p, "(" + team.teamstring + ") " + this.color + this.name + ":&f " + text);
            }
            return;
            }*/
                if (this.joker) {
                    if (File.Exists("text/joker.txt")) {
                        Server.s.Log("<JOKER>: " + this.name + ": " + text);
                        Player.GlobalMessageOps(Server.DefaultColor + "<&aJ&bO&cK&5E&9R" + Server.DefaultColor + ">: " + this.color + this.name + ":&f " + text);
                        FileInfo jokertxt = new FileInfo("text/joker.txt");
                        StreamReader stRead = jokertxt.OpenText();
                        List<string> lines = new List<string>();
                        Random rnd = new Random();
                        int i = 0;

                        while (!(stRead.Peek() == -1))
                            lines.Add(stRead.ReadLine());

                        stRead.Close();
                        stRead.Dispose();

                        if (lines.Count > 0) {
                            i = rnd.Next(lines.Count);
                            text = lines[i];
                        }

                    }
                    else { File.Create("text/joker.txt").Dispose(); }

                }

                //chatroom stuff
                if (this.Chatroom != null) {
                    ChatRoom(this, text, true, this.Chatroom);
                    return;
                }

                if (!level.worldChat) {
                    Server.s.Log("<" + name + ">[level] " + text);
                    GlobalChatLevel(this, text, true);
                    return;
                }

                if (text[0] == '%') {
                    string newtext = text;
                    if (!Server.worldChat) {
                        newtext = text.Remove(0, 1).Trim();
                        GlobalChatWorld(this, newtext, true);
                    }
                    else {
                        GlobalChat(this, newtext);
                    }
                    Server.s.Log("<" + name + "> " + newtext);
                    //IRCBot.Say("<" + name + "> " + newtext);
                    if (OnChat != null)
                        OnChat(this, text);
                    if (PlayerChat != null)
                        PlayerChat(this, text);
                    OnPlayerChatEvent.Call(this, text);
                    return;
                }
                Server.s.Log("<" + name + "> " + text);
                if (OnChat != null)
                    OnChat(this, text);
                if (PlayerChat != null)
                    PlayerChat(this, text);
                OnPlayerChatEvent.Call(this, text);
                if (cancelchat) {
                    cancelchat = false;
                    return;
                }
                if (Server.worldChat) {
                    GlobalChat(this, text);
                }
                else {
                    GlobalChatLevel(this, text, true);
                }

                //IRCBot.Say(name + ": " + text);
            }
            catch (Exception e) { Server.ErrorLog(e); Player.GlobalMessage("An error occurred: " + e.Message); }
        }
Example #2
0
        /*       void HandleFly(Player p, ushort x, ushort y, ushort z) {
                FlyPos pos;

                ushort xx; ushort yy; ushort zz;

                TempFly.Clear();

                if (!flyGlass) y = (ushort)(y + 1);

                for (yy = y; yy >= (ushort)(y - 1); --yy)
                for (xx = (ushort)(x - 2); xx <= (ushort)(x + 2); ++xx)
                    for (zz = (ushort)(z - 2); zz <= (ushort)(z + 2); ++zz)
                    if (p.level.GetTile(xx, yy, zz) == Block.air) {
                        pos.x = xx; pos.y = yy; pos.z = zz;
                        TempFly.Add(pos);
                    }

                FlyBuffer.ForEach(delegate(FlyPos pos2) {
                    try { if (!TempFly.Contains(pos2)) SendBlockchange(pos2.x, pos2.y, pos2.z, Block.air); } catch { }
                });

                FlyBuffer.Clear();

                TempFly.ForEach(delegate(FlyPos pos3){
                    FlyBuffer.Add(pos3);
                });

                if (flyGlass) {
                    FlyBuffer.ForEach(delegate(FlyPos pos1) {
                        try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.glass); } catch { }
                    });
                } else {
                    FlyBuffer.ForEach(delegate(FlyPos pos1) {
                        try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { }
                    });
                }
            } */
        void HandleChat(byte[] message)
        {
            try
            {
                if (!loggedIn) return;

                //byte[] message = (byte[])m;
                string text = enc.GetString(message, 1, 64).Trim();
                // removing nulls (matters for the /womid messages)
                text = text.Trim('\0');

                // handles the /womid client message, which displays the WoM version
                if (text.Truncate(6) == "/womid")
                {
                    Server.s.Log(name + " is using " + text.Substring(7));
                    return;
                }

                if (MessageHasBadColorCodes(this, text)) return;
                if (storedMessage != "")
                {
                    if (!text.EndsWith(">") && !text.EndsWith("<"))
                    {
                        text = storedMessage.Replace("|>|", " ").Replace("|<|", "") + text;
                        storedMessage = "";
                    }
                }
                if (text.EndsWith(">"))
                {
                    storedMessage += text.Replace(">", "|>|");
                    SendMessage("Message appended!");
                    return;
                }
                else if (text.EndsWith("<"))
                {
                    storedMessage += text.Replace("<", "|<|");
                    SendMessage("Message appended!");
                    return;
                }

                text = Regex.Replace(text, @"\s\s+", " ");
                foreach (char ch in text)
                {
                    if (ch < 32 || ch >= 127 || ch == '&')
                    {
                        Kick("Illegal character in chat message!");
                        return;
                    }
                }
                if (text.Length == 0)
                    return;
                afkCount = 0;

                if (text != "/afk")
                {
                    if (Server.afkset.Contains(this.name))
                    {
                        Server.afkset.Remove(this.name);
                        Player.GlobalMessage("-" + this.color + this.name + Server.DefaultColor + "- is no longer AFK");
                        //IRCBot.Say(this.name + " is no longer AFK");
                    }
                }

                if (text[0] == '/' || text[0] == '!')
                {
                    text = text.Remove(0, 1);

                    int pos = text.IndexOf(' ');
                    if (pos == -1)
                    {
                        HandleCommand(text.ToLower(), "");
                        return;
                    }
                    string cmd = text.Substring(0, pos).ToLower();
                    string msg = text.Substring(pos + 1);
                    HandleCommand(cmd, msg);
                    return;
                }

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

                //CmdVoteKick core vote recorder
                if (Server.voteKickInProgress && text.Length == 1)
                {
                    if (text.ToLower() == "y")
                    {
                        this.voteKickChoice = VoteKickChoice.Yes;
                        SendMessage("Thanks for voting!");
                        return;
                    }
                    if (text.ToLower() == "n")
                    {
                        this.voteKickChoice = VoteKickChoice.No;
                        SendMessage("Thanks for voting!");
                        return;
                    }
                }

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

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

                if (Server.checkspam == true)
                {
                    if (consecutivemessages == 0)
                    {
                        consecutivemessages++;
                    }
                    if (Player.lastMSG == this.name)
                    {
                        consecutivemessages++;
                    }
                    else
                    {
                        consecutivemessages--;
                    }

                    if (this.consecutivemessages >= Server.spamcounter)
                    {
                        int total = Server.mutespamtime;
                        Command.all.Find("mute").Use(null, this.name);
                        Player.GlobalMessage(this.name + " has been &0muted &efor spamming!");
                        muteTimer.Elapsed += delegate
                        {
                            total--;
                            if (total <= 0)
                            {
                                muteTimer.Stop();
                                if (this.muted == true)
                                {
                                    Command.all.Find("mute").Use(null, this.name);
                                }
                                this.consecutivemessages = 0;
                                Player.SendMessage(this, "Remember, no &cspamming &e" + "next time!");
                            }
                        };
                        muteTimer.Start();
                       return;
                    }
                }
                Player.lastMSG = this.name;

                if (text[0] == '@' || whisper)
                {
                    string newtext = text;
                    if (text[0] == '@') newtext = text.Remove(0, 1).Trim();

                    if (whisperTo == "")
                    {
                        int pos = newtext.IndexOf(' ');
                        if (pos != -1)
                        {
                            string to = newtext.Substring(0, pos);
                            string msg = newtext.Substring(pos + 1);
                            HandleQuery(to, msg); return;
                        }
                        else
                        {
                            SendMessage("No message entered");
                            return;
                        }
                    }
                    else
                    {
                        HandleQuery(whisperTo, newtext);
                        return;
                    }
                }
                if (text[0] == '#' || opchat)
                {
                    string newtext = text;
                    if (text[0] == '#') newtext = text.Remove(0, 1).Trim();

                    GlobalMessageOps("To Ops &f-" + color + name + "&f- " + newtext);
                    if (group.Permission < Server.opchatperm && !Server.devs.Contains(name.ToLower()))
                        SendMessage("To Ops &f-" + color + name + "&f- " + newtext);
                    Server.s.OpLog("(OPs): " + name + ": " + newtext);
                    //IRCBot.Say(name + ": " + newtext, true);
                    return;
                }
                if (text[0] == '+' || adminchat)
                {
                    string newtext = text;
                    if (text[0] == '+') newtext = text.Remove(0, 1).Trim();

                    GlobalMessageAdmins("To Admins &f-" + color + name + "&f- " + newtext);
                    if (group.Permission < Server.adminchatperm && !Server.devs.Contains(name.ToLower()))
                        SendMessage("To Admins &f-" + color + name + "&f- " + newtext);
                    Server.s.AdminLog("(Admins): " + name + ": " + newtext);
                    //IRCBot.Say(name + ": " + newtext, true);
                    return;
                }

                if (this.teamchat)
                {
                    if (team == null)
                    {
                        Player.SendMessage(this, "You are not on a team.");
                        return;
                    }
                    foreach (Player p in team.players)
                    {
                        Player.SendMessage(p, "(" + team.teamstring + ") " + this.color + this.name + ":&f " + text);
                    }
                    return;
                }
                if (this.joker)
                {
                    if (File.Exists("text/joker.txt"))
                    {
                        Server.s.Log("<JOKER>: " + this.name + ": " + text);
                        Player.GlobalMessageOps(Server.DefaultColor + "<&aJ&bO&cK&5E&9R" + Server.DefaultColor + ">: " + this.color + this.name + ":&f " + text);
                        FileInfo jokertxt = new FileInfo("text/joker.txt");
                        StreamReader stRead = jokertxt.OpenText();
                        List<string> lines = new List<string>();
                        Random rnd = new Random();
                        int i = 0;

                        while (!(stRead.Peek() == -1))
                            lines.Add(stRead.ReadLine());

                        stRead.Close();
                        stRead.Dispose();

                        if (lines.Count > 0)
                        {
                            i = rnd.Next(lines.Count);
                            text = lines[i];
                        }

                    }
                    else { File.Create("text/joker.txt").Dispose(); }

                }

                //chatroom stuff
                if (this.Chatroom != null)
                {
                    ChatRoom(this, text, true, this.Chatroom);
                    return;
                }

                if (!level.worldChat)
                {
                    Server.s.Log("<" + name + ">[level] " + text);
                    GlobalChatLevel(this, text, true);
                    return;
                }

                if (text[0] == '%')
                {
                    string newtext = text;
                    if (!Server.worldChat)
                    {
                        newtext = text.Remove(0, 1).Trim();
                        GlobalChatWorld(this, newtext, true);
                    }
                    else
                    {
                        GlobalChat(this, newtext);
                    }
                    Server.s.Log("<" + name + "> " + newtext);
                    //IRCBot.Say("<" + name + "> " + newtext);
                    return;
                }
                Server.s.Log("<" + name + "> " + text);
                if (OnChat != null)
                    OnChat(this, text);
                if (PlayerChat != null)
                    PlayerChat(this, text);
                if (cancelchat)
                {
                    cancelchat = false;
                    return;
                }
                if (Server.worldChat)
                {
                    GlobalChat(this, text);
                }
                else
                {
                    GlobalChatLevel(this, text, true);
                }

                //IRCBot.Say(name + ": " + text);
            }
            catch (Exception e) { Server.ErrorLog(e); Player.GlobalMessage("An error occurred: " + e.Message); }
        }