diff --git a/CHANGELOG.md b/CHANGELOG.md index f695a015..4cddb42c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ### 1.11 +* Add support for IPv6 proxies +* Shared configuration implementation for easier maintained code +* Use Gson for json parsing, because it's supported on all platforms and removes code duplicates +* Clean up project code * Drop support for deprecated AuthMe API * Remove legacy database migration code * Drop support for RoyalAuth, because it doesn't seem to be supported anymore diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java index a68d5779..bcd5a120 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java @@ -1,6 +1,5 @@ package com.github.games647.fastlogin.bukkit; -import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.mojang.MojangApiConnector; import com.github.games647.fastlogin.core.mojang.SkinProperties; import com.github.games647.fastlogin.core.mojang.VerificationReply; @@ -44,9 +43,7 @@ public class MojangApiBukkit extends MojangApiConnector { //validate parsing //http://wiki.vg/Protocol_Encryption#Server VerificationReply verification = gson.fromJson(reader, VerificationReply.class); - - String uuid = verification.getId(); - playerSession.setUuid(CommonUtil.parseId(uuid)); + playerSession.setUuid(verification.getId()); SkinProperties[] properties = verification.getProperties(); if (properties != null && properties.length > 0) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java index f0ded7b4..6ef0f0bf 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java @@ -77,7 +77,7 @@ public class ProtocolLibListener extends PacketAdapter { PacketContainer packet = packetEvent.getPacket(); String username = packet.getGameProfiles().read(0).getName(); - plugin.getLogger().log(Level.FINER, "Player {0} with {1} connecting", new Object[]{sessionKey, username}); + plugin.getLogger().log(Level.FINER, "GameProfile {0} with {1} connecting", new Object[]{sessionKey, username}); packetEvent.getAsyncMarker().incrementProcessingDelay(); Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java index 63a50200..216a76db 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/VerifyResponseTask.java @@ -52,7 +52,7 @@ public class VerifyResponseTask implements Runnable { BukkitLoginSession session = plugin.getLoginSessions().get(player.getAddress().toString()); if (session == null) { disconnect(plugin.getCore().getMessage("invalid-request"), true - , "Player {0} tried to send encryption response at invalid state", player.getAddress()); + , "GameProfile {0} tried to send encryption response at invalid state", player.getAddress()); } else { verifyResponse(session); } @@ -97,7 +97,7 @@ public class VerifyResponseTask implements Runnable { String username = session.getUsername(); if (plugin.getCore().getApiConnector().hasJoinedServer(session, serverId, player.getAddress())) { - plugin.getLogger().log(Level.INFO, "Player {0} has a verified premium account", username); + plugin.getLogger().log(Level.INFO, "GameProfile {0} has a verified premium account", username); session.setVerified(true); setPremiumUUID(session.getUuid()); @@ -105,7 +105,7 @@ public class VerifyResponseTask implements Runnable { } else { //user tried to fake a authentication disconnect(plugin.getCore().getMessage("invalid-session"), true - , "Player {0} ({1}) tried to log in with an invalid session ServerId: {2}" + , "GameProfile {0} ({1}) tried to log in with an invalid session ServerId: {2}" , session.getUsername(), player.getAddress(), serverId); } } @@ -132,7 +132,7 @@ public class VerifyResponseTask implements Runnable { if (!Arrays.equals(requestVerify, EncryptionUtil.decrypt(cipher, privateKey, responseVerify))) { //check if the verify token are equal to the server sent one disconnect(plugin.getCore().getMessage("invalid-verify-token"), true - , "Player {0} ({1}) tried to login with an invalid verify token. Server: {2} Client: {3}" + , "GameProfile {0} ({1}) tried to login with an invalid verify token. Server: {2} Client: {3}" , session.getUsername(), packetEvent.getPlayer().getAddress(), requestVerify, responseVerify); return false; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java index cccd4911..9e30c38f 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java @@ -3,7 +3,7 @@ package com.github.games647.fastlogin.core.hooks; /** * Represents a supporting authentication plugin in BungeeCord and Bukkit/Spigot/... servers * - * @param

either org.bukkit.entity.Player for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer for BungeeCord + * @param

either org.bukkit.entity.GameProfile for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer for BungeeCord */ public interface AuthPlugin

