Add much more configuration ability to spam module. Fixes #247

This commit is contained in:
h31ix committed 2013-10-14 12:53:12 -04:00
1 parent e474be703e
commit bd2fd0952f
14 files changed
+214 -90

No files matched your search

@@ -46,7 +46,7 @@ public class Backend {
private Map<String, Integer> ascensionCount = new HashMap<String, Integer>();
private Map<String, Double> blocksOverFlight = new HashMap<String, Double>();
private Map<String, Integer> chatLevel = new HashMap<String, Integer>();
private Map<String, Integer> chatKicks = new HashMap<String, Integer>();
private Map<String, Integer> commandLevel = new HashMap<String, Integer>();
private Map<String, Integer> nofallViolation = new HashMap<String, Integer>();
private Map<String, Integer> speedViolation = new HashMap<String, Integer>();
private Map<String, Integer> fastBreakViolation = new HashMap<String, Integer>();
@@ -127,7 +127,6 @@ public class Backend {
isAscending.remove(pN);
ascensionCount.remove(pN);
blocksOverFlight.remove(pN);
chatLevel.remove(pN);
nofallViolation.remove(pN);
fastBreakViolation.remove(pN);
yAxisViolations.remove(pN);
@@ -748,7 +747,7 @@ public class Backend {
lastHeal.put(player.getName(), System.currentTimeMillis());
}
public CheckResult checkSpam(Player player, String msg) {
public CheckResult checkChatSpam(Player player, String msg) {
String name = player.getName();
User user = manager.getUserManager().getUser(name);
if (user.getLastMessageTime() != -1) {
@@ -762,8 +761,12 @@ public class Backend {
if (System.currentTimeMillis() - l > magic.CHAT_REPEAT_MIN * 100) {
user.clearMessages();
break;
} else if ((m.equalsIgnoreCase(msg) && i == 1) || System.currentTimeMillis() - user.getLastMessageTime() < magic.CHAT_MIN * 2) {
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
} else {
if (manager.getConfiguration().getConfig().blockChatSpamRepetition.getValue() && m.equalsIgnoreCase(msg) && i == 1) {
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
} else if (manager.getConfiguration().getConfig().blockChatSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN * 2) {
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
}
}
}
}
@@ -771,6 +774,33 @@ public class Backend {
return PASS;
}
public CheckResult checkCommandSpam(Player player, String cmd) {
String name = player.getName();
User user = manager.getUserManager().getUser(name);
if (user.getLastCommandTime() != -1) {
for (int i = 0; i < 2; i++) {
String m = user.getCommand(i);
if (m == null) {
break;
}
Long l = user.getCommandTime(i);
if (System.currentTimeMillis() - l > magic.COMMAND_REPEAT_MIN * 100) {
user.clearCommands();
break;
} else {
if (manager.getConfiguration().getConfig().blockCommandSpamRepetition.getValue() && m.equalsIgnoreCase(cmd) && i == 1) {
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
} else if (manager.getConfiguration().getConfig().blockCommandSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN * 2) {
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
}
}
}
}
user.addCommand(cmd);
return PASS;
}
public CheckResult checkInventoryClicks(Player player) {
if (player.getGameMode() == GameMode.CREATIVE) {
return PASS;
@@ -865,10 +895,6 @@ public class Backend {
itemInHand.put(player.getName(), player.getItemInHand().getType());
}
public void clearChatLevel(Player player) {
chatLevel.remove(player.getName());
}
public void logInstantBreak(final Player player) {
instantBreakExempt.put(player.getName(), System.currentTimeMillis());
}
@@ -1036,24 +1062,24 @@ public class Backend {
}
public void processChatSpammer(Player player) {
if (chatLevel.get(player.getName()) != null && chatLevel.get(player.getName()) >= magic.CHAT_KICK_LEVEL) {
if (player != null && player.isOnline()) {
String name = player.getName();
int kick;
if (chatKicks.get(name) == null || chatKicks.get(name) == 0) {
kick = 1;
chatKicks.put(name, kick);
} else {
kick = chatKicks.get(name) + 1;
chatKicks.put(name, kick);
}
String event = kick <= magic.CHAT_BAN_LEVEL ? manager.getConfiguration().getConfig().spamKickAction.getValue() : manager.getConfiguration().getConfig().spamBanAction.getValue();
manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.SPAM, lang.spamKickReason.getValue() + "(" + kick + "/3)", Utilities.stringToList(lang.spamWarning.getValue()), lang.spamBanReason.getValue());
}
} else {
increment(player, chatLevel, magic.CHAT_KICK_LEVEL);
User user = manager.getUserManager().getUser(player.getName());
int level = chatLevel.containsKey(user.getName()) ? chatLevel.get(user.getName()) : 0;
if (player != null && player.isOnline() && level >= magic.CHAT_ACTION_ONE_LEVEL) {
String event = level >= magic.CHAT_ACTION_TWO_LEVEL ? manager.getConfiguration().getConfig().chatSpamActionTwo.getValue() : manager.getConfiguration().getConfig().chatSpamActionOne.getValue();
manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.CHAT_SPAM, lang.spamKickReason.getValue(), Utilities.stringToList(lang.spamWarning.getValue()), lang.spamBanReason.getValue());
}
System.out.println("Chat level: "+level);
chatLevel.put(user.getName(), level + 1);
}
public void processCommandSpammer(Player player) {
User user = manager.getUserManager().getUser(player.getName());
int level = commandLevel.containsKey(user.getName()) ? commandLevel.get(user.getName()) : 0;
if (player != null && player.isOnline() && level >= magic.COMMAND_ACTION_ONE_LEVEL) {
String event = level >= magic.COMMAND_ACTION_TWO_LEVEL ? manager.getConfiguration().getConfig().commandSpamActionTwo.getValue() : manager.getConfiguration().getConfig().commandSpamActionOne.getValue();
manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.COMMAND_SPAM, lang.spamKickReason.getValue(), Utilities.stringToList(lang.spamWarning.getValue()), lang.spamBanReason.getValue());
}
commandLevel.put(user.getName(), level + 1);
}
public int increment(Player player, Map<String, Integer> map, int num) {
@@ -137,7 +137,7 @@ public class CheckManager {
* @return true if the player's world is enabled
*/
public boolean checkInWorld(Player player) {
return !config.getConfig().exemptedWorlds.getValue().contains(player.getWorld().getName());
return !config.getConfig().disabledWorlds.getValue().contains(player.getWorld().getName());
}
/**
@@ -40,7 +40,8 @@ public enum CheckType {
NO_SWING(Permission.CHECK_NOSWING),
FAST_BREAK(Permission.CHECK_FASTBREAK),
FAST_PLACE(Permission.CHECK_FASTPLACE),
SPAM(Permission.CHECK_SPAM),
CHAT_SPAM(Permission.CHECK_CHATSPAM),
COMMAND_SPAM(Permission.CHECK_COMMANDSPAM),
SPRINT(Permission.CHECK_SPRINT),
SNEAK(Permission.CHECK_SNEAK),
SPEED(Permission.CHECK_SPEED),
@@ -43,6 +43,8 @@ public class User {
private int toX, toY, toZ;
private String[] messages = new String[2];
private Long[] messageTimes = new Long[2];
private String[] commands = new String[2];
private Long[] commandTimes = new Long[2];
private boolean isWaitingOnLevelSync;
private Timestamp levelSyncTimestamp;
@@ -281,11 +283,24 @@ public class User {
* @param message Message to log
*/
public void addMessage(String message) {
messages[1] = messages[0];
messages[0] = message;
addToSpamLog(message, messages, messageTimes);
}
messageTimes[1] = messageTimes[0];
messageTimes[0] = System.currentTimeMillis();
/**
* Log a player's command
*
* @param command Command to log
*/
public void addCommand(String command) {
addToSpamLog(command, commands, commandTimes);
}
private void addToSpamLog(String string, String[] messages, Long[] times) {
messages[1] = messages[0];
messages[0] = string;
times[1] = times[0];
times[0] = System.currentTimeMillis();
}
/**
@@ -298,6 +313,16 @@ public class User {
return messages[index];
}
/**
* Get a stored command
*
* @param index Index of the command in storage
* @return the command
*/
public String getCommand(int index) {
return commands[index];
}
/**
* Get the time a message in storage was sent
*
@@ -308,6 +333,16 @@ public class User {
return messageTimes[index];
}
/**
* Get the time a command in storage was sent
*
* @param index Index of the command in storage
* @return time the command was sent
*/
public Long getCommandTime(int index) {
return commandTimes[index];
}
/**
* Clear all stored messages
*/
@@ -316,6 +351,14 @@ public class User {
messageTimes = new Long[2];
}
/**
* Clear all stored commands
*/
public void clearCommands() {
commands = new String[2];
commandTimes = new Long[2];
}
/**
* Get the time the very last stored message was sent
*
@@ -325,6 +368,15 @@ public class User {
return getMessageTime(0) == null ? -1 : getMessageTime(0);
}
/**
* Get the time the very last stored command was sent
*
* @return the last command's time
*/
public Long getLastCommandTime() {
return getCommandTime(0) == null ? -1 : getCommandTime(0);
}
private List<Group> getLevels() {
return config.getGroups().getGroups();
}