Whats this? It compiles. Doesn't mean it near works though.

This commit is contained in:
md_5 2013-03-08 17:52:17 +11:00
parent c3d702a5b3
commit e18fe49cf9
15 changed files with 46 additions and 32 deletions

View File

@ -52,8 +52,10 @@ public final class UserConnection implements ProxiedPlayer
@Getter @Getter
private final Object switchMutex = new Object(); private final Object switchMutex = new Object();
public UserConnection(Channel channel, PendingConnection pendingConnection, Packet2Handshake handshake, Packet1Login forgeLogin, List<PacketFAPluginMessage> loginMessages) public UserConnection(BungeeCord bungee, Channel channel, PendingConnection pendingConnection, Packet2Handshake handshake, Packet1Login forgeLogin, List<PacketFAPluginMessage> loginMessages)
{ {
this.bungee = bungee;
this.ch = channel;
this.handshake = handshake; this.handshake = handshake;
this.pendingConnection = pendingConnection; this.pendingConnection = pendingConnection;
this.forgeLogin = forgeLogin; this.forgeLogin = forgeLogin;

View File

@ -142,7 +142,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{ {
Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" ); Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" );
UserConnection userCon = new UserConnection( socket, this, stream, handshake, forgeLogin, loginMessages ); UserConnection userCon = new UserConnection( (BungeeCord) bungee, ch, this, handshake, forgeLogin, loginMessages );
ServerInfo server = bungee.getReconnectHandler().getServer( userCon ); ServerInfo server = bungee.getReconnectHandler().getServer( userCon );
userCon.connect( server ); userCon.connect( server );

View File

@ -1,6 +1,5 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ReferenceCounted; import io.netty.buffer.ReferenceCounted;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -21,26 +20,20 @@ public abstract class DefinedPacket implements ByteBuf
{ {
ByteBuf.class, ReferenceCounted.class ByteBuf.class, ReferenceCounted.class
}) })
private ByteBuf out; private ByteBuf buf;
/**
* Packet id.
*/
public final int id;
public DefinedPacket(int id, byte[] buf) public DefinedPacket(int id, ByteBuf buf)
{ {
out = Unpooled.wrappedBuffer( buf ); this.buf = buf;
if ( readUnsignedByte() != id ) if ( readUnsignedByte() != id )
{ {
throw new IllegalArgumentException( "Wasn't expecting packet id " + Util.hex( id ) ); throw new IllegalArgumentException( "Wasn't expecting packet id " + Util.hex( id ) );
} }
this.id = id;
} }
public DefinedPacket(int id) public DefinedPacket(int id)
{ {
out = Unpooled.buffer(); buf = Unpooled.buffer();
this.id = id;
writeByte( id ); writeByte( id );
} }
@ -90,6 +83,8 @@ public abstract class DefinedPacket implements ByteBuf
public abstract void handle(PacketHandler handler) throws Exception; public abstract void handle(PacketHandler handler) throws Exception;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static Class<? extends DefinedPacket>[] classes = new Class[ 256 ]; private static Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
@SuppressWarnings("unchecked")
private static Constructor<? extends DefinedPacket>[] consructors = new Constructor[ 256 ];
public static DefinedPacket packet(ByteBuf buf) public static DefinedPacket packet(ByteBuf buf)
{ {
@ -100,7 +95,13 @@ public abstract class DefinedPacket implements ByteBuf
{ {
try try
{ {
Constructor<? extends DefinedPacket> constructor = clazz.getDeclaredConstructor( byte[].class ); Constructor<? extends DefinedPacket> constructor = consructors[id];
if ( constructor == null )
{
constructor = clazz.getDeclaredConstructor( ByteBuf.class );
consructors[id] = constructor;
}
if ( constructor != null ) if ( constructor != null )
{ {
ret = constructor.newInstance( buf ); ret = constructor.newInstance( buf );
@ -108,12 +109,8 @@ public abstract class DefinedPacket implements ByteBuf
} catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex ) } catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex )
{ {
} }
} else
{
return null;
} }
Preconditions.checkState( ret != null, "Don't know how to deal with packet ID %s", Util.hex( id ) );
return ret; return ret;
} }

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -10,9 +11,9 @@ public class Packet0KeepAlive extends DefinedPacket
public int id; public int id;
public Packet0KeepAlive(byte[] buffer) public Packet0KeepAlive(ByteBuf buf)
{ {
super( 0x00, buffer ); super( 0x00, buf );
id = readInt(); id = readInt();
} }

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -28,7 +29,7 @@ public class Packet1Login extends DefinedPacket
writeByte( maxPlayers ); writeByte( maxPlayers );
} }
public Packet1Login(byte[] buf) public Packet1Login(ByteBuf buf)
{ {
super( 0x01, buf ); super( 0x01, buf );
this.entityId = readInt(); this.entityId = readInt();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -22,7 +23,7 @@ public class Packet2Handshake extends DefinedPacket
writeInt( port ); writeInt( port );
} }
public Packet2Handshake(byte[] buf) public Packet2Handshake(ByteBuf buf)
{ {
super( 0x02, buf ); super( 0x02, buf );
this.procolVersion = readByte(); this.procolVersion = readByte();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -16,7 +17,7 @@ public class Packet3Chat extends DefinedPacket
writeString( message ); writeString( message );
} }
public Packet3Chat(byte[] buf) public Packet3Chat(ByteBuf buf)
{ {
super( 0x03, buf ); super( 0x03, buf );
this.message = readString(); this.message = readString();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -26,7 +27,7 @@ public class Packet9Respawn extends DefinedPacket
writeString( levelType ); writeString( levelType );
} }
public Packet9Respawn(byte[] buf) public Packet9Respawn(ByteBuf buf)
{ {
super( 0x09, buf ); super( 0x09, buf );
this.dimension = readInt(); this.dimension = readInt();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -12,9 +13,9 @@ public class PacketC9PlayerListItem extends DefinedPacket
public boolean online; public boolean online;
public int ping; public int ping;
public PacketC9PlayerListItem(byte[] packet) public PacketC9PlayerListItem(ByteBuf buf)
{ {
super( 0xC9, packet ); super( 0xC9, buf );
username = readString(); username = readString();
online = readBoolean(); online = readBoolean();
ping = readShort(); ping = readShort();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -21,7 +22,7 @@ public class PacketCDClientStatus extends DefinedPacket
writeByte( payload ); writeByte( payload );
} }
public PacketCDClientStatus(byte[] buf) public PacketCDClientStatus(ByteBuf buf)
{ {
super( 0xCD, buf ); super( 0xCD, buf );
} }

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -20,7 +21,7 @@ public class PacketFAPluginMessage extends DefinedPacket
this.data = data; this.data = data;
} }
public PacketFAPluginMessage(byte[] buf) public PacketFAPluginMessage(ByteBuf buf)
{ {
super( 0xFA, buf ); super( 0xFA, buf );
this.tag = readString(); this.tag = readString();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -25,7 +26,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket
writeArray( verifyToken ); writeArray( verifyToken );
} }
public PacketFCEncryptionResponse(byte[] buf) public PacketFCEncryptionResponse(ByteBuf buf)
{ {
super( 0xFC, buf ); super( 0xFC, buf );
this.sharedSecret = readArray(); this.sharedSecret = readArray();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -23,7 +24,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket
this.verifyToken = verifyToken; this.verifyToken = verifyToken;
} }
public PacketFDEncryptionRequest(byte[] buf) public PacketFDEncryptionRequest(ByteBuf buf)
{ {
super( 0xFD, buf ); super( 0xFD, buf );
serverId = readString(); serverId = readString();

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -8,9 +9,12 @@ import lombok.ToString;
public class PacketFEPing extends DefinedPacket public class PacketFEPing extends DefinedPacket
{ {
public PacketFEPing(byte[] buffer) public byte version;
public PacketFEPing(ByteBuf buffer)
{ {
super( 0xFE, buffer ); super( 0xFE, buffer );
version = readByte();
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.packet; package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -16,7 +17,7 @@ public class PacketFFKick extends DefinedPacket
writeString( message ); writeString( message );
} }
public PacketFFKick(byte[] buf) public PacketFFKick(ByteBuf buf)
{ {
super( 0xFF, buf ); super( 0xFF, buf );
this.message = readString(); this.message = readString();