Merge branch 'master' of https://github.com/AuthMe/AuthMeReloaded into 792-registration-date-and-ip

Conflicts:
	src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java
	src/main/java/fr/xephi/authme/datasource/Columns.java
	src/main/java/fr/xephi/authme/datasource/SQLite.java
	src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java
	src/main/java/fr/xephi/authme/service/SessionService.java
	src/main/java/fr/xephi/authme/settings/properties/DatabaseSettings.java
	src/test/java/fr/xephi/authme/service/SessionServiceTest.java
	src/test/resources/fr/xephi/authme/datasource/sql-initialize.sql
This commit is contained in:
ljacqu
2017-10-15 23:38:01 +02:00
19 changed files with 536 additions and 97 deletions
@@ -1,12 +1,9 @@
package fr.xephi.authme.process.join;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.RestoreSessionEvent;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.AsynchronousProcess;
@@ -14,11 +11,11 @@ import fr.xephi.authme.process.login.AsynchronousLogin;
import fr.xephi.authme.service.BukkitService;
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.settings.WelcomeMessageConfiguration;
import fr.xephi.authme.settings.commandconfig.CommandManager;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.PlayerUtils;
@@ -48,9 +45,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject
private CommonService service;
@Inject
private PlayerCache playerCache;
@Inject
private LimboService limboService;
@@ -72,6 +66,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject
private WelcomeMessageConfiguration welcomeMessageConfiguration;
@Inject
private SessionService sessionService;
AsynchronousJoin() {
}
@@ -121,7 +118,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
}
// Session logic
if (canResumeSession(player)) {
if (sessionService.canResumeSession(player)) {
service.send(player, MessageKey.SESSION_RECONNECTION);
// Run commands
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(
@@ -177,32 +174,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
});
}
// TODO #792: lastlogin date might be null (not updating now because of has_session branch changes)
private boolean canResumeSession(Player player) {
final String name = player.getName();
if (database.isLogged(name)) {
database.setUnlogged(name);
playerCache.removePlayer(name);
if(service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
PlayerAuth auth = database.getAuth(name);
if (auth != null) {
long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin();
if(timeSinceLastLogin < 0
|| timeSinceLastLogin > (service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * 60 * 1000)
|| !auth.getLastIp().equals(PlayerUtils.getPlayerIp(player))) {
service.send(player, MessageKey.SESSION_EXPIRED);
} else {
RestoreSessionEvent event = bukkitService.createAndCallEvent(
isAsync -> new RestoreSessionEvent(player, isAsync));
return !event.isCancelled();
}
}
}
}
return false;
}
/**
* Checks whether the maximum number of accounts has been exceeded for the given IP address (according to
* settings and permissions). If this is the case, the player is kicked.
@@ -20,6 +20,7 @@ import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.SessionService;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
@@ -69,6 +70,9 @@ public class AsynchronousLogin implements AsynchronousProcess {
@Inject
private EmailService emailService;
@Inject
private SessionService sessionService;
AsynchronousLogin() {
}
@@ -238,9 +242,10 @@ public class AsynchronousLogin implements AsynchronousProcess {
ConsoleLogger.fine(player.getName() + " logged in!");
// makes player isLoggedin via API
// makes player loggedin
playerCache.updatePlayer(auth);
dataSource.setLogged(name);
sessionService.grantSession(name);
// As the scheduling executes the Task most likely after the current
// task, we schedule it in the end
@@ -53,6 +53,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
playerCache.removePlayer(name);
database.setUnlogged(name);
database.revokeSession(name);
syncProcessManager.processSyncPlayerLogout(player);
}
}
@@ -82,8 +82,11 @@ public class AsynchronousQuit implements AsynchronousProcess {
playerCache.removePlayer(name);
//always update the database when the player quit the game (if sessions are disabled)
if(!wasLoggedIn || !service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
if (wasLoggedIn) {
database.setUnlogged(name);
if (!service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
database.revokeSession(name);
}
}
if (plugin.isEnabled()) {