From 0097f961b43ecf735513085f1cadaa760e473e73 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 7 Oct 2012 22:46:15 +0200 Subject: [PATCH] Prevent massive amount of mails being send. Added new config: mails-per-minute, default 1000 --- .../com/earth2me/essentials/ISettings.java | 2 ++ .../src/com/earth2me/essentials/Settings.java | 12 +++++++++++ .../essentials/commands/Commandmail.java | 21 +++++++++++++++++-- Essentials/src/config.yml | 3 +++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index d8c421fde..eac342d9e 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -179,4 +179,6 @@ public interface ISettings extends IConf double getMaxFlySpeed(); double getMaxWalkSpeed(); + + public int getMailsPerMinute(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index f05474196..c0cac8dcf 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -439,6 +439,7 @@ public class Settings implements ISettings chatRadius = _getChatRadius(); commandCosts = _getCommandCosts(); warnOnBuildDisallow = _warnOnBuildDisallow(); + mailsPerMinute = _getMailsPerMinute(); } private List itemSpawnBl = new ArrayList(); @@ -936,4 +937,15 @@ public class Settings implements ISettings double maxSpeed = config.getDouble("max-walk-speed", 0.8); return maxSpeed > 1.0 ? 1.0 : Math.abs(maxSpeed); } + + private int mailsPerMinute; + + private int _getMailsPerMinute() { + return config.getInt("mails-per-minute", 1000); + } + @Override + public int getMailsPerMinute() + { + return mailsPerMinute; + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 60306c272..e2c95afab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -11,6 +11,9 @@ import org.bukkit.entity.Player; public class Commandmail extends EssentialsCommand { + private static int mailsPerMinute = 0; + private static long timestamp = 0; + public Commandmail() { super("mail"); @@ -58,8 +61,22 @@ public class Commandmail extends EssentialsCommand } if (!u.isIgnoredPlayer(user)) { - final String mail = Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2))); - u.addMail(user.getName() + ": " + mail); + final String mail = user.getName() + ": " + Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2))); + if (mail.length() > 1000) + { + throw new Exception("Mail message too long. Try to keep it below 1000"); + } + if (Math.abs(System.currentTimeMillis() - timestamp) > 60000) + { + timestamp = System.currentTimeMillis(); + mailsPerMinute = 0; + } + mailsPerMinute++; + if (mailsPerMinute > ess.getSettings().getMailsPerMinute()) + { + throw new Exception("Too many mails have been send within the last minute. Maximum: " + ess.getSettings().getMailsPerMinute()); + } + u.addMail(mail); } user.sendMessage(_("mailSent")); return; diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 9fa0f8c4c..1eedc95dd 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -315,6 +315,9 @@ login-attack-delay: 5 #Set the max fly speed, values range from 0.1 to 1.0 max-fly-speed: 0.8 +#Set the maximum amount of mails that can be send within a minute. +mails-per-minute: 1000 + ############################################################ # +------------------------------------------------------+ # # | EssentialsHome | #