mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 20:57:35 +01:00
IN DEVELOPPEMENT : Change how session work
This commit is contained in:
parent
d22607e8bd
commit
30e9610053
@ -15,6 +15,7 @@ import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@ -28,6 +29,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
@ -109,6 +111,7 @@ public class AuthMe extends JavaPlugin {
|
||||
public boolean delayedAntiBot = true;
|
||||
protected static String vgUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||
public DataManager dataManager;
|
||||
public ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<String, BukkitTask>();
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
|
@ -441,18 +441,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAuthAvailable && LimboCache.getInstance().hasLimboPlayer(name))
|
||||
if (Settings.isSessionsEnabled)
|
||||
if (PlayerCache.getInstance().isAuthenticated(name))
|
||||
if (!Settings.sessionExpireOnIpChange)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
});
|
||||
|
||||
// Check if forceSingleSession is set to true, so kick player that has
|
||||
// joined with same nick of online player
|
||||
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
||||
@ -589,7 +577,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
String name = player.getName().toLowerCase();
|
||||
|
||||
plugin.management.performQuit(player);
|
||||
plugin.management.performQuit(player, false);
|
||||
|
||||
if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name) && Settings.enableProtection)
|
||||
event.setQuitMessage(null);
|
||||
@ -611,7 +599,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.management.performQuit(player);
|
||||
plugin.management.performQuit(player, true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
@ -16,8 +16,8 @@ import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @authors Xephi59, <a
|
||||
* href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
||||
* @authors Xephi59,
|
||||
* <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
||||
*
|
||||
*/
|
||||
public class Management {
|
||||
@ -65,12 +65,12 @@ public class Management {
|
||||
});
|
||||
}
|
||||
|
||||
public void performQuit(final Player player) {
|
||||
public void performQuit(final Player player, final boolean isKick) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new AsyncronousQuit(player, plugin, database).process();
|
||||
new AsyncronousQuit(player, plugin, database, isKick).process();
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1,7 +1,5 @@
|
||||
package fr.xephi.authme.process.join;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -25,7 +23,6 @@ import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.ProtectInventoryEvent;
|
||||
import fr.xephi.authme.events.SessionEvent;
|
||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
||||
@ -94,76 +91,6 @@ public class AsyncronousJoin {
|
||||
}
|
||||
final Location spawnLoc = plugin.getSpawnLocation(player);
|
||||
if (database.isAuthAvailable(name)) {
|
||||
if (Settings.isSessionsEnabled) {
|
||||
PlayerAuth auth = database.getAuth(name);
|
||||
long timeout = Settings.getSessionTimeout * 60000;
|
||||
long lastLogin = auth.getLastLogin();
|
||||
long cur = new Date().getTime();
|
||||
if ((cur - lastLogin < timeout || timeout == 0) && !auth.getIp().matches("198.168.(0|1).1")) {
|
||||
if (auth.getNickname().equalsIgnoreCase(name) && auth.getIp().equals(ip)) {
|
||||
if (PlayerCache.getInstance().getAuth(name) != null) {
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
} else {
|
||||
PlayerCache.getInstance().addPlayer(auth);
|
||||
database.setLogged(name);
|
||||
}
|
||||
m.send(player, "valid_session");
|
||||
// Restore Permission Group
|
||||
utils.setGroup(player, Utils.groupType.LOGGEDIN);
|
||||
plugin.getServer().getPluginManager().callEvent(new SessionEvent(auth, true));
|
||||
return;
|
||||
} else if (!Settings.sessionExpireOnIpChange) {
|
||||
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.put(name, true);
|
||||
player.setGameMode(gM);
|
||||
AuthMePlayerListener.causeByAuthMe.put(name, false);
|
||||
player.kickPlayer(m.send("invalid_session")[0]);
|
||||
}
|
||||
|
||||
});
|
||||
return;
|
||||
} else if (auth.getNickname().equalsIgnoreCase(name)) {
|
||||
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.put(name, true);
|
||||
Utils.forceGM(player);
|
||||
AuthMePlayerListener.causeByAuthMe.put(name, false);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
// Player change his IP between 2 relog-in
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
} else {
|
||||
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.put(name, true);
|
||||
player.setGameMode(gM);
|
||||
AuthMePlayerListener.causeByAuthMe.put(name, false);
|
||||
player.kickPlayer(m.send("invalid_session")[0]);
|
||||
}
|
||||
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Session is ended correctly
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
}
|
||||
}
|
||||
// isent in session or session was ended correctly
|
||||
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@ -301,6 +228,23 @@ public class AsyncronousJoin {
|
||||
}
|
||||
|
||||
});
|
||||
if (Settings.isSessionsEnabled && database.isAuthAvailable(name) && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) {
|
||||
if (plugin.sessions.containsKey(name))
|
||||
plugin.sessions.get(name).cancel();
|
||||
plugin.sessions.remove(name);
|
||||
PlayerAuth auth = database.getAuth(name);
|
||||
if (auth != null && auth.getIp().equals(ip)) {
|
||||
m.send(player, "valid_session");
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
plugin.management.performLogin(player, "dontneed", true);
|
||||
} else if (Settings.sessionExpireOnIpChange) {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
m.send(player, "invalid_session");
|
||||
}
|
||||
return;
|
||||
}
|
||||
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
}
|
||||
|
@ -147,16 +147,16 @@ public class AsyncronousLogin {
|
||||
}
|
||||
|
||||
player.setNoDamageTicks(0);
|
||||
m.send(player, "login");
|
||||
if (!forceLogin)
|
||||
m.send(player, "login");
|
||||
|
||||
displayOtherAccounts(auth, player);
|
||||
|
||||
|
||||
if (Settings.recallEmail) {
|
||||
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com"))
|
||||
m.send(player, "add_email");
|
||||
}
|
||||
|
||||
|
||||
if (!Settings.noConsoleSpam)
|
||||
ConsoleLogger.info(player.getName() + " logged in!");
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.Utils.groupType;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.backup.FileCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
@ -145,8 +146,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
} else {
|
||||
teleportBackFromSpawn();
|
||||
}
|
||||
} else
|
||||
if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
|
||||
} else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
|
||||
teleportToSpawn();
|
||||
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
|
||||
packQuitLocation();
|
||||
|
@ -28,7 +28,8 @@ public class AsyncronousLogout {
|
||||
private Utils utils = Utils.getInstance();
|
||||
private FileCache playerBackup;
|
||||
|
||||
public AsyncronousLogout(Player player, AuthMe plugin, DataSource database) {
|
||||
public AsyncronousLogout(Player player, AuthMe plugin,
|
||||
DataSource database) {
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
@ -50,8 +51,6 @@ public class AsyncronousLogout {
|
||||
final Player p = player;
|
||||
BukkitScheduler sched = p.getServer().getScheduler();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
if (Settings.isSessionsEnabled)
|
||||
auth.setLastLogin(0L);
|
||||
database.updateSession(auth);
|
||||
auth.setQuitLocX(p.getLocation().getX());
|
||||
auth.setQuitLocY(p.getLocation().getY());
|
||||
|
@ -32,6 +32,9 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.sessions.containsKey(name))
|
||||
plugin.sessions.get(name).cancel();
|
||||
plugin.sessions.remove(name);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = player.getServer().getScheduler();
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
@ -30,13 +31,16 @@ public class AsyncronousQuit {
|
||||
private boolean isOp = false;
|
||||
private boolean isFlying = false;
|
||||
private boolean needToChange = false;
|
||||
private boolean isKick = false;
|
||||
|
||||
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database) {
|
||||
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
|
||||
boolean isKick) {
|
||||
this.p = p;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.name = p.getName().toLowerCase();
|
||||
this.playerBackup = new FileCache(plugin);
|
||||
this.isKick = isKick;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@ -79,8 +83,23 @@ public class AsyncronousQuit {
|
||||
playerBackup.removeCache(player);
|
||||
}
|
||||
}
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
if (Settings.isSessionsEnabled && !isKick) {
|
||||
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
if (database.isLogged(name))
|
||||
database.setUnlogged(name);
|
||||
plugin.sessions.remove(name);
|
||||
}
|
||||
|
||||
}, Settings.getSessionTimeout * 20 * 60);
|
||||
plugin.sessions.put(name, task);
|
||||
} else {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
}
|
||||
AuthMePlayerListener.gameMode.remove(name);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user