Added premium UUID support (Fixes #5)

This commit is contained in:
games647
2016-03-22 22:16:48 +01:00
parent f3e675e547
commit fd3b1ed8b6
7 changed files with 72 additions and 4 deletions

View File

@ -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
*/

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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);
}
}
}
}

View File

@ -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);

View File

@ -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
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