Rework protocol system

This commit is contained in:
md_5 2013-05-30 18:09:46 +10:00
parent ad4c143ce4
commit 2f45f0d578
40 changed files with 273 additions and 164 deletions

View File

@ -0,0 +1,25 @@
package net.md_5.bungee.protocol;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import net.md_5.bungee.protocol.packet.DefinedPacket;
public class Forge extends Vanilla
{
@Getter
private static final Forge instance = new Forge();
@Override
public DefinedPacket read(short packetId, ByteBuf buf)
{
int start = buf.readerIndex();
DefinedPacket packet = read( packetId, buf, this );
if ( buf.readerIndex() == start )
{
packet = super.read( packetId, buf );
}
return packet;
}
}

View File

@ -0,0 +1,7 @@
package net.md_5.bungee.protocol;
public enum OpCode
{
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE
}

View File

@ -0,0 +1,20 @@
package net.md_5.bungee.protocol;
import io.netty.buffer.ByteBuf;
import java.lang.reflect.Constructor;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.skip.PacketReader;
public interface Protocol
{
PacketReader getSkipper();
DefinedPacket read(short packetId, ByteBuf buf);
OpCode[][] getOpCodes();
Class<? extends DefinedPacket>[] getClasses();
Constructor<? extends DefinedPacket>[] getConstructors();
}

View File

