Fix session system (#1337)

* Old session system

* Actually check if sessions are enabled

* Cleanup

* Don't use cached isLogged value
This commit is contained in:
Gabriele C 2017-09-30 15:15:25 +02:00 committed by GitHub
parent f45092bdd2
commit e59df84a84
6 changed files with 26 additions and 32 deletions

View File

@ -32,7 +32,7 @@ public class SessionManager implements SettingsDependent, HasCleanup {
* @param name The name to check.
* @return True if a session is found.
*/
public boolean hasSession(String name) {
private boolean hasSession(String name) {
return enabled && sessions.contains(name.toLowerCase());
}
@ -41,7 +41,7 @@ public class SessionManager implements SettingsDependent, HasCleanup {
*
* @param name The name of the player.
*/
public void addSession(String name) {
private void addSession(String name) {
if (enabled) {
sessions.add(name.toLowerCase());
}
@ -52,7 +52,7 @@ public class SessionManager implements SettingsDependent, HasCleanup {
*
* @param name The name of the player.
*/
public void removeSession(String name) {
private void removeSession(String name) {
sessions.remove(name.toLowerCase());
}

View File

@ -195,7 +195,7 @@ public class CacheDataSource implements DataSource {
@Override
public boolean isLogged(String user) {
return playerCache.isAuthenticated(user);
return source.isLogged(user);
}
@Override

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.process.join;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.SessionManager;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboService;
@ -18,6 +17,7 @@ import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.service.ValidationService;
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;
@ -53,9 +53,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
@Inject
private LimboService limboService;
@Inject
private SessionManager sessionManager;
@Inject
private PluginHookService pluginHookService;
@ -174,17 +171,22 @@ public class AsynchronousJoin implements AsynchronousProcess {
private boolean canResumeSession(Player player) {
final String name = player.getName();
if (sessionManager.hasSession(name) || database.isLogged(name)) {
PlayerAuth auth = database.getAuth(name);
if (database.isLogged(name)) {
database.setUnlogged(name);
playerCache.removePlayer(name);
if(service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
PlayerAuth auth = database.getAuth(name);
if (auth != null) {
if (auth.getIp().equals(PlayerUtils.getPlayerIp(player))) {
long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin();
if(timeSinceLastLogin < 0
|| timeSinceLastLogin > (service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * 60 * 60 * 1000)
|| !auth.getIp().equals(PlayerUtils.getPlayerIp(player))) {
service.send(player, MessageKey.SESSION_EXPIRED);
} else {
RestoreSessionEvent event = bukkitService.createAndCallEvent(
isAsync -> new RestoreSessionEvent(player, isAsync));
return !event.isCancelled();
} else {
service.send(player, MessageKey.SESSION_EXPIRED);
}
}
}
}

View File

@ -1,7 +1,7 @@
package fr.xephi.authme.process.logout;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.SessionManager;
//import fr.xephi.authme.data.SessionManager;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.events.LogoutEvent;
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
@ -36,9 +36,6 @@ public class ProcessSyncPlayerLogout implements SynchronousProcess {
@Inject
private LimboService limboService;
@Inject
private SessionManager sessionManager;
@Inject
private TeleportationService teleportationService;
@ -54,9 +51,6 @@ public class ProcessSyncPlayerLogout implements SynchronousProcess {
* @param player the player logging out
*/
public void processSyncLogout(Player player) {
final String name = player.getName().toLowerCase();
sessionManager.removeSession(name);
if (service.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
protocolLibService.sendBlankInventoryPacket(player);
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.process.quit;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.data.SessionManager;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.CacheDataSource;
@ -10,6 +9,7 @@ import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.service.ValidationService;
@ -38,9 +38,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
@Inject
private SyncProcessManager syncProcessManager;
@Inject
private SessionManager sessionManager;
@Inject
private SpawnLoader spawnLoader;
@ -79,19 +76,20 @@ public class AsynchronousQuit implements AsynchronousProcess {
.lastLogin(System.currentTimeMillis())
.build();
database.updateSession(auth);
sessionManager.addSession(name);
}
//always unauthenticate the player - use session only for auto logins on the same ip
playerCache.removePlayer(name);
//always update the database when the player quit the game
//always update the database when the player quit the game (if sessions are disabled)
if(!wasLoggedIn || !service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
database.setUnlogged(name);
}
if (plugin.isEnabled()) {
syncProcessManager.processSyncPlayerQuit(player, wasLoggedIn);
}
// remove player from cache
if (database instanceof CacheDataSource) {
((CacheDataSource) database).getCachedAuths().invalidate(name);