We can login now. Kindof. *wipes sweat off brow.

This commit is contained in:
md_5 2013-03-09 14:19:12 +11:00
parent 504f703fbb
commit 6525502836
12 changed files with 34 additions and 59 deletions

View File

@ -92,7 +92,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version> <version>2.5.1</version>
<configuration> <configuration>
<source>1.7</source> <source>1.7</source>
<target>1.7</target> <target>1.7</target>

View File

@ -21,8 +21,9 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId> <!-- TODO: Fix this -->
<version>4.0.0.Beta2</version> <artifactId>netty-all</artifactId>
<version>4.0.0.Beta3-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -22,7 +22,7 @@
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <artifactId>netty-all</artifactId>
<version>4.0.0.Beta2</version> <version>4.0.0.Beta3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>

View File

@ -79,7 +79,7 @@ public class ServerConnector extends PacketHandler
login.difficulty, login.difficulty,
login.unused, login.unused,
(byte) user.getPendingConnection().getListener().getTabListSize() ); (byte) user.getPendingConnection().getListener().getTabListSize() );
ch.write( modLogin ); user.ch.write( modLogin );
ch.write( BungeeCord.getInstance().registerChannels() ); ch.write( BungeeCord.getInstance().registerChannels() );
} else } else
{ {
@ -88,15 +88,16 @@ public class ServerConnector extends PacketHandler
user.sendPacket( Packet9Respawn.DIM2_SWITCH ); user.sendPacket( Packet9Respawn.DIM2_SWITCH );
user.serverEntityId = login.entityId; 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 // Remove from old servers
user.getServer().disconnect( "Quitting" ); user.getServer().disconnect( "Quitting" );
user.getServer().getInfo().removePlayer( user ); user.getServer().getInfo().removePlayer( user );
} }
// Add to new server
target.addPlayer( user );
ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) );
} }

View File

@ -7,6 +7,7 @@ import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.EntityMap; import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection; 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.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -30,6 +31,8 @@ public class DownstreamBridge extends PacketHandler
public void handle(ByteBuf buf) throws Exception public void handle(ByteBuf buf) throws Exception
{ {
EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId ); 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 ); con.ch.write( buf );
} }

View File

@ -92,18 +92,18 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(PacketFEPing ping) throws Exception 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() ); 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" String kickMessage = ChatColor.DARK_BLUE
+ "\00" + pingevent.getProtocolVersion() + "\00" + response.getProtocolVersion()
+ "\00" + pingevent.getGameVersion() + "\00" + response.getGameVersion()
+ "\00" + pingevent.getMotd() + "\00" + response.getMotd()
+ "\00" + pingevent.getCurrentPlayers() + "\00" + response.getCurrentPlayers()
+ "\00" + pingevent.getMaxPlayers(); + "\00" + response.getMaxPlayers();
disconnect( response ); disconnect( kickMessage );
} }
@Override @Override
@ -181,7 +181,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
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.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;
@ -205,6 +204,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
userCon.connect( server ); userCon.connect( server );
thisState = State.FINISHED; thisState = State.FINISHED;
throw new CancelSendSignal();
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.EntityMap; import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection; 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.ProxyServer;
import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
@ -24,18 +25,13 @@ public class UpstreamBridge extends PacketHandler
public void handle(ByteBuf buf) throws Exception public void handle(ByteBuf buf) throws Exception
{ {
EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId ); EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId );
System.out.println( "Got packet from client: " + Util.hex( buf.getUnsignedByte( 0 ) ) );
if ( con.getServer() != null ) if ( con.getServer() != null )
{ {
con.getServer().getCh().write( buf ); 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 @Override
public void handle(Packet0KeepAlive alive) throws Exception public void handle(Packet0KeepAlive alive) throws Exception
{ {

View File

@ -18,7 +18,6 @@ public class CipherCodec extends ByteToByteCodec
private Cipher encrypt; private Cipher encrypt;
private Cipher decrypt; private Cipher decrypt;
private ByteBuf heapOut;
public CipherCodec(Cipher encrypt, Cipher decrypt) public CipherCodec(Cipher encrypt, Cipher decrypt)
{ {
@ -29,13 +28,7 @@ public class CipherCodec extends ByteToByteCodec
@Override @Override
public void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception public void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
{ {
if ( heapOut == null ) cipher( encrypt, in, out );
{
heapOut = ctx.alloc().heapBuffer();
}
cipher( encrypt, in, heapOut );
out.writeBytes( heapOut );
heapOut.discardSomeReadBytes();
} }
@Override @Override
@ -44,25 +37,6 @@ public class CipherCodec extends ByteToByteCodec
cipher( decrypt, in, out ); 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 private void cipher(Cipher cipher, ByteBuf in, ByteBuf out) throws ShortBufferException
{ {
int available = in.readableBytes(); int available = in.readableBytes();
@ -71,8 +45,7 @@ public class CipherCodec extends ByteToByteCodec
{ {
out.capacity( outputSize ); out.capacity( outputSize );
} }
// TODO: Try and make this use out.nioBuffer() int processed = cipher.update( in.nioBuffer(), out.nioBuffer( out.readerIndex(), outputSize ) );
int processed = cipher.update( in.array(), in.arrayOffset() + in.readerIndex(), available, out.array(), out.arrayOffset() + out.writerIndex() );
in.readerIndex( in.readerIndex() + processed ); in.readerIndex( in.readerIndex() + processed );
out.writerIndex( out.writerIndex() + processed ); out.writerIndex( out.writerIndex() + processed );
} }

View File

@ -43,7 +43,7 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<ByteBuf>
} }
@Override @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() ) if ( handler != null && ctx.channel().isActive() )
{ {

View File

@ -3,11 +3,9 @@ package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder; import io.netty.handler.codec.ReplayingDecoder;
import java.io.IOException;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.md_5.bungee.Util;
import net.md_5.bungee.protocol.netty.PacketReader; import net.md_5.bungee.protocol.netty.PacketReader;
/** /**
@ -30,10 +28,7 @@ public class PacketDecoder extends ReplayingDecoder<ByteBuf>
protected ByteBuf decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception protected ByteBuf decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
{ {
int startIndex = in.readerIndex(); int startIndex = in.readerIndex();
PacketReader.readPacket( in, protocol ); PacketReader.readPacket( in, protocol );
System.out.println( Util.hex( in.getUnsignedByte( 0 ) ) );
return in.copy( startIndex, in.readerIndex() - startIndex ); return in.copy( startIndex, in.readerIndex() - startIndex );
} }
} }

View File

@ -2,6 +2,7 @@ package net.md_5.bungee.netty;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@ -32,6 +33,7 @@ public class PipelineUtils
{ {
BASE.initChannel( ch ); BASE.initChannel( ch );
ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) );
ch.config().setDefaultHandlerByteBufType( ChannelConfig.ChannelHandlerByteBufType.HEAP );
} }
}; };
public static final ChannelInitializer<Channel> CLIENT = new ChannelInitializer<Channel>() public static final ChannelInitializer<Channel> CLIENT = new ChannelInitializer<Channel>()

View File

@ -104,7 +104,11 @@ public abstract class DefinedPacket implements ByteBuf
if ( constructor != null ) if ( constructor != null )
{ {
buf.markReaderIndex();
buf.markWriterIndex();
ret = constructor.newInstance( buf ); ret = constructor.newInstance( buf );
buf.resetReaderIndex();
buf.resetWriterIndex();
} }
} catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex ) } catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex )
{ {