Refactor sessions a bit to fix #419
This commit is contained in:
parent
874869cef8
commit
469e8d3a48
@ -51,10 +51,9 @@ public class SessionManager implements SettingsDependent {
|
|||||||
* @param name The name of the player who's session to cancel.
|
* @param name The name of the player who's session to cancel.
|
||||||
*/
|
*/
|
||||||
public void cancelSession(String name) {
|
public void cancelSession(String name) {
|
||||||
BukkitTask task = sessions.get(name);
|
BukkitTask task = sessions.remove(name);
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
task.cancel();
|
task.cancel();
|
||||||
removeSession(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -142,10 +142,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Session logic
|
// Session logic
|
||||||
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (playerCache.isAuthenticated(name) || database.isLogged(name))) {
|
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (sessionManager.hasSession(name) || database.isLogged(name))) {
|
||||||
if (sessionManager.hasSession(name)) {
|
sessionManager.cancelSession(name);
|
||||||
sessionManager.cancelSession(name);
|
|
||||||
}
|
|
||||||
PlayerAuth auth = database.getAuth(name);
|
PlayerAuth auth = database.getAuth(name);
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
|
|||||||
@ -86,27 +86,29 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
isOp = limbo.isOperator();
|
isOp = limbo.isOperator();
|
||||||
limboCache.deleteLimboPlayer(name);
|
limboCache.deleteLimboPlayer(name);
|
||||||
}
|
}
|
||||||
if (!isKick) {
|
|
||||||
if (plugin.isEnabled()) {
|
|
||||||
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
//always unauthenticate the player - use session only for auto logins on the same ip
|
||||||
public void run() {
|
playerCache.removePlayer(name);
|
||||||
postLogout(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}, Settings.getSessionTimeout * TICKS_PER_MINUTE);
|
if (plugin.isEnabled() && Settings.isSessionsEnabled) {
|
||||||
|
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
sessionManager.addSession(name, task);
|
@Override
|
||||||
} else {
|
public void run() {
|
||||||
//plugin is disabled; we cannot schedule more tasks so run it directly here
|
postLogout(name);
|
||||||
postLogout(name);
|
}
|
||||||
}
|
|
||||||
|
}, Settings.getSessionTimeout * TICKS_PER_MINUTE);
|
||||||
|
|
||||||
|
sessionManager.addSession(name, task);
|
||||||
} else {
|
} else {
|
||||||
playerCache.removePlayer(name);
|
//plugin is disabled; we cannot schedule more tasks so run it directly here
|
||||||
database.setUnlogged(name);
|
postLogout(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//always update the database when the player quit the game
|
||||||
|
database.setUnlogged(name);
|
||||||
|
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
syncProcessManager.processSyncPlayerQuit(player, isOp, needToChange);
|
syncProcessManager.processSyncPlayerQuit(player, isOp, needToChange);
|
||||||
}
|
}
|
||||||
@ -117,8 +119,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void postLogout(String name) {
|
private void postLogout(String name) {
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
|
||||||
database.setUnlogged(name);
|
|
||||||
sessionManager.removeSession(name);
|
sessionManager.removeSession(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user