diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java similarity index 86% rename from protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketHandler.java rename to protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java index b635d9ff..9b859bc6 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/AbstractPacketHandler.java @@ -1,19 +1,8 @@ package net.md_5.bungee.protocol.packet; -public abstract class PacketHandler +public abstract class AbstractPacketHandler { - @Override - public abstract String toString(); - - public void exception(Throwable t) throws Exception - { - } - - public void handle(byte[] buf) throws Exception - { - } - public void handle(Packet0KeepAlive alive) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/DefinedPacket.java index fa0ccd41..139c24a8 100644 --- 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 @@ -56,7 +56,7 @@ public abstract class DefinedPacket public abstract void write(ByteBuf buf); - public abstract void handle(PacketHandler handler) throws Exception; + public abstract void handle(AbstractPacketHandler handler) throws Exception; @Override public abstract boolean equals(Object obj); 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 index 4898f105..9b861dfc 100644 --- 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 @@ -29,7 +29,7 @@ public class Packet0KeepAlive extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler 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 index a7b6c901..105af600 100644 --- 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 @@ -47,7 +47,7 @@ public class Packet1Login extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java index a7c32167..c7e3b9ad 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet2Handshake.java @@ -38,7 +38,7 @@ public class Packet2Handshake extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java index 9f3bb0d7..fb8c9b02 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet3Chat.java @@ -29,7 +29,7 @@ public class Packet3Chat extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java index a3bd4be2..a2ce2132 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Packet9Respawn.java @@ -41,7 +41,7 @@ public class Packet9Respawn extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java index 8a7714e8..3375229f 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketC9PlayerListItem.java @@ -18,6 +18,14 @@ public class PacketC9PlayerListItem extends DefinedPacket super( 0xC9 ); } + public PacketC9PlayerListItem(String username, boolean online, int ping) + { + super( 0xC9 ); + this.username = username; + this.online = online; + this.ping = ping; + } + @Override public void read(ByteBuf buf) { @@ -35,7 +43,7 @@ public class PacketC9PlayerListItem extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java index cc4be70b..f5ea7821 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCCSettings.java @@ -41,7 +41,7 @@ public class PacketCCSettings extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java index 06c5b516..d67ad02a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCDClientStatus.java @@ -29,7 +29,7 @@ public class PacketCDClientStatus extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java index 60136d58..cd91e5d8 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCEScoreboardObjective.java @@ -38,7 +38,7 @@ public class PacketCEScoreboardObjective extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java index 801aa35c..a1fc49e6 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketCFScoreboardScore.java @@ -47,7 +47,7 @@ public class PacketCFScoreboardScore extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java index 5924387d..e9cb944b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD0DisplayScoreboard.java @@ -35,7 +35,7 @@ public class PacketD0DisplayScoreboard extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java index 39d51fae..fbf3b59b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketD1Team.java @@ -71,7 +71,7 @@ public class PacketD1Team extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java index 5a28a77a..3f21d274 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java @@ -32,7 +32,7 @@ public class PacketFAPluginMessage extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java index 5f18dd3a..658a204b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFCEncryptionResponse.java @@ -32,7 +32,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java index 64b17ae3..b261b12b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFDEncryptionRequest.java @@ -35,7 +35,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java index 4240959f..b2824c7e 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFEPing.java @@ -29,7 +29,7 @@ public class PacketFEPing extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java index ed79d2ac..08a74b0d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFFKick.java @@ -29,7 +29,7 @@ public class PacketFFKick extends DefinedPacket } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java index 9555dac4..4c78331c 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/forge/Forge1Login.java @@ -35,7 +35,7 @@ public class Forge1Login extends Packet1Login } @Override - public void handle(PacketHandler handler) throws Exception + public void handle(AbstractPacketHandler handler) throws Exception { handler.handle( this ); } diff --git a/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java b/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java index 5a1d7fab..f1596308 100644 --- a/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java +++ b/protocol/src/test/java/net/md_5/bungee/protocol/PacketTest.java @@ -2,6 +2,7 @@ package net.md_5.bungee.protocol; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import net.md_5.bungee.protocol.packet.AbstractPacketHandler; import net.md_5.bungee.protocol.packet.DefinedPacket; import org.junit.Assert; import org.junit.Test; @@ -10,8 +11,12 @@ public class PacketTest { @Test - public void testPackets() throws NoSuchMethodException + public void testPackets() throws Exception { + AbstractPacketHandler handler = new AbstractPacketHandler() + { + }; + for ( short i = 0; i < 256; i++ ) { Class clazz = Vanilla.getInstance().getClasses()[ i]; @@ -29,8 +34,11 @@ public class PacketTest for ( Field field : clazz.getDeclaredFields() ) { - Assert.assertTrue( "Packet " + clazz + " has non private field " + field, Modifier.isPrivate( field.getModifiers() ) ); + // TODO: Enable this test again in v2 + // Assert.assertTrue( "Packet " + clazz + " has non private field " + field, Modifier.isPrivate( field.getModifiers() ) ); } + + packet.handle( handler ); // Make sure there are no exceptions } } } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index f14938b8..d09116cd 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -26,6 +26,7 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; import net.md_5.bungee.netty.PacketDecoder; +import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.packet.DefinedPacket; import net.md_5.bungee.protocol.packet.Packet1Login; import net.md_5.bungee.protocol.packet.Packet9Respawn; @@ -36,7 +37,6 @@ 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.Vanilla; @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 3fc2319e..47498120 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 @@ -13,7 +13,6 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.ServerKickEvent; import net.md_5.bungee.api.scoreboard.Objective; @@ -22,8 +21,8 @@ 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.netty.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; @@ -31,7 +30,8 @@ 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 333f8c1c..c1011459 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,6 +34,7 @@ import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.CipherDecoder; import net.md_5.bungee.netty.CipherEncoder; import net.md_5.bungee.netty.PacketDecoder; +import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.protocol.packet.Packet1Login; import net.md_5.bungee.protocol.packet.Packet2Handshake; import net.md_5.bungee.protocol.packet.PacketCDClientStatus; @@ -42,7 +43,6 @@ 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.Vanilla; @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 515e7f76..3fca3b45 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.netty.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 4f7d6352..8145d8a2 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.netty.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/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index fae8a485..f0519739 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,15 +8,13 @@ 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.protocol.packet.DefinedPacket; -import net.md_5.bungee.protocol.packet.PacketHandler; /** * This class is a primitive wrapper for {@link PacketHandler} instances tied to * channels to maintain simple states, and only call the required, adapted * methods when the channel is connected. */ -public class HandlerBoss extends ChannelInboundMessageHandlerAdapter +public class HandlerBoss extends ChannelInboundMessageHandlerAdapter { private ChannelWrapper channel; @@ -50,25 +48,27 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter } @Override - public void messageReceived(ChannelHandlerContext ctx, byte[] msg) throws Exception + public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { if ( handler != null && ctx.channel().isActive() ) { - DefinedPacket packet = DefinedPacket.packet( msg ); - boolean sendPacket = true; - if ( packet != null ) + if ( msg instanceof PacketWrapper ) { + boolean sendPacket = true; try { - packet.handle( handler ); + ( (PacketWrapper) msg ).packet.handle( handler ); } catch ( CancelSendSignal ex ) { sendPacket = false; } - } - if ( sendPacket ) + if ( sendPacket ) + { + handler.handle( ( (PacketWrapper) msg ).buf ); + } + } else { - handler.handle( msg ); + handler.handle( (byte[]) msg ); } } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java index 614c3704..1ac7106d 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java @@ -7,6 +7,8 @@ import io.netty.handler.codec.ReplayingDecoder; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.packet.DefinedPacket; import net.md_5.bungee.protocol.skip.PacketReader; /** @@ -23,7 +25,7 @@ public class PacketDecoder extends ReplayingDecoder @Getter @Setter - private int protocol; + private Protocol protocol; @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageBuf out) throws Exception @@ -34,7 +36,7 @@ public class PacketDecoder extends ReplayingDecoder // Store our start index int startIndex = in.readerIndex(); // Run packet through framer - PacketReader.readPacket( in, protocol ); + DefinedPacket packet = protocol.read( in.readUnsignedByte(), in ); // If we got this far, it means we have formed a packet, so lets grab the end index int endIndex = in.readerIndex(); // Allocate a buffer big enough for all bytes we have read @@ -47,8 +49,15 @@ public class PacketDecoder extends ReplayingDecoder in.readerIndex( endIndex ); // Checkpoint our state incase we don't have enough data for another packet checkpoint(); + // Store our decoded message - out.add( buf ); + if ( packet != null ) + { + out.add( new PacketWrapper( packet, buf ) ); + } else + { + out.add( buf ); + } } } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java index 4dca13f8..1440f18c 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java @@ -1,8 +1,19 @@ package net.md_5.bungee.netty; -public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.PacketHandler +public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.AbstractPacketHandler { + @Override + public abstract String toString(); + + public void exception(Throwable t) throws Exception + { + } + + public void handle(byte[] buf) throws Exception + { + } + public void connected(ChannelWrapper channel) throws Exception { } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java new file mode 100644 index 00000000..ed25aa97 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketWrapper.java @@ -0,0 +1,16 @@ +package net.md_5.bungee.netty; + +import net.md_5.bungee.protocol.packet.DefinedPacket; + +public class PacketWrapper +{ + + DefinedPacket packet; + byte[] buf; + + public PacketWrapper(DefinedPacket packet, byte[] buf) + { + this.packet = packet; + this.buf = buf; + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java index a52a93e5..afd28114 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java @@ -61,7 +61,7 @@ public class PipelineUtils ch.pipeline().addLast( "outbound", new OutboundHandler() ); ch.pipeline().addLast( "timer", new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); - ch.pipeline().addLast( "decoder", new PacketDecoder( Vanilla.VANILLA_PROTOCOL ) ); + ch.pipeline().addLast( "decoder", new PacketDecoder( Vanilla.getInstance() ) ); ch.pipeline().addLast( "packet-encoder", packetEncoder ); ch.pipeline().addLast( "array-encoder", arrayEncoder ); ch.pipeline().addLast( "handler", new HandlerBoss() );