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 c58687e5..9cb02b33 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 @@ -154,7 +154,7 @@ public class FastLoginBukkit extends JavaPlugin { /** * Gets the auth plugin hook in order to interact with the plugins. - * This can be null if no supporting auth plugin was found + * This can be null if no supporting auth plugin was found. * * @return interface to any supported auth plugin */ diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiConnector.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiConnector.java index 2e0fe209..4935b4c9 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiConnector.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiConnector.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.util.UUID; import java.util.logging.Level; import java.util.regex.Pattern; @@ -68,6 +69,7 @@ public class MojangApiConnector { //http://wiki.vg/Protocol_Encryption#Server JSONObject userData = (JSONObject) JSONValue.parseWithException(line); String uuid = (String) userData.get("id"); + session.setUuid(parseId(uuid)); JSONArray properties = (JSONArray) userData.get("properties"); JSONObject skinProperty = (JSONObject) properties.get(0); @@ -90,6 +92,14 @@ public class MojangApiConnector { return false; } + private UUID parseId(String withoutDashes) { + return UUID.fromString(withoutDashes.substring(0, 8) + + "-" + withoutDashes.substring(8, 12) + + "-" + withoutDashes.substring(12, 16) + + "-" + withoutDashes.substring(16, 20) + + "-" + withoutDashes.substring(20, 32)); + } + private HttpURLConnection getConnection(String url) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setConnectTimeout(TIMEOUT); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java index cf421235..6c95407f 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java @@ -2,6 +2,8 @@ package com.github.games647.fastlogin.bukkit; import com.comphenix.protocol.wrappers.WrappedSignedProperty; +import java.util.UUID; + import org.apache.commons.lang.ArrayUtils; /** @@ -15,6 +17,7 @@ public class PlayerSession { private final String serverId; private final byte[] verifyToken; + private UUID uuid; private WrappedSignedProperty skinProperty; private boolean verified; private boolean registered; @@ -110,6 +113,25 @@ public class PlayerSession { this.verified = verified; } + /** + * Get the premium UUID of this player + * + * @return the premium UUID or null if not fetched + */ + public synchronized UUID getUuid() { + return uuid; + } + + + /** + * Set the online UUID if it's fetched + * + * @param uuid premium UUID + */ + public synchronized void setUuid(UUID uuid) { + this.uuid = uuid; + } + /** * Get whether the player has a premium (paid account) account * and valid session diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java index a7442701..a069298a 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java @@ -105,6 +105,7 @@ public class EncryptionPacketListener extends PacketAdapter { plugin.getLogger().log(Level.FINE, "Player {0} has a verified premium account", username); session.setVerified(true); + setPremiumUUID(session, player); receiveFakeStartPacket(username, player); } else { //user tried to fake a authentication @@ -117,6 +118,20 @@ public class EncryptionPacketListener extends PacketAdapter { packetEvent.setCancelled(true); } + private void setPremiumUUID(PlayerSession session, Player player) { + UUID uuid = session.getUuid(); + if (plugin.getConfig().getBoolean("premiumUuid") && uuid != null) { + try { + Object networkManager = getNetworkManager(player); + //https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/NetworkManager.java#L69 + Field spoofField = FuzzyReflection.fromObject(networkManager).getFieldByType("spoofedUUID", UUID.class); + spoofField.set(networkManager, uuid); + } catch (ReflectiveOperationException reflectiveOperationException) { + plugin.getLogger().log(Level.SEVERE, "Error setting premium uuid", reflectiveOperationException); + } + } + } + private boolean checkVerifyToken(PlayerSession session, PrivateKey privateKey, PacketEvent packetEvent) { byte[] requestVerify = session.getVerifyToken(); //encrypted verify token diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java index 5d3f974a..d5c08774 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java @@ -59,7 +59,9 @@ public class ProtcolSupportListener implements Listener { PlayerSession playerSession = new PlayerSession(playerName, null, null); playerSession.setRegistered(registered); plugin.getSessions().put(address.toString(), playerSession); -// loginStartEvent.setUseOnlineModeUUID(true); + if (plugin.getConfig().getBoolean("premiumUuid")) { + loginStartEvent.setUseOnlineModeUUID(true); + } } } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java index c58e6b9f..6ab2555c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java @@ -76,7 +76,7 @@ public class StartPacketListener extends PacketAdapter { BukkitAuthPlugin authPlugin = plugin.getAuthPlugin(); if (plugin.getEnabledPremium().contains(username)) { enablePremiumLogin(username, sessionKey, player, packetEvent, true); - } else if (plugin.getConfig().getBoolean("autologin") + } else if (plugin.getConfig().getBoolean("autoRegister") && authPlugin != null && !plugin.getAuthPlugin().isRegistered(username)) { enablePremiumLogin(username, sessionKey, player, packetEvent, false); plugin.getEnabledPremium().add(username); diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 67eb5004..37149722 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -16,4 +16,23 @@ # the player just disconnect and sees the message: 'bad login' # There is no way to change this message # For more information: https://github.com/games647/FastLogin#why-do-players-have-to-invoke-a-command -autoRegister: false \ No newline at end of file +autoRegister: false + +# If this plugin detected that a player has a premium, it can also set the associated +# uuid from that account. +# +# So if the players changes their usernames, they will still have +# the same playerdata (inventory, permissions, ...) +# +# Warning: This also means that the UUID will be different if the player is connecting +# through a offline mode connection. This **could** cause plugin compatibility issues. +# +# This is a example and doesn't apply for every plugin. +# Example: If you want to ban players who aren't online at the moment, the ban plugin will look +# after a offline uuid associated to the player, because the server is in offline mode. Then the premium +# players could still join the server, because they have different UUID. +# +# Moreover you may want to convert the offline UUID to a premium UUID. This will ensure that the player +# will have the same inventory, permissions, ... if they switched to premium authentification from offline/cracked +# authentification. +premiumUuid: false \ No newline at end of file