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 1e7929d6..ce31f304 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -14,6 +14,7 @@ import net.md_5.bungee.packet.PacketFFKick; public class ServerConnection implements Server { + @Getter private final Channel ch; @Getter private final ServerInfo info; 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 f7e98127..ebe5de79 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -7,8 +7,11 @@ import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.event.ServerConnectedEvent; +import net.md_5.bungee.connection.DownstreamBridge; +import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.Packet1Login; +import net.md_5.bungee.packet.Packet2Handshake; import net.md_5.bungee.packet.Packet9Respawn; import net.md_5.bungee.packet.PacketCDClientStatus; import net.md_5.bungee.packet.PacketFDEncryptionRequest; @@ -35,7 +38,8 @@ public class ServerConnector extends PacketHandler public void connected(Channel channel) throws Exception { this.ch = channel; - channel.write( user.handshake ); + // TODO: Fix this crap + channel.write( new Packet2Handshake( user.handshake.procolVersion, user.handshake.username, user.handshake.host, user.handshake.port ) ); channel.write( PacketCDClientStatus.CLIENT_LOGIN ); } @@ -91,6 +95,8 @@ public class ServerConnector extends PacketHandler user.getServer().disconnect( "Quitting" ); user.getServer().getInfo().removePlayer( user ); } + + ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) ); } thisState = State.FINISHED; 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 f6095cc7..36cf93e3 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -33,7 +33,7 @@ public final class UserConnection implements ProxiedPlayer public final Packet2Handshake handshake; private final ProxyServer bungee; - private final Channel ch; + public final Channel ch; final Packet1Login forgeLogin; final List loginMessages; public Queue packetQueue = new ConcurrentLinkedQueue<>(); @@ -69,7 +69,8 @@ public final class UserConnection implements ProxiedPlayer this.pendingConnection = pendingConnection; this.forgeLogin = forgeLogin; this.loginMessages = loginMessages; - + this.name = handshake.username; + this.displayName = name; Collection g = bungee.getConfigurationAdapter().getGroups( name ); for ( String s : g ) 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 98c749af..d426690b 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 @@ -3,7 +3,9 @@ package net.md_5.bungee.connection; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; +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.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -24,6 +26,13 @@ public class DownstreamBridge extends PacketHandler private final ProxyServer bungee; private final UserConnection con; + @Override + public void handle(ByteBuf buf) throws Exception + { + EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId ); + con.ch.write( buf ); + } + @Override public void handle(Packet0KeepAlive alive) throws Exception { 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 1cad4c47..65195ad2 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 @@ -177,10 +177,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection } } - ch.write( new PacketFCEncryptionResponse() ); - 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; 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 e8c9eefc..04e5e8c9 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -1,6 +1,8 @@ package net.md_5.bungee.connection; +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.api.ProxyServer; import net.md_5.bungee.api.event.ChatEvent; @@ -17,6 +19,13 @@ public class UpstreamBridge extends PacketHandler private final ProxyServer bungee; private final UserConnection con; + @Override + public void handle(ByteBuf buf) throws Exception + { + EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId ); + con.getServer().getCh().write( buf ); + } + @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 9fd54eac..530b455e 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 @@ -33,9 +33,6 @@ public class CipherCodec extends ByteToByteCodec { heapOut = ctx.alloc().heapBuffer(); } - System.out.println( "e) in: " + in ); - System.out.println( "e) heapOut: " + heapOut ); - System.out.println( "e) out: " + out ); cipher( encrypt, in, heapOut ); out.writeBytes( heapOut ); heapOut.discardSomeReadBytes(); @@ -44,9 +41,6 @@ public class CipherCodec extends ByteToByteCodec @Override public void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { - System.out.println( "d) in: " + in ); - System.out.println( "d) heapOut: " + heapOut ); - System.out.println( "d) out: " + out ); cipher( decrypt, in, out ); } 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 b27d0f52..9292bc5e 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 @@ -51,17 +51,15 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter if ( packet != null ) { packet.handle( handler ); - } else - { - handler.handle( msg ); } + handler.handle( msg ); } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - System.out.println( handler + " " + Util.exception( cause ) ); + cause.printStackTrace(); if ( ctx.channel().isActive() ) { ctx.close(); 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 index 4b0ba51e..e8e77623 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet0KeepAlive.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/Packet0KeepAlive.java @@ -11,7 +11,7 @@ public class Packet0KeepAlive extends DefinedPacket public int id; - public Packet0KeepAlive(ByteBuf buf) + Packet0KeepAlive(ByteBuf buf) { super( 0x00, buf ); id = readInt(); 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 index b1a4ec02..533cd4db 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java @@ -29,7 +29,7 @@ public class Packet1Login extends DefinedPacket writeByte( maxPlayers ); } - public Packet1Login(ByteBuf buf) + Packet1Login(ByteBuf buf) { super( 0x01, buf ); this.entityId = readInt(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java b/proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java index e5a54c59..2a494926 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/Packet2Handshake.java @@ -23,7 +23,7 @@ public class Packet2Handshake extends DefinedPacket writeInt( port ); } - public Packet2Handshake(ByteBuf buf) + Packet2Handshake(ByteBuf buf) { super( 0x02, buf ); this.procolVersion = readByte(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java b/proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java index 0791b68e..7ad898df 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/Packet3Chat.java @@ -17,7 +17,7 @@ public class Packet3Chat extends DefinedPacket writeString( message ); } - public Packet3Chat(ByteBuf buf) + Packet3Chat(ByteBuf buf) { super( 0x03, buf ); this.message = readString(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java b/proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java index 66231a1f..a086d8e6 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/Packet9Respawn.java @@ -27,7 +27,7 @@ public class Packet9Respawn extends DefinedPacket writeString( levelType ); } - public Packet9Respawn(ByteBuf buf) + Packet9Respawn(ByteBuf buf) { super( 0x09, buf ); this.dimension = readInt(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java index 655b31de..13ba4694 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketC9PlayerListItem.java @@ -13,7 +13,7 @@ public class PacketC9PlayerListItem extends DefinedPacket public boolean online; public int ping; - public PacketC9PlayerListItem(ByteBuf buf) + PacketC9PlayerListItem(ByteBuf buf) { super( 0xC9, buf ); username = readString(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java index 47887656..9773bc31 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketCDClientStatus.java @@ -22,7 +22,7 @@ public class PacketCDClientStatus extends DefinedPacket writeByte( payload ); } - public PacketCDClientStatus(ByteBuf buf) + PacketCDClientStatus(ByteBuf buf) { super( 0xCD, buf ); } diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java index f12b0fb0..d7cc5ee0 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketFAPluginMessage.java @@ -21,7 +21,7 @@ public class PacketFAPluginMessage extends DefinedPacket this.data = data; } - public PacketFAPluginMessage(ByteBuf buf) + PacketFAPluginMessage(ByteBuf buf) { super( 0xFA, buf ); this.tag = readString(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java index 6670e6e5..38f885a8 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketFCEncryptionResponse.java @@ -26,7 +26,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket writeArray( verifyToken ); } - public PacketFCEncryptionResponse(ByteBuf buf) + PacketFCEncryptionResponse(ByteBuf buf) { super( 0xFC, buf ); this.sharedSecret = readArray(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java index fa6e63f2..a6df1164 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketFDEncryptionRequest.java @@ -24,7 +24,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket this.verifyToken = verifyToken; } - public PacketFDEncryptionRequest(ByteBuf buf) + PacketFDEncryptionRequest(ByteBuf buf) { super( 0xFD, buf ); serverId = readString(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java index 88e31929..1df353dc 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketFEPing.java @@ -11,7 +11,7 @@ public class PacketFEPing extends DefinedPacket public byte version; - public PacketFEPing(ByteBuf buffer) + PacketFEPing(ByteBuf buffer) { super( 0xFE, buffer ); version = readByte(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java index 7eeb12c2..d7d80b74 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketFFKick.java @@ -17,7 +17,7 @@ public class PacketFFKick extends DefinedPacket writeString( message ); } - public PacketFFKick(ByteBuf buf) + PacketFFKick(ByteBuf buf) { super( 0xFF, buf ); this.message = readString(); diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java index e5462daf..f487f641 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java @@ -6,11 +6,6 @@ import io.netty.channel.Channel; public abstract class PacketHandler { - private void nop(Object msg) - { - throw new UnsupportedOperationException( "No handler defined for packet " + msg.getClass() ); - } - public void connected(Channel channel) throws Exception { } @@ -25,66 +20,53 @@ public abstract class PacketHandler public void handle(ByteBuf buf) throws Exception { - nop( buf ); } public void handle(Packet0KeepAlive alive) throws Exception { - nop( alive ); } public void handle(Packet1Login login) throws Exception { - nop( login ); } public void handle(Packet2Handshake handshake) throws Exception { - nop( handshake ); } public void handle(Packet3Chat chat) throws Exception { - nop( chat ); } public void handle(Packet9Respawn respawn) throws Exception { - nop( respawn ); } public void handle(PacketC9PlayerListItem playerList) throws Exception { - nop( playerList ); } public void handle(PacketCDClientStatus clientStatus) throws Exception { - nop( clientStatus ); } public void handle(PacketFAPluginMessage pluginMessage) throws Exception { - nop( pluginMessage ); } public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception { - nop( encryptResponse ); } public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception { - nop( encryptRequest ); } public void handle(PacketFEPing ping) throws Exception { - nop( ping ); } public void handle(PacketFFKick kick) throws Exception { - nop( kick ); } }