From 6bc20ec13a478f0f3e3808f74278891a5acec6e3 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 2 Mar 2016 23:53:31 +0100 Subject: [PATCH 01/47] Update README.md --- README.md | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a0a3ac3876..cffef4b9ed 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,8 @@ -BungeeCord +BungeeCord for 1.7.10/1.8/1.9 ========== -The most reliable Minecraft server portal suite. ------------------------------------------------- -BungeeCord is a piece of Java software which allows a user to link multiple Minecraft servers together, allowing players to teleport between them and access advanced features. This makes it perfect for servers looking to expand their player base and spread across multiple gameplay styles. +This is a fork of md_5's BungeeCord +https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ -History -------- -For a long time developers have tried to create these mythical 'cloud' systems as outlined above. Until now, none of them have succeeded in making a fully open source and reliable 'cloud'. You may have already noticed my quoting of the word 'cloud', and this is one of the last times you will see it in this document. BungeeCord is **NOT** a 'cloud'. The actual meaning of the aforementioned word is quoted below: +This version reimplements Minecraft 1.7.10 and basic 1.7.10 Forge support. ->The use of computing resources (hardware and software) that are delivered as a service over a network (typically the Internet). - -BungeeCord does not do this and therefore is not a 'cloud'. Please do not refer to it as one, since the owners and operators of real clouds will get very angry, and you will be seen as ignorant and stupid. Instead I encourage you to use the term 'Server Port Suite' or something to that effect. - -Installation & Usage --------------------- -For and in depth guide to the installation and usage of BungeeCord you should check the current primary download location. The current link is provided below for your convenience. - - +This version is maintained by https://hexagonmc.eu From dd5da064ba1e889e55ff812cbfc509661e2d54c6 Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 00:37:50 +0100 Subject: [PATCH 02/47] Reimplemented legacy 1.7.* support --- README.md | 2 +- pom.xml | 17 +- .../md_5/bungee/protocol/DefinedPacket.java | 30 +++ .../bungee/protocol/MinecraftDecoder.java | 2 +- .../md_5/bungee/protocol/MinecraftInput.java | 38 ++++ .../md_5/bungee/protocol/MinecraftOutput.java | 56 ++++++ .../net/md_5/bungee/protocol/Protocol.java | 11 ++ .../bungee/protocol/ProtocolConstants.java | 3 + .../net/md_5/bungee/protocol/packet/Chat.java | 4 +- .../protocol/packet/ClientSettings.java | 8 + .../protocol/packet/EncryptionRequest.java | 22 ++- .../protocol/packet/EncryptionResponse.java | 22 ++- .../bungee/protocol/packet/KeepAlive.java | 16 +- .../protocol/packet/PlayerListItem.java | 179 ++++++++++-------- .../bungee/protocol/packet/PluginMessage.java | 29 ++- .../protocol/packet/ScoreboardObjective.java | 12 +- .../protocol/packet/ScoreboardScore.java | 32 +++- .../protocol/packet/TabCompleteRequest.java | 36 ++-- .../net/md_5/bungee/protocol/packet/Team.java | 32 +++- .../main/java/net/md_5/bungee/BungeeCord.java | 8 +- .../java/net/md_5/bungee/BungeeTitle.java | 13 +- .../net/md_5/bungee/PlayerInfoSerializer.java | 17 +- .../java/net/md_5/bungee/ServerConnector.java | 17 +- .../java/net/md_5/bungee/UserConnection.java | 28 +-- .../bungee/connection/DownstreamBridge.java | 21 +- .../bungee/connection/InitialHandler.java | 10 +- .../md_5/bungee/connection/PingHandler.java | 2 +- .../bungee/connection/UpstreamBridge.java | 5 +- .../net/md_5/bungee/entitymap/EntityMap.java | 4 + .../bungee/entitymap/EntityMap_1_7_2.java | 100 ++++++++++ .../bungee/entitymap/EntityMap_1_7_6.java | 60 ++++++ .../net/md_5/bungee/netty/HandlerBoss.java | 2 + .../main/java/net/md_5/bungee/tab/Global.java | 25 ++- .../java/net/md_5/bungee/tab/GlobalPing.java | 3 +- .../net/md_5/bungee/tab/ServerUnique.java | 45 ++++- .../java/net/md_5/bungee/tab/TabList.java | 3 + 36 files changed, 732 insertions(+), 182 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/MinecraftInput.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/MinecraftOutput.java create mode 100644 proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_2.java create mode 100644 proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java diff --git a/README.md b/README.md index cffef4b9ed..5f42305204 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -BungeeCord for 1.7.10/1.8/1.9 +BungeeCord for 1.7/1.8/1.9 ========== This is a fork of md_5's BungeeCord https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ diff --git a/pom.xml b/pom.xml index af523e1f46..df1056e91b 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ BungeeCord-Parent Parent project for all BungeeCord modules. - https://github.com/SpigotMC/BungeeCord + https://github.com/HexagonMC/BungeeCord 2012 SpigotMC @@ -34,6 +34,9 @@ md_5 + + Zartec + @@ -50,17 +53,17 @@ - scm:git:git@github.com:SpigotMC/BungeeCord.git - scm:git:git@github.com:SpigotMC/BungeeCord.git - git@github.com:SpigotMC/BungeeCord.git + scm:git:git@github.com:HexagonMC/BungeeCord.git + scm:git:git@github.com:HexagonMC/BungeeCord.git + git@github.com:HexagonMC/BungeeCord.git GitHub - https://github.com/SpigotMC/BungeeCord/issues + https://github.com/HexagonMC/BungeeCord/issues - jenkins - http://ci.md-5.net/job/BungeeCord + travis-ci + https://travis-ci.org/HexagonMC/BungeeCord 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 7eec240fa3..b7fd7e31fd 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 @@ -45,6 +45,36 @@ public static byte[] readArray(ByteBuf buf) buf.readBytes( ret ); return ret; } + + public static void writeArrayLegacy(byte[] b, ByteBuf buf, boolean allowExtended) + { + // (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit + if ( allowExtended ) + { + Preconditions.checkArgument( b.length <= ( Integer.MAX_VALUE & 0x1FFF9A ), "Cannot send array longer than 2097050 (got %s bytes)", b.length ); + } else + { + Preconditions.checkArgument( b.length <= Short.MAX_VALUE, "Cannot send array longer than Short.MAX_VALUE (got %s bytes)", b.length ); + } + // Write a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only) + // No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour. + writeVarShort( buf, b.length ); + buf.writeBytes( b ); + } + + public static byte[] readArrayLegacy(ByteBuf buf) + { + // Read in a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only) + // No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour. + int len = readVarShort( buf ); + + // (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit + Preconditions.checkArgument( len <= ( Integer.MAX_VALUE & 0x1FFF9A ), "Cannot receive array longer than 2097050 (got %s bytes)", len ); + + byte[] ret = new byte[ len ]; + buf.readBytes( ret ); + return ret; + } public static void writeStringArray(List s, ByteBuf buf) { 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 e7cb380342..9c5d4da17f 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 @@ -34,7 +34,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) t if ( in.isReadable() ) { - 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.getDirection().name() ); } } else { diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftInput.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftInput.java new file mode 100644 index 0000000000..ef2e269556 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftInput.java @@ -0,0 +1,38 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class MinecraftInput +{ + + private final ByteBuf buf; + + public byte readByte() + { + return buf.readByte(); + } + + public short readUnsignedByte() + { + return buf.readUnsignedByte(); + } + + public int readInt() + { + return buf.readInt(); + } + + public String readString() + { + short len = buf.readShort(); + char[] c = new char[ len ]; + for ( int i = 0; i < c.length; i++ ) + { + c[i] = buf.readChar(); + } + + return new String( c ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftOutput.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftOutput.java new file mode 100644 index 0000000000..94f6613d5d --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftOutput.java @@ -0,0 +1,56 @@ +package net.md_5.bungee.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.nio.charset.Charset; +import java.util.Arrays; + +public class MinecraftOutput +{ + + private final ByteBuf buf; + + public MinecraftOutput() + { + buf = Unpooled.buffer(); + } + + public byte[] toArray() + { + if ( buf.hasArray() ) + { + return Arrays.copyOfRange( buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.writerIndex() ); + } else + { + byte[] b = new byte[ buf.writerIndex() ]; + buf.readBytes( b ); + return b; + } + } + + public MinecraftOutput writeByte(byte b) + { + buf.writeByte( b ); + return this; + } + + public void writeInt(int i) + { + buf.writeInt( i ); + } + + public void writeString(String s) + { + char[] cc = s.toCharArray(); + buf.writeShort( cc.length ); + for ( char c : cc ) + { + buf.writeChar( c ); + } + } + + public void writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket(String s) + { + buf.writeBytes( s.getBytes( Charset.forName( "UTF-8" ) ) ); + } +} 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 26cf7c2b4b..d60ac86a2b 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 @@ -67,6 +67,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x3F, 0x18, PluginMessage.class ); TO_CLIENT.registerPacket( 0x40, 0x1A, Kick.class ); TO_CLIENT.registerPacket( 0x45, 0x45, Title.class ); + TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class ); TO_CLIENT.registerPacket( 0x47, 0x48, PlayerListHeaderFooter.class ); TO_SERVER.registerPacket( 0x00, 0x0B, KeepAlive.class ); @@ -105,6 +106,8 @@ public enum Protocol /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; public static List supportedVersions = Arrays.asList( + ProtocolConstants.MINECRAFT_1_7_2, + ProtocolConstants.MINECRAFT_1_7_6, ProtocolConstants.MINECRAFT_1_8, ProtocolConstants.MINECRAFT_1_9 ); @@ -127,6 +130,10 @@ public class DirectionData { + packetRemap.put( ProtocolConstants.MINECRAFT_1_7_2, new TIntIntHashMap() ); + packetRemapInv.put( ProtocolConstants.MINECRAFT_1_7_2, new TIntIntHashMap() ); + packetRemap.put( ProtocolConstants.MINECRAFT_1_7_6, new TIntIntHashMap() ); + packetRemapInv.put( ProtocolConstants.MINECRAFT_1_7_6, new TIntIntHashMap() ); packetRemap.put( ProtocolConstants.MINECRAFT_1_8, new TIntIntHashMap() ); packetRemapInv.put( ProtocolConstants.MINECRAFT_1_8, new TIntIntHashMap() ); packetRemap.put(ProtocolConstants.MINECRAFT_1_9, new TIntIntHashMap() ); @@ -176,6 +183,10 @@ protected final void registerPacket(int id, int newId, Class SUPPORTED_VERSIONS = Arrays.asList( + "1.7.x", "1.8.x", "1.9" ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java index 95ad39b766..6144bd6195 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java @@ -28,7 +28,7 @@ public Chat(String message) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { message = readString( buf ); - if ( direction == ProtocolConstants.Direction.TO_CLIENT ) + if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { position = buf.readByte(); } @@ -38,7 +38,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( message, buf ); - if ( direction == ProtocolConstants.Direction.TO_CLIENT ) + if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { buf.writeByte( position ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java index 0a54ac62e3..343ccd6612 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java @@ -31,6 +31,10 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco viewDistance = buf.readByte(); chatFlags = protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ? DefinedPacket.readVarInt( buf ) : buf.readUnsignedByte(); chatColours = buf.readBoolean(); + if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + difficulty = buf.readByte(); + } skinParts = buf.readByte(); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) { @@ -51,6 +55,10 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc buf.writeByte( chatFlags ); } buf.writeBoolean( chatColours ); + if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + buf.writeByte( difficulty ); + } buf.writeByte( skinParts ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) { 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 index a29524ca81..3d1a3f7904 100644 --- 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 @@ -24,16 +24,30 @@ public class EncryptionRequest extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { serverId = readString( buf ); - publicKey = readArray( buf ); - verifyToken = readArray( buf ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + publicKey = readArrayLegacy( buf ); + verifyToken = readArrayLegacy( buf ); + } else + { + publicKey = readArray( buf ); + verifyToken = readArray( buf ); + } } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( serverId, buf ); - writeArray( publicKey, buf ); - writeArray( verifyToken, buf ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + writeArrayLegacy( publicKey, buf, false ); + writeArrayLegacy( verifyToken, buf, false ); + } else + { + writeArray( publicKey, buf ); + writeArray( verifyToken, buf ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java index 1e6d8826b9..52a4eec809 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionResponse.java @@ -22,15 +22,29 @@ public class EncryptionResponse extends DefinedPacket @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - sharedSecret = readArray( buf ); - verifyToken = readArray( buf ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + sharedSecret = readArrayLegacy( buf ); + verifyToken = readArrayLegacy( buf ); + } else + { + sharedSecret = readArray( buf ); + verifyToken = readArray( buf ); + } } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - writeArray( sharedSecret, buf ); - writeArray( verifyToken, buf ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + writeArrayLegacy( sharedSecret, buf, false ); + writeArrayLegacy( verifyToken, buf, false ); + } else + { + writeArray( sharedSecret, buf ); + writeArray( verifyToken, buf ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java index 0960b7d8de..5172d8d0df 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/KeepAlive.java @@ -21,13 +21,25 @@ public class KeepAlive extends DefinedPacket @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - randomId = readVarInt( buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) + { + randomId = readVarInt( buf ); + } else + { + randomId = buf.readInt(); + } } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - writeVarInt( randomId, buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) + { + writeVarInt( randomId, buf ); + } else + { + buf.writeInt( randomId ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java index 198f724b6b..25c9bc6120 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerListItem.java @@ -22,53 +22,63 @@ public class PlayerListItem extends DefinedPacket @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - action = Action.values()[ DefinedPacket.readVarInt( buf )]; - items = new Item[ DefinedPacket.readVarInt( buf ) ]; - for ( int i = 0; i < items.length; i++ ) + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { - Item item = items[ i ] = new Item(); - item.setUuid( DefinedPacket.readUUID( buf ) ); - switch ( action ) + items = new Item[ 1 ]; + Item item = items[ 0 ] = new Item(); + item.displayName = item.username = readString( buf ); + action = !buf.readBoolean() ? Action.REMOVE_PLAYER : Action.ADD_PLAYER; + item.ping = buf.readShort(); + } else + { + action = Action.values()[ DefinedPacket.readVarInt( buf )]; + items = new Item[ DefinedPacket.readVarInt( buf ) ]; + for ( int i = 0; i < items.length; i++ ) { - case ADD_PLAYER: - item.username = DefinedPacket.readString( buf ); - item.properties = new String[ DefinedPacket.readVarInt( buf ) ][]; - for ( int j = 0; j < item.properties.length; j++ ) - { - String name = DefinedPacket.readString( buf ); - String value = DefinedPacket.readString( buf ); - if ( buf.readBoolean() ) + Item item = items[ i ] = new Item(); + item.setUuid( DefinedPacket.readUUID( buf ) ); + switch ( action ) + { + case ADD_PLAYER: + item.username = DefinedPacket.readString( buf ); + item.properties = new String[ DefinedPacket.readVarInt( buf ) ][]; + for ( int j = 0; j < item.properties.length; j++ ) { - item.properties[ j] = new String[] + String name = DefinedPacket.readString( buf ); + String value = DefinedPacket.readString( buf ); + if ( buf.readBoolean() ) { - name, value, DefinedPacket.readString( buf ) - }; - } else - { - item.properties[ j ] = new String[] + item.properties[ j] = new String[] + { + name, value, DefinedPacket.readString( buf ) + }; + } else { - name, value - }; + item.properties[ j ] = new String[] + { + name, value + }; + } + } + item.gamemode = DefinedPacket.readVarInt( buf ); + item.ping = DefinedPacket.readVarInt( buf ); + if ( buf.readBoolean() ) + { + item.displayName = DefinedPacket.readString( buf ); } - } - item.gamemode = DefinedPacket.readVarInt( buf ); - item.ping = DefinedPacket.readVarInt( buf ); - if ( buf.readBoolean() ) - { - item.displayName = DefinedPacket.readString( buf ); - } - break; - case UPDATE_GAMEMODE: - item.gamemode = DefinedPacket.readVarInt( buf ); - break; - case UPDATE_LATENCY: - item.ping = DefinedPacket.readVarInt( buf ); - break; - case UPDATE_DISPLAY_NAME: - if ( buf.readBoolean() ) - { - item.displayName = DefinedPacket.readString( buf ); - } + break; + case UPDATE_GAMEMODE: + item.gamemode = DefinedPacket.readVarInt( buf ); + break; + case UPDATE_LATENCY: + item.ping = DefinedPacket.readVarInt( buf ); + break; + case UPDATE_DISPLAY_NAME: + if ( buf.readBoolean() ) + { + item.displayName = DefinedPacket.readString( buf ); + } + } } } } @@ -76,50 +86,59 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - DefinedPacket.writeVarInt( action.ordinal(), buf ); - DefinedPacket.writeVarInt( items.length, buf ); - for ( Item item : items ) + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + Item item = items[0]; // Only one at a time + writeString( item.displayName, buf ); // TODO: Server unique only! + buf.writeBoolean( action != Action.REMOVE_PLAYER ); + buf.writeShort( item.ping ); + } else { - DefinedPacket.writeUUID( item.uuid, buf ); - switch ( action ) + DefinedPacket.writeVarInt( action.ordinal(), buf ); + DefinedPacket.writeVarInt( items.length, buf ); + for ( Item item : items ) { - case ADD_PLAYER: - DefinedPacket.writeString( item.username, buf ); - DefinedPacket.writeVarInt( item.properties.length, buf ); - for ( String[] prop : item.properties ) - { - DefinedPacket.writeString( prop[ 0], buf ); - DefinedPacket.writeString( prop[ 1], buf ); - if ( prop.length >= 3 ) + DefinedPacket.writeUUID( item.uuid, buf ); + switch ( action ) + { + case ADD_PLAYER: + DefinedPacket.writeString( item.username, buf ); + DefinedPacket.writeVarInt( item.properties.length, buf ); + for ( String[] prop : item.properties ) { - buf.writeBoolean( true ); - DefinedPacket.writeString( prop[ 2], buf ); - } else + DefinedPacket.writeString( prop[ 0], buf ); + DefinedPacket.writeString( prop[ 1], buf ); + if ( prop.length >= 3 ) + { + buf.writeBoolean( true ); + DefinedPacket.writeString( prop[ 2], buf ); + } else + { + buf.writeBoolean( false ); + } + } + DefinedPacket.writeVarInt( item.gamemode, buf ); + DefinedPacket.writeVarInt( item.ping, buf ); + buf.writeBoolean( item.displayName != null ); + if ( item.displayName != null ) + { + DefinedPacket.writeString( item.displayName, buf ); + } + break; + case UPDATE_GAMEMODE: + DefinedPacket.writeVarInt( item.gamemode, buf ); + break; + case UPDATE_LATENCY: + DefinedPacket.writeVarInt( item.ping, buf ); + break; + case UPDATE_DISPLAY_NAME: + buf.writeBoolean( item.displayName != null ); + if ( item.displayName != null ) { - buf.writeBoolean( false ); + DefinedPacket.writeString( item.displayName, buf ); } - } - DefinedPacket.writeVarInt( item.gamemode, buf ); - DefinedPacket.writeVarInt( item.ping, buf ); - buf.writeBoolean( item.displayName != null ); - if ( item.displayName != null ) - { - DefinedPacket.writeString( item.displayName, buf ); - } - break; - case UPDATE_GAMEMODE: - DefinedPacket.writeVarInt( item.gamemode, buf ); - break; - case UPDATE_LATENCY: - DefinedPacket.writeVarInt( item.ping, buf ); - break; - case UPDATE_DISPLAY_NAME: - buf.writeBoolean( item.displayName != null ); - if ( item.displayName != null ) - { - DefinedPacket.writeString( item.displayName, buf ); - } - break; + break; + } } } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java index 6e59526778..c1168d0a19 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java @@ -3,6 +3,7 @@ import com.google.common.base.Preconditions; 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; @@ -10,6 +11,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.MinecraftInput; import net.md_5.bungee.protocol.AbstractPacketHandler; import net.md_5.bungee.protocol.ProtocolConstants; @@ -32,17 +34,29 @@ public class PluginMessage extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { tag = readString( buf ); - int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; - Preconditions.checkArgument(buf.readableBytes() < maxSize); - data = new byte[ buf.readableBytes() ]; - buf.readBytes( data ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + data = readArrayLegacy( buf ); + } else + { + int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; + Preconditions.checkArgument(buf.readableBytes() < maxSize); + data = new byte[ buf.readableBytes() ]; + buf.readBytes( data ); + } } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( tag, buf ); - buf.writeBytes( data ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) + { + writeArrayLegacy( data, buf, allowExtendedPacket ); + } else + { + buf.writeBytes( data ); + } } @Override @@ -55,4 +69,9 @@ public DataInput getStream() { return new DataInputStream( new ByteArrayInputStream( data ) ); } + + public MinecraftInput getMCStream() + { + return new MinecraftInput( Unpooled.wrappedBuffer( data ) ); + } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java index ef9b8cf68a..a650b48245 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java @@ -28,8 +28,12 @@ public class ScoreboardObjective extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { name = readString( buf ); + if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + value = readString( buf ); + } action = buf.readByte(); - if ( action == 0 || action == 2 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && ( action == 0 || action == 2 ) ) { value = readString( buf ); type = readString( buf ); @@ -40,8 +44,12 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( name, buf ); + if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + writeString( value, buf ); + } buf.writeByte( action ); - if ( action == 0 || action == 2 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && ( action == 0 || action == 2 ) ) { writeString( value, buf ); writeString( type, buf ); 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 6f0de535d4..e8157005c8 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 @@ -29,10 +29,20 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { itemName = readString( buf ); action = buf.readByte(); - scoreName = readString( buf ); - if ( action != 1 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { - value = readVarInt( buf ); + scoreName = readString( buf ); + if ( action != 1 ) + { + value = readVarInt( buf ); + } + } else + { + if ( action != 1 ) + { + scoreName = readString( buf ); + value = buf.readInt(); + } } } @@ -41,10 +51,20 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc { writeString( itemName, buf ); buf.writeByte( action ); - writeString( scoreName, buf ); - if ( action != 1 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) + { + writeString( scoreName, buf ); + if ( action != 1 ) + { + writeVarInt( value, buf ); + } + } else { - writeVarInt( value, buf ); + if ( action != 1 ) + { + writeString( scoreName, buf ); + buf.writeInt( value ); + } } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java index e3bcbc330b..5234252aa1 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java @@ -25,14 +25,17 @@ public class TabCompleteRequest extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { cursor = readString( buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { - assumeCommand = buf.readBoolean(); - } - - if ( hasPositon = buf.readBoolean() ) - { - position = buf.readLong(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + { + assumeCommand = buf.readBoolean(); + } + + if ( hasPositon = buf.readBoolean() ) + { + position = buf.readLong(); + } } } @@ -40,15 +43,18 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( cursor, buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) - { - buf.writeBoolean( assumeCommand ); - } - - buf.writeBoolean( hasPositon ); - if ( hasPositon ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { - buf.writeLong( position ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + { + buf.writeBoolean( assumeCommand ); + } + + buf.writeBoolean( hasPositon ); + if ( hasPositon ) + { + buf.writeLong( position ); + } } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java index 846881f582..a5247a8601 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java @@ -50,16 +50,19 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco prefix = readString( buf ); suffix = readString( buf ); friendlyFire = buf.readByte(); - nameTagVisibility = readString( buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { - collisionRule = readString(buf); + nameTagVisibility = readString( buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + { + collisionRule = readString(buf); + } + color = buf.readByte(); } - color = buf.readByte(); } if ( mode == 0 || mode == 3 || mode == 4 ) { - int len = readVarInt( buf ); + int len = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) ? readVarInt( buf ) : buf.readShort(); players = new String[ len ]; for ( int i = 0; i < len; i++ ) { @@ -79,16 +82,25 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc writeString( prefix, buf ); writeString( suffix, buf ); buf.writeByte( friendlyFire ); - writeString( nameTagVisibility, buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) { - writeString( collisionRule, buf); + writeString( nameTagVisibility, buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) + { + writeString( collisionRule, buf); + } + buf.writeByte( color ); } - buf.writeByte( color ); } if ( mode == 0 || mode == 3 || mode == 4 ) { - writeVarInt( players.length, buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) + { + writeVarInt( players.length, buf ); + } else + { + buf.writeShort( players.length ); + } for ( String player : players ) { writeString( player, 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 e5afb89e92..1cda0af497 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -146,7 +146,13 @@ public class BungeeCord extends ProxyServer .registerTypeAdapter( BaseComponent.class, new ComponentSerializer() ) .registerTypeAdapter( TextComponent.class, new TextComponentSerializer() ) .registerTypeAdapter( TranslatableComponent.class, new TranslatableComponentSerializer() ) - .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer() ) + .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( ProtocolConstants.MINECRAFT_1_7_6 ) ) + .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); + public final Gson gsonLegacy = new GsonBuilder() + .registerTypeAdapter( BaseComponent.class, new ComponentSerializer() ) + .registerTypeAdapter( TextComponent.class, new TextComponentSerializer() ) + .registerTypeAdapter( TranslatableComponent.class, new TranslatableComponentSerializer() ) + .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( ProtocolConstants.MINECRAFT_1_7_2 ) ) .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); @Getter private ConnectionThrottle connectionThrottle; diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java b/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java index 1e11f68770..e9073c5d4c 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java @@ -152,11 +152,14 @@ private static void sendPacket(ProxiedPlayer player, DefinedPacket packet) @Override public Title send(ProxiedPlayer player) { - sendPacket( player, clear ); - sendPacket( player, reset ); - sendPacket( player, times ); - sendPacket( player, subtitle ); - sendPacket( player, title ); + if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + sendPacket( player, clear ); + sendPacket( player, reset ); + sendPacket( player, times ); + sendPacket( player, subtitle ); + sendPacket( player, title ); + } return this; } } diff --git a/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java b/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java index c8c4f1b9e7..e9530af965 100644 --- a/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java @@ -14,13 +14,20 @@ public class PlayerInfoSerializer implements JsonSerializer, JsonDeserializer { + private final int protocol; + + public PlayerInfoSerializer(int protocol) + { + this.protocol = protocol; + } + @Override public ServerPing.PlayerInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject js = json.getAsJsonObject(); ServerPing.PlayerInfo info = new ServerPing.PlayerInfo( js.get( "name" ).getAsString(), (UUID) null ); String id = js.get( "id" ).getAsString(); - if ( !id.contains( "-" ) ) + if ( protocol == 4 || !id.contains( "-" ) ) { info.setId( id ); } else @@ -35,7 +42,13 @@ public JsonElement serialize(ServerPing.PlayerInfo src, Type typeOfSrc, JsonSeri { JsonObject out = new JsonObject(); out.addProperty( "name", src.getName() ); - out.addProperty( "id", src.getUniqueId().toString() ); + if ( protocol == 4 ) + { + out.addProperty( "id", src.getId() ); + } else + { + out.addProperty( "id", src.getUniqueId().toString() ); + } return out; } } 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 71f87793b7..f15e066c04 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -30,6 +30,7 @@ import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.EncryptionRequest; @@ -198,10 +199,18 @@ public void handle(Login login) throws Exception user.unsafe().sendPacket( modLogin ); - ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); - DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand ); - user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) ); - brand.release(); + if ( user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8 ) + { + MinecraftOutput out = new MinecraftOutput(); + out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); + user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray(), handshakeHandler.isServerForge() ) ); + } else + { + ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); + DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand ); + user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) ); + brand.release(); + } } else { user.getServer().setObsolete( true ); 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 7139590a40..5eea7b4f3f 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -420,7 +420,7 @@ private void sendMessage(ChatMessageType position, String message) public void sendMessage(ChatMessageType position, BaseComponent... message) { // Action bar on 1.8 doesn't display the new JSON formattings, legacy works - send it using this for now - if ( position == ChatMessageType.ACTION_BAR && getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_8 ) + if ( position == ChatMessageType.ACTION_BAR && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 && getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_8 ) { sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) ); } else @@ -433,7 +433,7 @@ public void sendMessage(ChatMessageType position, BaseComponent... message) public void sendMessage(ChatMessageType position, BaseComponent message) { // Action bar on 1.8 doesn't display the new JSON formattings, legacy works - send it using this for now - if ( position == ChatMessageType.ACTION_BAR && getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_8 ) + if ( position == ChatMessageType.ACTION_BAR && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 && getPendingConnection().getVersion() <= ProtocolConstants.MINECRAFT_1_8 ) { sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) ); } else @@ -570,19 +570,25 @@ public Map getModList() @Override public void setTabHeader(BaseComponent header, BaseComponent footer) { - unsafe().sendPacket( new PlayerListHeaderFooter( - ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, - ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT - ) ); + if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + unsafe().sendPacket( new PlayerListHeaderFooter( + ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, + ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT + ) ); + } } @Override public void setTabHeader(BaseComponent[] header, BaseComponent[] footer) { - unsafe().sendPacket( new PlayerListHeaderFooter( - ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, - ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT - ) ); + if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + unsafe().sendPacket( new PlayerListHeaderFooter( + ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, + ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT + ) ); + } } @Override @@ -605,7 +611,7 @@ public String getExtraDataInHandshake() public void setCompressionThreshold(int compressionThreshold) { - if ( ch.getHandle().isActive() && this.compressionThreshold == -1 ) + if ( ch.getHandle().isActive() && this.compressionThreshold == -1 && getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) { this.compressionThreshold = compressionThreshold; unsafe.sendPacket( new SetCompression( compressionThreshold ) ); 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 974aeb253a..929a5cba76 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 @@ -230,13 +230,20 @@ public void handle(PluginMessage pluginMessage) throws Exception if ( pluginMessage.getTag().equals( "MC|Brand" ) ) { - ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); - String serverBrand = DefinedPacket.readString( brand ); - brand.release(); - brand = ByteBufAllocator.DEFAULT.heapBuffer(); - DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand ); - pluginMessage.setData( brand.array().clone() ); - brand.release(); + if ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); + String serverBrand = DefinedPacket.readString( brand ); + brand.release(); + brand = ByteBufAllocator.DEFAULT.heapBuffer(); + DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand ); + pluginMessage.setData( brand.array().clone() ); + brand.release(); + } else + { + String serverBrand = new String( pluginMessage.getData(), "UTF-8" ); + pluginMessage.setData( ( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand ).getBytes( "UTF-8" ) ); + } // changes in the packet are ignored so we need to send it manually con.unsafe().sendPacket( pluginMessage ); throw CancelSendSignal.INSTANCE; 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 34b1a4bcfc..fb09752494 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 @@ -214,7 +214,7 @@ public void done(ServerPing result, Throwable error) public void done(ProxyPingEvent pingResult, Throwable error) { BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); - Gson gson = BungeeCord.getInstance().gson; + Gson gson = handshake.getProtocolVersion() == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) ); } }; @@ -479,7 +479,13 @@ public void run() userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() ); userCon.init(); - unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between + if ( getVersion() >= ProtocolConstants.MINECRAFT_1_7_6 ) + { + unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between + } else + { + unsafe.sendPacket( new LoginSuccess( getUUID(), getName() ) ); // Without dashes, for older clients. + } ch.setProtocol( Protocol.GAME ); ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); 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 30fc7567c1..ba3260f399 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 @@ -53,7 +53,7 @@ public void exception(Throwable t) throws Exception @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") public void handle(StatusResponse statusResponse) throws Exception { - Gson gson = BungeeCord.getInstance().gson; + Gson gson = protocol == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; callback.done( gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null ); channel.close(); } 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 23d4f25661..c075cd5591 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 @@ -74,7 +74,10 @@ public void disconnected(ChannelWrapper channel) throws Exception } ); for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() ) { - player.unsafe().sendPacket( packet ); + if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + player.unsafe().sendPacket( packet ); + } } con.getServer().disconnect( "Quitting" ); } diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java index 17f9454642..099c02bd40 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java @@ -25,6 +25,10 @@ public static EntityMap getEntityMap(int version) { switch ( version ) { + case ProtocolConstants.MINECRAFT_1_7_2: + return EntityMap_1_7_2.INSTANCE; + case ProtocolConstants.MINECRAFT_1_7_6: + return EntityMap_1_7_6.INSTANCE; case ProtocolConstants.MINECRAFT_1_8: return EntityMap_1_8.INSTANCE; case ProtocolConstants.MINECRAFT_1_9: diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_2.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_2.java new file mode 100644 index 0000000000..05097bba44 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_2.java @@ -0,0 +1,100 @@ +package net.md_5.bungee.entitymap; + +import io.netty.buffer.ByteBuf; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.ProtocolConstants; + +class EntityMap_1_7_2 extends EntityMap +{ + + static final EntityMap INSTANCE = new EntityMap_1_7_2(); + + EntityMap_1_7_2() + { + addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Equipment + addRewrite( 0x0A, ProtocolConstants.Direction.TO_CLIENT, false ); // Use bed + addRewrite( 0x0B, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation + addRewrite( 0x0C, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player + addRewrite( 0x0D, ProtocolConstants.Direction.TO_CLIENT, false ); // Collect Item + addRewrite( 0x0E, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Object + addRewrite( 0x0F, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Mob + addRewrite( 0x10, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Painting + addRewrite( 0x11, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Experience Orb + addRewrite( 0x12, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Velocity + addRewrite( 0x14, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity + addRewrite( 0x15, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Relative Move + addRewrite( 0x16, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Look + addRewrite( 0x17, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Look and Relative Move + addRewrite( 0x18, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Teleport + addRewrite( 0x19, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Head Look + addRewrite( 0x1A, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status + addRewrite( 0x1B, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity + addRewrite( 0x1C, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Metadata + addRewrite( 0x1D, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Effect + addRewrite( 0x1E, ProtocolConstants.Direction.TO_CLIENT, false ); // Remove Entity Effect + addRewrite( 0x20, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Properties + addRewrite( 0x25, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation + addRewrite( 0x2C, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Global Entity + + addRewrite( 0x02, ProtocolConstants.Direction.TO_SERVER, false ); // Use Entity + addRewrite( 0x0A, ProtocolConstants.Direction.TO_SERVER, false ); // Animation + addRewrite( 0x0B, ProtocolConstants.Direction.TO_SERVER, false ); // Entity Action + } + + @Override + public void rewriteClientbound(ByteBuf packet, int oldId, int newId) + { + super.rewriteClientbound( packet, oldId, newId ); + + //Special cases + int readerIndex = packet.readerIndex(); + int packetId = DefinedPacket.readVarInt( packet ); + int packetIdLength = packet.readerIndex() - readerIndex; + if ( packetId == 0x0D /* Collect Item */ || packetId == 0x1B /* Attach Entity */ ) + { + rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 ); + } else if ( packetId == 0x13 /* Destroy Entities */ ) + { + int count = packet.getByte( packetIdLength ); + for ( int i = 0; i < count; i++ ) + { + rewriteInt( packet, oldId, newId, packetIdLength + 1 + i * 4 ); + } + } else if ( packetId == 0x0E /* Spawn Object */ ) + { + DefinedPacket.readVarInt( packet ); + int type = packet.readUnsignedByte(); + + if ( type == 60 || type == 90 ) + { + packet.skipBytes( 14 ); + int position = packet.readerIndex(); + int readId = packet.readInt(); + int changedId = -1; + if ( readId == oldId ) + { + packet.setInt( position, newId ); + changedId = newId; + } else if ( readId == newId ) + { + packet.setInt( position, oldId ); + changedId = oldId; + } + if ( changedId != -1 ) + { + if ( changedId == 0 && readId != 0 ) + { // Trim off the extra data + packet.readerIndex( readerIndex ); + packet.writerIndex( packet.readableBytes() - 6 ); + } else if ( changedId != 0 && readId == 0 ) + { // Add on the extra data + packet.readerIndex( readerIndex ); + packet.capacity( packet.readableBytes() + 6 ); + packet.writerIndex( packet.readableBytes() + 6 ); + } + } + } + } + packet.readerIndex( readerIndex ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java new file mode 100644 index 0000000000..301da0e700 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java @@ -0,0 +1,60 @@ +package net.md_5.bungee.entitymap; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import io.netty.buffer.ByteBuf; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.UserConnection; +import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.protocol.DefinedPacket; + +class EntityMap_1_7_6 extends EntityMap_1_7_2 +{ + + static final EntityMap_1_7_6 INSTANCE = new EntityMap_1_7_6(); + + @Override + @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") + public void rewriteClientbound(ByteBuf packet, int oldId, int newId) + { + super.rewriteClientbound( packet, oldId, newId ); + + int readerIndex = packet.readerIndex(); + int packetId = DefinedPacket.readVarInt( packet ); + int packetIdLength = packet.readerIndex() - readerIndex; + if ( packetId == 0x0C /* Spawn Player */ ) + { + DefinedPacket.readVarInt( packet ); + int idLength = packet.readerIndex() - readerIndex - packetIdLength; + String uuid = DefinedPacket.readString( packet ); + String username = DefinedPacket.readString( packet ); + int props = DefinedPacket.readVarInt( packet ); + if ( props == 0 ) + { + UserConnection player = (UserConnection) BungeeCord.getInstance().getPlayer( username ); + if ( player != null ) + { + LoginResult profile = player.getPendingConnection().getLoginProfile(); + if ( profile != null && profile.getProperties() != null + && profile.getProperties().length >= 1 ) + { + ByteBuf rest = packet.copy(); + packet.readerIndex( readerIndex ); + packet.writerIndex( readerIndex + packetIdLength + idLength ); + DefinedPacket.writeString( player.getUniqueId().toString(), packet ); + DefinedPacket.writeString( username, packet ); + DefinedPacket.writeVarInt( profile.getProperties().length, packet ); + for ( LoginResult.Property property : profile.getProperties() ) + { + DefinedPacket.writeString( property.getName(), packet ); + DefinedPacket.writeString( property.getValue(), packet ); + DefinedPacket.writeString( property.getSignature(), packet ); + } + packet.writeBytes( rest ); + rest.release(); + } + } + } + } + packet.readerIndex( readerIndex ); + } +} 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 8b9712bf1d..01e908fa2e 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 @@ -104,6 +104,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E { handler, cause.getCause().getMessage() } ); + + cause.printStackTrace(); } else if ( cause instanceof IOException ) { ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - IOException: {1}", new Object[] 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 32c6da7518..9e498f3a05 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 @@ -38,7 +38,7 @@ public void onPingChange(int ping) PlayerListItem.Item item = new PlayerListItem.Item(); item.setUuid( player.getUniqueId() ); item.setUsername( player.getName() ); - item.setDisplayName( ComponentSerializer.toString( TextComponent.fromLegacyText( player.getDisplayName() ) ) ); + item.setDisplayName( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ? ComponentSerializer.toString( TextComponent.fromLegacyText( player.getDisplayName() ) ) : player.getDisplayName() ); item.setPing( player.getPing() ); packet.setItems( new PlayerListItem.Item[] { @@ -68,7 +68,7 @@ public void onConnect() PlayerListItem.Item item = items[i++] = new PlayerListItem.Item(); item.setUuid( p.getUniqueId() ); item.setUsername( p.getName() ); - item.setDisplayName( ComponentSerializer.toString( TextComponent.fromLegacyText( p.getDisplayName() ) ) ); + item.setDisplayName( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ? ComponentSerializer.toString( TextComponent.fromLegacyText( p.getDisplayName() ) ) : p.getDisplayName() ); LoginResult loginResult = ( (UserConnection) p ).getPendingConnection().getLoginProfile(); if ( loginResult != null ) { @@ -90,13 +90,30 @@ public void onConnect() item.setGamemode( ( (UserConnection) p ).getGamemode() ); item.setPing( p.getPing() ); } - player.unsafe().sendPacket( playerListItem ); + if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + player.unsafe().sendPacket( playerListItem ); + } else + { + // Split up the packet + for ( PlayerListItem.Item item : playerListItem.getItems() ) + { + PlayerListItem packet = new PlayerListItem(); + packet.setAction( playerListItem.getAction() ); + + packet.setItems( new PlayerListItem.Item[] + { + item + } ); + player.unsafe().sendPacket( packet ); + } + } PlayerListItem packet = new PlayerListItem(); packet.setAction( PlayerListItem.Action.ADD_PLAYER ); PlayerListItem.Item item = new PlayerListItem.Item(); item.setUuid( player.getUniqueId() ); item.setUsername( player.getName() ); - item.setDisplayName( ComponentSerializer.toString( TextComponent.fromLegacyText( player.getDisplayName() ) ) ); + item.setDisplayName( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ? ComponentSerializer.toString( TextComponent.fromLegacyText( player.getDisplayName() ) ) : player.getDisplayName() ); LoginResult loginResult = ( (UserConnection) player ).getPendingConnection().getLoginProfile(); if ( loginResult != null ) { 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 fb4991c1d6..25ed37aeee 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 @@ -4,6 +4,7 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.chat.ComponentSerializer; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.PlayerListItem; public class GlobalPing extends Global @@ -29,7 +30,7 @@ public void onPingChange(int ping) PlayerListItem.Item item = new PlayerListItem.Item(); item.setUuid( player.getUniqueId() ); item.setUsername( player.getName() ); - item.setDisplayName( ComponentSerializer.toString( TextComponent.fromLegacyText( player.getDisplayName() ) ) ); + item.setDisplayName( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ? ComponentSerializer.toString( TextComponent.fromLegacyText( player.getDisplayName() ) ) : player.getDisplayName() ); item.setPing( player.getPing() ); packet.setItems( new PlayerListItem.Item[] { 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 0f7edadd56..c6629a9d7c 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 @@ -12,6 +12,7 @@ public class ServerUnique extends TabList { private final Collection uuids = new HashSet<>(); + private final Collection usernames = new HashSet<>(); // Support for <=1.7.9 public ServerUnique(ProxiedPlayer player) { @@ -25,10 +26,22 @@ public void onUpdate(PlayerListItem playerListItem) { if ( playerListItem.getAction() == PlayerListItem.Action.ADD_PLAYER ) { - uuids.add( item.getUuid() ); + if ( item.getUuid() != null ) + { + uuids.add( item.getUuid() ); + } else + { + usernames.add( item.getUsername() ); + } } else if ( playerListItem.getAction() == PlayerListItem.Action.REMOVE_PLAYER ) { - uuids.remove( item.getUuid() ); + if ( item.getUuid() != null ) + { + uuids.remove( item.getUuid() ); + } else + { + usernames.remove( item.getUsername() ); + } } } player.unsafe().sendPacket( playerListItem ); @@ -45,16 +58,40 @@ public void onServerChange() { PlayerListItem packet = new PlayerListItem(); packet.setAction( PlayerListItem.Action.REMOVE_PLAYER ); - PlayerListItem.Item[] items = new PlayerListItem.Item[ uuids.size() ]; + PlayerListItem.Item[] items = new PlayerListItem.Item[ uuids.size() + usernames.size() ]; int i = 0; for ( UUID uuid : uuids ) { PlayerListItem.Item item = items[i++] = new PlayerListItem.Item(); item.setUuid( uuid ); } + for ( String username : usernames ) + { + PlayerListItem.Item item = items[i++] = new PlayerListItem.Item(); + item.setUsername( username ); + item.setDisplayName( username ); + } packet.setItems( items ); - player.unsafe().sendPacket( packet ); + if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + { + player.unsafe().sendPacket( packet ); + } else + { + // Split up the packet + for ( PlayerListItem.Item item : packet.getItems() ) + { + PlayerListItem p2 = new PlayerListItem(); + p2.setAction( packet.getAction() ); + + p2.setItems( new PlayerListItem.Item[] + { + item + } ); + player.unsafe().sendPacket( p2 ); + } + } uuids.clear(); + usernames.clear(); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/tab/TabList.java b/proxy/src/main/java/net/md_5/bungee/tab/TabList.java index 4546a83a9a..e3116261b5 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/TabList.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/TabList.java @@ -3,8 +3,11 @@ import lombok.RequiredArgsConstructor; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.UserConnection; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.PlayerListItem; @RequiredArgsConstructor From a2e7a53ac6ec50c85c3849d7dfb5cf75534a5c3c Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 00:46:26 +0100 Subject: [PATCH 03/47] Added build status --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5f42305204..e2e636847c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ + BungeeCord for 1.7/1.8/1.9 ========== +[![Build Status](https://travis-ci.org/hexagonmc/BungeeCord.svg?branch=master)](https://travis-ci.org/hexagonmc/BungeeCord) + This is a fork of md_5's BungeeCord https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ From 911459e498664b479e0a78d3435a780341a96b94 Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 00:56:47 +0100 Subject: [PATCH 04/47] Added custom install step --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1cd525b712..303978dd95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,10 @@ jdk: - openjdk7 - oraclejdk7 - oraclejdk8 +branches: + only: + - master notifications: email: false +install: + - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dbuild.number=$TRAVIS_BUILD_NUMBER -B -V From 904a3522f8932552afd87013964779617ffe5a43 Mon Sep 17 00:00:00 2001 From: ghacproductions Date: Thu, 3 Mar 2016 01:04:01 +0100 Subject: [PATCH 05/47] Deploy things to github. --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index 303978dd95..9aedd04c5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,13 @@ notifications: email: false install: - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dbuild.number=$TRAVIS_BUILD_NUMBER -B -V +deploy: + provider: releases + api_key: + secure: ljpg29wmo0yPs+qXBVj1vHnY4WPXB1hNMDnHMxhXbPRhK5l9kCqJWy4YjJ6BbEb4keU5dMmt+cyB+Njr3IomJMoupVu0Osut/SNz4g0UZFTYYJQjvrurdmGxoh9E7xmc6Pcly+Pw99RSpqK+yD8SDDepTleHDv/8pC0d4Z5NZIJ9JJUeY2in1RXpStj7rJtmSN5XWFpWBGpHElFQqaSDfh62zn3bvb7J9oVA+NtBDXgpY1Km1Q76Evt4PuijOgdWx4rcNpi7UOd6XurkYuo4/igBEUE8HQSEIqgC0jxJg0gxtLbymPvW4sPXmEPhZwIUvoYFjX0DvlIqU8hbr/2CPtcHiKqnqTU92wgFFnf3Xvn2mdoCrgHDOcSA2JWsR70077bPzv+llNHN17mDlGE7vIiv54jNBkJpem8OBgDNIU2lDnhwZQr3ifZJ0ydhdhkYK7Kp1lAZtEZwbqs6cetlwLiuBH6wd3dErBduPQNLnl22qdhQQJFBXPkj+vHBAt9uSB3irWWME0XsR6G9OpzDYoO64vkkHnz1k7VK37ud2pe7yKYuUr+MUbyBnzycbKOhYRufPkMv8RJIbRH6lChRrZOamqbZTa1FFYsemgcJ9NG990tE0zJHw0G3vU+emxPY35UPIMZrSbzQ8mCOlwKfhAtubZRNe+V0ohJFvVx/dhI= + file: + - bootstrap/target/BungeeCord.jar + - module/*/target/*.jar + file_glob: true + on: + repo: hexagonmc/BungeeCord From b38737c286a710f449450a7d24801eaf78afbe4e Mon Sep 17 00:00:00 2001 From: ghacproductions Date: Thu, 3 Mar 2016 01:09:37 +0100 Subject: [PATCH 06/47] Dont't delete artifacts before deploying. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9aedd04c5a..d09e325768 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ install: - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dbuild.number=$TRAVIS_BUILD_NUMBER -B -V deploy: provider: releases + skip_cleanup: true api_key: secure: ljpg29wmo0yPs+qXBVj1vHnY4WPXB1hNMDnHMxhXbPRhK5l9kCqJWy4YjJ6BbEb4keU5dMmt+cyB+Njr3IomJMoupVu0Osut/SNz4g0UZFTYYJQjvrurdmGxoh9E7xmc6Pcly+Pw99RSpqK+yD8SDDepTleHDv/8pC0d4Z5NZIJ9JJUeY2in1RXpStj7rJtmSN5XWFpWBGpHElFQqaSDfh62zn3bvb7J9oVA+NtBDXgpY1Km1Q76Evt4PuijOgdWx4rcNpi7UOd6XurkYuo4/igBEUE8HQSEIqgC0jxJg0gxtLbymPvW4sPXmEPhZwIUvoYFjX0DvlIqU8hbr/2CPtcHiKqnqTU92wgFFnf3Xvn2mdoCrgHDOcSA2JWsR70077bPzv+llNHN17mDlGE7vIiv54jNBkJpem8OBgDNIU2lDnhwZQr3ifZJ0ydhdhkYK7Kp1lAZtEZwbqs6cetlwLiuBH6wd3dErBduPQNLnl22qdhQQJFBXPkj+vHBAt9uSB3irWWME0XsR6G9OpzDYoO64vkkHnz1k7VK37ud2pe7yKYuUr+MUbyBnzycbKOhYRufPkMv8RJIbRH6lChRrZOamqbZTa1FFYsemgcJ9NG990tE0zJHw0G3vU+emxPY35UPIMZrSbzQ8mCOlwKfhAtubZRNe+V0ohJFvVx/dhI= file: From 89641b75184a86fb19c0e39a6cdd0982bd20eaff Mon Sep 17 00:00:00 2001 From: ghacproductions Date: Thu, 3 Mar 2016 01:11:15 +0100 Subject: [PATCH 07/47] Only deploy when tag is set. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d09e325768..79a1e9d412 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,3 +22,4 @@ deploy: file_glob: true on: repo: hexagonmc/BungeeCord + tags: true From e6484778061906f0bb837096387d53087a49bf33 Mon Sep 17 00:00:00 2001 From: ghacproductions Date: Thu, 3 Mar 2016 01:14:13 +0100 Subject: [PATCH 08/47] Only deploy when tag is set. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 79a1e9d412..b9d98b79e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,4 @@ deploy: - module/*/target/*.jar file_glob: true on: - repo: hexagonmc/BungeeCord tags: true From 2ac49c9959061ca63a4e6e08e36ffdfbf3f61414 Mon Sep 17 00:00:00 2001 From: devryb Date: Tue, 28 Apr 2015 01:04:59 -0400 Subject: [PATCH 09/47] Update EntityMap.java to fix negitive packetID --- .../java/net/md_5/bungee/entitymap/EntityMap.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java index 099c02bd40..5b658359d3 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java @@ -106,12 +106,14 @@ private static void rewrite(ByteBuf packet, int oldId, int newId, boolean[] ints int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; - if ( ints[ packetId ] ) - { - rewriteInt( packet, oldId, newId, readerIndex + packetIdLength ); - } else if ( varints[ packetId ] ) - { - rewriteVarInt( packet, oldId, newId, readerIndex + packetIdLength ); + if(packetId>=0) { + if ( ints[ packetId ] ) + { + rewriteInt( packet, oldId, newId, readerIndex + packetIdLength ); + } else if ( varints[ packetId ] ) + { + rewriteVarInt( packet, oldId, newId, readerIndex + packetIdLength ); + } } packet.readerIndex( readerIndex ); } From 5f5237e2b7a088105470d3ab60060968183b88ac Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 01:27:41 +0100 Subject: [PATCH 10/47] Added automatic tagging to build script --- .travis.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9d98b79e9..31817b8c47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,21 @@ jdk: - oraclejdk7 - oraclejdk8 branches: - only: - - master + except: + - /^v[0-9]*/ notifications: email: false install: - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dbuild.number=$TRAVIS_BUILD_NUMBER -B -V +after_success: + # CREATE GIT TAG + - git config --global user.email "builds@travis-ci.com" + - git config --global user.name "Travis CI" + - export GIT_TAG=v$TRAVIS_BUILD_NUMBER + - echo -n $GIT_TAG > VERSION + - git commit -m "Set build VERSION number" VERSION + - git tag $GIT_TAG -a -m "Generated tag from TravisCI build $TRAVIS_BUILD_NUMBER" + - git push --quiet https://$GITHUBKEY@github.com/dev-confidence/example-backend-api $GIT_TAG > /dev/null 2>&1 deploy: provider: releases skip_cleanup: true From 443a2e06a37fa928cec4b373d97dc7034821acc0 Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 01:44:35 +0100 Subject: [PATCH 11/47] Changed build script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31817b8c47..f6f395feb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,4 +30,4 @@ deploy: - module/*/target/*.jar file_glob: true on: - tags: true + branch: master From 386a2fcbfcddc80ad334b5685227ba645a7803c6 Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 01:51:41 +0100 Subject: [PATCH 12/47] Implemented travis ci module source --- .../net/md_5/bungee/module/ModuleManager.java | 13 +++---- .../bungee/module/TravisCiModuleSource.java | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java diff --git a/proxy/src/main/java/net/md_5/bungee/module/ModuleManager.java b/proxy/src/main/java/net/md_5/bungee/module/ModuleManager.java index 901fc5a37c..8c14590090 100644 --- a/proxy/src/main/java/net/md_5/bungee/module/ModuleManager.java +++ b/proxy/src/main/java/net/md_5/bungee/module/ModuleManager.java @@ -29,6 +29,7 @@ public class ModuleManager public ModuleManager() { knownSources.put( "jenkins", new JenkinsModuleSource() ); + knownSources.put( "travis-ci", new TravisCiModuleSource() ); } @SuppressFBWarnings( @@ -80,13 +81,13 @@ public void load(ProxyServer proxy, File moduleDirectory) throws Exception switch ( version ) { case 0: - defaults.add( "jenkins://cmd_alert" ); - defaults.add( "jenkins://cmd_find" ); - defaults.add( "jenkins://cmd_list" ); - defaults.add( "jenkins://cmd_send" ); - defaults.add( "jenkins://cmd_server" ); + defaults.add( "travis-ci://cmd_alert" ); + defaults.add( "travis-ci://cmd_find" ); + defaults.add( "travis-ci://cmd_list" ); + defaults.add( "travis-ci://cmd_send" ); + defaults.add( "travis-ci://cmd_server" ); case 1: - defaults.add( "jenkins://reconnect_yaml" ); + defaults.add( "travis-ci://reconnect_yaml" ); } config.put( "modules", defaults ); config.put( "version", 2 ); diff --git a/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java b/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java new file mode 100644 index 0000000000..cfa7ede402 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/module/TravisCiModuleSource.java @@ -0,0 +1,36 @@ +package net.md_5.bungee.module; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; + +import com.google.common.io.ByteStreams; +import com.google.common.io.Files; + +import lombok.Data; +import net.md_5.bungee.Util; + +@Data +public class TravisCiModuleSource implements ModuleSource +{ + + @Override + public void retrieve(ModuleSpec module, ModuleVersion version) + { + System.out.println( "Attempting to Jenkins download module " + module.getName() + " v" + version.getBuild() ); + try + { + URL website = new URL( "https://github.com/HexagonMC/BungeeCord/releases/download/v" + version.getBuild() + "/" + module.getName() + ".jar" ); + URLConnection con = website.openConnection(); + // 15 second timeout at various stages + con.setConnectTimeout( 15000 ); + con.setReadTimeout( 15000 ); + + Files.write( ByteStreams.toByteArray( con.getInputStream() ), module.getFile() ); + System.out.println( "Download complete" ); + } catch ( IOException ex ) + { + System.out.println( "Failed to download: " + Util.exception( ex ) ); + } + } +} From 705918b757ebfbd60589d2b7b93eec79ad5a020e Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 01:57:31 +0100 Subject: [PATCH 13/47] Build only with oracle jdk 8 --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6f395feb4..ccb9a77c8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ sudo: false language: java jdk: - - openjdk7 - - oraclejdk7 - oraclejdk8 branches: except: From 690a63cc7df19c16b67caa59941065ada2066d1b Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 02:02:16 +0100 Subject: [PATCH 14/47] Cache dependencies between builds --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index ccb9a77c8b..46ef5a286e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,3 +29,6 @@ deploy: file_glob: true on: branch: master +cache: + directories: + - $HOME/.m2 From b54e74d77da9f960c42b0dafd919af4a0f45427e Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 03:51:39 +0100 Subject: [PATCH 15/47] Update README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e2e636847c..8e758a2c9f 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,8 @@ https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ This version reimplements Minecraft 1.7.10 and basic 1.7.10 Forge support. This version is maintained by https://hexagonmc.eu + +###Releases can be downloaded here: [Releases](https://github.com/HexagonMC/BungeeCord/releases) +``` +Modules are automatically downloaded from the releases page. +``` From 01c9cf04822367829e7f81562f0444bf641130e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lei=C3=9F?= Date: Thu, 3 Mar 2016 17:30:17 +0100 Subject: [PATCH 16/47] Fix. --- .../java/net/md_5/bungee/protocol/Protocol.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 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 d60ac86a2b..f632b0b0ad 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 @@ -67,7 +67,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x3F, 0x18, PluginMessage.class ); TO_CLIENT.registerPacket( 0x40, 0x1A, Kick.class ); TO_CLIENT.registerPacket( 0x45, 0x45, Title.class ); - TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class ); + TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class, false ); TO_CLIENT.registerPacket( 0x47, 0x48, PlayerListHeaderFooter.class ); TO_SERVER.registerPacket( 0x00, 0x0B, KeepAlive.class ); @@ -172,6 +172,11 @@ protected final void registerPacket(int id, Class packe } protected final void registerPacket(int id, int newId, Class packetClass) + { + registerPacket( id, newId, packetClass, true ); + } + + protected final void registerPacket(int id, int newId, Class packetClass, boolean also19) { try { @@ -189,8 +194,11 @@ protected final void registerPacket(int id, int newId, Class Date: Thu, 3 Mar 2016 19:58:25 +0100 Subject: [PATCH 17/47] Fixed priority list --- pom.xml | 3 +++ proxy/src/main/java/net/md_5/bungee/UserConnection.java | 1 + 2 files changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index df1056e91b..27cf01b527 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,9 @@ Zartec + + ghac + 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 5eea7b4f3f..6f9f2fbf9c 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -240,6 +240,7 @@ public ServerInfo updateAndGetNextServer(ServerInfo currentTarget) if ( !Objects.equal( currentTarget, candidate ) ) { next = candidate; + break; } } From 50904ba6c3bd4c4a8f9c690476a3ff2dd91ff36d Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 20:13:07 +0100 Subject: [PATCH 18/47] Fixed merge error --- protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5b47829354..97eacd9fd3 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 @@ -69,7 +69,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x3F, 0x18, PluginMessage.class ); TO_CLIENT.registerPacket( 0x40, 0x1A, Kick.class ); TO_CLIENT.registerPacket( 0x45, 0x45, Title.class ); - TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class, false ); + TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class, true ); TO_CLIENT.registerPacket( 0x47, 0x48, PlayerListHeaderFooter.class ); TO_SERVER.registerPacket( 0x00, 0x0B, KeepAlive.class ); From ba4625a32e4e546bf34901a44798e13130b876c8 Mon Sep 17 00:00:00 2001 From: Zartec Date: Thu, 3 Mar 2016 20:15:53 +0100 Subject: [PATCH 19/47] Fixed more merge errors :/ --- .../java/net/md_5/bungee/ServerConnector.java | 346 ++++++------ .../bungee/connection/DownstreamBridge.java | 502 ++++++++---------- 2 files changed, 393 insertions(+), 455 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 915766ce72..cf24ef92d7 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -1,12 +1,14 @@ package net.md_5.bungee; -import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; import java.util.Queue; import java.util.Set; import java.util.UUID; + +import com.google.common.base.Preconditions; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ChatColor; @@ -31,7 +33,7 @@ import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.Protocol; -import net.md_5.bungee.protocol.packet.BossBar; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Kick; @@ -42,88 +44,84 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.SetCompression; + @RequiredArgsConstructor public class ServerConnector extends PacketHandler { - - private final ProxyServer bungee; - private ChannelWrapper ch; - private final UserConnection user; + + private final ProxyServer bungee; + private ChannelWrapper ch; + private final UserConnection user; private final BungeeServerInfo target; - private State thisState = State.LOGIN_SUCCESS; + private State thisState = State.LOGIN_SUCCESS; @Getter - private ForgeServerHandler handshakeHandler; - private boolean obsolete; - + private ForgeServerHandler handshakeHandler; + private boolean obsolete; + private enum State { - - LOGIN_SUCCESS, ENCRYPT_RESPONSE, LOGIN, FINISHED; + + LOGIN_SUCCESS, + ENCRYPT_RESPONSE, + LOGIN, + FINISHED; } - + @Override public void exception(Throwable t) throws Exception { - if ( obsolete ) - { + if (obsolete) return; - } - - String message = "Exception Connecting:" + Util.exception( t ); - if ( user.getServer() == null ) - { - user.disconnect( message ); - } else - { - user.sendMessage( ChatColor.RED + message ); - } + + String message = "Exception Connecting:" + Util.exception(t); + if (user.getServer() == null) + user.disconnect(message); + else + user.sendMessage(ChatColor.RED + message); } - + @Override public void connected(ChannelWrapper channel) throws Exception { this.ch = channel; - - this.handshakeHandler = new ForgeServerHandler( user, ch, target ); + + this.handshakeHandler = new ForgeServerHandler(user, ch, target); Handshake originalHandshake = user.getPendingConnection().getHandshake(); - Handshake copiedHandshake = new Handshake( originalHandshake.getProtocolVersion(), originalHandshake.getHost(), originalHandshake.getPort(), 2 ); - - if ( BungeeCord.getInstance().config.isIpForward() ) + Handshake copiedHandshake = new Handshake(originalHandshake.getProtocolVersion(), originalHandshake.getHost(), originalHandshake.getPort(), 2); + + if (BungeeCord.getInstance().config.isIpForward()) { String newHost = copiedHandshake.getHost() + "\00" + user.getAddress().getHostString() + "\00" + user.getUUID(); - + LoginResult profile = user.getPendingConnection().getLoginProfile(); - if ( profile != null && profile.getProperties() != null && profile.getProperties().length > 0 ) - { - newHost += "\00" + BungeeCord.getInstance().gson.toJson( profile.getProperties() ); - } - copiedHandshake.setHost( newHost ); - } else if ( !user.getExtraDataInHandshake().isEmpty() ) - { + if (profile != null && profile.getProperties() != null && profile.getProperties().length > 0) + newHost += "\00" + BungeeCord.getInstance().gson.toJson(profile.getProperties()); + copiedHandshake.setHost(newHost); + } + else if (!user.getExtraDataInHandshake().isEmpty()) // Only restore the extra data if IP forwarding is off. // TODO: Add support for this data with IP forwarding. - copiedHandshake.setHost( copiedHandshake.getHost() + user.getExtraDataInHandshake() ); - } - - channel.write( copiedHandshake ); - - channel.setProtocol( Protocol.LOGIN ); - channel.write( user.getPendingConnection().getLoginRequest() ); + copiedHandshake.setHost(copiedHandshake.getHost() + user.getExtraDataInHandshake()); + + channel.write(copiedHandshake); + + channel.setProtocol(Protocol.LOGIN); + channel.write(user.getPendingConnection().getLoginRequest()); } - + @Override public void disconnected(ChannelWrapper channel) throws Exception { - user.getPendingConnects().remove( target ); + user.getPendingConnects().remove(target); } - + @Override public void handle(LoginSuccess loginSuccess) throws Exception { - Preconditions.checkState( thisState == State.LOGIN_SUCCESS, "Not expecting LOGIN_SUCCESS" ); - ch.setProtocol( Protocol.GAME ); + Preconditions.checkState(thisState == State.LOGIN_SUCCESS, "Not expecting LOGIN_SUCCESS"); + ch.setProtocol(Protocol.GAME); thisState = State.LOGIN; - + // Only reset the Forge client when: // 1) The user is switching servers (so has a current server) // 2) The handshake is complete @@ -137,219 +135,193 @@ public void handle(LoginSuccess loginSuccess) throws Exception // we need to switch to a modded connection. However, we always need to reset the // connection when we have a modded server regardless of where we go - doing it // here makes sense. - if ( user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() - && user.getServer().isForgeServer() ) - { + if (user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() && user.getServer().isForgeServer()) user.getForgeClientHandler().resetHandshake(); - } - + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(SetCompression setCompression) throws Exception { - ch.setCompressionThreshold( setCompression.getThreshold() ); + ch.setCompressionThreshold(setCompression.getThreshold()); } - + @Override public void handle(Login login) throws Exception { - Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" ); - - ServerConnection server = new ServerConnection( ch, target ); - ServerConnectedEvent event = new ServerConnectedEvent( user, server ); - bungee.getPluginManager().callEvent( event ); - - ch.write( BungeeCord.getInstance().registerChannels() ); + Preconditions.checkState(thisState == State.LOGIN, "Not expecting LOGIN"); + + ServerConnection server = new ServerConnection(ch, target); + ServerConnectedEvent event = new ServerConnectedEvent(user, server); + bungee.getPluginManager().callEvent(event); + + ch.write(BungeeCord.getInstance().registerChannels()); Queue packetQueue = target.getPacketQueue(); - synchronized ( packetQueue ) - { - while ( !packetQueue.isEmpty() ) - { - ch.write( packetQueue.poll() ); - } - } - - for ( PluginMessage message : user.getPendingConnection().getRegisterMessages() ) - { - ch.write( message ); - } - - if ( user.getSettings() != null ) + synchronized (packetQueue) { - ch.write( user.getSettings() ); + while (!packetQueue.isEmpty()) + ch.write(packetQueue.poll()); } - - if ( user.getForgeClientHandler().getClientModList() == null && !user.getForgeClientHandler().isHandshakeComplete() ) // Vanilla - { + + for (PluginMessage message : user.getPendingConnection().getRegisterMessages()) + ch.write(message); + + if (user.getSettings() != null) + ch.write(user.getSettings()); + + if (user.getForgeClientHandler().getClientModList() == null && !user.getForgeClientHandler().isHandshakeComplete()) user.getForgeClientHandler().setHandshakeComplete(); - } - - if ( user.getServer() == null ) + + if (user.getServer() == null) { // Once again, first connection - user.setClientEntityId( login.getEntityId() ); - user.setServerEntityId( login.getEntityId() ); - + user.setClientEntityId(login.getEntityId()); + 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.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), - (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); - - user.unsafe().sendPacket( modLogin ); - - if ( user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8 ) + Login modLogin = new Login(login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo()); + + user.unsafe().sendPacket(modLogin); + + if (user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8) { MinecraftOutput out = new MinecraftOutput(); - out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); - user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray(), handshakeHandler.isServerForge() ) ); - } else + out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket(ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")"); + user.unsafe().sendPacket(new PluginMessage("MC|Brand", out.toArray(), handshakeHandler.isServerForge())); + } + else { ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); - DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand ); - user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) ); + DefinedPacket.writeString(bungee.getName() + " (" + bungee.getVersion() + ")", brand); + user.unsafe().sendPacket(new PluginMessage("MC|Brand", brand.array().clone(), handshakeHandler.isServerForge())); brand.release(); } - } else + } + else { - user.getServer().setObsolete( true ); + user.getServer().setObsolete(true); user.getTabListHandler().onServerChange(); - + Scoreboard serverScoreboard = user.getServerSentScoreboard(); - for ( Objective objective : serverScoreboard.getObjectives() ) - { - user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), "integer", (byte) 1 ) ); // TODO: - } - for ( Team team : serverScoreboard.getTeams() ) - { - user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.Team( team.getName() ) ); - } + for (Objective objective : serverScoreboard.getObjectives()) + user.unsafe().sendPacket(new ScoreboardObjective(objective.getName(), objective.getValue(), "integer", (byte) 1)); // TODO: + for (Team team : serverScoreboard.getTeams()) + user.unsafe().sendPacket(new net.md_5.bungee.protocol.packet.Team(team.getName())); serverScoreboard.clear(); - - for ( UUID bossbar : user.getSentBossBars() ) - { + + for (UUID bossbar : user.getSentBossBars()) // Send remove bossbar packet - user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.BossBar( bossbar, 1 ) ); - } + user.unsafe().sendPacket(new net.md_5.bungee.protocol.packet.BossBar(bossbar, 1)); user.getSentBossBars().clear(); - + user.sendDimensionSwitch(); - - user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); - + + user.setServerEntityId(login.getEntityId()); + user.unsafe().sendPacket(new Respawn(login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType())); + // Remove from old servers - user.getServer().disconnect( "Quitting" ); + user.getServer().disconnect("Quitting"); } - + // TODO: Fix this? - if ( !user.isActive() ) + if (!user.isActive()) { - server.disconnect( "Quitting" ); + server.disconnect("Quitting"); // Silly server admins see stack trace and die - bungee.getLogger().warning( "No client connected for pending server!" ); + bungee.getLogger().warning("No client connected for pending server!"); return; } - + // Add to new server // TODO: Move this to the connected() method of DownstreamBridge - target.addPlayer( user ); - user.getPendingConnects().remove( target ); - user.setServerJoinQueue( null ); - user.setDimensionChange( false ); - - user.setServer( server ); - ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) ); - - bungee.getPluginManager().callEvent( new ServerSwitchEvent( user ) ); - + target.addPlayer(user); + user.getPendingConnects().remove(target); + user.setServerJoinQueue(null); + user.setDimensionChange(false); + + user.setServer(server); + ch.getHandle().pipeline().get(HandlerBoss.class).setHandler(new DownstreamBridge(bungee, user, server)); + + bungee.getPluginManager().callEvent(new ServerSwitchEvent(user)); + thisState = State.FINISHED; - + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(EncryptionRequest encryptionRequest) throws Exception { - throw new RuntimeException( "Server is online mode!" ); + throw new RuntimeException("Server is online mode!"); } - + @Override public void handle(Kick kick) throws Exception { - ServerInfo def = user.updateAndGetNextServer( target ); - ServerKickEvent event = new ServerKickEvent( user, target, ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTING ); - if ( event.getKickReason().toLowerCase().contains( "outdated" ) && def != null ) - { + ServerInfo def = user.updateAndGetNextServer(target); + ServerKickEvent event = new ServerKickEvent(user, target, ComponentSerializer.parse(kick.getMessage()), def, ServerKickEvent.State.CONNECTING); + if (event.getKickReason().toLowerCase().contains("outdated") && def != null) // Pre cancel the event if we are going to try another server - event.setCancelled( true ); - } - bungee.getPluginManager().callEvent( event ); - if ( event.isCancelled() && event.getCancelServer() != null ) + event.setCancelled(true); + bungee.getPluginManager().callEvent(event); + if (event.isCancelled() && event.getCancelServer() != null) { obsolete = true; - user.connect( event.getCancelServer() ); + user.connect(event.getCancelServer()); throw CancelSendSignal.INSTANCE; } - - String message = bungee.getTranslation( "connect_kick", target.getName(), event.getKickReason() ); - if ( user.isDimensionChange() ) - { - user.disconnect( message ); - } else - { - user.sendMessage( message ); - } - + + String message = bungee.getTranslation("connect_kick", target.getName(), event.getKickReason()); + if (user.isDimensionChange()) + user.disconnect(message); + else + user.sendMessage(message); + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(PluginMessage pluginMessage) throws Exception { - if ( pluginMessage.getTag().equals( ForgeConstants.FML_REGISTER ) ) + if (pluginMessage.getTag().equals(ForgeConstants.FML_REGISTER)) { - Set channels = ForgeUtils.readRegisteredChannels( pluginMessage ); + Set channels = ForgeUtils.readRegisteredChannels(pluginMessage); boolean isForgeServer = false; - for ( String channel : channels ) - { - if ( channel.equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) + for (String channel : channels) + if (channel.equals(ForgeConstants.FML_HANDSHAKE_TAG)) { // If we have a completed handshake and we have been asked to register a FML|HS // packet, let's send the reset packet now. Then, we can continue the message sending. // The handshake will not be complete if we reset this earlier. - if ( user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() ) - { + if (user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete()) user.getForgeClientHandler().resetHandshake(); - } - + isForgeServer = true; break; } - } - - if ( isForgeServer && !this.handshakeHandler.isServerForge() ) + + if (isForgeServer && !this.handshakeHandler.isServerForge()) { // We now set the server-side handshake handler for the client to this. handshakeHandler.setServerAsForgeServer(); - user.setForgeServerHandler( handshakeHandler ); + user.setForgeServerHandler(handshakeHandler); } } - - if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) || pluginMessage.getTag().equals( ForgeConstants.FORGE_REGISTER ) ) + + if (pluginMessage.getTag().equals(ForgeConstants.FML_HANDSHAKE_TAG) || pluginMessage.getTag().equals(ForgeConstants.FORGE_REGISTER)) { - this.handshakeHandler.handle( pluginMessage ); - + this.handshakeHandler.handle(pluginMessage); + // We send the message as part of the handler, so don't send it here. throw CancelSendSignal.INSTANCE; - } else - { + } + else // We have to forward these to the user, especially with Forge as stuff might break // This includes any REGISTER messages we intercepted earlier. - user.unsafe().sendPacket( pluginMessage ); - } + user.unsafe().sendPacket(pluginMessage); } - + @Override public String toString() { 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 5f97b61ce7..7d6d259e49 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 @@ -1,24 +1,27 @@ package net.md_5.bungee.connection; + +import java.io.DataInput; + import com.google.common.base.Objects; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -import java.io.DataInput; + import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.Unpooled; import lombok.RequiredArgsConstructor; import net.md_5.bungee.ServerConnection; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.event.ServerDisconnectEvent; -import net.md_5.bungee.api.event.TabCompleteResponseEvent; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.ServerDisconnectEvent; import net.md_5.bungee.api.event.ServerKickEvent; +import net.md_5.bungee.api.event.TabCompleteResponseEvent; import net.md_5.bungee.api.score.Objective; import net.md_5.bungee.api.score.Position; import net.md_5.bungee.api.score.Score; @@ -29,484 +32,447 @@ import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.PacketWrapper; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.BossBar; import net.md_5.bungee.protocol.packet.KeepAlive; +import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.PlayerListItem; +import net.md_5.bungee.protocol.packet.PluginMessage; +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.ScoreboardDisplay; -import net.md_5.bungee.protocol.packet.PluginMessage; -import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.tab.TabList; + @RequiredArgsConstructor public class DownstreamBridge extends PacketHandler { - - private final ProxyServer bungee; - private final UserConnection con; + + private final ProxyServer bungee; + private final UserConnection con; private final ServerConnection server; - + @Override public void exception(Throwable t) throws Exception { - if ( server.isObsolete() ) - { + if (server.isObsolete()) // do not perform any actions if the user has already moved return; - } - - ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() ); - if ( server.getInfo() != def ) - { - server.setObsolete( true ); - con.connectNow( def ); - con.sendMessage( bungee.getTranslation( "server_went_down" ) ); - } else + + ServerInfo def = bungee.getServerInfo(con.getPendingConnection().getListener().getFallbackServer()); + if (server.getInfo() != def) { - con.disconnect( Util.exception( t ) ); + server.setObsolete(true); + con.connectNow(def); + con.sendMessage(bungee.getTranslation("server_went_down")); } + else + con.disconnect(Util.exception(t)); } - + @Override public void disconnected(ChannelWrapper channel) throws Exception { // We lost connection to the server - server.getInfo().removePlayer( con ); - if ( bungee.getReconnectHandler() != null ) - { - bungee.getReconnectHandler().setServer( con ); - } - - if ( !server.isObsolete() ) - { - con.disconnect( bungee.getTranslation( "lost_connection" ) ); - } - - ServerDisconnectEvent serverDisconnectEvent = new ServerDisconnectEvent( con, server.getInfo() ); - bungee.getPluginManager().callEvent( serverDisconnectEvent ); + server.getInfo().removePlayer(con); + if (bungee.getReconnectHandler() != null) + bungee.getReconnectHandler().setServer(con); + + if (!server.isObsolete()) + con.disconnect(bungee.getTranslation("lost_connection")); + + ServerDisconnectEvent serverDisconnectEvent = new ServerDisconnectEvent(con, server.getInfo()); + bungee.getPluginManager().callEvent(serverDisconnectEvent); } - + @Override public boolean shouldHandle(PacketWrapper packet) throws Exception { return !server.isObsolete(); } - + @Override public void handle(PacketWrapper packet) throws Exception { - con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); - con.sendPacket( packet ); + con.getEntityRewrite().rewriteClientbound(packet.buf, con.getServerEntityId(), con.getClientEntityId()); + con.sendPacket(packet); } - + @Override public void handle(KeepAlive alive) throws Exception { - con.setSentPingId( alive.getRandomId() ); - con.setSentPingTime( System.currentTimeMillis() ); + con.setSentPingId(alive.getRandomId()); + con.setSentPingTime(System.currentTimeMillis()); } - + @Override public void handle(PlayerListItem playerList) throws Exception { - con.getTabListHandler().onUpdate( TabList.rewrite( playerList ) ); + con.getTabListHandler().onUpdate(TabList.rewrite(playerList)); throw CancelSendSignal.INSTANCE; // Always throw because of profile rewriting } - + @Override public void handle(ScoreboardObjective objective) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); - switch ( objective.getAction() ) + switch (objective.getAction()) { case 0: - serverScoreboard.addObjective( new Objective( objective.getName(), objective.getValue(), objective.getType() ) ); + serverScoreboard.addObjective(new Objective(objective.getName(), objective.getValue(), objective.getType())); break; case 1: - serverScoreboard.removeObjective( objective.getName() ); + serverScoreboard.removeObjective(objective.getName()); break; case 2: - Objective oldObjective = serverScoreboard.getObjective( objective.getName() ); - if ( oldObjective != null ) - { - oldObjective.setValue( objective.getValue() ); - } + Objective oldObjective = serverScoreboard.getObjective(objective.getName()); + if (oldObjective != null) + oldObjective.setValue(objective.getValue()); break; default: - throw new IllegalArgumentException( "Unknown objective action: " + objective.getAction() ); + throw new IllegalArgumentException("Unknown objective action: " + objective.getAction()); } } - + @Override public void handle(ScoreboardScore score) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); - switch ( score.getAction() ) + switch (score.getAction()) { case 0: - Score s = new Score( score.getItemName(), score.getScoreName(), score.getValue() ); - serverScoreboard.removeScore( score.getItemName() ); - serverScoreboard.addScore( s ); + Score s = new Score(score.getItemName(), score.getScoreName(), score.getValue()); + serverScoreboard.removeScore(score.getItemName()); + serverScoreboard.addScore(s); break; case 1: - serverScoreboard.removeScore( score.getItemName() ); + serverScoreboard.removeScore(score.getItemName()); break; default: - throw new IllegalArgumentException( "Unknown scoreboard action: " + score.getAction() ); + throw new IllegalArgumentException("Unknown scoreboard action: " + score.getAction()); } } - + @Override public void handle(ScoreboardDisplay displayScoreboard) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); - serverScoreboard.setName( displayScoreboard.getName() ); - serverScoreboard.setPosition( Position.values()[displayScoreboard.getPosition()] ); + serverScoreboard.setName(displayScoreboard.getName()); + serverScoreboard.setPosition(Position.values()[displayScoreboard.getPosition()]); } - + @Override public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception { Scoreboard serverScoreboard = con.getServerSentScoreboard(); // Remove team and move on - if ( team.getMode() == 1 ) + if (team.getMode() == 1) { - serverScoreboard.removeTeam( team.getName() ); + serverScoreboard.removeTeam(team.getName()); return; } - + // Create or get old team Team t; - if ( team.getMode() == 0 ) - { - t = new Team( team.getName() ); - serverScoreboard.addTeam( t ); - } else + if (team.getMode() == 0) { - t = serverScoreboard.getTeam( team.getName() ); + t = new Team(team.getName()); + serverScoreboard.addTeam(t); } - - if ( t != null ) + else + t = serverScoreboard.getTeam(team.getName()); + + if (t != null) { - if ( team.getMode() == 0 || team.getMode() == 2 ) + if (team.getMode() == 0 || team.getMode() == 2) { - t.setDisplayName( team.getDisplayName() ); - t.setPrefix( team.getPrefix() ); - t.setSuffix( team.getSuffix() ); - t.setFriendlyFire( team.getFriendlyFire() ); - t.setNameTagVisibility( team.getNameTagVisibility() ); - t.setCollisionRule( team.getCollisionRule() ); - t.setColor( team.getColor() ); - } - if ( team.getPlayers() != null ) - { - for ( String s : team.getPlayers() ) - { - if ( team.getMode() == 0 || team.getMode() == 3 ) - { - t.addPlayer( s ); - } else - { - t.removePlayer( s ); - } - } + t.setDisplayName(team.getDisplayName()); + t.setPrefix(team.getPrefix()); + t.setSuffix(team.getSuffix()); + t.setFriendlyFire(team.getFriendlyFire()); + t.setNameTagVisibility(team.getNameTagVisibility()); + t.setCollisionRule(team.getCollisionRule()); + t.setColor(team.getColor()); } + if (team.getPlayers() != null) + for (String s : team.getPlayers()) + if (team.getMode() == 0 || team.getMode() == 3) + t.addPlayer(s); + else + t.removePlayer(s); } } - + @Override public void handle(PluginMessage pluginMessage) throws Exception { DataInput in = pluginMessage.getStream(); - PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() ); - - if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) - { + PluginMessageEvent event = new PluginMessageEvent(con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone()); + + if (bungee.getPluginManager().callEvent(event).isCancelled()) throw CancelSendSignal.INSTANCE; - } - - if ( pluginMessage.getTag().equals( "MC|Brand" ) ) + + if (pluginMessage.getTag().equals("MC|Brand")) { - if ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) + if (con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8) { - ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); - String serverBrand = DefinedPacket.readString( brand ); + ByteBuf brand = Unpooled.wrappedBuffer(pluginMessage.getData()); + String serverBrand = DefinedPacket.readString(brand); brand.release(); brand = ByteBufAllocator.DEFAULT.heapBuffer(); - DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand ); - pluginMessage.setData( brand.array().clone() ); + DefinedPacket.writeString(bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand); + pluginMessage.setData(brand.array().clone()); brand.release(); - } else + } + else { - String serverBrand = new String( pluginMessage.getData(), "UTF-8" ); - pluginMessage.setData( ( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand ).getBytes( "UTF-8" ) ); + String serverBrand = new String(pluginMessage.getData(), "UTF-8"); + pluginMessage.setData((bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand).getBytes("UTF-8")); } // changes in the packet are ignored so we need to send it manually - con.unsafe().sendPacket( pluginMessage ); + con.unsafe().sendPacket(pluginMessage); throw CancelSendSignal.INSTANCE; } - - if ( pluginMessage.getTag().equals( "BungeeCord" ) ) + + if (pluginMessage.getTag().equals("BungeeCord")) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); String subChannel = in.readUTF(); - - if ( subChannel.equals( "ForwardToPlayer" ) ) + + if (subChannel.equals("ForwardToPlayer")) { - ProxiedPlayer target = bungee.getPlayer( in.readUTF() ); - if ( target != null ) + ProxiedPlayer target = bungee.getPlayer(in.readUTF()); + if (target != null) { // Read data from server String channel = in.readUTF(); short len = in.readShort(); - byte[] data = new byte[ len ]; - in.readFully( data ); - + byte[] data = new byte[len]; + in.readFully(data); + // Prepare new data to send - out.writeUTF( channel ); - out.writeShort( data.length ); - out.write( data ); + out.writeUTF(channel); + out.writeShort(data.length); + out.write(data); byte[] payload = out.toByteArray(); - - target.getServer().sendData( "BungeeCord", payload ); + + target.getServer().sendData("BungeeCord", payload); } - + // Null out stream, important as we don't want to send to ourselves out = null; } - if ( subChannel.equals( "Forward" ) ) + if (subChannel.equals("Forward")) { // Read data from server String target = in.readUTF(); String channel = in.readUTF(); short len = in.readShort(); - byte[] data = new byte[ len ]; - in.readFully( data ); - + byte[] data = new byte[len]; + in.readFully(data); + // Prepare new data to send - out.writeUTF( channel ); - out.writeShort( data.length ); - out.write( data ); + out.writeUTF(channel); + out.writeShort(data.length); + out.write(data); byte[] payload = out.toByteArray(); - + // Null out stream, important as we don't want to send to ourselves out = null; - - if ( target.equals( "ALL" ) ) + + if (target.equals("ALL")) { - for ( ServerInfo server : bungee.getServers().values() ) - { - if ( server != con.getServer().getInfo() ) - { - server.sendData( "BungeeCord", payload ); - } - } - } else if ( target.equals( "ONLINE" ) ) + for (ServerInfo server : bungee.getServers().values()) + if (server != con.getServer().getInfo()) + server.sendData("BungeeCord", payload); + } + else if (target.equals("ONLINE")) { - for ( ServerInfo server : bungee.getServers().values() ) - { - if ( server != con.getServer().getInfo() ) - { - server.sendData( "BungeeCord", payload, false ); - } - } - } else + for (ServerInfo server : bungee.getServers().values()) + if (server != con.getServer().getInfo()) + server.sendData("BungeeCord", payload, false); + } + else { - ServerInfo server = bungee.getServerInfo( target ); - if ( server != null ) - { - server.sendData( "BungeeCord", payload ); - } + ServerInfo server = bungee.getServerInfo(target); + if (server != null) + server.sendData("BungeeCord", payload); } } - if ( subChannel.equals( "Connect" ) ) + if (subChannel.equals("Connect")) { - ServerInfo server = bungee.getServerInfo( in.readUTF() ); - if ( server != null ) - { - con.connect( server ); - } + ServerInfo server = bungee.getServerInfo(in.readUTF()); + if (server != null) + con.connect(server); } - if ( subChannel.equals( "ConnectOther" ) ) + if (subChannel.equals("ConnectOther")) { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) + ProxiedPlayer player = bungee.getPlayer(in.readUTF()); + if (player != null) { - ServerInfo server = bungee.getServerInfo( in.readUTF() ); - if ( server != null ) - { - player.connect( server ); - } + ServerInfo server = bungee.getServerInfo(in.readUTF()); + if (server != null) + player.connect(server); } } - if ( subChannel.equals( "IP" ) ) + if (subChannel.equals("IP")) { - out.writeUTF( "IP" ); - out.writeUTF( con.getAddress().getHostString() ); - out.writeInt( con.getAddress().getPort() ); + out.writeUTF("IP"); + out.writeUTF(con.getAddress().getHostString()); + out.writeInt(con.getAddress().getPort()); } - if ( subChannel.equals( "PlayerCount" ) ) + if (subChannel.equals("PlayerCount")) { String target = in.readUTF(); - out.writeUTF( "PlayerCount" ); - if ( target.equals( "ALL" ) ) + out.writeUTF("PlayerCount"); + if (target.equals("ALL")) { - out.writeUTF( "ALL" ); - out.writeInt( bungee.getOnlineCount() ); - } else + out.writeUTF("ALL"); + out.writeInt(bungee.getOnlineCount()); + } + else { - ServerInfo server = bungee.getServerInfo( target ); - if ( server != null ) + ServerInfo server = bungee.getServerInfo(target); + if (server != null) { - out.writeUTF( server.getName() ); - out.writeInt( server.getPlayers().size() ); + out.writeUTF(server.getName()); + out.writeInt(server.getPlayers().size()); } } } - if ( subChannel.equals( "PlayerList" ) ) + if (subChannel.equals("PlayerList")) { String target = in.readUTF(); - out.writeUTF( "PlayerList" ); - if ( target.equals( "ALL" ) ) + out.writeUTF("PlayerList"); + if (target.equals("ALL")) { - out.writeUTF( "ALL" ); - out.writeUTF( Util.csv( bungee.getPlayers() ) ); - } else + out.writeUTF("ALL"); + out.writeUTF(Util.csv(bungee.getPlayers())); + } + else { - ServerInfo server = bungee.getServerInfo( target ); - if ( server != null ) + ServerInfo server = bungee.getServerInfo(target); + if (server != null) { - out.writeUTF( server.getName() ); - out.writeUTF( Util.csv( server.getPlayers() ) ); + out.writeUTF(server.getName()); + out.writeUTF(Util.csv(server.getPlayers())); } } } - if ( subChannel.equals( "GetServers" ) ) + if (subChannel.equals("GetServers")) { - out.writeUTF( "GetServers" ); - out.writeUTF( Util.csv( bungee.getServers().keySet() ) ); + out.writeUTF("GetServers"); + out.writeUTF(Util.csv(bungee.getServers().keySet())); } - if ( subChannel.equals( "Message" ) ) + if (subChannel.equals("Message")) { - ProxiedPlayer target = bungee.getPlayer( in.readUTF() ); - if ( target != null ) - { - target.sendMessage( in.readUTF() ); - } + ProxiedPlayer target = bungee.getPlayer(in.readUTF()); + if (target != null) + target.sendMessage(in.readUTF()); } - if ( subChannel.equals( "GetServer" ) ) + if (subChannel.equals("GetServer")) { - out.writeUTF( "GetServer" ); - out.writeUTF( server.getInfo().getName() ); + out.writeUTF("GetServer"); + out.writeUTF(server.getInfo().getName()); } - if ( subChannel.equals( "UUID" ) ) + if (subChannel.equals("UUID")) { - out.writeUTF( "UUID" ); - out.writeUTF( con.getUUID() ); + out.writeUTF("UUID"); + out.writeUTF(con.getUUID()); } - if ( subChannel.equals( "UUIDOther" ) ) + if (subChannel.equals("UUIDOther")) { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) + ProxiedPlayer player = bungee.getPlayer(in.readUTF()); + if (player != null) { - out.writeUTF( "UUIDOther" ); - out.writeUTF( player.getName() ); - out.writeUTF( player.getUUID() ); + out.writeUTF("UUIDOther"); + out.writeUTF(player.getName()); + out.writeUTF(player.getUUID()); } } - if ( subChannel.equals( "ServerIP" ) ) + if (subChannel.equals("ServerIP")) { - ServerInfo info = bungee.getServerInfo( in.readUTF() ); - if ( info != null ) + ServerInfo info = bungee.getServerInfo(in.readUTF()); + if (info != null) { - out.writeUTF( "ServerIP" ); - out.writeUTF( info.getName() ); - out.writeUTF( info.getAddress().getAddress().getHostAddress() ); - out.writeShort( info.getAddress().getPort() ); + out.writeUTF("ServerIP"); + out.writeUTF(info.getName()); + out.writeUTF(info.getAddress().getAddress().getHostAddress()); + out.writeShort(info.getAddress().getPort()); } } - if ( subChannel.equals( "KickPlayer" ) ) + if (subChannel.equals("KickPlayer")) { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) + ProxiedPlayer player = bungee.getPlayer(in.readUTF()); + if (player != null) { String kickReason = in.readUTF(); - player.disconnect( new TextComponent( kickReason ) ); + player.disconnect(new TextComponent(kickReason)); } } - + // Check we haven't set out to null, and we have written data, if so reply back back along the BungeeCord channel - if ( out != null ) + if (out != null) { byte[] b = out.toByteArray(); - if ( b.length != 0 ) - { - con.getServer().sendData( "BungeeCord", b ); - } + if (b.length != 0) + con.getServer().sendData("BungeeCord", b); } - + throw CancelSendSignal.INSTANCE; } } - + @Override public void handle(Kick kick) throws Exception { - ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() ); - if ( Objects.equal( server.getInfo(), def ) ) - { + ServerInfo def = bungee.getServerInfo(con.getPendingConnection().getListener().getFallbackServer()); + if (Objects.equal(server.getInfo(), def)) def = null; - } - ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, server.getInfo(), ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTED ) ); - if ( event.isCancelled() && event.getCancelServer() != null ) - { - con.connectNow( event.getCancelServer() ); - } else - { - con.disconnect0( event.getKickReasonComponent() ); // TODO: Prefix our own stuff. - } - server.setObsolete( true ); + ServerKickEvent event = bungee.getPluginManager().callEvent(new ServerKickEvent(con, server.getInfo(), ComponentSerializer.parse(kick.getMessage()), def, ServerKickEvent.State.CONNECTED)); + if (event.isCancelled() && event.getCancelServer() != null) + con.connectNow(event.getCancelServer()); + else + con.disconnect0(event.getKickReasonComponent()); // TODO: Prefix our own stuff. + server.setObsolete(true); throw CancelSendSignal.INSTANCE; } - + @Override public void handle(SetCompression setCompression) throws Exception { - server.getCh().setCompressionThreshold( setCompression.getThreshold() ); + server.getCh().setCompressionThreshold(setCompression.getThreshold()); } - + @Override public void handle(TabCompleteResponse tabCompleteResponse) throws Exception { - TabCompleteResponseEvent tabCompleteResponseEvent = new TabCompleteResponseEvent( con.getServer(), con, tabCompleteResponse.getCommands() ); - - if ( !bungee.getPluginManager().callEvent( tabCompleteResponseEvent ).isCancelled() ) - { - con.unsafe().sendPacket( tabCompleteResponse ); - } - + TabCompleteResponseEvent tabCompleteResponseEvent = new TabCompleteResponseEvent(con.getServer(), con, tabCompleteResponse.getCommands()); + + if (!bungee.getPluginManager().callEvent(tabCompleteResponseEvent).isCancelled()) + con.unsafe().sendPacket(tabCompleteResponse); + throw CancelSendSignal.INSTANCE; } - + @Override public void handle(BossBar bossBar) { - switch ( bossBar.getAction() ) + switch (bossBar.getAction()) { // Handle add bossbar case 0: - con.getSentBossBars().add( bossBar.getUuid() ); + con.getSentBossBars().add(bossBar.getUuid()); break; // Handle remove bossbar case 1: - con.getSentBossBars().remove( bossBar.getUuid() ); + con.getSentBossBars().remove(bossBar.getUuid()); break; } } - + @Override public String toString() { From bb0bb7199beee0d0ad692187d32436413b86df43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lei=C3=9F?= Date: Thu, 3 Mar 2016 20:47:30 +0100 Subject: [PATCH 20/47] Fixed some issues happened while merging. --- .../java/net/md_5/bungee/protocol/Protocol.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 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 97eacd9fd3..8bef08d62f 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 @@ -59,7 +59,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x01, 0x23, Login.class ); TO_CLIENT.registerPacket( 0x02, 0x0F, Chat.class ); TO_CLIENT.registerPacket( 0x07, 0x33, Respawn.class ); - TO_CLIENT.registerPacket( 0x0C, 0x0C, BossBar.class, true ); + TO_CLIENT.registerPacket( 0x0C, 0x0C, BossBar.class, true, false ); TO_CLIENT.registerPacket( 0x38, 0x2D, PlayerListItem.class ); // PlayerInfo TO_CLIENT.registerPacket( 0x3A, 0x0E, TabCompleteResponse.class ); TO_CLIENT.registerPacket( 0x3B, 0x3F, ScoreboardObjective.class ); @@ -69,7 +69,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x3F, 0x18, PluginMessage.class ); TO_CLIENT.registerPacket( 0x40, 0x1A, Kick.class ); TO_CLIENT.registerPacket( 0x45, 0x45, Title.class ); - TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class, true ); + TO_CLIENT.registerPacket( 0x46, 0x46, SetCompression.class, false , true ); TO_CLIENT.registerPacket( 0x47, 0x48, PlayerListHeaderFooter.class ); TO_SERVER.registerPacket( 0x00, 0x0B, KeepAlive.class ); @@ -175,11 +175,11 @@ protected final void registerPacket(int id, Class packe protected final void registerPacket(int id, int newId, Class packetClass) { - registerPacket( id, newId, packetClass, false ); + registerPacket( id, newId, packetClass, false , false); } - protected final void registerPacket(int id, int newId, Class packetClass, boolean newOnly) + protected final void registerPacket(int id, int newId, Class packetClass, boolean newOnly, boolean oldOnly) { try { @@ -195,16 +195,17 @@ protected final void registerPacket(int id, int newId, Class Date: Thu, 3 Mar 2016 21:10:45 +0100 Subject: [PATCH 21/47] Fixed packets being rewritten for wrong protocols --- README.md | 2 +- .../net/md_5/bungee/protocol/Protocol.java | 12 +++++----- .../bungee/module/TravisCiModuleSource.java | 23 +++++++++++-------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 8e758a2c9f..92fd36873a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ BungeeCord for 1.7/1.8/1.9 ========== -[![Build Status](https://travis-ci.org/hexagonmc/BungeeCord.svg?branch=master)](https://travis-ci.org/hexagonmc/BungeeCord) +[![Build Status](https://travis-ci.org/HexagonMC/BungeeCord.svg?branch=master)](https://travis-ci.org/HexagonMC/BungeeCord) This is a fork of md_5's BungeeCord https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ 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 8bef08d62f..0778de47f5 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 @@ -191,20 +191,20 @@ protected final void registerPacket(int id, int newId, Class Date: Thu, 3 Mar 2016 22:02:03 +0100 Subject: [PATCH 22/47] Added update check --- bootstrap/pom.xml | 2 +- .../net/md_5/bungee/BungeeCordLauncher.java | 100 +++++++++++++----- 2 files changed, 72 insertions(+), 30 deletions(-) diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index 0c023491bb..5e13b31706 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -59,7 +59,7 @@ net.md_5.bungee.Bootstrap ${describe} - ${maven.build.timestamp} + ${build.number} diff --git a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java index 3c1bbe9360..17e81932bd 100644 --- a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java +++ b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java @@ -1,69 +1,111 @@ package net.md_5.bungee; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; import java.security.Security; -import java.text.SimpleDateFormat; import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; import java.util.concurrent.TimeUnit; + +import com.google.gson.JsonIOException; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; + import joptsimple.OptionParser; import joptsimple.OptionSet; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.command.ConsoleCommandSender; + public class BungeeCordLauncher { - + public static void main(String[] args) throws Exception { Security.setProperty( "networkaddress.cache.ttl", "30" ); Security.setProperty( "networkaddress.cache.negative.ttl", "10" ); - + OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); - parser.acceptsAll( Arrays.asList( "v", "version" ) ); + parser.acceptsAll( Arrays.asList( "v", "version") ); parser.acceptsAll( Arrays.asList( "noconsole" ) ); - + OptionSet options = parser.parse( args ); - - if ( options.has( "version" ) ) + + if ( options.has("version") ) { - System.out.println( Bootstrap.class.getPackage().getImplementationVersion() ); + System.out.println(Bootstrap.class.getPackage().getImplementationVersion()); return; } - - if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null ) + + if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null) { - Date buildDate = new SimpleDateFormat( "yyyyMMdd" ).parse( BungeeCord.class.getPackage().getSpecificationVersion() ); - - Calendar deadline = Calendar.getInstance(); - deadline.add( Calendar.WEEK_OF_YEAR, -4 ); - if ( buildDate.before( deadline.getTime() ) ) + String version = BungeeCord.class.getPackage().getSpecificationVersion(); + int currentVersion = version.equalsIgnoreCase("unknown") ? 0 : Integer.parseInt( version ); + + try + { + URL api = new URL( "https://api.github.com/repos/HexagonMC/BungeeCord/releases/latest" ); + URLConnection con = api.openConnection(); + // 15 second timeout at various stages + con.setConnectTimeout( 15000 ); + con.setReadTimeout( 15000 ); + + String tagName = null; + + try + { + JsonObject json = new JsonParser().parse( new InputStreamReader( con.getInputStream() ) ).getAsJsonObject(); + tagName = json.get( "tag_name" ).getAsString(); + + int latestVersion = Integer.parseInt( tagName.substring( 1, tagName.length() ) ); + + if ( latestVersion > currentVersion ) + { + System.err.println("*** Warning, this build is outdated ***"); + System.err.println("*** Please download a new build from https://github.com/HexagonMC/BungeeCord/releases ***"); + System.err.println("*** You will get NO support regarding this build ***"); + System.err.println("*** Server will start in 10 seconds ***"); + Thread.sleep(TimeUnit.SECONDS.toMillis(10)); + } + } + catch ( JsonIOException e ) + { + throw new IOException(e); + } + catch ( JsonSyntaxException e ) + { + throw new IOException( e ); + } + catch( NumberFormatException e ) + { + throw new IOException( e ); + } + } + catch ( IOException e ) { - System.err.println( "*** Warning, this build is outdated ***" ); - System.err.println( "*** Please download a new build from http://ci.md-5.net/job/BungeeCord ***" ); - System.err.println( "*** You will get NO support regarding this build ***" ); - System.err.println( "*** Server will start in 10 seconds ***" ); - Thread.sleep( TimeUnit.SECONDS.toMillis( 10 ) ); + System.err.println( "*** Can not test if up to date ***" ); + System.err.println( "*** Using current version without warranty ***" ); + System.err.println( "*** Server will start in 2 seconds ***" ); + Thread.sleep( TimeUnit.SECONDS.toMillis( 2 ) ); } } - + BungeeCord bungee = new BungeeCord(); ProxyServer.setInstance( bungee ); bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); bungee.start(); - + if ( !options.has( "noconsole" ) ) { String line; while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null ) - { - if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) ) - { + if ( !bungee.getPluginManager().dispatchCommand(ConsoleCommandSender.getInstance(), line ) ) bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); - } - } } } } From 426e77996f4649d1fdce44541e30a7ae47975721 Mon Sep 17 00:00:00 2001 From: Zartec Date: Fri, 4 Mar 2016 19:16:19 +0100 Subject: [PATCH 23/47] Added seperate message if using a self compiled version. --- .../net/md_5/bungee/BungeeCordLauncher.java | 96 +++++++++++-------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java index 17e81932bd..109a61c5b9 100644 --- a/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java +++ b/bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java @@ -23,7 +23,6 @@ public class BungeeCordLauncher { - public static void main(String[] args) throws Exception { Security.setProperty( "networkaddress.cache.ttl", "30" ); @@ -33,79 +32,94 @@ public static void main(String[] args) throws Exception parser.allowsUnrecognizedOptions(); parser.acceptsAll( Arrays.asList( "v", "version") ); parser.acceptsAll( Arrays.asList( "noconsole" ) ); - + OptionSet options = parser.parse( args ); - + if ( options.has("version") ) { System.out.println(Bootstrap.class.getPackage().getImplementationVersion()); return; } - + if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null) { String version = BungeeCord.class.getPackage().getSpecificationVersion(); - int currentVersion = version.equalsIgnoreCase("unknown") ? 0 : Integer.parseInt( version ); - try + if ( version.equalsIgnoreCase("unknown") ) { - URL api = new URL( "https://api.github.com/repos/HexagonMC/BungeeCord/releases/latest" ); - URLConnection con = api.openConnection(); - // 15 second timeout at various stages - con.setConnectTimeout( 15000 ); - con.setReadTimeout( 15000 ); - - String tagName = null; + System.err.println( "*** You are using a self compiled version ***" ); + System.err.println( "*** Please make sure your server is up to date ***" ); + System.err.println( "*** Using current version without warranty ***" ); + System.err.println( "*** Server will start in 2 seconds ***" ); + Thread.sleep( TimeUnit.SECONDS.toMillis( 2 ) ); + } else + { + int currentVersion = Integer.parseInt( version ); try { - JsonObject json = new JsonParser().parse( new InputStreamReader( con.getInputStream() ) ).getAsJsonObject(); - tagName = json.get( "tag_name" ).getAsString(); + URL api = new URL( "https://api.github.com/repos/HexagonMC/BungeeCord/releases/latest" ); + URLConnection con = api.openConnection(); + // 15 second timeout at various stages + con.setConnectTimeout( 15000 ); + con.setReadTimeout( 15000 ); - int latestVersion = Integer.parseInt( tagName.substring( 1, tagName.length() ) ); + String tagName = null; - if ( latestVersion > currentVersion ) + try { - System.err.println("*** Warning, this build is outdated ***"); - System.err.println("*** Please download a new build from https://github.com/HexagonMC/BungeeCord/releases ***"); - System.err.println("*** You will get NO support regarding this build ***"); - System.err.println("*** Server will start in 10 seconds ***"); - Thread.sleep(TimeUnit.SECONDS.toMillis(10)); + JsonObject json = new JsonParser().parse( new InputStreamReader( con.getInputStream() ) ).getAsJsonObject(); + tagName = json.get( "tag_name" ).getAsString(); + + int latestVersion = Integer.parseInt( tagName.substring( 1, tagName.length() ) ); + + if ( latestVersion > currentVersion ) + { + System.err.println("*** Warning, this build is outdated ***"); + System.err.println("*** Please download a new build from https://github.com/HexagonMC/BungeeCord/releases ***"); + System.err.println("*** You will get NO support regarding this build ***"); + System.err.println("*** Server will start in 10 seconds ***"); + Thread.sleep(TimeUnit.SECONDS.toMillis(10)); + } + } + catch ( JsonIOException e ) + { + throw new IOException(e); + } + catch ( JsonSyntaxException e ) + { + throw new IOException( e ); + } + catch( NumberFormatException e ) + { + throw new IOException( e ); } } - catch ( JsonIOException e ) - { - throw new IOException(e); - } - catch ( JsonSyntaxException e ) - { - throw new IOException( e ); - } - catch( NumberFormatException e ) + catch ( IOException e ) { - throw new IOException( e ); + System.err.println( "*** Can not test if up to date ***" ); + System.err.println( "*** Using current version without warranty ***" ); + System.err.println( "*** Server will start in 2 seconds ***" ); + Thread.sleep( TimeUnit.SECONDS.toMillis( 2 ) ); } } - catch ( IOException e ) - { - System.err.println( "*** Can not test if up to date ***" ); - System.err.println( "*** Using current version without warranty ***" ); - System.err.println( "*** Server will start in 2 seconds ***" ); - Thread.sleep( TimeUnit.SECONDS.toMillis( 2 ) ); - } } - + BungeeCord bungee = new BungeeCord(); ProxyServer.setInstance( bungee ); bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); bungee.start(); - + if ( !options.has( "noconsole" ) ) { String line; while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null ) + { if ( !bungee.getPluginManager().dispatchCommand(ConsoleCommandSender.getInstance(), line ) ) + { bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); + } + } } } } From 4062518e2bfce78e22c88fd1d7a201a39f5ef642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lei=C3=9F?= Date: Sat, 5 Mar 2016 02:20:07 +0100 Subject: [PATCH 24/47] Try reconnecting by default. --- proxy/src/main/java/net/md_5/bungee/UserConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 330bbb5211..e6ddc23970 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -213,7 +213,7 @@ public void connect(ServerInfo target) @Override public void connect(ServerInfo target, Callback callback) { - connect( target, callback, false ); + connect( target, callback, true ); } void sendDimensionSwitch() From 5c2735c1082c2edb5e44140f850e29ca072714ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lei=C3=9F?= Date: Sat, 5 Mar 2016 11:30:28 +0100 Subject: [PATCH 25/47] Only skip playername-check if user is on 1.8+. --- proxy/src/main/java/net/md_5/bungee/UserConnection.java | 4 ++++ 1 file changed, 4 insertions(+) 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 4d95d22854..6d5bcb7409 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -200,6 +200,10 @@ public boolean isActive() public void setDisplayName(String name) { Preconditions.checkNotNull( name, "displayName" ); + if( pendingConnection.getVersion() <= ProtocolConstants.MINECRAFT_1_7_6 ) + { + Preconditions.checkArgument( name.length() <= 16, "Display name cannot be longer than 16 characters" ); + } displayName = name; } From 41751ffceb69dbfe6ab2d07d9ed28eedef689fce Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 5 Mar 2016 13:58:43 +0100 Subject: [PATCH 26/47] Do not reconnect by default as this may have some unwanted sideaffects. --- proxy/src/main/java/net/md_5/bungee/UserConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6d5bcb7409..6c07dfb9f7 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -216,7 +216,7 @@ public void connect(ServerInfo target) @Override public void connect(ServerInfo target, Callback callback) { - connect( target, callback, true ); + connect( target, callback, false ); } void sendDimensionSwitch() From e29ae2ce8be29ce845a9d7a5ddd128fb3acd02d9 Mon Sep 17 00:00:00 2001 From: Zartec Date: Sun, 6 Mar 2016 22:13:51 +0100 Subject: [PATCH 27/47] Changed name to simply enable support for BungeeAdminTools --- proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 2 +- proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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 1cda0af497..795e9d6bd6 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -453,7 +453,7 @@ public void broadcast(DefinedPacket packet) @Override public String getName() { - return "BungeeCord"; + return "BungeeCord-1.[7-9]"; } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java b/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java index b07987915f..5bb1dee6cd 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandBungee.java @@ -16,6 +16,7 @@ public CommandBungee() @Override public void execute(CommandSender sender, String[] args) { - sender.sendMessage( ChatColor.BLUE + "This server is running BungeeCord version " + ProxyServer.getInstance().getVersion() + " by md_5" ); + sender.sendMessage( ChatColor.BLUE + "This server is running " + ProxyServer.getInstance().getName() + " version " + ProxyServer.getInstance().getVersion() + " by md_5" ); + sender.sendMessage( ChatColor.BLUE + "Protocol support for 1.7.x by Zartec, ghac and I9hdkill" ); } } From f2ed38bccbfdc77e8bfc8fe53e0e651bc1ecc17c Mon Sep 17 00:00:00 2001 From: Zartec Date: Fri, 8 Apr 2016 22:13:18 +0200 Subject: [PATCH 28/47] Update .travis.yml [ci skip] --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 46ef5a286e..178f2fef82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,11 @@ branches: - /^v[0-9]*/ notifications: email: false + irc: + channels: + - "irc.spi.gt#hexagonmc" + use_notice: true + skip_join: true install: - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dbuild.number=$TRAVIS_BUILD_NUMBER -B -V after_success: From 989dd8db52b667ff62e32346a5c30d4d8ba9dcde Mon Sep 17 00:00:00 2001 From: ghac Date: Fri, 29 Apr 2016 17:10:32 +0200 Subject: [PATCH 29/47] Fix missing merge. --- proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java b/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java index ac2609539b..e9530af965 100644 --- a/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java +++ b/proxy/src/main/java/net/md_5/bungee/PlayerInfoSerializer.java @@ -14,7 +14,6 @@ public class PlayerInfoSerializer implements JsonSerializer, JsonDeserializer { -<<<<<<< HEAD private final int protocol; public PlayerInfoSerializer(int protocol) @@ -22,9 +21,6 @@ public PlayerInfoSerializer(int protocol) this.protocol = protocol; } -======= - ->>>>>>> 80b3135a93f0e23489cc19086e31feb12ff51798 @Override public ServerPing.PlayerInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { From 28bb88fc98a694b34aa16ca4372362235fc7cf48 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 29 Apr 2016 19:18:02 +0200 Subject: [PATCH 30/47] Fix some problems with serverlists. --- query/src/main/java/net/md_5/bungee/query/QueryHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java index 0be915cbc4..5f02f07da6 100644 --- a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java +++ b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java @@ -108,7 +108,7 @@ protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throw data.put( "gametype", "SMP" ); // Start Extra Info data.put( "game_id", "MINECRAFT" ); - data.put( "version", bungee.getGameVersion() ); + data.put( "version", "BungeeCord " + bungee.getGameVersion() ); data.put( "plugins", "" ); // End Extra Info data.put( "map", "BungeeCord_Proxy" ); From bf74e847dfa5f49ebaa1158f4e312a40e84206a4 Mon Sep 17 00:00:00 2001 From: ghac Date: Sat, 30 Apr 2016 01:44:57 +0200 Subject: [PATCH 31/47] Make servername configurable. Helps with some server lists. --- api/src/main/java/net/md_5/bungee/api/ProxyConfig.java | 5 +++++ proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 2 +- .../src/main/java/net/md_5/bungee/conf/Configuration.java | 8 ++++++++ .../src/main/java/net/md_5/bungee/query/QueryHandler.java | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java index edd82c1e0e..2f8bd6a407 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java @@ -79,4 +79,9 @@ public interface ProxyConfig * The favicon used for the server ping list. */ Favicon getFaviconObject(); + + /** + * The server name for the server ping list. + */ + String getCustomServerName(); } 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 9291a4efb3..1bb657beca 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -467,7 +467,7 @@ public void broadcast(DefinedPacket packet) @Override public String getName() { - return "BungeeCord-1.[7-9]"; + return config.getCustomServerName(); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 25d87d97d6..001bd8212b 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -57,6 +57,7 @@ public class Configuration implements ProxyConfig private boolean ipForward; private Favicon favicon; private int compressionThreshold = 256; + private String customServerName = "HexaCord"; public void load() { @@ -84,6 +85,7 @@ public void load() throttle = adapter.getInt( "connection_throttle", throttle ); ipForward = adapter.getBoolean( "ip_forward", ipForward ); compressionThreshold = adapter.getInt( "network_compression_threshold", compressionThreshold ); + customServerName = adapter.getString( "custom_server_name", "HexaCord"); disabledCommands = new CaseInsensitiveSet( (Collection) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) ); @@ -142,4 +144,10 @@ public Favicon getFaviconObject() { return favicon; } + + @Override + public String getCustomServerName() + { + return customServerName; + } } diff --git a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java index 0be915cbc4..ce8c9c89b8 100644 --- a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java +++ b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java @@ -108,7 +108,7 @@ protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throw data.put( "gametype", "SMP" ); // Start Extra Info data.put( "game_id", "MINECRAFT" ); - data.put( "version", bungee.getGameVersion() ); + data.put( "version", bungee.getConfig().getCustomServerName() + " " + bungee.getGameVersion() ); data.put( "plugins", "" ); // End Extra Info data.put( "map", "BungeeCord_Proxy" ); From cea172fdddf8660195e0f36b3a504849b6417779 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 11 May 2016 22:43:19 +0200 Subject: [PATCH 32/47] Force update. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 178f2fef82..7f19acceeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,3 +37,4 @@ deploy: cache: directories: - $HOME/.m2 + From 48710b14fad1590a1f4cc900582da094495f8ea4 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 9 Jun 2016 13:24:14 +0200 Subject: [PATCH 33/47] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92fd36873a..385baad945 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -BungeeCord for 1.7/1.8/1.9 +BungeeCord for 1.7/1.8/1.9/1.10 ========== [![Build Status](https://travis-ci.org/HexagonMC/BungeeCord.svg?branch=master)](https://travis-ci.org/HexagonMC/BungeeCord) From 76e468aeee033b50a9fef1f1e55d2536a8790514 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 11 Jun 2016 17:27:10 +0200 Subject: [PATCH 34/47] Fix formatting. [ci skip] --- .../main/java/net/md_5/bungee/conf/Configuration.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 001bd8212b..9210ca974c 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -145,9 +145,9 @@ public Favicon getFaviconObject() return favicon; } - @Override - public String getCustomServerName() - { - return customServerName; - } + @Override + public String getCustomServerName() + { + return customServerName; + } } From f5be0e0fbdfb2803e653886bb6dd64072e44ba7f Mon Sep 17 00:00:00 2001 From: ghac Date: Tue, 23 Aug 2016 15:08:37 +0200 Subject: [PATCH 35/47] Add config option whether the server should handle packets before the player has connected to a server --- api/src/main/java/net/md_5/bungee/api/ProxyConfig.java | 5 +++++ .../main/java/net/md_5/bungee/conf/Configuration.java | 9 ++++++++- .../java/net/md_5/bungee/connection/UpstreamBridge.java | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java index 2f8bd6a407..d44a356a00 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java @@ -84,4 +84,9 @@ public interface ProxyConfig * The server name for the server ping list. */ String getCustomServerName(); + + /** + * Whether the server should handle packets before the player has connected to a server + */ + boolean getAlwaysHandlePackets(); } diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 9210ca974c..5f20325fa5 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -58,6 +58,7 @@ public class Configuration implements ProxyConfig private Favicon favicon; private int compressionThreshold = 256; private String customServerName = "HexaCord"; + private boolean alwaysHandlePackets = false; public void load() { @@ -85,7 +86,8 @@ public void load() throttle = adapter.getInt( "connection_throttle", throttle ); ipForward = adapter.getBoolean( "ip_forward", ipForward ); compressionThreshold = adapter.getInt( "network_compression_threshold", compressionThreshold ); - customServerName = adapter.getString( "custom_server_name", "HexaCord"); + customServerName = adapter.getString( "custom_server_name", "HexaCord" ); + alwaysHandlePackets = adapter.getBoolean( "always_handle_packets", false ); disabledCommands = new CaseInsensitiveSet( (Collection) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) ); @@ -150,4 +152,9 @@ public String getCustomServerName() { return customServerName; } + + @Override + public boolean getAlwaysHandlePackets() { + return alwaysHandlePackets; + } } 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 ecb0485911..1ca3dd53d8 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 @@ -86,7 +86,7 @@ public void disconnected(ChannelWrapper channel) throws Exception @Override public boolean shouldHandle(PacketWrapper packet) throws Exception { - return con.getServer() != null || packet.packet instanceof PluginMessage; + return bungee.getConfig().getAlwaysHandlePackets() || con.getServer() != null || packet.packet instanceof PluginMessage; } @Override From 20c12f2fa8a0a3370308053c659d07555a3cff9b Mon Sep 17 00:00:00 2001 From: ghac Date: Thu, 25 Aug 2016 14:21:49 +0200 Subject: [PATCH 36/47] Some fixes for Forge's DimensionRegisterPacket (thanks to @bloodmc). --- .../java/net/md_5/bungee/ServerConnector.java | 19 +++++++++++++++---- .../md_5/bungee/forge/ForgeServerHandler.java | 11 +++++++++++ .../forge/ForgeServerHandshakeState.java | 3 +++ 3 files changed, 29 insertions(+), 4 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 755b48223c..edb1259984 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -180,8 +180,19 @@ public void handle(Login login) throws Exception 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.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), - (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); + // Forge allows dimension ID's > 127 + + Login modLogin; + if ( handshakeHandler != null && handshakeHandler.isServerForge() ) + { + modLogin = new Login( login.getEntityId(), login.getGameMode(), login.getDimension(), login.getDifficulty(), + (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); + } + else + { + modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), + (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); + } user.unsafe().sendPacket( modLogin ); @@ -310,9 +321,9 @@ public void handle(PluginMessage pluginMessage) throws Exception } } - if (pluginMessage.getTag().equals(ForgeConstants.FML_HANDSHAKE_TAG) || pluginMessage.getTag().equals(ForgeConstants.FORGE_REGISTER)) + if (!handshakeHandler.isHandshakeComplete() && ( pluginMessage.getTag().equals(ForgeConstants.FML_HANDSHAKE_TAG) || pluginMessage.getTag().equals(ForgeConstants.FORGE_REGISTER ) )) { - this.handshakeHandler.handle(pluginMessage); + handshakeHandler.handle( pluginMessage ); // We send the message as part of the handler, so don't send it here. throw CancelSendSignal.INSTANCE; diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java index 3fe5ec5fd3..56215d4b1c 100644 --- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandler.java @@ -82,4 +82,15 @@ public void setServerAsForgeServer() { serverForge = true; } + + + /** + * Returns whether the handshake is complete. + * + * @return true if the handshake has been completed. + */ + public boolean isHandshakeComplete() + { + return this.state == ForgeServerHandshakeState.DONE; + } } diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandshakeState.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandshakeState.java index d58b4945fd..00f92ad7d5 100644 --- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandshakeState.java +++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeServerHandshakeState.java @@ -132,6 +132,9 @@ public ForgeServerHandshakeState handle(PluginMessage message, ChannelWrapper ch @Override public ForgeServerHandshakeState send(PluginMessage message, UserConnection con) { + // Packets should never make it here but if they ever do, pass everything to client + ForgeLogger.logServer( LogDirection.SENDING, this.name(), message); + con.unsafe().sendPacket(message); return this; } } From 531029faa9e9910236781643735d21dce43091f0 Mon Sep 17 00:00:00 2001 From: ghac Date: Fri, 26 Aug 2016 16:25:13 +0200 Subject: [PATCH 37/47] Fix merge. --- proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 3 --- .../main/java/net/md_5/bungee/connection/UpstreamBridge.java | 1 + 2 files changed, 1 insertion(+), 3 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 9caf049887..4f898b42dd 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -33,10 +33,7 @@ import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.Protocol; -<<<<<<< HEAD import net.md_5.bungee.protocol.ProtocolConstants; -======= ->>>>>>> 5c809c24990ec06ecdb0ee6550d4d10595ed9323 import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Kick; 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 7ca229d965..76f76aa34f 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 @@ -13,6 +13,7 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.PacketWrapper; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.PlayerListItem; From 9799522ee7e611a3fbb2024197542264db9abfe0 Mon Sep 17 00:00:00 2001 From: ghac Date: Thu, 20 Oct 2016 22:43:46 +0200 Subject: [PATCH 38/47] Fix merge conflicts. --- proxy/src/main/java/net/md_5/bungee/BungeeTitle.java | 1 + proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java | 1 + proxy/src/main/java/net/md_5/bungee/tab/Global.java | 1 + proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java | 1 + 4 files changed, 4 insertions(+) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java b/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java index c580e73d1c..e9073c5d4c 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeTitle.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.Title.Action; public class BungeeTitle implements Title 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 f473ebadee..ba3260f399 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 @@ -14,6 +14,7 @@ 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.ProtocolConstants; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; 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 da09b9d2ed..e164cabd62 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 @@ -6,6 +6,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.PlayerListItem; import java.util.Collection; 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 5847e859ca..835a301ce8 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 @@ -4,6 +4,7 @@ import java.util.HashSet; import java.util.UUID; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.PlayerListItem; public class ServerUnique extends TabList From 939b922e1624f8a0c7c1df9d67a3eb712947f363 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 14 Nov 2016 16:46:37 +0100 Subject: [PATCH 39/47] Update Readme to 1.11 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 385baad945..f2d1fd756e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -BungeeCord for 1.7/1.8/1.9/1.10 +BungeeCord for 1.7/1.8/1.9/1.10/1.11 ========== [![Build Status](https://travis-ci.org/HexagonMC/BungeeCord.svg?branch=master)](https://travis-ci.org/HexagonMC/BungeeCord) From 0df78e3246aaea215982b11c2b49121f08899c34 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 27 Nov 2016 00:56:43 +0100 Subject: [PATCH 40/47] Create ISSUE_TEMPLATE.md --- ISSUE_TEMPLATE.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ISSUE_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000000..c175fce1b6 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,13 @@ +### What Hexacord version are you using? Post the output of /bungee + + +### Are you using Bungee plugins? If yes, please list all of them + versionnumber + + +### How can we reproduce the error/bug? + + +### Is an error message (bungee/spigot/client)? If yes, use pastebin.com and share the link. + + +### In addidtion to that, please explain your issue as detailed as possible. From 8d512530a7677820c145f0501536898dfdfdca26 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 1 Apr 2017 16:52:11 +0200 Subject: [PATCH 41/47] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f2d1fd756e..2364a8e82f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ This version reimplements Minecraft 1.7.10 and basic 1.7.10 Forge support. +IMPORTANT: We WON'T fix any 1.7 bugs. +This fork is designed for keeping your old servers in your network, until your modspacks are available for 1.10.2/1.11.2 or higher. +Most of them are, so get rid of 1.7 fast and move to 1.10.2/1.11.2 modpacks asap. + This version is maintained by https://hexagonmc.eu ###Releases can be downloaded here: [Releases](https://github.com/HexagonMC/BungeeCord/releases) From 4a40b9f6e95e6b426b0f52c41d1346c35cfdcf7a Mon Sep 17 00:00:00 2001 From: Daniel Naylor Date: Sun, 9 Aug 2015 13:43:57 +0100 Subject: [PATCH 42/47] Add support for FML with IP Forwarding enabled FML adds a \00FML\00 marker to the host field, so Forge can determine whether or not to start a Forge handshake, making way to allow vanilla clients to connect to Forge servers that don't need a client modification. However, Bungee also uses the field, and the two implementations collide when using Spigot. The original fix was to not send the FML information at the same time as the IP forwarding, you could have one or the other, but not both. This was OK, as no FML servers supported IP forwarding as of time of the patch. This was implemented in commit 4809f1f80ace9ae87b91453c8887c70f5e098bd0. However, there is now at least one Forge coremod that intends to support IP forwarding. To be able to support Forge with IP forwarding, a way to be able to support the FML token (and any other host data) is needed. This adds a property to the user Game Profile to forward on whether the user is a FML client, along with whether there is any extra data. No breaking changes occur due to this patch. --- .../java/net/md_5/bungee/ServerConnector.java | 3 +- .../java/net/md_5/bungee/UserConnection.java | 29 ++++++++++++++++++- .../net/md_5/bungee/forge/ForgeConstants.java | 4 +++ 3 files changed, 33 insertions(+), 3 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 13a99956b0..f1d5ff1a27 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -98,8 +98,7 @@ public void connected(ChannelWrapper channel) throws Exception copiedHandshake.setHost(newHost); } else if (!user.getExtraDataInHandshake().isEmpty()) - // Only restore the extra data if IP forwarding is off. - // TODO: Add support for this data with IP forwarding. + // Restore the extra data copiedHandshake.setHost(copiedHandshake.getHost() + user.getExtraDataInHandshake()); channel.write(copiedHandshake); 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 812dec3e19..b2d64872a2 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -11,6 +11,7 @@ import io.netty.channel.ChannelOption; import io.netty.util.internal.PlatformDependent; import java.net.InetSocketAddress; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -37,6 +38,8 @@ import net.md_5.bungee.api.score.Scoreboard; import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.connection.InitialHandler; +import net.md_5.bungee.connection.LoginResult; +import net.md_5.bungee.connection.LoginResult.Property; import net.md_5.bungee.entitymap.EntityMap; import net.md_5.bungee.forge.ForgeClientHandler; import net.md_5.bungee.forge.ForgeConstants; @@ -180,8 +183,32 @@ public void init() forgeClientHandler = new ForgeClientHandler( this ); + // No-config FML handshake marker. // Set whether the connection has a 1.8 FML marker in the handshake. - forgeClientHandler.setFmlTokenInHandshake( this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ) ); + if (this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN )) + { + forgeClientHandler.setFmlTokenInHandshake( true ); + + // If we IP forward, add the a FML marker to the game profile. + if ( BungeeCord.getInstance().config.isIpForward() ) + { + // Get the user profile. + LoginResult profile = pendingConnection.getLoginProfile(); + + // Get the current properties and copy them into a slightly bigger array. + Property[] oldp = profile.getProperties(); + Property[] newp = Arrays.copyOf( oldp, oldp.length + 2 ); + + // Add a new profile property that specifies that this user is a Forge user. + newp[newp.length - 2] = new Property( ForgeConstants.FML_LOGIN_PROFILE, "true", null ); + + // If we do not perform the replacement, then the IP Forwarding code in Spigot et. al. will try to split on this prematurely. + newp[newp.length - 1] = new Property( ForgeConstants.EXTRA_DATA, pendingConnection.getExtraDataInHandshake().replaceAll( "\0", "\1"), "" ); + + // Set the properties in the profile. All done. + profile.setProperties( newp ); + } + } } public void sendPacket(PacketWrapper packet) diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java index 6dca204830..f5253b897b 100644 --- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java @@ -14,6 +14,10 @@ public class ForgeConstants public static final String FML_HANDSHAKE_TAG = "FML|HS"; public static final String FML_REGISTER = "REGISTER"; + // Game profile key + public static final String FML_LOGIN_PROFILE = "forgeClient"; + public static final String EXTRA_DATA = "extraData"; + /** * The FML 1.8 handshake token. */ From 40270ea56ef525aab9d183d729c06a7282d3a41b Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 21 Apr 2017 15:31:48 +0200 Subject: [PATCH 43/47] Update README to show new feature implemented by dualspiral (ip-forwarding). --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2364a8e82f..33994c9e7d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ https://www.spigotmc.org/threads/1-8-1-9-bungeecord.392/ This version reimplements Minecraft 1.7.10 and basic 1.7.10 Forge support. +Since release 134+, SpongePls is no longer needed when using Sponge-servers within your network! + IMPORTANT: We WON'T fix any 1.7 bugs. This fork is designed for keeping your old servers in your network, until your modspacks are available for 1.10.2/1.11.2 or higher. Most of them are, so get rid of 1.7 fast and move to 1.10.2/1.11.2 modpacks asap. From 1f268b4bb567da0725caa130251641e27a379746 Mon Sep 17 00:00:00 2001 From: Daniel Naylor Date: Sat, 29 Apr 2017 17:42:41 +0100 Subject: [PATCH 44/47] Fix forwarding issue where the login profile is sometimes null. Now, we create the profile properly if it doesn't currently exist. Fixes HexagonMC/BungeeCord#139 --- .../java/net/md_5/bungee/ServerConnector.java | 33 +++++++++++++++++-- .../java/net/md_5/bungee/UserConnection.java | 26 +-------------- 2 files changed, 32 insertions(+), 27 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 f1d5ff1a27..14e533271a 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -1,5 +1,6 @@ package net.md_5.bungee; +import java.util.Arrays; import java.util.Queue; import java.util.Set; import java.util.UUID; @@ -91,15 +92,43 @@ public void connected(ChannelWrapper channel) throws Exception if (BungeeCord.getInstance().config.isIpForward()) { String newHost = copiedHandshake.getHost() + "\00" + user.getAddress().getHostString() + "\00" + user.getUUID(); - + + // Handle properties. + LoginResult.Property[] properties = new LoginResult.Property[0]; + LoginResult profile = user.getPendingConnection().getLoginProfile(); if (profile != null && profile.getProperties() != null && profile.getProperties().length > 0) + { newHost += "\00" + BungeeCord.getInstance().gson.toJson(profile.getProperties()); + } + + if ( user.getForgeClientHandler().isFmlTokenInHandshake() ) + { + // Get the current properties and copy them into a slightly bigger array. + LoginResult.Property[] newp = Arrays.copyOf( properties, properties.length + 2 ); + + // Add a new profile property that specifies that this user is a Forge user. + newp[newp.length - 2] = new LoginResult.Property( ForgeConstants.FML_LOGIN_PROFILE, "true", null ); + + // If we do not perform the replacement, then the IP Forwarding code in Spigot et. al. will try to split on this prematurely. + newp[newp.length - 1] = new LoginResult.Property( ForgeConstants.EXTRA_DATA, user.getExtraDataInHandshake().replaceAll( "\0", "\1"), "" ); + + // All done. + properties = newp; + } + + // If we touched any properties, then append them + if (properties.length > 0) + { + newHost += "\00" + BungeeCord.getInstance().gson.toJson(properties); + } + copiedHandshake.setHost(newHost); } - else if (!user.getExtraDataInHandshake().isEmpty()) + else if (!user.getExtraDataInHandshake().isEmpty()) { // Restore the extra data copiedHandshake.setHost(copiedHandshake.getHost() + user.getExtraDataInHandshake()); + } channel.write(copiedHandshake); 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 b2d64872a2..76bf173dbc 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -11,7 +11,6 @@ import io.netty.channel.ChannelOption; import io.netty.util.internal.PlatformDependent; import java.net.InetSocketAddress; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -38,8 +37,6 @@ import net.md_5.bungee.api.score.Scoreboard; import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.connection.InitialHandler; -import net.md_5.bungee.connection.LoginResult; -import net.md_5.bungee.connection.LoginResult.Property; import net.md_5.bungee.entitymap.EntityMap; import net.md_5.bungee.forge.ForgeClientHandler; import net.md_5.bungee.forge.ForgeConstants; @@ -58,7 +55,6 @@ import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter; import net.md_5.bungee.protocol.packet.PluginMessage; -import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.tab.ServerUnique; import net.md_5.bungee.tab.TabList; @@ -185,29 +181,9 @@ public void init() // No-config FML handshake marker. // Set whether the connection has a 1.8 FML marker in the handshake. - if (this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN )) + if (this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN )) { forgeClientHandler.setFmlTokenInHandshake( true ); - - // If we IP forward, add the a FML marker to the game profile. - if ( BungeeCord.getInstance().config.isIpForward() ) - { - // Get the user profile. - LoginResult profile = pendingConnection.getLoginProfile(); - - // Get the current properties and copy them into a slightly bigger array. - Property[] oldp = profile.getProperties(); - Property[] newp = Arrays.copyOf( oldp, oldp.length + 2 ); - - // Add a new profile property that specifies that this user is a Forge user. - newp[newp.length - 2] = new Property( ForgeConstants.FML_LOGIN_PROFILE, "true", null ); - - // If we do not perform the replacement, then the IP Forwarding code in Spigot et. al. will try to split on this prematurely. - newp[newp.length - 1] = new Property( ForgeConstants.EXTRA_DATA, pendingConnection.getExtraDataInHandshake().replaceAll( "\0", "\1"), "" ); - - // Set the properties in the profile. All done. - profile.setProperties( newp ); - } } } From faccbdadb39ecdd561c9fa44a54767d13966efdb Mon Sep 17 00:00:00 2001 From: ghac Date: Sun, 14 May 2017 19:06:10 +0200 Subject: [PATCH 45/47] Fix wrong Forge-connection handling. Fixes 143. --- proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 14e533271a..57915c0881 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -99,7 +99,7 @@ public void connected(ChannelWrapper channel) throws Exception LoginResult profile = user.getPendingConnection().getLoginProfile(); if (profile != null && profile.getProperties() != null && profile.getProperties().length > 0) { - newHost += "\00" + BungeeCord.getInstance().gson.toJson(profile.getProperties()); + properties = profile.getProperties(); } if ( user.getForgeClientHandler().isFmlTokenInHandshake() ) From 6e70b90c17bfa08b46f60095a62cd4dd037a7532 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 14 May 2017 21:45:15 +0200 Subject: [PATCH 46/47] Update README - 1.12 support. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33994c9e7d..cd69390b53 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -BungeeCord for 1.7/1.8/1.9/1.10/1.11 +BungeeCord for 1.7/1.8/1.9/1.10/1.11/1.12 ========== [![Build Status](https://travis-ci.org/HexagonMC/BungeeCord.svg?branch=master)](https://travis-ci.org/HexagonMC/BungeeCord) From e372443f8a875997893b8ddd96232ca0fd622836 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 19 May 2017 21:00:04 +1000 Subject: [PATCH 47/47] Update to Minecraft 1.12-pre5 Obsoletes 1.12-pre2 --- .../net/md_5/bungee/protocol/Protocol.java | 18 +++++++-------- .../bungee/protocol/ProtocolConstants.java | 2 +- .../md_5/bungee/entitymap/EntityMap_1_12.java | 22 +++++++++---------- 3 files changed, 21 insertions(+), 21 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 f16804ba8f..8ab354e28c 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 @@ -61,42 +61,42 @@ public enum Protocol KeepAlive.class, map( ProtocolConstants.MINECRAFT_1_8, 0x00 ), map( ProtocolConstants.MINECRAFT_1_9, 0x1F ), - map( ProtocolConstants.MINECRAFT_1_12, 0x20 ) + map( ProtocolConstants.MINECRAFT_1_12, 0x1F ) ); TO_CLIENT.registerPacket( Login.class, map( ProtocolConstants.MINECRAFT_1_8, 0x01 ), map( ProtocolConstants.MINECRAFT_1_9, 0x23 ), - map( ProtocolConstants.MINECRAFT_1_12, 0x24 ) + map( ProtocolConstants.MINECRAFT_1_12, 0x23 ) ); TO_CLIENT.registerPacket( Chat.class, map( ProtocolConstants.MINECRAFT_1_8, 0x02 ), map( ProtocolConstants.MINECRAFT_1_9, 0x0F ), - map( ProtocolConstants.MINECRAFT_1_12, 0x10 ) + map( ProtocolConstants.MINECRAFT_1_12, 0x0F ) ); TO_CLIENT.registerPacket( Respawn.class, map( ProtocolConstants.MINECRAFT_1_8, 0x07 ), map( ProtocolConstants.MINECRAFT_1_9, 0x33 ), - map( ProtocolConstants.MINECRAFT_1_12, 0x35 ) + map( ProtocolConstants.MINECRAFT_1_12, 0x34 ) ); TO_CLIENT.registerPacket( BossBar.class, map( ProtocolConstants.MINECRAFT_1_9, 0x0C ), - map( ProtocolConstants.MINECRAFT_1_12, 0x0D ) + map( ProtocolConstants.MINECRAFT_1_12, 0x0C ) ); TO_CLIENT.registerPacket( PlayerListItem.class, // PlayerInfo map( ProtocolConstants.MINECRAFT_1_8, 0x38 ), map( ProtocolConstants.MINECRAFT_1_9, 0x2D ), - map( ProtocolConstants.MINECRAFT_1_12, 0x2E ) + map( ProtocolConstants.MINECRAFT_1_12, 0x2D ) ); TO_CLIENT.registerPacket( TabCompleteResponse.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3A ), map( ProtocolConstants.MINECRAFT_1_9, 0x0E ), - map( ProtocolConstants.MINECRAFT_1_12, 0x0F ) + map( ProtocolConstants.MINECRAFT_1_12, 0x0E ) ); TO_CLIENT.registerPacket( ScoreboardObjective.class, @@ -126,13 +126,13 @@ public enum Protocol PluginMessage.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3F ), map( ProtocolConstants.MINECRAFT_1_9, 0x18 ), - map( ProtocolConstants.MINECRAFT_1_12, 0x19 ) + map( ProtocolConstants.MINECRAFT_1_12, 0x18 ) ); TO_CLIENT.registerPacket( Kick.class, map( ProtocolConstants.MINECRAFT_1_8, 0x40 ), map( ProtocolConstants.MINECRAFT_1_9, 0x1A ), - map( ProtocolConstants.MINECRAFT_1_12, 0x1B ) + map( ProtocolConstants.MINECRAFT_1_12, 0x1A ) ); TO_CLIENT.registerPacket( Title.class, diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java index 240b0e38e1..f2d6a8b992 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java @@ -15,7 +15,7 @@ public class ProtocolConstants public static final int MINECRAFT_1_10 = 210; public static final int MINECRAFT_1_11 = 315; public static final int MINECRAFT_1_11_1 = 316; - public static final int MINECRAFT_1_12 = 329; + public static final int MINECRAFT_1_12 = 332; public static final List SUPPORTED_VERSIONS = Arrays.asList( "1.7.x", "1.8.x", diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java index 3de2dfa971..2db69a51a5 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java @@ -24,14 +24,14 @@ class EntityMap_1_12 extends EntityMap addRewrite( 0x05, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player : PacketPlayOutNamedEntitySpawn addRewrite( 0x06, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation : PacketPlayOutAnimation addRewrite( 0x08, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation : PacketPlayOutBlockBreakAnimation - addRewrite( 0x1C, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus - addRewrite( 0x26, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove - addRewrite( 0x27, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook - addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook - addRewrite( 0x29, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity - addRewrite( 0x30, ProtocolConstants.Direction.TO_CLIENT, true ); // Use bed : PacketPlayOutBed - addRewrite( 0x33, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect - addRewrite( 0x36, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation + addRewrite( 0x1B, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus + addRewrite( 0x25, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove + addRewrite( 0x26, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook + addRewrite( 0x27, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook + addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity + addRewrite( 0x2F, ProtocolConstants.Direction.TO_CLIENT, true ); // Use bed : PacketPlayOutBed + addRewrite( 0x31, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect + addRewrite( 0x35, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation addRewrite( 0x38, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera addRewrite( 0x3B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata addRewrite( 0x3C, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity @@ -71,7 +71,7 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId) DefinedPacket.readVarInt( packet ); jumpIndex = packet.readerIndex(); // Fall through on purpose to int array of IDs - case 0x32 /* Destroy Entities : PacketPlayOutEntityDestroy */: + case 0x31 /* Destroy Entities : PacketPlayOutEntityDestroy */: int count = DefinedPacket.readVarInt( packet ); int[] ids = new int[ count ]; for ( int i = 0; i < count; i++ ) @@ -132,7 +132,7 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId) packet.writerIndex( previous ); } break; - case 0x2D /* Combat Event : PacketPlayOutCombatEvent */: + case 0x2C /* Combat Event : PacketPlayOutCombatEvent */: int event = packet.readUnsignedByte(); if ( event == 1 /* End Combat*/ ) { @@ -164,7 +164,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId) int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; - if ( packetId == 0x1D /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) + if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player;