Implement AuthMeBungee autologin (#1402)
* Implement AuthMeBungee autologin There is a failing test due to cyclic dependency injection, @ljacqu could you take a quick look at this? * Try to fix recursive dependency injection * Fix codestyle * Fix the subchannel name, again... * Split BungeeService into BungeeSender and BungeeReceiver
This commit is contained in:
parent
7e079d0b9c
commit
b7c3d4b42e
@ -27,6 +27,7 @@ import fr.xephi.authme.security.crypts.Sha256;
|
|||||||
import fr.xephi.authme.service.BackupService;
|
import fr.xephi.authme.service.BackupService;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.MigrationService;
|
import fr.xephi.authme.service.MigrationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeReceiver;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SettingsWarner;
|
import fr.xephi.authme.settings.SettingsWarner;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
@ -247,6 +248,9 @@ public class AuthMe extends JavaPlugin {
|
|||||||
commandHandler = injector.getSingleton(CommandHandler.class);
|
commandHandler = injector.getSingleton(CommandHandler.class);
|
||||||
backupService = injector.getSingleton(BackupService.class);
|
backupService = injector.getSingleton(BackupService.class);
|
||||||
|
|
||||||
|
// Trigger instantiation (class not used elsewhere)
|
||||||
|
injector.getSingleton(BungeeReceiver.class);
|
||||||
|
|
||||||
// Trigger construction of API classes; they will keep track of the singleton
|
// Trigger construction of API classes; they will keep track of the singleton
|
||||||
injector.getSingleton(fr.xephi.authme.api.v3.AuthMeApi.class);
|
injector.getSingleton(fr.xephi.authme.api.v3.AuthMeApi.class);
|
||||||
injector.getSingleton(NewAPI.class);
|
injector.getSingleton(NewAPI.class);
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import fr.xephi.authme.command.ExecutableCommand;
|
|||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
|
|||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||||
@ -34,7 +34,7 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
|
|||||||
for (PlayerAuth auth : dataSource.getAllAuths()) {
|
for (PlayerAuth auth : dataSource.getAllAuths()) {
|
||||||
resetLastPosition(auth);
|
resetLastPosition(auth);
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName);
|
||||||
}
|
}
|
||||||
sender.sendMessage("All players last position locations are now reset");
|
sender.sendMessage("All players last position locations are now reset");
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +47,7 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
|
|||||||
|
|
||||||
resetLastPosition(auth);
|
resetLastPosition(auth);
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName);
|
||||||
sender.sendMessage(playerName + "'s last position location is now reset");
|
sender.sendMessage(playerName + "'s last position location is now reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.data.limbo.LimboService;
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
@ -37,7 +37,7 @@ public class OnShutdownPlayerSaver {
|
|||||||
@Inject
|
@Inject
|
||||||
private LimboService limboService;
|
private LimboService limboService;
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
OnShutdownPlayerSaver() {
|
OnShutdownPlayerSaver() {
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ public class OnShutdownPlayerSaver {
|
|||||||
.realName(player.getName())
|
.realName(player.getName())
|
||||||
.location(loc).build();
|
.location(loc).build();
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, player.getName());
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,11 +8,11 @@ import fr.xephi.authme.permission.PermissionsManager;
|
|||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.service.AntiBotService;
|
import fr.xephi.authme.service.AntiBotService;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.JoinMessageService;
|
import fr.xephi.authme.service.JoinMessageService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
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.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
@ -86,7 +86,7 @@ public class PlayerListener implements Listener {
|
|||||||
@Inject
|
@Inject
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
private boolean isAsyncPlayerPreLoginEventCalled = false;
|
private boolean isAsyncPlayerPreLoginEventCalled = false;
|
||||||
|
|
||||||
@ -430,7 +430,7 @@ public class PlayerListener implements Listener {
|
|||||||
.location(spawn)
|
.location(spawn)
|
||||||
.build();
|
.build();
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
||||||
}
|
}
|
||||||
if (spawn != null && spawn.getWorld() != null) {
|
if (spawn != null && spawn.getWorld() != null) {
|
||||||
event.setRespawnLocation(spawn);
|
event.setRespawnLocation(spawn);
|
||||||
|
|||||||
@ -6,10 +6,10 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -31,7 +31,7 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsyncChangePassword() {
|
AsyncChangePassword() {
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
commonService.send(player, MessageKey.ERROR);
|
commonService.send(player, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, name);
|
||||||
|
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||||
@ -84,7 +84,7 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
|
|
||||||
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName);
|
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName);
|
||||||
if (dataSource.updatePassword(lowerCaseName, hashedPassword)) {
|
if (dataSource.updatePassword(lowerCaseName, hashedPassword)) {
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, lowerCaseName);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, lowerCaseName);
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||||
ConsoleLogger.info(sender.getName() + " changed password of " + lowerCaseName);
|
ConsoleLogger.info(sender.getName() + " changed password of " + lowerCaseName);
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -33,7 +33,7 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsyncAddEmail() { }
|
AsyncAddEmail() { }
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
|||||||
auth.setEmail(email);
|
auth.setEmail(email);
|
||||||
if (dataSource.updateEmail(auth)) {
|
if (dataSource.updateEmail(auth)) {
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, playerName);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, playerName);
|
||||||
service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
ConsoleLogger.warning("Could not save email for player '" + player + "'");
|
ConsoleLogger.warning("Could not save email for player '" + player + "'");
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import fr.xephi.authme.data.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsyncChangeEmail() { }
|
AsyncChangeEmail() { }
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
|||||||
auth.setEmail(newEmail);
|
auth.setEmail(newEmail);
|
||||||
if (dataSource.updateEmail(auth)) {
|
if (dataSource.updateEmail(auth)) {
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, player.getName());
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, player.getName());
|
||||||
service.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
|
service.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
service.send(player, MessageKey.ERROR);
|
service.send(player, MessageKey.ERROR);
|
||||||
|
|||||||
@ -19,9 +19,9 @@ import fr.xephi.authme.process.AsynchronousProcess;
|
|||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.SessionService;
|
import fr.xephi.authme.service.SessionService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
@ -76,7 +76,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
private SessionService sessionService;
|
private SessionService sessionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsynchronousLogin() {
|
AsynchronousLogin() {
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
auth.setLastLogin(System.currentTimeMillis());
|
auth.setLastLogin(System.currentTimeMillis());
|
||||||
auth.setLastIp(ip);
|
auth.setLastIp(ip);
|
||||||
dataSource.updateSession(auth);
|
dataSource.updateSession(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, player.getName());
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, player.getName());
|
||||||
|
|
||||||
// Successful login, so reset the captcha & temp ban count
|
// Successful login, so reset the captcha & temp ban count
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
@ -252,7 +252,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
dataSource.setLogged(name);
|
dataSource.setLogged(name);
|
||||||
sessionService.grantSession(name);
|
sessionService.grantSession(name);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.LOGIN, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.LOGIN, name);
|
||||||
|
|
||||||
// As the scheduling executes the Task most likely after the current
|
// As the scheduling executes the Task most likely after the current
|
||||||
// task, we schedule it in the end
|
// task, we schedule it in the end
|
||||||
|
|||||||
@ -8,10 +8,10 @@ import fr.xephi.authme.events.LoginEvent;
|
|||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.JoinMessageService;
|
import fr.xephi.authme.service.JoinMessageService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.settings.WelcomeMessageConfiguration;
|
import fr.xephi.authme.settings.WelcomeMessageConfiguration;
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
@ -25,7 +25,7 @@ import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_IN
|
|||||||
public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LimboService limboService;
|
private LimboService limboService;
|
||||||
@ -96,6 +96,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
commandManager.runCommandsOnLogin(player);
|
commandManager.runCommandsOnLogin(player);
|
||||||
|
|
||||||
// Send Bungee stuff. The service will check if it is enabled or not.
|
// Send Bungee stuff. The service will check if it is enabled or not.
|
||||||
bungeeService.connectPlayerOnLogin(player);
|
bungeeSender.connectPlayerOnLogin(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,9 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.SessionService;
|
import fr.xephi.authme.service.SessionService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -40,7 +40,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
private SessionService sessionService;
|
private SessionService sessionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsynchronousLogout() {
|
AsynchronousLogout() {
|
||||||
}
|
}
|
||||||
@ -59,18 +59,18 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
|
|
||||||
PlayerAuth auth = playerCache.getAuth(name);
|
PlayerAuth auth = playerCache.getAuth(name);
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, name);
|
||||||
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
||||||
auth.setQuitLocation(player.getLocation());
|
auth.setQuitLocation(player.getLocation());
|
||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
codeManager.unverify(name);
|
codeManager.unverify(name);
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
sessionService.revokeSession(name);
|
sessionService.revokeSession(name);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.LOGOUT, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.LOGOUT, name);
|
||||||
syncProcessManager.processSyncPlayerLogout(player);
|
syncProcessManager.processSyncPlayerLogout(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import fr.xephi.authme.process.SyncProcessManager;
|
|||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.SessionService;
|
import fr.xephi.authme.service.SessionService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
@ -54,7 +54,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
private SessionService sessionService;
|
private SessionService sessionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsynchronousQuit() {
|
AsynchronousQuit() {
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
.lastLogin(System.currentTimeMillis())
|
.lastLogin(System.currentTimeMillis())
|
||||||
.build();
|
.build();
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//always unauthenticate the player - use session only for auto logins on the same ip
|
//always unauthenticate the player - use session only for auto logins on the same ip
|
||||||
|
|||||||
@ -8,10 +8,10 @@ import fr.xephi.authme.message.MessageKey;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.register.executors.RegistrationExecutor;
|
import fr.xephi.authme.process.register.executors.RegistrationExecutor;
|
||||||
import fr.xephi.authme.process.register.executors.RegistrationParameters;
|
|
||||||
import fr.xephi.authme.process.register.executors.RegistrationMethod;
|
import fr.xephi.authme.process.register.executors.RegistrationMethod;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
import fr.xephi.authme.process.register.executors.RegistrationParameters;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -39,7 +39,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private SingletonStore<RegistrationExecutor> registrationExecutorFactory;
|
private SingletonStore<RegistrationExecutor> registrationExecutorFactory;
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsyncRegister() {
|
AsyncRegister() {
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
PlayerAuth auth = executor.buildPlayerAuth(parameters);
|
PlayerAuth auth = executor.buildPlayerAuth(parameters);
|
||||||
if (database.saveAuth(auth)) {
|
if (database.saveAuth(auth)) {
|
||||||
executor.executePostPersistAction(parameters);
|
executor.executePostPersistAction(parameters);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.REGISTER, parameters.getPlayerName());
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REGISTER, parameters.getPlayerName());
|
||||||
} else {
|
} else {
|
||||||
service.send(parameters.getPlayer(), MessageKey.ERROR);
|
service.send(parameters.getPlayer(), MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.data.limbo.LimboService;
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
@ -19,7 +19,7 @@ import javax.inject.Inject;
|
|||||||
public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CommonService service;
|
private CommonService service;
|
||||||
@ -72,6 +72,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send Bungee stuff. The service will check if it is enabled or not.
|
// Send Bungee stuff. The service will check if it is enabled or not.
|
||||||
bungeeService.connectPlayerOnLogin(player);
|
bungeeSender.connectPlayerOnLogin(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,9 @@ import fr.xephi.authme.message.MessageKey;
|
|||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
@ -54,7 +54,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
AsynchronousUnregister() {
|
AsynchronousUnregister() {
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
*/
|
*/
|
||||||
private void performPostUnregisterActions(String name, Player player) {
|
private void performPostUnregisterActions(String name, Player player) {
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
bungeeService.sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
bungeeSender.sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
||||||
|
|
||||||
if (player == null || !player.isOnline()) {
|
if (player == null || !player.isOnline()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -0,0 +1,92 @@
|
|||||||
|
package fr.xephi.authme.service.bungeecord;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
|
import fr.xephi.authme.process.Management;
|
||||||
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.Messenger;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class BungeeReceiver implements PluginMessageListener, SettingsDependent {
|
||||||
|
|
||||||
|
private final AuthMe plugin;
|
||||||
|
private final BukkitService bukkitService;
|
||||||
|
private final Management management;
|
||||||
|
private final DataSource dataSource;
|
||||||
|
|
||||||
|
private boolean isEnabled;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BungeeReceiver(AuthMe plugin, BukkitService bukkitService, Management management, DataSource dataSource,
|
||||||
|
Settings settings) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.bukkitService = bukkitService;
|
||||||
|
this.management = management;
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
reload(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload(Settings settings) {
|
||||||
|
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
||||||
|
|
||||||
|
if (this.isEnabled) {
|
||||||
|
Messenger messenger = plugin.getServer().getMessenger();
|
||||||
|
if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) {
|
||||||
|
messenger.registerIncomingPluginChannel(plugin, "BungeeCord", this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(data);
|
||||||
|
String subchannel = in.readUTF();
|
||||||
|
if (!"AuthMe".equals(subchannel)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = in.readUTF();
|
||||||
|
String name = in.readUTF();
|
||||||
|
switch (type) {
|
||||||
|
case MessageType.UNREGISTER:
|
||||||
|
dataSource.invalidateCache(name);
|
||||||
|
break;
|
||||||
|
case MessageType.REFRESH_PASSWORD:
|
||||||
|
case MessageType.REFRESH_QUITLOC:
|
||||||
|
case MessageType.REFRESH_EMAIL:
|
||||||
|
case MessageType.REFRESH:
|
||||||
|
dataSource.refreshCache(name);
|
||||||
|
break;
|
||||||
|
case MessageType.BUNGEE_LOGIN:
|
||||||
|
handleBungeeLogin(name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ConsoleLogger.debug("Received unsupported bungeecord message type! ({0})", type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleBungeeLogin(String name) {
|
||||||
|
Player player = bukkitService.getPlayerExact(name);
|
||||||
|
if (player != null && player.isOnline()) {
|
||||||
|
management.forceLogin(player);
|
||||||
|
ConsoleLogger.info("The user " + player.getName() + " has been automatically logged in, "
|
||||||
|
+ "as requested by the AuthMeBungee integration.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
package fr.xephi.authme.service.bungeecord;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.Messenger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
public class BungeeSender implements SettingsDependent {
|
||||||
|
|
||||||
|
private final AuthMe plugin;
|
||||||
|
private final BukkitService bukkitService;
|
||||||
|
|
||||||
|
private boolean isEnabled;
|
||||||
|
private String destinationServerOnLogin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
BungeeSender(AuthMe plugin, BukkitService bukkitService, Settings settings) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.bukkitService = bukkitService;
|
||||||
|
reload(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload(Settings settings) {
|
||||||
|
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
||||||
|
this.destinationServerOnLogin = settings.getProperty(HooksSettings.BUNGEECORD_SERVER);
|
||||||
|
|
||||||
|
if (this.isEnabled) {
|
||||||
|
Messenger messenger = plugin.getServer().getMessenger();
|
||||||
|
if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) {
|
||||||
|
messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendBungeecordMessage(String... data) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
for (String element : data) {
|
||||||
|
out.writeUTF(element);
|
||||||
|
}
|
||||||
|
bukkitService.sendPluginMessage("BungeeCord", out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a player to a specified server. If no server is configured, this will
|
||||||
|
* do nothing.
|
||||||
|
*
|
||||||
|
* @param player The player to send.
|
||||||
|
*/
|
||||||
|
public void connectPlayerOnLogin(Player player) {
|
||||||
|
if (isEnabled && !destinationServerOnLogin.isEmpty()) {
|
||||||
|
bukkitService.scheduleSyncDelayedTask(() ->
|
||||||
|
sendBungeecordMessage("Connect", player.getName(), destinationServerOnLogin), 20L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to the AuthMe plugin messaging channel, if enabled.
|
||||||
|
*
|
||||||
|
* @param type The message type, See {@link MessageType}
|
||||||
|
* @param playerName the player related to the message
|
||||||
|
*/
|
||||||
|
public void sendAuthMeBungeecordMessage(String type, String playerName) {
|
||||||
|
if (isEnabled) {
|
||||||
|
sendBungeecordMessage("AuthMe", type, playerName.toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,121 +0,0 @@
|
|||||||
package fr.xephi.authme.service.bungeecord;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
|
||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
|
||||||
import fr.xephi.authme.service.BukkitService;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.messaging.Messenger;
|
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class to manage all BungeeCord related processes.
|
|
||||||
*/
|
|
||||||
public class BungeeService implements SettingsDependent, PluginMessageListener {
|
|
||||||
|
|
||||||
private final AuthMe plugin;
|
|
||||||
private final BukkitService service;
|
|
||||||
private final DataSource dataSource;
|
|
||||||
|
|
||||||
private boolean isEnabled;
|
|
||||||
private String destinationServerOnLogin;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
BungeeService(AuthMe plugin, BukkitService service, Settings settings, DataSource dataSource) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.service = service;
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
reload(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload(Settings settings) {
|
|
||||||
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
|
||||||
this.destinationServerOnLogin = settings.getProperty(HooksSettings.BUNGEECORD_SERVER);
|
|
||||||
Messenger messenger = plugin.getServer().getMessenger();
|
|
||||||
if (!this.isEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) {
|
|
||||||
messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
|
|
||||||
}
|
|
||||||
if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) {
|
|
||||||
messenger.registerIncomingPluginChannel(plugin, "BungeeCord", this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendBungeecordMessage(String... data) {
|
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
for (String element : data) {
|
|
||||||
out.writeUTF(element);
|
|
||||||
}
|
|
||||||
service.sendPluginMessage("BungeeCord", out.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a player to a specified server. If no server is configured, this will
|
|
||||||
* do nothing.
|
|
||||||
*
|
|
||||||
* @param player The player to send.
|
|
||||||
*/
|
|
||||||
public void connectPlayerOnLogin(Player player) {
|
|
||||||
if (isEnabled && !destinationServerOnLogin.isEmpty()) {
|
|
||||||
service.scheduleSyncDelayedTask(() ->
|
|
||||||
sendBungeecordMessage("Connect", player.getName(), destinationServerOnLogin), 20L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a message to the AuthMe plugin messaging channel, if enabled.
|
|
||||||
*
|
|
||||||
* @param type The message type, See {@link MessageType}
|
|
||||||
* @param playerName the player related to the message
|
|
||||||
*/
|
|
||||||
public void sendAuthMeBungeecordMessage(String type, String playerName) {
|
|
||||||
if (isEnabled) {
|
|
||||||
sendBungeecordMessage("AuthMe", type, playerName.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
|
|
||||||
if (!isEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(data);
|
|
||||||
String subchannel = in.readUTF();
|
|
||||||
if (!"AuthMe".equals(subchannel)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String type = in.readUTF();
|
|
||||||
String name = in.readUTF();
|
|
||||||
switch (type) {
|
|
||||||
case MessageType.UNREGISTER:
|
|
||||||
dataSource.invalidateCache(name);
|
|
||||||
break;
|
|
||||||
case MessageType.REFRESH_PASSWORD:
|
|
||||||
case MessageType.REFRESH_QUITLOC:
|
|
||||||
case MessageType.REFRESH_EMAIL:
|
|
||||||
case MessageType.REFRESH:
|
|
||||||
dataSource.refreshCache(name);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ConsoleLogger.debug("Received unsupported bungeecord message type! ({0})", type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -11,6 +11,7 @@ public final class MessageType {
|
|||||||
public static final String REFRESH_QUITLOC = "refresh.quitloc";
|
public static final String REFRESH_QUITLOC = "refresh.quitloc";
|
||||||
public static final String REFRESH_EMAIL = "refresh.email";
|
public static final String REFRESH_EMAIL = "refresh.email";
|
||||||
public static final String REFRESH = "refresh";
|
public static final String REFRESH = "refresh";
|
||||||
|
public static final String BUNGEE_LOGIN = "bungeelogin";
|
||||||
|
|
||||||
private MessageType() {
|
private MessageType() {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,8 @@ import fr.xephi.authme.process.Management;
|
|||||||
import fr.xephi.authme.process.login.ProcessSyncPlayerLogin;
|
import fr.xephi.authme.process.login.ProcessSyncPlayerLogin;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeReceiver;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.task.purge.PurgeService;
|
import fr.xephi.authme.task.purge.PurgeService;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -112,10 +114,12 @@ public class AuthMeInitializationTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
// Take a few samples and ensure that they are not null
|
// Take a few samples and ensure that they are not null
|
||||||
|
assertThat(injector.getIfAvailable(AuthMeApi.class), not(nullValue()));
|
||||||
assertThat(injector.getIfAvailable(BlockListener.class), not(nullValue()));
|
assertThat(injector.getIfAvailable(BlockListener.class), not(nullValue()));
|
||||||
|
assertThat(injector.getIfAvailable(BungeeReceiver.class), not(nullValue()));
|
||||||
|
assertThat(injector.getIfAvailable(BungeeSender.class), not(nullValue()));
|
||||||
assertThat(injector.getIfAvailable(CommandHandler.class), not(nullValue()));
|
assertThat(injector.getIfAvailable(CommandHandler.class), not(nullValue()));
|
||||||
assertThat(injector.getIfAvailable(Management.class), not(nullValue()));
|
assertThat(injector.getIfAvailable(Management.class), not(nullValue()));
|
||||||
assertThat(injector.getIfAvailable(AuthMeApi.class), not(nullValue()));
|
|
||||||
assertThat(injector.getIfAvailable(PasswordSecurity.class), not(nullValue()));
|
assertThat(injector.getIfAvailable(PasswordSecurity.class), not(nullValue()));
|
||||||
assertThat(injector.getIfAvailable(PermissionsManager.class), not(nullValue()));
|
assertThat(injector.getIfAvailable(PermissionsManager.class), not(nullValue()));
|
||||||
assertThat(injector.getIfAvailable(ProcessSyncPlayerLogin.class), not(nullValue()));
|
assertThat(injector.getIfAvailable(ProcessSyncPlayerLogin.class), not(nullValue()));
|
||||||
|
|||||||
@ -3,8 +3,8 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -37,7 +37,7 @@ public class PurgeLastPositionCommandTest {
|
|||||||
private CommonService service;
|
private CommonService service;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldPurgeLastPosOfUser() {
|
public void shouldPurgeLastPosOfUser() {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -39,7 +39,7 @@ public class AsyncChangePasswordTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PasswordSecurity passwordSecurity;
|
private PasswordSecurity passwordSecurity;
|
||||||
@Mock
|
@Mock
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpLogger() {
|
public void setUpLogger() {
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -47,7 +47,7 @@ public class AsyncAddEmailTest {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -46,7 +46,7 @@ public class AsyncChangeEmailTest {
|
|||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldChangeEmail() {
|
public void shouldChangeEmail() {
|
||||||
|
|||||||
@ -10,9 +10,9 @@ import fr.xephi.authme.message.MessageKey;
|
|||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeService;
|
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -63,7 +63,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
@Mock
|
@Mock
|
||||||
private BungeeService bungeeService;
|
private BungeeSender bungeeSender;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initLogger() {
|
public static void initLogger() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user