diff --git a/src/main/java/fr/xephi/authme/process/Management.java b/src/main/java/fr/xephi/authme/process/Management.java index 5260fed13..454c0c185 100644 --- a/src/main/java/fr/xephi/authme/process/Management.java +++ b/src/main/java/fr/xephi/authme/process/Management.java @@ -57,6 +57,10 @@ public class Management { runTask(() -> asynchronousLogin.forceLogin(player)); } + public void forceLogin(Player player, boolean quiet) { + runTask(() -> asynchronousLogin.forceLogin(player, quiet)); + } + public void performLogout(Player player) { runTask(() -> asynchronousLogout.logout(player)); } diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index 7b16e564a..cacfdbd6c 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -15,6 +15,8 @@ import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.service.SessionService; import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.service.bungeecord.BungeeSender; +import fr.xephi.authme.service.bungeecord.MessageType; import fr.xephi.authme.settings.WelcomeMessageConfiguration; import fr.xephi.authme.settings.commandconfig.CommandManager; import fr.xephi.authme.settings.properties.HooksSettings; @@ -73,6 +75,9 @@ public class AsynchronousJoin implements AsynchronousProcess { @Inject private SessionService sessionService; + @Inject + private BungeeSender bungeeSender; + @Inject private ProxySessionManager proxySessionManager; @@ -148,6 +153,7 @@ public class AsynchronousJoin implements AsynchronousProcess { }); // Skip if registration is optional + bungeeSender.sendAuthMeBungeecordMessage(MessageType.LOGIN, name); return; } diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 2e345dd47..371c2a355 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -118,6 +118,19 @@ public class AsynchronousLogin implements AsynchronousProcess { } } + /** + * Logs a player in without requiring a password. + * + * @param player the player to log in + * @param quiet if true no messages will be sent + */ + public void forceLogin(Player player, boolean quiet) { + PlayerAuth auth = getPlayerAuth(player, quiet); + if (auth != null) { + performLogin(player, auth); + } + } + /** * Checks the precondition for authentication (like user known) and returns * the player's {@link PlayerAuth} object. @@ -127,15 +140,32 @@ public class AsynchronousLogin implements AsynchronousProcess { * (e.g. because he is already logged in) */ private PlayerAuth getPlayerAuth(Player player) { + return getPlayerAuth(player, false); + } + + /** + * Checks the precondition for authentication (like user known) and returns + * the player's {@link PlayerAuth} object. + * + * @param player the player to check + * @param quiet don't send messages + * @return the PlayerAuth object, or {@code null} if the player doesn't exist or may not log in + * (e.g. because he is already logged in) + */ + private PlayerAuth getPlayerAuth(Player player, boolean quiet) { final String name = player.getName().toLowerCase(); if (playerCache.isAuthenticated(name)) { - service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); + if (!quiet) { + service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); + } return null; } PlayerAuth auth = dataSource.getAuth(name); if (auth == null) { - service.send(player, MessageKey.UNKNOWN_USER); + if (!quiet) { + service.send(player, MessageKey.UNKNOWN_USER); + } // Recreate the message task to immediately send the message again as response limboService.resetMessageTask(player, LimboMessageType.REGISTER); return null; @@ -143,13 +173,17 @@ public class AsynchronousLogin implements AsynchronousProcess { if (!service.getProperty(DatabaseSettings.MYSQL_COL_GROUP).isEmpty() && auth.getGroupId() == service.getProperty(HooksSettings.NON_ACTIVATED_USERS_GROUP)) { - service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); + if (!quiet) { + service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); + } return null; } final String ip = PlayerUtils.getPlayerIp(player); if (hasReachedMaxLoggedInPlayersForIp(player, ip)) { - service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); + if (!quiet) { + service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); + } return null; } diff --git a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java index 9de3a75bc..04f55033e 100644 --- a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java +++ b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java @@ -152,7 +152,7 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent private void performLogin(final String name) { Player player = bukkitService.getPlayerExact(name); if (player != null && player.isOnline()) { - management.forceLogin(player); + management.forceLogin(player, true); logger.info("The user " + player.getName() + " has been automatically logged in, " + "as requested via plugin messaging."); } else {