Login performance (#1331)
* Ignore intellij tmp files * Enhance onLogin performance
This commit is contained in:
@@ -64,16 +64,16 @@ public class OnJoinVerifier implements Reloadable {
|
||||
/**
|
||||
* Checks if Antibot is enabled.
|
||||
*
|
||||
* @param player the player
|
||||
* @param name the player name
|
||||
* @param isAuthAvailable whether or not the player is registered
|
||||
* @throws FailedVerificationException if the verification fails
|
||||
*/
|
||||
public void checkAntibot(Player player, boolean isAuthAvailable) throws FailedVerificationException {
|
||||
if (isAuthAvailable || permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_ANTIBOT)) {
|
||||
public void checkAntibot(String name, boolean isAuthAvailable) throws FailedVerificationException {
|
||||
if (isAuthAvailable || permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_ANTIBOT)) {
|
||||
return;
|
||||
}
|
||||
if (antiBotService.shouldKick()) {
|
||||
antiBotService.addPlayerKick(player.getName());
|
||||
antiBotService.addPlayerKick(name);
|
||||
throw new FailedVerificationException(MessageKey.KICK_ANTIBOT);
|
||||
}
|
||||
}
|
||||
@@ -148,14 +148,13 @@ public class OnJoinVerifier implements Reloadable {
|
||||
/**
|
||||
* Checks that the casing in the username corresponds to the one in the database, if so configured.
|
||||
*
|
||||
* @param player the player to verify
|
||||
* @param connectingName the player name to verify
|
||||
* @param auth the auth object associated with the player
|
||||
* @throws FailedVerificationException if the verification fails
|
||||
*/
|
||||
public void checkNameCasing(Player player, PlayerAuth auth) throws FailedVerificationException {
|
||||
public void checkNameCasing(String connectingName, PlayerAuth auth) throws FailedVerificationException {
|
||||
if (auth != null && settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)) {
|
||||
String realName = auth.getRealName(); // might be null or "Player"
|
||||
String connectingName = player.getName();
|
||||
|
||||
if (StringUtils.isEmpty(realName) || "Player".equals(realName)) {
|
||||
dataSource.updateRealName(connectingName.toLowerCase(), connectingName);
|
||||
@@ -168,15 +167,15 @@ public class OnJoinVerifier implements Reloadable {
|
||||
/**
|
||||
* Checks that the player's country is admitted.
|
||||
*
|
||||
* @param player the player
|
||||
* @param name the player name
|
||||
* @param address the player address
|
||||
* @param isAuthAvailable whether or not the user is registered
|
||||
* @throws FailedVerificationException if the verification fails
|
||||
*/
|
||||
public void checkPlayerCountry(Player player, String address, boolean isAuthAvailable) throws FailedVerificationException {
|
||||
public void checkPlayerCountry(String name, String address, boolean isAuthAvailable) throws FailedVerificationException {
|
||||
if ((!isAuthAvailable || settings.getProperty(ProtectionSettings.ENABLE_PROTECTION_REGISTERED))
|
||||
&& settings.getProperty(ProtectionSettings.ENABLE_PROTECTION)
|
||||
&& !permissionsManager.hasPermission(player, PlayerStatePermission.BYPASS_COUNTRY_CHECK)
|
||||
&& !permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_COUNTRY_CHECK)
|
||||
&& !validationService.isCountryAdmitted(address)) {
|
||||
throw new FailedVerificationException(MessageKey.COUNTRY_BANNED_ERROR);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import fr.xephi.authme.service.TeleportationService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -26,6 +27,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@@ -77,6 +79,8 @@ public class PlayerListener implements Listener {
|
||||
@Inject
|
||||
private JoinMessageService joinMessageService;
|
||||
|
||||
private boolean isAsyncPlayerPreLoginEventCalled = false;
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
String cmd = event.getMessage().split(" ")[0].toLowerCase();
|
||||
@@ -190,19 +194,54 @@ public class PlayerListener implements Listener {
|
||||
management.performJoin(player);
|
||||
}
|
||||
|
||||
private void runOnJoinChecks(String name, String ip) throws FailedVerificationException {
|
||||
// Fast stuff
|
||||
onJoinVerifier.checkSingleSession(name);
|
||||
onJoinVerifier.checkIsValidName(name);
|
||||
|
||||
// Get the auth later as this may cause the single session check to fail
|
||||
// Slow stuff
|
||||
final PlayerAuth auth = dataSource.getAuth(name);
|
||||
final boolean isAuthAvailable = auth != null;
|
||||
onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
|
||||
onJoinVerifier.checkAntibot(name, isAuthAvailable);
|
||||
onJoinVerifier.checkNameCasing(name, auth);
|
||||
onJoinVerifier.checkPlayerCountry(name, ip, isAuthAvailable);
|
||||
}
|
||||
|
||||
// Note #831: AsyncPlayerPreLoginEvent is not fired by all servers in offline mode
|
||||
// e.g. CraftBukkit does not fire it. So we need to run crucial things with PlayerLoginEvent.
|
||||
// Single session feature can be implemented for Spigot and CraftBukkit by canceling a kick
|
||||
// event caused by "logged in from another location". The nicer way, but only for Spigot, would be
|
||||
// to check in the AsyncPlayerPreLoginEvent. To support all servers, we use the less nice way.
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onAsyncPlayerPreLoginEvent(AsyncPlayerPreLoginEvent event) {
|
||||
isAsyncPlayerPreLoginEventCalled = true;
|
||||
|
||||
final String name = event.getName();
|
||||
|
||||
if (validationService.isUnrestricted(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
runOnJoinChecks(name, event.getAddress().getHostAddress());
|
||||
} catch (FailedVerificationException e) {
|
||||
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final String name = player.getName();
|
||||
|
||||
if (validationService.isUnrestricted(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (onJoinVerifier.refusePlayerForFullServer(event)) {
|
||||
return;
|
||||
}
|
||||
@@ -210,26 +249,16 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Fast stuff
|
||||
onJoinVerifier.checkSingleSession(name);
|
||||
onJoinVerifier.checkIsValidName(name);
|
||||
|
||||
// Get the auth later as this may cause the single session check to fail
|
||||
// Slow stuff
|
||||
final PlayerAuth auth = dataSource.getAuth(name);
|
||||
final boolean isAuthAvailable = auth != null;
|
||||
onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
|
||||
onJoinVerifier.checkAntibot(player, isAuthAvailable);
|
||||
onJoinVerifier.checkNameCasing(player, auth);
|
||||
onJoinVerifier.checkPlayerCountry(player, event.getAddress().getHostAddress(), isAuthAvailable);
|
||||
} catch (FailedVerificationException e) {
|
||||
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
|
||||
teleportationService.teleportOnJoin(player);
|
||||
|
||||
if(!isAsyncPlayerPreLoginEventCalled) {
|
||||
try {
|
||||
runOnJoinChecks(name, event.getAddress().getHostAddress());
|
||||
} catch (FailedVerificationException e) {
|
||||
event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
||||
Reference in New Issue
Block a user