Prevent massive amount of mails being send.

Added new config: mails-per-minute, default 1000
This commit is contained in:
snowleo 2012-10-07 22:46:15 +02:00
parent 98d657ec4b
commit 0097f961b4
4 changed files with 36 additions and 2 deletions

View File

@ -179,4 +179,6 @@ public interface ISettings extends IConf
double getMaxFlySpeed(); double getMaxFlySpeed();
double getMaxWalkSpeed(); double getMaxWalkSpeed();
public int getMailsPerMinute();
} }

View File

@ -439,6 +439,7 @@ public class Settings implements ISettings
chatRadius = _getChatRadius(); chatRadius = _getChatRadius();
commandCosts = _getCommandCosts(); commandCosts = _getCommandCosts();
warnOnBuildDisallow = _warnOnBuildDisallow(); warnOnBuildDisallow = _warnOnBuildDisallow();
mailsPerMinute = _getMailsPerMinute();
} }
private List<Integer> itemSpawnBl = new ArrayList<Integer>(); private List<Integer> itemSpawnBl = new ArrayList<Integer>();
@ -936,4 +937,15 @@ public class Settings implements ISettings
double maxSpeed = config.getDouble("max-walk-speed", 0.8); double maxSpeed = config.getDouble("max-walk-speed", 0.8);
return maxSpeed > 1.0 ? 1.0 : Math.abs(maxSpeed); 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;
}
} }

View File

@ -11,6 +11,9 @@ import org.bukkit.entity.Player;
public class Commandmail extends EssentialsCommand public class Commandmail extends EssentialsCommand
{ {
private static int mailsPerMinute = 0;
private static long timestamp = 0;
public Commandmail() public Commandmail()
{ {
super("mail"); super("mail");
@ -58,8 +61,22 @@ public class Commandmail extends EssentialsCommand
} }
if (!u.isIgnoredPlayer(user)) if (!u.isIgnoredPlayer(user))
{ {
final String mail = Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2))); final String mail = user.getName() + ": " + Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2)));
u.addMail(user.getName() + ": " + mail); 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")); user.sendMessage(_("mailSent"));
return; return;

View File

@ -315,6 +315,9 @@ login-attack-delay: 5
#Set the max fly speed, values range from 0.1 to 1.0 #Set the max fly speed, values range from 0.1 to 1.0
max-fly-speed: 0.8 max-fly-speed: 0.8
#Set the maximum amount of mails that can be send within a minute.
mails-per-minute: 1000
############################################################ ############################################################
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
# | EssentialsHome | # # | EssentialsHome | #