From bcaafc206fca0ff8ae11a5cda109a2a2df5570a8 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 9 Mar 2013 10:10:36 +1100 Subject: [PATCH] Advancing further in the login process. --- .../java/net/md_5/bungee/protocol/netty/BulkChunk.java | 2 +- .../java/net/md_5/bungee/protocol/netty/Instruction.java | 5 ----- .../main/java/net/md_5/bungee/protocol/netty/Item.java | 2 +- .../main/java/net/md_5/bungee/protocol/netty/Jump.java | 2 +- .../java/net/md_5/bungee/protocol/netty/MetaData.java | 2 +- .../net/md_5/bungee/protocol/netty/OptionalMotion.java | 2 +- .../md_5/bungee/protocol/netty/UnsignedShortByte.java | 2 +- .../java/net/md_5/bungee/connection/InitialHandler.java | 2 +- .../src/main/java/net/md_5/bungee/netty/HandlerBoss.java | 2 +- .../main/java/net/md_5/bungee/netty/PacketDecoder.java | 9 ++++++--- 10 files changed, 14 insertions(+), 16 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/BulkChunk.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/BulkChunk.java index 37499018..54fee12d 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/BulkChunk.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/BulkChunk.java @@ -12,6 +12,6 @@ public class BulkChunk extends Instruction short count = in.readShort(); int size = in.readInt(); in.readBoolean(); - skip( in, size + count * 12 ); + in.skipBytes( size + count * 12 ); } } 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 6b84dc59..7340055c 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 @@ -28,9 +28,4 @@ abstract class Instruction static final Instruction BYTE_INT = new ByteHeader( INT ); abstract void read(ByteBuf in) throws IOException; - - final void skip(ByteBuf in, int len) throws IOException - { - in.readerIndex( in.readerIndex() + len ); - } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Item.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Item.java index 5026b521..529be2f3 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Item.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Item.java @@ -12,7 +12,7 @@ class Item extends Instruction short type = in.readShort(); if ( type >= 0 ) { - skip( in, 3 ); + in.skipBytes( 3 ); SHORT_BYTE.read( in ); } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Jump.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Jump.java index 0c9ed2a4..aca0d763 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/Jump.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/Jump.java @@ -20,6 +20,6 @@ class Jump extends Instruction @Override void read(ByteBuf in) throws IOException { - skip( in, len ); + in.skipBytes( len ); } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/MetaData.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/MetaData.java index 7ebc3c16..730f3686 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/MetaData.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/MetaData.java @@ -34,7 +34,7 @@ class MetaData extends Instruction ITEM.read( in ); break; case 6: - skip( in, 12 ); // int, int, int + in.skipBytes( 12 ); // int, int, int break; default: throw new IllegalArgumentException( "Unknown metadata type " + type ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/OptionalMotion.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/OptionalMotion.java index 7e304007..4e618360 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/OptionalMotion.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/OptionalMotion.java @@ -12,7 +12,7 @@ class OptionalMotion extends Instruction int data = in.readInt(); if ( data > 0 ) { - skip( in, 6 ); + in.skipBytes( 6 ); } } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/netty/UnsignedShortByte.java b/protocol/src/main/java/net/md_5/bungee/protocol/netty/UnsignedShortByte.java index 2b409884..1dea256b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/netty/UnsignedShortByte.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/netty/UnsignedShortByte.java @@ -10,6 +10,6 @@ class UnsignedShortByte extends Instruction void read(ByteBuf in) throws IOException { int size = in.readUnsignedShort(); - skip( in, size ); + in.skipBytes( size ); } } 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 a8ee0278..1cad4c47 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 @@ -179,8 +179,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection ch.write( new PacketFCEncryptionResponse() ); - Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, shared ); Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, shared ); + Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, shared ); ch.pipeline().addBefore( "decoder", "cipher", new CipherCodec( encrypt, decrypt ) ); thisState = InitialHandler.State.LOGIN; 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 269ae264..bce51eaa 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 @@ -60,7 +60,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - super.exceptionCaught( ctx, cause ); + cause.printStackTrace(); if ( ctx.channel().isActive() ) { ctx.close(); 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 0f7e2d0f..6d12c2d7 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 @@ -3,9 +3,11 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ReplayingDecoder; +import java.io.IOException; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import net.md_5.bungee.Util; import net.md_5.bungee.protocol.netty.PacketReader; /** @@ -28,9 +30,10 @@ public class PacketDecoder extends ReplayingDecoder protected ByteBuf decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { int startIndex = in.readerIndex(); + PacketReader.readPacket( in, protocol ); - ByteBuf readPacket = in.copy( startIndex, in.readerIndex() - startIndex ); - System.out.println( readPacket ); - return readPacket; + + System.out.println( Util.hex( in.getUnsignedByte( 0 ) ) ); + return in.copy( startIndex, in.readerIndex() - startIndex ); } }