'session expired' message spam fix

This commit is contained in:
HexelDev 2018-03-04 18:36:21 +01:00
parent 914c4adc0b
commit 5abc9b9d45
2 changed files with 29 additions and 8 deletions

View File

@ -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) {

View File

@ -0,0 +1,13 @@
package fr.xephi.authme.service;
public enum SessionState {
VALID,
NOT_VALID,
OUTDATED,
IP_CHANGED
}