Merge pull request #142 from AuthMe-Team/random-logout
Fix random logout
This commit is contained in:
commit
cca668a2dd
@ -11,7 +11,6 @@ import java.io.IOException;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +21,6 @@ public final class ConsoleLogger {
|
|||||||
private static final String NEW_LINE = System.getProperty("line.separator");
|
private static final String NEW_LINE = System.getProperty("line.separator");
|
||||||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||||
private static Logger logger;
|
private static Logger logger;
|
||||||
private static boolean enableDebug = false;
|
|
||||||
private static boolean useLogging = false;
|
private static boolean useLogging = false;
|
||||||
private static File logFile;
|
private static File logFile;
|
||||||
private static FileWriter fileWriter;
|
private static FileWriter fileWriter;
|
||||||
@ -40,7 +38,6 @@ public final class ConsoleLogger {
|
|||||||
|
|
||||||
public static void setLoggingOptions(NewSetting settings) {
|
public static void setLoggingOptions(NewSetting settings) {
|
||||||
ConsoleLogger.useLogging = settings.getProperty(SecuritySettings.USE_LOGGING);
|
ConsoleLogger.useLogging = settings.getProperty(SecuritySettings.USE_LOGGING);
|
||||||
ConsoleLogger.enableDebug = !settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE);
|
|
||||||
if (useLogging) {
|
if (useLogging) {
|
||||||
if (fileWriter == null) {
|
if (fileWriter == null) {
|
||||||
try {
|
try {
|
||||||
@ -67,19 +64,6 @@ public final class ConsoleLogger {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String message) {
|
|
||||||
if (enableDebug) {
|
|
||||||
//creating and filling an exception is a expensive call
|
|
||||||
//TODO #419 20160601: ->so it should be removed as soon #419 is fixed
|
|
||||||
//logger.isLoggable does not work because the plugin logger is always ALL
|
|
||||||
logger.log(Level.FINE, message + ' ' + Thread.currentThread().getName(), new Exception());
|
|
||||||
|
|
||||||
if (useLogging) {
|
|
||||||
writeLog("Debug: " + Thread.currentThread().getName() + ':' + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print an error message.
|
* Print an error message.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.cache.auth;
|
package fr.xephi.authme.cache.auth;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -34,7 +33,6 @@ public class PlayerCache {
|
|||||||
* @param auth PlayerAuth
|
* @param auth PlayerAuth
|
||||||
*/
|
*/
|
||||||
public void addPlayer(PlayerAuth auth) {
|
public void addPlayer(PlayerAuth auth) {
|
||||||
ConsoleLogger.debug("ADDED PLAYER TO CACHE " + auth.getNickname());
|
|
||||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +42,6 @@ public class PlayerCache {
|
|||||||
* @param auth PlayerAuth
|
* @param auth PlayerAuth
|
||||||
*/
|
*/
|
||||||
public void updatePlayer(PlayerAuth auth) {
|
public void updatePlayer(PlayerAuth auth) {
|
||||||
ConsoleLogger.debug("UPDATE PLAYER " + auth.getNickname());
|
|
||||||
cache.put(auth.getNickname(), auth);
|
cache.put(auth.getNickname(), auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +51,6 @@ public class PlayerCache {
|
|||||||
* @param user String
|
* @param user String
|
||||||
*/
|
*/
|
||||||
public void removePlayer(String user) {
|
public void removePlayer(String user) {
|
||||||
ConsoleLogger.debug("REMOVE PLAYER " + user);
|
|
||||||
cache.remove(user.toLowerCase());
|
cache.remove(user.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,6 @@ public class CacheDataSource implements DataSource {
|
|||||||
return executorService.submit(new Callable<Optional<PlayerAuth>>() {
|
return executorService.submit(new Callable<Optional<PlayerAuth>>() {
|
||||||
@Override
|
@Override
|
||||||
public Optional<PlayerAuth> call() {
|
public Optional<PlayerAuth> call() {
|
||||||
ConsoleLogger.debug("REFRESH " + key);
|
|
||||||
return load(key);
|
return load(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,9 +28,6 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private SessionManager sessionManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private NewSetting settings;
|
private NewSetting settings;
|
||||||
@ -60,11 +57,6 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
if ("login".equals(act)) {
|
if ("login".equals(act)) {
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
dataSource.setLogged(name);
|
dataSource.setLogged(name);
|
||||||
//START 03062016 sgdc3: should fix #731 but we need to recode this mess
|
|
||||||
if (sessionManager.hasSession(name)) {
|
|
||||||
sessionManager.cancelSession(name);
|
|
||||||
}
|
|
||||||
//END
|
|
||||||
|
|
||||||
if (!settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
if (!settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||||
ConsoleLogger.info("Player " + auth.getNickname() + " has logged in from one of your server!");
|
ConsoleLogger.info("Player " + auth.getNickname() + " has logged in from one of your server!");
|
||||||
@ -72,6 +64,7 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
} else if ("logout".equals(act)) {
|
} else if ("logout".equals(act)) {
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
dataSource.setUnlogged(name);
|
dataSource.setUnlogged(name);
|
||||||
|
|
||||||
if (!settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
if (!settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||||
ConsoleLogger.info("Player " + auth.getNickname() + " has logged out from one of your server!");
|
ConsoleLogger.info("Player " + auth.getNickname() + " has logged out from one of your server!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
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.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
@ -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() && service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
|
||||||
|
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);
|
}
|
||||||
}
|
|
||||||
|
}, service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * 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