Added premium skin forward

This commit is contained in:
games647
2016-01-23 20:53:13 +01:00
parent d118de8649
commit b22df62f90
8 changed files with 59 additions and 13 deletions

View File

@ -1,3 +1,7 @@
######0.4
* Added forward premium skin
######0.3.2 ######0.3.2
* Run packet readers in a different thread (separated from the Netty I/O Thread) * Run packet readers in a different thread (separated from the Netty I/O Thread)

View File

@ -1,6 +1,7 @@
# FastLogin # FastLogin
[![Build Status](https://travis-ci.org/games647/FastLogin.svg?branch=master)](https://travis-ci.org/games647/FastLogin) [![Build Status](https://travis-ci.org/games647/FastLogin.svg?branch=master)](https://travis-ci.org/games647/FastLogin)
[![Donate Button](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8ZBULMAPN7MZC)
Checks if a minecraft player has a paid account (premium). If so, they can skip offline authentication (auth plugins). Checks if a minecraft player has a paid account (premium). If so, they can skip offline authentication (auth plugins).
So they don't need to enter passwords. This is also called auto login (auto-login). So they don't need to enter passwords. This is also called auto login (auto-login).
@ -134,8 +135,4 @@ It's not tested yet, but all needed methods also exists in Cauldron so it could
###Useful Links: ###Useful Links:
* [Login Protocol](http://wiki.vg/Protocol#Login) * [Login Protocol](http://wiki.vg/Protocol#Login)
* [Protocol Encryption](http://wiki.vg/Protocol_Encryption) * [Protocol Encryption](http://wiki.vg/Protocol_Encryption)
###Donate
[![Donate Button](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8ZBULMAPN7MZC)

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.github.games647</groupId> <groupId>com.github.games647</groupId>
<artifactId>fastlogin-parent</artifactId> <artifactId>fastlogin-parent</artifactId>
<version>0.3</version> <version>0.4</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bukkit; package com.github.games647.fastlogin.bukkit;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
/** /**
@ -12,6 +13,8 @@ public class PlayerSession {
private final String username; private final String username;
private final String serverId; private final String serverId;
private final byte[] verifyToken; private final byte[] verifyToken;
private WrappedSignedProperty skinProperty;
private boolean verified; private boolean verified;
public PlayerSession(String username, String serverId, byte[] verifyToken) { public PlayerSession(String username, String serverId, byte[] verifyToken) {
@ -51,6 +54,24 @@ public class PlayerSession {
return username; return username;
} }
/**
* Gets the premium skin of this player
*
* @return skin property or null if the player has no skin or is a cracked account
*/
public synchronized WrappedSignedProperty getSkin() {
return this.skinProperty;
}
/**
* Sets the premium skin property which was retrieved by the session server
*
* @param skinProperty premium skin property
*/
public synchronized void setSkin(WrappedSignedProperty skinProperty) {
this.skinProperty = skinProperty;
}
/** /**
* Sets whether the player has a premium (paid account) account * Sets whether the player has a premium (paid account) account
* and valid session * and valid session

View File

@ -1,5 +1,7 @@
package com.github.games647.fastlogin.bukkit.listener; package com.github.games647.fastlogin.bukkit.listener;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.PlayerSession; import com.github.games647.fastlogin.bukkit.PlayerSession;
import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin; import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin;
@ -15,8 +17,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
/** /**
* This listener tells authentication plugins if the player has a premium account and we checked it successfully. * This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the
* So the plugin can skip authentication. * plugin can skip authentication.
*/ */
public class BukkitJoinListener implements Listener { public class BukkitJoinListener implements Listener {
@ -34,6 +36,15 @@ public class BukkitJoinListener implements Listener {
public void onPlayerJoin(PlayerJoinEvent joinEvent) { public void onPlayerJoin(PlayerJoinEvent joinEvent) {
final Player player = joinEvent.getPlayer(); final Player player = joinEvent.getPlayer();
PlayerSession session = plugin.getSessions().get(player.getAddress().toString());
if (session != null) {
WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player);
WrappedSignedProperty skin = session.getSkin();
if (skin != null) {
gameProfile.getProperties().put("textures", skin);
}
}
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override @Override

View File

@ -9,6 +9,7 @@ import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.github.games647.fastlogin.bukkit.EncryptionUtil; import com.github.games647.fastlogin.bukkit.EncryptionUtil;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.PlayerSession; import com.github.games647.fastlogin.bukkit.PlayerSession;
@ -28,6 +29,7 @@ import java.util.logging.Level;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
@ -109,7 +111,7 @@ public class EncryptionPacketListener extends PacketAdapter {
String serverId = (new BigInteger(serverIdHash)).toString(16); String serverId = (new BigInteger(serverIdHash)).toString(16);
String username = session.getUsername(); String username = session.getUsername();
if (hasJoinedServer(username, serverId)) { if (hasJoinedServer(session, serverId)) {
plugin.getLogger().log(Level.FINE, "Player {0} has a verified premium account", username); plugin.getLogger().log(Level.FINE, "Player {0} has a verified premium account", username);
session.setVerified(true); session.setVerified(true);
@ -201,9 +203,9 @@ public class EncryptionPacketListener extends PacketAdapter {
} }
} }
private boolean hasJoinedServer(String username, String serverId) { private boolean hasJoinedServer(PlayerSession session, String serverId) {
try { try {
String url = HAS_JOINED_URL + "username=" + username + "&serverId=" + serverId; String url = HAS_JOINED_URL + "username=" + session.getUsername() + "&serverId=" + serverId;
HttpURLConnection conn = plugin.getConnection(url); HttpURLConnection conn = plugin.getConnection(url);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
@ -213,6 +215,17 @@ public class EncryptionPacketListener extends PacketAdapter {
//http://wiki.vg/Protocol_Encryption#Server //http://wiki.vg/Protocol_Encryption#Server
JSONObject userData = (JSONObject) JSONValue.parseWithException(line); JSONObject userData = (JSONObject) JSONValue.parseWithException(line);
String uuid = (String) userData.get("id"); String uuid = (String) userData.get("id");
JSONArray properties = (JSONArray) userData.get("properties");
JSONObject skinProperty = (JSONObject) properties.get(0);
String propertyName = (String) skinProperty.get("name");
if (propertyName.equals("textures")) {
String skinValue = (String) skinProperty.get("value");
String signature = (String) skinProperty.get("signature");
session.setSkin(WrappedSignedProperty.fromValues(propertyName, skinValue, signature));
}
return true; return true;
} }
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.github.games647</groupId> <groupId>com.github.games647</groupId>
<artifactId>fastlogin-parent</artifactId> <artifactId>fastlogin-parent</artifactId>
<version>0.3</version> <version>0.4</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -8,7 +8,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<name>FastLogin</name> <name>FastLogin</name>
<version>0.3</version> <version>0.4</version>
<inceptionYear>2015</inceptionYear> <inceptionYear>2015</inceptionYear>
<url>https://www.spigotmc.org/resources/fastlogin.14153/</url> <url>https://www.spigotmc.org/resources/fastlogin.14153/</url>
<description> <description>