From 96acdb97fd79f453e7453da4881533a22a1c5594 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 28 Sep 2013 17:03:18 +1000 Subject: [PATCH 01/24] Update to latest snapshot. --- .../api/connection/PendingConnection.java | 7 ++++ .../bungee/api/connection/ProxiedPlayer.java | 7 ++++ .../net/md_5/bungee/protocol/Vanilla.java | 14 +++---- .../packet/AbstractPacketHandler.java | 4 ++ .../protocol/packet/PacketC8Statistic.java | 41 +++++++++++++++++++ .../java/net/md_5/bungee/UserConnection.java | 6 +++ .../bungee/connection/InitialHandler.java | 32 +++++++-------- .../net/md_5/bungee/http/HttpHandler.java | 29 +++++++++---- 8 files changed, 107 insertions(+), 33 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC8Statistic.java 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(); + } + } } From 4257b81d8c188d4ccfc11879a8e6f316a68cb700 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 11 Oct 2013 18:40:21 +1100 Subject: [PATCH 02/24] WIP --- api/pom.xml | 6 - .../bungee/api/connection/Connection.java | 2 +- pom.xml | 12 + .../protocol/AbstractPacketHandler.java | 95 +++++ .../bungee/protocol/BadPacketException.java | 5 + .../md_5/bungee/protocol/DefinedPacket.java | 105 +++++ .../java/net/md_5/bungee/protocol/Forge.java | 33 -- .../java/net/md_5/bungee/protocol/OpCode.java | 7 - .../net/md_5/bungee/protocol/Protocol.java | 76 +++- .../net/md_5/bungee/protocol/Vanilla.java | 382 ------------------ .../bungee/protocol/game/GameProtocol.java | 16 + .../{packet => game}/Packet0KeepAlive.java | 19 +- .../Packet15Settings.java} | 22 +- .../Packet16ClientStatus.java} | 25 +- .../Packet1Login.java} | 35 +- .../Packet2Chat.java} | 27 +- .../Packet3BPlayerListItem.java} | 29 +- .../Packet3DTabComplete.java} | 24 +- .../Packet3EScoreboardObjective.java} | 29 +- .../Packet3FScoreboardScore.java} | 19 +- .../Packet40DisplayScoreboard.java} | 21 +- .../Packet41Team.java} | 23 +- .../Packet42PluginMessage.java} | 29 +- .../Packet43Kick.java} | 29 +- .../Packet7Respawn.java} | 28 +- .../protocol/handshake/HandshakeProtocol.java | 17 + .../protocol/handshake/Packet0Handshake.java | 46 +++ .../bungee/protocol/login/LoginProtocol.java | 17 + .../bungee/protocol/login/Packet0Kick.java | 37 ++ .../Packet1EncryptionResponse.java} | 28 +- .../protocol/login/Packet2LoginSuccess.java | 37 ++ .../packet/AbstractPacketHandler.java | 85 ---- .../bungee/protocol/packet/DefinedPacket.java | 69 ---- .../bungee/protocol/packet/Packet1Login.java | 73 ---- .../packet/Packet2CEntityProperties.java | 47 --- .../protocol/packet/Packet2Handshake.java | 49 --- .../protocol/packet/PacketC8Statistic.java | 41 -- .../packet/PacketFDEncryptionRequest.java | 52 --- .../bungee/protocol/packet/PacketFEPing.java | 36 -- .../bungee/protocol/ping/PingProtocol.java | 16 + .../md_5/bungee/protocol/skip/BulkChunk.java | 16 - .../md_5/bungee/protocol/skip/ByteHeader.java | 24 -- .../bungee/protocol/skip/Instruction.java | 33 -- .../md_5/bungee/protocol/skip/IntHeader.java | 24 -- .../net/md_5/bungee/protocol/skip/Item.java | 18 - .../net/md_5/bungee/protocol/skip/Jump.java | 24 -- .../md_5/bungee/protocol/skip/MetaData.java | 44 -- .../bungee/protocol/skip/OptionalMotion.java | 17 - .../bungee/protocol/skip/OptionalWindow.java | 21 - .../bungee/protocol/skip/PacketReader.java | 74 ---- .../bungee/protocol/skip/ShortHeader.java | 24 -- .../protocol/skip/UnsignedShortByte.java | 14 - .../net/md_5/bungee/protocol/PacketTest.java | 45 --- .../md_5/bungee/protocol/ProtocolTest.java | 14 - proxy/pom.xml | 6 - .../main/java/net/md_5/bungee/BungeeCord.java | 12 +- .../net/md_5/bungee/BungeeServerInfo.java | 6 +- .../java/net/md_5/bungee/EncryptionUtil.java | 4 +- .../java/net/md_5/bungee/PacketConstants.java | 16 +- .../net/md_5/bungee/ServerConnection.java | 10 +- .../java/net/md_5/bungee/ServerConnector.java | 40 +- .../java/net/md_5/bungee/UserConnection.java | 20 +- .../bungee/connection/DownstreamBridge.java | 30 +- .../bungee/connection/InitialHandler.java | 26 +- .../md_5/bungee/connection/PingHandler.java | 4 +- .../bungee/connection/UpstreamBridge.java | 20 +- .../bungee/netty/DefinedPacketEncoder.java | 2 +- .../net/md_5/bungee/netty/PacketDecoder.java | 2 +- .../net/md_5/bungee/netty/PacketHandler.java | 2 +- .../net/md_5/bungee/netty/PacketWrapper.java | 2 +- .../main/java/net/md_5/bungee/tab/Custom.java | 6 +- .../main/java/net/md_5/bungee/tab/Global.java | 10 +- .../java/net/md_5/bungee/tab/GlobalPing.java | 4 +- .../net/md_5/bungee/tab/ServerUnique.java | 4 +- 74 files changed, 745 insertions(+), 1621 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/Forge.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/OpCode.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/Vanilla.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java rename protocol/src/main/java/net/md_5/bungee/protocol/{packet => game}/Packet0KeepAlive.java (62%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketCCSettings.java => game/Packet15Settings.java} (67%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketCDClientStatus.java => game/Packet16ClientStatus.java} (58%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/forge/Forge1Login.java => game/Packet1Login.java} (57%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketFFKick.java => game/Packet2Chat.java} (59%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketC9PlayerListItem.java => game/Packet3BPlayerListItem.java} (59%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketCBTabComplete.java => game/Packet3DTabComplete.java} (66%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketCEScoreboardObjective.java => game/Packet3EScoreboardObjective.java} (61%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketCFScoreboardScore.java => game/Packet3FScoreboardScore.java} (74%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketD0DisplayScoreboard.java => game/Packet40DisplayScoreboard.java} (64%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketD1Team.java => game/Packet41Team.java} (84%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketFAPluginMessage.java => game/Packet42PluginMessage.java} (69%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/Packet3Chat.java => game/Packet43Kick.java} (57%) rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/Packet9Respawn.java => game/Packet7Respawn.java} (64%) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java rename protocol/src/main/java/net/md_5/bungee/protocol/{packet/PacketFCEncryptionResponse.java => login/Packet1EncryptionResponse.java} (57%) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2CEntityProperties.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC8Statistic.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/BulkChunk.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/ByteHeader.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/Instruction.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/IntHeader.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/Item.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/Jump.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/MetaData.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalMotion.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalWindow.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/PacketReader.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/ShortHeader.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/skip/UnsignedShortByte.java delete mode 100644 protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java delete mode 100644 protocol/src/test/java/net/md_5/bungee/protocol/ProtocolTest.java diff --git a/api/pom.xml b/api/pom.xml index 1828ce78..54c3345b 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -19,12 +19,6 @@ API implemented by the Elastic Portal Suite - - com.google.guava - guava - 14.0.1 - compile - net.md-5 bungeecord-config diff --git a/api/src/main/java/net/md_5/bungee/api/connection/Connection.java b/api/src/main/java/net/md_5/bungee/api/connection/Connection.java index f0a3f504..2c9cae14 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/Connection.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/Connection.java @@ -1,7 +1,7 @@ package net.md_5.bungee.api.connection; import java.net.InetSocketAddress; -import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.DefinedPacket; /** * A proxy connection is defined as a connection directly connected to a socket. diff --git a/pom.xml b/pom.xml index 83d018bb..ca95d790 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,18 @@ 4.11 test + + com.google.guava + guava + 14.0.1 + compile + + + net.sf.trove4j + trove4j + 3.0.3 + compile + org.projectlombok lombok diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java new file mode 100644 index 00000000..d9fd51ff --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -0,0 +1,95 @@ +package net.md_5.bungee.protocol; + +import net.md_5.bungee.protocol.handshake.Packet0Handshake; +import net.md_5.bungee.protocol.login.Packet0Kick; +import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; +import net.md_5.bungee.protocol.login.Packet2LoginSuccess; + +public abstract class AbstractPacketHandler +{ + + /*========================================================================*/ + // Handshake Start + public void handle(Packet0Handshake handshake) throws Exception + { + } + // Handshake End + /*========================================================================*/ + // Game Start + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + + public void handle(Packet0Handshake handshake) throws Exception + { + } + // Game End + /*========================================================================*/ + // Ping Start + // Ping End + /*========================================================================*/ + // Login Start + + public void handle(Packet0Kick kick) throws Exception + { + } + + public void handle(Packet1EncryptionResponse encryptionResponse) throws Exception + { + } + + public void handle(Packet2LoginSuccess loginSuccess) throws Exception + { + } + // Login End + /*========================================================================*/ +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java b/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java index 523aeafc..6c0ef4df 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java @@ -7,4 +7,9 @@ public class BadPacketException extends RuntimeException { super( message ); } + + public BadPacketException(String message, Throwable cause) + { + super( message, cause ); + } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java new file mode 100644 index 00000000..c3a034bc --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -0,0 +1,105 @@ +package net.md_5.bungee.protocol; + +import com.google.common.base.Charsets; +import io.netty.buffer.ByteBuf; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public abstract class DefinedPacket +{ + + public void writeString(String s, ByteBuf buf) + { + // TODO: Check len - use Guava? + byte[] b = s.getBytes( Charsets.UTF_8 ); + writeVarInt( b.length, buf ); + buf.writeBytes( b ); + } + + public String readString(ByteBuf buf) + { + int len = readVarInt( buf ); + byte[] b = new byte[ len ]; + buf.readBytes( b ); + + return new String( b, Charsets.UTF_8 ); + } + + public void writeArray(byte[] b, ByteBuf buf) + { + // TODO: Check len - use Guava? + buf.writeShort( b.length ); + buf.writeBytes( b ); + } + + public byte[] readArray(ByteBuf buf) + { + // TODO: Check len - use Guava? + short len = buf.readShort(); + byte[] ret = new byte[ len ]; + buf.readBytes( ret ); + return ret; + } + + public int readVarInt(ByteBuf input) + { + int out = 0; + int bytes = 0; + byte in; + while ( true ) + { + in = input.readByte(); + + out |= ( in & 0x7F ) << ( bytes++ * 7 ); + + if ( bytes > 32 ) + { + throw new RuntimeException( "VarInt too big" ); + } + + if ( ( in & 0x80 ) != 0x80 ) + { + break; + } + } + + return out; + } + + public void writeVarInt(int value, ByteBuf output) + { + int part; + while ( true ) + { + part = value & 0x7F; + + value >>>= 7; + if ( value != 0 ) + { + part |= 0x80; + } + + output.writeByte( part ); + + if ( value == 0 ) + { + break; + } + } + } + + public abstract void read(ByteBuf buf); + + public abstract void write(ByteBuf buf); + + public abstract void handle(AbstractPacketHandler handler) throws Exception; + + @Override + public abstract boolean equals(Object obj); + + @Override + public abstract int hashCode(); + + @Override + public abstract String toString(); +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Forge.java b/protocol/src/main/java/net/md_5/bungee/protocol/Forge.java deleted file mode 100644 index a5707e84..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Forge.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.md_5.bungee.protocol; - -import io.netty.buffer.ByteBuf; -import lombok.Getter; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.forge.Forge1Login; -import net.md_5.bungee.protocol.skip.PacketReader; - -public class Forge extends Vanilla -{ - - @Getter - private static final Forge instance = new Forge(); - - public Forge() - { - classes[0x01] = Forge1Login.class; - skipper = new PacketReader( this ); // TODO: :( - } - - @Override - public DefinedPacket read(short packetId, ByteBuf buf) - { - int start = buf.readerIndex(); - DefinedPacket packet = read( packetId, buf, this ); - if ( buf.readerIndex() == start ) - { - packet = super.read( packetId, buf ); - } - - return packet; - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/OpCode.java b/protocol/src/main/java/net/md_5/bungee/protocol/OpCode.java deleted file mode 100644 index e201c5c8..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/OpCode.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.md_5.bungee.protocol; - -public enum OpCode -{ - - BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE, OPTIONAL_WINDOW -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 82fbd8e5..fe088e14 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -1,20 +1,78 @@ package net.md_5.bungee.protocol; -import io.netty.buffer.ByteBuf; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.map.hash.TObjectIntHashMap; import java.lang.reflect.Constructor; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.skip.PacketReader; +import net.md_5.bungee.protocol.handshake.HandshakeProtocol; -public interface Protocol +public class Protocol { - PacketReader getSkipper(); + private static final int MAX_PACKET_ID = 0xFF; + private static final int MAX_PROTOCOLS = 0xF; + /*========================================================================*/ + private static final Protocol[] protocols = new Protocol[ MAX_PROTOCOLS ]; + /*========================================================================*/ + private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); + private final Class[] packetClasses = new Class[ MAX_PACKET_ID ]; + private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; - DefinedPacket read(short packetId, ByteBuf buf); + static + { - OpCode[][] getOpCodes(); + } - Class[] getClasses(); + public Protocol(int protocolId) + { + } - Constructor[] getConstructors(); + public static Protocol getProtocol(int id) + { + return protocols[id]; + } + + public final DefinedPacket createPacket(int id) + { + if ( id > MAX_PACKET_ID ) + { + throw new BadPacketException( "Packet with id " + id + " outside of range " ); + } + if ( packetConstructors[id] == null ) + { + throw new BadPacketException( "No packet with id " + id ); + } + + try + { + return packetClasses[id].newInstance(); + } catch ( ReflectiveOperationException ex ) + { + throw new BadPacketException( "Could not construct packet with id " + id, ex ); + } + } + + protected final void registerPacket(int id, Class packetClass) + { + try + { + packetConstructors[id] = packetClass.getDeclaredConstructor(); + } catch ( NoSuchMethodException ex ) + { + throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass ); + } + packetClasses[id] = packetClass; + packetMap.put( packetClass, id ); + } + + protected final void unregisterPacket(int id) + { + packetMap.remove( packetClasses[id] ); + packetClasses[id] = null; + packetConstructors[id] = null; + } + + final int getId(Class packet) + { + return packetMap.get( packet ); + } } 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 deleted file mode 100644 index 3615181d..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Vanilla.java +++ /dev/null @@ -1,382 +0,0 @@ -package net.md_5.bungee.protocol; - -import io.netty.buffer.ByteBuf; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import lombok.Getter; -import static net.md_5.bungee.protocol.OpCode.*; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.Packet0KeepAlive; -import net.md_5.bungee.protocol.packet.Packet1Login; -import net.md_5.bungee.protocol.packet.Packet2CEntityProperties; -import net.md_5.bungee.protocol.packet.Packet2Handshake; -import net.md_5.bungee.protocol.packet.Packet3Chat; -import net.md_5.bungee.protocol.packet.Packet9Respawn; -import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; -import net.md_5.bungee.protocol.packet.PacketCBTabComplete; -import net.md_5.bungee.protocol.packet.PacketCCSettings; -import net.md_5.bungee.protocol.packet.PacketCDClientStatus; -import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective; -import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore; -import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard; -import net.md_5.bungee.protocol.packet.PacketD1Team; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; -import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; -import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; -import net.md_5.bungee.protocol.packet.PacketFEPing; -import net.md_5.bungee.protocol.packet.PacketFFKick; -import net.md_5.bungee.protocol.skip.PacketReader; - -public class Vanilla implements Protocol -{ - - public static final byte PROTOCOL_VERSION = 80; - public static final String GAME_VERSION = "13w39b"; - @Getter - private static final Vanilla instance = new Vanilla(); - /*========================================================================*/ - @Getter - private final OpCode[][] opCodes = new OpCode[ 256 ][]; - @SuppressWarnings("unchecked") - @Getter - protected Class[] classes = new Class[ 256 ]; - @SuppressWarnings("unchecked") - @Getter - private Constructor[] constructors = new Constructor[ 256 ]; - @Getter - protected PacketReader skipper; - /*========================================================================*/ - - public Vanilla() - { - classes[0x00] = Packet0KeepAlive.class; - classes[0x01] = Packet1Login.class; - classes[0x02] = Packet2Handshake.class; - classes[0x03] = Packet3Chat.class; - classes[0x09] = Packet9Respawn.class; - classes[0xC9] = PacketC9PlayerListItem.class; - classes[0x2C] = Packet2CEntityProperties.class; - classes[0xCC] = PacketCCSettings.class; - classes[0xCB] = PacketCBTabComplete.class; - classes[0xCD] = PacketCDClientStatus.class; - classes[0xCE] = PacketCEScoreboardObjective.class; - classes[0xCF] = PacketCFScoreboardScore.class; - classes[0xD0] = PacketD0DisplayScoreboard.class; - classes[0xD1] = PacketD1Team.class; - classes[0xFA] = PacketFAPluginMessage.class; - classes[0xFC] = PacketFCEncryptionResponse.class; - classes[0xFD] = PacketFDEncryptionRequest.class; - classes[0xFE] = PacketFEPing.class; - classes[0xFF] = PacketFFKick.class; - skipper = new PacketReader( this ); - } - - @Override - public DefinedPacket read(short packetId, ByteBuf buf) - { - int start = buf.readerIndex(); - DefinedPacket packet = read( packetId, buf, this ); - if ( buf.readerIndex() == start ) - { - throw new BadPacketException( "Unknown packet id " + packetId ); - } - return packet; - } - - public static DefinedPacket read(short id, ByteBuf buf, Protocol protocol) - { - DefinedPacket packet = packet( id, protocol ); - if ( packet != null ) - { - packet.read( buf ); - return packet; - } - protocol.getSkipper().tryRead( id, buf ); - return null; - } - - public static DefinedPacket packet(short id, Protocol protocol) - { - DefinedPacket ret = null; - Class clazz = protocol.getClasses()[id]; - - if ( clazz != null ) - { - try - { - Constructor constructor = protocol.getConstructors()[id]; - if ( constructor == null ) - { - constructor = clazz.getDeclaredConstructor(); - constructor.setAccessible( true ); - protocol.getConstructors()[id] = constructor; - } - - if ( constructor != null ) - { - ret = constructor.newInstance(); - } - } catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) - { - } - } - - return ret; - } - - - { - opCodes[0x04] = new OpCode[] - { - LONG, LONG - }; - opCodes[0x05] = new OpCode[] - { - INT, SHORT, ITEM - }; - opCodes[0x06] = new OpCode[] - { - INT, INT, INT - }; - opCodes[0x07] = new OpCode[] - { - INT, INT, BOOLEAN - }; - opCodes[0x08] = new OpCode[] - { - FLOAT, SHORT, FLOAT - }; - opCodes[0x0A] = new OpCode[] - { - BOOLEAN - }; - opCodes[0x0B] = new OpCode[] - { - DOUBLE, DOUBLE, DOUBLE, DOUBLE, BOOLEAN - }; - opCodes[0x0C] = new OpCode[] - { - FLOAT, FLOAT, BOOLEAN - }; - opCodes[0x0D] = new OpCode[] - { - DOUBLE, DOUBLE, DOUBLE, DOUBLE, FLOAT, FLOAT, BOOLEAN - }; - opCodes[0x0E] = new OpCode[] - { - BYTE, INT, BYTE, INT, BYTE - }; - opCodes[0x0F] = new OpCode[] - { - INT, BYTE, INT, BYTE, ITEM, BYTE, BYTE, BYTE - }; - opCodes[0x10] = new OpCode[] - { - SHORT - }; - opCodes[0x11] = new OpCode[] - { - INT, BYTE, INT, BYTE, INT - }; - opCodes[0x12] = new OpCode[] - { - INT, BYTE - }; - opCodes[0x13] = new OpCode[] - { - INT, BYTE, INT - }; - opCodes[0x14] = new OpCode[] - { - INT, STRING, STRING, INT, INT, INT, BYTE, BYTE, SHORT, METADATA - }; - opCodes[0x16] = new OpCode[] - { - INT, INT - }; - opCodes[0x17] = new OpCode[] - { - INT, BYTE, INT, INT, INT, BYTE, BYTE, OPTIONAL_MOTION - }; - opCodes[0x18] = new OpCode[] - { - INT, BYTE, INT, INT, INT, BYTE, BYTE, BYTE, SHORT, SHORT, SHORT, METADATA - }; - opCodes[0x19] = new OpCode[] - { - INT, STRING, INT, INT, INT, INT - }; - opCodes[0x1A] = new OpCode[] - { - INT, INT, INT, INT, SHORT - }; - opCodes[0x1B] = new OpCode[] - { - FLOAT, FLOAT, BOOLEAN, BOOLEAN - }; - opCodes[0x1C] = new OpCode[] - { - INT, SHORT, SHORT, SHORT - }; - opCodes[0x1D] = new OpCode[] - { - BYTE_INT - }; - opCodes[0x1E] = new OpCode[] - { - INT - }; - opCodes[0x1F] = new OpCode[] - { - INT, BYTE, BYTE, BYTE - }; - opCodes[0x20] = new OpCode[] - { - INT, BYTE, BYTE - }; - opCodes[0x21] = new OpCode[] - { - INT, BYTE, BYTE, BYTE, BYTE, BYTE - }; - opCodes[0x22] = new OpCode[] - { - INT, INT, INT, INT, BYTE, BYTE - }; - opCodes[0x23] = new OpCode[] - { - INT, BYTE - }; - opCodes[0x26] = new OpCode[] - { - INT, BYTE - }; - opCodes[0x27] = new OpCode[] - { - INT, INT, BOOLEAN - }; - opCodes[0x28] = new OpCode[] - { - INT, METADATA - }; - opCodes[0x29] = new OpCode[] - { - INT, BYTE, BYTE, SHORT - }; - opCodes[0x2A] = new OpCode[] - { - INT, BYTE - }; - opCodes[0x2B] = new OpCode[] - { - FLOAT, SHORT, SHORT - }; - opCodes[0x33] = new OpCode[] - { - INT, INT, BOOLEAN, SHORT, SHORT, INT_BYTE - }; - opCodes[0x34] = new OpCode[] - { - INT, INT, SHORT, INT_BYTE - }; - opCodes[0x35] = new OpCode[] - { - INT, BYTE, INT, SHORT, BYTE - }; - opCodes[0x36] = new OpCode[] - { - INT, SHORT, INT, BYTE, BYTE, SHORT - }; - opCodes[0x37] = new OpCode[] - { - INT, INT, INT, INT, BYTE - }; - opCodes[0x38] = new OpCode[] - { - BULK_CHUNK - }; - opCodes[0x3C] = new OpCode[] - { - DOUBLE, DOUBLE, DOUBLE, FLOAT, INT_3, FLOAT, FLOAT, FLOAT - }; - opCodes[0x3D] = new OpCode[] - { - INT, INT, BYTE, INT, INT, BOOLEAN - }; - opCodes[0x3E] = new OpCode[] - { - STRING, INT, INT, INT, FLOAT, BYTE, BYTE - }; - opCodes[0x3F] = new OpCode[] - { - STRING, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, INT - }; - opCodes[0x46] = new OpCode[] - { - BYTE, FLOAT - }; - opCodes[0x47] = new OpCode[] - { - INT, BYTE, INT, INT, INT - }; - opCodes[0x64] = new OpCode[] - { - OPTIONAL_WINDOW - }; - opCodes[0x65] = new OpCode[] - { - BYTE - }; - opCodes[0x66] = new OpCode[] - { - BYTE, SHORT, BYTE, SHORT, BOOLEAN, ITEM - }; - opCodes[0x67] = new OpCode[] - { - BYTE, SHORT, ITEM - }; - opCodes[0x68] = new OpCode[] - { - BYTE, SHORT_ITEM - }; - opCodes[0x69] = new OpCode[] - { - BYTE, SHORT, SHORT - }; - opCodes[0x6A] = new OpCode[] - { - BYTE, SHORT, BOOLEAN - }; - opCodes[0x6B] = new OpCode[] - { - SHORT, ITEM - }; - opCodes[0x6C] = new OpCode[] - { - BYTE, BYTE - }; - opCodes[0x82] = new OpCode[] - { - INT, SHORT, INT, STRING, STRING, STRING, STRING - }; - opCodes[0x83] = new OpCode[] - { - SHORT, SHORT, USHORT_BYTE - }; - opCodes[0x84] = new OpCode[] - { - INT, SHORT, INT, BYTE, SHORT_BYTE - }; - opCodes[0x85] = new OpCode[] - { - BYTE, INT, INT, INT - }; - opCodes[0xC3] = new OpCode[] - { - SHORT, SHORT, INT_BYTE - }; - opCodes[0xCA] = new OpCode[] - { - BYTE, FLOAT, FLOAT - }; - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java new file mode 100644 index 00000000..8ee68642 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java @@ -0,0 +1,16 @@ +package net.md_5.bungee.protocol.game; + +import lombok.Getter; +import net.md_5.bungee.protocol.Protocol; + +public class GameProtocol extends Protocol +{ + + @Getter + private static final GameProtocol instance = new GameProtocol(); + + private GameProtocol() + { + super( 0 ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet0KeepAlive.java similarity index 62% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet0KeepAlive.java index 9afdcb38..d7a1adee 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet0KeepAlive.java @@ -1,23 +1,22 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) public class Packet0KeepAlive extends DefinedPacket { private int randomId; - private Packet0KeepAlive() - { - super( 0x00 ); - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet15Settings.java similarity index 67% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet15Settings.java index 83c2d361..ba852647 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet15Settings.java @@ -1,31 +1,34 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketCCSettings extends DefinedPacket +public class Packet15Settings extends DefinedPacket { private String locale; private byte viewDistance; private byte chatFlags; + private boolean unknown; private byte difficulty; private boolean showCape; - private PacketCCSettings() - { - super( 0xCC ); - } - @Override public void read(ByteBuf buf) { locale = readString( buf ); viewDistance = buf.readByte(); chatFlags = buf.readByte(); + unknown = buf.readBoolean(); difficulty = buf.readByte(); showCape = buf.readBoolean(); } @@ -36,6 +39,7 @@ public class PacketCCSettings extends DefinedPacket writeString( locale, buf ); buf.writeByte( viewDistance ); buf.writeByte( chatFlags ); + buf.writeBoolean( unknown ); buf.writeByte( difficulty ); buf.writeBoolean( showCape ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet16ClientStatus.java similarity index 58% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet16ClientStatus.java index ff2d7c18..ce71376f 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet16ClientStatus.java @@ -1,27 +1,22 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketCDClientStatus extends DefinedPacket +public class Packet16ClientStatus extends DefinedPacket { private byte payload; - private PacketCDClientStatus() - { - super( 0xCD ); - } - - public PacketCDClientStatus(byte payload) - { - this(); - this.payload = payload; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet1Login.java similarity index 57% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet1Login.java index 96e12d2d..3ce6a546 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet1Login.java @@ -1,24 +1,29 @@ -package net.md_5.bungee.protocol.packet.forge; +package net.md_5.bungee.protocol.game; -import net.md_5.bungee.protocol.packet.*; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.ToString; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Forge1Login extends Packet1Login +public class Packet1Login extends DefinedPacket { - private Forge1Login() - { - super(); - } - - public Forge1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers) - { - super( entityId, levelType, gameMode, dimension, difficulty, unused, maxPlayers ); - } + private int entityId; + private String levelType; + private byte gameMode; + private int dimension; + private byte difficulty; + private byte unused; + private byte maxPlayers; @Override public void read(ByteBuf buf) @@ -26,7 +31,7 @@ public class Forge1Login extends Packet1Login entityId = buf.readInt(); levelType = readString( buf ); gameMode = buf.readByte(); - dimension = buf.readInt(); + dimension = buf.readByte(); difficulty = buf.readByte(); unused = buf.readByte(); maxPlayers = buf.readByte(); @@ -38,7 +43,7 @@ public class Forge1Login extends Packet1Login buf.writeInt( entityId ); writeString( levelType, buf ); buf.writeByte( gameMode ); - buf.writeInt( dimension ); + buf.writeByte( dimension ); buf.writeByte( difficulty ); buf.writeByte( unused ); buf.writeByte( maxPlayers ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet2Chat.java similarity index 59% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet2Chat.java index 54923cee..152ee301 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet2Chat.java @@ -1,29 +1,22 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketFFKick extends DefinedPacket +public class Packet2Chat extends DefinedPacket { private String message; - private PacketFFKick() - { - super( 0xFF ); - } - - public PacketFFKick(String message) - { - this(); - this.message = message; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3BPlayerListItem.java similarity index 59% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3BPlayerListItem.java index 9fbfaf7d..e5e7d78b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3BPlayerListItem.java @@ -1,33 +1,24 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketC9PlayerListItem extends DefinedPacket +public class Packet3BPlayerListItem extends DefinedPacket { private String username; private boolean online; private short ping; - private PacketC9PlayerListItem() - { - super( 0xC9 ); - } - - public PacketC9PlayerListItem(String username, boolean online, short ping) - { - super( 0xC9 ); - this.username = username; - this.online = online; - this.ping = ping; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3DTabComplete.java similarity index 66% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3DTabComplete.java index 01df2ff4..0474d566 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCBTabComplete.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3DTabComplete.java @@ -1,27 +1,25 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketCBTabComplete extends DefinedPacket +public class Packet3DTabComplete extends DefinedPacket { private String cursor; private String[] commands; - private PacketCBTabComplete() + public Packet3DTabComplete(String[] alternatives) { - super( 0xCB ); - } - - public PacketCBTabComplete(String[] alternatives) - { - this(); commands = alternatives; } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3EScoreboardObjective.java similarity index 61% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3EScoreboardObjective.java index db5d6033..aedaeab0 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3EScoreboardObjective.java @@ -1,14 +1,18 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketCEScoreboardObjective extends DefinedPacket +public class Packet3EScoreboardObjective extends DefinedPacket { private String name; @@ -18,19 +22,6 @@ public class PacketCEScoreboardObjective extends DefinedPacket */ private byte action; - private PacketCEScoreboardObjective() - { - super( 0xCE ); - } - - public PacketCEScoreboardObjective(String name, String text, byte action) - { - this(); - this.name = name; - this.text = text; - this.action = action; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3FScoreboardScore.java similarity index 74% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3FScoreboardScore.java index e55efa1e..c4a7fe12 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3FScoreboardScore.java @@ -1,14 +1,20 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.ToString; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketCFScoreboardScore extends DefinedPacket +public class Packet3FScoreboardScore extends DefinedPacket { private String itemName; @@ -19,11 +25,6 @@ public class PacketCFScoreboardScore extends DefinedPacket private String scoreName; private int value; - private PacketCFScoreboardScore() - { - super( 0xCF ); - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet40DisplayScoreboard.java similarity index 64% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet40DisplayScoreboard.java index de729f17..caba6d91 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet40DisplayScoreboard.java @@ -1,14 +1,18 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketD0DisplayScoreboard extends DefinedPacket +public class Packet40DisplayScoreboard extends DefinedPacket { /** @@ -17,11 +21,6 @@ public class PacketD0DisplayScoreboard extends DefinedPacket private byte position; private String name; - private PacketD0DisplayScoreboard() - { - super( 0xD0 ); - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet41Team.java similarity index 84% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet41Team.java index 69bf3771..50ababc1 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet41Team.java @@ -1,14 +1,18 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketD1Team extends DefinedPacket +public class Packet41Team extends DefinedPacket { private String name; @@ -23,17 +27,12 @@ public class PacketD1Team extends DefinedPacket private short playerCount; private String[] players; - private PacketD1Team() - { - super( 0xD1 ); - } - /** * Packet to destroy a team. * * @param name */ - public PacketD1Team(String name) + public Packet41Team(String name) { this(); this.name = name; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet42PluginMessage.java similarity index 69% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet42PluginMessage.java index d2eef89b..41a5210f 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet42PluginMessage.java @@ -1,37 +1,28 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.io.ByteArrayInputStream; import java.io.DataInput; import java.io.DataInputStream; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; import net.md_5.bungee.protocol.MinecraftInput; -import net.md_5.bungee.protocol.MinecraftOutput; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketFAPluginMessage extends DefinedPacket +public class Packet42PluginMessage extends DefinedPacket { private String tag; private byte[] data; - private PacketFAPluginMessage() - { - super( 0xFA ); - } - - public PacketFAPluginMessage(String tag, byte[] data) - { - this(); - this.tag = tag; - this.data = data; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet43Kick.java similarity index 57% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet43Kick.java index 44a60738..58a40a44 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet43Kick.java @@ -1,31 +1,22 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@Setter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet3Chat extends DefinedPacket +public class Packet43Kick extends DefinedPacket { private String message; - private Packet3Chat() - { - super( 0x03 ); - } - - public Packet3Chat(String message) - { - this(); - this.message = message; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet7Respawn.java similarity index 64% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java rename to protocol/src/main/java/net/md_5/bungee/protocol/game/Packet7Respawn.java index 3e916cbc..32c8ee7a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet7Respawn.java @@ -1,12 +1,19 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.game; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import lombok.ToString; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet9Respawn extends DefinedPacket +public class Packet7Respawn extends DefinedPacket { private int dimension; @@ -15,21 +22,6 @@ public class Packet9Respawn extends DefinedPacket private short worldHeight; private String levelType; - private Packet9Respawn() - { - super( 0x09 ); - } - - public Packet9Respawn(int dimension, byte difficulty, byte gameMode, short worldHeight, String levelType) - { - this(); - this.dimension = dimension; - this.difficulty = difficulty; - this.gameMode = gameMode; - this.worldHeight = worldHeight; - this.levelType = levelType; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java new file mode 100644 index 00000000..93877984 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java @@ -0,0 +1,17 @@ +package net.md_5.bungee.protocol.handshake; + +import lombok.Getter; +import net.md_5.bungee.protocol.Protocol; + +public class HandshakeProtocol extends Protocol +{ + + @Getter + private static final HandshakeProtocol instance = new HandshakeProtocol(); + + private HandshakeProtocol() + { + super( 0xF ); + registerPacket( 0, Packet0Handshake.class ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java new file mode 100644 index 00000000..8a9a324e --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java @@ -0,0 +1,46 @@ +package net.md_5.bungee.protocol.handshake; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.AbstractPacketHandler; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class Packet0Handshake extends DefinedPacket +{ + + private int protocolVersion; + private String serverAddress; + private int serverPort; + private int requestedProtocol; + + @Override + public void read(ByteBuf buf) + { + protocolVersion = readVarInt( buf ); + serverAddress = readString( buf ); + serverPort = readVarInt( buf ); + requestedProtocol = readVarInt( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeVarInt( protocolVersion, buf ); + writeString( serverAddress, buf ); + writeVarInt( serverPort, buf ); + writeVarInt( requestedProtocol, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java new file mode 100644 index 00000000..59794e5d --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java @@ -0,0 +1,17 @@ +package net.md_5.bungee.protocol.login; + +import net.md_5.bungee.protocol.ping.*; +import lombok.Getter; +import net.md_5.bungee.protocol.Protocol; + +public class LoginProtocol extends Protocol +{ + + @Getter + private static final LoginProtocol instance = new LoginProtocol(); + + private LoginProtocol() + { + super( 2 ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java b/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java new file mode 100644 index 00000000..0d18e2b2 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java @@ -0,0 +1,37 @@ +package net.md_5.bungee.protocol.login; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.AbstractPacketHandler; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class Packet0Kick extends DefinedPacket +{ + + private String message; + + @Override + public void read(ByteBuf buf) + { + message = readString( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeString( message, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet1EncryptionResponse.java similarity index 57% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java rename to protocol/src/main/java/net/md_5/bungee/protocol/login/Packet1EncryptionResponse.java index 2f484622..3f23a4da 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet1EncryptionResponse.java @@ -1,31 +1,23 @@ -package net.md_5.bungee.protocol.packet; +package net.md_5.bungee.protocol.login; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; -@Getter -@ToString +@Data +@NoArgsConstructor +@AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class PacketFCEncryptionResponse extends DefinedPacket +public class Packet1EncryptionResponse extends DefinedPacket { private byte[] sharedSecret; private byte[] verifyToken; - private PacketFCEncryptionResponse() - { - super( 0xFC ); - } - - public PacketFCEncryptionResponse(byte[] sharedSecret, byte[] verifyToken) - { - this(); - this.sharedSecret = sharedSecret; - this.verifyToken = verifyToken; - } - @Override public void read(ByteBuf buf) { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java b/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java new file mode 100644 index 00000000..7e0cb0f7 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java @@ -0,0 +1,37 @@ +package net.md_5.bungee.protocol.login; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.AbstractPacketHandler; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class Packet2LoginSuccess extends DefinedPacket +{ + + private String data; + + @Override + public void read(ByteBuf buf) + { + data = readString( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeString( data, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} 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 deleted file mode 100644 index b8c984c5..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -package net.md_5.bungee.protocol.packet; - -public abstract class AbstractPacketHandler -{ - - public void handle(Packet0KeepAlive alive) throws Exception - { - } - - public void handle(Packet1Login login) throws Exception - { - } - - public void handle(Packet2Handshake handshake) throws Exception - { - } - - public void handle(Packet3Chat chat) throws Exception - { - } - - public void handle(Packet9Respawn respawn) throws Exception - { - } - - public void handle(Packet2CEntityProperties properties) throws Exception - { - } - - public void handle(PacketC8Statistic statistic) throws Exception - { - } - - public void handle(PacketC9PlayerListItem playerList) throws Exception - { - } - - public void handle(PacketCCSettings settings) throws Exception - { - } - - public void handle(PacketCDClientStatus clientStatus) throws Exception - { - } - - public void handle(PacketCEScoreboardObjective objective) throws Exception - { - } - - public void handle(PacketCFScoreboardScore score) throws Exception - { - } - - public void handle(PacketD0DisplayScoreboard displayScoreboard) throws Exception - { - } - - public void handle(PacketD1Team team) throws Exception - { - } - - public void handle(PacketFAPluginMessage pluginMessage) throws Exception - { - } - - public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception - { - } - - public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception - { - } - - public void handle(PacketFEPing ping) throws Exception - { - } - - public void handle(PacketFFKick kick) throws Exception - { - } - - public void handle(PacketCBTabComplete tabComplete) throws Exception - { - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java deleted file mode 100644 index cf81095a..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.md_5.bungee.protocol.packet; - -import io.netty.buffer.ByteBuf; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public abstract class DefinedPacket -{ - - private final int id; - - public final int getId() - { - return id; - } - - public void writeString(String s, ByteBuf buf) - { - // TODO: Check len - use Guava? - buf.writeShort( s.length() ); - for ( char c : s.toCharArray() ) - { - buf.writeChar( c ); - } - } - - public String readString(ByteBuf buf) - { - // TODO: Check len - use Guava? - short len = buf.readShort(); - char[] chars = new char[ len ]; - for ( int i = 0; i < len; i++ ) - { - chars[i] = buf.readChar(); - } - return new String( chars ); - } - - public void writeArray(byte[] b, ByteBuf buf) - { - // TODO: Check len - use Guava? - buf.writeShort( b.length ); - buf.writeBytes( b ); - } - - public byte[] readArray(ByteBuf buf) - { - // TODO: Check len - use Guava? - short len = buf.readShort(); - byte[] ret = new byte[ len ]; - buf.readBytes( ret ); - return ret; - } - - public abstract void read(ByteBuf buf); - - public abstract void write(ByteBuf buf); - - public abstract void handle(AbstractPacketHandler handler) throws Exception; - - @Override - public abstract boolean equals(Object obj); - - @Override - public abstract int hashCode(); - - @Override - public abstract String toString(); -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java deleted file mode 100644 index d73674fd..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java +++ /dev/null @@ -1,73 +0,0 @@ -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 Packet1Login extends DefinedPacket -{ - - protected int entityId; - protected String levelType; - protected byte gameMode; - protected int dimension; - protected byte difficulty; - protected byte unused; - protected byte maxPlayers; - - protected Packet1Login() - { - super( 0x01 ); - } - - public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers) - { - this( entityId, levelType, gameMode, (int) dimension, difficulty, unused, maxPlayers ); - } - - public Packet1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers) - { - this(); - this.entityId = entityId; - this.levelType = levelType; - this.gameMode = gameMode; - this.dimension = dimension; - this.difficulty = difficulty; - this.unused = unused; - this.maxPlayers = maxPlayers; - } - - @Override - public void read(ByteBuf buf) - { - entityId = buf.readInt(); - levelType = readString( buf ); - gameMode = buf.readByte(); - dimension = buf.readByte(); - difficulty = buf.readByte(); - unused = buf.readByte(); - maxPlayers = buf.readByte(); - } - - @Override - public void write(ByteBuf buf) - { - buf.writeInt( entityId ); - writeString( levelType, buf ); - buf.writeByte( gameMode ); - buf.writeByte( dimension ); - buf.writeByte( difficulty ); - buf.writeByte( unused ); - buf.writeByte( maxPlayers ); - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2CEntityProperties.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2CEntityProperties.java deleted file mode 100644 index a0bd50de..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2CEntityProperties.java +++ /dev/null @@ -1,47 +0,0 @@ -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 Packet2CEntityProperties extends DefinedPacket -{ - - public Packet2CEntityProperties() - { - super( 0x2C ); - } - - @Override - public void read(ByteBuf buf) - { - buf.readInt(); - int recordCount = buf.readInt(); - for ( int i = 0; i < recordCount; i++ ) - { - readString( buf ); - buf.readDouble(); - short size = buf.readShort(); - for ( short s = 0; s < size; s++ ) - { - buf.skipBytes( 25 ); // long, long, double, byte - } - } - } - - @Override - public void write(ByteBuf buf) - { - throw new UnsupportedOperationException(); - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java deleted file mode 100644 index af8b059f..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.md_5.bungee.protocol.packet; - -import io.netty.buffer.ByteBuf; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@EqualsAndHashCode(callSuper = false) -public class Packet2Handshake extends DefinedPacket -{ - - private byte protocolVersion; - private String username; - private String host; - private int port; - - private Packet2Handshake() - { - super( 0x02 ); - } - - @Override - public void read(ByteBuf buf) - { - protocolVersion = buf.readByte(); - username = readString( buf ); - host = readString( buf ); - port = buf.readInt(); - } - - @Override - public void write(ByteBuf buf) - { - buf.writeByte( protocolVersion ); - writeString( username, buf ); - writeString( host, buf ); - buf.writeInt( port ); - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} 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 deleted file mode 100644 index 61552a8a..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC8Statistic.java +++ /dev/null @@ -1,41 +0,0 @@ -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/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java deleted file mode 100644 index 278646a0..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java +++ /dev/null @@ -1,52 +0,0 @@ -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 PacketFDEncryptionRequest extends DefinedPacket -{ - - private String serverId; - private byte[] publicKey; - private byte[] verifyToken; - - private PacketFDEncryptionRequest() - { - super( 0xFD ); - } - - public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken) - { - this(); - this.serverId = serverId; - this.publicKey = publicKey; - this.verifyToken = verifyToken; - } - - @Override - public void read(ByteBuf buf) - { - serverId = readString( buf ); - publicKey = readArray( buf ); - verifyToken = readArray( buf ); - } - - @Override - public void write(ByteBuf buf) - { - writeString( serverId, buf ); - writeArray( publicKey, buf ); - writeArray( verifyToken, buf ); - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java deleted file mode 100644 index b2824c7e..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.md_5.bungee.protocol.packet; - -import io.netty.buffer.ByteBuf; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@ToString -@EqualsAndHashCode(callSuper = false) -public class PacketFEPing extends DefinedPacket -{ - - private byte version; - - private PacketFEPing() - { - super( 0xFE ); - } - - @Override - public void read(ByteBuf buf) - { - version = buf.readByte(); - } - - @Override - public void write(ByteBuf buf) - { - buf.writeByte( version ); - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java new file mode 100644 index 00000000..5e4b7642 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java @@ -0,0 +1,16 @@ +package net.md_5.bungee.protocol.ping; + +import lombok.Getter; +import net.md_5.bungee.protocol.Protocol; + +public class PingProtocol extends Protocol +{ + + @Getter + private static final PingProtocol instance = new PingProtocol(); + + private PingProtocol() + { + super( 1 ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/BulkChunk.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/BulkChunk.java deleted file mode 100644 index 33f03e37..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/BulkChunk.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -public class BulkChunk extends Instruction -{ - - @Override - void read(ByteBuf in) - { - short count = in.readShort(); - int size = in.readInt(); - in.readBoolean(); - in.skipBytes( size + count * 12 ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/ByteHeader.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/ByteHeader.java deleted file mode 100644 index d9f99e02..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/ByteHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class ByteHeader extends Instruction -{ - - private final Instruction child; - - ByteHeader(Instruction child) - { - this.child = child; - } - - @Override - void read(ByteBuf in) - { - byte size = in.readByte(); - for ( byte b = 0; b < size; b++ ) - { - child.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/Instruction.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/Instruction.java deleted file mode 100644 index b85feeeb..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/Instruction.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -abstract class Instruction -{ - - static final Instruction BOOLEAN = new Jump( 1 ); - static final Instruction BULK_CHUNK = new BulkChunk(); - static final Instruction BYTE = new Jump( 1 ); - // BYTE_INT moved down - static final Instruction DOUBLE = new Jump( 8 ); - static final Instruction FLOAT = new Jump( 4 ); - static final Instruction INT = new Jump( 4 ); - static final Instruction INT_3 = new IntHeader( new Jump( 3 ) ); - static final Instruction INT_BYTE = new IntHeader( BYTE ); - static final Instruction ITEM = new Item(); - static final Instruction LONG = new Jump( 8 ); - static final Instruction METADATA = new MetaData(); - static final Instruction OPTIONAL_MOTION = new OptionalMotion(); - static final Instruction SHORT = new Jump( 2 ); - static final Instruction SHORT_BYTE = new ShortHeader( BYTE ); - static final Instruction SHORT_ITEM = new ShortHeader( ITEM ); - static final Instruction STRING = new ShortHeader( new Jump( 2 ) ); - static final Instruction USHORT_BYTE = new UnsignedShortByte(); - static final Instruction OPTIONAL_WINDOW = new OptionalWindow(); - // Illegal forward references below this line - static final Instruction BYTE_INT = new ByteHeader( INT ); - // Custom instructions - static final Instruction STRING_ARRAY = new ShortHeader( STRING ); - - abstract void read(ByteBuf in); -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/IntHeader.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/IntHeader.java deleted file mode 100644 index 0b87c54e..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/IntHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class IntHeader extends Instruction -{ - - private final Instruction child; - - IntHeader(Instruction child) - { - this.child = child; - } - - @Override - void read(ByteBuf in) - { - int size = in.readInt(); - for ( int i = 0; i < size; i++ ) - { - child.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/Item.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/Item.java deleted file mode 100644 index cb632e33..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/Item.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class Item extends Instruction -{ - - @Override - void read(ByteBuf in) - { - short type = in.readShort(); - if ( type >= 0 ) - { - in.skipBytes( 3 ); - SHORT_BYTE.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/Jump.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/Jump.java deleted file mode 100644 index d7c451ae..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/Jump.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class Jump extends Instruction -{ - - final int len; - - Jump(int len) - { - if ( len < 0 ) - { - throw new IndexOutOfBoundsException(); - } - this.len = len; - } - - @Override - void read(ByteBuf in) - { - in.skipBytes( len ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/MetaData.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/MetaData.java deleted file mode 100644 index 929a664f..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/MetaData.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class MetaData extends Instruction -{ - - @Override - void read(ByteBuf in) - { - int x = in.readUnsignedByte(); - while ( x != 127 ) - { - int type = x >> 5; - switch ( type ) - { - case 0: - BYTE.read( in ); - break; - case 1: - SHORT.read( in ); - break; - case 2: - INT.read( in ); - break; - case 3: - FLOAT.read( in ); - break; - case 4: - STRING.read( in ); - break; - case 5: - ITEM.read( in ); - break; - case 6: - in.skipBytes( 12 ); // int, int, int - break; - default: - throw new IllegalArgumentException( "Unknown metadata type " + type ); - } - x = in.readUnsignedByte(); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalMotion.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalMotion.java deleted file mode 100644 index 45e040fb..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalMotion.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class OptionalMotion extends Instruction -{ - - @Override - void read(ByteBuf in) - { - int data = in.readInt(); - if ( data > 0 ) - { - in.skipBytes( 6 ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalWindow.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalWindow.java deleted file mode 100644 index 1fc71340..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/OptionalWindow.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -public class OptionalWindow extends Instruction -{ - - @Override - void read(ByteBuf in) - { - BYTE.read( in ); - byte type = in.readByte(); - STRING.read( in ); - BYTE.read( in ); - BOOLEAN.read( in ); - if ( type == 11 ) - { - INT.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/PacketReader.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/PacketReader.java deleted file mode 100644 index 141b718d..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/PacketReader.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; -import java.util.ArrayList; -import java.util.List; -import net.md_5.bungee.protocol.OpCode; -import net.md_5.bungee.protocol.Protocol; - -public class PacketReader -{ - - private final Instruction[][] instructions; - - public PacketReader(Protocol protocol) - { - instructions = new Instruction[ protocol.getOpCodes().length ][]; - for ( int i = 0; i < instructions.length; i++ ) - { - List output = new ArrayList<>(); - - OpCode[] enums = protocol.getOpCodes()[i]; - if ( enums != null ) - { - for ( OpCode struct : enums ) - { - try - { - output.add( (Instruction) Instruction.class.getDeclaredField( struct.name() ).get( null ) ); - } catch ( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex ) - { - throw new UnsupportedOperationException( "No definition for " + struct.name() ); - } - } - - List crushed = new ArrayList<>(); - int nextJumpSize = 0; - for ( Instruction child : output ) - { - if ( child instanceof Jump ) - { - nextJumpSize += ( (Jump) child ).len; - } else - { - if ( nextJumpSize != 0 ) - { - crushed.add( new Jump( nextJumpSize ) ); - } - crushed.add( child ); - nextJumpSize = 0; - } - } - if ( nextJumpSize != 0 ) - { - crushed.add( new Jump( nextJumpSize ) ); - } - - instructions[i] = crushed.toArray( new Instruction[ crushed.size() ] ); - } - } - } - - public void tryRead(short packetId, ByteBuf in) - { - Instruction[] packetDef = instructions[packetId]; - - if ( packetDef != null ) - { - for ( Instruction instruction : packetDef ) - { - instruction.read( in ); - } - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/ShortHeader.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/ShortHeader.java deleted file mode 100644 index 6db71894..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/ShortHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class ShortHeader extends Instruction -{ - - private final Instruction child; - - ShortHeader(Instruction child) - { - this.child = child; - } - - @Override - void read(ByteBuf in) - { - short size = in.readShort(); - for ( short s = 0; s < size; s++ ) - { - child.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/skip/UnsignedShortByte.java b/protocol/src/main/java/net/md_5/bungee/protocol/skip/UnsignedShortByte.java deleted file mode 100644 index 3ea6ebea..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/skip/UnsignedShortByte.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.md_5.bungee.protocol.skip; - -import io.netty.buffer.ByteBuf; - -class UnsignedShortByte extends Instruction -{ - - @Override - void read(ByteBuf in) - { - int size = in.readUnsignedShort(); - in.skipBytes( size ); - } -} diff --git a/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java b/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java deleted file mode 100644 index f1596308..00000000 --- a/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.md_5.bungee.protocol; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import net.md_5.bungee.protocol.packet.AbstractPacketHandler; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import org.junit.Assert; -import org.junit.Test; - -public class PacketTest -{ - - @Test - public void testPackets() throws Exception - { - AbstractPacketHandler handler = new AbstractPacketHandler() - { - }; - - for ( short i = 0; i < 256; i++ ) - { - Class clazz = Vanilla.getInstance().getClasses()[ i]; - if ( clazz != null ) - { - Assert.assertTrue( "Packet " + clazz + " is not public", Modifier.isPublic( clazz.getModifiers() ) ); - DefinedPacket packet = Vanilla.packet( i, Vanilla.getInstance() ); - Assert.assertTrue( "Could not create packet with id " + i + " and class " + clazz, packet != null ); - Assert.assertTrue( "Packet with id " + i + " does not have correct class (expected " + clazz + " but got " + packet.getClass(), packet.getClass() == clazz ); - Assert.assertTrue( "Packet " + clazz + " does not report correct id", packet.getId() == i ); - Assert.assertTrue( "Packet " + clazz + " does not have custom hash code", packet.hashCode() != System.identityHashCode( packet ) ); - Assert.assertTrue( "Packet " + clazz + " does not have custom toString", packet.toString().indexOf( '@' ) == -1 ); - // TODO: Enable this test again in v2 - // Assert.assertTrue( "Packet " + clazz + " does not have private no args constructor", Modifier.isPrivate( clazz.getDeclaredConstructor().getModifiers() ) ); - - for ( Field field : clazz.getDeclaredFields() ) - { - // TODO: Enable this test again in v2 - // Assert.assertTrue( "Packet " + clazz + " has non private field " + field, Modifier.isPrivate( field.getModifiers() ) ); - } - - packet.handle( handler ); // Make sure there are no exceptions - } - } - } -} diff --git a/protocol/src/test/java/net/md_5/bungee/protocol/ProtocolTest.java b/protocol/src/test/java/net/md_5/bungee/protocol/ProtocolTest.java deleted file mode 100644 index d9f675ad..00000000 --- a/protocol/src/test/java/net/md_5/bungee/protocol/ProtocolTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.md_5.bungee.protocol; - -import org.junit.Assert; -import org.junit.Test; - -public class ProtocolTest -{ - - @Test - public void testProtocol() - { - Assert.assertFalse( "Protocols should have different login packet", Vanilla.getInstance().getClasses()[0x01] == Forge.getInstance().classes[0x01] ); - } -} diff --git a/proxy/pom.xml b/proxy/pom.xml index 91000270..3bee3d90 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -59,12 +59,6 @@ ${project.version} compile - - net.sf.trove4j - trove4j - 3.0.3 - compile - mysql mysql-connector-java diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 5afc2016..86c04666 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -57,9 +57,9 @@ import net.md_5.bungee.command.*; import net.md_5.bungee.config.YamlConfig; import net.md_5.bungee.log.LoggingOutputStream; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.Packet3Chat; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.game.Packet2Chat; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; import net.md_5.bungee.protocol.Vanilla; import net.md_5.bungee.query.RemoteQuery; import net.md_5.bungee.tab.Custom; @@ -447,9 +447,9 @@ public class BungeeCord extends ProxyServer return Collections.unmodifiableCollection( pluginChannels ); } - public PacketFAPluginMessage registerChannels() + public Packet42PluginMessage registerChannels() { - return new PacketFAPluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes() ); + return new Packet42PluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes() ); } @Override @@ -482,7 +482,7 @@ public class BungeeCord extends ProxyServer getConsole().sendMessage( message ); // TODO: Here too String encoded = BungeeCord.getInstance().gson.toJson( message ); - broadcast( new Packet3Chat( "{\"text\":" + encoded + "}" ) ); + broadcast( new Packet2Chat( "{\"text\":" + encoded + "}" ) ); } public void addConnection(UserConnection con) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 489b2082..bc0908a1 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -25,8 +25,8 @@ import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; @RequiredArgsConstructor public class BungeeServerInfo implements ServerInfo @@ -97,7 +97,7 @@ public class BungeeServerInfo implements ServerInfo server.sendData( channel, data ); } else { - packetQueue.add( new PacketFAPluginMessage( channel, data ) ); + packetQueue.add( new Packet42PluginMessage( channel, data ) ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 046a84d2..2432240e 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -15,7 +15,7 @@ import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import lombok.Getter; -import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; /** @@ -49,7 +49,7 @@ public class EncryptionUtil return new PacketFDEncryptionRequest( hash, pubKey, verify ); } - public static SecretKey getSecret(PacketFCEncryptionResponse resp, PacketFDEncryptionRequest request) throws GeneralSecurityException + public static SecretKey getSecret(Packet1EncryptionResponse resp, PacketFDEncryptionRequest request) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance( "RSA" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java index e63212da..730a24af 100644 --- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java @@ -1,18 +1,18 @@ package net.md_5.bungee; -import net.md_5.bungee.protocol.packet.Packet9Respawn; -import net.md_5.bungee.protocol.packet.PacketCDClientStatus; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.game.Packet7Respawn; +import net.md_5.bungee.protocol.game.Packet16ClientStatus; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; public class PacketConstants { - public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); - public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); - public static final PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 ); - public static final PacketFAPluginMessage FORGE_MOD_REQUEST = new PacketFAPluginMessage( "FML", new byte[] + public static final Packet7Respawn DIM1_SWITCH = new Packet7Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); + public static final Packet7Respawn DIM2_SWITCH = new Packet7Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); + public static final Packet16ClientStatus CLIENT_LOGIN = new Packet16ClientStatus( (byte) 0 ); + public static final Packet42PluginMessage FORGE_MOD_REQUEST = new Packet42PluginMessage( "FML", new byte[] { 0, 0, 0, 0, 0, 2 } ); - public static final PacketFAPluginMessage I_AM_BUNGEE = new PacketFAPluginMessage( "BungeeCord", new byte[ 0 ] ); + public static final Packet42PluginMessage I_AM_BUNGEE = new Packet42PluginMessage( "BungeeCord", new byte[ 0 ] ); } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 555b0ff4..92e133d9 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -7,9 +7,9 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.netty.ChannelWrapper; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; -import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.game.Packet43Kick; @RequiredArgsConstructor public class ServerConnection implements Server @@ -34,7 +34,7 @@ public class ServerConnection implements Server @Override public void sendData(String channel, byte[] data) { - unsafe().sendPacket( new PacketFAPluginMessage( channel, data ) ); + unsafe().sendPacket( new Packet42PluginMessage( channel, data ) ); } @Override @@ -43,7 +43,7 @@ public class ServerConnection implements Server if ( !ch.isClosed() ) { // TODO: Can we just use a future here? - unsafe().sendPacket( new PacketFFKick( reason ) ); + unsafe().sendPacket( new Packet43Kick( reason ) ); ch.getHandle().eventLoop().schedule( new Runnable() { @Override diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index a410ff5f..f8ac88e2 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -30,15 +30,15 @@ import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.MinecraftOutput; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.Packet1Login; -import net.md_5.bungee.protocol.packet.Packet9Respawn; -import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective; -import net.md_5.bungee.protocol.packet.PacketD1Team; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; -import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.game.Packet1Login; +import net.md_5.bungee.protocol.game.Packet7Respawn; +import net.md_5.bungee.protocol.game.Packet3EScoreboardObjective; +import net.md_5.bungee.protocol.game.Packet41Team; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; -import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.game.Packet43Kick; import net.md_5.bungee.protocol.packet.forge.Forge1Login; @RequiredArgsConstructor @@ -81,7 +81,7 @@ public class ServerConnector extends PacketHandler out.writeUTF( "Login" ); out.writeUTF( user.getAddress().getHostString() ); out.writeInt( user.getAddress().getPort() ); - channel.write( new PacketFAPluginMessage( "BungeeCord", out.toByteArray() ) ); + channel.write( new Packet42PluginMessage( "BungeeCord", out.toByteArray() ) ); channel.write( user.getPendingConnection().getHandshake() ); @@ -117,13 +117,13 @@ public class ServerConnector extends PacketHandler } } - for ( PacketFAPluginMessage message : user.getPendingConnection().getRegisterMessages() ) + for ( Packet42PluginMessage message : user.getPendingConnection().getRegisterMessages() ) { ch.write( message ); } if ( !sentMessages ) { - for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() ) + for ( Packet42PluginMessage message : user.getPendingConnection().getLoginMessages() ) { ch.write( message ); } @@ -157,7 +157,7 @@ public class ServerConnector extends PacketHandler MinecraftOutput out = new MinecraftOutput(); out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); - user.unsafe().sendPacket( new PacketFAPluginMessage( "MC|Brand", out.toArray() ) ); + user.unsafe().sendPacket( new Packet42PluginMessage( "MC|Brand", out.toArray() ) ); } else { user.getTabList().onServerChange(); @@ -165,18 +165,18 @@ public class ServerConnector extends PacketHandler Scoreboard serverScoreboard = user.getServerSentScoreboard(); for ( Objective objective : serverScoreboard.getObjectives() ) { - user.unsafe().sendPacket( new PacketCEScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); + user.unsafe().sendPacket( new Packet3EScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); } for ( Team team : serverScoreboard.getTeams() ) { - user.unsafe().sendPacket( new PacketD1Team( team.getName() ) ); + user.unsafe().sendPacket( new Packet41Team( team.getName() ) ); } serverScoreboard.clear(); user.sendDimensionSwitch(); user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Packet9Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) ); + user.unsafe().sendPacket( new Packet7Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) ); // Remove from old servers user.getServer().setObsolete( true ); @@ -222,7 +222,7 @@ public class ServerConnector extends PacketHandler byte[] shared = EncryptionUtil.encrypt( publickey, secretkey.getEncoded() ); byte[] token = EncryptionUtil.encrypt( publickey, encryptRequest.getVerifyToken() ); - ch.write( new PacketFCEncryptionResponse( shared, token ) ); + ch.write( new Packet1EncryptionResponse( shared, token ) ); Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, secretkey ); ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); @@ -235,7 +235,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception + public void handle(Packet1EncryptionResponse encryptResponse) throws Exception { Preconditions.checkState( thisState == State.ENCRYPT_RESPONSE, "Not expecting ENCRYPT_RESPONSE" ); @@ -249,7 +249,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(PacketFFKick kick) throws Exception + public void handle(Packet43Kick kick) throws Exception { ServerInfo def = bungee.getServerInfo( user.getPendingConnection().getListener().getFallbackServer() ); if ( Objects.equals( target, def ) ) @@ -274,7 +274,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(PacketFAPluginMessage pluginMessage) throws Exception + public void handle(Packet42PluginMessage pluginMessage) throws Exception { if ( pluginMessage.equals( PacketConstants.I_AM_BUNGEE ) ) { @@ -299,7 +299,7 @@ public class ServerConnector extends PacketHandler user.unsafe().sendPacket( pluginMessage ); // We have to forward these to the user, especially with Forge as stuff might break if ( !sentMessages && user.getPendingConnection().getForgeLogin() != null ) { - for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() ) + for ( Packet42PluginMessage message : user.getPendingConnection().getLoginMessages() ) { ch.write( message ); } 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 5d39ff7f..37779bda 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -32,11 +32,11 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PacketWrapper; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.Packet3Chat; -import net.md_5.bungee.protocol.packet.PacketCCSettings; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; -import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.game.Packet2Chat; +import net.md_5.bungee.protocol.game.Packet15Settings; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.game.Packet43Kick; import net.md_5.bungee.util.CaseInsensitiveSet; @RequiredArgsConstructor @@ -88,7 +88,7 @@ public final class UserConnection implements ProxiedPlayer private int serverEntityId; @Getter @Setter - private PacketCCSettings settings; + private Packet15Settings settings; @Getter private final Scoreboard serverSentScoreboard = new Scoreboard(); /*========================================================================*/ @@ -251,7 +251,7 @@ public final class UserConnection implements ProxiedPlayer if ( ch.getHandle().isActive() ) { bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + reason ); - unsafe().sendPacket( new PacketFFKick( reason ) ); + unsafe().sendPacket( new Packet43Kick( reason ) ); ch.close(); if ( server != null ) { @@ -264,7 +264,7 @@ public final class UserConnection implements ProxiedPlayer public void chat(String message) { Preconditions.checkState( server != null, "Not connected to server" ); - server.getCh().write( new Packet3Chat( message ) ); + server.getCh().write( new Packet2Chat( message ) ); } @Override @@ -272,7 +272,7 @@ public final class UserConnection implements ProxiedPlayer { // TODO: Fix this String encoded = BungeeCord.getInstance().gson.toJson( message ); - unsafe().sendPacket( new Packet3Chat( "{\"text\":" + encoded + "}" ) ); + unsafe().sendPacket( new Packet2Chat( "{\"text\":" + encoded + "}" ) ); } @Override @@ -287,7 +287,7 @@ public final class UserConnection implements ProxiedPlayer @Override public void sendData(String channel, byte[] data) { - unsafe().sendPacket( new PacketFAPluginMessage( channel, data ) ); + unsafe().sendPacket( new Packet42PluginMessage( channel, data ) ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 2e9286d8..42ffb09b 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -22,14 +22,14 @@ import net.md_5.bungee.api.score.Team; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketWrapper; -import net.md_5.bungee.protocol.packet.Packet0KeepAlive; -import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; -import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective; -import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore; -import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard; -import net.md_5.bungee.protocol.packet.PacketD1Team; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; -import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.game.Packet0KeepAlive; +import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; +import net.md_5.bungee.protocol.game.Packet3EScoreboardObjective; +import net.md_5.bungee.protocol.game.Packet3FScoreboardScore; +import net.md_5.bungee.protocol.game.Packet40DisplayScoreboard; +import net.md_5.bungee.protocol.game.Packet41Team; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.game.Packet43Kick; @RequiredArgsConstructor public class DownstreamBridge extends PacketHandler @@ -88,7 +88,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketC9PlayerListItem playerList) throws Exception + public void handle(Packet3BPlayerListItem playerList) throws Exception { if ( !con.getTabList().onListUpdate( playerList.getUsername(), playerList.isOnline(), playerList.getPing() ) ) @@ -98,7 +98,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketCEScoreboardObjective objective) throws Exception + public void handle(Packet3EScoreboardObjective objective) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); switch ( objective.getAction() ) @@ -113,7 +113,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketCFScoreboardScore score) throws Exception + public void handle(Packet3FScoreboardScore score) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); switch ( score.getAction() ) @@ -130,7 +130,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketD0DisplayScoreboard displayScoreboard) throws Exception + public void handle(Packet40DisplayScoreboard displayScoreboard) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); serverScoreboard.setName( displayScoreboard.getName() ); @@ -138,7 +138,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketD1Team team) throws Exception + public void handle(Packet41Team team) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); // Remove team and move on @@ -185,7 +185,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketFAPluginMessage pluginMessage) throws Exception + public void handle(Packet42PluginMessage pluginMessage) throws Exception { DataInput in = pluginMessage.getStream(); PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() ); @@ -330,7 +330,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(PacketFFKick kick) throws Exception + public void handle(Packet43Kick kick) throws Exception { ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() ); if ( Objects.equals( server.getInfo(), def ) ) 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 e885f311..ef793f67 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 @@ -44,15 +44,15 @@ import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.MinecraftInput; import net.md_5.bungee.protocol.Vanilla; -import net.md_5.bungee.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.Packet1Login; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.game.Packet1Login; import net.md_5.bungee.protocol.packet.Packet2Handshake; -import net.md_5.bungee.protocol.packet.PacketCDClientStatus; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; -import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.game.Packet16ClientStatus; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; import net.md_5.bungee.protocol.packet.PacketFEPing; -import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.game.Packet43Kick; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; @@ -70,9 +70,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection private Packet2Handshake handshake; private PacketFDEncryptionRequest request; @Getter - private List loginMessages = new ArrayList<>(); + private List loginMessages = new ArrayList<>(); @Getter - private List registerMessages = new ArrayList<>(); + private List registerMessages = new ArrayList<>(); private State thisState = State.HANDSHAKE; private SecretKey sharedKey; private final Unsafe unsafe = new Unsafe() @@ -110,7 +110,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(PacketFAPluginMessage pluginMessage) throws Exception + public void handle(Packet42PluginMessage pluginMessage) throws Exception { if ( pluginMessage.getTag().equals( "MC|PingHost" ) ) { @@ -243,7 +243,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(final PacketFCEncryptionResponse encryptResponse) throws Exception + public void handle(final Packet1EncryptionResponse encryptResponse) throws Exception { Preconditions.checkState( thisState == State.ENCRYPT, "Not expecting ENCRYPT" ); @@ -323,7 +323,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( ch.getHandle().isActive() ) { - unsafe().sendPacket( new PacketFCEncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); + unsafe().sendPacket( new Packet1EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); try { Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); @@ -343,7 +343,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(PacketCDClientStatus clientStatus) throws Exception + public void handle(Packet16ClientStatus clientStatus) throws Exception { Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" ); @@ -373,7 +373,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( !ch.isClosed() ) { - unsafe().sendPacket( new PacketFFKick( reason ) ); + unsafe().sendPacket( new Packet43Kick( reason ) ); ch.close(); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index 20b5abef..dfca6b64 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -8,7 +8,7 @@ import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.game.Packet43Kick; @RequiredArgsConstructor public class PingHandler extends PacketHandler @@ -34,7 +34,7 @@ public class PingHandler extends PacketHandler } @Override - public void handle(PacketFFKick kick) throws Exception + public void handle(Packet43Kick kick) throws Exception { String[] split = kick.getMessage().split( "\00" ); ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index d2e5afef..8648d0e6 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -11,11 +11,11 @@ import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketWrapper; -import net.md_5.bungee.protocol.packet.Packet0KeepAlive; -import net.md_5.bungee.protocol.packet.Packet3Chat; -import net.md_5.bungee.protocol.packet.PacketCBTabComplete; -import net.md_5.bungee.protocol.packet.PacketCCSettings; -import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.game.Packet0KeepAlive; +import net.md_5.bungee.protocol.game.Packet2Chat; +import net.md_5.bungee.protocol.game.Packet3DTabComplete; +import net.md_5.bungee.protocol.game.Packet15Settings; +import net.md_5.bungee.protocol.game.Packet42PluginMessage; import java.util.ArrayList; import java.util.List; @@ -78,7 +78,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(Packet3Chat chat) throws Exception + public void handle(Packet2Chat chat) throws Exception { ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() ); if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) @@ -93,7 +93,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(PacketCBTabComplete tabComplete) throws Exception + public void handle(Packet3DTabComplete tabComplete) throws Exception { if ( tabComplete.getCursor().startsWith( "/" ) ) { @@ -102,20 +102,20 @@ public class UpstreamBridge extends PacketHandler if ( !results.isEmpty() ) { - con.unsafe().sendPacket( new PacketCBTabComplete( results.toArray( new String[ results.size() ] ) ) ); + con.unsafe().sendPacket( new Packet3DTabComplete( results.toArray( new String[ results.size() ] ) ) ); throw new CancelSendSignal(); } } } @Override - public void handle(PacketCCSettings settings) throws Exception + public void handle(Packet15Settings settings) throws Exception { con.setSettings( settings ); } @Override - public void handle(PacketFAPluginMessage pluginMessage) throws Exception + public void handle(Packet42PluginMessage pluginMessage) throws Exception { if ( pluginMessage.getTag().equals( "BungeeCord" ) ) { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java b/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java index cfa34503..c5e8b8ff 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java @@ -4,7 +4,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.DefinedPacket; @ChannelHandler.Sharable public class DefinedPacketEncoder extends MessageToByteEncoder diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java index 47043da4..99e959aa 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import net.md_5.bungee.protocol.Protocol; -import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.skip.PacketReader; /** diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java index ca4684ff..e5634c92 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java @@ -1,6 +1,6 @@ package net.md_5.bungee.netty; -public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.AbstractPacketHandler +public abstract class PacketHandler extends net.md_5.bungee.protocol.AbstractPacketHandler { @Override diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java index b61cfd04..2d0f66fc 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java @@ -3,7 +3,7 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; import lombok.RequiredArgsConstructor; import lombok.Setter; -import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.DefinedPacket; @RequiredArgsConstructor public class PacketWrapper diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java index b38ae4b1..86c2a084 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java @@ -7,7 +7,7 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.tab.CustomTabList; import net.md_5.bungee.api.tab.TabListAdapter; -import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; public class Custom extends TabListAdapter implements CustomTabList { @@ -96,7 +96,7 @@ public class Custom extends TabListAdapter implements CustomTabList { String text = ( slots[i][j] != null ) ? slots[i][j] : new StringBuilder().append( base( i ) ).append( base( j ) ).toString(); sent[i][j] = text; - getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( text, true, (short) 0 ) ); + getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( text, true, (short) 0 ) ); } } } @@ -112,7 +112,7 @@ public class Custom extends TabListAdapter implements CustomTabList { String text = sent[i][j]; sent[i][j] = null; - getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( text, false, (short) 9999 ) ); + getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( text, false, (short) 9999 ) ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Global.java b/proxy/src/main/java/net/md_5/bungee/tab/Global.java index ccc4f014..82c327a5 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/Global.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/Global.java @@ -4,7 +4,7 @@ import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.tab.TabListAdapter; -import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; public class Global extends TabListAdapter { @@ -16,9 +16,9 @@ public class Global extends TabListAdapter { for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() ) { - getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) ); + getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) ); } - BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); + BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); } @Override @@ -27,14 +27,14 @@ public class Global extends TabListAdapter if ( !sentPing ) { sentPing = true; - BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); + BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); } } @Override public void onDisconnect() { - BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), false, (short) 9999 ) ); + BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), false, (short) 9999 ) ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java index c7233a2a..15633ff9 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java @@ -2,7 +2,7 @@ package net.md_5.bungee.tab; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; public class GlobalPing extends Global { @@ -17,7 +17,7 @@ public class GlobalPing extends Global if ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing ) { lastPing = ping; - BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), true, (short) ping ) ); + BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), true, (short) ping ) ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java index 722987b1..f2969279 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java @@ -3,7 +3,7 @@ package net.md_5.bungee.tab; import java.util.Collection; import java.util.HashSet; import net.md_5.bungee.api.tab.TabListAdapter; -import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; public class ServerUnique extends TabListAdapter { @@ -17,7 +17,7 @@ public class ServerUnique extends TabListAdapter { for ( String username : usernames ) { - getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( username, false, (short) 9999 ) ); + getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( username, false, (short) 9999 ) ); } usernames.clear(); } From 7be929bb089bad2446e51c715128fa6f656b5ab2 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 11 Oct 2013 19:26:40 +1100 Subject: [PATCH 03/24] Update protocol - major overhaul --- .../protocol/AbstractPacketHandler.java | 83 +++++++------- .../net/md_5/bungee/protocol/Protocol.java | 108 +++++++++++++++--- .../bungee/protocol/game/GameProtocol.java | 16 --- .../protocol/handshake/HandshakeProtocol.java | 17 --- .../bungee/protocol/login/LoginProtocol.java | 17 --- .../Packet2Chat.java => packet/Chat.java} | 4 +- .../ClientSettings.java} | 4 +- .../ClientStatus.java} | 4 +- .../EncryptionResponse.java} | 4 +- .../Handshake.java} | 4 +- .../KeepAlive.java} | 4 +- .../Packet0Kick.java => packet/Kick.java} | 6 +- .../Packet1Login.java => packet/Login.java} | 6 +- .../LoginRequest.java} | 16 ++- .../LoginSuccess.java} | 4 +- .../PlayerListItem.java} | 4 +- .../PluginMessage.java} | 4 +- .../Respawn.java} | 4 +- .../ScoreboardDisplay.java} | 4 +- .../ScoreboardObjective.java} | 4 +- .../ScoreboardScore.java} | 4 +- .../TabComplete.java} | 6 +- .../Packet41Team.java => packet/Team.java} | 6 +- .../bungee/protocol/ping/PingProtocol.java | 16 --- .../main/java/net/md_5/bungee/BungeeCord.java | 10 +- .../net/md_5/bungee/BungeeServerInfo.java | 4 +- .../java/net/md_5/bungee/EncryptionUtil.java | 4 +- .../java/net/md_5/bungee/PacketConstants.java | 16 +-- .../net/md_5/bungee/ServerConnection.java | 8 +- .../java/net/md_5/bungee/ServerConnector.java | 44 +++---- .../java/net/md_5/bungee/UserConnection.java | 18 +-- .../bungee/connection/DownstreamBridge.java | 32 +++--- .../bungee/connection/InitialHandler.java | 28 ++--- .../md_5/bungee/connection/PingHandler.java | 4 +- .../bungee/connection/UpstreamBridge.java | 22 ++-- .../main/java/net/md_5/bungee/tab/Custom.java | 6 +- .../main/java/net/md_5/bungee/tab/Global.java | 10 +- .../java/net/md_5/bungee/tab/GlobalPing.java | 4 +- .../net/md_5/bungee/tab/ServerUnique.java | 4 +- 39 files changed, 285 insertions(+), 278 deletions(-) delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet2Chat.java => packet/Chat.java} (89%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet15Settings.java => packet/ClientSettings.java} (93%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet16ClientStatus.java => packet/ClientStatus.java} (87%) rename protocol/src/main/java/net/md_5/bungee/protocol/{login/Packet1EncryptionResponse.java => packet/EncryptionResponse.java} (89%) rename protocol/src/main/java/net/md_5/bungee/protocol/{handshake/Packet0Handshake.java => packet/Handshake.java} (91%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet0KeepAlive.java => packet/KeepAlive.java} (84%) rename protocol/src/main/java/net/md_5/bungee/protocol/{login/Packet0Kick.java => packet/Kick.java} (88%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet1Login.java => packet/Login.java} (90%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet43Kick.java => packet/LoginRequest.java} (67%) rename protocol/src/main/java/net/md_5/bungee/protocol/{login/Packet2LoginSuccess.java => packet/LoginSuccess.java} (87%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet3BPlayerListItem.java => packet/PlayerListItem.java} (90%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet42PluginMessage.java => packet/PluginMessage.java} (92%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet7Respawn.java => packet/Respawn.java} (92%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet40DisplayScoreboard.java => packet/ScoreboardDisplay.java} (89%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet3EScoreboardObjective.java => packet/ScoreboardObjective.java} (90%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet3FScoreboardScore.java => packet/ScoreboardScore.java} (92%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet3DTabComplete.java => packet/TabComplete.java} (86%) rename protocol/src/main/java/net/md_5/bungee/protocol/{game/Packet41Team.java => packet/Team.java} (94%) delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index d9fd51ff..5ee2fd17 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -1,95 +1,96 @@ package net.md_5.bungee.protocol; -import net.md_5.bungee.protocol.handshake.Packet0Handshake; -import net.md_5.bungee.protocol.login.Packet0Kick; -import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; -import net.md_5.bungee.protocol.login.Packet2LoginSuccess; +import net.md_5.bungee.protocol.packet.KeepAlive; +import net.md_5.bungee.protocol.packet.ClientSettings; +import net.md_5.bungee.protocol.packet.ClientStatus; +import net.md_5.bungee.protocol.packet.Login; +import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.packet.PlayerListItem; +import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.ScoreboardObjective; +import net.md_5.bungee.protocol.packet.ScoreboardScore; +import net.md_5.bungee.protocol.packet.ScoreboardDisplay; +import net.md_5.bungee.protocol.packet.Team; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.Kick; +import net.md_5.bungee.protocol.packet.Respawn; +import net.md_5.bungee.protocol.packet.Handshake; +import net.md_5.bungee.protocol.packet.EncryptionResponse; +import net.md_5.bungee.protocol.packet.LoginRequest; +import net.md_5.bungee.protocol.packet.LoginSuccess; public abstract class AbstractPacketHandler { - /*========================================================================*/ - // Handshake Start - public void handle(Packet0Handshake handshake) throws Exception - { - } - // Handshake End - /*========================================================================*/ - // Game Start - - public void handle(Packet0Handshake handshake) throws Exception + public void handle(Handshake handshake) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(KeepAlive keepAlive) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(Login login) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(Chat chat) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(Respawn respawn) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(LoginRequest loginRequest) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(ClientSettings settings) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(ClientStatus clientStatus) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(PlayerListItem playerListItem) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(TabComplete tabComplete) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(ScoreboardObjective scoreboardObjective) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(ScoreboardScore scoreboardScore) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception + public void handle(ScoreboardDisplay displayScoreboard) throws Exception { } - public void handle(Packet0Handshake handshake) throws Exception - { - } - // Game End - /*========================================================================*/ - // Ping Start - // Ping End - /*========================================================================*/ - // Login Start - - public void handle(Packet0Kick kick) throws Exception + public void handle(Team team) throws Exception { } - public void handle(Packet1EncryptionResponse encryptionResponse) throws Exception + public void handle(PluginMessage pluginMessage) throws Exception { } - public void handle(Packet2LoginSuccess loginSuccess) throws Exception + public void handle(Kick kick) throws Exception + { + } + + public void handle(EncryptionResponse encryptionResponse) throws Exception + { + } + + public void handle(LoginSuccess loginSuccess) throws Exception { } - // Login End - /*========================================================================*/ } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index fe088e14..d9f28385 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -3,34 +3,104 @@ package net.md_5.bungee.protocol; import gnu.trove.map.TObjectIntMap; import gnu.trove.map.hash.TObjectIntHashMap; import java.lang.reflect.Constructor; -import net.md_5.bungee.protocol.handshake.HandshakeProtocol; +import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.packet.ClientSettings; +import net.md_5.bungee.protocol.packet.EncryptionResponse; +import net.md_5.bungee.protocol.packet.Handshake; +import net.md_5.bungee.protocol.packet.KeepAlive; +import net.md_5.bungee.protocol.packet.Kick; +import net.md_5.bungee.protocol.packet.Login; +import net.md_5.bungee.protocol.packet.LoginRequest; +import net.md_5.bungee.protocol.packet.LoginSuccess; +import net.md_5.bungee.protocol.packet.PlayerListItem; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.Respawn; +import net.md_5.bungee.protocol.packet.ScoreboardDisplay; +import net.md_5.bungee.protocol.packet.ScoreboardObjective; +import net.md_5.bungee.protocol.packet.ScoreboardScore; +import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.Team; -public class Protocol +public enum Protocol { - private static final int MAX_PACKET_ID = 0xFF; - private static final int MAX_PROTOCOLS = 0xF; + // Undef + SERVER_HANDSHAKE + { + + { + registerPacket( 0x00, Handshake.class ); + } + }, + // 0 + CLIENT_GAME + { + + { + registerPacket( 0x00, KeepAlive.class ); + registerPacket( 0x01, Login.class ); + registerPacket( 0x02, Chat.class ); + registerPacket( 0x07, Respawn.class ); + registerPacket( 0x3B, PlayerListItem.class ); + registerPacket( 0x3D, TabComplete.class ); + registerPacket( 0x3E, ScoreboardObjective.class ); + registerPacket( 0x3F, ScoreboardScore.class ); + registerPacket( 0x40, ScoreboardDisplay.class ); + registerPacket( 0x41, Team.class ); + registerPacket( 0x42, PluginMessage.class ); + registerPacket( 0x43, Kick.class ); + } + }, + // 0 + SERVER_GAME + { + + { + registerPacket( 0x00, KeepAlive.class ); + registerPacket( 0x14, TabComplete.class ); + registerPacket( 0x15, ClientSettings.class ); + registerPacket( 0x17, PluginMessage.class ); + } + }, + // 1 + CLIENT_STATUS + { + + { + } + }, + // 1 + SERVER_STATUS + { + + { + } + }, + // 2 + CLIENT_LOGIN + { + + { + registerPacket( 0x00, Kick.class ); + registerPacket( 0x01, EncryptionResponse.class ); + registerPacket( 0x02, LoginSuccess.class ); + } + }, + // 2 + SERVER_LOGIN + { + + { + registerPacket( 0x00, LoginRequest.class ); + } + }; /*========================================================================*/ - private static final Protocol[] protocols = new Protocol[ MAX_PROTOCOLS ]; + public static final int MAX_PACKET_ID = 0xFF; /*========================================================================*/ private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); private final Class[] packetClasses = new Class[ MAX_PACKET_ID ]; private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; - static - { - - } - - public Protocol(int protocolId) - { - } - - public static Protocol getProtocol(int id) - { - return protocols[id]; - } - public final DefinedPacket createPacket(int id) { if ( id > MAX_PACKET_ID ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java deleted file mode 100644 index 8ee68642..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/GameProtocol.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.md_5.bungee.protocol.game; - -import lombok.Getter; -import net.md_5.bungee.protocol.Protocol; - -public class GameProtocol extends Protocol -{ - - @Getter - private static final GameProtocol instance = new GameProtocol(); - - private GameProtocol() - { - super( 0 ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java deleted file mode 100644 index 93877984..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/handshake/HandshakeProtocol.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.md_5.bungee.protocol.handshake; - -import lombok.Getter; -import net.md_5.bungee.protocol.Protocol; - -public class HandshakeProtocol extends Protocol -{ - - @Getter - private static final HandshakeProtocol instance = new HandshakeProtocol(); - - private HandshakeProtocol() - { - super( 0xF ); - registerPacket( 0, Packet0Handshake.class ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java deleted file mode 100644 index 59794e5d..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/login/LoginProtocol.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.md_5.bungee.protocol.login; - -import net.md_5.bungee.protocol.ping.*; -import lombok.Getter; -import net.md_5.bungee.protocol.Protocol; - -public class LoginProtocol extends Protocol -{ - - @Getter - private static final LoginProtocol instance = new LoginProtocol(); - - private LoginProtocol() - { - super( 2 ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet2Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java similarity index 89% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet2Chat.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java index 152ee301..40e92d68 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet2Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet2Chat extends DefinedPacket +public class Chat extends DefinedPacket { private String message; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet15Settings.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java similarity index 93% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet15Settings.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java index ba852647..e3078ba0 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet15Settings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet15Settings extends DefinedPacket +public class ClientSettings extends DefinedPacket { private String locale; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet16ClientStatus.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientStatus.java similarity index 87% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet16ClientStatus.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientStatus.java index ce71376f..d4314dc5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet16ClientStatus.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientStatus.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet16ClientStatus extends DefinedPacket +public class ClientStatus extends DefinedPacket { private byte payload; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet1EncryptionResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java similarity index 89% rename from protocol/src/main/java/net/md_5/bungee/protocol/login/Packet1EncryptionResponse.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java index 3f23a4da..443c7a5b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet1EncryptionResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.login; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet1EncryptionResponse extends DefinedPacket +public class EncryptionResponse extends DefinedPacket { private byte[] sharedSecret; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java similarity index 91% rename from protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java index 8a9a324e..47d12299 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/handshake/Packet0Handshake.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.handshake; +package net.md_5.bungee.protocol.packet; import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet0Handshake extends DefinedPacket +public class Handshake extends DefinedPacket { private int protocolVersion; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet0KeepAlive.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java similarity index 84% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet0KeepAlive.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java index d7a1adee..12065ac4 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet0KeepAlive.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet0KeepAlive extends DefinedPacket +public class KeepAlive extends DefinedPacket { private int randomId; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Kick.java similarity index 88% rename from protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Kick.java index 0d18e2b2..05ae1ae0 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet0Kick.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Kick.java @@ -1,18 +1,18 @@ -package net.md_5.bungee.protocol.login; +package net.md_5.bungee.protocol.packet; +import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.AbstractPacketHandler; @Data @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet0Kick extends DefinedPacket +public class Kick extends DefinedPacket { private String message; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet1Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java similarity index 90% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet1Login.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index 3ce6a546..65510da6 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet1Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -1,20 +1,18 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.ToString; import net.md_5.bungee.protocol.AbstractPacketHandler; @Data @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet1Login extends DefinedPacket +public class Login extends DefinedPacket { private int entityId; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet43Kick.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java similarity index 67% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet43Kick.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java index 58a40a44..32ba098c 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet43Kick.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java @@ -1,32 +1,36 @@ -package net.md_5.bungee.protocol.game; +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package net.md_5.bungee.protocol.packet; -import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; @Data @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet43Kick extends DefinedPacket +public class LoginRequest extends DefinedPacket { - private String message; + private String data; @Override public void read(ByteBuf buf) { - message = readString( buf ); + data = readString( buf ); } @Override public void write(ByteBuf buf) { - writeString( message, buf ); + writeString( data, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java similarity index 87% rename from protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java index 7e0cb0f7..ed9e5b57 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/login/Packet2LoginSuccess.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.login; +package net.md_5.bungee.protocol.packet; import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet2LoginSuccess extends DefinedPacket +public class LoginSuccess extends DefinedPacket { private String data; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3BPlayerListItem.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java similarity index 90% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3BPlayerListItem.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java index e5e7d78b..9182c1cc 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3BPlayerListItem.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet3BPlayerListItem extends DefinedPacket +public class PlayerListItem extends DefinedPacket { private String username; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet42PluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java similarity index 92% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet42PluginMessage.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java index 41a5210f..57d4efea 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet42PluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -17,7 +17,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet42PluginMessage extends DefinedPacket +public class PluginMessage extends DefinedPacket { private String tag; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet7Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java similarity index 92% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet7Respawn.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java index 32c8ee7a..b6e60599 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet7Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -13,7 +13,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet7Respawn extends DefinedPacket +public class Respawn extends DefinedPacket { private int dimension; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet40DisplayScoreboard.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardDisplay.java similarity index 89% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet40DisplayScoreboard.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardDisplay.java index caba6d91..3a6830db 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet40DisplayScoreboard.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardDisplay.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet40DisplayScoreboard extends DefinedPacket +public class ScoreboardDisplay extends DefinedPacket { /** diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3EScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java similarity index 90% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3EScoreboardObjective.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java index aedaeab0..e2b61e48 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3EScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet3EScoreboardObjective extends DefinedPacket +public class ScoreboardObjective extends DefinedPacket { private String name; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3FScoreboardScore.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java similarity index 92% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3FScoreboardScore.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java index c4a7fe12..58dfa17c 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3FScoreboardScore.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -14,7 +14,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet3FScoreboardScore extends DefinedPacket +public class ScoreboardScore extends DefinedPacket { private String itemName; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3DTabComplete.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java similarity index 86% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3DTabComplete.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java index 0474d566..ec9ca0c4 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet3DTabComplete.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,13 +12,13 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet3DTabComplete extends DefinedPacket +public class TabComplete extends DefinedPacket { private String cursor; private String[] commands; - public Packet3DTabComplete(String[] alternatives) + public TabComplete(String[] alternatives) { commands = alternatives; } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet41Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java similarity index 94% rename from protocol/src/main/java/net/md_5/bungee/protocol/game/Packet41Team.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java index 50ababc1..2ecce118 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/game/Packet41Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.protocol.game; +package net.md_5.bungee.protocol.packet; import net.md_5.bungee.protocol.DefinedPacket; import io.netty.buffer.ByteBuf; @@ -12,7 +12,7 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class Packet41Team extends DefinedPacket +public class Team extends DefinedPacket { private String name; @@ -32,7 +32,7 @@ public class Packet41Team extends DefinedPacket * * @param name */ - public Packet41Team(String name) + public Team(String name) { this(); this.name = name; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java deleted file mode 100644 index 5e4b7642..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/ping/PingProtocol.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.md_5.bungee.protocol.ping; - -import lombok.Getter; -import net.md_5.bungee.protocol.Protocol; - -public class PingProtocol extends Protocol -{ - - @Getter - private static final PingProtocol instance = new PingProtocol(); - - private PingProtocol() - { - super( 1 ); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 86c04666..d04db1a2 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -58,8 +58,8 @@ import net.md_5.bungee.config.YamlConfig; import net.md_5.bungee.log.LoggingOutputStream; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.game.Packet2Chat; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.Vanilla; import net.md_5.bungee.query.RemoteQuery; import net.md_5.bungee.tab.Custom; @@ -447,9 +447,9 @@ public class BungeeCord extends ProxyServer return Collections.unmodifiableCollection( pluginChannels ); } - public Packet42PluginMessage registerChannels() + public PluginMessage registerChannels() { - return new Packet42PluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes() ); + return new PluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes() ); } @Override @@ -482,7 +482,7 @@ public class BungeeCord extends ProxyServer getConsole().sendMessage( message ); // TODO: Here too String encoded = BungeeCord.getInstance().gson.toJson( message ); - broadcast( new Packet2Chat( "{\"text\":" + encoded + "}" ) ); + broadcast( new Chat( "{\"text\":" + encoded + "}" ) ); } public void addConnection(UserConnection con) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index bc0908a1..48e46ed1 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -26,7 +26,7 @@ import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.packet.PluginMessage; @RequiredArgsConstructor public class BungeeServerInfo implements ServerInfo @@ -97,7 +97,7 @@ public class BungeeServerInfo implements ServerInfo server.sendData( channel, data ); } else { - packetQueue.add( new Packet42PluginMessage( channel, data ) ); + packetQueue.add( new PluginMessage( channel, data ) ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 2432240e..15a87766 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -15,7 +15,7 @@ import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import lombok.Getter; -import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; +import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; /** @@ -49,7 +49,7 @@ public class EncryptionUtil return new PacketFDEncryptionRequest( hash, pubKey, verify ); } - public static SecretKey getSecret(Packet1EncryptionResponse resp, PacketFDEncryptionRequest request) throws GeneralSecurityException + public static SecretKey getSecret(EncryptionResponse resp, PacketFDEncryptionRequest request) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance( "RSA" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java index 730a24af..b2072618 100644 --- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java @@ -1,18 +1,18 @@ package net.md_5.bungee; -import net.md_5.bungee.protocol.game.Packet7Respawn; -import net.md_5.bungee.protocol.game.Packet16ClientStatus; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.packet.Respawn; +import net.md_5.bungee.protocol.packet.ClientStatus; +import net.md_5.bungee.protocol.packet.PluginMessage; public class PacketConstants { - public static final Packet7Respawn DIM1_SWITCH = new Packet7Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); - public static final Packet7Respawn DIM2_SWITCH = new Packet7Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); - public static final Packet16ClientStatus CLIENT_LOGIN = new Packet16ClientStatus( (byte) 0 ); - public static final Packet42PluginMessage FORGE_MOD_REQUEST = new Packet42PluginMessage( "FML", new byte[] + public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); + public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); + public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 ); + public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[] { 0, 0, 0, 0, 0, 2 } ); - public static final Packet42PluginMessage I_AM_BUNGEE = new Packet42PluginMessage( "BungeeCord", new byte[ 0 ] ); + public static final PluginMessage I_AM_BUNGEE = new PluginMessage( "BungeeCord", new byte[ 0 ] ); } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 92e133d9..b5c5af50 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -8,8 +8,8 @@ import lombok.Setter; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; -import net.md_5.bungee.protocol.game.Packet43Kick; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.Kick; @RequiredArgsConstructor public class ServerConnection implements Server @@ -34,7 +34,7 @@ public class ServerConnection implements Server @Override public void sendData(String channel, byte[] data) { - unsafe().sendPacket( new Packet42PluginMessage( channel, data ) ); + unsafe().sendPacket( new PluginMessage( channel, data ) ); } @Override @@ -43,7 +43,7 @@ public class ServerConnection implements Server if ( !ch.isClosed() ) { // TODO: Can we just use a future here? - unsafe().sendPacket( new Packet43Kick( reason ) ); + unsafe().sendPacket( new Kick( reason ) ); ch.getHandle().eventLoop().schedule( new Runnable() { @Override diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index f8ac88e2..42c1e83e 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -31,14 +31,14 @@ import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.game.Packet1Login; -import net.md_5.bungee.protocol.game.Packet7Respawn; -import net.md_5.bungee.protocol.game.Packet3EScoreboardObjective; -import net.md_5.bungee.protocol.game.Packet41Team; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; -import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; +import net.md_5.bungee.protocol.packet.Login; +import net.md_5.bungee.protocol.packet.Respawn; +import net.md_5.bungee.protocol.packet.ScoreboardObjective; +import net.md_5.bungee.protocol.packet.Team; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; -import net.md_5.bungee.protocol.game.Packet43Kick; +import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.forge.Forge1Login; @RequiredArgsConstructor @@ -81,7 +81,7 @@ public class ServerConnector extends PacketHandler out.writeUTF( "Login" ); out.writeUTF( user.getAddress().getHostString() ); out.writeInt( user.getAddress().getPort() ); - channel.write( new Packet42PluginMessage( "BungeeCord", out.toByteArray() ) ); + channel.write( new PluginMessage( "BungeeCord", out.toByteArray() ) ); channel.write( user.getPendingConnection().getHandshake() ); @@ -99,7 +99,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(Packet1Login login) throws Exception + public void handle(Login login) throws Exception { Preconditions.checkState( thisState == State.LOGIN, "Not exepcting LOGIN" ); @@ -117,13 +117,13 @@ public class ServerConnector extends PacketHandler } } - for ( Packet42PluginMessage message : user.getPendingConnection().getRegisterMessages() ) + for ( PluginMessage message : user.getPendingConnection().getRegisterMessages() ) { ch.write( message ); } if ( !sentMessages ) { - for ( Packet42PluginMessage message : user.getPendingConnection().getLoginMessages() ) + for ( PluginMessage message : user.getPendingConnection().getLoginMessages() ) { ch.write( message ); } @@ -143,21 +143,21 @@ public class ServerConnector extends PacketHandler user.setServerEntityId( login.getEntityId() ); // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability - Packet1Login modLogin; + Login modLogin; if ( ch.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == Forge.getInstance() ) { modLogin = new Forge1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), login.getDimension(), login.getDifficulty(), login.getUnused(), (byte) user.getPendingConnection().getListener().getTabListSize() ); } else { - modLogin = new Packet1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(), + modLogin = new Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(), (byte) user.getPendingConnection().getListener().getTabListSize() ); } user.unsafe().sendPacket( modLogin ); MinecraftOutput out = new MinecraftOutput(); out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); - user.unsafe().sendPacket( new Packet42PluginMessage( "MC|Brand", out.toArray() ) ); + user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) ); } else { user.getTabList().onServerChange(); @@ -165,18 +165,18 @@ public class ServerConnector extends PacketHandler Scoreboard serverScoreboard = user.getServerSentScoreboard(); for ( Objective objective : serverScoreboard.getObjectives() ) { - user.unsafe().sendPacket( new Packet3EScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); + user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) ); } for ( Team team : serverScoreboard.getTeams() ) { - user.unsafe().sendPacket( new Packet41Team( team.getName() ) ); + user.unsafe().sendPacket( new Team( team.getName() ) ); } serverScoreboard.clear(); user.sendDimensionSwitch(); user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Packet7Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) ); + user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) ); // Remove from old servers user.getServer().setObsolete( true ); @@ -222,7 +222,7 @@ public class ServerConnector extends PacketHandler byte[] shared = EncryptionUtil.encrypt( publickey, secretkey.getEncoded() ); byte[] token = EncryptionUtil.encrypt( publickey, encryptRequest.getVerifyToken() ); - ch.write( new Packet1EncryptionResponse( shared, token ) ); + ch.write( new EncryptionResponse( shared, token ) ); Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, secretkey ); ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); @@ -235,7 +235,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(Packet1EncryptionResponse encryptResponse) throws Exception + public void handle(EncryptionResponse encryptResponse) throws Exception { Preconditions.checkState( thisState == State.ENCRYPT_RESPONSE, "Not expecting ENCRYPT_RESPONSE" ); @@ -249,7 +249,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(Packet43Kick kick) throws Exception + public void handle(Kick kick) throws Exception { ServerInfo def = bungee.getServerInfo( user.getPendingConnection().getListener().getFallbackServer() ); if ( Objects.equals( target, def ) ) @@ -274,7 +274,7 @@ public class ServerConnector extends PacketHandler } @Override - public void handle(Packet42PluginMessage pluginMessage) throws Exception + public void handle(PluginMessage pluginMessage) throws Exception { if ( pluginMessage.equals( PacketConstants.I_AM_BUNGEE ) ) { @@ -299,7 +299,7 @@ public class ServerConnector extends PacketHandler user.unsafe().sendPacket( pluginMessage ); // We have to forward these to the user, especially with Forge as stuff might break if ( !sentMessages && user.getPendingConnection().getForgeLogin() != null ) { - for ( Packet42PluginMessage message : user.getPendingConnection().getLoginMessages() ) + for ( PluginMessage message : user.getPendingConnection().getLoginMessages() ) { ch.write( message ); } 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 37779bda..117f86c1 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -33,10 +33,10 @@ import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PacketWrapper; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.game.Packet2Chat; -import net.md_5.bungee.protocol.game.Packet15Settings; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; -import net.md_5.bungee.protocol.game.Packet43Kick; +import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.packet.ClientSettings; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.util.CaseInsensitiveSet; @RequiredArgsConstructor @@ -88,7 +88,7 @@ public final class UserConnection implements ProxiedPlayer private int serverEntityId; @Getter @Setter - private Packet15Settings settings; + private ClientSettings settings; @Getter private final Scoreboard serverSentScoreboard = new Scoreboard(); /*========================================================================*/ @@ -251,7 +251,7 @@ public final class UserConnection implements ProxiedPlayer if ( ch.getHandle().isActive() ) { bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + reason ); - unsafe().sendPacket( new Packet43Kick( reason ) ); + unsafe().sendPacket( new Kick( reason ) ); ch.close(); if ( server != null ) { @@ -264,7 +264,7 @@ public final class UserConnection implements ProxiedPlayer public void chat(String message) { Preconditions.checkState( server != null, "Not connected to server" ); - server.getCh().write( new Packet2Chat( message ) ); + server.getCh().write( new Chat( message ) ); } @Override @@ -272,7 +272,7 @@ public final class UserConnection implements ProxiedPlayer { // TODO: Fix this String encoded = BungeeCord.getInstance().gson.toJson( message ); - unsafe().sendPacket( new Packet2Chat( "{\"text\":" + encoded + "}" ) ); + unsafe().sendPacket( new Chat( "{\"text\":" + encoded + "}" ) ); } @Override @@ -287,7 +287,7 @@ public final class UserConnection implements ProxiedPlayer @Override public void sendData(String channel, byte[] data) { - unsafe().sendPacket( new Packet42PluginMessage( channel, data ) ); + unsafe().sendPacket( new PluginMessage( channel, data ) ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 42ffb09b..e6da72e3 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -22,14 +22,14 @@ import net.md_5.bungee.api.score.Team; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketWrapper; -import net.md_5.bungee.protocol.game.Packet0KeepAlive; -import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; -import net.md_5.bungee.protocol.game.Packet3EScoreboardObjective; -import net.md_5.bungee.protocol.game.Packet3FScoreboardScore; -import net.md_5.bungee.protocol.game.Packet40DisplayScoreboard; -import net.md_5.bungee.protocol.game.Packet41Team; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; -import net.md_5.bungee.protocol.game.Packet43Kick; +import net.md_5.bungee.protocol.packet.KeepAlive; +import net.md_5.bungee.protocol.packet.PlayerListItem; +import net.md_5.bungee.protocol.packet.ScoreboardObjective; +import net.md_5.bungee.protocol.packet.ScoreboardScore; +import net.md_5.bungee.protocol.packet.ScoreboardDisplay; +import net.md_5.bungee.protocol.packet.Team; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.Kick; @RequiredArgsConstructor public class DownstreamBridge extends PacketHandler @@ -81,14 +81,14 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet0KeepAlive alive) throws Exception + public void handle(KeepAlive alive) throws Exception { con.setSentPingId( alive.getRandomId() ); con.setSentPingTime( System.currentTimeMillis() ); } @Override - public void handle(Packet3BPlayerListItem playerList) throws Exception + public void handle(PlayerListItem playerList) throws Exception { if ( !con.getTabList().onListUpdate( playerList.getUsername(), playerList.isOnline(), playerList.getPing() ) ) @@ -98,7 +98,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet3EScoreboardObjective objective) throws Exception + public void handle(ScoreboardObjective objective) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); switch ( objective.getAction() ) @@ -113,7 +113,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet3FScoreboardScore score) throws Exception + public void handle(ScoreboardScore score) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); switch ( score.getAction() ) @@ -130,7 +130,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet40DisplayScoreboard displayScoreboard) throws Exception + public void handle(ScoreboardDisplay displayScoreboard) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); serverScoreboard.setName( displayScoreboard.getName() ); @@ -138,7 +138,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet41Team team) throws Exception + public void handle(Team team) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); // Remove team and move on @@ -185,7 +185,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet42PluginMessage pluginMessage) throws Exception + public void handle(PluginMessage pluginMessage) throws Exception { DataInput in = pluginMessage.getStream(); PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() ); @@ -330,7 +330,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Packet43Kick kick) throws Exception + public void handle(Kick kick) throws Exception { ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() ); if ( Objects.equals( server.getInfo(), def ) ) 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 ef793f67..c150b090 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 @@ -45,14 +45,14 @@ import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.MinecraftInput; import net.md_5.bungee.protocol.Vanilla; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.game.Packet1Login; +import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Packet2Handshake; -import net.md_5.bungee.protocol.game.Packet16ClientStatus; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; -import net.md_5.bungee.protocol.login.Packet1EncryptionResponse; +import net.md_5.bungee.protocol.packet.ClientStatus; +import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; import net.md_5.bungee.protocol.packet.PacketFEPing; -import net.md_5.bungee.protocol.game.Packet43Kick; +import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; @@ -65,14 +65,14 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Getter private final ListenerInfo listener; @Getter - private Packet1Login forgeLogin; + private Login forgeLogin; @Getter private Packet2Handshake handshake; private PacketFDEncryptionRequest request; @Getter - private List loginMessages = new ArrayList<>(); + private List loginMessages = new ArrayList<>(); @Getter - private List registerMessages = new ArrayList<>(); + private List registerMessages = new ArrayList<>(); private State thisState = State.HANDSHAKE; private SecretKey sharedKey; private final Unsafe unsafe = new Unsafe() @@ -110,7 +110,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(Packet42PluginMessage pluginMessage) throws Exception + public void handle(PluginMessage pluginMessage) throws Exception { if ( pluginMessage.getTag().equals( "MC|PingHost" ) ) { @@ -188,7 +188,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(Packet1Login login) throws Exception + public void handle(Login login) throws Exception { Preconditions.checkState( thisState == State.LOGIN, "Not expecting FORGE LOGIN" ); Preconditions.checkState( forgeLogin == null, "Already received FORGE LOGIN" ); @@ -243,7 +243,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(final Packet1EncryptionResponse encryptResponse) throws Exception + public void handle(final EncryptionResponse encryptResponse) throws Exception { Preconditions.checkState( thisState == State.ENCRYPT, "Not expecting ENCRYPT" ); @@ -323,7 +323,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( ch.getHandle().isActive() ) { - unsafe().sendPacket( new Packet1EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); + unsafe().sendPacket( new EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); try { Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); @@ -343,7 +343,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } @Override - public void handle(Packet16ClientStatus clientStatus) throws Exception + public void handle(ClientStatus clientStatus) throws Exception { Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" ); @@ -373,7 +373,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( !ch.isClosed() ) { - unsafe().sendPacket( new Packet43Kick( reason ) ); + unsafe().sendPacket( new Kick( reason ) ); ch.close(); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index dfca6b64..32370e2a 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -8,7 +8,7 @@ import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.protocol.game.Packet43Kick; +import net.md_5.bungee.protocol.packet.Kick; @RequiredArgsConstructor public class PingHandler extends PacketHandler @@ -34,7 +34,7 @@ public class PingHandler extends PacketHandler } @Override - public void handle(Packet43Kick kick) throws Exception + public void handle(Kick kick) throws Exception { String[] split = kick.getMessage().split( "\00" ); ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 8648d0e6..eae12258 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -11,11 +11,11 @@ import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketWrapper; -import net.md_5.bungee.protocol.game.Packet0KeepAlive; -import net.md_5.bungee.protocol.game.Packet2Chat; -import net.md_5.bungee.protocol.game.Packet3DTabComplete; -import net.md_5.bungee.protocol.game.Packet15Settings; -import net.md_5.bungee.protocol.game.Packet42PluginMessage; +import net.md_5.bungee.protocol.packet.KeepAlive; +import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.ClientSettings; +import net.md_5.bungee.protocol.packet.PluginMessage; import java.util.ArrayList; import java.util.List; @@ -67,7 +67,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(Packet0KeepAlive alive) throws Exception + public void handle(KeepAlive alive) throws Exception { if ( alive.getRandomId() == con.getSentPingId() ) { @@ -78,7 +78,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(Packet2Chat chat) throws Exception + public void handle(Chat chat) throws Exception { ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() ); if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) @@ -93,7 +93,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(Packet3DTabComplete tabComplete) throws Exception + public void handle(TabComplete tabComplete) throws Exception { if ( tabComplete.getCursor().startsWith( "/" ) ) { @@ -102,20 +102,20 @@ public class UpstreamBridge extends PacketHandler if ( !results.isEmpty() ) { - con.unsafe().sendPacket( new Packet3DTabComplete( results.toArray( new String[ results.size() ] ) ) ); + con.unsafe().sendPacket( new TabComplete( results.toArray( new String[ results.size() ] ) ) ); throw new CancelSendSignal(); } } } @Override - public void handle(Packet15Settings settings) throws Exception + public void handle(ClientSettings settings) throws Exception { con.setSettings( settings ); } @Override - public void handle(Packet42PluginMessage pluginMessage) throws Exception + public void handle(PluginMessage pluginMessage) throws Exception { if ( pluginMessage.getTag().equals( "BungeeCord" ) ) { diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java index 86c2a084..902d2cf6 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java @@ -7,7 +7,7 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.tab.CustomTabList; import net.md_5.bungee.api.tab.TabListAdapter; -import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; +import net.md_5.bungee.protocol.packet.PlayerListItem; public class Custom extends TabListAdapter implements CustomTabList { @@ -96,7 +96,7 @@ public class Custom extends TabListAdapter implements CustomTabList { String text = ( slots[i][j] != null ) ? slots[i][j] : new StringBuilder().append( base( i ) ).append( base( j ) ).toString(); sent[i][j] = text; - getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( text, true, (short) 0 ) ); + getPlayer().unsafe().sendPacket( new PlayerListItem( text, true, (short) 0 ) ); } } } @@ -112,7 +112,7 @@ public class Custom extends TabListAdapter implements CustomTabList { String text = sent[i][j]; sent[i][j] = null; - getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( text, false, (short) 9999 ) ); + getPlayer().unsafe().sendPacket( new PlayerListItem( text, false, (short) 9999 ) ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Global.java b/proxy/src/main/java/net/md_5/bungee/tab/Global.java index 82c327a5..608513e4 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/Global.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/Global.java @@ -4,7 +4,7 @@ import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.tab.TabListAdapter; -import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; +import net.md_5.bungee.protocol.packet.PlayerListItem; public class Global extends TabListAdapter { @@ -16,9 +16,9 @@ public class Global extends TabListAdapter { for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() ) { - getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) ); + getPlayer().unsafe().sendPacket( new PlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) ); } - BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); + BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); } @Override @@ -27,14 +27,14 @@ public class Global extends TabListAdapter if ( !sentPing ) { sentPing = true; - BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); + BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) ); } } @Override public void onDisconnect() { - BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), false, (short) 9999 ) ); + BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), false, (short) 9999 ) ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java index 15633ff9..0c6a1169 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java @@ -2,7 +2,7 @@ package net.md_5.bungee.tab; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; +import net.md_5.bungee.protocol.packet.PlayerListItem; public class GlobalPing extends Global { @@ -17,7 +17,7 @@ public class GlobalPing extends Global if ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing ) { lastPing = ping; - BungeeCord.getInstance().broadcast( new Packet3BPlayerListItem( getPlayer().getDisplayName(), true, (short) ping ) ); + BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), true, (short) ping ) ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java index f2969279..00dc2074 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java @@ -3,7 +3,7 @@ package net.md_5.bungee.tab; import java.util.Collection; import java.util.HashSet; import net.md_5.bungee.api.tab.TabListAdapter; -import net.md_5.bungee.protocol.game.Packet3BPlayerListItem; +import net.md_5.bungee.protocol.packet.PlayerListItem; public class ServerUnique extends TabListAdapter { @@ -17,7 +17,7 @@ public class ServerUnique extends TabListAdapter { for ( String username : usernames ) { - getPlayer().unsafe().sendPacket( new Packet3BPlayerListItem( username, false, (short) 9999 ) ); + getPlayer().unsafe().sendPacket( new PlayerListItem( username, false, (short) 9999 ) ); } usernames.clear(); } From d900417d95b4cb76c0cff23200930d3297cb0ee9 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 11 Oct 2013 20:00:54 +1100 Subject: [PATCH 04/24] It compiles --- .../java/net/md_5/bungee/api/ProxyServer.java | 2 +- .../api/connection/PendingConnection.java | 2 +- .../api/event/PlayerHandshakeEvent.java | 5 +- protocol/pom.xml | 2 +- .../protocol/AbstractPacketHandler.java | 5 ++ .../md_5/bungee/protocol/DefinedPacket.java | 12 +-- .../md_5/bungee/protocol/MinecraftCodec.java | 38 +++++++++ .../md_5/bungee/protocol}/PacketWrapper.java | 2 +- .../net/md_5/bungee/protocol/Protocol.java | 11 ++- .../protocol/packet/EncryptionRequest.java | 43 ++++++++++ .../bungee/protocol/packet/Handshake.java | 12 +-- .../main/java/net/md_5/bungee/BungeeCord.java | 8 +- .../java/net/md_5/bungee/EncryptionUtil.java | 10 +-- .../java/net/md_5/bungee/ServerConnector.java | 53 ++---------- .../java/net/md_5/bungee/UserConnection.java | 2 +- .../bungee/connection/DownstreamBridge.java | 5 +- .../bungee/connection/InitialHandler.java | 81 +++++++++---------- .../bungee/connection/UpstreamBridge.java | 2 +- .../net/md_5/bungee/netty/ChannelWrapper.java | 1 + .../bungee/netty/DefinedPacketEncoder.java | 19 ----- .../net/md_5/bungee/netty/HandlerBoss.java | 1 + .../net/md_5/bungee/netty/PacketDecoder.java | 50 ------------ .../net/md_5/bungee/netty/PacketHandler.java | 2 + .../net/md_5/bungee/netty/PipelineUtils.java | 17 ++-- 24 files changed, 186 insertions(+), 199 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java rename {proxy/src/main/java/net/md_5/bungee/netty => protocol/src/main/java/net/md_5/bungee/protocol}/PacketWrapper.java (93%) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java index 474391e1..b4894ab4 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java @@ -180,7 +180,7 @@ public abstract class ProxyServer * * @return the Minecraft protocol version */ - public abstract byte getProtocolVersion(); + public abstract int getProtocolVersion(); /** * Factory method to construct an implementation specific server info 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 f0cb572a..8513e8e3 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 @@ -21,7 +21,7 @@ public interface PendingConnection extends Connection * * @return the protocol version of the remote client */ - byte getVersion(); + int getVersion(); /** * Get the requested virtual host that the client tried to connect to. diff --git a/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java b/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java index de927325..06db41e1 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java @@ -6,6 +6,7 @@ import lombok.ToString; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.protocol.packet.Packet2Handshake; import net.md_5.bungee.api.plugin.Event; +import net.md_5.bungee.protocol.packet.Handshake; /** * Event called to represent a player first making their presence and username @@ -24,9 +25,9 @@ public class PlayerHandshakeEvent extends Event /** * The handshake. */ - private final Packet2Handshake handshake; + private final Handshake handshake; - public PlayerHandshakeEvent(PendingConnection connection, Packet2Handshake handshake) + public PlayerHandshakeEvent(PendingConnection connection, Handshake handshake) { this.connection = connection; this.handshake = handshake; diff --git a/protocol/pom.xml b/protocol/pom.xml index e13e8062..c25d094d 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -21,7 +21,7 @@ io.netty - netty-buffer + netty-codec ${netty.version} compile diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 5ee2fd17..6101c314 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -5,6 +5,7 @@ import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Chat; +import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.TabComplete; import net.md_5.bungee.protocol.packet.ScoreboardObjective; @@ -70,6 +71,10 @@ public abstract class AbstractPacketHandler { } + public void handle(EncryptionRequest encryptionRequest) throws Exception + { + } + public void handle(ScoreboardDisplay displayScoreboard) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index c3a034bc..be342952 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -8,7 +8,7 @@ import lombok.RequiredArgsConstructor; public abstract class DefinedPacket { - public void writeString(String s, ByteBuf buf) + public static void writeString(String s, ByteBuf buf) { // TODO: Check len - use Guava? byte[] b = s.getBytes( Charsets.UTF_8 ); @@ -16,7 +16,7 @@ public abstract class DefinedPacket buf.writeBytes( b ); } - public String readString(ByteBuf buf) + public static String readString(ByteBuf buf) { int len = readVarInt( buf ); byte[] b = new byte[ len ]; @@ -25,14 +25,14 @@ public abstract class DefinedPacket return new String( b, Charsets.UTF_8 ); } - public void writeArray(byte[] b, ByteBuf buf) + public static void writeArray(byte[] b, ByteBuf buf) { // TODO: Check len - use Guava? buf.writeShort( b.length ); buf.writeBytes( b ); } - public byte[] readArray(ByteBuf buf) + public static byte[] readArray(ByteBuf buf) { // TODO: Check len - use Guava? short len = buf.readShort(); @@ -41,7 +41,7 @@ public abstract class DefinedPacket return ret; } - public int readVarInt(ByteBuf input) + public static int readVarInt(ByteBuf input) { int out = 0; int bytes = 0; @@ -66,7 +66,7 @@ public abstract class DefinedPacket return out; } - public void writeVarInt(int value, ByteBuf output) + public static void writeVarInt(int value, ByteBuf output) { int part; while ( true ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java new file mode 100644 index 00000000..530253ea --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java @@ -0,0 +1,38 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageCodec; +import java.util.List; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class MinecraftCodec extends MessageToMessageCodec +{ + + private Protocol protocol; + + @Override + protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, List out) throws Exception + { + ByteBuf buf = ctx.alloc().buffer(); + DefinedPacket.writeVarInt( protocol.getId( msg.getClass() ), buf ); + msg.write( buf ); + } + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception + { + int packetId = DefinedPacket.readVarInt( msg ); + + ByteBuf copy = msg.copy(); + DefinedPacket packet = null; + if ( protocol.hasPacket( packetId ) ) + { + packet = protocol.createPacket( packetId ); + packet.read( msg ); + } + + out.add( new PacketWrapper( packet, copy ) ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java b/protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java similarity index 93% rename from proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java rename to protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java index 2d0f66fc..44610630 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java @@ -1,4 +1,4 @@ -package net.md_5.bungee.netty; +package net.md_5.bungee.protocol; import io.netty.buffer.ByteBuf; import lombok.RequiredArgsConstructor; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index d9f28385..fdcce8b7 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -5,6 +5,7 @@ import gnu.trove.map.hash.TObjectIntHashMap; import java.lang.reflect.Constructor; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClientSettings; +import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.KeepAlive; @@ -82,7 +83,7 @@ public enum Protocol { registerPacket( 0x00, Kick.class ); - registerPacket( 0x01, EncryptionResponse.class ); + registerPacket( 0x01, EncryptionRequest.class ); registerPacket( 0x02, LoginSuccess.class ); } }, @@ -92,15 +93,23 @@ public enum Protocol { registerPacket( 0x00, LoginRequest.class ); + registerPacket( 0x01, EncryptionResponse.class ); } }; /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; + public static final int PROTOCOL_VERSION = 0x00; + public static final String MINECRAFT_VERSION = "13w41a"; /*========================================================================*/ private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); private final Class[] packetClasses = new Class[ MAX_PACKET_ID ]; private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; + public boolean hasPacket(int id) + { + return id < MAX_PACKET_ID && packetConstructors[id] != null; + } + public final DefinedPacket createPacket(int id) { if ( id > MAX_PACKET_ID ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java new file mode 100644 index 00000000..4521f6c3 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java @@ -0,0 +1,43 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class EncryptionRequest extends DefinedPacket +{ + + private String serverId; + private byte[] publicKey; + private byte[] verifyToken; + + @Override + public void read(ByteBuf buf) + { + serverId = readString( buf ); + publicKey = readArray( buf ); + verifyToken = readArray( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeString( serverId, buf ); + writeArray( publicKey, buf ); + writeArray( verifyToken, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java index 47d12299..ed55d472 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java @@ -16,16 +16,16 @@ public class Handshake extends DefinedPacket { private int protocolVersion; - private String serverAddress; - private int serverPort; + private String host; + private int port; private int requestedProtocol; @Override public void read(ByteBuf buf) { protocolVersion = readVarInt( buf ); - serverAddress = readString( buf ); - serverPort = readVarInt( buf ); + host = readString( buf ); + port = readVarInt( buf ); requestedProtocol = readVarInt( buf ); } @@ -33,8 +33,8 @@ public class Handshake extends DefinedPacket public void write(ByteBuf buf) { writeVarInt( protocolVersion, buf ); - writeString( serverAddress, buf ); - writeVarInt( serverPort, buf ); + writeString( host, buf ); + writeVarInt( port, buf ); writeVarInt( requestedProtocol, buf ); } diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index d04db1a2..751d2e21 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -58,9 +58,9 @@ import net.md_5.bungee.config.YamlConfig; import net.md_5.bungee.log.LoggingOutputStream; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.PluginMessage; -import net.md_5.bungee.protocol.Vanilla; import net.md_5.bungee.query.RemoteQuery; import net.md_5.bungee.tab.Custom; import net.md_5.bungee.util.CaseInsensitiveMap; @@ -453,15 +453,15 @@ public class BungeeCord extends ProxyServer } @Override - public byte getProtocolVersion() + public int getProtocolVersion() { - return Vanilla.PROTOCOL_VERSION; + return Protocol.PROTOCOL_VERSION; } @Override public String getGameVersion() { - return Vanilla.GAME_VERSION; + return Protocol.MINECRAFT_VERSION; } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 15a87766..9cc2140d 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -16,7 +16,7 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import lombok.Getter; import net.md_5.bungee.protocol.packet.EncryptionResponse; -import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; +import net.md_5.bungee.protocol.packet.EncryptionRequest; /** * Class containing all encryption related methods for the proxy. @@ -40,16 +40,16 @@ public class EncryptionUtil } } - public static PacketFDEncryptionRequest encryptRequest(boolean onlinemode) + public static EncryptionRequest encryptRequest(boolean onlinemode) { String hash = ( onlinemode ) ? Long.toString( random.nextLong(), 16 ) : "-"; byte[] pubKey = keys.getPublic().getEncoded(); byte[] verify = new byte[ 4 ]; random.nextBytes( verify ); - return new PacketFDEncryptionRequest( hash, pubKey, verify ); + return new EncryptionRequest( hash, pubKey, verify ); } - public static SecretKey getSecret(EncryptionResponse resp, PacketFDEncryptionRequest request) throws GeneralSecurityException + public static SecretKey getSecret(EncryptionResponse resp, EncryptionRequest request) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance( "RSA" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); @@ -71,7 +71,7 @@ public class EncryptionUtil return cip; } - public static PublicKey getPubkey(PacketFDEncryptionRequest request) throws GeneralSecurityException + public static PublicKey getPubkey(EncryptionRequest request) throws GeneralSecurityException { return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.getPublicKey() ) ); } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 42c1e83e..b4a51d8c 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -4,7 +4,6 @@ import com.google.common.base.Preconditions; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import java.io.DataInput; -import java.security.PublicKey; import java.util.Objects; import java.util.Queue; import javax.crypto.Cipher; @@ -24,22 +23,16 @@ import net.md_5.bungee.connection.DownstreamBridge; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.CipherDecoder; -import net.md_5.bungee.netty.CipherEncoder; -import net.md_5.bungee.netty.PacketDecoder; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.ScoreboardObjective; -import net.md_5.bungee.protocol.packet.Team; import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.EncryptionResponse; -import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; import net.md_5.bungee.protocol.packet.Kick; -import net.md_5.bungee.protocol.packet.forge.Forge1Login; @RequiredArgsConstructor public class ServerConnector extends PacketHandler @@ -83,7 +76,7 @@ public class ServerConnector extends PacketHandler out.writeInt( user.getAddress().getPort() ); channel.write( new PluginMessage( "BungeeCord", out.toByteArray() ) ); - channel.write( user.getPendingConnection().getHandshake() ); + // channel.write( user.getPendingConnection().getHandshake() ); FIX // Skip encryption if we are not using Forge if ( user.getPendingConnection().getForgeLogin() == null ) @@ -143,16 +136,9 @@ public class ServerConnector extends PacketHandler user.setServerEntityId( login.getEntityId() ); // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability - Login modLogin; - if ( ch.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == Forge.getInstance() ) - { - modLogin = new Forge1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), login.getDimension(), login.getDifficulty(), login.getUnused(), - (byte) user.getPendingConnection().getListener().getTabListSize() ); - } else - { - modLogin = new Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(), - (byte) user.getPendingConnection().getListener().getTabListSize() ); - } + Login modLogin = new Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(), + (byte) user.getPendingConnection().getListener().getTabListSize() ); + user.unsafe().sendPacket( modLogin ); MinecraftOutput out = new MinecraftOutput(); @@ -169,7 +155,7 @@ public class ServerConnector extends PacketHandler } for ( Team team : serverScoreboard.getTeams() ) { - user.unsafe().sendPacket( new Team( team.getName() ) ); + user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.Team( team.getName() ) ); } serverScoreboard.clear(); @@ -208,39 +194,13 @@ public class ServerConnector extends PacketHandler throw new CancelSendSignal(); } - @Override - public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception - { - Preconditions.checkState( thisState == State.ENCRYPT_REQUEST, "Not expecting ENCRYPT_REQUEST" ); - - // Only need to handle this if we want to use encryption - if ( user.getPendingConnection().getForgeLogin() != null ) - { - PublicKey publickey = EncryptionUtil.getPubkey( encryptRequest ); - this.secretkey = EncryptionUtil.getSecret(); - - byte[] shared = EncryptionUtil.encrypt( publickey, secretkey.getEncoded() ); - byte[] token = EncryptionUtil.encrypt( publickey, encryptRequest.getVerifyToken() ); - - ch.write( new EncryptionResponse( shared, token ) ); - - Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, secretkey ); - ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); - - thisState = State.ENCRYPT_RESPONSE; - } else - { - thisState = State.LOGIN; - } - } - @Override public void handle(EncryptionResponse encryptResponse) throws Exception { Preconditions.checkState( thisState == State.ENCRYPT_RESPONSE, "Not expecting ENCRYPT_RESPONSE" ); Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, secretkey ); - ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) ); + ch.addBefore( PipelineUtils.FRAME_DECODER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) ); ch.write( user.getPendingConnection().getForgeLogin() ); @@ -292,7 +252,6 @@ public class ServerConnector extends PacketHandler if ( in.readByte() != 0 ) { // TODO: Using forge flag - ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Forge.getInstance() ); } } 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 117f86c1..6b0771f3 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -30,7 +30,7 @@ import net.md_5.bungee.api.tab.TabListHandler; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; -import net.md_5.bungee.netty.PacketWrapper; +import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.packet.Chat; diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index e6da72e3..25f73c30 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -21,13 +21,12 @@ import net.md_5.bungee.api.score.Scoreboard; import net.md_5.bungee.api.score.Team; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.netty.PacketWrapper; +import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.ScoreboardDisplay; -import net.md_5.bungee.protocol.packet.Team; import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.Kick; @@ -138,7 +137,7 @@ public class DownstreamBridge extends PacketHandler } @Override - public void handle(Team team) throws Exception + public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); // Remove team and move on 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 c150b090..475d7695 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 @@ -4,14 +4,11 @@ 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; import java.net.URLEncoder; import java.security.GeneralSecurityException; -import java.security.MessageDigest; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.logging.Level; import javax.crypto.Cipher; import javax.crypto.SecretKey; @@ -38,23 +35,20 @@ import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; -import net.md_5.bungee.netty.PacketDecoder; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.protocol.Forge; import net.md_5.bungee.protocol.MinecraftInput; -import net.md_5.bungee.protocol.Vanilla; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.packet.Login; -import net.md_5.bungee.protocol.packet.Packet2Handshake; +import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.EncryptionResponse; -import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; -import net.md_5.bungee.protocol.packet.PacketFEPing; +import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; +import net.md_5.bungee.protocol.packet.LoginRequest; @RequiredArgsConstructor public class InitialHandler extends PacketHandler implements PendingConnection @@ -67,8 +61,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Getter private Login forgeLogin; @Getter - private Packet2Handshake handshake; - private PacketFDEncryptionRequest request; + private Handshake handshake; + @Getter + private LoginRequest loginRequest; + private EncryptionRequest request; @Getter private List loginMessages = new ArrayList<>(); @Getter @@ -170,35 +166,25 @@ public class InitialHandler extends PacketHandler implements PendingConnection forced.ping( pingBack ); } else { - pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); + // pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); } } + /* + @Override + public void handle(PacketFEPing ping) throws Exception + { + pingFuture = ch.getHandle().eventLoop().schedule( new Runnable() + { + @Override + public void run() + { + respondToPing(); + } + }, 200, TimeUnit.MILLISECONDS ); + }*/ @Override - public void handle(PacketFEPing ping) throws Exception - { - pingFuture = ch.getHandle().eventLoop().schedule( new Runnable() - { - @Override - public void run() - { - respondToPing(); - } - }, 200, TimeUnit.MILLISECONDS ); - } - - @Override - public void handle(Login login) throws Exception - { - Preconditions.checkState( thisState == State.LOGIN, "Not expecting FORGE LOGIN" ); - Preconditions.checkState( forgeLogin == null, "Already received FORGE LOGIN" ); - forgeLogin = login; - - ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Forge.getInstance() ); - } - - @Override - public void handle(Packet2Handshake handshake) throws Exception + public void handle(Handshake handshake) throws Exception { Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" ); this.handshake = handshake; @@ -207,15 +193,22 @@ public class InitialHandler extends PacketHandler implements PendingConnection bungee.getPluginManager().callEvent( new PlayerHandshakeEvent( InitialHandler.this, handshake ) ); - if ( handshake.getProtocolVersion() > Vanilla.PROTOCOL_VERSION ) + if ( handshake.getProtocolVersion() > bungee.getProtocolVersion() ) { disconnect( bungee.getTranslation( "outdated_server" ) ); - } else if ( handshake.getProtocolVersion() < Vanilla.PROTOCOL_VERSION ) + } else if ( handshake.getProtocolVersion() < bungee.getProtocolVersion() ) { disconnect( bungee.getTranslation( "outdated_client" ) ); } - if ( handshake.getUsername().length() > 16 ) + } + + @Override + public void handle(LoginRequest loginRequest) throws Exception + { + this.loginRequest = loginRequest; + + if ( getName().length() > 16 ) { disconnect( "Cannot have username longer than 16 characters" ); return; @@ -229,7 +222,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } // If offline mode and they are already on, don't allow connect - if ( !isOnlineMode() && bungee.getPlayer( handshake.getUsername() ) != null ) + if ( !isOnlineMode() && bungee.getPlayer( getName() ) != null ) { disconnect( bungee.getTranslation( "already_connected" ) ); return; @@ -249,7 +242,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection sharedKey = EncryptionUtil.getSecret( encryptResponse, request ); Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, sharedKey ); - ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) ); + ch.addBefore( PipelineUtils.FRAME_DECODER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) ); if ( this.onlineMode ) { @@ -295,7 +288,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection private void finish() { // Check for multiple connections - ProxiedPlayer old = bungee.getPlayer( handshake.getUsername() ); + ProxiedPlayer old = bungee.getPlayer( getName() ); if ( old != null ) { old.disconnect( bungee.getTranslation( "already_connected" ) ); @@ -381,11 +374,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public String getName() { - return ( handshake == null ) ? null : handshake.getUsername(); + return ( loginRequest == null ) ? null : loginRequest.getData(); } @Override - public byte getVersion() + public int getVersion() { return ( handshake == null ) ? version : handshake.getProtocolVersion(); } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index eae12258..6fb545b4 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -10,7 +10,7 @@ import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.netty.PacketWrapper; +import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.TabComplete; diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index e16ae233..b4e9fc1d 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -1,5 +1,6 @@ package net.md_5.bungee.netty; +import net.md_5.bungee.protocol.PacketWrapper; import com.google.common.base.Preconditions; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; diff --git a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java b/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java deleted file mode 100644 index c5e8b8ff..00000000 --- a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.md_5.bungee.netty; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.md_5.bungee.protocol.DefinedPacket; - -@ChannelHandler.Sharable -public class DefinedPacketEncoder extends MessageToByteEncoder -{ - - @Override - protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception - { - out.writeByte( msg.getId() ); - msg.write( out ); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index d3a59eef..fc80d169 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -1,5 +1,6 @@ package net.md_5.bungee.netty; +import net.md_5.bungee.protocol.PacketWrapper; import com.google.common.base.Preconditions; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java deleted file mode 100644 index 99e959aa..00000000 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.md_5.bungee.netty; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ReplayingDecoder; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import net.md_5.bungee.protocol.Protocol; -import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.skip.PacketReader; - -/** - * This class will attempt to read a packet from {@link PacketReader}, with the - * specified {@link #protocol} before returning a new {@link ByteBuf} with the - * copied contents of all bytes read in this frame. - *

