mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 01:27:35 +01:00
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.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
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 DateFormat DATE_FORMAT = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||
private static Logger logger;
|
||||
private static boolean enableDebug = false;
|
||||
private static boolean useLogging = false;
|
||||
private static File logFile;
|
||||
private static FileWriter fileWriter;
|
||||
@ -40,7 +38,6 @@ public final class ConsoleLogger {
|
||||
|
||||
public static void setLoggingOptions(NewSetting settings) {
|
||||
ConsoleLogger.useLogging = settings.getProperty(SecuritySettings.USE_LOGGING);
|
||||
ConsoleLogger.enableDebug = !settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE);
|
||||
if (useLogging) {
|
||||
if (fileWriter == null) {
|
||||
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.
|
||||
*
|
||||
|
@ -51,10 +51,9 @@ public class SessionManager implements SettingsDependent {
|
||||
* @param name The name of the player who's session to cancel.
|
||||
*/
|
||||
public void cancelSession(String name) {
|
||||
BukkitTask task = sessions.get(name);
|
||||
BukkitTask task = sessions.remove(name);
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
removeSession(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.cache.auth;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -34,7 +33,6 @@ public class PlayerCache {
|
||||
* @param auth PlayerAuth
|
||||
*/
|
||||
public void addPlayer(PlayerAuth auth) {
|
||||
ConsoleLogger.debug("ADDED PLAYER TO CACHE " + auth.getNickname());
|
||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||
}
|
||||
|
||||
@ -44,7 +42,6 @@ public class PlayerCache {
|
||||
* @param auth PlayerAuth
|
||||
*/
|
||||
public void updatePlayer(PlayerAuth auth) {
|
||||
ConsoleLogger.debug("UPDATE PLAYER " + auth.getNickname());
|
||||
cache.put(auth.getNickname(), auth);
|
||||
}
|
||||
|
||||
@ -54,7 +51,6 @@ public class PlayerCache {
|
||||
* @param user String
|
||||
*/
|
||||
public void removePlayer(String user) {
|
||||
ConsoleLogger.debug("REMOVE PLAYER " + user);
|
||||
cache.remove(user.toLowerCase());
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,6 @@ public class CacheDataSource implements DataSource {
|
||||
return executorService.submit(new Callable<Optional<PlayerAuth>>() {
|
||||
@Override
|
||||
public Optional<PlayerAuth> call() {
|
||||
ConsoleLogger.debug("REFRESH " + key);
|
||||
return load(key);
|
||||
}
|
||||
});
|
||||
|
@ -28,9 +28,6 @@ public class BungeeCordMessage implements PluginMessageListener {
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private SessionManager sessionManager;
|
||||
|
||||
@Inject
|
||||
private NewSetting settings;
|
||||
@ -60,11 +57,6 @@ public class BungeeCordMessage implements PluginMessageListener {
|
||||
if ("login".equals(act)) {
|
||||
playerCache.updatePlayer(auth);
|
||||
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)) {
|
||||
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)) {
|
||||
playerCache.removePlayer(name);
|
||||
dataSource.setUnlogged(name);
|
||||
|
||||
if (!settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||
ConsoleLogger.info("Player " + auth.getNickname() + " has logged out from one of your server!");
|
||||
}
|
||||
|
@ -142,10 +142,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
}
|
||||
|
||||
// Session logic
|
||||
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (playerCache.isAuthenticated(name) || database.isLogged(name))) {
|
||||
if (sessionManager.hasSession(name)) {
|
||||
sessionManager.cancelSession(name);
|
||||
}
|
||||
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (sessionManager.hasSession(name) || database.isLogged(name))) {
|
||||
sessionManager.cancelSession(name);
|
||||
|
||||
PlayerAuth auth = database.getAuth(name);
|
||||
database.setUnlogged(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.ProcessService;
|
||||
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.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
@ -86,27 +86,29 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
||||
isOp = limbo.isOperator();
|
||||
limboCache.deleteLimboPlayer(name);
|
||||
}
|
||||
if (!isKick) {
|
||||
if (plugin.isEnabled()) {
|
||||
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
postLogout(name);
|
||||
}
|
||||
//always unauthenticate the player - use session only for auto logins on the same ip
|
||||
playerCache.removePlayer(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);
|
||||
} else {
|
||||
//plugin is disabled; we cannot schedule more tasks so run it directly here
|
||||
postLogout(name);
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
postLogout(name);
|
||||
}
|
||||
|
||||
}, service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * TICKS_PER_MINUTE);
|
||||
|
||||
sessionManager.addSession(name, task);
|
||||
} else {
|
||||
playerCache.removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
//plugin is disabled; we cannot schedule more tasks so run it directly here
|
||||
postLogout(name);
|
||||
}
|
||||
|
||||
//always update the database when the player quit the game
|
||||
database.setUnlogged(name);
|
||||
|
||||
if (plugin.isEnabled()) {
|
||||
syncProcessManager.processSyncPlayerQuit(player, isOp, needToChange);
|
||||
}
|
||||
@ -117,8 +119,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
||||
}
|
||||
|
||||
private void postLogout(String name) {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
sessionManager.removeSession(name);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user