mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-31 11:17:33 +02:00
Try to upgrade to Java 8. I hope enough people are using it.
This commit is contained in:
@ -120,9 +120,9 @@ public class FastLoginBukkit extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//remove old blacklists
|
//remove old blacklists
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
getServer().getOnlinePlayers().forEach(player -> {
|
||||||
player.removeMetadata(getName(), this);
|
player.removeMetadata(getName(), this);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitCore getCore() {
|
public BukkitCore getCore() {
|
||||||
|
@ -42,11 +42,8 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(plugin.getCore().getMessage("remove-premium"));
|
sender.sendMessage(plugin.getCore().getMessage("remove-premium"));
|
||||||
profile.setPremium(false);
|
profile.setPremium(false);
|
||||||
profile.setUuid(null);
|
profile.setUuid(null);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
plugin.getCore().getStorage().save(profile);
|
||||||
public void run() {
|
|
||||||
plugin.getCore().getStorage().save(profile);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(plugin.getCore().getMessage("not-premium"));
|
sender.sendMessage(plugin.getCore().getMessage("not-premium"));
|
||||||
@ -87,11 +84,8 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
sender.sendMessage(plugin.getCore().getMessage("remove-premium"));
|
sender.sendMessage(plugin.getCore().getMessage("remove-premium"));
|
||||||
profile.setPremium(false);
|
profile.setPremium(false);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
plugin.getCore().getStorage().save(profile);
|
||||||
public void run() {
|
|
||||||
plugin.getCore().getStorage().save(profile);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,8 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
//todo: resolve uuid
|
//todo: resolve uuid
|
||||||
profile.setPremium(true);
|
profile.setPremium(true);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
plugin.getCore().getStorage().save(profile);
|
||||||
public void run() {
|
|
||||||
plugin.getCore().getStorage().save(profile);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
sender.sendMessage(plugin.getCore().getMessage("add-premium"));
|
sender.sendMessage(plugin.getCore().getMessage("add-premium"));
|
||||||
@ -103,11 +100,8 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
//todo: resolve uuid
|
//todo: resolve uuid
|
||||||
profile.setPremium(true);
|
profile.setPremium(true);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
plugin.getCore().getStorage().save(profile);
|
||||||
public void run() {
|
|
||||||
plugin.getCore().getStorage().save(profile);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
sender.sendMessage(plugin.getCore().getMessage("add-premium-other"));
|
sender.sendMessage(plugin.getCore().getMessage("add-premium-other"));
|
||||||
|
@ -8,7 +8,6 @@ import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase;
|
|||||||
import de.st_ddt.crazylogin.listener.PlayerListener;
|
import de.st_ddt.crazylogin.listener.PlayerListener;
|
||||||
import de.st_ddt.crazylogin.metadata.Authenticated;
|
import de.st_ddt.crazylogin.metadata.Authenticated;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -32,39 +31,35 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(final Player player) {
|
public boolean forceLogin(final Player player) {
|
||||||
//not thread-safe operation
|
//not thread-safe operation
|
||||||
Future<LoginPlayerData> future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin
|
Future<LoginPlayerData> future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin, () -> {
|
||||||
, new Callable<LoginPlayerData>() {
|
LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
|
||||||
@Override
|
if (playerData != null) {
|
||||||
public LoginPlayerData call() throws Exception {
|
//mark the account as logged in
|
||||||
LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
|
playerData.setLoggedIn(true);
|
||||||
if (playerData != null) {
|
|
||||||
//mark the account as logged in
|
|
||||||
playerData.setLoggedIn(true);
|
|
||||||
|
|
||||||
String ip = player.getAddress().getAddress().getHostAddress();
|
String ip = player.getAddress().getAddress().getHostAddress();
|
||||||
//this should be done after login to restore the inventory, unhide players, prevent potential memory leaks...
|
//this should be done after login to restore the inventory, unhide players, prevent potential memory leaks...
|
||||||
//from: https://github.com/ST-DDT/CrazyLogin/blob/master/src/main/java/de/st_ddt/crazylogin/CrazyLogin.java#L1948
|
//from: https://github.com/ST-DDT/CrazyLogin/blob/master/src/main/java/de/st_ddt/crazylogin/CrazyLogin.java#L1948
|
||||||
playerData.resetLoginFails();
|
playerData.resetLoginFails();
|
||||||
player.setFireTicks(0);
|
player.setFireTicks(0);
|
||||||
|
|
||||||
if (playerListener != null) {
|
if (playerListener != null) {
|
||||||
playerListener.removeMovementBlocker(player);
|
playerListener.removeMovementBlocker(player);
|
||||||
playerListener.disableHidenInventory(player);
|
playerListener.disableHidenInventory(player);
|
||||||
playerListener.disableSaveLogin(player);
|
playerListener.disableSaveLogin(player);
|
||||||
playerListener.unhidePlayer(player);
|
playerListener.unhidePlayer(player);
|
||||||
}
|
|
||||||
|
|
||||||
//loginFailuresPerIP.remove(IP);
|
|
||||||
//illegalCommandUsesPerIP.remove(IP);
|
|
||||||
//tempBans.remove(IP);
|
|
||||||
playerData.addIP(ip);
|
|
||||||
player.setMetadata("Authenticated", new Authenticated(crazyLoginPlugin, player));
|
|
||||||
crazyLoginPlugin.unregisterDynamicHooks();
|
|
||||||
return playerData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
//loginFailuresPerIP.remove(IP);
|
||||||
|
//illegalCommandUsesPerIP.remove(IP);
|
||||||
|
//tempBans.remove(IP);
|
||||||
|
playerData.addIP(ip);
|
||||||
|
player.setMetadata("Authenticated", new Authenticated(crazyLoginPlugin, player));
|
||||||
|
crazyLoginPlugin.unregisterDynamicHooks();
|
||||||
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -110,7 +105,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
|
|||||||
PlayerListener listener;
|
PlayerListener listener;
|
||||||
try {
|
try {
|
||||||
listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true);
|
listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true);
|
||||||
} catch (Exception ex) {
|
} catch (IllegalAccessException ex) {
|
||||||
crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
|
crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
|
||||||
listener = null;
|
listener = null;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks;
|
|||||||
|
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -27,17 +26,14 @@ public class RoyalAuthHook implements AuthPlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(final Player player) {
|
public boolean forceLogin(final Player player) {
|
||||||
//not thread-safe
|
//not thread-safe
|
||||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(royalAuthPlugin, new Callable<Boolean>() {
|
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(royalAuthPlugin, () -> {
|
||||||
@Override
|
AuthPlayer authPlayer = AuthPlayer.getAuthPlayer(player);
|
||||||
public Boolean call() throws Exception {
|
|
||||||
AuthPlayer authPlayer = AuthPlayer.getAuthPlayer(player);
|
|
||||||
|
|
||||||
//https://github.com/RoyalDev/RoyalAuth/blob/master/src/main/java/org/royaldev/royalauth/commands/CmdLogin.java#L62
|
//https://github.com/RoyalDev/RoyalAuth/blob/master/src/main/java/org/royaldev/royalauth/commands/CmdLogin.java#L62
|
||||||
//not thread-safe
|
//not thread-safe
|
||||||
authPlayer.login();
|
authPlayer.login();
|
||||||
|
|
||||||
return authPlayer.isLoggedIn();
|
return authPlayer.isLoggedIn();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks;
|
|||||||
|
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -28,12 +27,9 @@ public class UltraAuthHook implements AuthPlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(final Player player) {
|
public boolean forceLogin(final Player player) {
|
||||||
//not thread-safe
|
//not thread-safe
|
||||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, new Callable<Boolean>() {
|
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, () -> {
|
||||||
@Override
|
UltraAuthAPI.authenticatedPlayer(player);
|
||||||
public Boolean call() throws Exception {
|
return UltraAuthAPI.isAuthenticated(player);
|
||||||
UltraAuthAPI.authenticatedPlayer(player);
|
|
||||||
return UltraAuthAPI.isAuthenticated(player);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -5,7 +5,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
|||||||
import de.luricos.bukkit.xAuth.xAuth;
|
import de.luricos.bukkit.xAuth.xAuth;
|
||||||
import de.luricos.bukkit.xAuth.xAuthPlayer;
|
import de.luricos.bukkit.xAuth.xAuthPlayer;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -28,20 +27,17 @@ public class xAuthHook implements AuthPlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(final Player player) {
|
public boolean forceLogin(final Player player) {
|
||||||
//not thread-safe
|
//not thread-safe
|
||||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, new Callable<Boolean>() {
|
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> {
|
||||||
@Override
|
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
|
||||||
public Boolean call() throws Exception {
|
if (xAuthPlayer != null) {
|
||||||
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
|
//we checked that the player is premium (paid account)
|
||||||
if (xAuthPlayer != null) {
|
xAuthPlayer.setPremium(true);
|
||||||
//we checked that the player is premium (paid account)
|
|
||||||
xAuthPlayer.setPremium(true);
|
|
||||||
|
|
||||||
//unprotect the inventory, op status...
|
//unprotect the inventory, op status...
|
||||||
return xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer);
|
return xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer);
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -62,21 +58,18 @@ public class xAuthHook implements AuthPlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean forceRegister(final Player player, final String password) {
|
public boolean forceRegister(final Player player, final String password) {
|
||||||
//not thread-safe
|
//not thread-safe
|
||||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, new Callable<Boolean>() {
|
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> {
|
||||||
@Override
|
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
|
||||||
public Boolean call() throws Exception {
|
if (xAuthPlayer != null) {
|
||||||
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
|
//this should run async because the plugin executes a sql query, but the method
|
||||||
if (xAuthPlayer != null) {
|
//accesses non thread-safe collections :(
|
||||||
//this should run async because the plugin executes a sql query, but the method
|
boolean registerSuccess = xAuthPlugin.getAuthClass(xAuthPlayer)
|
||||||
//accesses non thread-safe collections :(
|
.adminRegister(player.getName(), password, null);
|
||||||
boolean registerSuccess = xAuthPlugin.getAuthClass(xAuthPlayer)
|
|
||||||
.adminRegister(player.getName(), password, null);
|
|
||||||
|
|
||||||
return registerSuccess;
|
return registerSuccess;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -21,7 +21,7 @@ public class BukkitJoinListener implements Listener {
|
|||||||
|
|
||||||
private static final long DELAY_LOGIN = 20L / 2;
|
private static final long DELAY_LOGIN = 20L / 2;
|
||||||
|
|
||||||
protected final FastLoginBukkit plugin;
|
private final FastLoginBukkit plugin;
|
||||||
|
|
||||||
public BukkitJoinListener(FastLoginBukkit plugin) {
|
public BukkitJoinListener(FastLoginBukkit plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -52,10 +52,10 @@ public class BungeeCordListener implements PluginMessageListener {
|
|||||||
plugin.getLogger().log(Level.FINEST, "Received plugin message for subchannel {0} from {1}"
|
plugin.getLogger().log(Level.FINEST, "Received plugin message for subchannel {0} from {1}"
|
||||||
, new Object[]{subchannel, player});
|
, new Object[]{subchannel, player});
|
||||||
|
|
||||||
final String playerName = dataInput.readUTF();
|
String playerName = dataInput.readUTF();
|
||||||
|
|
||||||
//check if the player is still online or disconnected
|
//check if the player is still online or disconnected
|
||||||
final Player checkedPlayer = plugin.getServer().getPlayerExact(playerName);
|
Player checkedPlayer = plugin.getServer().getPlayerExact(playerName);
|
||||||
//fail if target player is blacklisted because already authed or wrong bungeecord id
|
//fail if target player is blacklisted because already authed or wrong bungeecord id
|
||||||
if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) {
|
if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) {
|
||||||
//blacklist this target player for BungeeCord Id brute force attacks
|
//blacklist this target player for BungeeCord Id brute force attacks
|
||||||
@ -77,21 +77,18 @@ public class BungeeCordListener implements PluginMessageListener {
|
|||||||
plugin.getSessions().put(id, playerSession);
|
plugin.getSessions().put(id, playerSession);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new ForceLoginTask(plugin, player));
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new ForceLoginTask(plugin, player));
|
||||||
} else if ("AUTO_REGISTER".equalsIgnoreCase(subchannel)) {
|
} else if ("AUTO_REGISTER".equalsIgnoreCase(subchannel)) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
|
||||||
public void run() {
|
try {
|
||||||
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
|
//we need to check if the player is registered on Bukkit too
|
||||||
try {
|
if (authPlugin == null || !authPlugin.isRegistered(playerName)) {
|
||||||
//we need to check if the player is registered on Bukkit too
|
BukkitLoginSession playerSession = new BukkitLoginSession(playerName, false);
|
||||||
if (authPlugin == null || !authPlugin.isRegistered(playerName)) {
|
playerSession.setVerified(true);
|
||||||
BukkitLoginSession playerSession = new BukkitLoginSession(playerName, false);
|
plugin.getSessions().put(id, playerSession);
|
||||||
playerSession.setVerified(true);
|
new ForceLoginTask(plugin, player).run();
|
||||||
plugin.getSessions().put(id, playerSession);
|
|
||||||
new ForceLoginTask(plugin, player).run();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex);
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class ProtocolLibLoginSource implements LoginSource {
|
|||||||
private final Random random;
|
private final Random random;
|
||||||
|
|
||||||
private String serverId;
|
private String serverId;
|
||||||
private byte[] verifyToken = new byte[VERIFY_TOKEN_LENGTH];
|
private final byte[] verifyToken = new byte[VERIFY_TOKEN_LENGTH];
|
||||||
|
|
||||||
public ProtocolLibLoginSource(FastLoginBukkit plugin, PacketEvent packetEvent, Player player, Random random) {
|
public ProtocolLibLoginSource(FastLoginBukkit plugin, PacketEvent packetEvent, Player player, Random random) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -9,8 +9,8 @@ import com.github.games647.fastlogin.bukkit.hooks.UltraAuthHook;
|
|||||||
import com.github.games647.fastlogin.bukkit.hooks.xAuthHook;
|
import com.github.games647.fastlogin.bukkit.hooks.xAuthHook;
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -40,7 +40,7 @@ public class DelayedAuthHook implements Runnable {
|
|||||||
private boolean registerHooks() {
|
private boolean registerHooks() {
|
||||||
AuthPlugin<Player> authPluginHook = null;
|
AuthPlugin<Player> authPluginHook = null;
|
||||||
try {
|
try {
|
||||||
ArrayList<Class<? extends AuthPlugin<Player>>> supportedHooks = Lists.newArrayList(AuthMeHook.class
|
List<Class<? extends AuthPlugin<Player>>> supportedHooks = Lists.newArrayList(AuthMeHook.class
|
||||||
, CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class
|
, CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class
|
||||||
, xAuthHook.class);
|
, xAuthHook.class);
|
||||||
for (Class<? extends AuthPlugin<Player>> clazz : supportedHooks) {
|
for (Class<? extends AuthPlugin<Player>> clazz : supportedHooks) {
|
||||||
|
@ -122,12 +122,7 @@ public class ForceLoginTask implements Runnable {
|
|||||||
|
|
||||||
private boolean isOnlineThreadSafe() {
|
private boolean isOnlineThreadSafe() {
|
||||||
//the playerlist isn't thread-safe
|
//the playerlist isn't thread-safe
|
||||||
Future<Boolean> onlineFuture = Bukkit.getScheduler().callSyncMethod(plugin, new Callable<Boolean>() {
|
Future<Boolean> onlineFuture = Bukkit.getScheduler().callSyncMethod(plugin, player::isOnline);
|
||||||
@Override
|
|
||||||
public Boolean call() throws Exception {
|
|
||||||
return player.isOnline();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return onlineFuture.get();
|
return onlineFuture.get();
|
||||||
|
@ -26,9 +26,9 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
|||||||
private static Map<String, Object> generateConfigMap(Configuration config) {
|
private static Map<String, Object> generateConfigMap(Configuration config) {
|
||||||
Map<String, Object> configMap = Maps.newHashMap();
|
Map<String, Object> configMap = Maps.newHashMap();
|
||||||
Collection<String> keys = config.getKeys();
|
Collection<String> keys = config.getKeys();
|
||||||
for (String key : keys) {
|
keys.forEach(key -> {
|
||||||
configMap.put(key, config.get(key));
|
configMap.put(key, config.get(key));
|
||||||
}
|
});
|
||||||
|
|
||||||
return configMap;
|
return configMap;
|
||||||
}
|
}
|
||||||
@ -72,12 +72,12 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
|||||||
File messageFile = new File(getDataFolder(), "messages.yml");
|
File messageFile = new File(getDataFolder(), "messages.yml");
|
||||||
Configuration messageConfig = ConfigurationProvider.getProvider(YamlConfiguration.class)
|
Configuration messageConfig = ConfigurationProvider.getProvider(YamlConfiguration.class)
|
||||||
.load(messageFile, defaults);
|
.load(messageFile, defaults);
|
||||||
for (String key : messageConfig.getKeys()) {
|
messageConfig.getKeys().forEach((key) -> {
|
||||||
String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key));
|
String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key));
|
||||||
if (!message.isEmpty()) {
|
if (!message.isEmpty()) {
|
||||||
localeMessages.put(key, message);
|
localeMessages.put(key, message);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
getLogger().log(Level.SEVERE, "Failed to load messages", ex);
|
getLogger().log(Level.SEVERE, "Failed to load messages", ex);
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,12 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public interface BungeeAuthPlugin extends AuthPlugin<ProxiedPlayer> {
|
public interface BungeeAuthPlugin extends AuthPlugin<ProxiedPlayer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
boolean forceLogin(ProxiedPlayer player);
|
boolean forceLogin(ProxiedPlayer player);
|
||||||
|
|
||||||
|
@Override
|
||||||
boolean isRegistered(String playerName) throws Exception;
|
boolean isRegistered(String playerName) throws Exception;
|
||||||
|
|
||||||
|
@Override
|
||||||
boolean forceRegister(ProxiedPlayer player, String password);
|
boolean forceRegister(ProxiedPlayer player, String password);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,10 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
preLoginEvent.registerIntent(plugin);
|
preLoginEvent.registerIntent(plugin);
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, new AsyncPremiumCheck(plugin, preLoginEvent));
|
|
||||||
|
PendingConnection connection = preLoginEvent.getConnection();
|
||||||
|
AsyncPremiumCheck asyncPremiumCheck = new AsyncPremiumCheck(plugin, preLoginEvent, connection);
|
||||||
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, asyncPremiumCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
@ -44,46 +44,43 @@ public class PluginMessageListener implements Listener {
|
|||||||
|
|
||||||
private void readMessage(PluginMessageEvent pluginMessageEvent) {
|
private void readMessage(PluginMessageEvent pluginMessageEvent) {
|
||||||
//so that we can safely process this in the background
|
//so that we can safely process this in the background
|
||||||
final byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
|
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
|
||||||
final ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() {
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
|
||||||
@Override
|
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
|
||||||
public void run() {
|
String subchannel = dataInput.readUTF();
|
||||||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
|
if ("ON".equals(subchannel)) {
|
||||||
String subchannel = dataInput.readUTF();
|
String playerName = dataInput.readUTF();
|
||||||
if ("ON".equals(subchannel)) {
|
|
||||||
String playerName = dataInput.readUTF();
|
if (playerName.equals(forPlayer.getName()) && plugin.getConfig().getBoolean("premium-warning")
|
||||||
|
&& !plugin.getCore().getPendingConfirms().contains(forPlayer.getUniqueId())) {
|
||||||
if (playerName.equals(forPlayer.getName()) && plugin.getConfig().getBoolean("premium-warning")
|
String message = plugin.getCore().getMessage("premium-warning");
|
||||||
&& !plugin.getCore().getPendingConfirms().contains(forPlayer.getUniqueId())) {
|
forPlayer.sendMessage(TextComponent.fromLegacyText(message));
|
||||||
String message = plugin.getCore().getMessage("premium-warning");
|
plugin.getCore().getPendingConfirms().add(forPlayer.getUniqueId());
|
||||||
forPlayer.sendMessage(TextComponent.fromLegacyText(message));
|
return;
|
||||||
plugin.getCore().getPendingConfirms().add(forPlayer.getUniqueId());
|
}
|
||||||
return;
|
|
||||||
}
|
plugin.getCore().getPendingConfirms().remove(forPlayer.getUniqueId());
|
||||||
|
AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, true);
|
||||||
plugin.getCore().getPendingConfirms().remove(forPlayer.getUniqueId());
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
|
||||||
AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, true);
|
} else if ("OFF".equals(subchannel)) {
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
|
String playerName = dataInput.readUTF();
|
||||||
} else if ("OFF".equals(subchannel)) {
|
|
||||||
String playerName = dataInput.readUTF();
|
AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, false);
|
||||||
|
ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
|
||||||
AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, false);
|
} else if ("SUCCESS".equals(subchannel)) {
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(plugin, task);
|
if (forPlayer.getPendingConnection().isOnlineMode()) {
|
||||||
} else if ("SUCCESS".equals(subchannel)) {
|
//bukkit module successfully received and force logged in the user
|
||||||
if (forPlayer.getPendingConnection().isOnlineMode()) {
|
//update only on success to prevent corrupt data
|
||||||
//bukkit module successfully received and force logged in the user
|
BungeeLoginSession loginSession = plugin.getSession().get(forPlayer.getPendingConnection());
|
||||||
//update only on success to prevent corrupt data
|
PlayerProfile playerProfile = loginSession.getProfile();
|
||||||
BungeeLoginSession loginSession = plugin.getSession().get(forPlayer.getPendingConnection());
|
loginSession.setRegistered(true);
|
||||||
PlayerProfile playerProfile = loginSession.getProfile();
|
|
||||||
loginSession.setRegistered(true);
|
if (!loginSession.isAlreadySaved()) {
|
||||||
|
playerProfile.setPremium(true);
|
||||||
if (!loginSession.isAlreadySaved()) {
|
plugin.getCore().getStorage().save(playerProfile);
|
||||||
playerProfile.setPremium(true);
|
loginSession.setAlreadySaved(true);
|
||||||
plugin.getCore().getStorage().save(playerProfile);
|
|
||||||
loginSession.setAlreadySaved(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,25 @@ import com.github.games647.fastlogin.core.shared.JoinManagement;
|
|||||||
|
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
import net.md_5.bungee.api.event.AsyncEvent;
|
||||||
|
|
||||||
public class AsyncPremiumCheck extends JoinManagement<ProxiedPlayer, BungeeLoginSource> implements Runnable {
|
public class AsyncPremiumCheck extends JoinManagement<ProxiedPlayer, BungeeLoginSource> implements Runnable {
|
||||||
|
|
||||||
private final FastLoginBungee plugin;
|
private final FastLoginBungee plugin;
|
||||||
private final PreLoginEvent preLoginEvent;
|
private final AsyncEvent<?> preLoginEvent;
|
||||||
|
|
||||||
public AsyncPremiumCheck(FastLoginBungee plugin, PreLoginEvent preLoginEvent) {
|
private final PendingConnection connection;
|
||||||
|
|
||||||
|
public AsyncPremiumCheck(FastLoginBungee plugin, AsyncEvent<?> preLoginEvent, PendingConnection connection) {
|
||||||
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
|
super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.preLoginEvent = preLoginEvent;
|
this.preLoginEvent = preLoginEvent;
|
||||||
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PendingConnection connection = preLoginEvent.getConnection();
|
|
||||||
plugin.getSession().remove(connection);
|
plugin.getSession().remove(connection);
|
||||||
|
|
||||||
String username = connection.getName();
|
String username = connection.getName();
|
||||||
|
@ -9,8 +9,8 @@ import com.google.common.io.ByteStreams;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.connection.Server;
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
@ -18,13 +18,13 @@ public class AuthStorage {
|
|||||||
|
|
||||||
private static final String PREMIUM_TABLE = "premium";
|
private static final String PREMIUM_TABLE = "premium";
|
||||||
|
|
||||||
private final FastLoginCore core;
|
private final FastLoginCore<?> core;
|
||||||
private final HikariDataSource dataSource;
|
private final HikariDataSource dataSource;
|
||||||
|
|
||||||
//a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647
|
//a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647
|
||||||
private final Calendar calendar = Calendar.getInstance(Locale.US);
|
private final Calendar calendar = Calendar.getInstance(Locale.US);
|
||||||
|
|
||||||
public AuthStorage(FastLoginCore core, String driver, String host, int port, String databasePath
|
public AuthStorage(FastLoginCore<?> core, String driver, String host, int port, String databasePath
|
||||||
, String user, String pass) {
|
, String user, String pass) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
|
||||||
@ -17,9 +18,7 @@ public class BalancedSSLFactory extends SSLSocketFactory {
|
|||||||
//in order to be thread-safe
|
//in order to be thread-safe
|
||||||
private final List<InetAddress> localAddresses;
|
private final List<InetAddress> localAddresses;
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private AtomicInteger id;
|
||||||
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
public BalancedSSLFactory(SSLSocketFactory oldFactory, Set<InetAddress> localAddresses) {
|
public BalancedSSLFactory(SSLSocketFactory oldFactory, Set<InetAddress> localAddresses) {
|
||||||
this.oldFactory = oldFactory;
|
this.oldFactory = oldFactory;
|
||||||
@ -65,16 +64,7 @@ public class BalancedSSLFactory extends SSLSocketFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private InetAddress getNextLocalAddress() {
|
private InetAddress getNextLocalAddress() {
|
||||||
int next;
|
int index = id.incrementAndGet() % localAddresses.size();
|
||||||
synchronized (lock) {
|
|
||||||
next = id;
|
|
||||||
id++;
|
|
||||||
if (next == Integer.MAX_VALUE) {
|
|
||||||
id = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = next % localAddresses.size();
|
|
||||||
return localAddresses.get(index);
|
return localAddresses.get(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ public class CompatibleCacheBuilder<K, V> {
|
|||||||
* @return A new cache builder.
|
* @return A new cache builder.
|
||||||
*/
|
*/
|
||||||
public static <K, V> CompatibleCacheBuilder<K, V> newBuilder() {
|
public static <K, V> CompatibleCacheBuilder<K, V> newBuilder() {
|
||||||
return new CompatibleCacheBuilder<K, V>();
|
return new CompatibleCacheBuilder<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CacheBuilder<K, V> builder;
|
private final CacheBuilder<K, V> builder;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private CompatibleCacheBuilder() {
|
private CompatibleCacheBuilder() {
|
||||||
|
@ -4,9 +4,9 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class DefaultPasswordGenerator<T> implements PasswordGenerator<T> {
|
public class DefaultPasswordGenerator<T> implements PasswordGenerator<T> {
|
||||||
|
|
||||||
private final Random random = new Random();
|
|
||||||
private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
.toCharArray();
|
.toCharArray();
|
||||||
|
private final Random random = new Random();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRandomPassword(T player) {
|
public String getRandomPassword(T player) {
|
||||||
|
@ -8,10 +8,10 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public abstract class JoinManagement<T, S extends LoginSource> {
|
public abstract class JoinManagement<T, S extends LoginSource> {
|
||||||
|
|
||||||
protected final FastLoginCore core;
|
protected final FastLoginCore<T> core;
|
||||||
protected final AuthPlugin<T> authHook;
|
protected final AuthPlugin<T> authHook;
|
||||||
|
|
||||||
public JoinManagement(FastLoginCore core, AuthPlugin<T> authHook) {
|
public JoinManagement(FastLoginCore<T> core, AuthPlugin<T> authHook) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.authHook = authHook;
|
this.authHook = authHook;
|
||||||
}
|
}
|
||||||
@ -62,8 +62,7 @@ public abstract class JoinManagement<T, S extends LoginSource> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkPremiumName(String username, S source, PlayerProfile profile)
|
private boolean checkPremiumName(String username, S source, PlayerProfile profile) throws Exception {
|
||||||
throws Exception {
|
|
||||||
if (core.getSharedConfig().get("autoRegister", false)
|
if (core.getSharedConfig().get("autoRegister", false)
|
||||||
&& (authHook == null || !authHook.isRegistered(username))) {
|
&& (authHook == null || !authHook.isRegistered(username))) {
|
||||||
core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.games647.fastlogin.core.shared;
|
package com.github.games647.fastlogin.core.shared;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.BalancedSSLFactory;
|
import com.github.games647.fastlogin.core.BalancedSSLFactory;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@ -8,7 +10,6 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -56,7 +57,7 @@ public abstract class MojangApiConnector {
|
|||||||
if (localAddresses.isEmpty()) {
|
if (localAddresses.isEmpty()) {
|
||||||
this.sslFactory = null;
|
this.sslFactory = null;
|
||||||
} else {
|
} else {
|
||||||
Set<InetAddress> addresses = new HashSet<>();
|
Set<InetAddress> addresses = Sets.newHashSet();
|
||||||
for (String localAddress : localAddresses) {
|
for (String localAddress : localAddresses) {
|
||||||
try {
|
try {
|
||||||
InetAddress address = InetAddress.getByName(localAddress);
|
InetAddress address = InetAddress.getByName(localAddress);
|
||||||
|
4
pom.xml
4
pom.xml
@ -50,8 +50,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>3.5.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.8</source>
|
||||||
<target>1.7</target>
|
<target>1.8</target>
|
||||||
<showWarnings>true</showWarnings>
|
<showWarnings>true</showWarnings>
|
||||||
<showDeprecation>true</showDeprecation>
|
<showDeprecation>true</showDeprecation>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Reference in New Issue
Block a user