Cancel autologin for AuthMe sessions (Fixes #189, #148, #103)

This commit is contained in:
games647
2018-02-05 15:01:28 +01:00
parent d0d5bd300b
commit e5e815a885
4 changed files with 58 additions and 11 deletions

View File

@ -1,10 +1,20 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.google.common.collect.Sets;
import fr.xephi.authme.api.v3.AuthMeApi; import fr.xephi.authme.api.v3.AuthMeApi;
import fr.xephi.authme.events.RestoreSessionEvent;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
/** /**
* Github: https://github.com/Xephi/AuthMeReloaded/ * Github: https://github.com/Xephi/AuthMeReloaded/
@ -15,12 +25,31 @@ import org.bukkit.entity.Player;
* <p> * <p>
* Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/ * Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/
*/ */
public class AuthMeHook implements AuthPlugin<Player> { public class AuthMeHook implements AuthPlugin<Player>, Listener {
private final Set<UUID> sessionLogins = Sets.newConcurrentHashSet();
private final FastLoginBukkit plugin;
public AuthMeHook(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onRestoreSession(RestoreSessionEvent restoreSessionEvent) {
UUID uniqueId = restoreSessionEvent.getPlayer().getUniqueId();
sessionLogins.add(uniqueId);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent quitEvent) {
UUID uniqueId = quitEvent.getPlayer().getUniqueId();
sessionLogins.remove(uniqueId);
}
@Override @Override
public boolean forceLogin(Player player) { public boolean forceLogin(Player player) {
//skips registration and login //skips registration and login
if (AuthMeApi.getInstance().isAuthenticated(player)) { if (AuthMeApi.getInstance().isAuthenticated(player) || sessionLogins.contains(player.getUniqueId())) {
return false; return false;
} else { } else {
AuthMeApi.getInstance().forceLogin(player); AuthMeApi.getInstance().forceLogin(player);
@ -38,7 +67,6 @@ public class AuthMeHook implements AuthPlugin<Player> {
public boolean forceRegister(Player player, String password) { public boolean forceRegister(Player player, String password) {
//this automatically registers the player too //this automatically registers the player too
AuthMeApi.getInstance().forceRegister(player, password); AuthMeApi.getInstance().forceRegister(player, password);
return true; return true;
} }
} }

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import de.st_ddt.crazylogin.CrazyLogin; import de.st_ddt.crazylogin.CrazyLogin;
@ -26,13 +27,19 @@ import org.bukkit.entity.Player;
*/ */
public class CrazyLoginHook implements AuthPlugin<Player> { public class CrazyLoginHook implements AuthPlugin<Player> {
private final FastLoginBukkit plugin;
private final CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin(); private final CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
private final PlayerListener playerListener = getListener(); private final PlayerListener playerListener = getListener();
public CrazyLoginHook(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@Override @Override
public boolean forceLogin(Player player) { public boolean forceLogin(Player player) {
//not thread-safe operation //not thread-safe operation
Future<Optional<LoginPlayerData>> future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin, () -> { Future<Optional<LoginPlayerData>> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player); LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player);
if (playerData != null) { if (playerData != null) {
//mark the account as logged in //mark the account as logged in
@ -71,7 +78,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
return true; return true;
} }
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
return false; return false;
} }
@ -105,7 +112,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
try { try {
listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true); listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true);
} catch (IllegalAccessException ex) { } catch (IllegalAccessException ex) {
crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex); plugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
listener = null; listener = null;
} }

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -23,11 +24,16 @@ import ultraauth.managers.PlayerManager;
public class UltraAuthHook implements AuthPlugin<Player> { public class UltraAuthHook implements AuthPlugin<Player> {
private final Plugin ultraAuthPlugin = Main.main; private final Plugin ultraAuthPlugin = Main.main;
private final FastLoginBukkit plugin;
public UltraAuthHook(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@Override @Override
public boolean forceLogin(Player player) { public boolean forceLogin(Player player) {
//not thread-safe //not thread-safe
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, () -> { Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
if (UltraAuthAPI.isAuthenticated(player)) { if (UltraAuthAPI.isAuthenticated(player)) {
return true; return true;
} }
@ -39,7 +45,7 @@ public class UltraAuthHook implements AuthPlugin<Player> {
try { try {
return future.get(); return future.get();
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
ultraAuthPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
return false; return false;
} }
} }

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit.hooks; package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuth;
@ -22,11 +23,16 @@ import org.bukkit.entity.Player;
public class xAuthHook implements AuthPlugin<Player> { public class xAuthHook implements AuthPlugin<Player> {
private final xAuth xAuthPlugin = xAuth.getPlugin(); private final xAuth xAuthPlugin = xAuth.getPlugin();
private final FastLoginBukkit plugin;
public xAuthHook(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@Override @Override
public boolean forceLogin(Player player) { public boolean forceLogin(Player player) {
//not thread-safe //not thread-safe
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> { Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
if (xAuthPlayer != null) { if (xAuthPlayer != null) {
if (xAuthPlayer.isAuthenticated()) { if (xAuthPlayer.isAuthenticated()) {
@ -46,7 +52,7 @@ public class xAuthHook implements AuthPlugin<Player> {
try { try {
return future.get(); return future.get();
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
xAuthPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
return false; return false;
} }
} }
@ -74,7 +80,7 @@ public class xAuthHook implements AuthPlugin<Player> {
//login in the player after registration //login in the player after registration
return future.get() && forceLogin(player); return future.get() && forceLogin(player);
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
xAuthPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
return false; return false;
} }
} }