From 835e4e332c3bba7a130ddae0742a03a73b4f9c60 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 30 May 2013 16:38:53 +1000 Subject: [PATCH] Start work on more efficient, publically accessable packet API --- .../bungee/protocol/PacketDefinitions.java | 75 +----- .../bungee/protocol/netty/Instruction.java | 2 - .../net/md_5/bungee/protocol/netty/Score.java | 19 -- .../net/md_5/bungee/protocol/netty/Team.java | 26 -- .../bungee/protocol/packet/DefinedPacket.java | 117 +++++++++ .../protocol/packet/Packet0KeepAlive.java | 35 +++ .../bungee/protocol/packet/Packet1Login.java | 53 ++++ .../protocol}/packet/Packet2Handshake.java | 7 +- .../bungee/protocol}/packet/Packet3Chat.java | 5 +- .../protocol}/packet/Packet9Respawn.java | 5 +- .../packet/PacketC9PlayerListItem.java | 5 +- .../protocol}/packet/PacketCCSettings.java | 3 +- .../packet/PacketCDClientStatus.java | 3 +- .../packet/PacketCEScoreboardObjective.java | 7 +- .../packet/PacketCFScoreboardScore.java | 7 +- .../packet/PacketD0DisplayScoreboard.java | 3 +- .../bungee/protocol}/packet/PacketD1Team.java | 5 +- .../packet/PacketFAPluginMessage.java | 5 +- .../packet/PacketFCEncryptionResponse.java | 3 +- .../packet/PacketFDEncryptionRequest.java | 5 +- .../bungee/protocol}/packet/PacketFEPing.java | 3 +- .../bungee/protocol}/packet/PacketFFKick.java | 5 +- .../protocol}/packet/PacketHandler.java | 19 +- .../main/java/net/md_5/bungee/BungeeCord.java | 6 +- .../net/md_5/bungee/BungeeServerInfo.java | 4 +- .../java/net/md_5/bungee/EncryptionUtil.java | 4 +- .../net/md_5/bungee/ServerConnection.java | 4 +- .../java/net/md_5/bungee/ServerConnector.java | 22 +- .../java/net/md_5/bungee/UserConnection.java | 12 +- .../bungee/connection/DownstreamBridge.java | 20 +- .../bungee/connection/InitialHandler.java | 18 +- .../md_5/bungee/connection/PingHandler.java | 4 +- .../bungee/connection/UpstreamBridge.java | 10 +- .../bungee/netty/DefinedPacketEncoder.java | 2 +- .../net/md_5/bungee/netty/HandlerBoss.java | 4 +- .../net/md_5/bungee/packet/DefinedPacket.java | 240 ------------------ .../md_5/bungee/packet/Packet0KeepAlive.java | 24 -- .../net/md_5/bungee/packet/Packet1Login.java | 70 ----- .../java/net/md_5/bungee/tablist/Global.java | 2 +- .../net/md_5/bungee/tablist/GlobalPing.java | 2 +- .../net/md_5/bungee/tablist/ServerUnique.java | 2 +- 41 files changed, 325 insertions(+), 542 deletions(-) delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/netty/Score.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/netty/Team.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/Packet2Handshake.java (86%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/Packet3Chat.java (81%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/Packet9Respawn.java (92%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketC9PlayerListItem.java (85%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketCCSettings.java (88%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketCDClientStatus.java (90%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketCEScoreboardObjective.java (85%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketCFScoreboardScore.java (87%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketD0DisplayScoreboard.java (86%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketD1Team.java (91%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketFAPluginMessage.java (85%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketFCEncryptionResponse.java (91%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketFDEncryptionRequest.java (88%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketFEPing.java (78%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketFFKick.java (80%) rename {proxy/src/main/java/net/md_5/bungee => protocol/src/main/java/net/md_5/bungee/protocol}/packet/PacketHandler.java (63%) delete mode 100644 proxy/src/main/java/net/md_5/bungee/packet/DefinedPacket.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/packet/Packet0KeepAlive.java delete mode 100644 proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/PacketDefinitions.java b/protocol/src/main/java/net/md_5/bungee/protocol/PacketDefinitions.java index 9a468784..4d536b6c 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/PacketDefinitions.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/PacketDefinitions.java @@ -14,27 +14,11 @@ public class PacketDefinitions public enum OpCode { - BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SCORE, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, TEAM, USHORT_BYTE + BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE } static { - opCodes[0x00] = new OpCode[] - { - INT - }; - opCodes[0x01] = new OpCode[] - { - INT, STRING, BYTE, BYTE, BYTE, BYTE, BYTE - }; - opCodes[0x02] = new OpCode[] - { - BYTE, STRING, STRING, INT - }; - opCodes[0x03] = new OpCode[] - { - STRING - }; opCodes[0x04] = new OpCode[] { LONG, LONG @@ -55,10 +39,6 @@ public class PacketDefinitions { SHORT, SHORT, FLOAT }; - opCodes[0x09] = new OpCode[] - { - INT, BYTE, BYTE, SHORT, STRING - }; opCodes[0x0A] = new OpCode[] { BOOLEAN @@ -283,10 +263,6 @@ public class PacketDefinitions { INT, BYTE }; - opCodes[0xC9] = new OpCode[] - { - STRING, BOOLEAN, SHORT - }; opCodes[0xCA] = new OpCode[] { BYTE, BYTE, BYTE @@ -295,54 +271,5 @@ public class PacketDefinitions { STRING }; - opCodes[0xCC] = new OpCode[] - { - STRING, BYTE, BYTE, BYTE, BOOLEAN - }; - opCodes[0xCD] = new OpCode[] - { - BYTE - }; - opCodes[0xCE] = new OpCode[] - { - STRING, STRING, BYTE - }; - opCodes[0xCF] = new OpCode[] - { - SCORE - }; - opCodes[0xD0] = new OpCode[] - { - BYTE, STRING - }; - opCodes[0xD1] = new OpCode[] - { - TEAM - }; - opCodes[0xFA] = new OpCode[] - { - STRING, SHORT_BYTE - }; - opCodes[0xFC] = new OpCode[] - { - SHORT_BYTE, SHORT_BYTE - }; - opCodes[0xFD] = new OpCode[] - { - STRING, SHORT_BYTE, SHORT_BYTE - }; - opCodes[0xFE] = new OpCode[] - { - BYTE - }; - opCodes[0xFF] = new OpCode[] - { - STRING - }; - /*========================== Minecraft Forge ===========================*/ - opCodes[0x01 + FORGE_PROTOCOL] = new OpCode[] - { - INT, STRING, BYTE, INT, BYTE, BYTE, BYTE - }; } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Instruction.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Instruction.java index 9a25a2a8..d22fdb38 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Instruction.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Instruction.java @@ -19,12 +19,10 @@ abstract class Instruction static final Instruction LONG = new Jump( 8 ); static final Instruction METADATA = new MetaData(); static final Instruction OPTIONAL_MOTION = new OptionalMotion(); - static final Instruction SCORE = new Score(); static final Instruction SHORT = new Jump( 2 ); static final Instruction SHORT_BYTE = new ShortHeader( BYTE ); static final Instruction SHORT_ITEM = new ShortHeader( ITEM ); static final Instruction STRING = new ShortHeader( new Jump( 2 ) ); - static final Instruction TEAM = new Team(); static final Instruction USHORT_BYTE = new UnsignedShortByte(); // Illegal forward references below this line static final Instruction BYTE_INT = new ByteHeader( INT ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Score.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Score.java deleted file mode 100644 index f5feb541..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Score.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.md_5.bungee.protocol.netty; - -import io.netty.buffer.ByteBuf; -import java.io.IOException; - -public class Score extends Instruction -{ - - @Override - void read(ByteBuf in) throws IOException - { - STRING.read( in ); - if ( in.readByte() == 0 ) - { - STRING.read( in ); - INT.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Team.java deleted file mode 100644 index 935aed6f..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Team.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.md_5.bungee.protocol.netty; - -import io.netty.buffer.ByteBuf; -import java.io.IOException; - -class Team extends Instruction -{ - - @Override - void read(ByteBuf in) throws IOException - { - STRING.read( in ); - byte mode = in.readByte(); - if ( mode == 0 || mode == 2 ) - { - STRING.read( in ); - STRING.read( in ); - STRING.read( in ); - BYTE.read( in ); - } - if ( mode == 0 || mode == 3 || mode == 4 ) - { - STRING_ARRAY.read( in ); - } - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java new file mode 100644 index 00000000..362fa0c8 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java @@ -0,0 +1,117 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +public abstract class DefinedPacket +{ + + @SuppressWarnings("unchecked") + private static Class[] classes = new Class[ 256 ]; + @SuppressWarnings("unchecked") + private static Constructor[] consructors = new Constructor[ 256 ]; + + public static DefinedPacket packet(ByteBuf buf) + { + DefinedPacket ret = null; + int id = buf.readUnsignedByte(); + Class clazz = classes[id]; + + if ( clazz != null ) + { + try + { + Constructor constructor = consructors[id]; + if ( constructor == null ) + { + constructor = clazz.getDeclaredConstructor(); + consructors[id] = constructor; + } + + if ( constructor != null ) + { + ret = constructor.newInstance( buf ); + } + } catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex ) + { + } + } + + return ret; + } + + public void writeString(String s, ByteBuf buf) + { + // TODO: Check len - use Guava? + buf.writeShort( s.length() ); + for ( char c : s.toCharArray() ) + { + buf.writeChar( c ); + } + } + + public String readString(ByteBuf buf) + { + // TODO: Check len - use Guava? + short len = buf.readShort(); + char[] chars = new char[ len ]; + for ( int i = 0; i < len; i++ ) + { + chars[i] = buf.readChar(); + } + return new String( chars ); + } + + public void writeArray(byte[] b, ByteBuf buf) + { + // TODO: Check len - use Guava? + buf.writeByte( b.length ); + buf.writeBytes( b ); + } + + public byte[] readArray(ByteBuf buf) + { + // TODO: Check len - use Guava? + short len = buf.readShort(); + byte[] ret = new byte[ len ]; + buf.readBytes( ret ); + return ret; + } + + public abstract void read(ByteBuf buf); + + public abstract void write(ByteBuf buf); + + public abstract void handle(PacketHandler handler) throws Exception; + + @Override + public abstract boolean equals(Object obj); + + @Override + public abstract int hashCode(); + + @Override + public abstract String toString(); + + static + { + classes[0x00] = Packet0KeepAlive.class; + classes[0x01] = Packet1Login.class; + classes[0x02] = Packet2Handshake.class; + classes[0x03] = Packet3Chat.class; + classes[0x09] = Packet9Respawn.class; + classes[0xC9] = PacketC9PlayerListItem.class; + classes[0xCC] = PacketCCSettings.class; + classes[0xCD] = PacketCDClientStatus.class; + classes[0xCE] = PacketCEScoreboardObjective.class; + classes[0xCF] = PacketCFScoreboardScore.class; + classes[0xD0] = PacketD0DisplayScoreboard.class; + classes[0xD1] = PacketD1Team.class; + classes[0xFA] = PacketFAPluginMessage.class; + classes[0xFC] = PacketFCEncryptionResponse.class; + classes[0xFD] = PacketFDEncryptionRequest.class; + classes[0xFE] = PacketFEPing.class; + classes[0xFF] = PacketFFKick.class; + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java new file mode 100644 index 00000000..7ff29cca --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet0KeepAlive.java @@ -0,0 +1,35 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@ToString +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class Packet0KeepAlive extends DefinedPacket +{ + + private int id; + + @Override + public void read(ByteBuf buf) + { + id = buf.readInt(); + } + + @Override + public void write(ByteBuf buf) + { + buf.writeInt( id ); + } + + @Override + public void handle(PacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java new file mode 100644 index 00000000..cd69c3b0 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet1Login.java @@ -0,0 +1,53 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@ToString +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class Packet1Login extends DefinedPacket +{ + + private int entityId; + private String levelType; + private byte gameMode; + private byte dimension; + private byte difficulty; + private byte unused; + private byte maxPlayers; + + @Override + public void read(ByteBuf buf) + { + entityId = buf.readInt(); + levelType = readString( buf ); + gameMode = buf.readByte(); + dimension = buf.readByte(); + difficulty = buf.readByte(); + unused = buf.readByte(); + maxPlayers = buf.readByte(); + } + + @Override + public void write(ByteBuf buf) + { + buf.writeInt( entityId ); + writeString( levelType, buf ); + buf.writeByte( gameMode ); + buf.writeByte( dimension ); + buf.writeByte( difficulty ); + buf.writeByte( unused ); + buf.writeByte( maxPlayers ); + } + + @Override + public void handle(PacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java similarity index 86% rename from proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java index 9ad693ad..d7cfb968 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -17,8 +18,8 @@ public class Packet2Handshake extends DefinedPacket { super( 0x02 ); writeByte( protocolVersion ); - writeUTF( username ); - writeUTF( host ); + writeString( username ); + writeString( host ); writeInt( port ); this.procolVersion = protocolVersion; this.username = username; diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java similarity index 81% rename from proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java index 5162e2bd..66e3e30e 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -13,7 +14,7 @@ public class Packet3Chat extends DefinedPacket public Packet3Chat(String message) { super( 0x03 ); - writeUTF( message ); + writeString( message ); this.message = message; } diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java similarity index 92% rename from proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java index 11986184..c7577695 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -23,7 +24,7 @@ public class Packet9Respawn extends DefinedPacket writeByte( difficulty ); writeByte( gameMode ); writeShort( worldHeight ); - writeUTF( levelType ); + writeString( levelType ); this.dimension = dimension; this.difficulty = difficulty; this.gameMode = gameMode; diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java similarity index 85% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java index de289ea2..a96feec0 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -23,7 +24,7 @@ public class PacketC9PlayerListItem extends DefinedPacket public PacketC9PlayerListItem(String username, boolean online, int ping) { super( 0xC9 ); - writeUTF( username ); + writeString( username ); writeBoolean( online ); writeShort( ping ); } diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java similarity index 88% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java index d2d652a8..a924454b 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java similarity index 90% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java index c82a7f41..f5c02312 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketCEScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java similarity index 85% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketCEScoreboardObjective.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java index e635aa80..b5d71a39 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketCEScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -18,8 +19,8 @@ public class PacketCEScoreboardObjective extends DefinedPacket public PacketCEScoreboardObjective(String name, String text, byte status) { super( 0xCE ); - writeUTF( name ); - writeUTF( text ); + writeString( name ); + writeString( text ); writeByte( status ); this.name = name; this.text = text; diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketCFScoreboardScore.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java similarity index 87% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketCFScoreboardScore.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java index 16d609ca..60f1a4b4 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketCFScoreboardScore.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -31,11 +32,11 @@ public class PacketCFScoreboardScore extends DefinedPacket public PacketCFScoreboardScore(String itemName, byte action, String scoreName, int value) { super( 0xCF ); - writeUTF( itemName ); + writeString( itemName ); writeByte( action ); if ( action == 0 ) { - writeUTF( scoreName ); + writeString( scoreName ); writeInt( value ); } this.itemName = itemName; diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketD0DisplayScoreboard.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java similarity index 86% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketD0DisplayScoreboard.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java index f2a534fa..3aa0caaf 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketD0DisplayScoreboard.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java similarity index 91% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java index 28b70e39..e6a25022 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketD1Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -50,7 +51,7 @@ public class PacketD1Team extends DefinedPacket public static PacketD1Team destroy(String name) { PacketD1Team packet = new PacketD1Team(); - packet.writeUTF( name ); + packet.writeString( name ); packet.writeByte( 1 ); return packet; } diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java similarity index 85% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java index ce5fe198..cd79608b 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -14,7 +15,7 @@ public class PacketFAPluginMessage extends DefinedPacket public PacketFAPluginMessage(String tag, byte[] data) { super( 0xFA ); - writeUTF( tag ); + writeString( tag ); writeArray( data ); this.tag = tag; this.data = data; diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java similarity index 91% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java index 788f4718..5a3316a8 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java similarity index 88% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java index ba061ac6..49655f02 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java @@ -1,8 +1,9 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import io.netty.buffer.ByteBuf; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -16,7 +17,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken) { super( 0xFD ); - writeUTF( serverId ); + writeString( serverId ); writeArray( publicKey ); writeArray( verifyToken ); this.serverId = serverId; diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java similarity index 78% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java index 7d532a97..8fcaeb5e 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java similarity index 80% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java index 5c3c4bc4..0ed8a361 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java @@ -1,7 +1,8 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; import lombok.EqualsAndHashCode; import lombok.ToString; +import net.md_5.bungee.packet.PacketHandler; @ToString @EqualsAndHashCode(callSuper = false) @@ -13,7 +14,7 @@ public class PacketFFKick extends DefinedPacket public PacketFFKick(String message) { super( 0xFF ); - writeUTF( message ); + writeString( message ); } PacketFFKick(byte[] buf) diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketHandler.java similarity index 63% rename from proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketHandler.java index d2bc6033..5666f0c4 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketHandler.java @@ -1,5 +1,22 @@ -package net.md_5.bungee.packet; +package net.md_5.bungee.protocol.packet; +import net.md_5.bungee.protocol.packet.Packet1Login; +import net.md_5.bungee.protocol.packet.Packet3Chat; +import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard; +import net.md_5.bungee.protocol.packet.PacketFEPing; +import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.Packet2Handshake; +import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; +import net.md_5.bungee.protocol.packet.PacketCDClientStatus; +import net.md_5.bungee.protocol.packet.PacketCCSettings; +import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore; +import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective; +import net.md_5.bungee.protocol.packet.Packet9Respawn; +import net.md_5.bungee.protocol.packet.PacketD1Team; +import net.md_5.bungee.protocol.packet.Packet0KeepAlive; import net.md_5.bungee.netty.ChannelWrapper; public abstract class PacketHandler 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 dacd10f9..0f23f1b5 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -51,9 +51,9 @@ import net.md_5.bungee.api.scheduler.TaskScheduler; import net.md_5.bungee.command.*; import net.md_5.bungee.config.YamlConfig; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.packet.DefinedPacket; -import net.md_5.bungee.packet.Packet3Chat; -import net.md_5.bungee.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.packet.Packet3Chat; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; import net.md_5.bungee.protocol.PacketDefinitions; import net.md_5.bungee.scheduler.BungeeThreadPool; import net.md_5.bungee.util.CaseInsensitiveMap; diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 588ff89d..1d1aa699 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -25,8 +25,8 @@ import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.packet.DefinedPacket; -import net.md_5.bungee.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; @RequiredArgsConstructor public class BungeeServerInfo implements ServerInfo diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 8f6494e0..e667ed57 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -15,8 +15,8 @@ import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import lombok.Getter; -import net.md_5.bungee.packet.PacketFCEncryptionResponse; -import net.md_5.bungee.packet.PacketFDEncryptionRequest; +import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; /** * Class containing all encryption related methods for the proxy. diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 4015eb26..8ea46b32 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -7,8 +7,8 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.netty.ChannelWrapper; -import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.PacketFFKick; @RequiredArgsConstructor public class ServerConnection implements Server 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 b2a907e5..ef6a80c3 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -26,17 +26,17 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; import net.md_5.bungee.netty.PacketDecoder; -import net.md_5.bungee.packet.DefinedPacket; -import net.md_5.bungee.packet.Packet1Login; -import net.md_5.bungee.packet.Packet9Respawn; -import net.md_5.bungee.packet.PacketCDClientStatus; -import net.md_5.bungee.packet.PacketCEScoreboardObjective; -import net.md_5.bungee.packet.PacketD1Team; -import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketFCEncryptionResponse; -import net.md_5.bungee.packet.PacketFDEncryptionRequest; -import net.md_5.bungee.packet.PacketFFKick; -import net.md_5.bungee.packet.PacketHandler; +import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.packet.Packet1Login; +import net.md_5.bungee.protocol.packet.Packet9Respawn; +import net.md_5.bungee.protocol.packet.PacketCDClientStatus; +import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective; +import net.md_5.bungee.protocol.packet.PacketD1Team; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; +import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.PacketHandler; import net.md_5.bungee.protocol.PacketDefinitions; @RequiredArgsConstructor 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 bd1bb6a4..c26163a4 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -30,12 +30,12 @@ import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.PipelineUtils; -import net.md_5.bungee.packet.DefinedPacket; -import net.md_5.bungee.packet.Packet3Chat; -import net.md_5.bungee.packet.Packet9Respawn; -import net.md_5.bungee.packet.PacketCCSettings; -import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.packet.Packet3Chat; +import net.md_5.bungee.protocol.packet.Packet9Respawn; +import net.md_5.bungee.protocol.packet.PacketCCSettings; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.PacketFFKick; import net.md_5.bungee.util.CaseInsensitiveSet; @RequiredArgsConstructor 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 d02b1a4a..3fc2319e 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -22,16 +22,16 @@ import net.md_5.bungee.api.scoreboard.Score; import net.md_5.bungee.api.scoreboard.Scoreboard; import net.md_5.bungee.api.scoreboard.Team; import net.md_5.bungee.netty.ChannelWrapper; -import net.md_5.bungee.packet.Packet0KeepAlive; -import net.md_5.bungee.packet.Packet3Chat; -import net.md_5.bungee.packet.PacketC9PlayerListItem; -import net.md_5.bungee.packet.PacketCEScoreboardObjective; -import net.md_5.bungee.packet.PacketCFScoreboardScore; -import net.md_5.bungee.packet.PacketD0DisplayScoreboard; -import net.md_5.bungee.packet.PacketD1Team; -import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketFFKick; -import net.md_5.bungee.packet.PacketHandler; +import net.md_5.bungee.protocol.packet.Packet0KeepAlive; +import net.md_5.bungee.protocol.packet.Packet3Chat; +import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective; +import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore; +import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard; +import net.md_5.bungee.protocol.packet.PacketD1Team; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.PacketHandler; @RequiredArgsConstructor public class DownstreamBridge extends PacketHandler 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 368efffd..acb409cb 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 @@ -34,15 +34,15 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; import net.md_5.bungee.netty.PacketDecoder; -import net.md_5.bungee.packet.Packet1Login; -import net.md_5.bungee.packet.Packet2Handshake; -import net.md_5.bungee.packet.PacketCDClientStatus; -import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketFCEncryptionResponse; -import net.md_5.bungee.packet.PacketFDEncryptionRequest; -import net.md_5.bungee.packet.PacketFEPing; -import net.md_5.bungee.packet.PacketFFKick; -import net.md_5.bungee.packet.PacketHandler; +import net.md_5.bungee.protocol.packet.Packet1Login; +import net.md_5.bungee.protocol.packet.Packet2Handshake; +import net.md_5.bungee.protocol.packet.PacketCDClientStatus; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse; +import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; +import net.md_5.bungee.protocol.packet.PacketFEPing; +import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.PacketHandler; import net.md_5.bungee.protocol.PacketDefinitions; @RequiredArgsConstructor 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 61c87d0c..515e7f76 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 @@ -5,8 +5,8 @@ import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.netty.ChannelWrapper; -import net.md_5.bungee.packet.PacketFFKick; -import net.md_5.bungee.packet.PacketHandler; +import net.md_5.bungee.protocol.packet.PacketFFKick; +import net.md_5.bungee.protocol.packet.PacketHandler; @RequiredArgsConstructor public class PingHandler extends PacketHandler 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 07cb99fd..4f7d6352 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -10,11 +10,11 @@ import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.netty.ChannelWrapper; -import net.md_5.bungee.packet.Packet0KeepAlive; -import net.md_5.bungee.packet.Packet3Chat; -import net.md_5.bungee.packet.PacketCCSettings; -import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketHandler; +import net.md_5.bungee.protocol.packet.Packet0KeepAlive; +import net.md_5.bungee.protocol.packet.Packet3Chat; +import net.md_5.bungee.protocol.packet.PacketCCSettings; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; +import net.md_5.bungee.protocol.packet.PacketHandler; public class UpstreamBridge extends PacketHandler { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java b/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java index e17e7dea..ff426543 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java @@ -4,7 +4,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -import net.md_5.bungee.packet.DefinedPacket; +import net.md_5.bungee.protocol.packet.DefinedPacket; @ChannelHandler.Sharable public class DefinedPacketEncoder extends MessageToByteEncoder 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 9e311d58..fae8a485 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 @@ -8,8 +8,8 @@ import java.io.IOException; import java.util.logging.Level; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.connection.CancelSendSignal; -import net.md_5.bungee.packet.DefinedPacket; -import net.md_5.bungee.packet.PacketHandler; +import net.md_5.bungee.protocol.packet.DefinedPacket; +import net.md_5.bungee.protocol.packet.PacketHandler; /** * This class is a primitive wrapper for {@link PacketHandler} instances tied to diff --git a/proxy/src/main/java/net/md_5/bungee/packet/DefinedPacket.java b/proxy/src/main/java/net/md_5/bungee/packet/DefinedPacket.java deleted file mode 100644 index e30a5fc3..00000000 --- a/proxy/src/main/java/net/md_5/bungee/packet/DefinedPacket.java +++ /dev/null @@ -1,240 +0,0 @@ -package net.md_5.bungee.packet; - -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.DataOutput; -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import lombok.Delegate; -import net.md_5.bungee.Util; - -/** - * This class represents a packet which has been given a special definition. All - * subclasses can read and write to the backing byte array which can be - * retrieved via the {@link #getPacket()} method. - */ -public abstract class DefinedPacket implements DataOutput -{ - - private static interface Overriden - { - - void readUTF(); - - void writeUTF(String s); - } - private ByteArrayInputStream byteStream; - private DataInputStream in; - @Delegate(excludes = Overriden.class) - private ByteArrayDataOutput out; - private byte[] buf; - - public DefinedPacket(int id, byte[] buf) - { - byteStream = new ByteArrayInputStream( buf ); - in = new DataInputStream( byteStream ); - if ( readUnsignedByte() != id ) - { - throw new IllegalArgumentException( "Wasn't expecting packet id " + Util.hex( id ) ); - } - this.buf = buf; - } - - public DefinedPacket(int id) - { - out = ByteStreams.newDataOutput(); - writeByte( id ); - } - - /** - * Gets the bytes that make up this packet. - * - * @return the bytes which make up this packet, either the original byte - * array or the newly written one. - */ - public byte[] getPacket() - { - return buf == null ? buf = out.toByteArray() : buf; - } - - @Override - public void writeUTF(String s) - { - writeShort( s.length() ); - writeChars( s ); - } - - public String readUTF() - { - short len = readShort(); - char[] chars = new char[ len ]; - for ( int i = 0; i < len; i++ ) - { - chars[i] = this.readChar(); - } - return new String( chars ); - } - - public void writeArray(byte[] b) - { - writeShort( b.length ); - write( b ); - } - - public byte[] readArray() - { - short len = readShort(); - byte[] ret = new byte[ len ]; - readFully( ret ); - return ret; - } - - public final int available() - { - return byteStream.available(); - } - - public final void readFully(byte b[]) - { - try - { - in.readFully( b ); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public final boolean readBoolean() - { - try - { - return in.readBoolean(); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public final byte readByte() - { - try - { - return in.readByte(); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public final int readUnsignedByte() - { - try - { - return in.readUnsignedByte(); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public final short readShort() - { - try - { - return in.readShort(); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public final char readChar() - { - try - { - return in.readChar(); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public final int readInt() - { - try - { - return in.readInt(); - } catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - @Override - public abstract boolean equals(Object obj); - - @Override - public abstract int hashCode(); - - @Override - public abstract String toString(); - - public abstract void handle(PacketHandler handler) throws Exception; - @SuppressWarnings("unchecked") - private static Class[] classes = new Class[ 256 ]; - @SuppressWarnings("unchecked") - private static Constructor[] consructors = new Constructor[ 256 ]; - - public static DefinedPacket packet(byte[] buf) - { - int id = buf[0] & 0xFF; - Class clazz = classes[id]; - DefinedPacket ret = null; - if ( clazz != null ) - { - try - { - Constructor constructor = consructors[id]; - if ( constructor == null ) - { - constructor = clazz.getDeclaredConstructor( byte[].class ); - consructors[id] = constructor; - } - - if ( constructor != null ) - { - ret = constructor.newInstance( buf ); - } - } catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex ) - { - } - } - - return ret; - } - - static - { - classes[0x00] = Packet0KeepAlive.class; - classes[0x01] = Packet1Login.class; - classes[0x02] = Packet2Handshake.class; - classes[0x03] = Packet3Chat.class; - classes[0x09] = Packet9Respawn.class; - classes[0xC9] = PacketC9PlayerListItem.class; - classes[0xCC] = PacketCCSettings.class; - classes[0xCD] = PacketCDClientStatus.class; - classes[0xCE] = PacketCEScoreboardObjective.class; - classes[0xCF] = PacketCFScoreboardScore.class; - classes[0xD0] = PacketD0DisplayScoreboard.class; - classes[0xD1] = PacketD1Team.class; - classes[0xFA] = PacketFAPluginMessage.class; - classes[0xFC] = PacketFCEncryptionResponse.class; - classes[0xFD] = PacketFDEncryptionRequest.class; - classes[0xFE] = PacketFEPing.class; - classes[0xFF] = PacketFFKick.class; - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet0KeepAlive.java b/proxy/src/main/java/net/md_5/bungee/packet/Packet0KeepAlive.java deleted file mode 100644 index 2a0a93d8..00000000 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet0KeepAlive.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.md_5.bungee.packet; - -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@ToString -@EqualsAndHashCode(callSuper = false) -public class Packet0KeepAlive extends DefinedPacket -{ - - public int id; - - Packet0KeepAlive(byte[] buf) - { - super( 0x00, buf ); - id = readInt(); - } - - @Override - public void handle(PacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java b/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java deleted file mode 100644 index a38d0be1..00000000 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.md_5.bungee.packet; - -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@ToString -@EqualsAndHashCode(callSuper = false) -public class Packet1Login extends DefinedPacket -{ - - public int entityId; - public String levelType; - public byte gameMode; - public int dimension; - public byte difficulty; - public byte unused; - public byte maxPlayers; - - public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers, boolean forge) - { - super( 0x01 ); - writeInt( entityId ); - writeUTF( levelType ); - writeByte( gameMode ); - if ( forge ) - { - writeInt( dimension ); - } else - { - writeByte( dimension ); - } - writeByte( difficulty ); - writeByte( unused ); - writeByte( maxPlayers ); - this.entityId = entityId; - this.levelType = levelType; - this.gameMode = gameMode; - this.dimension = dimension; - this.difficulty = difficulty; - this.unused = unused; - this.maxPlayers = maxPlayers; - } - - Packet1Login(byte[] buf) - { - super( 0x01, buf ); - this.entityId = readInt(); - this.levelType = readUTF(); - this.gameMode = readByte(); - if ( available() == 4 ) - { - this.dimension = readByte(); - } else if ( available() == 7 ) - { - this.dimension = readInt(); - } else - { - throw new IllegalStateException(); - } - this.difficulty = readByte(); - this.unused = readByte(); - this.maxPlayers = readByte(); - } - - @Override - public void handle(PacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/Global.java b/proxy/src/main/java/net/md_5/bungee/tablist/Global.java index 08906487..dad53566 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/Global.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/Global.java @@ -7,7 +7,7 @@ import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.TabListHandler; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; public class Global implements TabListHandler { diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java index ceeeed0a..f17843a5 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java @@ -4,7 +4,7 @@ import gnu.trove.map.TObjectIntMap; import gnu.trove.map.hash.TObjectIntHashMap; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; public class GlobalPing extends Global { diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java b/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java index 73eaee37..af9045e9 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java @@ -7,7 +7,7 @@ import java.util.Collection; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.TabListHandler; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.packet.PacketC9PlayerListItem; +import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem; public class ServerUnique implements TabListHandler {