diff --git a/pom.xml b/pom.xml index 2b9a2e4b6..fc5c3e48a 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.0 + 2.5.1 1.7 1.7 diff --git a/protocol/pom.xml b/protocol/pom.xml index 6b972fe51..e624fdcf7 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -21,8 +21,9 @@ io.netty - netty-buffer - 4.0.0.Beta2 + + netty-all + 4.0.0.Beta3-SNAPSHOT provided diff --git a/proxy/pom.xml b/proxy/pom.xml index 577546fc6..8f718f1a6 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -22,7 +22,7 @@ io.netty netty-all - 4.0.0.Beta2 + 4.0.0.Beta3-SNAPSHOT net.md-5 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 40995a8d6..3bdab4b90 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -79,7 +79,7 @@ public class ServerConnector extends PacketHandler login.difficulty, login.unused, (byte) user.getPendingConnection().getListener().getTabListSize() ); - ch.write( modLogin ); + user.ch.write( modLogin ); ch.write( BungeeCord.getInstance().registerChannels() ); } else { @@ -88,15 +88,16 @@ public class ServerConnector extends PacketHandler user.sendPacket( Packet9Respawn.DIM2_SWITCH ); user.serverEntityId = login.entityId; - ch.write( new Packet9Respawn( login.dimension, login.difficulty, login.gameMode, (short) 256, login.levelType ) ); + user.ch.write( new Packet9Respawn( login.dimension, login.difficulty, login.gameMode, (short) 256, login.levelType ) ); - // Add to new server - target.addPlayer( user ); // Remove from old servers user.getServer().disconnect( "Quitting" ); user.getServer().getInfo().removePlayer( user ); } + // Add to new server + target.addPlayer( user ); + ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) ); } 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 d426690b6..1922e4442 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 @@ -7,6 +7,7 @@ import io.netty.buffer.ByteBuf; import lombok.RequiredArgsConstructor; 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; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -30,6 +31,8 @@ public class DownstreamBridge extends PacketHandler public void handle(ByteBuf buf) throws Exception { EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId ); + System.out.println( "Got packet from server: " + Util.hex( buf.getUnsignedByte( 0 ) ) ); + System.out.println( buf ); con.ch.write( buf ); } 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 6d8335c53..c4b76fb40 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 @@ -92,18 +92,18 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void handle(PacketFEPing ping) throws Exception { - ServerPing pingevent = new ServerPing( BungeeCord.PROTOCOL_VERSION, BungeeCord.GAME_VERSION, + ServerPing response = new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), listener.getMotd(), bungee.getPlayers().size(), listener.getMaxPlayers() ); - pingevent = bungee.getPluginManager().callEvent( new ProxyPingEvent( this, pingevent ) ).getResponse(); + response = bungee.getPluginManager().callEvent( new ProxyPingEvent( this, response ) ).getResponse(); - String response = ChatColor.COLOR_CHAR + "1" - + "\00" + pingevent.getProtocolVersion() - + "\00" + pingevent.getGameVersion() - + "\00" + pingevent.getMotd() - + "\00" + pingevent.getCurrentPlayers() - + "\00" + pingevent.getMaxPlayers(); - disconnect( response ); + String kickMessage = ChatColor.DARK_BLUE + + "\00" + response.getProtocolVersion() + + "\00" + response.getGameVersion() + + "\00" + response.getMotd() + + "\00" + response.getCurrentPlayers() + + "\00" + response.getMaxPlayers(); + disconnect( kickMessage ); } @Override @@ -181,7 +181,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, shared ); Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, shared ); ch.write( new PacketFCEncryptionResponse() ); - ch.config().setAutoRead( false ); ch.pipeline().addBefore( "decoder", "cipher", new CipherCodec( encrypt, decrypt ) ); thisState = InitialHandler.State.LOGIN; @@ -205,6 +204,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection userCon.connect( server ); thisState = State.FINISHED; + throw new CancelSendSignal(); } @Override 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 3ad9461ff..6f2dd6adb 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 @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import lombok.RequiredArgsConstructor; 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; import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.PluginMessageEvent; @@ -24,18 +25,13 @@ public class UpstreamBridge extends PacketHandler public void handle(ByteBuf buf) throws Exception { EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId ); + System.out.println( "Got packet from client: " + Util.hex( buf.getUnsignedByte( 0 ) ) ); if ( con.getServer() != null ) { con.getServer().getCh().write( buf ); } } - @Override - public void handle(Packet1Login login) throws Exception - { - super.handle( login ); //To change body of generated methods, choose Tools | Templates. - } - @Override public void handle(Packet0KeepAlive alive) throws Exception { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java b/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java index 530b455e6..565ee1574 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/CipherCodec.java @@ -18,7 +18,6 @@ public class CipherCodec extends ByteToByteCodec private Cipher encrypt; private Cipher decrypt; - private ByteBuf heapOut; public CipherCodec(Cipher encrypt, Cipher decrypt) { @@ -29,13 +28,7 @@ public class CipherCodec extends ByteToByteCodec @Override public void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { - if ( heapOut == null ) - { - heapOut = ctx.alloc().heapBuffer(); - } - cipher( encrypt, in, heapOut ); - out.writeBytes( heapOut ); - heapOut.discardSomeReadBytes(); + cipher( encrypt, in, out ); } @Override @@ -44,25 +37,6 @@ public class CipherCodec extends ByteToByteCodec cipher( decrypt, in, out ); } - @Override - public void freeInboundBuffer(ChannelHandlerContext ctx) throws Exception - { - super.freeInboundBuffer( ctx ); - decrypt = null; - } - - @Override - public void freeOutboundBuffer(ChannelHandlerContext ctx) throws Exception - { - super.freeOutboundBuffer( ctx ); - if ( heapOut != null ) - { - heapOut.release(); - heapOut = null; - } - encrypt = null; - } - private void cipher(Cipher cipher, ByteBuf in, ByteBuf out) throws ShortBufferException { int available = in.readableBytes(); @@ -71,8 +45,7 @@ public class CipherCodec extends ByteToByteCodec { out.capacity( outputSize ); } - // TODO: Try and make this use out.nioBuffer() - int processed = cipher.update( in.array(), in.arrayOffset() + in.readerIndex(), available, out.array(), out.arrayOffset() + out.writerIndex() ); + int processed = cipher.update( in.nioBuffer(), out.nioBuffer( out.readerIndex(), outputSize ) ); in.readerIndex( in.readerIndex() + processed ); out.writerIndex( out.writerIndex() + processed ); } 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 22728baf3..9e97f9e2e 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 @@ -43,7 +43,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter } @Override - protected void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception + public void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { if ( handler != null && ctx.channel().isActive() ) { 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 6d12c2d76..696f01485 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,11 +3,9 @@ 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; /** @@ -30,10 +28,7 @@ public class PacketDecoder extends ReplayingDecoder protected ByteBuf decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { int startIndex = in.readerIndex(); - PacketReader.readPacket( in, protocol ); - - System.out.println( Util.hex( in.getUnsignedByte( 0 ) ) ); return in.copy( startIndex, in.readerIndex() - startIndex ); } } 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 d1977f56a..f5f7e4439 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 @@ -2,6 +2,7 @@ package net.md_5.bungee.netty; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; +import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelException; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; @@ -32,6 +33,7 @@ public class PipelineUtils { BASE.initChannel( ch ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); + ch.config().setDefaultHandlerByteBufType( ChannelConfig.ChannelHandlerByteBufType.HEAP ); } }; public static final ChannelInitializer CLIENT = new ChannelInitializer() 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 index f4a4e44cc..421fe87dc 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/DefinedPacket.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/DefinedPacket.java @@ -104,7 +104,11 @@ public abstract class DefinedPacket implements ByteBuf if ( constructor != null ) { + buf.markReaderIndex(); + buf.markWriterIndex(); ret = constructor.newInstance( buf ); + buf.resetReaderIndex(); + buf.resetWriterIndex(); } } catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex ) {