Nearly ready to get a working connection, however few hacks due to own shortcomings and netty shortcomings.

This commit is contained in:
md_5 2013-03-09 12:08:26 +11:00
parent e12bc1d92e
commit 4fb85721a9
21 changed files with 45 additions and 45 deletions

View File

@ -14,6 +14,7 @@ import net.md_5.bungee.packet.PacketFFKick;
public class ServerConnection implements Server public class ServerConnection implements Server
{ {
@Getter
private final Channel ch; private final Channel ch;
@Getter @Getter
private final ServerInfo info; private final ServerInfo info;

View File

@ -7,8 +7,11 @@ import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectedEvent; 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.DefinedPacket;
import net.md_5.bungee.packet.Packet1Login; 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.Packet9Respawn;
import net.md_5.bungee.packet.PacketCDClientStatus; import net.md_5.bungee.packet.PacketCDClientStatus;
import net.md_5.bungee.packet.PacketFDEncryptionRequest; import net.md_5.bungee.packet.PacketFDEncryptionRequest;
@ -35,7 +38,8 @@ public class ServerConnector extends PacketHandler
public void connected(Channel channel) throws Exception public void connected(Channel channel) throws Exception
{ {
this.ch = channel; 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 ); channel.write( PacketCDClientStatus.CLIENT_LOGIN );
} }
@ -91,6 +95,8 @@ public class ServerConnector extends PacketHandler
user.getServer().disconnect( "Quitting" ); user.getServer().disconnect( "Quitting" );
user.getServer().getInfo().removePlayer( user ); user.getServer().getInfo().removePlayer( user );
} }
ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) );
} }
thisState = State.FINISHED; thisState = State.FINISHED;

View File

@ -33,7 +33,7 @@ public final class UserConnection implements ProxiedPlayer
public final Packet2Handshake handshake; public final Packet2Handshake handshake;
private final ProxyServer bungee; private final ProxyServer bungee;
private final Channel ch; public final Channel ch;
final Packet1Login forgeLogin; final Packet1Login forgeLogin;
final List<PacketFAPluginMessage> loginMessages; final List<PacketFAPluginMessage> loginMessages;
public Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>(); public Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
@ -69,7 +69,8 @@ public final class UserConnection implements ProxiedPlayer
this.pendingConnection = pendingConnection; this.pendingConnection = pendingConnection;
this.forgeLogin = forgeLogin; this.forgeLogin = forgeLogin;
this.loginMessages = loginMessages; this.loginMessages = loginMessages;
this.name = handshake.username;
this.displayName = name;
Collection<String> g = bungee.getConfigurationAdapter().getGroups( name ); Collection<String> g = bungee.getConfigurationAdapter().getGroups( name );
for ( String s : g ) for ( String s : g )

View File

@ -3,7 +3,9 @@ package net.md_5.bungee.connection;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
@ -24,6 +26,13 @@ public class DownstreamBridge extends PacketHandler
private final ProxyServer bungee; private final ProxyServer bungee;
private final UserConnection con; private final UserConnection con;
@Override
public void handle(ByteBuf buf) throws Exception
{
EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId );
con.ch.write( buf );
}
@Override @Override
public void handle(Packet0KeepAlive alive) throws Exception public void handle(Packet0KeepAlive alive) throws Exception
{ {

View File

@ -177,10 +177,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} }
} }
ch.write( new PacketFCEncryptionResponse() );
Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, shared ); Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, shared );
Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_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 ) ); ch.pipeline().addBefore( "decoder", "cipher", new CipherCodec( encrypt, decrypt ) );
thisState = InitialHandler.State.LOGIN; thisState = InitialHandler.State.LOGIN;

View File

@ -1,6 +1,8 @@
package net.md_5.bungee.connection; package net.md_5.bungee.connection;
import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.ChatEvent;
@ -17,6 +19,13 @@ public class UpstreamBridge extends PacketHandler
private final ProxyServer bungee; private final ProxyServer bungee;
private final UserConnection con; 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 @Override
public void handle(Packet0KeepAlive alive) throws Exception public void handle(Packet0KeepAlive alive) throws Exception
{ {

View File

@ -33,9 +33,6 @@ public class CipherCodec extends ByteToByteCodec
{ {
heapOut = ctx.alloc().heapBuffer(); 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 ); cipher( encrypt, in, heapOut );
out.writeBytes( heapOut ); out.writeBytes( heapOut );
heapOut.discardSomeReadBytes(); heapOut.discardSomeReadBytes();
@ -44,9 +41,6 @@ public class CipherCodec extends ByteToByteCodec
@Override @Override
public void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception 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 ); cipher( decrypt, in, out );
} }

View File

