mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-07 16:37:35 +01:00
If a player is not registered then we send a LOGIN plugin message on join (#2275)
* If a player is not registered then we send a LOGIN plugin message on join * Make looking up a profile optionally quiet This prevents an issue where a forcedLogin of a player that doesn't exist occurring when an unregistered player switches a server. The first login would tell AuthBungee that the player is logged in, and subsequent switches would have AuthBungee send a performLogin back that would then send an unregistered player error message to the player. Co-authored-by: bundabrg <bundabrg@grieve.com.au> Co-authored-by: Gabriele C <sgdc3.mail@gmail.com>
This commit is contained in:
parent
5426ada8f3
commit
80e37578b1
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user