Implement bungee messaging, CacheDataSource sync

This commit is contained in:
Gabriele C
2017-10-30 10:38:13 +01:00
parent a5542051f4
commit 2d2eb740e3
21 changed files with 233 additions and 25 deletions
@@ -6,6 +6,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
@@ -28,6 +29,9 @@ public class AsyncChangePassword implements AsynchronousProcess {
@Inject
private PlayerCache playerCache;
@Inject
private BungeeService bungeeService;
AsyncChangePassword() {
}
@@ -49,6 +53,7 @@ public class AsyncChangePassword implements AsynchronousProcess {
commonService.send(player, MessageKey.ERROR);
return;
}
bungeeService.sendRefreshPassword(name);
playerCache.updatePlayer(auth);
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
@@ -78,6 +83,7 @@ public class AsyncChangePassword implements AsynchronousProcess {
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName);
if (dataSource.updatePassword(lowerCaseName, hashedPassword)) {
bungeeService.sendRefreshPassword(lowerCaseName);
if (sender != null) {
commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
ConsoleLogger.info(sender.getName() + " changed password of " + lowerCaseName);
@@ -6,6 +6,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.util.Utils;
@@ -30,6 +31,9 @@ public class AsyncAddEmail implements AsynchronousProcess {
@Inject
private ValidationService validationService;
@Inject
private BungeeService bungeeService;
AsyncAddEmail() { }
/**
@@ -55,6 +59,7 @@ public class AsyncAddEmail implements AsynchronousProcess {
auth.setEmail(email);
if (dataSource.updateEmail(auth)) {
playerCache.updatePlayer(auth);
bungeeService.sendRefreshEmail(playerName);
service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
} else {
ConsoleLogger.warning("Could not save email for player '" + player + "'");
@@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.entity.Player;
@@ -28,6 +29,9 @@ public class AsyncChangeEmail implements AsynchronousProcess {
@Inject
private ValidationService validationService;
@Inject
private BungeeService bungeeService;
AsyncChangeEmail() { }
/**
@@ -63,6 +67,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
auth.setEmail(newEmail);
if (dataSource.updateEmail(auth)) {
playerCache.updatePlayer(auth);
bungeeService.sendRefreshEmail(player.getName());
service.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
} else {
service.send(player, MessageKey.ERROR);
@@ -19,6 +19,7 @@ import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.SessionService;
import fr.xephi.authme.settings.properties.DatabaseSettings;
@@ -73,6 +74,9 @@ public class AsynchronousLogin implements AsynchronousProcess {
@Inject
private SessionService sessionService;
@Inject
private BungeeService bungeeService;
AsynchronousLogin() {
}
@@ -221,6 +225,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
auth.setLastLogin(System.currentTimeMillis());
auth.setLastIp(ip);
dataSource.updateSession(auth);
bungeeService.sendRefreshSession(player.getName());
// Successful login, so reset the captcha & temp ban count
final String name = player.getName();
@@ -246,6 +251,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
playerCache.updatePlayer(auth);
dataSource.setLogged(name);
sessionService.grantSession(name);
bungeeService.sendLogin(name);
// As the scheduling executes the Task most likely after the current
// task, we schedule it in the end
@@ -96,6 +96,6 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
commandManager.runCommandsOnLogin(player);
// Send Bungee stuff. The service will check if it is enabled or not.
bungeeService.connectPlayer(player);
bungeeService.connectPlayerOnLogin(player);
}
}
@@ -7,7 +7,9 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.SessionService;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
@@ -33,6 +35,12 @@ public class AsynchronousLogout implements AsynchronousProcess {
@Inject
private SyncProcessManager syncProcessManager;
@Inject
private SessionService sessionService;
@Inject
private BungeeService bungeeService;
AsynchronousLogout() {
}
@@ -50,15 +58,18 @@ public class AsynchronousLogout implements AsynchronousProcess {
PlayerAuth auth = playerCache.getAuth(name);
database.updateSession(auth);
bungeeService.sendRefreshSession(name);
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
auth.setQuitLocation(player.getLocation());
database.updateQuitLoc(auth);
bungeeService.sendRefreshQuitLoc(name);
}
playerCache.removePlayer(name);
codeManager.unverify(name);
database.setUnlogged(name);
database.revokeSession(name);
sessionService.revokeSession(name);
bungeeService.sendLogout(name);
syncProcessManager.processSyncPlayerLogout(player);
}
}
@@ -7,8 +7,10 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.CacheDataSource;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.service.SessionService;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -48,6 +50,12 @@ public class AsynchronousQuit implements AsynchronousProcess {
@Inject
private VerificationCodeManager codeManager;
@Inject
private SessionService sessionService;
@Inject
private BungeeService bungeeService;
AsynchronousQuit() {
}
@@ -70,6 +78,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
.name(name).location(loc)
.realName(player.getName()).build();
database.updateQuitLoc(auth);
bungeeService.sendRefreshQuitLoc(name);
}
final String ip = PlayerUtils.getPlayerIp(player);
@@ -80,6 +89,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
.lastLogin(System.currentTimeMillis())
.build();
database.updateSession(auth);
bungeeService.sendRefreshSession(name);
}
//always unauthenticate the player - use session only for auto logins on the same ip
@@ -90,7 +100,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
if (wasLoggedIn) {
database.setUnlogged(name);
if (!service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
database.revokeSession(name);
sessionService.revokeSession(name);
}
}
@@ -10,6 +10,7 @@ import fr.xephi.authme.process.AsynchronousProcess;
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.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -36,6 +37,8 @@ public class AsyncRegister implements AsynchronousProcess {
private PermissionsManager permissionsManager;
@Inject
private SingletonStore<RegistrationExecutor> registrationExecutorFactory;
@Inject
private BungeeService bungeeService;
AsyncRegister() {
}
@@ -84,6 +87,7 @@ public class AsyncRegister implements AsynchronousProcess {
PlayerAuth auth = executor.buildPlayerAuth(parameters);
if (database.saveAuth(auth)) {
executor.executePostPersistAction(parameters);
bungeeService.sendRegister(parameters.getPlayerName());
} else {
service.send(parameters.getPlayer(), MessageKey.ERROR);
}
@@ -72,6 +72,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
}
// Send Bungee stuff. The service will check if it is enabled or not.
bungeeService.connectPlayer(player);
bungeeService.connectPlayerOnLogin(player);
}
}
@@ -11,6 +11,7 @@ import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.TeleportationService;
import fr.xephi.authme.settings.commandconfig.CommandManager;
@@ -51,6 +52,9 @@ public class AsynchronousUnregister implements AsynchronousProcess {
@Inject
private CommandManager commandManager;
@Inject
private BungeeService bungeeService;
AsynchronousUnregister() {
}
@@ -104,6 +108,8 @@ public class AsynchronousUnregister implements AsynchronousProcess {
private void performUnregister(String name, Player player) {
playerCache.removePlayer(name);
bungeeService.sendUnregister(name);
if (player == null || !player.isOnline()) {
return;
}