Rework protocol system
This commit is contained in:
parent
ad4c143ce4
commit
2f45f0d578
25
protocol/src/main/java/net/md_5/bungee/protocol/Forge.java
Normal file
25
protocol/src/main/java/net/md_5/bungee/protocol/Forge.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
@ -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();
|
||||
}
|
@ -1,23 +1,125 @@
|
||||
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 String GAME_VERSION = "1.5.2";
|
||||
public static final OpCode[][] opCodes = new OpCode[ 512 ][];
|
||||
public static final int VANILLA_PROTOCOL = 0;
|
||||
public static final int FORGE_PROTOCOL = 256;
|
||||
public static final Vanilla INSTANCE = new Vanilla();
|
||||
/*========================================================================*/
|
||||
@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
|
||||
|
||||
{
|
||||
|
||||
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[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;
|
||||
}
|
||||
|
||||
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[]
|
||||
{
|
@ -1,51 +1,14 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
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;
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
return id;
|
||||
@ -103,25 +66,4 @@ public abstract class DefinedPacket
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class Packet0KeepAlive extends DefinedPacket
|
||||
|
||||
private int id;
|
||||
|
||||
Packet0KeepAlive()
|
||||
private Packet0KeepAlive()
|
||||
{
|
||||
super( 0x00 );
|
||||
}
|
||||
|
@ -9,15 +9,15 @@ import lombok.ToString;
|
||||
public class Packet1Login extends DefinedPacket
|
||||
{
|
||||
|
||||
private int entityId;
|
||||
private String levelType;
|
||||
private byte gameMode;
|
||||
private byte dimension;
|
||||
private byte difficulty;
|
||||
private byte unused;
|
||||
private byte maxPlayers;
|
||||
protected int entityId;
|
||||
protected String levelType;
|
||||
protected byte gameMode;
|
||||
protected int dimension;
|
||||
protected byte difficulty;
|
||||
protected byte unused;
|
||||
protected byte maxPlayers;
|
||||
|
||||
Packet1Login()
|
||||
protected Packet1Login()
|
||||
{
|
||||
super( 0x01 );
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class Packet2Handshake extends DefinedPacket
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
Packet2Handshake()
|
||||
private Packet2Handshake()
|
||||
{
|
||||
super( 0x02 );
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class Packet3Chat extends DefinedPacket
|
||||
|
||||
private String message;
|
||||
|
||||
Packet3Chat()
|
||||
private Packet3Chat()
|
||||
{
|
||||
super( 0x03 );
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class Packet9Respawn extends DefinedPacket
|
||||
private short worldHeight;
|
||||
private String levelType;
|
||||
|
||||
Packet9Respawn()
|
||||
private Packet9Respawn()
|
||||
{
|
||||
super( 0x09 );
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class PacketC9PlayerListItem extends DefinedPacket
|
||||
private boolean online;
|
||||
private int ping;
|
||||
|
||||
PacketC9PlayerListItem()
|
||||
private PacketC9PlayerListItem()
|
||||
{
|
||||
super( 0xC9 );
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class PacketCCSettings extends DefinedPacket
|
||||
private byte difficulty;
|
||||
private boolean showCape;
|
||||
|
||||
PacketCCSettings()
|
||||
private PacketCCSettings()
|
||||
{
|
||||
super( 0xCC );
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class PacketCDClientStatus extends DefinedPacket
|
||||
|
||||
private byte payload;
|
||||
|
||||
PacketCDClientStatus()
|
||||
private PacketCDClientStatus()
|
||||
{
|
||||
super( 0xCD );
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class PacketCEScoreboardObjective extends DefinedPacket
|
||||
*/
|
||||
private byte action;
|
||||
|
||||
PacketCEScoreboardObjective()
|
||||
private PacketCEScoreboardObjective()
|
||||
{
|
||||
super( 0xCE );
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class PacketCFScoreboardScore extends DefinedPacket
|
||||
private String scoreName;
|
||||
private int value;
|
||||
|
||||
PacketCFScoreboardScore()
|
||||
private PacketCFScoreboardScore()
|
||||
{
|
||||
super( 0xCF );
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class PacketD0DisplayScoreboard extends DefinedPacket
|
||||
private byte position;
|
||||
private String name;
|
||||
|
||||
PacketD0DisplayScoreboard()
|
||||
private PacketD0DisplayScoreboard()
|
||||
{
|
||||
super( 0xD0 );
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class PacketD1Team extends DefinedPacket
|
||||
private short playerCount;
|
||||
private String[] players;
|
||||
|
||||
PacketD1Team()
|
||||
private PacketD1Team()
|
||||
{
|
||||
super( 0xD1 );
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class PacketFAPluginMessage extends DefinedPacket
|
||||
private String tag;
|
||||
private byte[] data;
|
||||
|
||||
PacketFAPluginMessage()
|
||||
private PacketFAPluginMessage()
|
||||
{
|
||||
super( 0xFA );
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket
|
||||
private byte[] sharedSecret;
|
||||
private byte[] verifyToken;
|
||||
|
||||
PacketFCEncryptionResponse()
|
||||
private PacketFCEncryptionResponse()
|
||||
{
|
||||
super( 0xFC );
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket
|
||||
private byte[] publicKey;
|
||||
private byte[] verifyToken;
|
||||
|
||||
PacketFDEncryptionRequest()
|
||||
private PacketFDEncryptionRequest()
|
||||
{
|
||||
super( 0xFD );
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class PacketFEPing extends DefinedPacket
|
||||
|
||||
private byte version;
|
||||
|
||||
PacketFEPing()
|
||||
private PacketFEPing()
|
||||
{
|
||||
super( 0xFE );
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class PacketFFKick extends DefinedPacket
|
||||
|
||||
private String message;
|
||||
|
||||
PacketFFKick()
|
||||
private PacketFFKick()
|
||||
{
|
||||
super( 0xFF );
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BulkChunk extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
short count = in.readShort();
|
||||
int size = in.readInt();
|
@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class ByteHeader extends Instruction
|
||||
{
|
||||
@ -14,7 +13,7 @@ class ByteHeader extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
byte size = in.readByte();
|
||||
for ( byte b = 0; b < size; b++ )
|
@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
abstract class Instruction
|
||||
{
|
||||
@ -29,5 +28,5 @@ abstract class Instruction
|
||||
// Custom instructions
|
||||
static final Instruction STRING_ARRAY = new ShortHeader( STRING );
|
||||
|
||||
abstract void read(ByteBuf in) throws IOException;
|
||||
abstract void read(ByteBuf in);
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class IntHeader extends Instruction
|
||||
{
|
||||
@ -14,7 +13,7 @@ class IntHeader extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int size = in.readInt();
|
||||
for ( int i = 0; i < size; i++ )
|
@ -1,13 +1,12 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class Item extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
short type = in.readShort();
|
||||
if ( type >= 0 )
|
@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class Jump extends Instruction
|
||||
{
|
||||
@ -18,7 +17,7 @@ class Jump extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
in.skipBytes( len );
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class MetaData extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int x = in.readUnsignedByte();
|
||||
while ( x != 127 )
|
@ -1,13 +1,12 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class OptionalMotion extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int data = in.readInt();
|
||||
if ( data > 0 )
|
@ -1,24 +1,24 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions.OpCode;
|
||||
import net.md_5.bungee.protocol.OpCode;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
|
||||
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++ )
|
||||
{
|
||||
List<Instruction> output = new ArrayList<>();
|
||||
|
||||
OpCode[] enums = PacketDefinitions.opCodes[i];
|
||||
OpCode[] enums = protocol.getOpCodes()[i];
|
||||
if ( enums != null )
|
||||
{
|
||||
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;
|
||||
if ( packetId + protocol < instructions.length )
|
||||
{
|
||||
packetDef = instructions[packetId + protocol];
|
||||
}
|
||||
Instruction[] packetDef = instructions[packetId];
|
||||
|
||||
if ( packetDef == null )
|
||||
if ( packetDef != null )
|
||||
{
|
||||
if ( protocol == PacketDefinitions.VANILLA_PROTOCOL )
|
||||
for ( Instruction instruction : packetDef )
|
||||
{
|
||||
throw new IOException( "Unknown packet id " + packetId );
|
||||
} else
|
||||
{
|
||||
readPacket( packetId, in, PacketDefinitions.VANILLA_PROTOCOL );
|
||||
return;
|
||||
instruction.read( in );
|
||||
}
|
||||
}
|
||||
|
||||
for ( Instruction instruction : packetDef )
|
||||
{
|
||||
instruction.read( in );
|
||||
}
|
||||
}
|
||||
|
||||
public static void readPacket(ByteBuf in, int protocol) throws IOException
|
||||
{
|
||||
int packetId = in.readUnsignedByte();
|
||||
readPacket( packetId, in, protocol );
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class ShortHeader extends Instruction
|
||||
{
|
||||
@ -14,7 +13,7 @@ class ShortHeader extends Instruction
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
short size = in.readShort();
|
||||
for ( short s = 0; s < size; s++ )
|
@ -1,13 +1,12 @@
|
||||
package net.md_5.bungee.protocol.netty;
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.IOException;
|
||||
|
||||
class UnsignedShortByte extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in) throws IOException
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int size = in.readUnsignedShort();
|
||||
in.skipBytes( size );
|
@ -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 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 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() )
|
||||
{
|
||||
|
@ -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.Packet3Chat;
|
||||
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.util.CaseInsensitiveMap;
|
||||
|
||||
@ -444,13 +444,13 @@ public class BungeeCord extends ProxyServer
|
||||
@Override
|
||||
public byte getProtocolVersion()
|
||||
{
|
||||
return PacketDefinitions.PROTOCOL_VERSION;
|
||||
return Vanilla.PROTOCOL_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGameVersion()
|
||||
{
|
||||
return PacketDefinitions.GAME_VERSION;
|
||||
return Vanilla.GAME_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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.PacketFFKick;
|
||||
import net.md_5.bungee.protocol.packet.PacketHandler;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions;
|
||||
import net.md_5.bungee.protocol.Vanilla;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ServerConnector extends PacketHandler
|
||||
@ -144,7 +144,7 @@ public class ServerConnector extends PacketHandler
|
||||
login.difficulty,
|
||||
login.unused,
|
||||
(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 );
|
||||
} else
|
||||
{
|
||||
@ -277,7 +277,7 @@ public class ServerConnector extends PacketHandler
|
||||
if ( in.readByte() != 0 )
|
||||
{
|
||||
// TODO: Using forge flag
|
||||
ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( PacketDefinitions.FORGE_PROTOCOL );
|
||||
ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Vanilla.FORGE_PROTOCOL );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.PacketFFKick;
|
||||
import net.md_5.bungee.protocol.packet.PacketHandler;
|
||||
import net.md_5.bungee.protocol.PacketDefinitions;
|
||||
import net.md_5.bungee.protocol.Vanilla;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
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" );
|
||||
forgeLogin = login;
|
||||
|
||||
ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( PacketDefinitions.FORGE_PROTOCOL );
|
||||
ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Vanilla.FORGE_PROTOCOL );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,7 @@ import io.netty.handler.codec.ReplayingDecoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
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
|
||||
|
@ -15,7 +15,7 @@ import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.connection.InitialHandler;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
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
|
||||
{
|
||||
@ -61,7 +61,7 @@ public class PipelineUtils
|
||||
|
||||
ch.pipeline().addLast( "outbound", new OutboundHandler() );
|
||||
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( "array-encoder", arrayEncoder );
|
||||
ch.pipeline().addLast( "handler", new HandlerBoss() );
|
||||
|
Loading…
Reference in New Issue
Block a user