From 6170b4649186e6af18ea532d0194accf0396f6d0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 7 Aug 2016 15:07:20 +1000 Subject: [PATCH] Now more chat commands will auto-mute for them being used to spam. --- Commands/Chat/CmdEat.cs | 7 +++--- Commands/Chat/CmdHigh5.cs | 1 + Commands/Chat/CmdHug.cs | 4 ++- Commands/Chat/CmdMe.cs | 13 +++++----- Commands/Chat/CmdRoll.cs | 1 + Commands/Information/CmdAfk.cs | 7 +++--- Levels/Level.cs | 3 --- Player/Player.Handlers.cs | 46 ++++++++++++++++++---------------- 8 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Commands/Chat/CmdEat.cs b/Commands/Chat/CmdEat.cs index 6725a515d..9ba9ae3d4 100644 --- a/Commands/Chat/CmdEat.cs +++ b/Commands/Chat/CmdEat.cs @@ -39,9 +39,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "You need to have at least 1 &3" + Server.moneys + " %Sto purchase a snack."); return; } - if (p.muted) { - Player.Message(p, "You cannot use this command while muted."); return; - } + if (p.muted) { Player.Message(p, "You cannot use this command while muted."); return; } p.NextEat = DateTime.UtcNow.AddSeconds(10); if (Economy.Enabled) { @@ -60,7 +58,8 @@ namespace MCGalaxy.Commands { Chat.GlobalChatLevel(p, "" + p.ColoredName + " %S" + action, false); } else { Player.SendChatFrom(p, p.ColoredName + " %S" + action, false); - } + } + p.CheckForMessageSpam(); } static string[] defMessages = { "guzzled a grape", "chewed a cherry", "ate an avocado" }; diff --git a/Commands/Chat/CmdHigh5.cs b/Commands/Chat/CmdHigh5.cs index dc63cf391..3bf4abd2a 100644 --- a/Commands/Chat/CmdHigh5.cs +++ b/Commands/Chat/CmdHigh5.cs @@ -35,6 +35,7 @@ namespace MCGalaxy.Commands { string giver = (p == null) ? "(console)" : p.ColoredName; Player.Message(who, giver + " just highfived you"); Player.GlobalMessage(p, giver + " %Sjust highfived " + who.ColoredName); + p.CheckForMessageSpam(); } public override void Help(Player p) { diff --git a/Commands/Chat/CmdHug.cs b/Commands/Chat/CmdHug.cs index 4e7eeb24e..2626f6857 100644 --- a/Commands/Chat/CmdHug.cs +++ b/Commands/Chat/CmdHug.cs @@ -43,7 +43,8 @@ namespace MCGalaxy.Commands { type = args[1]; } if (type == null) { - Player.GlobalMessage(p, giver + " %Shugged " + who.ColoredName + "."); return; + Player.GlobalMessage(p, giver + " %Shugged " + who.ColoredName + "."); + p.CheckForMessageSpam(); return; } if (type == "deadly") { @@ -56,6 +57,7 @@ namespace MCGalaxy.Commands { who.HandleDeath(Block.rock, " died from a %cdeadly hug."); } Player.GlobalMessage(p, giver + " %Sgave " + who.ColoredName + " %Sa " + type + " hug."); + p.CheckForMessageSpam(); } public override void Help(Player p) { diff --git a/Commands/Chat/CmdMe.cs b/Commands/Chat/CmdMe.cs index fd89f09f6..197d472e4 100644 --- a/Commands/Chat/CmdMe.cs +++ b/Commands/Chat/CmdMe.cs @@ -16,30 +16,29 @@ permissions and limitations under the Licenses. */ using System; -namespace MCGalaxy.Commands -{ - public sealed class CmdMe : Command - { +namespace MCGalaxy.Commands { + public sealed class CmdMe : Command { public override string name { get { return "me"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } public CmdMe() { } - public override void Use(Player p, string message) - { + + public override void Use(Player p, string message) { if (message == "") { Player.Message(p, "You"); return; } if (p == null) { MessageInGameOnly(p); return; } if (p.joker || p.muted) { Player.Message(p, "Cannot use /me while muted or jokered."); return; } if (Server.chatmod && !p.voice) { Player.Message(p, "Chat moderation is on, you cannot emote."); return; } - + if (!p.level.worldChat) { Chat.GlobalChatLevel(p, "" + p.color + "*" + Colors.StripColors(p.DisplayName) + " " + message, false); } else { Player.SendChatFrom(p, p.color + "*" + Colors.StripColors(p.DisplayName) + " " + message, false); Player.RaisePlayerAction(p, PlayerAction.Me, message); } + p.CheckForMessageSpam(); } public override void Help(Player p) { diff --git a/Commands/Chat/CmdRoll.cs b/Commands/Chat/CmdRoll.cs index 935d1e5d6..a285dc1d6 100644 --- a/Commands/Chat/CmdRoll.cs +++ b/Commands/Chat/CmdRoll.cs @@ -37,6 +37,7 @@ namespace MCGalaxy.Commands { if (min > max) { int a = min; min = max; max = a; } Player.GlobalMessage(p, p.ColoredName + " %Srolled a &a" + rand.Next(min, max + 1) + " %S(" + min + "|" + max + ")"); + p.CheckForMessageSpam(); } public override void Help(Player p) { diff --git a/Commands/Information/CmdAfk.cs b/Commands/Information/CmdAfk.cs index 22fb4b2c5..19767888c 100644 --- a/Commands/Information/CmdAfk.cs +++ b/Commands/Information/CmdAfk.cs @@ -46,7 +46,7 @@ namespace MCGalaxy.Commands { p.afkMessage = p.IsAfk ? message : null; TabList.Update(p, true); p.LastAction = DateTime.UtcNow; - + bool send = !Server.chatmod && !p.muted; if (p.IsAfk) { if (send) { @@ -61,12 +61,13 @@ namespace MCGalaxy.Commands { OnPlayerAFKEvent.Call(p); } else { if (send) { - Player.GlobalMessage("-" + p.ColoredName + "%S- is no longer AFK"); - Player.RaisePlayerAction(p, PlayerAction.UnAFK, message); + Player.GlobalMessage("-" + p.ColoredName + "%S- is no longer AFK"); + Player.RaisePlayerAction(p, PlayerAction.UnAFK, message); } else { Player.Message(p, "You are no longer marked as being AFK."); } } + p.CheckForMessageSpam(); } public override void Help(Player p) { diff --git a/Levels/Level.cs b/Levels/Level.cs index ed84e2453..5c91ba789 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -186,11 +186,8 @@ namespace MCGalaxy { try { PlayerBot.UnloadFromLevel(this); - //physChecker.Stop(); - //physChecker.Dispose(); physThread.Abort(); physThread.Join(); - } catch { } finally { Dispose(); diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 022b860ff..7de06e8e6 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -558,7 +558,7 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { } } hello: // People who are muted can't speak or vote - if ( muted ) { this.SendMessage("You are muted."); return; } //Muted: Only allow commands + 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()) ) { @@ -578,28 +578,10 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { } if (IsHandledMessage(text)) return; // Put this after vote collection so that people can vote even when chat is moderated - if ( Server.chatmod && !voice ) { this.SendMessage("Chat moderation is on, you cannot speak."); return; } + if (Server.chatmod && !voice) { SendMessage("Chat moderation is on, you cannot speak."); return; } + CheckForMessageSpam(); - if (Server.checkspam) { - if (Player.lastMSG == name) { - consecutivemessages++; - } else { - consecutivemessages--; - } - - if (consecutivemessages >= Server.spamcounter) { - muteCooldown = Server.mutespamtime; - Command.all.Find("mute").Use(null, name); - Player.GlobalMessage(color + DisplayName + " %Shas been &0muted &efor spamming!"); - muteTimer.Elapsed += MuteTimerElapsed; - muteTimer.Start(); - return; - } - } - Player.lastMSG = this.name; - - if( Chat.HandleModes(this, text) ) - return; + if (Chat.HandleModes(this, text)) return; if ( text[0] == ':' ) { if ( PlayingTntWars ) { @@ -678,6 +660,26 @@ return; catch ( Exception e ) { Server.ErrorLog(e); Player.GlobalMessage("An error occurred: " + e.Message); } } + public void CheckForMessageSpam() { + if (!Server.checkspam || ircNick != null) { Player.lastMSG = name; return; } + + if (Player.lastMSG == name) { + consecutivemessages++; + } else { + consecutivemessages--; + } + + if (consecutivemessages >= Server.spamcounter) { + muteCooldown = Server.mutespamtime; + Command.all.Find("mute").Use(null, name); + Player.GlobalMessage(color + DisplayName + " %Shas been &0muted &efor spamming!"); + muteTimer.Elapsed += MuteTimerElapsed; + muteTimer.Start(); + return; + } + Player.lastMSG = name; + } + string HandleJoker(string text) { if (!joker) return text; if (!File.Exists("text/joker.txt")) {