More reliable IP address limit.
This commit is contained in:
parent
7f95d70d4d
commit
a76b834495
|
|
@ -1614,6 +1614,7 @@ public abstract class DataStore
|
|||
this.addDefault(defaults, Messages.IsIgnoringYou, "That player is ignoring you.", null);
|
||||
this.addDefault(defaults, Messages.ConsoleOnlyCommand, "That command may only be executed from the server console.", null);
|
||||
this.addDefault(defaults, Messages.WorldNotFound, "World not found.", null);
|
||||
this.addDefault(defaults, Messages.TooMuchIpOverlap, "Sorry, there are too many players logged in with your IP address.", null);
|
||||
|
||||
//load the config file
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath));
|
||||
|
|
|
|||
|
|
@ -245,5 +245,6 @@ public enum Messages
|
|||
TooManyActiveBlocksInClaim,
|
||||
ConsoleOnlyCommand,
|
||||
WorldNotFound,
|
||||
AdjustBlocksAllSuccess
|
||||
AdjustBlocksAllSuccess,
|
||||
TooMuchIpOverlap
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,9 +142,6 @@ public class PlayerData
|
|||
//profanity warning, once per play session
|
||||
boolean profanityWarned = false;
|
||||
|
||||
//true when the player's IP address was counted against the re-use limit when he joined
|
||||
boolean ipLimited = false;
|
||||
|
||||
//whether or not this player is "in" pvp combat
|
||||
public boolean inPvpCombat()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -563,9 +563,6 @@ class PlayerEventHandler implements Listener
|
|||
|
||||
private ConcurrentHashMap<UUID, Date> lastLoginThisServerSessionMap = new ConcurrentHashMap<UUID, Date>();
|
||||
|
||||
//counts how many players are using each IP address connected to the server right now
|
||||
private ConcurrentHashMap<String, Integer> ipCountHash = new ConcurrentHashMap<String, Integer>();
|
||||
|
||||
//when a player attempts to join the server...
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
void onPlayerLogin (PlayerLoginEvent event)
|
||||
|
|
@ -727,27 +724,34 @@ class PlayerEventHandler implements Listener
|
|||
InetAddress ipAddress = playerData.ipAddress;
|
||||
if(ipAddress != null)
|
||||
{
|
||||
String ipAddressString = ipAddress.toString();
|
||||
int ipLimit = GriefPrevention.instance.config_ipLimit;
|
||||
if(ipLimit > 0 && GriefPrevention.isNewToServer(player))
|
||||
{
|
||||
Integer ipCount = this.ipCountHash.get(ipAddressString);
|
||||
if(ipCount == null) ipCount = 0;
|
||||
int ipCount = 0;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for(Player onlinePlayer : players)
|
||||
{
|
||||
if(onlinePlayer.getUniqueId().equals(player.getUniqueId())) continue;
|
||||
|
||||
PlayerData otherData = GriefPrevention.instance.dataStore.getPlayerData(onlinePlayer.getUniqueId());
|
||||
if(ipAddress.equals(otherData.ipAddress) && GriefPrevention.isNewToServer(onlinePlayer))
|
||||
{
|
||||
ipCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if(ipCount >= ipLimit)
|
||||
{
|
||||
//kick player
|
||||
PlayerKickBanTask task = new PlayerKickBanTask(player, "Sorry, there are too many players logged in with your IP address.", "GriefPrevention IP-sharing limit.", false);
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 10L);
|
||||
PlayerKickBanTask task = new PlayerKickBanTask(player, GriefPrevention.instance.dataStore.getMessage(Messages.TooMuchIpOverlap), "GriefPrevention IP-sharing limit.", false);
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 100L);
|
||||
|
||||
//silence join message
|
||||
event.setJoinMessage(null);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ipCountHash.put(ipAddressString, ipCount + 1);
|
||||
playerData.ipLimited = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -912,19 +916,6 @@ class PlayerEventHandler implements Listener
|
|||
if(player.getHealth() > 0) player.setHealth(0); //might already be zero from above, this avoids a double death message
|
||||
}
|
||||
|
||||
//reduce count of players with that player's IP address
|
||||
if(GriefPrevention.instance.config_ipLimit > 0 && playerData.ipLimited)
|
||||
{
|
||||
InetAddress ipAddress = playerData.ipAddress;
|
||||
if(ipAddress != null)
|
||||
{
|
||||
String ipAddressString = ipAddress.toString();
|
||||
Integer count = this.ipCountHash.get(ipAddressString);
|
||||
if(count == null) count = 1;
|
||||
this.ipCountHash.put(ipAddressString, count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
//drop data about this player
|
||||
this.dataStore.clearCachedPlayerData(playerID);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user