diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index c282f3453..37f0cba9d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -7,7 +7,7 @@ import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.PlayerListItem; -import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.ScoreboardDisplay; @@ -22,10 +22,15 @@ import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; +import net.md_5.bungee.protocol.packet.TabCompleteResponse; public abstract class AbstractPacketHandler { + public void handle(TabCompleteResponse tabResponse) throws Exception + { + } + public void handle(PingPacket ping) throws Exception { } @@ -74,7 +79,7 @@ public abstract class AbstractPacketHandler { } - public void handle(TabComplete tabComplete) throws Exception + public void handle(TabCompleteRequest tabComplete) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index be3429524..3cc2a54ad 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -41,6 +41,26 @@ public abstract class DefinedPacket return ret; } + public static void writeStringArray(String[] s, ByteBuf buf) + { + writeVarInt( s.length, buf ); + for ( String str : s ) + { + writeString( str, buf ); + } + } + + public static String[] readStringArray(ByteBuf buf) + { + int len = readVarInt( buf ); + String[] ret = new String[ len ]; + for ( int i = 0; i < ret.length; i++ ) + { + ret[i] = readString( buf ); + } + return ret; + } + public static int readVarInt(ByteBuf input) { int out = 0; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 274608ebc..87f3e6a5d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -24,7 +24,8 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; -import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.TabCompleteRequest; +import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.protocol.packet.Team; public enum Protocol @@ -48,7 +49,7 @@ public enum Protocol TO_CLIENT.registerPacket( 0x02, Chat.class ); TO_CLIENT.registerPacket( 0x07, Respawn.class ); TO_CLIENT.registerPacket( 0x3B, PlayerListItem.class ); - TO_CLIENT.registerPacket( 0x3D, TabComplete.class ); + TO_CLIENT.registerPacket( 0x3D, TabCompleteResponse.class ); TO_CLIENT.registerPacket( 0x3E, ScoreboardObjective.class ); TO_CLIENT.registerPacket( 0x3F, ScoreboardScore.class ); TO_CLIENT.registerPacket( 0x40, ScoreboardDisplay.class ); @@ -59,7 +60,7 @@ public enum Protocol TO_SERVER.registerPacket( 0x00, KeepAlive.class ); TO_SERVER.registerPacket( 0x01, Chat.class ); - TO_SERVER.registerPacket( 0x14, TabComplete.class ); + TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class ); TO_SERVER.registerPacket( 0x15, ClientSettings.class ); TO_SERVER.registerPacket( 0x17, PluginMessage.class ); } @@ -92,7 +93,7 @@ public enum Protocol /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; public static final int PROTOCOL_VERSION = 0x00; - public static final String MINECRAFT_VERSION = "13w41a"; + public static final String MINECRAFT_VERSION = "13w41b"; /*========================================================================*/ public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java index ed55d4725..930b3474a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java @@ -25,7 +25,7 @@ public class Handshake extends DefinedPacket { protocolVersion = readVarInt( buf ); host = readString( buf ); - port = readVarInt( buf ); + port = buf.readUnsignedShort(); requestedProtocol = readVarInt( buf ); } @@ -34,7 +34,7 @@ public class Handshake extends DefinedPacket { writeVarInt( protocolVersion, buf ); writeString( host, buf ); - writeVarInt( port, buf ); + buf.writeShort( port ); writeVarInt( requestedProtocol, buf ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index 65510da6d..321b93a82 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -16,34 +16,28 @@ public class Login extends DefinedPacket { private int entityId; - private String levelType; - private byte gameMode; + private short gameMode; private int dimension; - private byte difficulty; - private byte unused; - private byte maxPlayers; + private short difficulty; + private short maxPlayers; @Override public void read(ByteBuf buf) { entityId = buf.readInt(); - levelType = readString( buf ); - gameMode = buf.readByte(); + gameMode = buf.readUnsignedByte(); dimension = buf.readByte(); - difficulty = buf.readByte(); - unused = buf.readByte(); - maxPlayers = buf.readByte(); + difficulty = buf.readUnsignedByte(); + maxPlayers = buf.readUnsignedByte(); } @Override public void write(ByteBuf buf) { buf.writeInt( entityId ); - writeString( levelType, buf ); buf.writeByte( gameMode ); buf.writeByte( dimension ); buf.writeByte( difficulty ); - buf.writeByte( unused ); buf.writeByte( maxPlayers ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java index b6e60599d..b5a448230 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Respawn.java @@ -6,7 +6,6 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.ToString; import net.md_5.bungee.protocol.AbstractPacketHandler; @Data @@ -17,19 +16,15 @@ public class Respawn extends DefinedPacket { private int dimension; - private byte difficulty; - private byte gameMode; - private short worldHeight; - private String levelType; + private short difficulty; + private short gameMode; @Override public void read(ByteBuf buf) { dimension = buf.readInt(); - difficulty = buf.readByte(); - gameMode = buf.readByte(); - worldHeight = buf.readShort(); - levelType = readString( buf ); + difficulty = buf.readUnsignedByte(); + gameMode = buf.readUnsignedByte(); } @Override @@ -38,8 +33,6 @@ public class Respawn extends DefinedPacket buf.writeInt( dimension ); buf.writeByte( difficulty ); buf.writeByte( gameMode ); - buf.writeShort( worldHeight ); - writeString( levelType, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java similarity index 62% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java index ec9ca0c44..3bedbd5eb 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabComplete.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java @@ -12,16 +12,10 @@ import net.md_5.bungee.protocol.AbstractPacketHandler; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) -public class TabComplete extends DefinedPacket +public class TabCompleteRequest extends DefinedPacket { private String cursor; - private String[] commands; - - public TabComplete(String[] alternatives) - { - commands = alternatives; - } @Override public void read(ByteBuf buf) @@ -32,13 +26,7 @@ public class TabComplete extends DefinedPacket @Override public void write(ByteBuf buf) { - StringBuilder tab = new StringBuilder(); - for ( String alternative : commands ) - { - tab.append( alternative ); - tab.append( "\00" ); - } - writeString( tab.substring( 0, tab.length() - 1 ), buf ); + writeString( cursor, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java new file mode 100644 index 000000000..0027b989f --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java @@ -0,0 +1,37 @@ +package net.md_5.bungee.protocol.packet; + +import net.md_5.bungee.protocol.DefinedPacket; +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class TabCompleteResponse extends DefinedPacket +{ + + private String[] commands; + + @Override + public void read(ByteBuf buf) + { + commands = readStringArray( buf ); + } + + @Override + public void write(ByteBuf buf) + { + writeStringArray( commands, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java index b20726186..75fd9b551 100644 --- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java @@ -7,8 +7,8 @@ import net.md_5.bungee.protocol.packet.PluginMessage; public class PacketConstants { - public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); - public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); + public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0 ); + public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0 ); public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 ); public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[] { diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index a0a46cf92..05f022638 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -22,7 +22,6 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.MinecraftOutput; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.Login; import net.md_5.bungee.protocol.packet.Respawn; @@ -131,7 +130,7 @@ public class ServerConnector extends PacketHandler user.setServerEntityId( login.getEntityId() ); // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability - Login modLogin = new Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(), + Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), (byte) user.getPendingConnection().getListener().getTabListSize() ); user.unsafe().sendPacket( modLogin ); @@ -157,7 +156,7 @@ public class ServerConnector extends PacketHandler user.sendDimensionSwitch(); user.setServerEntityId( login.getEntityId() ); - user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) ); + user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode() ) ); // Remove from old servers user.getServer().setObsolete( true ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 06a6bd283..411003cb4 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -1,7 +1,6 @@ package net.md_5.bungee.connection; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.EntityMap; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; import net.md_5.bungee.api.ProxyServer; @@ -13,11 +12,12 @@ import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Chat; -import net.md_5.bungee.protocol.packet.TabComplete; +import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.PluginMessage; import java.util.ArrayList; import java.util.List; +import net.md_5.bungee.protocol.packet.TabCompleteResponse; public class UpstreamBridge extends PacketHandler { @@ -93,7 +93,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(TabComplete tabComplete) throws Exception + public void handle(TabCompleteRequest tabComplete) throws Exception { if ( tabComplete.getCursor().startsWith( "/" ) ) { @@ -102,7 +102,7 @@ public class UpstreamBridge extends PacketHandler if ( !results.isEmpty() ) { - con.unsafe().sendPacket( new TabComplete( results.toArray( new String[ results.size() ] ) ) ); + con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) ); throw new CancelSendSignal(); } }