mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-25 01:57:48 +01:00
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:
parent
f45092bdd2
commit
e59df84a84
@ -32,7 +32,7 @@ public class SessionManager implements SettingsDependent, HasCleanup {
|
|||||||
* @param name The name to check.
|
* @param name The name to check.
|
||||||
* @return True if a session is found.
|
* @return True if a session is found.
|
||||||
*/
|
*/
|
||||||
public boolean hasSession(String name) {
|
private boolean hasSession(String name) {
|
||||||
return enabled && sessions.contains(name.toLowerCase());
|
return enabled && sessions.contains(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class SessionManager implements SettingsDependent, HasCleanup {
|
|||||||
*
|
*
|
||||||
* @param name The name of the player.
|
* @param name The name of the player.
|
||||||
*/
|
*/
|
||||||
public void addSession(String name) {
|
private void addSession(String name) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
sessions.add(name.toLowerCase());
|
sessions.add(name.toLowerCase());
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ public class SessionManager implements SettingsDependent, HasCleanup {
|
|||||||
*
|
*
|
||||||
* @param name The name of the player.
|
* @param name The name of the player.
|
||||||
*/
|
*/
|
||||||
public void removeSession(String name) {
|
private void removeSession(String name) {
|
||||||
sessions.remove(name.toLowerCase());
|
sessions.remove(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +195,7 @@ public class CacheDataSource implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogged(String user) {
|
public boolean isLogged(String user) {
|
||||||
return playerCache.isAuthenticated(user);
|
return source.isLogged(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fr.xephi.authme.process.join;
|
package fr.xephi.authme.process.join;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.SessionManager;
|
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
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.data.limbo.LimboService;
|
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.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
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.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.PlayerUtils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
@ -53,9 +53,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private LimboService limboService;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private SessionManager sessionManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PluginHookService pluginHookService;
|
private PluginHookService pluginHookService;
|
||||||
|
|
||||||
@ -174,17 +171,22 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
|
|
||||||
private boolean canResumeSession(Player player) {
|
private boolean canResumeSession(Player player) {
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
if (sessionManager.hasSession(name) || database.isLogged(name)) {
|
if (database.isLogged(name)) {
|
||||||
PlayerAuth auth = database.getAuth(name);
|
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
if (auth != null) {
|
if(service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
|
||||||
if (auth.getIp().equals(PlayerUtils.getPlayerIp(player))) {
|
PlayerAuth auth = database.getAuth(name);
|
||||||
RestoreSessionEvent event = bukkitService.createAndCallEvent(
|
if (auth != null) {
|
||||||
isAsync -> new RestoreSessionEvent(player, isAsync));
|
long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin();
|
||||||
return !event.isCancelled();
|
if(timeSinceLastLogin < 0
|
||||||
} else {
|
|| timeSinceLastLogin > (service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * 60 * 60 * 1000)
|
||||||
service.send(player, MessageKey.SESSION_EXPIRED);
|
|| !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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.xephi.authme.process.logout;
|
package fr.xephi.authme.process.logout;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
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.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.events.LogoutEvent;
|
import fr.xephi.authme.events.LogoutEvent;
|
||||||
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
||||||
@ -36,9 +36,6 @@ public class ProcessSyncPlayerLogout implements SynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private LimboService limboService;
|
private LimboService limboService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private SessionManager sessionManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private TeleportationService teleportationService;
|
private TeleportationService teleportationService;
|
||||||
|
|
||||||
@ -54,9 +51,6 @@ public class ProcessSyncPlayerLogout implements SynchronousProcess {
|
|||||||
* @param player the player logging out
|
* @param player the player logging out
|
||||||
*/
|
*/
|
||||||
public void processSyncLogout(Player player) {
|
public void processSyncLogout(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
|
||||||
|
|
||||||
sessionManager.removeSession(name);
|
|
||||||
if (service.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
if (service.getProperty(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||||
protocolLibService.sendBlankInventoryPacket(player);
|
protocolLibService.sendBlankInventoryPacket(player);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fr.xephi.authme.process.quit;
|
package fr.xephi.authme.process.quit;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.data.SessionManager;
|
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
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.CacheDataSource;
|
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.service.CommonService;
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
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.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.PlayerUtils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
@ -38,9 +38,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private SyncProcessManager syncProcessManager;
|
private SyncProcessManager syncProcessManager;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private SessionManager sessionManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SpawnLoader spawnLoader;
|
private SpawnLoader spawnLoader;
|
||||||
|
|
||||||
@ -79,19 +76,20 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
.lastLogin(System.currentTimeMillis())
|
.lastLogin(System.currentTimeMillis())
|
||||||
.build();
|
.build();
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
|
|
||||||
sessionManager.addSession(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
|
||||||
playerCache.removePlayer(name);
|
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)
|
||||||
database.setUnlogged(name);
|
if(!wasLoggedIn || !service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
|
||||||
|
database.setUnlogged(name);
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
syncProcessManager.processSyncPlayerQuit(player, wasLoggedIn);
|
syncProcessManager.processSyncPlayerQuit(player, wasLoggedIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove player from cache
|
// remove player from cache
|
||||||
if (database instanceof CacheDataSource) {
|
if (database instanceof CacheDataSource) {
|
||||||
((CacheDataSource) database).getCachedAuths().invalidate(name);
|
((CacheDataSource) database).getCachedAuths().invalidate(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user