diff --git a/README.md b/README.md index b08654c3..9034d5ae 100644 --- a/README.md +++ b/README.md @@ -26,15 +26,15 @@ So they don't need to enter passwords. This is also called auto login (auto-logi *** ### Commands: - * /premium [player] Label the invoker or the argument as paid account - * /cracked [player] Label the invoker or the argument as cracked account + /premium [player] Label the invoker or the argument as paid account + /cracked [player] Label the invoker or the argument as cracked account ### Permissions: - * fastlogin.bukkit.command.premium - * fastlogin.bukkit.command.cracked - * fastlogin.command.premium.other - * fastlogin.command.cracked.other - * fastlogin.command.import + fastlogin.bukkit.command.premium + fastlogin.bukkit.command.cracked + fastlogin.command.premium.other + fastlogin.command.cracked.other + fastlogin.command.import ### Requirements: * Plugin: [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) or diff --git a/bukkit/pom.xml b/bukkit/pom.xml index bfc75e92..fbbfd514 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -127,7 +127,7 @@ me.clip placeholderapi - 2.8.2 + 2.8.4 provided true diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java index f52dbb7a..446ece75 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java @@ -40,19 +40,6 @@ public class BukkitLoginSession extends LoginSession { this(username, "", ArrayUtils.EMPTY_BYTE_ARRAY, false, profile); } - /** - * Gets the random generated server id. This makes sure the request sent from the client is just for this server. - * - * See this for details https://www.sk89q.com/2011/09/Minecraft-name-spoofing-exploit/ - * - * Empty if it's a BungeeCord connection - * - * @return random generated server id - */ - public String getServerId() { - return serverId; - } - /** * Gets the verify token the server sent to the client. * @@ -64,7 +51,6 @@ public class BukkitLoginSession extends LoginSession { return ArrayUtils.clone(verifyToken); } - //todo: this should be optional for players without a skin at all public synchronized Optional getSkin() { return Optional.ofNullable(skinProperty); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 627bbbfb..1ec8fa1a 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -19,13 +19,13 @@ import com.google.common.io.ByteStreams; import com.google.common.net.HostAndPort; import java.nio.file.Path; -import java.security.KeyPair; import java.util.List; import java.util.Optional; import java.util.concurrent.ConcurrentMap; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.messaging.PluginMessageRecipient; import org.slf4j.Logger; @@ -35,8 +35,6 @@ import org.slf4j.Logger; */ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin { - //provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic - private final KeyPair keyPair = EncryptionUtil.generateKeyPair(); private final Logger logger = CommonUtil.createLoggerFromJDK(getLogger()); private boolean bungeeCord; @@ -65,6 +63,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin { private final FastLoginBukkit plugin; - private final CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin(); - private final PlayerListener playerListener = getListener(); + private final CrazyLogin crazyLoginPlugin; + private final PlayerListener playerListener; public CrazyLoginHook(FastLoginBukkit plugin) { this.plugin = plugin; + + crazyLoginPlugin = CrazyLogin.getPlugin(); + playerListener = getListener(); } @Override @@ -78,7 +80,7 @@ public class CrazyLoginHook implements AuthPlugin { return true; } } catch (InterruptedException | ExecutionException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); + plugin.getLog().error("Failed to forceLogin player: {}", player, ex); return false; } @@ -112,7 +114,7 @@ public class CrazyLoginHook implements AuthPlugin { try { listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true); } catch (IllegalAccessException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex); + plugin.getLog().error("Failed to get the listener instance for auto login", ex); listener = null; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java index 1fd74210..3fbad417 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java @@ -5,7 +5,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -45,7 +44,7 @@ public class UltraAuthHook implements AuthPlugin { try { return future.get(); } catch (InterruptedException | ExecutionException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); + plugin.getLog().error("Failed to forceLogin player: {}", player, ex); return false; } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java index f2febb00..74db193f 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java @@ -8,7 +8,6 @@ import de.luricos.bukkit.xAuth.xAuthPlayer; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -52,7 +51,7 @@ public class xAuthHook implements AuthPlugin { try { return future.get(); } catch (InterruptedException | ExecutionException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); + plugin.getLog().error("Failed to forceLogin player: {}", player, ex); return false; } } @@ -80,7 +79,7 @@ public class xAuthHook implements AuthPlugin { //login in the player after registration return future.get() && forceLogin(player); } catch (InterruptedException | ExecutionException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex); + plugin.getLog().error("Failed to forceRegister player: {}", player, ex); return false; } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java index e889b202..c2b52a17 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java @@ -99,7 +99,7 @@ public class BungeeListener implements PluginMessageListener { new ForceLoginTask(plugin.getCore(), player).run(); } } catch (Exception ex) { - plugin.getLog().error("Failed to query isRegistered", ex); + plugin.getLog().error("Failed to query isRegistered for player: {}", player, ex); } }, 20L); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index 714b31f6..545be923 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -7,6 +7,7 @@ import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.core.PlayerProfile; import com.github.games647.fastlogin.core.shared.JoinManagement; +import java.security.PublicKey; import java.util.Random; import org.bukkit.command.CommandSender; @@ -17,6 +18,7 @@ public class NameCheckTask extends JoinManagement com.zaxxer HikariCP - 2.7.7 + 2.7.8 diff --git a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java index fa3c3dd2..dd82a8de 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java @@ -11,6 +11,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.time.Instant; +import java.util.Optional; import java.util.Properties; import java.util.UUID; import java.util.concurrent.ThreadFactory; @@ -93,25 +94,15 @@ public class AuthStorage { public PlayerProfile loadProfile(String name) { try (Connection con = dataSource.getConnection(); - PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_NAME)) { + PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_NAME) + ) { loadStmt.setString(1, name); try (ResultSet resultSet = loadStmt.executeQuery()) { - if (resultSet.next()) { - long userId = resultSet.getInt(1); - - UUID uuid = UUIDTypeAdapter.parseId(resultSet.getString(2)); - - boolean premium = resultSet.getBoolean(4); - String lastIp = resultSet.getString(5); - Instant lastLogin = resultSet.getTimestamp(6).toInstant(); - return new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin); - } else { - return new PlayerProfile(null, name, false, ""); - } + return parseResult(resultSet).orElseGet(() -> new PlayerProfile(null, name, false, "")); } } catch (SQLException sqlEx) { - core.getPlugin().getLog().error("Failed to query profile", sqlEx); + core.getPlugin().getLog().error("Failed to query profile: {}", name, sqlEx); } return null; @@ -119,27 +110,36 @@ public class AuthStorage { public PlayerProfile loadProfile(UUID uuid) { try (Connection con = dataSource.getConnection(); - PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_UUID)) { + PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_UUID) + ) { loadStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid)); try (ResultSet resultSet = loadStmt.executeQuery()) { - if (resultSet.next()) { - long userId = resultSet.getInt(1); - - String name = resultSet.getString(3); - boolean premium = resultSet.getBoolean(4); - String lastIp = resultSet.getString(5); - Instant lastLogin = resultSet.getTimestamp(6).toInstant(); - return new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin); - } + return parseResult(resultSet).orElse(null); } } catch (SQLException sqlEx) { - core.getPlugin().getLog().error("Failed to query profile", sqlEx); + core.getPlugin().getLog().error("Failed to query profile: {}", uuid, sqlEx); } return null; } + private Optional parseResult(ResultSet resultSet) throws SQLException { + if (resultSet.next()) { + long userId = resultSet.getInt(1); + + UUID uuid = UUIDTypeAdapter.parseId(resultSet.getString(2)); + + String name = resultSet.getString(3); + boolean premium = resultSet.getBoolean(4); + String lastIp = resultSet.getString(5); + Instant lastLogin = resultSet.getTimestamp(6).toInstant(); + return Optional.of(new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin)); + } + + return Optional.empty(); + } + public void save(PlayerProfile playerProfile) { try (Connection con = dataSource.getConnection()) { String uuid = playerProfile.getId().map(UUIDTypeAdapter::toMojangId).orElse(null); @@ -163,7 +163,6 @@ public class AuthStorage { saveStmt.setString(4, playerProfile.getLastIp()); saveStmt.execute(); - try (ResultSet generatedKeys = saveStmt.getGeneratedKeys()) { if (generatedKeys != null && generatedKeys.next()) { playerProfile.setRowId(generatedKeys.getInt(1)); @@ -171,11 +170,9 @@ public class AuthStorage { } } } - } catch (SQLException ex) { - core.getPlugin().getLog().error("Failed to save playerProfile", ex); + core.getPlugin().getLog().error("Failed to save playerProfile {}", playerProfile, ex); } - } public void close() { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java index e55c18b8..73042789 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java @@ -7,7 +7,6 @@ import java.util.UUID; public class PlayerProfile { private String playerName; - private long rowId; private UUID uuid; @@ -48,7 +47,6 @@ public class PlayerProfile { this.rowId = generatedId; } - //todo: this should be optional public synchronized Optional getId() { return Optional.ofNullable(uuid); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java b/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java index 7f6761a9..e6257245 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/MojangApiConnector.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -62,13 +61,13 @@ public class MojangApiConnector { protected final Gson gson = new GsonBuilder() .registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); - public MojangApiConnector(Logger logger, Collection localAddresses, int rateLimit + public MojangApiConnector(Logger logger, Iterable localAddresses, int rateLimit , Iterable proxies) { this.logger = logger; this.rateLimit = Math.max(rateLimit, 600); this.sslFactory = buildAddresses(logger, localAddresses); - List proxyBuilder = new ArrayList<>(); + Collection proxyBuilder = new ArrayList<>(); for (HostAndPort proxy : proxies) { proxyBuilder.add(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getHostText(), proxy.getPort()))); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/mojang/UUIDTypeAdapter.java b/core/src/main/java/com/github/games647/fastlogin/core/mojang/UUIDTypeAdapter.java index 07f782d8..d85fb301 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/mojang/UUIDTypeAdapter.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/UUIDTypeAdapter.java @@ -14,7 +14,7 @@ public class UUIDTypeAdapter extends TypeAdapter { private static final Pattern UUID_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); - public static UUID parseId(String withoutDashes) { + public static UUID parseId(CharSequence withoutDashes) { return UUID.fromString(UUID_PATTERN.matcher(withoutDashes).replaceAll("$1-$2-$3-$4-$5")); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 596cb705..66797b91 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -42,7 +41,7 @@ public class FastLoginCore

> { protected final Map localeMessages = new ConcurrentHashMap<>(); private final ConcurrentMap pendingLogin = CommonUtil.buildCache(5, -1); - private final Set pendingConfirms = new HashSet<>(); + private final Collection pendingConfirms = new HashSet<>(); private final T plugin; private Configuration config; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java index 8740de4d..00a9bb58 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/ForceLoginManagement.java @@ -64,7 +64,7 @@ public abstract class ForceLoginManagement

{ } } } catch (Exception ex) { - core.getPlugin().getLog().error("Failed to check premium state", ex); + core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex); } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java index 3facc876..b973d3db 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/LoginSession.java @@ -55,7 +55,7 @@ public abstract class LoginSession { } @Override - public String toString() { + public synchronized String toString() { return this.getClass().getSimpleName() + '{' + "username='" + username + '\'' + ", profile=" + profile +