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.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.mcstats.Metrics;
|
import org.mcstats.Metrics;
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
@ -109,6 +111,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
public boolean delayedAntiBot = true;
|
public boolean delayedAntiBot = true;
|
||||||
protected static String vgUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
protected static String vgUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||||
public DataManager dataManager;
|
public DataManager dataManager;
|
||||||
|
public ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<String, BukkitTask>();
|
||||||
|
|
||||||
public Settings getSettings() {
|
public Settings getSettings() {
|
||||||
return settings;
|
return settings;
|
||||||
|
|||||||
@ -441,18 +441,6 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
return;
|
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
|
// Check if forceSingleSession is set to true, so kick player that has
|
||||||
// joined with same nick of online player
|
// joined with same nick of online player
|
||||||
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
||||||
@ -589,7 +577,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String name = player.getName().toLowerCase();
|
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)
|
if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name) && Settings.enableProtection)
|
||||||
event.setQuitMessage(null);
|
event.setQuitMessage(null);
|
||||||
@ -611,7 +599,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.management.performQuit(player);
|
plugin.management.performQuit(player, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
|||||||
@ -16,8 +16,8 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @authors Xephi59, <a
|
* @authors Xephi59,
|
||||||
* href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
* <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Management {
|
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() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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;
|
package fr.xephi.authme.process.join;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
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.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.ProtectInventoryEvent;
|
import fr.xephi.authme.events.ProtectInventoryEvent;
|
||||||
import fr.xephi.authme.events.SessionEvent;
|
|
||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
||||||
@ -94,76 +91,6 @@ public class AsyncronousJoin {
|
|||||||
}
|
}
|
||||||
final Location spawnLoc = plugin.getSpawnLocation(player);
|
final Location spawnLoc = plugin.getSpawnLocation(player);
|
||||||
if (database.isAuthAvailable(name)) {
|
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) {
|
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
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));
|
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -147,16 +147,16 @@ public class AsyncronousLogin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.setNoDamageTicks(0);
|
player.setNoDamageTicks(0);
|
||||||
m.send(player, "login");
|
if (!forceLogin)
|
||||||
|
m.send(player, "login");
|
||||||
|
|
||||||
displayOtherAccounts(auth, player);
|
displayOtherAccounts(auth, player);
|
||||||
|
|
||||||
if (Settings.recallEmail) {
|
if (Settings.recallEmail) {
|
||||||
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com"))
|
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com"))
|
||||||
m.send(player, "add_email");
|
m.send(player, "add_email");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!Settings.noConsoleSpam)
|
if (!Settings.noConsoleSpam)
|
||||||
ConsoleLogger.info(player.getName() + " logged in!");
|
ConsoleLogger.info(player.getName() + " logged in!");
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.Utils;
|
||||||
import fr.xephi.authme.Utils.groupType;
|
import fr.xephi.authme.Utils.groupType;
|
||||||
|
import fr.xephi.authme.api.API;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.backup.FileCache;
|
import fr.xephi.authme.cache.backup.FileCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
@ -145,8 +146,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
|||||||
} else {
|
} else {
|
||||||
teleportBackFromSpawn();
|
teleportBackFromSpawn();
|
||||||
}
|
}
|
||||||
} else
|
} else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
|
||||||
if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
|
|
||||||
teleportToSpawn();
|
teleportToSpawn();
|
||||||
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
|
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
|
||||||
packQuitLocation();
|
packQuitLocation();
|
||||||
|
|||||||
@ -28,7 +28,8 @@ public class AsyncronousLogout {
|
|||||||
private Utils utils = Utils.getInstance();
|
private Utils utils = Utils.getInstance();
|
||||||
private FileCache playerBackup;
|
private FileCache playerBackup;
|
||||||
|
|
||||||
public AsyncronousLogout(Player player, AuthMe plugin, DataSource database) {
|
public AsyncronousLogout(Player player, AuthMe plugin,
|
||||||
|
DataSource database) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
@ -50,8 +51,6 @@ public class AsyncronousLogout {
|
|||||||
final Player p = player;
|
final Player p = player;
|
||||||
BukkitScheduler sched = p.getServer().getScheduler();
|
BukkitScheduler sched = p.getServer().getScheduler();
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||||
if (Settings.isSessionsEnabled)
|
|
||||||
auth.setLastLogin(0L);
|
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
auth.setQuitLocX(p.getLocation().getX());
|
auth.setQuitLocX(p.getLocation().getX());
|
||||||
auth.setQuitLocY(p.getLocation().getY());
|
auth.setQuitLocY(p.getLocation().getY());
|
||||||
|
|||||||
@ -32,6 +32,9 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (plugin.sessions.containsKey(name))
|
||||||
|
plugin.sessions.get(name).cancel();
|
||||||
|
plugin.sessions.remove(name);
|
||||||
int delay = Settings.getRegistrationTimeout * 20;
|
int delay = Settings.getRegistrationTimeout * 20;
|
||||||
int interval = Settings.getWarnMessageInterval;
|
int interval = Settings.getWarnMessageInterval;
|
||||||
BukkitScheduler sched = player.getServer().getScheduler();
|
BukkitScheduler sched = player.getServer().getScheduler();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.Utils;
|
||||||
@ -30,13 +31,16 @@ public class AsyncronousQuit {
|
|||||||
private boolean isOp = false;
|
private boolean isOp = false;
|
||||||
private boolean isFlying = false;
|
private boolean isFlying = false;
|
||||||
private boolean needToChange = 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.p = p;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.name = p.getName().toLowerCase();
|
this.name = p.getName().toLowerCase();
|
||||||
this.playerBackup = new FileCache(plugin);
|
this.playerBackup = new FileCache(plugin);
|
||||||
|
this.isKick = isKick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
@ -79,8 +83,23 @@ public class AsyncronousQuit {
|
|||||||
playerBackup.removeCache(player);
|
playerBackup.removeCache(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
if (Settings.isSessionsEnabled && !isKick) {
|
||||||
database.setUnlogged(name);
|
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);
|
AuthMePlayerListener.gameMode.remove(name);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange));
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user