diff --git a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java index fba6e4f7..f0cb572a 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java @@ -36,4 +36,11 @@ public interface PendingConnection extends Connection * @return the accepting listener */ ListenerInfo getListener(); + + /** + * Get this connection's UUID, if set. + * + * @return the UUID + */ + String getUUID(); } diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index 6ef00b28..bc5f6ee5 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -99,4 +99,11 @@ public interface ProxiedPlayer extends Connection, CommandSender * @param server the server to set */ void setReconnectServer(ServerInfo server); + + /** + * Get this connection's UUID, if set. + * + * @return the UUID + */ + String getUUID(); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Vanilla.java b/protocol/src/main/java/net/md_5/bungee/protocol/Vanilla.java index 87312772..3615181d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Vanilla.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Vanilla.java @@ -30,8 +30,8 @@ import net.md_5.bungee.protocol.skip.PacketReader; public class Vanilla implements Protocol { - public static final byte PROTOCOL_VERSION = 78; - public static final String GAME_VERSION = "1.6.4"; + public static final byte PROTOCOL_VERSION = 80; + public static final String GAME_VERSION = "13w39b"; @Getter private static final Vanilla instance = new Vanilla(); /*========================================================================*/ @@ -188,7 +188,7 @@ public class Vanilla implements Protocol }; opCodes[0x14] = new OpCode[] { - INT, STRING, INT, INT, INT, BYTE, BYTE, SHORT, METADATA + INT, STRING, STRING, INT, INT, INT, BYTE, BYTE, SHORT, METADATA }; opCodes[0x16] = new OpCode[] { @@ -304,7 +304,7 @@ public class Vanilla implements Protocol }; opCodes[0x3E] = new OpCode[] { - STRING, INT, INT, INT, FLOAT, BYTE + STRING, INT, INT, INT, FLOAT, BYTE, BYTE }; opCodes[0x3F] = new OpCode[] { @@ -312,7 +312,7 @@ public class Vanilla implements Protocol }; opCodes[0x46] = new OpCode[] { - BYTE, BYTE + BYTE, FLOAT }; opCodes[0x47] = new OpCode[] { @@ -374,10 +374,6 @@ public class Vanilla implements Protocol { SHORT, SHORT, INT_BYTE }; - opCodes[0xC8] = new OpCode[] - { - INT, INT - }; opCodes[0xCA] = new OpCode[] { BYTE, FLOAT, FLOAT diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java index 7c2cf698..b8c984c5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java @@ -27,6 +27,10 @@ public abstract class AbstractPacketHandler { } + public void handle(PacketC8Statistic statistic) throws Exception + { + } + public void handle(PacketC9PlayerListItem playerList) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC8Statistic.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC8Statistic.java new file mode 100644 index 00000000..61552a8a --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC8Statistic.java @@ -0,0 +1,41 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +@EqualsAndHashCode(callSuper = false) +public class PacketC8Statistic extends DefinedPacket +{ + + public PacketC8Statistic() + { + super( 0xC8 ); + } + + @Override + public void read(ByteBuf buf) + { + int len = buf.readInt(); + for ( int i = 0; i < len; i++ ) + { + readString( buf ); + buf.readInt(); + } + } + + @Override + public void write(ByteBuf buf) + { + throw new UnsupportedOperationException(); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 9dec6c59..5d39ff7f 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -357,4 +357,10 @@ public final class UserConnection implements ProxiedPlayer { return unsafe; } + + @Override + public String getUUID() + { + return getPendingConnection().getUUID(); + } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 77683b0b..e885f311 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -1,6 +1,8 @@ package net.md_5.bungee.connection; import com.google.common.base.Preconditions; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import io.netty.util.concurrent.ScheduledFuture; import java.math.BigInteger; import java.net.InetSocketAddress; @@ -86,6 +88,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection private ScheduledFuture pingFuture; private InetSocketAddress vHost; private byte version = -1; + @Getter + private String UUID; private enum State { @@ -250,18 +254,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection if ( this.onlineMode ) { String encName = URLEncoder.encode( InitialHandler.this.getName(), "UTF-8" ); + String encID = URLEncoder.encode( InitialHandler.this.request.getServerId(), "UTF-8" ); - MessageDigest sha = MessageDigest.getInstance( "SHA-1" ); - for ( byte[] bit : new byte[][] - { - request.getServerId().getBytes( "ISO_8859_1" ), sharedKey.getEncoded(), EncryptionUtil.keys.getPublic().getEncoded() - } ) - { - sha.update( bit ); - } - - String encodedHash = URLEncoder.encode( new BigInteger( sha.digest() ).toString( 16 ), "UTF-8" ); - String authURL = "http://session.minecraft.net/game/checkserver.jsp?user=" + encName + "&serverId=" + encodedHash; + String authURL = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + encName + "&serverId=" + encID; Callback handler = new Callback() { @@ -270,13 +265,18 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( error == null ) { - if ( "YES".equals( result ) ) + JsonObject obj = BungeeCord.getInstance().gson.fromJson( result, JsonObject.class ); + if ( obj != null ) { - finish(); - } else - { - disconnect( "Not authenticated with Minecraft.net" ); + JsonElement id = obj.get( "id" ); + if ( id != null ) + { + UUID = id.getAsString(); + finish(); + return; + } } + disconnect( "Not authenticated with Minecraft.net" ); } else { disconnect( bungee.getTranslation( "mojang_fail" ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java b/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java index fd486e04..96d0a71d 100644 --- a/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java @@ -36,7 +36,15 @@ public class HttpHandler extends SimpleChannelInboundHandler if ( msg instanceof HttpResponse ) { HttpResponse response = (HttpResponse) msg; - if ( response.getStatus().code() != 200 ) + int responseCode = response.getStatus().code(); + + if ( responseCode == HttpResponseStatus.NO_CONTENT.code() ) + { + done( ctx ); + return; + } + + if ( responseCode != HttpResponseStatus.OK.code() ) { throw new IllegalStateException( "Expected HTTP response 200 OK, got " + response.getStatus() ); } @@ -48,14 +56,19 @@ public class HttpHandler extends SimpleChannelInboundHandler if ( msg instanceof LastHttpContent ) { - try - { - callback.done( buffer.toString(), null ); - } finally - { - ctx.channel().close(); - } + done( ctx ); } } } + + private void done(ChannelHandlerContext ctx) + { + try + { + callback.done( buffer.toString(), null ); + } finally + { + ctx.channel().close(); + } + } }