Merge branch 'master' into 674-purge-process-refactor

This commit is contained in:
Gnat008
2016-06-15 13:07:21 -04:00
12 changed files with 143 additions and 52 deletions
+5 -9
View File
@@ -7,8 +7,6 @@ import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import javax.inject.Inject;
@@ -21,13 +19,11 @@ import java.util.concurrent.ConcurrentHashMap;
// TODO Gnat008 20160613: Figure out the best way to remove entries based on time
public class TempbanManager implements SettingsDependent {
private static final long MINUTE_IN_MILLISECONDS = 60000;
private final ConcurrentHashMap<String, Integer> ipLoginFailureCounts;
private final long MINUTE_IN_MILLISECONDS = 60000;
private BukkitService bukkitService;
private Messages messages;
private final BukkitService bukkitService;
private final Messages messages;
private boolean isEnabled;
private int threshold;
@@ -102,7 +98,7 @@ public class TempbanManager implements SettingsDependent {
bukkitService.scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
Bukkit.getServer().getBanList(BanList.Type.IP).addBan(ip, reason, expires, "AuthMe");
bukkitService.banIp(ip, reason, expires, "AuthMe");
player.kickPlayer(reason);
}
});
@@ -217,6 +217,9 @@ public class AuthMePlayerListener implements Listener {
onJoinVerifier.checkAntibot(name, isAuthAvailable);
onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
onJoinVerifier.checkIsValidName(name);
// Note #760: Single session must be checked here - checking with PlayerLoginEvent is too late and
// the first connection will have been kicked. This means this feature doesn't work on CraftBukkit.
onJoinVerifier.checkSingleSession(name);
} catch (FailedVerificationException e) {
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
@@ -243,7 +246,6 @@ public class AuthMePlayerListener implements Listener {
onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
onJoinVerifier.checkIsValidName(name);
onJoinVerifier.checkNameCasing(player, auth);
onJoinVerifier.checkSingleSession(player);
onJoinVerifier.checkPlayerCountry(isAuthAvailable, event);
} catch (FailedVerificationException e) {
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
@@ -3,9 +3,6 @@ package fr.xephi.authme.listener;
import fr.xephi.authme.AntiBot;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.output.MessageKey;
@@ -18,7 +15,6 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.ValidationService;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@@ -49,8 +45,6 @@ class OnJoinVerifier implements Reloadable {
@Inject
private BukkitService bukkitService;
@Inject
private LimboCache limboCache;
@Inject
private Server server;
private Pattern nicknamePattern;
@@ -187,21 +181,15 @@ class OnJoinVerifier implements Reloadable {
* Checks if a player with the same name (case-insensitive) is already playing and refuses the
* connection if so configured.
*
* @param player the player to verify
* @param name the player name to check
*/
public void checkSingleSession(Player player) throws FailedVerificationException {
public void checkSingleSession(String name) throws FailedVerificationException {
if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) {
return;
}
Player onlinePlayer = bukkitService.getPlayerExact(player.getName());
Player onlinePlayer = bukkitService.getPlayerExact(name);
if (onlinePlayer != null) {
String name = player.getName().toLowerCase();
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (limbo != null && PlayerCache.getInstance().isAuthenticated(name)) {
Utils.addNormal(player, limbo.getGroup());
limboCache.deleteLimboPlayer(name);
}
throw new FailedVerificationException(MessageKey.USERNAME_ALREADY_ONLINE_ERROR);
}
}
@@ -124,7 +124,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
// Protect inventory
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN) && plugin.inventoryProtector != null) {
ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
plugin.getServer().getPluginManager().callEvent(ev);
bukkitService.callEvent(ev);
if (ev.isCancelled()) {
plugin.inventoryProtector.sendInventoryPacket(player);
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
@@ -133,7 +133,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
}
// The Login event now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player));
bukkitService.callEvent(new LoginEvent(player));
player.saveData();
if (service.getProperty(HooksSettings.BUNGEECORD)) {
sendBungeeMessage(player);
@@ -124,7 +124,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
}
// The LoginEvent now fires (as intended) after everything is processed
plugin.getServer().getPluginManager().callEvent(new LoginEvent(player));
bukkitService.callEvent(new LoginEvent(player));
player.saveData();
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
@@ -2,6 +2,8 @@ package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
@@ -15,6 +17,7 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
/**
@@ -206,4 +209,20 @@ public class BukkitService {
return false;
}
/**
* Adds a ban to the this list. If a previous ban exists, this will
* update the previous entry.
*
* @param ip the ip of the ban
* @param reason reason for the ban, null indicates implementation default
* @param expires date for the ban's expiration (unban), or null to imply
* forever
* @param source source of the ban, null indicates implementation default
* @return the entry for the newly created ban, or the entry for the
* (updated) previous ban
*/
public BanEntry banIp(String ip, String reason, Date expires, String source) {
return Bukkit.getServer().getBanList(BanList.Type.IP).addBan(ip, reason, expires, source);
}
}
+3 -3
View File
@@ -332,11 +332,11 @@ Security:
# information correctly without any corruption.
kickPlayersBeforeStopping: true
tempban:
# Tempban users if they enter the wrong password too many times
# Tempban a user's IP address if they enter the wrong password too many times
enableTempban: false
# How many times a user can attempt to login before being tempbanned
# How many times a user can attempt to login before their IP being tempbanned
maxLoginTries: 10
# The length of time a player will be tempbanned in minutes
# The length of time a IP address will be tempbanned in minutes
# Default: 480 minutes, or 8 hours
tempbanLength: 480
Converter: