Finish and create passing unit tests for the integrity of all packet classes.
This commit is contained in:
parent
835e4e332c
commit
ad4c143ce4
@ -3,14 +3,19 @@ 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.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
public abstract class DefinedPacket
|
public abstract class DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
|
public static Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Constructor<? extends DefinedPacket>[] consructors = new Constructor[ 256 ];
|
private static Constructor<? extends DefinedPacket>[] consructors = new Constructor[ 256 ];
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
|
||||||
public static DefinedPacket packet(ByteBuf buf)
|
public static DefinedPacket packet(ByteBuf buf)
|
||||||
{
|
{
|
||||||
@ -31,9 +36,9 @@ public abstract class DefinedPacket
|
|||||||
|
|
||||||
if ( constructor != null )
|
if ( constructor != null )
|
||||||
{
|
{
|
||||||
ret = constructor.newInstance( buf );
|
ret = constructor.newInstance();
|
||||||
}
|
}
|
||||||
} catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex )
|
} catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,6 +46,11 @@ public abstract class DefinedPacket
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public void writeString(String s, ByteBuf buf)
|
public void writeString(String s, ByteBuf buf)
|
||||||
{
|
{
|
||||||
// TODO: Check len - use Guava?
|
// TODO: Check len - use Guava?
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
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 lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Packet0KeepAlive extends DefinedPacket
|
public class Packet0KeepAlive extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
|
Packet0KeepAlive()
|
||||||
|
{
|
||||||
|
super( 0x00 );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuf buf)
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
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 lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Packet1Login extends DefinedPacket
|
public class Packet1Login extends DefinedPacket
|
||||||
{
|
{
|
||||||
@ -21,6 +17,11 @@ public class Packet1Login extends DefinedPacket
|
|||||||
private byte unused;
|
private byte unused;
|
||||||
private byte maxPlayers;
|
private byte maxPlayers;
|
||||||
|
|
||||||
|
Packet1Login()
|
||||||
|
{
|
||||||
|
super( 0x01 );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuf buf)
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
|
@ -1,39 +1,40 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Packet2Handshake extends DefinedPacket
|
public class Packet2Handshake extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public byte procolVersion;
|
private byte procolVersion;
|
||||||
public String username;
|
private String username;
|
||||||
public String host;
|
private String host;
|
||||||
public int port;
|
private int port;
|
||||||
|
|
||||||
public Packet2Handshake(byte protocolVersion, String username, String host, int port)
|
Packet2Handshake()
|
||||||
{
|
{
|
||||||
super( 0x02 );
|
super( 0x02 );
|
||||||
writeByte( protocolVersion );
|
|
||||||
writeString( username );
|
|
||||||
writeString( host );
|
|
||||||
writeInt( port );
|
|
||||||
this.procolVersion = protocolVersion;
|
|
||||||
this.username = username;
|
|
||||||
this.host = host;
|
|
||||||
this.port = port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet2Handshake(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0x02, buf );
|
procolVersion = buf.readByte();
|
||||||
this.procolVersion = readByte();
|
username = readString( buf );
|
||||||
this.username = readUTF();
|
host = readString( buf );
|
||||||
this.host = readUTF();
|
port = buf.readInt();
|
||||||
this.port = readInt();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( procolVersion );
|
||||||
|
writeString( username, buf );
|
||||||
|
writeString( host, buf );
|
||||||
|
buf.writeInt( port );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Packet3Chat extends DefinedPacket
|
public class Packet3Chat extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String message;
|
private String message;
|
||||||
|
|
||||||
public Packet3Chat(String message)
|
Packet3Chat()
|
||||||
{
|
{
|
||||||
super( 0x03 );
|
super( 0x03 );
|
||||||
writeString( message );
|
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet3Chat(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0x03, buf );
|
message = readString( buf );
|
||||||
this.message = readUTF();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( message, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,45 +1,43 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Packet9Respawn extends DefinedPacket
|
public class Packet9Respawn extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
|
private int dimension;
|
||||||
public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
|
private byte difficulty;
|
||||||
public int dimension;
|
private byte gameMode;
|
||||||
public byte difficulty;
|
private short worldHeight;
|
||||||
public byte gameMode;
|
private String levelType;
|
||||||
public short worldHeight;
|
|
||||||
public String levelType;
|
|
||||||
|
|
||||||
public Packet9Respawn(int dimension, byte difficulty, byte gameMode, short worldHeight, String levelType)
|
Packet9Respawn()
|
||||||
{
|
{
|
||||||
super( 0x09 );
|
super( 0x09 );
|
||||||
writeInt( dimension );
|
|
||||||
writeByte( difficulty );
|
|
||||||
writeByte( gameMode );
|
|
||||||
writeShort( worldHeight );
|
|
||||||
writeString( levelType );
|
|
||||||
this.dimension = dimension;
|
|
||||||
this.difficulty = difficulty;
|
|
||||||
this.gameMode = gameMode;
|
|
||||||
this.worldHeight = worldHeight;
|
|
||||||
this.levelType = levelType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet9Respawn(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0x09, buf );
|
dimension = buf.readInt();
|
||||||
this.dimension = readInt();
|
difficulty = buf.readByte();
|
||||||
this.difficulty = readByte();
|
gameMode = buf.readByte();
|
||||||
this.gameMode = readByte();
|
worldHeight = buf.readShort();
|
||||||
this.worldHeight = readShort();
|
levelType = readString( buf );
|
||||||
this.levelType = readUTF();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeInt( dimension );
|
||||||
|
buf.writeByte( difficulty );
|
||||||
|
buf.writeByte( gameMode );
|
||||||
|
buf.writeShort( worldHeight );
|
||||||
|
writeString( levelType, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,32 +1,37 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketC9PlayerListItem extends DefinedPacket
|
public class PacketC9PlayerListItem extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String username;
|
private String username;
|
||||||
public boolean online;
|
private boolean online;
|
||||||
public int ping;
|
private int ping;
|
||||||
|
|
||||||
PacketC9PlayerListItem(byte[] buf)
|
PacketC9PlayerListItem()
|
||||||
{
|
|
||||||
super( 0xC9, buf );
|
|
||||||
username = readUTF();
|
|
||||||
online = readBoolean();
|
|
||||||
ping = readShort();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PacketC9PlayerListItem(String username, boolean online, int ping)
|
|
||||||
{
|
{
|
||||||
super( 0xC9 );
|
super( 0xC9 );
|
||||||
writeString( username );
|
}
|
||||||
writeBoolean( online );
|
|
||||||
writeShort( ping );
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
username = readString( buf );
|
||||||
|
online = buf.readBoolean();
|
||||||
|
ping = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( username, buf );
|
||||||
|
buf.writeBoolean( online );
|
||||||
|
buf.writeInt( ping );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,28 +1,43 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketCCSettings extends DefinedPacket
|
public class PacketCCSettings extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String locale;
|
private String locale;
|
||||||
public byte viewDistance;
|
private byte viewDistance;
|
||||||
public byte chatFlags;
|
private byte chatFlags;
|
||||||
public byte difficulty;
|
private byte difficulty;
|
||||||
public boolean showCape;
|
private boolean showCape;
|
||||||
|
|
||||||
public PacketCCSettings(byte[] buf)
|
PacketCCSettings()
|
||||||
{
|
{
|
||||||
super( 0xCC, buf );
|
super( 0xCC );
|
||||||
locale = readUTF();
|
}
|
||||||
viewDistance = readByte();
|
|
||||||
chatFlags = readByte();
|
@Override
|
||||||
difficulty = readByte();
|
public void read(ByteBuf buf)
|
||||||
showCape = readBoolean();
|
{
|
||||||
|
locale = readString( buf );
|
||||||
|
viewDistance = buf.readByte();
|
||||||
|
chatFlags = buf.readByte();
|
||||||
|
difficulty = buf.readByte();
|
||||||
|
showCape = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
locale = readString( buf );
|
||||||
|
buf.writeByte( viewDistance );
|
||||||
|
buf.writeByte( chatFlags );
|
||||||
|
buf.writeByte( difficulty );
|
||||||
|
buf.writeBoolean( showCape );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,34 +1,31 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketCDClientStatus extends DefinedPacket
|
public class PacketCDClientStatus extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
private byte payload;
|
||||||
* Represents the packet the client sends to the server when it is ready to
|
|
||||||
* login.
|
|
||||||
*/
|
|
||||||
public static PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 );
|
|
||||||
|
|
||||||
/**
|
PacketCDClientStatus()
|
||||||
* Sent from the client to the server upon respawn,
|
|
||||||
*
|
|
||||||
* @param payload 0 if initial spawn, 1 if respawn after death.
|
|
||||||
*/
|
|
||||||
public PacketCDClientStatus(byte payload)
|
|
||||||
{
|
{
|
||||||
super( 0xCD );
|
super( 0xCD );
|
||||||
writeByte( payload );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketCDClientStatus(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xCD, buf );
|
payload = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( payload );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,38 +1,40 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketCEScoreboardObjective extends DefinedPacket
|
public class PacketCEScoreboardObjective extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String name;
|
private String name;
|
||||||
public String text;
|
private String text;
|
||||||
/**
|
/**
|
||||||
* 0 to create, 1 to remove.
|
* 0 to create, 1 to remove.
|
||||||
*/
|
*/
|
||||||
public byte action;
|
private byte action;
|
||||||
|
|
||||||
public PacketCEScoreboardObjective(String name, String text, byte status)
|
PacketCEScoreboardObjective()
|
||||||
{
|
{
|
||||||
super( 0xCE );
|
super( 0xCE );
|
||||||
writeString( name );
|
|
||||||
writeString( text );
|
|
||||||
writeByte( status );
|
|
||||||
this.name = name;
|
|
||||||
this.text = text;
|
|
||||||
this.action = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketCEScoreboardObjective(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xCE, buf );
|
name = readString( buf );
|
||||||
this.name = readUTF();
|
text = readString( buf );
|
||||||
this.text = readUTF();
|
action = buf.readByte();
|
||||||
this.action = readByte();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( name, buf );
|
||||||
|
writeString( text, buf );
|
||||||
|
buf.writeByte( action );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,48 +1,49 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketCFScoreboardScore extends DefinedPacket
|
public class PacketCFScoreboardScore extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String itemName;
|
private String itemName;
|
||||||
/**
|
/**
|
||||||
* 0 = create / update, 1 = remove.
|
* 0 = create / update, 1 = remove.
|
||||||
*/
|
*/
|
||||||
public byte action;
|
private byte action;
|
||||||
public String scoreName;
|
private String scoreName;
|
||||||
public int value;
|
private int value;
|
||||||
|
|
||||||
public PacketCFScoreboardScore(byte[] buf)
|
PacketCFScoreboardScore()
|
||||||
{
|
{
|
||||||
super( 0xCF, buf );
|
super( 0xCF );
|
||||||
itemName = readUTF();
|
}
|
||||||
action = readByte();
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
itemName = readString( buf );
|
||||||
|
action = buf.readByte();
|
||||||
if ( action == 0 )
|
if ( action == 0 )
|
||||||
{
|
{
|
||||||
scoreName = readUTF();
|
scoreName = readString( buf );
|
||||||
value = readInt();
|
value = buf.readInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketCFScoreboardScore(String itemName, byte action, String scoreName, int value)
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xCF );
|
writeString( itemName, buf );
|
||||||
writeString( itemName );
|
buf.writeByte( action );
|
||||||
writeByte( action );
|
|
||||||
if ( action == 0 )
|
if ( action == 0 )
|
||||||
{
|
{
|
||||||
writeString( scoreName );
|
writeString( scoreName, buf );
|
||||||
writeInt( value );
|
buf.writeInt( value );
|
||||||
}
|
}
|
||||||
this.itemName = itemName;
|
|
||||||
this.action = action;
|
|
||||||
this.scoreName = scoreName;
|
|
||||||
this.value = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@ -12,14 +12,26 @@ public class PacketD0DisplayScoreboard extends DefinedPacket
|
|||||||
/**
|
/**
|
||||||
* 0 = list, 1 = side, 2 = below.
|
* 0 = list, 1 = side, 2 = below.
|
||||||
*/
|
*/
|
||||||
public byte position;
|
private byte position;
|
||||||
public String name;
|
private String name;
|
||||||
|
|
||||||
public PacketD0DisplayScoreboard(byte[] buf)
|
PacketD0DisplayScoreboard()
|
||||||
{
|
{
|
||||||
super( 0xD0, buf );
|
super( 0xD0 );
|
||||||
position = readByte();
|
}
|
||||||
name = readUTF();
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
position = buf.readByte();
|
||||||
|
name = readString( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( position );
|
||||||
|
writeString( name, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,59 +1,73 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketD1Team extends DefinedPacket
|
public class PacketD1Team extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 0 - create, 1 remove, 2 info update, 3 player add, 4 player remove.
|
* 0 - create, 1 remove, 2 info update, 3 player add, 4 player remove.
|
||||||
*/
|
*/
|
||||||
public byte mode;
|
private byte mode;
|
||||||
public String displayName;
|
private String displayName;
|
||||||
public String prefix;
|
private String prefix;
|
||||||
public String suffix;
|
private String suffix;
|
||||||
public byte friendlyFire;
|
private boolean friendlyFire;
|
||||||
public short playerCount;
|
private short playerCount;
|
||||||
public String[] players;
|
private String[] players;
|
||||||
|
|
||||||
public PacketD1Team(byte[] buf)
|
PacketD1Team()
|
||||||
{
|
|
||||||
super( 0xD1, buf );
|
|
||||||
name = readUTF();
|
|
||||||
mode = readByte();
|
|
||||||
if ( mode == 0 || mode == 2 )
|
|
||||||
{
|
|
||||||
displayName = readUTF();
|
|
||||||
prefix = readUTF();
|
|
||||||
suffix = readUTF();
|
|
||||||
friendlyFire = readByte();
|
|
||||||
}
|
|
||||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
|
||||||
{
|
|
||||||
players = new String[ readShort() ];
|
|
||||||
for ( int i = 0; i < players.length; i++ )
|
|
||||||
{
|
|
||||||
players[i] = readUTF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public PacketD1Team()
|
|
||||||
{
|
{
|
||||||
super( 0xD1 );
|
super( 0xD1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketD1Team destroy(String name)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
PacketD1Team packet = new PacketD1Team();
|
name = readString( buf );
|
||||||
packet.writeString( name );
|
mode = buf.readByte();
|
||||||
packet.writeByte( 1 );
|
if ( mode == 0 || mode == 2 )
|
||||||
return packet;
|
{
|
||||||
|
displayName = readString( buf );
|
||||||
|
prefix = readString( buf );
|
||||||
|
suffix = readString( buf );
|
||||||
|
friendlyFire = buf.readBoolean();
|
||||||
|
}
|
||||||
|
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||||
|
{
|
||||||
|
players = new String[ buf.readShort() ];
|
||||||
|
for ( int i = 0; i < players.length; i++ )
|
||||||
|
{
|
||||||
|
players[i] = readString( buf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( name, buf );
|
||||||
|
buf.writeByte( mode );
|
||||||
|
if ( mode == 0 || mode == 2 )
|
||||||
|
{
|
||||||
|
writeString( displayName, buf );
|
||||||
|
writeString( prefix, buf );
|
||||||
|
writeString( suffix, buf );
|
||||||
|
buf.writeBoolean( friendlyFire );
|
||||||
|
}
|
||||||
|
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||||
|
{
|
||||||
|
buf.writeShort( players.length );
|
||||||
|
for ( int i = 0; i < players.length; i++ )
|
||||||
|
{
|
||||||
|
writeString( players[i], buf );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,31 +1,34 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketFAPluginMessage extends DefinedPacket
|
public class PacketFAPluginMessage extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String tag;
|
private String tag;
|
||||||
public byte[] data;
|
private byte[] data;
|
||||||
|
|
||||||
public PacketFAPluginMessage(String tag, byte[] data)
|
PacketFAPluginMessage()
|
||||||
{
|
{
|
||||||
super( 0xFA );
|
super( 0xFA );
|
||||||
writeString( tag );
|
|
||||||
writeArray( data );
|
|
||||||
this.tag = tag;
|
|
||||||
this.data = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketFAPluginMessage(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xFA, buf );
|
tag = readString( buf );
|
||||||
this.tag = readUTF();
|
data = readArray( buf );
|
||||||
this.data = readArray();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( tag, buf );
|
||||||
|
writeArray( data, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,38 +1,34 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketFCEncryptionResponse extends DefinedPacket
|
public class PacketFCEncryptionResponse extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public byte[] sharedSecret;
|
private byte[] sharedSecret;
|
||||||
public byte[] verifyToken;
|
private byte[] verifyToken;
|
||||||
|
|
||||||
public PacketFCEncryptionResponse()
|
PacketFCEncryptionResponse()
|
||||||
{
|
{
|
||||||
super( 0xFC );
|
super( 0xFC );
|
||||||
writeArray( new byte[ 0 ] );
|
|
||||||
writeArray( new byte[ 0 ] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketFCEncryptionResponse(byte[] sharedSecret, byte[] verifyToken)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xFC );
|
sharedSecret = readArray( buf );
|
||||||
writeArray( sharedSecret );
|
verifyToken = readArray( buf );
|
||||||
writeArray( verifyToken );
|
|
||||||
this.sharedSecret = sharedSecret;
|
|
||||||
this.verifyToken = verifyToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketFCEncryptionResponse(byte[] buf)
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xFC, buf );
|
writeArray( sharedSecret, buf );
|
||||||
this.sharedSecret = readArray();
|
writeArray( verifyToken, buf );
|
||||||
this.verifyToken = readArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,34 +3,35 @@ package net.md_5.bungee.protocol.packet;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketFDEncryptionRequest extends DefinedPacket
|
public class PacketFDEncryptionRequest extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String serverId;
|
private String serverId;
|
||||||
public byte[] publicKey;
|
private byte[] publicKey;
|
||||||
public byte[] verifyToken;
|
private byte[] verifyToken;
|
||||||
|
|
||||||
public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken)
|
PacketFDEncryptionRequest()
|
||||||
{
|
{
|
||||||
super( 0xFD );
|
super( 0xFD );
|
||||||
writeString( serverId );
|
|
||||||
writeArray( publicKey );
|
|
||||||
writeArray( verifyToken );
|
|
||||||
this.serverId = serverId;
|
|
||||||
this.publicKey = publicKey;
|
|
||||||
this.verifyToken = verifyToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketFDEncryptionRequest(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xFD, buf );
|
serverId = readString( buf );
|
||||||
serverId = readUTF();
|
publicKey = readArray( buf );
|
||||||
publicKey = readArray();
|
verifyToken = readArray( buf );
|
||||||
verifyToken = readArray();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( serverId, buf );
|
||||||
|
writeArray( publicKey, buf );
|
||||||
|
writeArray( verifyToken, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,20 +1,31 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketFEPing extends DefinedPacket
|
public class PacketFEPing extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public byte version;
|
private byte version;
|
||||||
|
|
||||||
PacketFEPing(byte[] buffer)
|
PacketFEPing()
|
||||||
{
|
{
|
||||||
super( 0xFE, buffer );
|
super( 0xFE );
|
||||||
version = readByte();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
version = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( version );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,26 +1,31 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.packet.PacketHandler;
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class PacketFFKick extends DefinedPacket
|
public class PacketFFKick extends DefinedPacket
|
||||||
{
|
{
|
||||||
|
|
||||||
public String message;
|
private String message;
|
||||||
|
|
||||||
public PacketFFKick(String message)
|
PacketFFKick()
|
||||||
{
|
{
|
||||||
super( 0xFF );
|
super( 0xFF );
|
||||||
writeString( message );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketFFKick(byte[] buf)
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
{
|
{
|
||||||
super( 0xFF, buf );
|
message = readString( buf );
|
||||||
this.message = readUTF();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( message, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,38 +1,11 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
import net.md_5.bungee.protocol.packet.Packet1Login;
|
|
||||||
import net.md_5.bungee.protocol.packet.Packet3Chat;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketFEPing;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketFFKick;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
|
|
||||||
import net.md_5.bungee.protocol.packet.Packet2Handshake;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketCCSettings;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective;
|
|
||||||
import net.md_5.bungee.protocol.packet.Packet9Respawn;
|
|
||||||
import net.md_5.bungee.protocol.packet.PacketD1Team;
|
|
||||||
import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
|
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
|
||||||
|
|
||||||
public abstract class PacketHandler
|
public abstract class PacketHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract String toString();
|
public abstract String toString();
|
||||||
|
|
||||||
public void connected(ChannelWrapper channel) throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnected(ChannelWrapper channel) throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exception(Throwable t) throws Exception
|
public void exception(Throwable t) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PacketTest
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPackets() throws NoSuchMethodException
|
||||||
|
{
|
||||||
|
for ( short i = 0; i < 256; i++ )
|
||||||
|
{
|
||||||
|
ByteBuf buf = Unpooled.wrappedBuffer( new byte[]
|
||||||
|
{
|
||||||
|
(byte) i
|
||||||
|
} );
|
||||||
|
Class<? extends DefinedPacket> clazz = DefinedPacket.classes[i];
|
||||||
|
if ( clazz != null )
|
||||||
|
{
|
||||||
|
Assert.assertTrue( "Packet " + clazz + " is not public", Modifier.isPublic( clazz.getModifiers() ) );
|
||||||
|
DefinedPacket packet = DefinedPacket.packet( buf );
|
||||||
|
Assert.assertTrue( "Could not create packet with id " + i + " and class " + clazz, packet != null );
|
||||||
|
Assert.assertTrue( "Packet with id " + i + " does not have correct class (expected " + clazz + " but got " + packet.getClass(), packet.getClass() == clazz );
|
||||||
|
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 );
|
||||||
|
|
||||||
|
for ( Field field : clazz.getDeclaredFields() )
|
||||||
|
{
|
||||||
|
Assert.assertTrue( "Packet " + clazz + " has non private field " + field, Modifier.isPrivate( field.getModifiers() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ public class DefinedPacketEncoder extends MessageToByteEncoder<DefinedPacket>
|
|||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception
|
protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception
|
||||||
{
|
{
|
||||||
out.writeBytes( msg.getPacket() );
|
out.writeByte( msg.getId() );
|
||||||
|
msg.write( out );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java
Normal file
13
proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package net.md_5.bungee.netty;
|
||||||
|
|
||||||
|
public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.PacketHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public void connected(ChannelWrapper channel) throws Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnected(ChannelWrapper channel) throws Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user