mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-16 15:25:22 +01:00
'session expired' message spam fix
This commit is contained in:
parent
914c4adc0b
commit
5abc9b9d45
@ -45,11 +45,12 @@ public class SessionService implements Reloadable {
|
||||
database.setUnlogged(name);
|
||||
database.revokeSession(name);
|
||||
PlayerAuth auth = database.getAuth(name);
|
||||
if (hasValidSessionData(auth, player)) {
|
||||
SessionState state = hasValidSessionData(auth, player);
|
||||
if(state.equals(SessionState.VALID)) {
|
||||
RestoreSessionEvent event = bukkitService.createAndCallEvent(
|
||||
isAsync -> new RestoreSessionEvent(player, isAsync));
|
||||
return !event.isCancelled();
|
||||
} else {
|
||||
} else if(state.equals(SessionState.IP_CHANGED)) {
|
||||
service.send(player, MessageKey.SESSION_EXPIRED);
|
||||
}
|
||||
}
|
||||
@ -64,17 +65,24 @@ public class SessionService implements Reloadable {
|
||||
* @param player the associated player
|
||||
* @return true if the player may resume his login session, false otherwise
|
||||
*/
|
||||
private boolean hasValidSessionData(PlayerAuth auth, Player player) {
|
||||
private SessionState hasValidSessionData(PlayerAuth auth, Player player) {
|
||||
if (auth == null) {
|
||||
ConsoleLogger.warning("No PlayerAuth in database for '" + player.getName() + "' during session check");
|
||||
return false;
|
||||
return SessionState.NOT_VALID;
|
||||
} else if (auth.getLastLogin() == null) {
|
||||
return false;
|
||||
return SessionState.NOT_VALID;
|
||||
}
|
||||
long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin();
|
||||
return PlayerUtils.getPlayerIp(player).equals(auth.getLastIp())
|
||||
&& timeSinceLastLogin > 0
|
||||
&& timeSinceLastLogin < service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE;
|
||||
|
||||
if(timeSinceLastLogin > 0
|
||||
&& timeSinceLastLogin < service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE) {
|
||||
if(PlayerUtils.getPlayerIp(player).equals(auth.getLastIp())) {
|
||||
return SessionState.VALID;
|
||||
} else {
|
||||
return SessionState.IP_CHANGED;
|
||||
}
|
||||
}
|
||||
return SessionState.OUTDATED;
|
||||
}
|
||||
|
||||
public void grantSession(String name) {
|
||||
|
13
src/main/java/fr/xephi/authme/service/SessionState.java
Normal file
13
src/main/java/fr/xephi/authme/service/SessionState.java
Normal file
@ -0,0 +1,13 @@
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
public enum SessionState {
|
||||
|
||||
VALID,
|
||||
|
||||
NOT_VALID,
|
||||
|
||||
OUTDATED,
|
||||
|
||||
IP_CHANGED
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user