@ -51,17 +51,15 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<ByteBuf>
if ( packet != null ) if ( packet != null )
{ {
packet.handle( handler ); packet.handle( handler );
} else
{
handler.handle( msg );
} }
handler.handle( msg );
} }
} }
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{ {
System.out.println( handler + " " + Util.exception( cause ) ); cause.printStackTrace();
if ( ctx.channel().isActive() ) if ( ctx.channel().isActive() )
{ {
ctx.close(); ctx.close();

View File

@ -11,7 +11,7 @@ public class Packet0KeepAlive extends DefinedPacket
public int id; public int id;
public Packet0KeepAlive(ByteBuf buf) Packet0KeepAlive(ByteBuf buf)
{ {
super( 0x00, buf ); super( 0x00, buf );
id = readInt(); id = readInt();

View File

@ -29,7 +29,7 @@ public class Packet1Login extends DefinedPacket
writeByte( maxPlayers ); writeByte( maxPlayers );
} }
public Packet1Login(ByteBuf buf) Packet1Login(ByteBuf buf)
{ {
super( 0x01, buf ); super( 0x01, buf );
this.entityId = readInt(); this.entityId = readInt();

View File

@ -23,7 +23,7 @@ public class Packet2Handshake extends DefinedPacket
writeInt( port ); writeInt( port );
} }
public Packet2Handshake(ByteBuf buf) Packet2Handshake(ByteBuf buf)
{ {
super( 0x02, buf ); super( 0x02, buf );
this.procolVersion = readByte(); this.procolVersion = readByte();

View File

@ -17,7 +17,7 @@ public class Packet3Chat extends DefinedPacket
writeString( message ); writeString( message );
} }
public Packet3Chat(ByteBuf buf) Packet3Chat(ByteBuf buf)
{ {
super( 0x03, buf ); super( 0x03, buf );
this.message = readString(); this.message = readString();

View File

@ -27,7 +27,7 @@ public class Packet9Respawn extends DefinedPacket
writeString( levelType ); writeString( levelType );
} }
public Packet9Respawn(ByteBuf buf) Packet9Respawn(ByteBuf buf)
{ {
super( 0x09, buf ); super( 0x09, buf );
this.dimension = readInt(); this.dimension = readInt();

View File

@ -13,7 +13,7 @@ public class PacketC9PlayerListItem extends DefinedPacket
public boolean online; public boolean online;
public int ping; public int ping;
public PacketC9PlayerListItem(ByteBuf buf) PacketC9PlayerListItem(ByteBuf buf)
{ {
super( 0xC9, buf ); super( 0xC9, buf );
username = readString(); username = readString();

View File

@ -22,7 +22,7 @@ public class PacketCDClientStatus extends DefinedPacket
writeByte( payload ); writeByte( payload );
} }
public PacketCDClientStatus(ByteBuf buf) PacketCDClientStatus(ByteBuf buf)
{ {
super( 0xCD, buf ); super( 0xCD, buf );
} }

View File

@ -21,7 +21,7 @@ public class PacketFAPluginMessage extends DefinedPacket
this.data = data; this.data = data;
} }
public PacketFAPluginMessage(ByteBuf buf) PacketFAPluginMessage(ByteBuf buf)
{ {
super( 0xFA, buf ); super( 0xFA, buf );
this.tag = readString(); this.tag = readString();

View File

@ -26,7 +26,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket
writeArray( verifyToken ); writeArray( verifyToken );
} }
public PacketFCEncryptionResponse(ByteBuf buf) PacketFCEncryptionResponse(ByteBuf buf)
{ {
super( 0xFC, buf ); super( 0xFC, buf );
this.sharedSecret = readArray(); this.sharedSecret = readArray();

View File

@ -24,7 +24,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket
this.verifyToken = verifyToken; this.verifyToken = verifyToken;
} }
public PacketFDEncryptionRequest(ByteBuf buf) PacketFDEncryptionRequest(ByteBuf buf)
{ {
super( 0xFD, buf ); super( 0xFD, buf );
serverId = readString(); serverId = readString();

View File

@ -11,7 +11,7 @@ public class PacketFEPing extends DefinedPacket
public byte version; public byte version;
public PacketFEPing(ByteBuf buffer) PacketFEPing(ByteBuf buffer)
{ {
super( 0xFE, buffer ); super( 0xFE, buffer );
version = readByte(); version = readByte();

View File

@ -17,7 +17,7 @@ public class PacketFFKick extends DefinedPacket
writeString( message ); writeString( message );
} }
public PacketFFKick(ByteBuf buf) PacketFFKick(ByteBuf buf)
{ {
super( 0xFF, buf ); super( 0xFF, buf );
this.message = readString(); this.message = readString();

View File

@ -6,11 +6,6 @@ import io.netty.channel.Channel;
public abstract class PacketHandler 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 public void connected(Channel channel) throws Exception
{ {
} }
@ -25,66 +20,53 @@ public abstract class PacketHandler
public void handle(ByteBuf buf) throws Exception public void handle(ByteBuf buf) throws Exception
{ {
nop( buf );
} }
public void handle(Packet0KeepAlive alive) throws Exception public void handle(Packet0KeepAlive alive) throws Exception
{ {
nop( alive );
} }
public void handle(Packet1Login login) throws Exception public void handle(Packet1Login login) throws Exception
{ {
nop( login );
} }
public void handle(Packet2Handshake handshake) throws Exception public void handle(Packet2Handshake handshake) throws Exception
{ {
nop( handshake );
} }
public void handle(Packet3Chat chat) throws Exception public void handle(Packet3Chat chat) throws Exception
{ {
nop( chat );
} }
public void handle(Packet9Respawn respawn) throws Exception public void handle(Packet9Respawn respawn) throws Exception
{ {
nop( respawn );
} }
public void handle(PacketC9PlayerListItem playerList) throws Exception public void handle(PacketC9PlayerListItem playerList) throws Exception
{ {
nop( playerList );
} }
public void handle(PacketCDClientStatus clientStatus) throws Exception public void handle(PacketCDClientStatus clientStatus) throws Exception
{ {
nop( clientStatus );
} }
public void handle(PacketFAPluginMessage pluginMessage) throws Exception public void handle(PacketFAPluginMessage pluginMessage) throws Exception
{ {
nop( pluginMessage );
} }
public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception
{ {
nop( encryptResponse );
} }
public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception
{ {
nop( encryptRequest );
} }
public void handle(PacketFEPing ping) throws Exception public void handle(PacketFEPing ping) throws Exception
{ {
nop( ping );
} }
public void handle(PacketFFKick kick) throws Exception public void handle(PacketFFKick kick) throws Exception
{ {
nop( kick );
} }
} }