Preventing signs with blocked IP addresses.

This commit is contained in:
ryanhamshire 2015-03-18 15:49:07 -07:00
parent 4662f7a3f3
commit 68da411528
3 changed files with 38 additions and 18 deletions

View File

@ -121,6 +121,13 @@ public class BlockEventHandler implements Listener
String signMessage = lines.toString(); String signMessage = lines.toString();
//prevent signs with blocked IP addresses
if(!player.hasPermission("griefprevention.spam") && GriefPrevention.instance.containsBlockedIP(signMessage))
{
event.setCancelled(true);
return;
}
//if not empty and wasn't the same as the last sign, log it and remember it for later //if not empty and wasn't the same as the last sign, log it and remember it for later
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
if(notEmpty && playerData.lastMessage != null && !playerData.lastMessage.equals(signMessage)) if(notEmpty && playerData.lastMessage != null && !playerData.lastMessage.equals(signMessage))

View File

@ -28,6 +28,8 @@ import java.util.UUID;
import java.util.Vector; import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
@ -2698,4 +2700,23 @@ public class GriefPrevention extends JavaPlugin
return result; return result;
} }
public boolean containsBlockedIP(String message)
{
message = message.replace("\r\n", "");
Pattern ipAddressPattern = Pattern.compile("([0-9]{1,3}\\.){3}[0-9]{1,3}");
Matcher matcher = ipAddressPattern.matcher(message);
//if it looks like an IP address
if(matcher.find())
{
//and it's not in the list of allowed IP addresses
if(!GriefPrevention.instance.config_spam_allowedIpAddresses.contains(matcher.group()))
{
return true;
}
}
return false;
}
} }

View File

@ -246,14 +246,7 @@ class PlayerEventHandler implements Listener
//filter IP addresses //filter IP addresses
if(!muted) if(!muted)
{ {
Pattern ipAddressPattern = Pattern.compile("([0-9]{1,3}\\.){3}[0-9]{1,3}"); if(GriefPrevention.instance.containsBlockedIP(message))
Matcher matcher = ipAddressPattern.matcher(message);
//if it looks like an IP address
if(matcher.find())
{
//and it's not in the list of allowed IP addresses
if(!GriefPrevention.instance.config_spam_allowedIpAddresses.contains(matcher.group()))
{ {
//log entry //log entry
GriefPrevention.AddLogEntry("Muted IP address from " + player.getName() + ": " + message); GriefPrevention.AddLogEntry("Muted IP address from " + player.getName() + ": " + message);
@ -266,7 +259,6 @@ class PlayerEventHandler implements Listener
muted = true; muted = true;
} }
} }
}
//if the message was mostly non-alpha-numerics or doesn't include much whitespace, consider it a spam (probably ansi art or random text gibberish) //if the message was mostly non-alpha-numerics or doesn't include much whitespace, consider it a spam (probably ansi art or random text gibberish)
if(!muted && message.length() > 5) if(!muted && message.length() > 5)