- * It is based on {@link ReplayingDecoder} so that packets will only be returned - * when all needed data is present. - */ -@AllArgsConstructor -public class PacketDecoder extends ReplayingDecoder -{ - - @Getter - @Setter - private Protocol protocol; - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception - { - // While we have enough data - while ( true ) - { - // Store our start index - int startIndex = in.readerIndex(); - // Run packet through framer - DefinedPacket packet = protocol.read( in.readUnsignedByte(), in ); - // If we got this far, it means we have formed a packet, so lets grab the end index - int endIndex = in.readerIndex(); - // Allocate a buffer big enough for all bytes we have read - ByteBuf buf = in.copy( startIndex, endIndex - startIndex ); - // Checkpoint our state incase we don't have enough data for another packet - checkpoint(); - // Store our decoded message - out.add( new PacketWrapper( packet, buf ) ); - } - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java index e5634c92..08ab8152 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java @@ -1,5 +1,7 @@ package net.md_5.bungee.netty; +import net.md_5.bungee.protocol.PacketWrapper; + public abstract class PacketHandler extends net.md_5.bungee.protocol.AbstractPacketHandler { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index f37d9951..3c001a89 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -4,6 +4,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelException; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; +import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.util.AttributeKey; import java.net.InetSocketAddress; @@ -15,7 +16,8 @@ import net.md_5.bungee.UserConnection; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ListenerInfo; -import net.md_5.bungee.protocol.Vanilla; +import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.Protocol; public class PipelineUtils { @@ -49,13 +51,15 @@ public class PipelineUtils } }; public static final Base BASE = new Base(); - private static final DefinedPacketEncoder packetEncoder = new DefinedPacketEncoder(); + private static final ProtobufVarint32FrameDecoder frameDecoder = new ProtobufVarint32FrameDecoder(); + private static final ProtobufVarint32FrameDecoder framePrepender = new ProtobufVarint32FrameDecoder(); public static String TIMEOUT_HANDLER = "timeout"; - public static String PACKET_DECODE_HANDLER = "packet-decoder"; - public static String PACKET_ENCODE_HANDLER = "packet-encoder"; + public static String PACKET_CODEC = "packet-codec"; public static String BOSS_HANDLER = "inbound-boss"; public static String ENCRYPT_HANDLER = "encrypt"; public static String DECRYPT_HANDLER = "decrypt"; + public static String FRAME_DECODER = "frame-decoder"; + public static String FRAME_PREPENDER = "frame-prepender"; public final static class Base extends ChannelInitializer { @@ -72,8 +76,9 @@ public class PipelineUtils } ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); - ch.pipeline().addLast( PACKET_DECODE_HANDLER, new PacketDecoder( Vanilla.getInstance() ) ); - ch.pipeline().addLast( PACKET_ENCODE_HANDLER, packetEncoder ); + ch.pipeline().addLast( FRAME_DECODER, frameDecoder ); + ch.pipeline().addLast( PACKET_CODEC, new MinecraftCodec( Protocol.SERVER_HANDSHAKE ) ); + ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() ); } }; From 7121c20338fdba6bef357027c393e6fdd236080b Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 11 Oct 2013 20:34:21 +1100 Subject: [PATCH 05/24] Compiles yet again --- .../api/event/PlayerHandshakeEvent.java | 1 - .../md_5/bungee/protocol/MinecraftCodec.java | 13 +- .../net/md_5/bungee/protocol/Protocol.java | 163 ++++++++---------- .../bungee/protocol/Varint21FrameDecoder.java | 47 +++++ .../Varint21LengthFieldPrepender.java | 43 +++++ .../bungee/connection/InitialHandler.java | 16 +- .../net/md_5/bungee/netty/ChannelWrapper.java | 7 + .../net/md_5/bungee/netty/HandlerBoss.java | 2 + .../net/md_5/bungee/netty/PipelineUtils.java | 11 +- 9 files changed, 206 insertions(+), 97 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java diff --git a/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java b/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java index 06db41e1..2f7b38d9 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java @@ -4,7 +4,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import net.md_5.bungee.api.connection.PendingConnection; -import net.md_5.bungee.protocol.packet.Packet2Handshake; import net.md_5.bungee.api.plugin.Event; import net.md_5.bungee.protocol.packet.Handshake; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java index 530253ea..fca9ffc9 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java @@ -5,31 +5,38 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageCodec; import java.util.List; import lombok.AllArgsConstructor; +import lombok.Setter; @AllArgsConstructor public class MinecraftCodec extends MessageToMessageCodec { + @Setter private Protocol protocol; + private boolean server; @Override protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, List out) throws Exception { + Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_CLIENT : protocol.TO_SERVER; + ByteBuf buf = ctx.alloc().buffer(); - DefinedPacket.writeVarInt( protocol.getId( msg.getClass() ), buf ); + DefinedPacket.writeVarInt( prot.getId( msg.getClass() ), buf ); msg.write( buf ); } @Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception { + Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT; + int packetId = DefinedPacket.readVarInt( msg ); ByteBuf copy = msg.copy(); DefinedPacket packet = null; - if ( protocol.hasPacket( packetId ) ) + if ( prot.hasPacket( packetId ) ) { - packet = protocol.createPacket( packetId ); + packet = prot.createPacket( packetId ); packet.read( msg ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index fdcce8b7..2bc5abf5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -26,74 +26,56 @@ public enum Protocol { // Undef - SERVER_HANDSHAKE + HANDSHAKE { { - registerPacket( 0x00, Handshake.class ); + TO_SERVER.registerPacket( 0x00, Handshake.class ); } }, // 0 - CLIENT_GAME + GAME { { - registerPacket( 0x00, KeepAlive.class ); - registerPacket( 0x01, Login.class ); - registerPacket( 0x02, Chat.class ); - registerPacket( 0x07, Respawn.class ); - registerPacket( 0x3B, PlayerListItem.class ); - registerPacket( 0x3D, TabComplete.class ); - registerPacket( 0x3E, ScoreboardObjective.class ); - registerPacket( 0x3F, ScoreboardScore.class ); - registerPacket( 0x40, ScoreboardDisplay.class ); - registerPacket( 0x41, Team.class ); - registerPacket( 0x42, PluginMessage.class ); - registerPacket( 0x43, Kick.class ); - } - }, - // 0 - SERVER_GAME - { - - { - registerPacket( 0x00, KeepAlive.class ); - registerPacket( 0x14, TabComplete.class ); - registerPacket( 0x15, ClientSettings.class ); - registerPacket( 0x17, PluginMessage.class ); + TO_CLIENT.registerPacket( 0x00, KeepAlive.class ); + TO_CLIENT.registerPacket( 0x01, Login.class ); + TO_CLIENT.registerPacket( 0x02, Chat.class ); + TO_CLIENT.registerPacket( 0x07, Respawn.class ); + TO_CLIENT.registerPacket( 0x3B, PlayerListItem.class ); + TO_CLIENT.registerPacket( 0x3D, TabComplete.class ); + TO_CLIENT.registerPacket( 0x3E, ScoreboardObjective.class ); + TO_CLIENT.registerPacket( 0x3F, ScoreboardScore.class ); + TO_CLIENT.registerPacket( 0x40, ScoreboardDisplay.class ); + TO_CLIENT.registerPacket( 0x41, Team.class ); + TO_CLIENT.registerPacket( 0x42, PluginMessage.class ); + TO_CLIENT.registerPacket( 0x43, Kick.class ); + + + TO_SERVER.registerPacket( 0x00, KeepAlive.class ); + TO_SERVER.registerPacket( 0x14, TabComplete.class ); + TO_SERVER.registerPacket( 0x15, ClientSettings.class ); + TO_SERVER.registerPacket( 0x17, PluginMessage.class ); } }, // 1 - CLIENT_STATUS + STATUS { { } }, - // 1 - SERVER_STATUS + //2 + LOGIN { { - } - }, - // 2 - CLIENT_LOGIN - { - - { - registerPacket( 0x00, Kick.class ); - registerPacket( 0x01, EncryptionRequest.class ); - registerPacket( 0x02, LoginSuccess.class ); - } - }, - // 2 - SERVER_LOGIN - { - - { - registerPacket( 0x00, LoginRequest.class ); - registerPacket( 0x01, EncryptionResponse.class ); + TO_CLIENT.registerPacket( 0x00, Kick.class ); + TO_CLIENT.registerPacket( 0x01, EncryptionRequest.class ); + TO_CLIENT.registerPacket( 0x02, LoginSuccess.class ); + + TO_SERVER.registerPacket( 0x00, LoginRequest.class ); + TO_SERVER.registerPacket( 0x01, EncryptionResponse.class ); } }; /*========================================================================*/ @@ -101,57 +83,64 @@ public enum Protocol public static final int PROTOCOL_VERSION = 0x00; public static final String MINECRAFT_VERSION = "13w41a"; /*========================================================================*/ - private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); - private final Class[] packetClasses = new Class[ MAX_PACKET_ID ]; - private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; + public final ProtocolDirection TO_SERVER = new ProtocolDirection(); + public final ProtocolDirection TO_CLIENT = new ProtocolDirection(); - public boolean hasPacket(int id) + public class ProtocolDirection { - return id < MAX_PACKET_ID && packetConstructors[id] != null; - } - public final DefinedPacket createPacket(int id) - { - if ( id > MAX_PACKET_ID ) + private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); + private final Class[] packetClasses = new Class[ MAX_PACKET_ID ]; + private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; + + public boolean hasPacket(int id) { - throw new BadPacketException( "Packet with id " + id + " outside of range " ); - } - if ( packetConstructors[id] == null ) - { - throw new BadPacketException( "No packet with id " + id ); + return id < MAX_PACKET_ID && packetConstructors[id] != null; } - try + public final DefinedPacket createPacket(int id) { - return packetClasses[id].newInstance(); - } catch ( ReflectiveOperationException ex ) - { - throw new BadPacketException( "Could not construct packet with id " + id, ex ); + if ( id > MAX_PACKET_ID ) + { + throw new BadPacketException( "Packet with id " + id + " outside of range " ); + } + if ( packetConstructors[id] == null ) + { + throw new BadPacketException( "No packet with id " + id ); + } + + try + { + return packetClasses[id].newInstance(); + } catch ( ReflectiveOperationException ex ) + { + throw new BadPacketException( "Could not construct packet with id " + id, ex ); + } } - } - protected final void registerPacket(int id, Class packetClass) - { - try + protected final void registerPacket(int id, Class packetClass) { - packetConstructors[id] = packetClass.getDeclaredConstructor(); - } catch ( NoSuchMethodException ex ) - { - throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass ); + try + { + packetConstructors[id] = packetClass.getDeclaredConstructor(); + } catch ( NoSuchMethodException ex ) + { + throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass ); + } + packetClasses[id] = packetClass; + packetMap.put( packetClass, id ); } - packetClasses[id] = packetClass; - packetMap.put( packetClass, id ); - } - protected final void unregisterPacket(int id) - { - packetMap.remove( packetClasses[id] ); - packetClasses[id] = null; - packetConstructors[id] = null; - } + protected final void unregisterPacket(int id) + { + packetMap.remove( packetClasses[id] ); + packetClasses[id] = null; + packetConstructors[id] = null; + } - final int getId(Class packet) - { - return packetMap.get( packet ); + final int getId(Class packet) + { + return packetMap.get( packet ); + } } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java new file mode 100644 index 00000000..c6441445 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java @@ -0,0 +1,47 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.CorruptedFrameException; + +import java.util.List; + +public class Varint21FrameDecoder extends ByteToMessageDecoder +{ + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception + { + in.markReaderIndex(); + + final byte[] buf = new byte[ 3 ]; + for ( int i = 0; i < buf.length; i++ ) + { + if ( !in.isReadable() ) + { + in.resetReaderIndex(); + return; + } + + buf[i] = in.readByte(); + if ( buf[i] >= 0 ) + { + int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) ); + + if ( in.readableBytes() < length ) + { + in.resetReaderIndex(); + return; + } else + { + out.add( in.readBytes( length ) ); + return; + } + } + } + + throw new CorruptedFrameException( "length wider than 21-bit" ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java new file mode 100644 index 00000000..417adf38 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java @@ -0,0 +1,43 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.netty.channel.ChannelHandler; + +@ChannelHandler.Sharable +public class Varint21LengthFieldPrepender extends MessageToByteEncoder +{ + + @Override + protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception + { + int bodyLen = msg.readableBytes(); + int headerLen = varintSize( bodyLen ); + out.ensureWritable( headerLen + bodyLen ); + + DefinedPacket.writeVarInt( bodyLen, out ); + out.writeBytes( msg, msg.readerIndex(), bodyLen ); + } + + private static int varintSize(int paramInt) + { + if ( ( paramInt & 0xFFFFFF80 ) == 0 ) + { + return 1; + } + if ( ( paramInt & 0xFFFFC000 ) == 0 ) + { + return 2; + } + if ( ( paramInt & 0xFFE00000 ) == 0 ) + { + return 3; + } + if ( ( paramInt & 0xF0000000 ) == 0 ) + { + return 4; + } + return 5; + } +} 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 475d7695..5fd22518 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 @@ -48,6 +48,7 @@ import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; +import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.LoginRequest; @RequiredArgsConstructor @@ -166,7 +167,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection forced.ping( pingBack ); } else { - // pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); + // pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); } } /* @@ -201,6 +202,19 @@ public class InitialHandler extends PacketHandler implements PendingConnection disconnect( bungee.getTranslation( "outdated_client" ) ); } + switch ( handshake.getRequestedProtocol() ) + { + case 1: + // Ping + ch.setProtocol( Protocol.STATUS ); + break; + case 2: + ch.setProtocol( Protocol.LOGIN ); + // Login + break; + default: + throw new IllegalArgumentException( "Cannot request protocol " + handshake.getRequestedProtocol() ); + } } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index b4e9fc1d..492c1d00 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -6,6 +6,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import lombok.Getter; +import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.Protocol; public class ChannelWrapper { @@ -19,6 +21,11 @@ public class ChannelWrapper this.ch = ctx.channel(); } + public void setProtocol(Protocol protocol) + { + ch.pipeline().get( MinecraftCodec.class ).setProtocol( protocol ); + } + public synchronized void write(Object packet) { if ( !closed ) diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index fc80d169..56f0ade4 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -12,6 +12,8 @@ import net.md_5.bungee.connection.CancelSendSignal; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.protocol.BadPacketException; +import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.Protocol; /** * This class is a primitive wrapper for {@link PacketHandler} instances tied to diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index 3c001a89..f1c2d1e7 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -4,7 +4,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelException; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; -import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.util.AttributeKey; import java.net.InetSocketAddress; @@ -18,6 +17,8 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.protocol.MinecraftCodec; import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.Varint21FrameDecoder; +import net.md_5.bungee.protocol.Varint21LengthFieldPrepender; public class PipelineUtils { @@ -38,6 +39,7 @@ public class PipelineUtils } BASE.initChannel( ch ); + ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.HANDSHAKE, true ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); } }; @@ -47,12 +49,12 @@ public class PipelineUtils protected void initChannel(Channel ch) throws Exception { BASE.initChannel( ch ); + ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.LOGIN, false) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( ProxyServer.getInstance(), ch.attr( USER ).get(), ch.attr( TARGET ).get() ) ); } }; public static final Base BASE = new Base(); - private static final ProtobufVarint32FrameDecoder frameDecoder = new ProtobufVarint32FrameDecoder(); - private static final ProtobufVarint32FrameDecoder framePrepender = new ProtobufVarint32FrameDecoder(); + private static final Varint21LengthFieldPrepender framePrepender = new Varint21LengthFieldPrepender(); public static String TIMEOUT_HANDLER = "timeout"; public static String PACKET_CODEC = "packet-codec"; public static String BOSS_HANDLER = "inbound-boss"; @@ -76,8 +78,7 @@ public class PipelineUtils } ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); - ch.pipeline().addLast( FRAME_DECODER, frameDecoder ); - ch.pipeline().addLast( PACKET_CODEC, new MinecraftCodec( Protocol.SERVER_HANDSHAKE ) ); + ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() ); ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() ); } From dbdae87ec6bef8b5ce2c34cb40789134d36c6a89 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 11 Oct 2013 21:36:28 +1100 Subject: [PATCH 06/24] Basically done with login --- .../java/net/md_5/bungee/api/ServerPing.java | 2 +- .../protocol/AbstractPacketHandler.java | 15 +++ .../md_5/bungee/protocol/MinecraftCodec.java | 2 + .../net/md_5/bungee/protocol/Protocol.java | 11 ++ .../Varint21LengthFieldPrepender.java | 2 +- .../bungee/protocol/packet/PingPacket.java | 37 ++++++ .../bungee/protocol/packet/StatusRequest.java | 31 +++++ .../protocol/packet/StatusResponse.java | 37 ++++++ proxy/src/main/java/Test.java | 40 ++++++ .../bungee/connection/InitialHandler.java | 122 ++++++++++-------- .../md_5/bungee/connection/LoginResult.java | 12 ++ .../net/md_5/bungee/netty/ChannelWrapper.java | 4 +- .../net/md_5/bungee/netty/HandlerBoss.java | 2 - .../net/md_5/bungee/netty/PipelineUtils.java | 4 +- 14 files changed, 257 insertions(+), 64 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/PingPacket.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusRequest.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusResponse.java create mode 100644 proxy/src/main/java/Test.java create mode 100644 proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java diff --git a/api/src/main/java/net/md_5/bungee/api/ServerPing.java b/api/src/main/java/net/md_5/bungee/api/ServerPing.java index e37f9aee..a74da42d 100644 --- a/api/src/main/java/net/md_5/bungee/api/ServerPing.java +++ b/api/src/main/java/net/md_5/bungee/api/ServerPing.java @@ -13,7 +13,7 @@ public class ServerPing /** * Numeric protocol version supported by the server. */ - private final byte protocolVersion; + private final int protocolVersion; /** * Human readable game version. */ diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 6101c314..c282f345 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -19,10 +19,25 @@ import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; +import net.md_5.bungee.protocol.packet.PingPacket; +import net.md_5.bungee.protocol.packet.StatusRequest; +import net.md_5.bungee.protocol.packet.StatusResponse; public abstract class AbstractPacketHandler { + public void handle(PingPacket ping) throws Exception + { + } + + public void handle(StatusRequest statusRequest) throws Exception + { + } + + public void handle(StatusResponse statusResponse) throws Exception + { + } + public void handle(Handshake handshake) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java index fca9ffc9..65961ab9 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java @@ -23,6 +23,8 @@ public class MinecraftCodec extends MessageToMessageCodec packet) { + Preconditions.checkArgument( packetMap.containsKey( packet ), "Cannot get ID for packet " + packet ); + return packetMap.get( packet ); } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java index 417adf38..dfae35ae 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21LengthFieldPrepender.java @@ -17,7 +17,7 @@ public class Varint21LengthFieldPrepender extends MessageToByteEncoder out.ensureWritable( headerLen + bodyLen ); DefinedPacket.writeVarInt( bodyLen, out ); - out.writeBytes( msg, msg.readerIndex(), bodyLen ); + out.writeBytes( msg ); } private static int varintSize(int paramInt) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PingPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PingPacket.java new file mode 100644 index 00000000..5f24d425 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PingPacket.java @@ -0,0 +1,37 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class PingPacket extends DefinedPacket +{ + + private long time; + + @Override + public void read(ByteBuf buf) + { + time = buf.readLong(); + } + + @Override + public void write(ByteBuf buf) + { + buf.writeLong( time ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusRequest.java new file mode 100644 index 00000000..738f0c92 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusRequest.java @@ -0,0 +1,31 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class StatusRequest extends DefinedPacket +{ + + @Override + public void read(ByteBuf buf) + { + } + + @Override + public void write(ByteBuf buf) + { + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusResponse.java new file mode 100644 index 00000000..69a9d46c --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/StatusResponse.java @@ -0,0 +1,37 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class StatusResponse extends DefinedPacket +{ + + private String response; + + @Override + public void read(ByteBuf buf) + { + response = readString( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeString( response, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/Test.java b/proxy/src/main/java/Test.java new file mode 100644 index 00000000..cc08bad4 --- /dev/null +++ b/proxy/src/main/java/Test.java @@ -0,0 +1,40 @@ + +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.command.ConsoleCommandSender; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author michael + */ +public class Test +{ + + public static void main(String[] args) throws Exception + { + + System.setProperty( "java.net.preferIPv4Stack", "true" ); + + BungeeCord bungee = new BungeeCord(); + ProxyServer.setInstance( bungee ); + bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); + bungee.start(); + + while ( bungee.isRunning ) + { + String line = bungee.getConsoleReader().readLine( ">" ); + if ( line != null ) + { + if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) ) + { + bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); + } + } + } + } +} 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 5fd22518..96d6b1b7 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 @@ -3,10 +3,11 @@ 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; import java.net.URLEncoder; import java.security.GeneralSecurityException; +import java.security.MessageDigest; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -16,7 +17,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.EncryptionUtil; -import net.md_5.bungee.PacketConstants; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; import net.md_5.bungee.api.Callback; @@ -37,7 +37,6 @@ import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.protocol.MinecraftInput; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Handshake; @@ -48,8 +47,12 @@ import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; +import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.LoginRequest; +import net.md_5.bungee.protocol.packet.LoginSuccess; +import net.md_5.bungee.protocol.packet.PingPacket; +import net.md_5.bungee.protocol.packet.StatusRequest; @RequiredArgsConstructor public class InitialHandler extends PacketHandler implements PendingConnection @@ -82,7 +85,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection }; @Getter private boolean onlineMode = BungeeCord.getInstance().config.isOnlineMode(); - private ScheduledFuture pingFuture; private InetSocketAddress vHost; private byte version = -1; @Getter @@ -91,7 +93,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection private enum State { - HANDSHAKE, ENCRYPT, LOGIN, FINISHED; + HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, LOGIN, FINISHED; } @Override @@ -100,6 +102,14 @@ public class InitialHandler extends PacketHandler implements PendingConnection this.ch = channel; } + @Override + public void handle(PacketWrapper packet) throws Exception + { + int len = DefinedPacket.readVarInt( packet.buf ); + int id = DefinedPacket.readVarInt( packet.buf ); + throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" ); + } + @Override public void exception(Throwable t) throws Exception { @@ -109,22 +119,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(PluginMessage pluginMessage) throws Exception { - if ( pluginMessage.getTag().equals( "MC|PingHost" ) ) - { - if ( pingFuture.cancel( false ) ) - { - MinecraftInput in = pluginMessage.getMCStream(); - version = in.readByte(); - String connectHost = in.readString(); - int connectPort = in.readInt(); - this.vHost = new InetSocketAddress( connectHost, connectPort ); - - respondToPing(); - } - - return; - } - // TODO: Unregister? if ( pluginMessage.getTag().equals( "REGISTER" ) ) { @@ -135,7 +129,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection } } - private void respondToPing() + @Override + public void handle(StatusRequest statusRequest) throws Exception { ServerInfo forced = AbstractReconnectHandler.getForcedHost( this ); final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); @@ -167,22 +162,17 @@ public class InitialHandler extends PacketHandler implements PendingConnection forced.ping( pingBack ); } else { - // pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); + pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); } } - /* - @Override - public void handle(PacketFEPing ping) throws Exception - { - pingFuture = ch.getHandle().eventLoop().schedule( new Runnable() - { - @Override - public void run() - { - respondToPing(); - } - }, 200, TimeUnit.MILLISECONDS ); - }*/ + + @Override + public void handle(PingPacket ping) throws Exception + { + Preconditions.checkState( thisState == State.PING, "Not expecting PING" ); + unsafe.sendPacket( ping ); + disconnect( "" ); + } @Override public void handle(Handshake handshake) throws Exception @@ -206,9 +196,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection { case 1: // Ping + thisState = State.STATUS; ch.setProtocol( Protocol.STATUS ); break; case 2: + thisState = State.USERNAME; ch.setProtocol( Protocol.LOGIN ); // Login break; @@ -220,6 +212,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(LoginRequest loginRequest) throws Exception { + Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" ); this.loginRequest = loginRequest; if ( getName().length() > 16 ) @@ -242,8 +235,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection return; } - unsafe().sendPacket( PacketConstants.I_AM_BUNGEE ); - unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST ); + // TODO: Nuuuu Mojang why u do this + // unsafe().sendPacket( PacketConstants.I_AM_BUNGEE ); + // unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST ); unsafe().sendPacket( request = EncryptionUtil.encryptRequest( this.onlineMode ) ); thisState = State.ENCRYPT; @@ -261,9 +255,18 @@ 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" ); - String authURL = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + encName + "&serverId=" + encID; + 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 = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + encName + "&serverId=" + encodedHash; Callback handler = new Callback() { @@ -272,16 +275,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( error == null ) { - JsonObject obj = BungeeCord.getInstance().gson.fromJson( result, JsonObject.class ); + LoginResult obj = BungeeCord.getInstance().gson.fromJson( result, LoginResult.class ); if ( obj != null ) { - JsonElement id = obj.get( "id" ); - if ( id != null ) - { - UUID = id.getAsString(); - finish(); - return; - } + UUID = obj.getId(); + finish(); + return; } disconnect( "Not authenticated with Minecraft.net" ); } else @@ -330,15 +329,26 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( ch.getHandle().isActive() ) { - unsafe().sendPacket( new EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); - try + + if ( onlineMode ) { - Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); - ch.addBefore( PipelineUtils.DECRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); - } catch ( GeneralSecurityException ex ) - { - disconnect( "Cipher error: " + Util.exception( ex ) ); + unsafe().sendPacket( new EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); + try + { + Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); + ch.addBefore( PipelineUtils.DECRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); + } catch ( GeneralSecurityException ex ) + { + disconnect( "Cipher error: " + Util.exception( ex ) ); + } } + + if ( UUID == null ) + { + UUID = java.util.UUID.randomUUID().toString(); + } + unsafe.sendPacket( new LoginSuccess( BungeeCord.getInstance().gson.toJson( new LoginResult( UUID ) ) ) ); + ch.setProtocol( Protocol.GAME ); } } } ); @@ -380,7 +390,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( !ch.isClosed() ) { - unsafe().sendPacket( new Kick( reason ) ); + unsafe().sendPacket( new Kick( BungeeCord.getInstance().gson.toJson( reason ) ) ); ch.close(); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java b/proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java new file mode 100644 index 00000000..e0b4060c --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java @@ -0,0 +1,12 @@ +package net.md_5.bungee.connection; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class LoginResult +{ + + private String id; +} diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index 492c1d00..10bb86b1 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -33,10 +33,10 @@ public class ChannelWrapper if ( packet instanceof PacketWrapper ) { ( (PacketWrapper) packet ).setReleased( true ); - ch.write( ( (PacketWrapper) packet ).buf ); + ch.write( ( (PacketWrapper) packet ).buf, ch.voidPromise() ); } else { - ch.write( packet ); + ch.write( packet, ch.voidPromise() ); } ch.flush(); } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index 56f0ade4..fc80d169 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -12,8 +12,6 @@ import net.md_5.bungee.connection.CancelSendSignal; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.protocol.BadPacketException; -import net.md_5.bungee.protocol.MinecraftCodec; -import net.md_5.bungee.protocol.Protocol; /** * This class is a primitive wrapper for {@link PacketHandler} instances tied to diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index f1c2d1e7..52ae773a 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -76,10 +76,10 @@ public class PipelineUtils { // IP_TOS is not supported (Windows XP / Windows Server 2003) } - + ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() ); - ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); + ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() ); } }; From b358fd25f5f881d7ac33e5ddfbd1b79229c2333b Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 11 Oct 2013 21:40:23 +1100 Subject: [PATCH 07/24] Done with the proxy to client part. Now we just need the proxy to server part. --- .../bungee/connection/InitialHandler.java | 53 ++++++++----------- 1 file changed, 21 insertions(+), 32 deletions(-) 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 96d6b1b7..8487bf6f 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,8 +1,6 @@ package net.md_5.bungee.connection; import com.google.common.base.Preconditions; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import java.math.BigInteger; import java.net.InetSocketAddress; import java.net.URLEncoder; @@ -40,7 +38,6 @@ import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Handshake; -import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EncryptionRequest; @@ -93,7 +90,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection private enum State { - HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, LOGIN, FINISHED; + HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHED; } @Override @@ -320,7 +317,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection { return; } - thisState = InitialHandler.State.LOGIN; ch.getHandle().eventLoop().execute( new Runnable() { @@ -332,7 +328,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection if ( onlineMode ) { - unsafe().sendPacket( new EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); + // unsafe().sendPacket( new EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) ); try { Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); @@ -349,6 +345,25 @@ public class InitialHandler extends PacketHandler implements PendingConnection } unsafe.sendPacket( new LoginSuccess( BungeeCord.getInstance().gson.toJson( new LoginResult( UUID ) ) ) ); ch.setProtocol( Protocol.GAME ); + + UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this ); + userCon.init(); + + bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) ); + + ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); + + ServerInfo server; + if ( bungee.getReconnectHandler() != null ) + { + server = bungee.getReconnectHandler().getServer( userCon ); + } else + { + server = AbstractReconnectHandler.getForcedHost( InitialHandler.this ); + } + userCon.connect( server, true ); + + thisState = State.FINISHED; } } } ); @@ -359,32 +374,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection bungee.getPluginManager().callEvent( new LoginEvent( InitialHandler.this, complete ) ); } - @Override - public void handle(ClientStatus clientStatus) throws Exception - { - Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" ); - - UserConnection userCon = new UserConnection( bungee, ch, getName(), this ); - userCon.init(); - - bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) ); - - ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); - - ServerInfo server; - if ( bungee.getReconnectHandler() != null ) - { - server = bungee.getReconnectHandler().getServer( userCon ); - } else - { - server = AbstractReconnectHandler.getForcedHost( this ); - } - userCon.connect( server, true ); - - thisState = State.FINISHED; - throw new CancelSendSignal(); - } - @Override public synchronized void disconnect(String reason) { From 1b41682e37db79efc31f7c817d9ed97dc3b47eee Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 11:36:53 +1100 Subject: [PATCH 08/24] Checkpoint --- .../md_5/bungee/protocol/MinecraftCodec.java | 10 +- .../md_5/bungee/protocol/PacketWrapper.java | 1 - .../net/md_5/bungee/protocol/Protocol.java | 13 ++- .../bungee/protocol/packet/LoginSuccess.java | 9 +- .../java/net/md_5/bungee/ServerConnector.java | 98 +++++-------------- .../java/net/md_5/bungee/UserConnection.java | 5 + .../bungee/connection/DownstreamBridge.java | 2 +- .../bungee/connection/InitialHandler.java | 7 +- .../bungee/connection/UpstreamBridge.java | 2 +- .../net/md_5/bungee/netty/PipelineUtils.java | 15 +-- 10 files changed, 66 insertions(+), 96 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java index 65961ab9..a8909e6a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java @@ -1,5 +1,6 @@ package net.md_5.bungee.protocol; +import com.google.common.base.Charsets; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageCodec; @@ -23,7 +24,7 @@ public class MinecraftCodec extends MessageToMessageCodec out) throws Exception { Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT; + ByteBuf copy = msg.copy(); int packetId = DefinedPacket.readVarInt( msg ); - ByteBuf copy = msg.copy(); DefinedPacket packet = null; if ( prot.hasPacket( packetId ) ) { packet = prot.createPacket( packetId ); packet.read( msg ); + if ( msg.readableBytes() != 0 ) + { + System.out.println( msg.toString( Charsets.UTF_8 ) ); + throw new BadPacketException( "Did not read all bytes from packet " + packetId + " Protocol " + protocol + " Direction " + prot ); + } } out.add( new PacketWrapper( packet, copy ) ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java b/protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java index 44610630..8eba797b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/PacketWrapper.java @@ -3,7 +3,6 @@ package net.md_5.bungee.protocol; import io.netty.buffer.ByteBuf; import lombok.RequiredArgsConstructor; import lombok.Setter; -import net.md_5.bungee.protocol.DefinedPacket; @RequiredArgsConstructor public class PacketWrapper diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 5cb03a8d..10ddb602 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import gnu.trove.map.TObjectIntMap; import gnu.trove.map.hash.TObjectIntHashMap; import java.lang.reflect.Constructor; +import lombok.RequiredArgsConstructor; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.EncryptionRequest; @@ -92,12 +93,14 @@ public enum Protocol public static final int PROTOCOL_VERSION = 0x00; public static final String MINECRAFT_VERSION = "13w41a"; /*========================================================================*/ - public final ProtocolDirection TO_SERVER = new ProtocolDirection(); - public final ProtocolDirection TO_CLIENT = new ProtocolDirection(); + public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); + public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); + @RequiredArgsConstructor public class ProtocolDirection { + private final String name; private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); private final Class[] packetClasses = new Class[ MAX_PACKET_ID ]; private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; @@ -107,6 +110,12 @@ public enum Protocol return id < MAX_PACKET_ID && packetConstructors[id] != null; } + @Override + public String toString() + { + return name; + } + public final DefinedPacket createPacket(int id) { if ( id > MAX_PACKET_ID ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java index ed9e5b57..09c718b5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginSuccess.java @@ -15,18 +15,21 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; public class LoginSuccess extends DefinedPacket { - private String data; + private String uuid; + private String username; @Override public void read(ByteBuf buf) { - data = readString( buf ); + uuid = readString( buf ); + username = readString( buf ); } @Override public void write(ByteBuf buf) { - writeString( data, buf ); + writeString( uuid, buf ); + writeString( username, buf ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index b4a51d8c..4ca384ad 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -3,11 +3,8 @@ package net.md_5.bungee; import com.google.common.base.Preconditions; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -import java.io.DataInput; import java.util.Objects; import java.util.Queue; -import javax.crypto.Cipher; -import javax.crypto.SecretKey; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; @@ -22,17 +19,17 @@ import net.md_5.bungee.connection.CancelSendSignal; import net.md_5.bungee.connection.DownstreamBridge; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.ChannelWrapper; -import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.PacketWrapper; +import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.PluginMessage; -import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.Kick; +import net.md_5.bungee.protocol.packet.LoginSuccess; @RequiredArgsConstructor public class ServerConnector extends PacketHandler @@ -42,14 +39,12 @@ public class ServerConnector extends PacketHandler private ChannelWrapper ch; private final UserConnection user; private final BungeeServerInfo target; - private State thisState = State.ENCRYPT_REQUEST; - private SecretKey secretkey; - private boolean sentMessages; + private State thisState = State.LOGIN_SUCCESS; private enum State { - ENCRYPT_REQUEST, ENCRYPT_RESPONSE, LOGIN, FINISHED; + LOGIN_SUCCESS, ENCRYPT_RESPONSE, LOGIN, FINISHED; } @Override @@ -74,15 +69,12 @@ public class ServerConnector extends PacketHandler out.writeUTF( "Login" ); out.writeUTF( user.getAddress().getHostString() ); out.writeInt( user.getAddress().getPort() ); - channel.write( new PluginMessage( "BungeeCord", out.toByteArray() ) ); + // channel.write( new PluginMessage( "BungeeCord", out.toByteArray() ) ); MOJANG - // channel.write( user.getPendingConnection().getHandshake() ); FIX + channel.write( user.getPendingConnection().getHandshake() ); - // Skip encryption if we are not using Forge - if ( user.getPendingConnection().getForgeLogin() == null ) - { - channel.write( PacketConstants.CLIENT_LOGIN ); - } + channel.setProtocol( Protocol.LOGIN ); + channel.write( user.getPendingConnection().getLoginRequest() ); } @Override @@ -91,6 +83,24 @@ public class ServerConnector extends PacketHandler user.getPendingConnects().remove( target ); } + @Override + public void handle(PacketWrapper packet) throws Exception + { + int packetID = DefinedPacket.readVarInt( packet.buf ); + System.out.println( packetID + " : " + packet.packet ); + super.handle( packet ); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void handle(LoginSuccess loginSuccess) throws Exception + { + Preconditions.checkState( thisState == State.LOGIN_SUCCESS, "Not exepcting LOGIN_SUCCESS" ); + ch.setProtocol( Protocol.GAME ); + thisState = State.LOGIN; + + throw new CancelSendSignal(); + } + @Override public void handle(Login login) throws Exception { @@ -114,13 +124,6 @@ public class ServerConnector extends PacketHandler { ch.write( message ); } - if ( !sentMessages ) - { - for ( PluginMessage message : user.getPendingConnection().getLoginMessages() ) - { - ch.write( message ); - } - } if ( user.getSettings() != null ) { @@ -194,20 +197,6 @@ public class ServerConnector extends PacketHandler throw new CancelSendSignal(); } - @Override - public void handle(EncryptionResponse encryptResponse) throws Exception - { - Preconditions.checkState( thisState == State.ENCRYPT_RESPONSE, "Not expecting ENCRYPT_RESPONSE" ); - - Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, secretkey ); - ch.addBefore( PipelineUtils.FRAME_DECODER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) ); - - ch.write( user.getPendingConnection().getForgeLogin() ); - - ch.write( PacketConstants.CLIENT_LOGIN ); - thisState = State.LOGIN; - } - @Override public void handle(Kick kick) throws Exception { @@ -233,39 +222,6 @@ public class ServerConnector extends PacketHandler } } - @Override - public void handle(PluginMessage pluginMessage) throws Exception - { - if ( pluginMessage.equals( PacketConstants.I_AM_BUNGEE ) ) - { - throw new IllegalStateException( "May not connect to another BungeCord!" ); - } - - DataInput in = pluginMessage.getStream(); - if ( pluginMessage.getTag().equals( "FML" ) && in.readUnsignedByte() == 0 ) - { - int count = in.readInt(); - for ( int i = 0; i < count; i++ ) - { - in.readUTF(); - } - if ( in.readByte() != 0 ) - { - // TODO: Using forge flag - } - } - - user.unsafe().sendPacket( pluginMessage ); // We have to forward these to the user, especially with Forge as stuff might break - if ( !sentMessages && user.getPendingConnection().getForgeLogin() != null ) - { - for ( PluginMessage message : user.getPendingConnection().getLoginMessages() ) - { - ch.write( message ); - } - sentMessages = true; - } - } - @Override public String toString() { 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 6b0771f3..e6efb419 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -32,7 +32,11 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.netty.PipelineUtils; +import static net.md_5.bungee.netty.PipelineUtils.FRAME_DECODER; +import static net.md_5.bungee.netty.PipelineUtils.PACKET_CODEC; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.PluginMessage; @@ -200,6 +204,7 @@ public final class UserConnection implements ProxiedPlayer protected void initChannel(Channel ch) throws Exception { PipelineUtils.BASE.initChannel( ch ); + ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.HANDSHAKE, false ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) ); } }; diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 25f73c30..d39410c9 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -74,7 +74,7 @@ public class DownstreamBridge extends PacketHandler { if ( !server.isObsolete() ) { - EntityMap.rewrite( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); + // EntityMap.rewrite( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); con.sendPacket( packet ); } } 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 8487bf6f..057c5e15 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 @@ -104,7 +104,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { int len = DefinedPacket.readVarInt( packet.buf ); int id = DefinedPacket.readVarInt( packet.buf ); - throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" ); + // throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" ); } @Override @@ -343,7 +343,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection { UUID = java.util.UUID.randomUUID().toString(); } - unsafe.sendPacket( new LoginSuccess( BungeeCord.getInstance().gson.toJson( new LoginResult( UUID ) ) ) ); + System.out.println( ch.getHandle().pipeline() ); + unsafe.sendPacket( new LoginSuccess( UUID, getName() ) ); ch.setProtocol( Protocol.GAME ); UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this ); @@ -361,7 +362,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { server = AbstractReconnectHandler.getForcedHost( InitialHandler.this ); } - userCon.connect( server, true ); + // userCon.connect( server, true ); thisState = State.FINISHED; } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 6fb545b4..06a6bd28 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -59,7 +59,7 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(PacketWrapper packet) throws Exception { - EntityMap.rewrite( packet.buf, con.getClientEntityId(), con.getServerEntityId() ); + // EntityMap.rewrite( packet.buf, con.getClientEntityId(), con.getServerEntityId() ); if ( con.getServer() != null ) { con.getServer().getCh().write( packet ); diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index 52ae773a..2295b5d4 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -10,7 +10,6 @@ import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeServerInfo; -import net.md_5.bungee.ServerConnector; import net.md_5.bungee.UserConnection; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.api.ProxyServer; @@ -40,19 +39,10 @@ public class PipelineUtils BASE.initChannel( ch ); ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.HANDSHAKE, true ) ); + System.out.println( ch.pipeline() ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); } }; - public static final ChannelInitializer CLIENT = new ChannelInitializer() - { - @Override - protected void initChannel(Channel ch) throws Exception - { - BASE.initChannel( ch ); - ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.LOGIN, false) ); - ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( ProxyServer.getInstance(), ch.attr( USER ).get(), ch.attr( TARGET ).get() ) ); - } - }; public static final Base BASE = new Base(); private static final Varint21LengthFieldPrepender framePrepender = new Varint21LengthFieldPrepender(); public static String TIMEOUT_HANDLER = "timeout"; @@ -76,9 +66,10 @@ public class PipelineUtils { // IP_TOS is not supported (Windows XP / Windows Server 2003) } - ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); + ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() ); + ch.pipeline().addLast( FRAME_PREPENDER, framePrepender ); ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() ); } From b8c9330bd623cc13d0cf9dd54c919b4c1971e569 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 12:01:17 +1100 Subject: [PATCH 09/24] Sigh --- .../md_5/bungee/protocol/MinecraftCodec.java | 53 ------------------- .../bungee/protocol/MinecraftDecoder.java | 41 ++++++++++++++ .../bungee/protocol/MinecraftEncoder.java | 24 +++++++++ .../java/net/md_5/bungee/UserConnection.java | 9 ++-- .../bungee/connection/InitialHandler.java | 2 +- .../net/md_5/bungee/netty/ChannelWrapper.java | 6 ++- .../net/md_5/bungee/netty/PipelineUtils.java | 9 ++-- 7 files changed, 80 insertions(+), 64 deletions(-) delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/MinecraftEncoder.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java deleted file mode 100644 index a8909e6a..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftCodec.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.md_5.bungee.protocol; - -import com.google.common.base.Charsets; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageCodec; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Setter; - -@AllArgsConstructor -public class MinecraftCodec extends MessageToMessageCodec -{ - - @Setter - private Protocol protocol; - private boolean server; - - @Override - protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, List out) throws Exception - { - Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_CLIENT : protocol.TO_SERVER; - - ByteBuf buf = ctx.alloc().buffer(); - DefinedPacket.writeVarInt( prot.getId( msg.getClass() ), buf ); - msg.write( buf ); - - out.add( buf ); - } - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception - { - Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT; - ByteBuf copy = msg.copy(); - - int packetId = DefinedPacket.readVarInt( msg ); - - DefinedPacket packet = null; - if ( prot.hasPacket( packetId ) ) - { - packet = prot.createPacket( packetId ); - packet.read( msg ); - if ( msg.readableBytes() != 0 ) - { - System.out.println( msg.toString( Charsets.UTF_8 ) ); - throw new BadPacketException( "Did not read all bytes from packet " + packetId + " Protocol " + protocol + " Direction " + prot ); - } - } - - out.add( new PacketWrapper( packet, copy ) ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java new file mode 100644 index 00000000..27d9cf40 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java @@ -0,0 +1,41 @@ +package net.md_5.bungee.protocol; + +import com.google.common.base.Charsets; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +public class MinecraftDecoder extends ByteToMessageDecoder +{ + + @Setter + private Protocol protocol; + private boolean server; + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception + { + Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT; + ByteBuf copy = in.copy(); + + int packetId = DefinedPacket.readVarInt( in ); + + DefinedPacket packet = null; + if ( prot.hasPacket( packetId ) ) + { + packet = prot.createPacket( packetId ); + packet.read( in ); + if ( in.readableBytes() != 0 ) + { + System.out.println( in.toString( Charsets.UTF_8 ) ); + throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); + } + } + + out.add( new PacketWrapper( packet, copy ) ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftEncoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftEncoder.java new file mode 100644 index 00000000..28689b9f --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftEncoder.java @@ -0,0 +1,24 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import lombok.AllArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +public class MinecraftEncoder extends MessageToByteEncoder +{ + + @Setter + private Protocol protocol; + private boolean server; + + @Override + protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception + { + Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_CLIENT : protocol.TO_SERVER; + DefinedPacket.writeVarInt( prot.getId( msg.getClass() ), out ); + msg.write( out ); + } +} 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 e6efb419..fa19f25b 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -19,7 +19,6 @@ import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.Setter; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -32,10 +31,9 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.netty.PipelineUtils; -import static net.md_5.bungee.netty.PipelineUtils.FRAME_DECODER; -import static net.md_5.bungee.netty.PipelineUtils.PACKET_CODEC; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.MinecraftDecoder; +import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClientSettings; @@ -204,7 +202,8 @@ public final class UserConnection implements ProxiedPlayer protected void initChannel(Channel ch) throws Exception { PipelineUtils.BASE.initChannel( ch ); - ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.HANDSHAKE, false ) ); + ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false ) ); + ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) ); } }; 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 057c5e15..e971e1ac 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 @@ -362,7 +362,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { server = AbstractReconnectHandler.getForcedHost( InitialHandler.this ); } - // userCon.connect( server, true ); + userCon.connect( server, true ); thisState = State.FINISHED; } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java index 10bb86b1..77ecd687 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java @@ -6,7 +6,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import lombok.Getter; -import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.MinecraftDecoder; +import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.Protocol; public class ChannelWrapper @@ -23,7 +24,8 @@ public class ChannelWrapper public void setProtocol(Protocol protocol) { - ch.pipeline().get( MinecraftCodec.class ).setProtocol( protocol ); + ch.pipeline().get( MinecraftDecoder.class ).setProtocol( protocol ); + ch.pipeline().get( MinecraftEncoder.class ).setProtocol( protocol ); } public synchronized void write(Object packet) diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index 2295b5d4..af2899a9 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -14,7 +14,8 @@ import net.md_5.bungee.UserConnection; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ListenerInfo; -import net.md_5.bungee.protocol.MinecraftCodec; +import net.md_5.bungee.protocol.MinecraftDecoder; +import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.Varint21FrameDecoder; import net.md_5.bungee.protocol.Varint21LengthFieldPrepender; @@ -38,7 +39,8 @@ public class PipelineUtils } BASE.initChannel( ch ); - ch.pipeline().addAfter( FRAME_DECODER, PACKET_CODEC, new MinecraftCodec( Protocol.HANDSHAKE, true ) ); + ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true ) ); + ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true ) ); System.out.println( ch.pipeline() ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); } @@ -46,7 +48,8 @@ public class PipelineUtils public static final Base BASE = new Base(); private static final Varint21LengthFieldPrepender framePrepender = new Varint21LengthFieldPrepender(); public static String TIMEOUT_HANDLER = "timeout"; - public static String PACKET_CODEC = "packet-codec"; + public static String PACKET_DECODER = "packet-decoder"; + public static String PACKET_ENCODER = "packet-encoder"; public static String BOSS_HANDLER = "inbound-boss"; public static String ENCRYPT_HANDLER = "encrypt"; public static String DECRYPT_HANDLER = "decrypt"; From e0ebf1af21a05bf385c11ed4ad0858cdf6be1e8d Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 12:08:26 +1100 Subject: [PATCH 10/24] All my work on 1.7 so far. Pinging doesnt work, but everything else is near functional. Gotta figure out wtf is happening. --- .../main/java/net/md_5/bungee/protocol/MinecraftDecoder.java | 4 ++-- .../main/java/net/md_5/bungee/connection/InitialHandler.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java index 27d9cf40..4ecb7a4e 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java @@ -20,7 +20,7 @@ public class MinecraftDecoder extends ByteToMessageDecoder protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { Protocol.ProtocolDirection prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT; - ByteBuf copy = in.copy(); + ByteBuf copy = in.copy(); // TODO int packetId = DefinedPacket.readVarInt( in ); @@ -32,7 +32,7 @@ public class MinecraftDecoder extends ByteToMessageDecoder if ( in.readableBytes() != 0 ) { System.out.println( in.toString( Charsets.UTF_8 ) ); - throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); + // throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); } } 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 e971e1ac..f29ecf1c 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 @@ -332,7 +332,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection try { Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey ); - ch.addBefore( PipelineUtils.DECRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); + ch.addBefore( PipelineUtils.FRAME_PREPENDER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) ); } catch ( GeneralSecurityException ex ) { disconnect( "Cipher error: " + Util.exception( ex ) ); From 1551bf6f3a101a4a9b25d42f6c61694b60d9d45e Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 13:51:33 +1100 Subject: [PATCH 11/24] Ping stuffs, doesnt seem to work for some reason though --- .../java/net/md_5/bungee/api/ServerPing.java | 45 ++++++++++--------- .../bungee/connection/InitialHandler.java | 26 ++++++----- .../md_5/bungee/connection/PingHandler.java | 4 +- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ServerPing.java b/api/src/main/java/net/md_5/bungee/api/ServerPing.java index a74da42d..96946c4d 100644 --- a/api/src/main/java/net/md_5/bungee/api/ServerPing.java +++ b/api/src/main/java/net/md_5/bungee/api/ServerPing.java @@ -1,33 +1,38 @@ package net.md_5.bungee.api; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * Represents the standard list data returned by opening a server in the * Minecraft client server list, or hitting it with a packet 0xFE. */ @Data +@NoArgsConstructor +@AllArgsConstructor public class ServerPing { - /** - * Numeric protocol version supported by the server. - */ - private final int protocolVersion; - /** - * Human readable game version. - */ - private final String gameVersion; - /** - * Server MOTD. - */ - private final String motd; - /** - * Current amount of players on the server. - */ - private final int currentPlayers; - /** - * Max amount of players the server will allow. - */ - private final int maxPlayers; + private Protocol version; + + @Data + @AllArgsConstructor + public static class Protocol + { + + private String name; + private int version; + } + private Players players; + + @Data + @AllArgsConstructor + public static class Players + { + + private int max; + private int online; + } + private String description; } 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 f29ecf1c..cb4a9bdd 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 @@ -50,6 +50,7 @@ import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; import net.md_5.bungee.protocol.packet.StatusRequest; +import net.md_5.bungee.protocol.packet.StatusResponse; @RequiredArgsConstructor public class InitialHandler extends PacketHandler implements PendingConnection @@ -102,8 +103,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(PacketWrapper packet) throws Exception { - int len = DefinedPacket.readVarInt( packet.buf ); - int id = DefinedPacket.readVarInt( packet.buf ); + // int len = DefinedPacket.readVarInt( packet.buf ); + // int id = DefinedPacket.readVarInt( packet.buf ); // throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" ); } @@ -129,6 +130,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(StatusRequest statusRequest) throws Exception { + Preconditions.checkState( thisState == State.STATUS, "Not expecting STATUS" ); + ServerInfo forced = AbstractReconnectHandler.getForcedHost( this ); final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); @@ -139,18 +142,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( error != null ) { - result = new ServerPing( (byte) -1, "-1", "Error pinging remote server: " + Util.exception( error ), -1, -1 ); + result = new ServerPing(); + result.setDescription( "Error pinging remote server: " + Util.exception( error ) ); } result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse(); - String kickMessage = ChatColor.DARK_BLUE - + "\00" + result.getProtocolVersion() - + "\00" + result.getGameVersion() - + "\00" + result.getMotd() - + "\00" + result.getCurrentPlayers() - + "\00" + result.getMaxPlayers(); BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); - disconnect( kickMessage ); + unsafe.sendPacket( new StatusResponse( BungeeCord.getInstance().gson.toJson( result ) ) ); } }; @@ -159,8 +157,14 @@ public class InitialHandler extends PacketHandler implements PendingConnection forced.ping( pingBack ); } else { - pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); + pingBack.done( new ServerPing( + new ServerPing.Protocol( bungee.getGameVersion(), bungee.getProtocolVersion() ), + new ServerPing.Players( bungee.getOnlineCount(), listener.getMaxPlayers() ), + motd ), + null ); } + + thisState = State.PING; } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index 32370e2a..8c6e72bd 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -37,8 +37,8 @@ public class PingHandler extends PacketHandler public void handle(Kick kick) throws Exception { String[] split = kick.getMessage().split( "\00" ); - ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); - callback.done( ping, null ); + // ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); + // callback.done( ping, null ); } @Override From 26be0566f41e52b01b64d00043e4dda4d2bf6e68 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 15:29:39 +1100 Subject: [PATCH 12/24] I love @Cobi --- .../main/java/net/md_5/bungee/protocol/MinecraftDecoder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java index 4ecb7a4e..1c6476fe 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java @@ -32,8 +32,11 @@ public class MinecraftDecoder extends ByteToMessageDecoder if ( in.readableBytes() != 0 ) { System.out.println( in.toString( Charsets.UTF_8 ) ); - // throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); + // throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); } + } else + { + in.skipBytes( in.readableBytes() ); } out.add( new PacketWrapper( packet, copy ) ); From d96e561a6f8c4cd086e08aaacf8589a9c7a7ba6f Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 15:30:32 +1100 Subject: [PATCH 13/24] Cleanup debug --- proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 8 -------- .../java/net/md_5/bungee/connection/InitialHandler.java | 9 --------- .../main/java/net/md_5/bungee/netty/PipelineUtils.java | 1 - 3 files changed, 18 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 4ca384ad..a0a46cf9 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -83,14 +83,6 @@ public class ServerConnector extends PacketHandler user.getPendingConnects().remove( target ); } - @Override - public void handle(PacketWrapper packet) throws Exception - { - int packetID = DefinedPacket.readVarInt( packet.buf ); - System.out.println( packetID + " : " + packet.packet ); - super.handle( packet ); //To change body of generated methods, choose Tools | Templates. - } - @Override public void handle(LoginSuccess loginSuccess) throws Exception { 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 cb4a9bdd..a22e3b29 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 @@ -100,14 +100,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection this.ch = channel; } - @Override - public void handle(PacketWrapper packet) throws Exception - { - // int len = DefinedPacket.readVarInt( packet.buf ); - // int id = DefinedPacket.readVarInt( packet.buf ); - // throw new UnsupportedOperationException( "Cannot handle unknown packet at login!" ); - } - @Override public void exception(Throwable t) throws Exception { @@ -347,7 +339,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection { UUID = java.util.UUID.randomUUID().toString(); } - System.out.println( ch.getHandle().pipeline() ); unsafe.sendPacket( new LoginSuccess( UUID, getName() ) ); ch.setProtocol( Protocol.GAME ); diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index af2899a9..24a24581 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -41,7 +41,6 @@ public class PipelineUtils BASE.initChannel( ch ); ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true ) ); ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true ) ); - System.out.println( ch.pipeline() ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); } }; From 69b209bcc69e6cf9c52299c19eb3a12ef3f766f0 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 15:36:22 +1100 Subject: [PATCH 14/24] Fix /server command. Now working! --- protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java | 1 + 1 file changed, 1 insertion(+) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 10ddb602..274608eb 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -58,6 +58,7 @@ public enum Protocol TO_SERVER.registerPacket( 0x00, KeepAlive.class ); + TO_SERVER.registerPacket( 0x01, Chat.class ); TO_SERVER.registerPacket( 0x14, TabComplete.class ); TO_SERVER.registerPacket( 0x15, ClientSettings.class ); TO_SERVER.registerPacket( 0x17, PluginMessage.class ); From 062dd38b2ba9139dd1d30d2d6aa63b57320ae8c7 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Oct 2013 15:50:08 +1100 Subject: [PATCH 15/24] Fix pinging. I love you @Sircmpwn --- api/src/main/java/net/md_5/bungee/api/ServerPing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ServerPing.java b/api/src/main/java/net/md_5/bungee/api/ServerPing.java index 96946c4d..2458d133 100644 --- a/api/src/main/java/net/md_5/bungee/api/ServerPing.java +++ b/api/src/main/java/net/md_5/bungee/api/ServerPing.java @@ -22,7 +22,7 @@ public class ServerPing { private String name; - private int version; + private int protocol; } private Players players; From 18db20fe428edf9d196c5e0b922b1dc20d946689 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 15 Oct 2013 16:29:36 +1100 Subject: [PATCH 16/24] 41b update --- .../protocol/AbstractPacketHandler.java | 9 ++++- .../md_5/bungee/protocol/DefinedPacket.java | 20 ++++++++++ .../net/md_5/bungee/protocol/Protocol.java | 9 +++-- .../bungee/protocol/packet/Handshake.java | 4 +- .../md_5/bungee/protocol/packet/Login.java | 18 +++------ .../md_5/bungee/protocol/packet/Respawn.java | 15 ++------ ...bComplete.java => TabCompleteRequest.java} | 16 +------- .../protocol/packet/TabCompleteResponse.java | 37 +++++++++++++++++++ .../java/net/md_5/bungee/PacketConstants.java | 4 +- .../java/net/md_5/bungee/ServerConnector.java | 5 +-- .../bungee/connection/UpstreamBridge.java | 8 ++-- 11 files changed, 91 insertions(+), 54 deletions(-) rename protocol/src/main/java/net/md_5/bungee/protocol/packet/{TabComplete.java => TabCompleteRequest.java} (62%) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index c282f345..37f0cba9 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -7,7 +7,7 @@ import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.PlayerListItem; -import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.ScoreboardDisplay; @@ -22,10 +22,15 @@ import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; +import net.md_5.bungee.protocol.packet.TabCompleteResponse; public abstract class AbstractPacketHandler { + public void handle(TabCompleteResponse tabResponse) throws Exception + { + } + public void handle(PingPacket ping) throws Exception { } @@ -74,7 +79,7 @@ public abstract class AbstractPacketHandler { } - public void handle(TabComplete tabComplete) throws Exception + public void handle(TabCompleteRequest tabComplete) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index be342952..3cc2a54a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -41,6 +41,26 @@ public abstract class DefinedPacket return ret; } + public static void writeStringArray(String[] s, ByteBuf buf) + { + writeVarInt( s.length, buf ); + for ( String str : s ) + { + writeString( str, buf ); + } + } + + public static String[] readStringArray(ByteBuf buf) + { + int len = readVarInt( buf ); + String[] ret = new String[ len ]; + for ( int i = 0; i < ret.length; i++ ) + { + ret[i] = readString( buf ); + } + return ret; + } + public static int readVarInt(ByteBuf input) { int out = 0; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 274608eb..87f3e6a5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -24,7 +24,8 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; -import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.TabCompleteRequest; +import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.protocol.packet.Team; public enum Protocol @@ -48,7 +49,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x02, Chat.class ); TO_CLIENT.registerPacket( 0x07, Respawn.class ); TO_CLIENT.registerPacket( 0x3B, PlayerListItem.class ); - TO_CLIENT.registerPacket( 0x3D, TabComplete.class ); + TO_CLIENT.registerPacket( 0x3D, TabCompleteResponse.class ); TO_CLIENT.registerPacket( 0x3E, ScoreboardObjective.class ); TO_CLIENT.registerPacket( 0x3F, ScoreboardScore.class ); TO_CLIENT.registerPacket( 0x40, ScoreboardDisplay.class ); @@ -59,7 +60,7 @@ public enum Protocol TO_SERVER.registerPacket( 0x00, KeepAlive.class ); TO_SERVER.registerPacket( 0x01, Chat.class ); - TO_SERVER.registerPacket( 0x14, TabComplete.class ); + TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class ); TO_SERVER.registerPacket( 0x15, ClientSettings.class ); TO_SERVER.registerPacket( 0x17, PluginMessage.class ); } @@ -92,7 +93,7 @@ public enum Protocol /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; public static final int PROTOCOL_VERSION = 0x00; - public static final String MINECRAFT_VERSION = "13w41a"; + public static final String MINECRAFT_VERSION = "13w41b"; /*========================================================================*/ public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java index ed55d472..930b3474 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java @@ -25,7 +25,7 @@ public class Handshake extends DefinedPacket { protocolVersion = readVarInt( buf ); host = readString( buf ); - port = readVarInt( buf ); + port = buf.readUnsignedShort(); requestedProtocol = readVarInt( buf ); } @@ -34,7 +34,7 @@ public class Handshake extends DefinedPacket { writeVarInt( protocolVersion, buf ); writeString( host, buf ); - writeVarInt( port, buf ); + buf.writeShort( port ); writeVarInt( requestedProtocol, buf ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index 65510da6..321b93a8 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -16,34 +16,28 @@ public class Login extends DefinedPacket { private int entityId; - private String levelType; - private byte gameMode; + private short gameMode; private int dimension; - private byte difficulty; - private byte unused; - private byte maxPlayers; + private short difficulty; + private short maxPlayers; @Override public void read(ByteBuf buf) { entityId = buf.readInt(); - levelType = readString( buf ); - gameMode = buf.readByte(); + gameMode = buf.readUnsignedByte(); dimension = buf.readByte(); - difficulty = buf.readByte(); - unused = buf.readByte(); - maxPlayers = buf.readByte(); + difficulty = buf.readUnsignedByte(); + maxPlayers = buf.readUnsignedByte(); } @Override public void write(ByteBuf buf) { buf.writeInt( entityId ); - writeString( levelType, buf ); buf.writeByte( gameMode ); buf.writeByte( dimension ); buf.writeByte( difficulty ); - buf.writeByte( unused ); buf.writeByte( maxPlayers ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java index b6e60599..b5a44823 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java @@ -6,7 +6,6 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.ToString; import net.md_5.bungee.protocol.AbstractPacketHandler; @Data @@ -17,19 +16,15 @@ public class Respawn extends DefinedPacket { private int dimension; - private byte difficulty; - private byte gameMode; - private short worldHeight; - private String levelType; + private short difficulty; + private short gameMode; @Override public void read(ByteBuf buf) { dimension = buf.readInt(); - difficulty = buf.readByte(); - gameMode = buf.readByte(); - worldHeight = buf.readShort(); - levelType = readString( buf ); + difficulty = buf.readUnsignedByte(); + gameMode = buf.readUnsignedByte(); } @Override @@ -38,8 +33,6 @@ public class Respawn extends DefinedPacket buf.writeInt( dimension ); buf.writeByte( difficulty ); buf.writeByte( gameMode ); - buf.writeShort( worldHeight ); - writeString( levelType, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java similarity index 62% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java index ec9ca0c4..3bedbd5e 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java @@ -12,16 +12,10 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class TabComplete extends DefinedPacket +public class TabCompleteRequest extends DefinedPacket { private String cursor; - private String[] commands; - - public TabComplete(String[] alternatives) - { - commands = alternatives; - } @Override public void read(ByteBuf buf) @@ -32,13 +26,7 @@ public class TabComplete extends DefinedPacket @Override public void write(ByteBuf buf) { - StringBuilder tab = new StringBuilder(); - for ( String alternative : commands ) - { - tab.append( alternative ); - tab.append( "\00" ); - } - writeString( tab.substring( 0, tab.length() - 1 ), buf ); + writeString( cursor, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java new file mode 100644 index 00000000..0027b989 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java @@ -0,0 +1,37 @@ +package net.md_5.bungee.protocol.packet; + +import net.md_5.bungee.protocol.DefinedPacket; +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class TabCompleteResponse extends DefinedPacket +{ + + private String[] commands; + + @Override + public void read(ByteBuf buf) + { + commands = readStringArray( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeStringArray( commands, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java index b2072618..75fd9b55 100644 --- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java @@ -7,8 +7,8 @@ import net.md_5.bungee.protocol.packet.PluginMessage; public class PacketConstants { - public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); - public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); + public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0 ); + public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0 ); public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 ); public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[] { diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index a0a46cf9..05f02263 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -22,7 +22,6 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Respawn; @@ -131,7 +130,7 @@ public class ServerConnector extends PacketHandler user.setServerEntityId( login.getEntityId() ); // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability - Login modLogin = new Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(), + Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), (byte) user.getPendingConnection().getListener().getTabListSize() ); user.unsafe().sendPacket( modLogin ); @@ -157,7 +156,7 @@ public class ServerConnector extends PacketHandler user.sendDimensionSwitch(); user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) ); + user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode() ) ); // Remove from old servers user.getServer().setObsolete( true ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 06a6bd28..411003cb 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -1,7 +1,6 @@ package net.md_5.bungee.connection; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.EntityMap; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; import net.md_5.bungee.api.ProxyServer; @@ -13,11 +12,12 @@ import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Chat; -import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.PluginMessage; import java.util.ArrayList; import java.util.List; +import net.md_5.bungee.protocol.packet.TabCompleteResponse; public class UpstreamBridge extends PacketHandler { @@ -93,7 +93,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(TabComplete tabComplete) throws Exception + public void handle(TabCompleteRequest tabComplete) throws Exception { if ( tabComplete.getCursor().startsWith( "/" ) ) { @@ -102,7 +102,7 @@ public class UpstreamBridge extends PacketHandler if ( !results.isEmpty() ) { - con.unsafe().sendPacket( new TabComplete( results.toArray( new String[ results.size() ] ) ) ); + con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) ); throw new CancelSendSignal(); } } From 3b9af0ab859affd1f93e922c812d8e99663b7e1c Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 16 Oct 2013 17:29:49 +1100 Subject: [PATCH 17/24] Fix 41b support --- .../java/net/md_5/bungee/protocol/Protocol.java | 16 ++++++++-------- .../bungee/protocol/packet/ScoreboardScore.java | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 87f3e6a5..59c28f9d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -48,14 +48,14 @@ public enum Protocol TO_CLIENT.registerPacket( 0x01, Login.class ); TO_CLIENT.registerPacket( 0x02, Chat.class ); TO_CLIENT.registerPacket( 0x07, Respawn.class ); - TO_CLIENT.registerPacket( 0x3B, PlayerListItem.class ); - TO_CLIENT.registerPacket( 0x3D, TabCompleteResponse.class ); - TO_CLIENT.registerPacket( 0x3E, ScoreboardObjective.class ); - TO_CLIENT.registerPacket( 0x3F, ScoreboardScore.class ); - TO_CLIENT.registerPacket( 0x40, ScoreboardDisplay.class ); - TO_CLIENT.registerPacket( 0x41, Team.class ); - TO_CLIENT.registerPacket( 0x42, PluginMessage.class ); - TO_CLIENT.registerPacket( 0x43, Kick.class ); + TO_CLIENT.registerPacket( 0x38, PlayerListItem.class ); + TO_CLIENT.registerPacket( 0x3A, TabCompleteResponse.class ); + TO_CLIENT.registerPacket( 0x3B, ScoreboardObjective.class ); + TO_CLIENT.registerPacket( 0x3C, ScoreboardScore.class ); + TO_CLIENT.registerPacket( 0x3D, ScoreboardDisplay.class ); + TO_CLIENT.registerPacket( 0x3E, Team.class ); + TO_CLIENT.registerPacket( 0x3F, PluginMessage.class ); + TO_CLIENT.registerPacket( 0x40, Kick.class ); TO_SERVER.registerPacket( 0x00, KeepAlive.class ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java index 58dfa17c..a14fd155 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java @@ -5,9 +5,7 @@ import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.ToString; import net.md_5.bungee.protocol.AbstractPacketHandler; @Data From 4f8085678ce2c365f4f89b53d99df69530440abb Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 19 Oct 2013 17:27:13 +1100 Subject: [PATCH 18/24] 1.6.4 ping support --- .../protocol/AbstractPacketHandler.java | 5 ++ .../bungee/protocol/KickStringWriter.java | 20 ++++++++ .../md_5/bungee/protocol/LegacyDecoder.java | 31 +++++++++++++ .../bungee/protocol/MinecraftDecoder.java | 3 +- .../bungee/protocol/packet/LegacyPing.java | 46 +++++++++++++++++++ .../bungee/connection/InitialHandler.java | 19 +++++++- .../net/md_5/bungee/netty/PipelineUtils.java | 6 +++ 7 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/LegacyPing.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 37f0cba9..08b12630 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -17,6 +17,7 @@ import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.EncryptionResponse; +import net.md_5.bungee.protocol.packet.LegacyPing; import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; @@ -27,6 +28,10 @@ import net.md_5.bungee.protocol.packet.TabCompleteResponse; public abstract class AbstractPacketHandler { + public void handle(LegacyPing ping) throws Exception + { + } + public void handle(TabCompleteResponse tabResponse) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java b/protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java new file mode 100644 index 00000000..eda9571e --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java @@ -0,0 +1,20 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +public class KickStringWriter extends MessageToByteEncoder +{ + + @Override + protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception + { + out.writeByte( 0xFF ); + out.writeShort( msg.length() ); + for ( char c : msg.toCharArray() ) + { + out.writeChar( c ); + } + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java new file mode 100644 index 00000000..7cc06d9b --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java @@ -0,0 +1,31 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import java.util.List; +import net.md_5.bungee.protocol.packet.LegacyPing; + +public class LegacyDecoder extends ByteToMessageDecoder +{ + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception + { + if ( in.readableBytes() < 3 ) + { + return; + } + int i = in.readerIndex(); + short b1 = in.getUnsignedByte( i++ ); + short b2 = in.getUnsignedByte( i++ ); + short b3 = in.getUnsignedByte( i++ ); + + if ( b1 == 0xFE && b2 == 0x01 && b3 == 0xFA ) + { + out.add( new PacketWrapper( new LegacyPing(), Unpooled.EMPTY_BUFFER ) ); + } + ctx.pipeline().remove( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java index 1c6476fe..7a222d66 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java @@ -31,8 +31,7 @@ public class MinecraftDecoder extends ByteToMessageDecoder packet.read( in ); if ( in.readableBytes() != 0 ) { - System.out.println( in.toString( Charsets.UTF_8 ) ); - // throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); + throw new BadPacketException( "Did not read all bytes from packet " + packet.getClass() + " " + packetId + " Protocol " + protocol + " Direction " + prot ); } } else { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LegacyPing.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LegacyPing.java new file mode 100644 index 00000000..2ead20af --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LegacyPing.java @@ -0,0 +1,46 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +public class LegacyPing extends DefinedPacket +{ + + @Override + public void read(ByteBuf buf) + { + throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void write(ByteBuf buf) + { + throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } + + @Override + public boolean equals(Object obj) + { + throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int hashCode() + { + throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String toString() + { + throw new UnsupportedOperationException( "Not supported yet." ); //To change body of generated methods, choose Tools | Templates. + } + +} 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 a22e3b29..1a0a2db8 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 io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import java.math.BigInteger; import java.net.InetSocketAddress; import java.net.URLEncoder; @@ -44,8 +46,8 @@ import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; -import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.packet.LegacyPing; import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; @@ -119,6 +121,20 @@ public class InitialHandler extends PacketHandler implements PendingConnection } } + @Override + public void handle(LegacyPing ping) throws Exception + { + String kickMessage = ChatColor.DARK_BLUE + + "\00" + bungee.getProtocolVersion() + + "\00" + bungee.getGameVersion() + + "\00" + listener.getMotd() + + "\00" + bungee.getOnlineCount() + + "\00" + listener.getMaxPlayers(); + + ch.getHandle().writeAndFlush( kickMessage ); + ch.close(); + } + @Override public void handle(StatusRequest statusRequest) throws Exception { @@ -231,7 +247,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection // TODO: Nuuuu Mojang why u do this // unsafe().sendPacket( PacketConstants.I_AM_BUNGEE ); // unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST ); - unsafe().sendPacket( request = EncryptionUtil.encryptRequest( this.onlineMode ) ); thisState = State.ENCRYPT; } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index 24a24581..fd22e5c0 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -14,6 +14,8 @@ import net.md_5.bungee.UserConnection; import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ListenerInfo; +import net.md_5.bungee.protocol.KickStringWriter; +import net.md_5.bungee.protocol.LegacyDecoder; import net.md_5.bungee.protocol.MinecraftDecoder; import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.Protocol; @@ -39,8 +41,10 @@ public class PipelineUtils } BASE.initChannel( ch ); + ch.pipeline().addBefore( FRAME_DECODER, LEGACY_DECODER, new LegacyDecoder() ); ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true ) ); ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true ) ); + ch.pipeline().addBefore( FRAME_PREPENDER, LEGACY_KICKER, new KickStringWriter() ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); } }; @@ -54,6 +58,8 @@ public class PipelineUtils public static String DECRYPT_HANDLER = "decrypt"; public static String FRAME_DECODER = "frame-decoder"; public static String FRAME_PREPENDER = "frame-prepender"; + public static String LEGACY_DECODER = "legacy-decoder"; + public static String LEGACY_KICKER = "legacy-kick"; public final static class Base extends ChannelInitializer { From 00854988fb36f7f90ea7aa3747c976e7d7412ea4 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 19 Oct 2013 17:42:45 +1100 Subject: [PATCH 19/24] Latest snapshot. Doesnt seem to be worky though --- protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java | 4 ++-- .../src/main/java/net/md_5/bungee/protocol/packet/Login.java | 3 +++ .../main/java/net/md_5/bungee/protocol/packet/Respawn.java | 3 +++ proxy/src/main/java/net/md_5/bungee/PacketConstants.java | 4 ++-- proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 59c28f9d..cb1b6a68 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -92,8 +92,8 @@ public enum Protocol }; /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; - public static final int PROTOCOL_VERSION = 0x00; - public static final String MINECRAFT_VERSION = "13w41b"; + public static final int PROTOCOL_VERSION = 0x01; + public static final String MINECRAFT_VERSION = "13w42b"; /*========================================================================*/ public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index 321b93a8..ff41f7b9 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -20,6 +20,7 @@ public class Login extends DefinedPacket private int dimension; private short difficulty; private short maxPlayers; + private String levelType; @Override public void read(ByteBuf buf) @@ -29,6 +30,7 @@ public class Login extends DefinedPacket dimension = buf.readByte(); difficulty = buf.readUnsignedByte(); maxPlayers = buf.readUnsignedByte(); + levelType = readString( buf ); } @Override @@ -39,6 +41,7 @@ public class Login extends DefinedPacket buf.writeByte( dimension ); buf.writeByte( difficulty ); buf.writeByte( maxPlayers ); + writeString( levelType, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java index b5a44823..d0a7529e 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java @@ -18,6 +18,7 @@ public class Respawn extends DefinedPacket private int dimension; private short difficulty; private short gameMode; + private String levelType; @Override public void read(ByteBuf buf) @@ -25,6 +26,7 @@ public class Respawn extends DefinedPacket dimension = buf.readInt(); difficulty = buf.readUnsignedByte(); gameMode = buf.readUnsignedByte(); + levelType = readString( buf ); } @Override @@ -33,6 +35,7 @@ public class Respawn extends DefinedPacket buf.writeInt( dimension ); buf.writeByte( difficulty ); buf.writeByte( gameMode ); + writeString( levelType, buf ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java index 75fd9b55..82814b07 100644 --- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java @@ -7,8 +7,8 @@ import net.md_5.bungee.protocol.packet.PluginMessage; public class PacketConstants { - public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0 ); - public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0 ); + public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0, "default" ); + public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0, "default" ); public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 ); public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[] { diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 05f02263..d56e0f5e 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -131,7 +131,7 @@ public class ServerConnector extends PacketHandler // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), - (byte) user.getPendingConnection().getListener().getTabListSize() ); + (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType() ); user.unsafe().sendPacket( modLogin ); @@ -156,7 +156,7 @@ public class ServerConnector extends PacketHandler user.sendDimensionSwitch(); user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode() ) ); + user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); // Remove from old servers user.getServer().setObsolete( true ); From da5fa4bb7c161968a3b217867ea432321a0662ac Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 19 Oct 2013 17:50:54 +1100 Subject: [PATCH 20/24] Fix outdatedness --- .../md_5/bungee/connection/InitialHandler.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 1a0a2db8..042a8734 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 @@ -193,14 +193,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection bungee.getPluginManager().callEvent( new PlayerHandshakeEvent( InitialHandler.this, handshake ) ); - if ( handshake.getProtocolVersion() > bungee.getProtocolVersion() ) - { - disconnect( bungee.getTranslation( "outdated_server" ) ); - } else if ( handshake.getProtocolVersion() < bungee.getProtocolVersion() ) - { - disconnect( bungee.getTranslation( "outdated_client" ) ); - } - switch ( handshake.getRequestedProtocol() ) { case 1: @@ -224,6 +216,16 @@ public class InitialHandler extends PacketHandler implements PendingConnection Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" ); this.loginRequest = loginRequest; + if ( handshake.getProtocolVersion() > bungee.getProtocolVersion() ) + { + disconnect( bungee.getTranslation( "outdated_server" ) ); + return; + } else if ( handshake.getProtocolVersion() < bungee.getProtocolVersion() ) + { + disconnect( bungee.getTranslation( "outdated_client" ) ); + return; + } + if ( getName().length() > 16 ) { disconnect( "Cannot have username longer than 16 characters" ); From b7babd2888d1f19f1adb44b2a3024bd1f369a4fa Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 19 Oct 2013 17:56:14 +1100 Subject: [PATCH 21/24] Fix ping player counts being swapped --- .../main/java/net/md_5/bungee/connection/InitialHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 042a8734..67234e8d 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 @@ -167,7 +167,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { pingBack.done( new ServerPing( new ServerPing.Protocol( bungee.getGameVersion(), bungee.getProtocolVersion() ), - new ServerPing.Players( bungee.getOnlineCount(), listener.getMaxPlayers() ), + new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount() ), motd ), null ); } From cdf47d84d8176c85a8d5b83ccdd8e0111627b55a Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 19 Oct 2013 20:01:22 +1100 Subject: [PATCH 22/24] Fix offline mode. Latest snapshot appears to be pretty much functional, although the client itself seems to have some reliability issues. --- .../src/main/java/net/md_5/bungee/EncryptionUtil.java | 4 ++-- .../net/md_5/bungee/connection/InitialHandler.java | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 9cc2140d..eb7fe4f1 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -40,9 +40,9 @@ public class EncryptionUtil } } - public static EncryptionRequest encryptRequest(boolean onlinemode) + public static EncryptionRequest encryptRequest() { - String hash = ( onlinemode ) ? Long.toString( random.nextLong(), 16 ) : "-"; + String hash = Long.toString( random.nextLong(), 16 ); byte[] pubKey = keys.getPublic().getEncoded(); byte[] verify = new byte[ 4 ]; random.nextBytes( verify ); 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 67234e8d..89f9d299 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,8 +1,6 @@ package net.md_5.bungee.connection; import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import java.math.BigInteger; import java.net.InetSocketAddress; import java.net.URLEncoder; @@ -249,7 +247,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection // TODO: Nuuuu Mojang why u do this // unsafe().sendPacket( PacketConstants.I_AM_BUNGEE ); // unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST ); - unsafe().sendPacket( request = EncryptionUtil.encryptRequest( this.onlineMode ) ); + if ( this.onlineMode ) + { + unsafe().sendPacket( request = EncryptionUtil.encryptRequest() ); + } else + { + finish(); + } thisState = State.ENCRYPT; } From 21019643304df02eab3ef9c73d9edcdf304c7b51 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 23 Oct 2013 06:30:16 +1100 Subject: [PATCH 23/24] 1.7 pre release support --- protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index cb1b6a68..b21a64dd 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -92,8 +92,8 @@ public enum Protocol }; /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; - public static final int PROTOCOL_VERSION = 0x01; - public static final String MINECRAFT_VERSION = "13w42b"; + public static final int PROTOCOL_VERSION = 0x03; + public static final String MINECRAFT_VERSION = "1.7"; /*========================================================================*/ public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); From 0952e53d11318fa994ec46ca8264cc2f5121c128 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 23 Oct 2013 17:33:21 +1100 Subject: [PATCH 24/24] Update to 1.7 poms. --- api/pom.xml | 4 ++-- bootstrap/pom.xml | 4 ++-- config/pom.xml | 4 ++-- event/pom.xml | 4 ++-- pom.xml | 2 +- protocol/pom.xml | 4 ++-- proxy/pom.xml | 4 ++-- .../src/main/java/net/md_5/bungee/connection/PingHandler.java | 2 +- query/pom.xml | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 54c3345b..cf923879 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-api - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-API diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index f2107213..c81de384 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-bootstrap - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-Bootstrap diff --git a/config/pom.xml b/config/pom.xml index 8c7e4cff..b96e3420 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-config - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-Config diff --git a/event/pom.xml b/event/pom.xml index 51f10759..bb4a8313 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-event - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-Event diff --git a/pom.xml b/pom.xml index e4429247..cf3da354 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT pom BungeeCord diff --git a/protocol/pom.xml b/protocol/pom.xml index c25d094d..545508d5 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-protocol - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-Protocol diff --git a/proxy/pom.xml b/proxy/pom.xml index 3bee3d90..1369b852 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-proxy - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-Proxy diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index 8c6e72bd..8629f055 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -20,7 +20,7 @@ public class PingHandler extends PacketHandler @Override public void connected(ChannelWrapper channel) throws Exception { - // TODO: Update this to 1.6.4 style! + // TODO: Update this to 1.7 style! channel.write( Unpooled.wrappedBuffer( new byte[] { (byte) 0xFE, (byte) 0x01 diff --git a/query/pom.xml b/query/pom.xml index f86726ce..bcf3dc50 100644 --- a/query/pom.xml +++ b/query/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT ../pom.xml net.md-5 bungeecord-query - 1.6.4-SNAPSHOT + 1.7-SNAPSHOT jar BungeeCord-Query