@ -1,23 +1,125 @@
package net.md_5.bungee.protocol; package net.md_5.bungee.protocol;
import static net.md_5.bungee.protocol.PacketDefinitions.OpCode.*; import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import lombok.Getter;
import static net.md_5.bungee.protocol.OpCode.*;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
import net.md_5.bungee.protocol.packet.Packet1Login;
import net.md_5.bungee.protocol.packet.Packet2Handshake;
import net.md_5.bungee.protocol.packet.Packet3Chat;
import net.md_5.bungee.protocol.packet.Packet9Respawn;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
import net.md_5.bungee.protocol.packet.PacketCCSettings;
import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective;
import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore;
import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard;
import net.md_5.bungee.protocol.packet.PacketD1Team;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.protocol.packet.PacketFEPing;
import net.md_5.bungee.protocol.packet.PacketFFKick;
import net.md_5.bungee.protocol.skip.PacketReader;
public class PacketDefinitions public class Vanilla implements Protocol
{ {
public static final byte PROTOCOL_VERSION = 61; public static final byte PROTOCOL_VERSION = 61;
public static final String GAME_VERSION = "1.5.2"; public static final String GAME_VERSION = "1.5.2";
public static final OpCode[][] opCodes = new OpCode[ 512 ][]; public static final Vanilla INSTANCE = new Vanilla();
public static final int VANILLA_PROTOCOL = 0; /*========================================================================*/
public static final int FORGE_PROTOCOL = 256; @Getter
private final OpCode[][] opCodes = new OpCode[ 256 ][];
@SuppressWarnings("unchecked")
@Getter
private Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
@SuppressWarnings("unchecked")
@Getter
private Constructor<? extends DefinedPacket>[] constructors = new Constructor[ 256 ];
@Getter
private final PacketReader skipper = new PacketReader( this );
/*========================================================================*/
public enum OpCode
{ {
classes[0x00] = Packet0KeepAlive.class;
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE classes[0x01] = Packet1Login.class;
classes[0x02] = Packet2Handshake.class;
classes[0x03] = Packet3Chat.class;
classes[0x09] = Packet9Respawn.class;
classes[0xC9] = PacketC9PlayerListItem.class;
classes[0xCC] = PacketCCSettings.class;
classes[0xCD] = PacketCDClientStatus.class;
classes[0xCE] = PacketCEScoreboardObjective.class;
classes[0xCF] = PacketCFScoreboardScore.class;
classes[0xD0] = PacketD0DisplayScoreboard.class;
classes[0xD1] = PacketD1Team.class;
classes[0xFA] = PacketFAPluginMessage.class;
classes[0xFC] = PacketFCEncryptionResponse.class;
classes[0xFD] = PacketFDEncryptionRequest.class;
classes[0xFE] = PacketFEPing.class;
classes[0xFF] = PacketFFKick.class;
} }
static @Override
public DefinedPacket read(short packetId, ByteBuf buf)
{
int start = buf.readerIndex();
DefinedPacket packet = read( packetId, buf, this );
if ( buf.readerIndex() == start )
{
throw new RuntimeException( "Unknown packet id " + packetId );
}
return packet;
}
public static DefinedPacket read(short id, ByteBuf buf, Protocol protocol)
{
DefinedPacket packet = packet( id, protocol );
if ( packet != null )
{
packet.read( buf );
return packet;
}
protocol.getSkipper().tryRead( id, buf );
return null;
}
public static DefinedPacket packet(short id, Protocol protocol)
{
DefinedPacket ret = null;
Class<? extends DefinedPacket> clazz = protocol.getClasses()[id];
if ( clazz != null )
{
try
{
Constructor<? extends DefinedPacket> constructor = protocol.getConstructors()[id];
if ( constructor == null )
{
constructor = clazz.getDeclaredConstructor();
constructor.setAccessible( true );
protocol.getConstructors()[id] = constructor;
}
if ( constructor != null )
{
ret = constructor.newInstance();
}
} catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex )
{
}
}
return ret;
}
{ {
opCodes[0x04] = new OpCode[] opCodes[0x04] = new OpCode[]
{ {

View File

@ -1,51 +1,14 @@
package net.md_5.bungee.protocol.packet; package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public abstract class DefinedPacket public abstract class DefinedPacket
{ {
@SuppressWarnings("unchecked")
public static Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
@SuppressWarnings("unchecked")
private static Constructor<? extends DefinedPacket>[] consructors = new Constructor[ 256 ];
private final int id; private final int id;
public static DefinedPacket packet(ByteBuf buf)
{
DefinedPacket ret = null;
int id = buf.readUnsignedByte();
Class<? extends DefinedPacket> clazz = classes[id];
if ( clazz != null )
{
try
{
Constructor<? extends DefinedPacket> constructor = consructors[id];
if ( constructor == null )
{
constructor = clazz.getDeclaredConstructor();
consructors[id] = constructor;
}
if ( constructor != null )
{
ret = constructor.newInstance();
}
} catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex )
{
}
}
return ret;
}
public final int getId() public final int getId()
{ {
return id; return id;
@ -103,25 +66,4 @@ public abstract class DefinedPacket
@Override @Override
public abstract String toString(); public abstract String toString();
static
{
classes[0x00] = Packet0KeepAlive.class;
classes[0x01] = Packet1Login.class;
classes[0x02] = Packet2Handshake.class;
classes[0x03] = Packet3Chat.class;
classes[0x09] = Packet9Respawn.class;
classes[0xC9] = PacketC9PlayerListItem.class;
classes[0xCC] = PacketCCSettings.class;
classes[0xCD] = PacketCDClientStatus.class;
classes[0xCE] = PacketCEScoreboardObjective.class;
classes[0xCF] = PacketCFScoreboardScore.class;
classes[0xD0] = PacketD0DisplayScoreboard.class;
classes[0xD1] = PacketD1Team.class;
classes[0xFA] = PacketFAPluginMessage.class;
classes[0xFC] = PacketFCEncryptionResponse.class;
classes[0xFD] = PacketFDEncryptionRequest.class;
classes[0xFE] = PacketFEPing.class;
classes[0xFF] = PacketFFKick.class;
}
} }

View File

@ -11,7 +11,7 @@ public class Packet0KeepAlive extends DefinedPacket
private int id; private int id;
Packet0KeepAlive() private Packet0KeepAlive()
{ {
super( 0x00 ); super( 0x00 );
} }

View File

@ -9,15 +9,15 @@ import lombok.ToString;
public class Packet1Login extends DefinedPacket public class Packet1Login extends DefinedPacket
{ {
private int entityId; protected int entityId;
private String levelType; protected String levelType;
private byte gameMode; protected byte gameMode;
private byte dimension; protected int dimension;
private byte difficulty; protected byte difficulty;
private byte unused; protected byte unused;
private byte maxPlayers; protected byte maxPlayers;
Packet1Login() protected Packet1Login()
{ {
super( 0x01 ); super( 0x01 );
} }

View File

@ -14,7 +14,7 @@ public class Packet2Handshake extends DefinedPacket
private String host; private String host;
private int port; private int port;
Packet2Handshake() private Packet2Handshake()
{ {
super( 0x02 ); super( 0x02 );
} }

View File

@ -11,7 +11,7 @@ public class Packet3Chat extends DefinedPacket
private String message; private String message;
Packet3Chat() private Packet3Chat()
{ {
super( 0x03 ); super( 0x03 );
} }

View File

@ -15,7 +15,7 @@ public class Packet9Respawn extends DefinedPacket
private short worldHeight; private short worldHeight;
private String levelType; private String levelType;
Packet9Respawn() private Packet9Respawn()
{ {
super( 0x09 ); super( 0x09 );
} }

View File

@ -13,7 +13,7 @@ public class PacketC9PlayerListItem extends DefinedPacket
private boolean online; private boolean online;
private int ping; private int ping;
PacketC9PlayerListItem() private PacketC9PlayerListItem()
{ {
super( 0xC9 ); super( 0xC9 );
} }

View File

@ -15,7 +15,7 @@ public class PacketCCSettings extends DefinedPacket
private byte difficulty; private byte difficulty;
private boolean showCape; private boolean showCape;
PacketCCSettings() private PacketCCSettings()
{ {
super( 0xCC ); super( 0xCC );
} }

View File

@ -11,7 +11,7 @@ public class PacketCDClientStatus extends DefinedPacket
private byte payload; private byte payload;
PacketCDClientStatus() private PacketCDClientStatus()
{ {
super( 0xCD ); super( 0xCD );
} }

View File

@ -16,7 +16,7 @@ public class PacketCEScoreboardObjective extends DefinedPacket
*/ */
private byte action; private byte action;
PacketCEScoreboardObjective() private PacketCEScoreboardObjective()
{ {
super( 0xCE ); super( 0xCE );
} }

View File

@ -17,7 +17,7 @@ public class PacketCFScoreboardScore extends DefinedPacket
private String scoreName; private String scoreName;
private int value; private int value;
PacketCFScoreboardScore() private PacketCFScoreboardScore()
{ {
super( 0xCF ); super( 0xCF );
} }

View File

@ -15,7 +15,7 @@ public class PacketD0DisplayScoreboard extends DefinedPacket
private byte position; private byte position;
private String name; private String name;
PacketD0DisplayScoreboard() private PacketD0DisplayScoreboard()
{ {
super( 0xD0 ); super( 0xD0 );
} }

View File

@ -21,7 +21,7 @@ public class PacketD1Team extends DefinedPacket
private short playerCount; private short playerCount;
private String[] players; private String[] players;
PacketD1Team() private PacketD1Team()
{ {
super( 0xD1 ); super( 0xD1 );
} }

View File

@ -12,7 +12,7 @@ public class PacketFAPluginMessage extends DefinedPacket
private String tag; private String tag;
private byte[] data; private byte[] data;
PacketFAPluginMessage() private PacketFAPluginMessage()
{ {
super( 0xFA ); super( 0xFA );
} }

View File

@ -12,7 +12,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket
private byte[] sharedSecret; private byte[] sharedSecret;
private byte[] verifyToken; private byte[] verifyToken;
PacketFCEncryptionResponse() private PacketFCEncryptionResponse()
{ {
super( 0xFC ); super( 0xFC );
} }

View File

@ -13,7 +13,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket
private byte[] publicKey; private byte[] publicKey;
private byte[] verifyToken; private byte[] verifyToken;
PacketFDEncryptionRequest() private PacketFDEncryptionRequest()
{ {
super( 0xFD ); super( 0xFD );
} }

View File

@ -11,7 +11,7 @@ public class PacketFEPing extends DefinedPacket
private byte version; private byte version;
PacketFEPing() private PacketFEPing()
{ {
super( 0xFE ); super( 0xFE );
} }

View File

@ -11,7 +11,7 @@ public class PacketFFKick extends DefinedPacket
private String message; private String message;
PacketFFKick() private PacketFFKick()
{ {
super( 0xFF ); super( 0xFF );
} }

View File

@ -0,0 +1,42 @@
package net.md_5.bungee.protocol.packet.forge;
import net.md_5.bungee.protocol.packet.*;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Forge1Login extends Packet1Login
{
@Override
public void read(ByteBuf buf)
{
entityId = buf.readInt();
levelType = readString( buf );
gameMode = buf.readByte();
dimension = buf.readInt();
difficulty = buf.readByte();
unused = buf.readByte();
maxPlayers = buf.readByte();
}
@Override
public void write(ByteBuf buf)
{
buf.writeInt( entityId );
writeString( levelType, buf );
buf.writeByte( gameMode );
buf.writeInt(dimension );
buf.writeByte( difficulty );
buf.writeByte( unused );
buf.writeByte( maxPlayers );
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,13 +1,12 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class BulkChunk extends Instruction public class BulkChunk extends Instruction
{ {
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
short count = in.readShort(); short count = in.readShort();
int size = in.readInt(); int size = in.readInt();

View File

@ -1,7 +1,6 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class ByteHeader extends Instruction class ByteHeader extends Instruction
{ {
@ -14,7 +13,7 @@ class ByteHeader extends Instruction
} }
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
byte size = in.readByte(); byte size = in.readByte();
for ( byte b = 0; b < size; b++ ) for ( byte b = 0; b < size; b++ )

View File

@ -1,7 +1,6 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
abstract class Instruction abstract class Instruction
{ {
@ -29,5 +28,5 @@ abstract class Instruction
// Custom instructions // Custom instructions
static final Instruction STRING_ARRAY = new ShortHeader( STRING ); static final Instruction STRING_ARRAY = new ShortHeader( STRING );
abstract void read(ByteBuf in) throws IOException; abstract void read(ByteBuf in);
} }

View File

@ -1,7 +1,6 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class IntHeader extends Instruction class IntHeader extends Instruction
{ {
@ -14,7 +13,7 @@ class IntHeader extends Instruction
} }
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
int size = in.readInt(); int size = in.readInt();
for ( int i = 0; i < size; i++ ) for ( int i = 0; i < size; i++ )

View File

@ -1,13 +1,12 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class Item extends Instruction class Item extends Instruction
{ {
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
short type = in.readShort(); short type = in.readShort();
if ( type >= 0 ) if ( type >= 0 )

View File

@ -1,7 +1,6 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class Jump extends Instruction class Jump extends Instruction
{ {
@ -18,7 +17,7 @@ class Jump extends Instruction
} }
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
in.skipBytes( len ); in.skipBytes( len );
} }

View File

@ -1,13 +1,12 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class MetaData extends Instruction class MetaData extends Instruction
{ {
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
int x = in.readUnsignedByte(); int x = in.readUnsignedByte();
while ( x != 127 ) while ( x != 127 )

View File

@ -1,13 +1,12 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class OptionalMotion extends Instruction class OptionalMotion extends Instruction
{ {
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
int data = in.readInt(); int data = in.readInt();
if ( data > 0 ) if ( data > 0 )

View File

@ -1,24 +1,24 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.md_5.bungee.protocol.PacketDefinitions; import net.md_5.bungee.protocol.OpCode;
import net.md_5.bungee.protocol.PacketDefinitions.OpCode; import net.md_5.bungee.protocol.Protocol;
public class PacketReader public class PacketReader
{ {
private static final Instruction[][] instructions = new Instruction[ PacketDefinitions.opCodes.length ][]; private final Instruction[][] instructions;
static public PacketReader(Protocol protocol)
{ {
instructions = new Instruction[ protocol.getOpCodes().length ][];
for ( int i = 0; i < instructions.length; i++ ) for ( int i = 0; i < instructions.length; i++ )
{ {
List<Instruction> output = new ArrayList<>(); List<Instruction> output = new ArrayList<>();
OpCode[] enums = PacketDefinitions.opCodes[i]; OpCode[] enums = protocol.getOpCodes()[i];
if ( enums != null ) if ( enums != null )
{ {
for ( OpCode struct : enums ) for ( OpCode struct : enums )
@ -59,35 +59,16 @@ public class PacketReader
} }
} }
private static void readPacket(int packetId, ByteBuf in, int protocol) throws IOException public void tryRead(short packetId, ByteBuf in)
{ {
Instruction[] packetDef = null; Instruction[] packetDef = instructions[packetId];
if ( packetId + protocol < instructions.length )
{
packetDef = instructions[packetId + protocol];
}
if ( packetDef == null ) if ( packetDef != null )
{ {
if ( protocol == PacketDefinitions.VANILLA_PROTOCOL )
{
throw new IOException( "Unknown packet id " + packetId );
} else
{
readPacket( packetId, in, PacketDefinitions.VANILLA_PROTOCOL );
return;
}
}
for ( Instruction instruction : packetDef ) for ( Instruction instruction : packetDef )
{ {
instruction.read( in ); instruction.read( in );
} }
} }
public static void readPacket(ByteBuf in, int protocol) throws IOException
{
int packetId = in.readUnsignedByte();
readPacket( packetId, in, protocol );
} }
} }

View File

@ -1,7 +1,6 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class ShortHeader extends Instruction class ShortHeader extends Instruction
{ {
@ -14,7 +13,7 @@ class ShortHeader extends Instruction
} }
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
short size = in.readShort(); short size = in.readShort();
for ( short s = 0; s < size; s++ ) for ( short s = 0; s < size; s++ )

View File

@ -1,13 +1,12 @@
package net.md_5.bungee.protocol.netty; package net.md_5.bungee.protocol.skip;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.IOException;
class UnsignedShortByte extends Instruction class UnsignedShortByte extends Instruction
{ {
@Override @Override
void read(ByteBuf in) throws IOException void read(ByteBuf in)
{ {
int size = in.readUnsignedShort(); int size = in.readUnsignedShort();
in.skipBytes( size ); in.skipBytes( size );

View File

@ -30,7 +30,7 @@ public class PacketTest
Assert.assertTrue( "Packet " + clazz + " does not report correct id", packet.getId() == i ); Assert.assertTrue( "Packet " + clazz + " does not report correct id", packet.getId() == i );
Assert.assertTrue( "Packet " + clazz + " does not have custom hash code", packet.hashCode() != System.identityHashCode( packet ) ); Assert.assertTrue( "Packet " + clazz + " does not have custom hash code", packet.hashCode() != System.identityHashCode( packet ) );
Assert.assertTrue( "Packet " + clazz + " does not have custom toString", packet.toString().indexOf( '@' ) == -1 ); Assert.assertTrue( "Packet " + clazz + " does not have custom toString", packet.toString().indexOf( '@' ) == -1 );
Assert.assertTrue( "Packet " + clazz + " does not have package private no args constructor", clazz.getDeclaredConstructor().getModifiers() == 0 ); Assert.assertTrue( "Packet " + clazz + " does not have private no args constructor", Modifier.isPrivate( clazz.getDeclaredConstructor().getModifiers() ) );
for ( Field field : clazz.getDeclaredFields() ) for ( Field field : clazz.getDeclaredFields() )
{ {

View File

@ -54,7 +54,7 @@ import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.protocol.packet.DefinedPacket; import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.Packet3Chat; import net.md_5.bungee.protocol.packet.Packet3Chat;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
import net.md_5.bungee.protocol.PacketDefinitions; import net.md_5.bungee.protocol.Vanilla;
import net.md_5.bungee.scheduler.BungeeThreadPool; import net.md_5.bungee.scheduler.BungeeThreadPool;
import net.md_5.bungee.util.CaseInsensitiveMap; import net.md_5.bungee.util.CaseInsensitiveMap;
@ -444,13 +444,13 @@ public class BungeeCord extends ProxyServer
@Override @Override
public byte getProtocolVersion() public byte getProtocolVersion()
{ {
return PacketDefinitions.PROTOCOL_VERSION; return Vanilla.PROTOCOL_VERSION;
} }
@Override @Override
public String getGameVersion() public String getGameVersion()
{ {
return PacketDefinitions.GAME_VERSION; return Vanilla.GAME_VERSION;
} }
@Override @Override

View File

@ -37,7 +37,7 @@ import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest; import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.protocol.packet.PacketFFKick; import net.md_5.bungee.protocol.packet.PacketFFKick;
import net.md_5.bungee.protocol.packet.PacketHandler; import net.md_5.bungee.protocol.packet.PacketHandler;
import net.md_5.bungee.protocol.PacketDefinitions; import net.md_5.bungee.protocol.Vanilla;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ServerConnector extends PacketHandler public class ServerConnector extends PacketHandler
@ -144,7 +144,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.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == PacketDefinitions.FORGE_PROTOCOL ); ch.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == Vanilla.FORGE_PROTOCOL );
user.sendPacket( modLogin ); user.sendPacket( modLogin );
} else } else
{ {
@ -277,7 +277,7 @@ public class ServerConnector extends PacketHandler
if ( in.readByte() != 0 ) if ( in.readByte() != 0 )
{ {
// TODO: Using forge flag // TODO: Using forge flag
ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( PacketDefinitions.FORGE_PROTOCOL ); ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Vanilla.FORGE_PROTOCOL );
} }
} }

View File

@ -43,7 +43,7 @@ import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.protocol.packet.PacketFEPing; import net.md_5.bungee.protocol.packet.PacketFEPing;
import net.md_5.bungee.protocol.packet.PacketFFKick; import net.md_5.bungee.protocol.packet.PacketFFKick;
import net.md_5.bungee.protocol.packet.PacketHandler; import net.md_5.bungee.protocol.packet.PacketHandler;
import net.md_5.bungee.protocol.PacketDefinitions; import net.md_5.bungee.protocol.Vanilla;
@RequiredArgsConstructor @RequiredArgsConstructor
public class InitialHandler extends PacketHandler implements PendingConnection public class InitialHandler extends PacketHandler implements PendingConnection
@ -115,7 +115,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
Preconditions.checkState( forgeLogin == null, "Already received FORGE LOGIN" ); Preconditions.checkState( forgeLogin == null, "Already received FORGE LOGIN" );
forgeLogin = login; forgeLogin = login;
ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( PacketDefinitions.FORGE_PROTOCOL ); ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Vanilla.FORGE_PROTOCOL );
} }
@Override @Override

View File

@ -7,7 +7,7 @@ import io.netty.handler.codec.ReplayingDecoder;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.md_5.bungee.protocol.netty.PacketReader; import net.md_5.bungee.protocol.skip.PacketReader;
/** /**
* This class will attempt to read a packet from {@link PacketReader}, with the * This class will attempt to read a packet from {@link PacketReader}, with the

View File

@ -15,7 +15,7 @@ import net.md_5.bungee.UserConnection;
import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.protocol.PacketDefinitions; import net.md_5.bungee.protocol.Vanilla;
public class PipelineUtils public class PipelineUtils
{ {
@ -61,7 +61,7 @@ public class PipelineUtils
ch.pipeline().addLast( "outbound", new OutboundHandler() ); ch.pipeline().addLast( "outbound", new OutboundHandler() );
ch.pipeline().addLast( "timer", new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) ); ch.pipeline().addLast( "timer", new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
ch.pipeline().addLast( "decoder", new PacketDecoder( PacketDefinitions.VANILLA_PROTOCOL ) ); ch.pipeline().addLast( "decoder", new PacketDecoder( Vanilla.VANILLA_PROTOCOL ) );
ch.pipeline().addLast( "packet-encoder", packetEncoder ); ch.pipeline().addLast( "packet-encoder", packetEncoder );
ch.pipeline().addLast( "array-encoder", arrayEncoder ); ch.pipeline().addLast( "array-encoder", arrayEncoder );
ch.pipeline().addLast( "handler", new HandlerBoss() ); ch.pipeline().addLast( "handler", new HandlerBoss() );