{ diff --git a/core/src/main/java/com/github/games647/fastlogin/core/mojang/Player.java b/core/src/main/java/com/github/games647/fastlogin/core/mojang/GameProfile.java similarity index 62% rename from core/src/main/java/com/github/games647/fastlogin/core/mojang/Player.java rename to core/src/main/java/com/github/games647/fastlogin/core/mojang/GameProfile.java index 25656ad4..e2c9447a 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/mojang/Player.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/GameProfile.java @@ -1,11 +1,13 @@ package com.github.games647.fastlogin.core.mojang; -public class Player { +import java.util.UUID; - private String id; +public class GameProfile { + + private UUID id; private String name; - public String getId() { + public UUID getId() { return id; } 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 0446a2db..46b15c91 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 @@ -8,6 +8,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.net.HostAndPort; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import java.io.BufferedReader; import java.io.IOException; @@ -53,7 +54,7 @@ public class MojangApiConnector { private final int rateLimit; private long lastRateLimit; - protected final Gson gson = new Gson(); + protected final Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); protected final Logger logger; public MojangApiConnector(Logger logger, Collection localAddresses, int rateLimit @@ -122,15 +123,14 @@ public class MojangApiConnector { private UUID getUUIDFromJson(String json) { boolean isArray = json.startsWith("["); - Player mojangPlayer; + GameProfile mojangPlayer; if (isArray) { - mojangPlayer = gson.fromJson(json, Player[].class)[0]; + mojangPlayer = gson.fromJson(json, GameProfile[].class)[0]; } else { - mojangPlayer = gson.fromJson(json, Player.class); + mojangPlayer = gson.fromJson(json, GameProfile.class); } - String id = mojangPlayer.getId(); - return CommonUtil.parseId(id); + return mojangPlayer.getId(); } protected HttpsURLConnection getConnection(String url, Proxy proxy) throws IOException { @@ -141,11 +141,9 @@ public class MojangApiConnector { connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("User-Agent", USER_AGENT); - //this connection doesn't need to be closed. So can make use of keep alive in java - if (sslFactory != null) { - connection.setSSLSocketFactory(sslFactory); - } + connection.setSSLSocketFactory(sslFactory); + //this connection doesn't need to be closed. So can make use of keep alive in java return connection; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/mojang/SkinProperties.java b/core/src/main/java/com/github/games647/fastlogin/core/mojang/SkinProperties.java index 95c606fd..e10752ee 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/mojang/SkinProperties.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/SkinProperties.java @@ -2,12 +2,11 @@ package com.github.games647.fastlogin.core.mojang; public class SkinProperties { - private String name; private String value; private String signature; public String getName() { - return name; + return "textures"; } public String getValue() { 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 new file mode 100644 index 00000000..562ae223 --- /dev/null +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/UUIDTypeAdapter.java @@ -0,0 +1,28 @@ +package com.github.games647.fastlogin.core.mojang; + +import com.github.games647.fastlogin.core.CommonUtil; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; +import java.util.UUID; + +public class UUIDTypeAdapter extends TypeAdapter { + + public void write(JsonWriter out, UUID value) throws IOException { + out.value(fromUUID(value)); + } + + public UUID read(JsonReader in) throws IOException { + return fromString(in.nextString()); + } + + public static String fromUUID(UUID value) { + return value.toString().replace("-", ""); + } + + public static UUID fromString(String input) { + return CommonUtil.parseId(input); + } +} diff --git a/core/src/main/java/com/github/games647/fastlogin/core/mojang/VerificationReply.java b/core/src/main/java/com/github/games647/fastlogin/core/mojang/VerificationReply.java index d147d4c0..6244213a 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/mojang/VerificationReply.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/mojang/VerificationReply.java @@ -1,12 +1,14 @@ package com.github.games647.fastlogin.core.mojang; +import java.util.UUID; + public class VerificationReply { - private String id; + private UUID id; private String name; private SkinProperties[] properties; - public String getId() { + public UUID getId() { return id; } 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 6dfc15b6..7c39c8d0 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 @@ -31,7 +31,7 @@ import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; /** - * @param

Player class + * @param

GameProfile class * @param CommandSender * @param Plugin class */ diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java index 8d8d4add..05ed5436 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java @@ -65,7 +65,7 @@ public abstract class JoinManagement

{ } private boolean checkPremiumName(S source, String username, PlayerProfile profile) throws Exception { - core.getPlugin().getLogger().log(Level.FINER, "Player {0} uses a premium username", username); + core.getPlugin().getLogger().log(Level.FINER, "GameProfile {0} uses a premium username", username); if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) { requestPremiumLogin(source, profile, username, false); return true; @@ -80,7 +80,7 @@ public abstract class JoinManagement

{ PlayerProfile profile = core.getStorage().loadProfile(premiumUUID); if (profile != null) { //uuid exists in the database - core.getPlugin().getLogger().log(Level.FINER, "Player {0} changed it's username", premiumUUID); + core.getPlugin().getLogger().log(Level.FINER, "GameProfile {0} changed it's username", premiumUUID); //update the username to the new one in the database profile.setPlayerName(username); diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 11f44ec1..f73e6f52 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -62,7 +62,7 @@ premiumUuid: false # #### Case 1 # nameChangeCheck = false ----- autoRegister = false # -# Player logins as cracked until the player invoked the command /premium. Then we could override the existing database +# GameProfile logins as cracked until the player invoked the command /premium. Then we could override the existing database # record. # # #### Case 2 diff --git a/core/src/main/resources/messages.yml b/core/src/main/resources/messages.yml index b4affdbd..34643086 100644 --- a/core/src/main/resources/messages.yml +++ b/core/src/main/resources/messages.yml @@ -24,25 +24,25 @@ # Switch mode is activated and a new (non-whitelist) cracked player tries to join switch-kick-message: '&4Only paid minecraft whitelisted accounts are allowed to join this server' -# Player activated premium login in order to skip offline authentication +# GameProfile activated premium login in order to skip offline authentication add-premium: '&2Added to the list of premium players' -# Player activated premium login in order to skip offline authentication +# GameProfile activated premium login in order to skip offline authentication add-premium-other: '&2Player has been added to the premium list' -# Player is already set be a paid account +# GameProfile is already set be a paid account already-exists: '&4You are already on the premium list' -# Player is already set be a paid account +# GameProfile is already set be a paid account already-exists-other: '&4Player is already on the premium list' -# Player was changed to be cracked +# GameProfile was changed to be cracked remove-premium: '&2Removed from the list of premium players' -# Player is already set to be cracked +# GameProfile is already set to be cracked not-premium: '&4You are not in the premium list' -# Player is already set to be cracked +# GameProfile is already set to be cracked not-premium-other: '&4Player is not in the premium list' # Admin wanted to change the premium of a user that isn't known to the plugin @@ -58,7 +58,7 @@ auto-login: '&2Auto logged in' auto-register: '&2Auto registered with password: %password You may want change it?' -# Player is not able to toggle the premium state of other players +# GameProfile is not able to toggle the premium state of other players no-permission: '&4Not enough permissions' # Although the console can toggle the premium state, it's not possible for the console itself.