[TESTING] Merge protocol api into master. This should provide slightly better performance and allow more flexibility for plugin developers.

This commit is contained in:
md_5 2013-05-31 16:53:41 +10:00
commit 9fd69068ae
78 changed files with 1486 additions and 1296 deletions

View File

@ -14,7 +14,7 @@ public class Team
private String displayName;
private String prefix;
private String suffix;
private byte friendlyMode;
private boolean friendlyFire;
private Set<String> players = new HashSet<>();
public Collection<String> getPlayers()

View File

@ -0,0 +1,33 @@
package net.md_5.bungee.protocol;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.forge.Forge1Login;
import net.md_5.bungee.protocol.skip.PacketReader;
public class Forge extends Vanilla
{
@Getter
private static final Forge instance = new Forge();
public Forge()
{
classes[0x01] = Forge1Login.class;
skipper = new PacketReader( this ); // TODO: :(
}
@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,40 +1,128 @@
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;
@Getter
private static final Vanilla instance = new Vanilla();
/*========================================================================*/
@Getter
private final OpCode[][] opCodes = new OpCode[ 256 ][];
@SuppressWarnings("unchecked")
@Getter
protected Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
@SuppressWarnings("unchecked")
@Getter
private Constructor<? extends DefinedPacket>[] constructors = new Constructor[ 256 ];
@Getter
protected PacketReader skipper;
/*========================================================================*/
public enum OpCode
public Vanilla()
{
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SCORE, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, TEAM, 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;
skipper = new PacketReader( this );
}
static
@Override
public DefinedPacket read(short packetId, ByteBuf buf)
{
opCodes[0x00] = new OpCode[]
int start = buf.readerIndex();
DefinedPacket packet = read( packetId, buf, this );
if ( buf.readerIndex() == start )
{
INT
};
opCodes[0x01] = new OpCode[]
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 )
{
INT, STRING, BYTE, BYTE, BYTE, BYTE, BYTE
};
opCodes[0x02] = new OpCode[]
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 )
{
BYTE, STRING, STRING, INT
};
opCodes[0x03] = new OpCode[]
{
STRING
};
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[]
{
LONG, LONG
@ -55,10 +143,6 @@ public class PacketDefinitions
{
SHORT, SHORT, FLOAT
};
opCodes[0x09] = new OpCode[]
{
INT, BYTE, BYTE, SHORT, STRING
};
opCodes[0x0A] = new OpCode[]
{
BOOLEAN
@ -283,10 +367,6 @@ public class PacketDefinitions
{
INT, BYTE
};
opCodes[0xC9] = new OpCode[]
{
STRING, BOOLEAN, SHORT
};
opCodes[0xCA] = new OpCode[]
{
BYTE, BYTE, BYTE
@ -295,54 +375,5 @@ public class PacketDefinitions
{
STRING
};
opCodes[0xCC] = new OpCode[]
{
STRING, BYTE, BYTE, BYTE, BOOLEAN
};
opCodes[0xCD] = new OpCode[]
{
BYTE
};
opCodes[0xCE] = new OpCode[]
{
STRING, STRING, BYTE
};
opCodes[0xCF] = new OpCode[]
{
SCORE
};
opCodes[0xD0] = new OpCode[]
{
BYTE, STRING
};
opCodes[0xD1] = new OpCode[]
{
TEAM
};
opCodes[0xFA] = new OpCode[]
{
STRING, SHORT_BYTE
};
opCodes[0xFC] = new OpCode[]
{
SHORT_BYTE, SHORT_BYTE
};
opCodes[0xFD] = new OpCode[]
{
STRING, SHORT_BYTE, SHORT_BYTE
};
opCodes[0xFE] = new OpCode[]
{
BYTE
};
opCodes[0xFF] = new OpCode[]
{
STRING
};
/*========================== Minecraft Forge ===========================*/
opCodes[0x01 + FORGE_PROTOCOL] = new OpCode[]
{
INT, STRING, BYTE, INT, BYTE, BYTE, BYTE
};
}
}

View File

@ -1,19 +0,0 @@
package net.md_5.bungee.protocol.netty;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class Score extends Instruction
{
@Override
void read(ByteBuf in) throws IOException
{
STRING.read( in );
if ( in.readByte() == 0 )
{
STRING.read( in );
INT.read( in );
}
}
}

View File

@ -1,26 +0,0 @@
package net.md_5.bungee.protocol.netty;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
class Team extends Instruction
{
@Override
void read(ByteBuf in) throws IOException
{
STRING.read( in );
byte mode = in.readByte();
if ( mode == 0 || mode == 2 )
{
STRING.read( in );
STRING.read( in );
STRING.read( in );
BYTE.read( in );
}
if ( mode == 0 || mode == 3 || mode == 4 )
{
STRING_ARRAY.read( in );
}
}
}

View File

@ -1,29 +1,8 @@
package net.md_5.bungee.packet;
package net.md_5.bungee.protocol.packet;
import net.md_5.bungee.netty.ChannelWrapper;
public abstract class PacketHandler
public abstract class AbstractPacketHandler
{
@Override
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 handle(byte[] buf) throws Exception
{
}
public void handle(Packet0KeepAlive alive) throws Exception
{
}

View File

@ -0,0 +1,69 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public abstract class DefinedPacket
{
private final int id;
public final int getId()
{
return id;
}
public void writeString(String s, ByteBuf buf)
{
// TODO: Check len - use Guava?
buf.writeShort( s.length() );
for ( char c : s.toCharArray() )
{
buf.writeChar( c );
}
}
public String readString(ByteBuf buf)
{
// TODO: Check len - use Guava?
short len = buf.readShort();
char[] chars = new char[ len ];
for ( int i = 0; i < len; i++ )
{
chars[i] = buf.readChar();
}
return new String( chars );
}
public void writeArray(byte[] b, ByteBuf buf)
{
// TODO: Check len - use Guava?
buf.writeShort( b.length );
buf.writeBytes( b );
}
public byte[] readArray(ByteBuf buf)
{
// TODO: Check len - use Guava?
short len = buf.readShort();
byte[] ret = new byte[ len ];
buf.readBytes( ret );
return ret;
}
public abstract void read(ByteBuf buf);
public abstract void write(ByteBuf buf);
public abstract void handle(AbstractPacketHandler handler) throws Exception;
@Override
public abstract boolean equals(Object obj);
@Override
public abstract int hashCode();
@Override
public abstract String toString();
}

View File

@ -0,0 +1,38 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet0KeepAlive extends DefinedPacket
{
private int randomId;
private Packet0KeepAlive()
{
super( 0x00 );
}
@Override
public void read(ByteBuf buf)
{
randomId = buf.readInt();
}
@Override
public void write(ByteBuf buf)
{
buf.writeInt( randomId );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,73 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet1Login extends DefinedPacket
{
protected int entityId;
protected String levelType;
protected byte gameMode;
protected int dimension;
protected byte difficulty;
protected byte unused;
protected byte maxPlayers;
protected Packet1Login()
{
super( 0x01 );
}
public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers)
{
this( entityId, levelType, gameMode, (int) dimension, difficulty, unused, maxPlayers );
}
public Packet1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers)
{
this();
this.entityId = entityId;
this.levelType = levelType;
this.gameMode = gameMode;
this.dimension = dimension;
this.difficulty = difficulty;
this.unused = unused;
this.maxPlayers = maxPlayers;
}
@Override
public void read(ByteBuf buf)
{
entityId = buf.readInt();
levelType = readString( buf );
gameMode = buf.readByte();
dimension = buf.readByte();
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.writeByte( dimension );
buf.writeByte( difficulty );
buf.writeByte( unused );
buf.writeByte( maxPlayers );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,47 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet2Handshake extends DefinedPacket
{
private byte procolVersion;
private String username;
private String host;
private int port;
private Packet2Handshake()
{
super( 0x02 );
}
@Override
public void read(ByteBuf buf)
{
procolVersion = buf.readByte();
username = readString( buf );
host = readString( buf );
port = buf.readInt();
}
@Override
public void write(ByteBuf buf)
{
buf.writeByte( procolVersion );
writeString( username, buf );
writeString( host, buf );
buf.writeInt( port );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,44 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet3Chat extends DefinedPacket
{
private String message;
private Packet3Chat()
{
super( 0x03 );
}
public Packet3Chat(String message)
{
this();
this.message = message;
}
@Override
public void read(ByteBuf buf)
{
message = readString( buf );
}
@Override
public void write(ByteBuf buf)
{
writeString( message, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,58 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet9Respawn extends DefinedPacket
{
private int dimension;
private byte difficulty;
private byte gameMode;
private short worldHeight;
private String levelType;
private Packet9Respawn()
{
super( 0x09 );
}
public Packet9Respawn(int dimension, byte difficulty, byte gameMode, short worldHeight, String levelType)
{
this();
this.dimension = dimension;
this.difficulty = difficulty;
this.gameMode = gameMode;
this.worldHeight = worldHeight;
this.levelType = levelType;
}
@Override
public void read(ByteBuf buf)
{
dimension = buf.readInt();
difficulty = buf.readByte();
gameMode = buf.readByte();
worldHeight = buf.readShort();
levelType = readString( buf );
}
@Override
public void write(ByteBuf buf)
{
buf.writeInt( dimension );
buf.writeByte( difficulty );
buf.writeByte( gameMode );
buf.writeShort( worldHeight );
writeString( levelType, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,52 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketC9PlayerListItem extends DefinedPacket
{
private String username;
private boolean online;
private short ping;
private PacketC9PlayerListItem()
{
super( 0xC9 );
}
public PacketC9PlayerListItem(String username, boolean online, short ping)
{
super( 0xC9 );
this.username = username;
this.online = online;
this.ping = ping;
}
@Override
public void read(ByteBuf buf)
{
username = readString( buf );
online = buf.readBoolean();
ping = buf.readShort();
}
@Override
public void write(ByteBuf buf)
{
writeString( username, buf );
buf.writeBoolean( online );
buf.writeShort(ping );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,48 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCCSettings extends DefinedPacket
{
private String locale;
private byte viewDistance;
private byte chatFlags;
private byte difficulty;
private boolean showCape;
private PacketCCSettings()
{
super( 0xCC );
}
@Override
public void read(ByteBuf buf)
{
locale = readString( buf );
viewDistance = buf.readByte();
chatFlags = buf.readByte();
difficulty = buf.readByte();
showCape = buf.readBoolean();
}
@Override
public void write(ByteBuf buf)
{
writeString( locale, buf );
buf.writeByte( viewDistance );
buf.writeByte( chatFlags );
buf.writeByte( difficulty );
buf.writeBoolean( showCape );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,42 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCDClientStatus extends DefinedPacket
{
private byte payload;
private PacketCDClientStatus()
{
super( 0xCD );
}
public PacketCDClientStatus(byte payload)
{
this();
this.payload = payload;
}
@Override
public void read(ByteBuf buf)
{
payload = buf.readByte();
}
@Override
public void write(ByteBuf buf)
{
buf.writeByte( payload );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,55 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCEScoreboardObjective extends DefinedPacket
{
private String name;
private String text;
/**
* 0 to create, 1 to remove.
*/
private byte action;
private PacketCEScoreboardObjective()
{
super( 0xCE );
}
public PacketCEScoreboardObjective(String name, String text, byte action)
{
this();
this.name = name;
this.text = text;
this.action = action;
}
@Override
public void read(ByteBuf buf)
{
name = readString( buf );
text = readString( buf );
action = buf.readByte();
}
@Override
public void write(ByteBuf buf)
{
writeString( name, buf );
writeString( text, buf );
buf.writeByte( action );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,56 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCFScoreboardScore extends DefinedPacket
{
private String itemName;
/**
* 0 = create / update, 1 = remove.
*/
private byte action;
private String scoreName;
private int value;
private PacketCFScoreboardScore()
{
super( 0xCF );
}
@Override
public void read(ByteBuf buf)
{
itemName = readString( buf );
action = buf.readByte();
if ( action == 0 )
{
scoreName = readString( buf );
value = buf.readInt();
}
}
@Override
public void write(ByteBuf buf)
{
writeString( itemName, buf );
buf.writeByte( action );
if ( action == 0 )
{
writeString( scoreName, buf );
buf.writeInt( value );
}
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,44 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketD0DisplayScoreboard extends DefinedPacket
{
/**
* 0 = list, 1 = side, 2 = below.
*/
private byte position;
private String name;
private PacketD0DisplayScoreboard()
{
super( 0xD0 );
}
@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
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,91 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketD1Team extends DefinedPacket
{
private String name;
/**
* 0 - create, 1 remove, 2 info update, 3 player add, 4 player remove.
*/
private byte mode;
private String displayName;
private String prefix;
private String suffix;
private boolean friendlyFire;
private short playerCount;
private String[] players;
private PacketD1Team()
{
super( 0xD1 );
}
/**
* Packet to destroy a team.
*
* @param name
*/
public PacketD1Team(String name)
{
this();
mode = 1;
}
@Override
public void read(ByteBuf buf)
{
name = readString( buf );
mode = buf.readByte();
if ( getMode() == 0 || getMode() == 2 )
{
displayName = readString( buf );
prefix = readString( buf );
suffix = readString( buf );
friendlyFire = buf.readBoolean();
}
if ( getMode() == 0 || getMode() == 3 || getMode() == 4 )
{
players = new String[ buf.readShort() ];
for ( int i = 0; i < getPlayers().length; i++ )
{
players[i] = readString( buf );
}
}
}
@Override
public void write(ByteBuf buf)
{
writeString( getName(), buf );
buf.writeByte( getMode() );
if ( getMode() == 0 || getMode() == 2 )
{
writeString( getDisplayName(), buf );
writeString( getPrefix(), buf );
writeString( getSuffix(), buf );
buf.writeBoolean( isFriendlyFire() );
}
if ( getMode() == 0 || getMode() == 3 || getMode() == 4 )
{
buf.writeShort( getPlayers().length );
for ( int i = 0; i < getPlayers().length; i++ )
{
writeString( getPlayers()[i], buf );
}
}
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,48 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFAPluginMessage extends DefinedPacket
{
private String tag;
private byte[] data;
private PacketFAPluginMessage()
{
super( 0xFA );
}
public PacketFAPluginMessage(String tag, byte[] data)
{
this();
this.tag = tag;
this.data = data;
}
@Override
public void read(ByteBuf buf)
{
tag = readString( buf );
data = readArray( buf );
}
@Override
public void write(ByteBuf buf)
{
writeString( tag, buf );
writeArray( data, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,48 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFCEncryptionResponse extends DefinedPacket
{
private byte[] sharedSecret;
private byte[] verifyToken;
private PacketFCEncryptionResponse()
{
super( 0xFC );
}
public PacketFCEncryptionResponse(byte[] sharedSecret, byte[] verifyToken)
{
this();
this.sharedSecret = sharedSecret;
this.verifyToken = verifyToken;
}
@Override
public void read(ByteBuf buf)
{
sharedSecret = readArray( buf );
verifyToken = readArray( buf );
}
@Override
public void write(ByteBuf buf)
{
writeArray( sharedSecret, buf );
writeArray( verifyToken, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,52 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFDEncryptionRequest extends DefinedPacket
{
private String serverId;
private byte[] publicKey;
private byte[] verifyToken;
private PacketFDEncryptionRequest()
{
super( 0xFD );
}
public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken)
{
this();
this.serverId = serverId;
this.publicKey = publicKey;
this.verifyToken = verifyToken;
}
@Override
public void read(ByteBuf buf)
{
serverId = readString( buf );
publicKey = readArray( buf );
verifyToken = readArray( buf );
}
@Override
public void write(ByteBuf buf)
{
writeString( serverId, buf );
writeArray( publicKey, buf );
writeArray( verifyToken, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,36 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFEPing extends DefinedPacket
{
private byte version;
private PacketFEPing()
{
super( 0xFE );
}
@Override
public void read(ByteBuf buf)
{
version = buf.readByte();
}
@Override
public void write(ByteBuf buf)
{
buf.writeByte( version );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,44 @@
package net.md_5.bungee.protocol.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFFKick extends DefinedPacket
{
private String message;
private PacketFFKick()
{
super( 0xFF );
}
public PacketFFKick(String message)
{
this();
this.message = message;
}
@Override
public void read(ByteBuf buf)
{
message = readString( buf );
}
@Override
public void write(ByteBuf buf)
{
writeString( message, buf );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -0,0 +1,47 @@
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
{
public Forge1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers)
{
super( entityId, levelType, gameMode, dimension, difficulty, unused, maxPlayers );
}
@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(AbstractPacketHandler 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 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();

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 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++ )

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 java.io.IOException;
abstract class Instruction
{
@ -19,17 +18,15 @@ abstract class Instruction
static final Instruction LONG = new Jump( 8 );
static final Instruction METADATA = new MetaData();
static final Instruction OPTIONAL_MOTION = new OptionalMotion();
static final Instruction SCORE = new Score();
static final Instruction SHORT = new Jump( 2 );
static final Instruction SHORT_BYTE = new ShortHeader( BYTE );
static final Instruction SHORT_ITEM = new ShortHeader( ITEM );
static final Instruction STRING = new ShortHeader( new Jump( 2 ) );
static final Instruction TEAM = new Team();
static final Instruction USHORT_BYTE = new UnsignedShortByte();
// Illegal forward references below this line
static final Instruction BYTE_INT = new ByteHeader( INT );
// Custom instructions
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 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++ )

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 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 )

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 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 );
}

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 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 )

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 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 )

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 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 );
}
}

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 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++ )

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 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 );

View File

@ -0,0 +1,45 @@
package net.md_5.bungee.protocol;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import net.md_5.bungee.protocol.packet.AbstractPacketHandler;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import org.junit.Assert;
import org.junit.Test;
public class PacketTest
{
@Test
public void testPackets() throws Exception
{
AbstractPacketHandler handler = new AbstractPacketHandler()
{
};
for ( short i = 0; i < 256; i++ )
{
Class<? extends DefinedPacket> clazz = Vanilla.getInstance().getClasses()[ i];
if ( clazz != null )
{
Assert.assertTrue( "Packet " + clazz + " is not public", Modifier.isPublic( clazz.getModifiers() ) );
DefinedPacket packet = Vanilla.packet( i, Vanilla.getInstance() );
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 );
// TODO: Enable this test again in v2
// Assert.assertTrue( "Packet " + clazz + " does not have private no args constructor", Modifier.isPrivate( clazz.getDeclaredConstructor().getModifiers() ) );
for ( Field field : clazz.getDeclaredFields() )
{
// TODO: Enable this test again in v2
// Assert.assertTrue( "Packet " + clazz + " has non private field " + field, Modifier.isPrivate( field.getModifiers() ) );
}
packet.handle( handler ); // Make sure there are no exceptions
}
}
}
}

View File

@ -0,0 +1,14 @@
package net.md_5.bungee.protocol;
import org.junit.Assert;
import org.junit.Test;
public class ProtocolTest
{
@Test
public void testProtocol()
{
Assert.assertFalse( "Protocols should have different login packet", Vanilla.getInstance().getClasses()[0x01] == Forge.getInstance().classes[0x01] );
}
}

View File

@ -51,10 +51,10 @@ import net.md_5.bungee.api.scheduler.TaskScheduler;
import net.md_5.bungee.command.*;
import net.md_5.bungee.config.YamlConfig;
import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.Packet3Chat;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.protocol.PacketDefinitions;
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.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

View File

@ -25,8 +25,8 @@ import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.connection.PingHandler;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
@RequiredArgsConstructor
public class BungeeServerInfo implements ServerInfo

View File

@ -15,8 +15,8 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import lombok.Getter;
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
/**
* Class containing all encryption related methods for the proxy.
@ -53,18 +53,15 @@ public class EncryptionUtil
{
Cipher cipher = Cipher.getInstance( "RSA" );
cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() );
byte[] decrypted = cipher.doFinal( resp.verifyToken );
byte[] decrypted = cipher.doFinal( resp.getVerifyToken() );
if ( !Arrays.equals( request.verifyToken, decrypted ) )
if ( !Arrays.equals( request.getVerifyToken(), decrypted ) )
{
throw new IllegalStateException( "Key pairs do not match!" );
}
cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() );
byte[] shared = resp.sharedSecret;
byte[] secret = cipher.doFinal( shared );
return new SecretKeySpec( secret, "AES" );
return new SecretKeySpec( cipher.doFinal( resp.getSharedSecret() ), "AES" );
}
public static Cipher getCipher(int opMode, Key shared) throws GeneralSecurityException
@ -76,7 +73,7 @@ public class EncryptionUtil
public static PublicKey getPubkey(PacketFDEncryptionRequest request) throws GeneralSecurityException
{
return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.publicKey ) );
return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.getPublicKey() ) );
}
public static byte[] encrypt(Key key, byte[] b) throws GeneralSecurityException

View File

@ -0,0 +1,12 @@
package net.md_5.bungee;
import net.md_5.bungee.protocol.packet.Packet9Respawn;
import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
public class PacketConstants
{
public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
public static final PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 );
}

View File

@ -7,8 +7,8 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
import net.md_5.bungee.protocol.packet.PacketFFKick;
@RequiredArgsConstructor
public class ServerConnection implements Server

View File

@ -26,18 +26,18 @@ import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.CipherDecoder;
import net.md_5.bungee.netty.CipherEncoder;
import net.md_5.bungee.netty.PacketDecoder;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.Packet1Login;
import net.md_5.bungee.packet.Packet9Respawn;
import net.md_5.bungee.packet.PacketCDClientStatus;
import net.md_5.bungee.packet.PacketCEScoreboardObjective;
import net.md_5.bungee.packet.PacketD1Team;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketHandler;
import net.md_5.bungee.protocol.PacketDefinitions;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.Forge;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.Packet1Login;
import net.md_5.bungee.protocol.packet.Packet9Respawn;
import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective;
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.PacketFFKick;
import net.md_5.bungee.protocol.packet.forge.Forge1Login;
@RequiredArgsConstructor
public class ServerConnector extends PacketHandler
@ -60,7 +60,7 @@ public class ServerConnector extends PacketHandler
@Override
public void exception(Throwable t) throws Exception
{
String message = "Exception Connectiong:" + Util.exception( t );
String message = "Exception Connecting:" + Util.exception( t );
if ( user.getServer() == null )
{
user.disconnect( message );
@ -86,7 +86,7 @@ public class ServerConnector extends PacketHandler
// Skip encryption if we are not using Forge
if ( user.getPendingConnection().getForgeLogin() == null )
{
channel.write( PacketCDClientStatus.CLIENT_LOGIN );
channel.write( PacketConstants.CLIENT_LOGIN );
}
}
@ -133,18 +133,20 @@ public class ServerConnector extends PacketHandler
if ( user.getServer() == null )
{
// Once again, first connection
user.setClientEntityId( login.entityId );
user.setServerEntityId( login.entityId );
// Set tab list size
Packet1Login modLogin = new Packet1Login(
login.entityId,
login.levelType,
login.gameMode,
(byte) login.dimension,
login.difficulty,
login.unused,
(byte) user.getPendingConnection().getListener().getTabListSize(),
ch.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == PacketDefinitions.FORGE_PROTOCOL );
user.setClientEntityId( login.getEntityId() );
user.setServerEntityId( login.getEntityId() );
// Set tab list size, this sucks balls, TODO: what shall we do about packet mutability
Packet1Login modLogin;
if ( ch.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == Forge.getInstance() )
{
modLogin = new Forge1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), login.getDimension(), login.getDifficulty(), login.getUnused(),
(byte) user.getPendingConnection().getListener().getTabListSize() );
} else
{
modLogin = new Packet1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(),
(byte) user.getPendingConnection().getListener().getTabListSize() );
}
user.sendPacket( modLogin );
} else
{
@ -157,15 +159,14 @@ public class ServerConnector extends PacketHandler
}
for ( Team team : serverScoreboard.getTeams() )
{
user.sendPacket( PacketD1Team.destroy( team.getName() ) );
user.sendPacket( new PacketD1Team( team.getName() ) );
}
serverScoreboard.clear();
user.sendPacket( Packet9Respawn.DIM1_SWITCH );
user.sendPacket( Packet9Respawn.DIM2_SWITCH );
user.sendDimensionSwitch();
user.setServerEntityId( login.entityId );
user.sendPacket( new Packet9Respawn( login.dimension, login.difficulty, login.gameMode, (short) 256, login.levelType ) );
user.setServerEntityId( login.getEntityId() );
user.sendPacket( new Packet9Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) );
// Remove from old servers
user.getServer().setObsolete( true );
@ -209,7 +210,7 @@ public class ServerConnector extends PacketHandler
this.secretkey = EncryptionUtil.getSecret();
byte[] shared = EncryptionUtil.encrypt( publickey, secretkey.getEncoded() );
byte[] token = EncryptionUtil.encrypt( publickey, encryptRequest.verifyToken );
byte[] token = EncryptionUtil.encrypt( publickey, encryptRequest.getVerifyToken() );
ch.write( new PacketFCEncryptionResponse( shared, token ) );
@ -233,7 +234,7 @@ public class ServerConnector extends PacketHandler
ch.write( user.getPendingConnection().getForgeLogin() );
ch.write( PacketCDClientStatus.CLIENT_LOGIN );
ch.write( PacketConstants.CLIENT_LOGIN );
thisState = State.LOGIN;
}
@ -245,14 +246,14 @@ public class ServerConnector extends PacketHandler
{
def = null;
}
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( user, kick.message, def ) );
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( user, kick.getMessage(), def ) );
if ( event.isCancelled() && event.getCancelServer() != null )
{
user.connect( event.getCancelServer() );
return;
}
String message = bungee.getTranslation( "connect_kick" ) + target.getName() + ": " + kick.message;
String message = bungee.getTranslation( "connect_kick" ) + target.getName() + ": " + kick.getMessage();
if ( user.getServer() == null )
{
user.disconnect( message );
@ -265,9 +266,9 @@ public class ServerConnector extends PacketHandler
@Override
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
{
if ( ( pluginMessage.data[0] & 0xFF ) == 0 && pluginMessage.tag.equals( "FML" ) )
if ( ( pluginMessage.getData()[0] & 0xFF ) == 0 && pluginMessage.getTag().equals( "FML" ) )
{
ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.data );
ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() );
in.readUnsignedByte();
int count = in.readInt();
for ( int i = 0; i < count; i++ )
@ -277,7 +278,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( Forge.getInstance() );
}
}

View File

@ -30,12 +30,11 @@ import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.Packet3Chat;
import net.md_5.bungee.packet.Packet9Respawn;
import net.md_5.bungee.packet.PacketCCSettings;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.Packet3Chat;
import net.md_5.bungee.protocol.packet.PacketCCSettings;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
import net.md_5.bungee.protocol.packet.PacketFFKick;
import net.md_5.bungee.util.CaseInsensitiveSet;
@RequiredArgsConstructor
@ -133,10 +132,15 @@ public final class UserConnection implements ProxiedPlayer
connect( target, false );
}
void sendDimensionSwitch()
{
sendPacket( PacketConstants.DIM1_SWITCH );
sendPacket( PacketConstants.DIM2_SWITCH );
}
public void connectNow(ServerInfo target)
{
sendPacket( Packet9Respawn.DIM1_SWITCH );
sendPacket( Packet9Respawn.DIM2_SWITCH );
sendDimensionSwitch();
connect( target );
}

View File

@ -13,7 +13,6 @@ import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.scoreboard.Objective;
@ -22,16 +21,17 @@ import net.md_5.bungee.api.scoreboard.Score;
import net.md_5.bungee.api.scoreboard.Scoreboard;
import net.md_5.bungee.api.scoreboard.Team;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.packet.Packet0KeepAlive;
import net.md_5.bungee.packet.Packet3Chat;
import net.md_5.bungee.packet.PacketC9PlayerListItem;
import net.md_5.bungee.packet.PacketCEScoreboardObjective;
import net.md_5.bungee.packet.PacketCFScoreboardScore;
import net.md_5.bungee.packet.PacketD0DisplayScoreboard;
import net.md_5.bungee.packet.PacketD1Team;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketHandler;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
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.PacketFFKick;
;
@RequiredArgsConstructor
public class DownstreamBridge extends PacketHandler
@ -78,7 +78,7 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(Packet0KeepAlive alive) throws Exception
{
con.setSentPingId( alive.id );
con.setSentPingId( alive.getRandomId() );
con.setSentPingTime( System.currentTimeMillis() );
}
@ -86,7 +86,7 @@ public class DownstreamBridge extends PacketHandler
public void handle(PacketC9PlayerListItem playerList) throws Exception
{
if ( !bungee.getTabListHandler().onListUpdate( con, playerList.username, playerList.online, playerList.ping ) )
if ( !bungee.getTabListHandler().onListUpdate( con, playerList.getUsername(), playerList.isOnline(), playerList.getPing() ) )
{
throw new CancelSendSignal();
}
@ -96,13 +96,13 @@ public class DownstreamBridge extends PacketHandler
public void handle(PacketCEScoreboardObjective objective) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
switch ( objective.action )
switch ( objective.getAction() )
{
case 0:
serverScoreboard.addObjective( new Objective( objective.name, objective.text ) );
serverScoreboard.addObjective( new Objective( objective.getName(), objective.getText() ) );
break;
case 1:
serverScoreboard.removeObjective( objective.name );
serverScoreboard.removeObjective( objective.getName() );
break;
}
}
@ -111,15 +111,15 @@ public class DownstreamBridge extends PacketHandler
public void handle(PacketCFScoreboardScore score) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
switch ( score.action )
switch ( score.getAction() )
{
case 0:
Score s = new Score( score.itemName, score.scoreName, score.value );
serverScoreboard.removeScore( score.itemName );
Score s = new Score( score.getItemName(), score.getScoreName(), score.getValue() );
serverScoreboard.removeScore( score.getItemName() );
serverScoreboard.addScore( s );
break;
case 1:
serverScoreboard.removeScore( score.itemName );
serverScoreboard.removeScore( score.getItemName() );
break;
}
}
@ -128,8 +128,8 @@ public class DownstreamBridge extends PacketHandler
public void handle(PacketD0DisplayScoreboard displayScoreboard) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
serverScoreboard.setName( displayScoreboard.name );
serverScoreboard.setPosition( Position.values()[displayScoreboard.position] );
serverScoreboard.setName( displayScoreboard.getName() );
serverScoreboard.setPosition( Position.values()[displayScoreboard.getPosition()] );
}
@Override
@ -137,37 +137,37 @@ public class DownstreamBridge extends PacketHandler
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
// Remove team and move on
if ( team.mode == 1 )
if ( team.getMode() == 1 )
{
serverScoreboard.removeTeam( team.name );
serverScoreboard.removeTeam( team.getName() );
return;
}
// Create or get old team
Team t;
if ( team.mode == 0 )
if ( team.getMode() == 0 )
{
t = new Team( team.name );
t = new Team( team.getName() );
serverScoreboard.addTeam( t );
} else
{
t = serverScoreboard.getTeam( team.name );
t = serverScoreboard.getTeam( team.getName() );
}
if ( t != null )
{
if ( team.mode == 0 || team.mode == 2 )
if ( team.getMode() == 0 || team.getMode() == 2 )
{
t.setDisplayName( team.displayName );
t.setPrefix( team.prefix );
t.setSuffix( team.suffix );
t.setFriendlyMode( team.friendlyFire );
t.setDisplayName( team.getDisplayName() );
t.setPrefix( team.getPrefix() );
t.setSuffix( team.getSuffix() );
t.setFriendlyFire(team.isFriendlyFire() );
}
if ( team.players != null )
if ( team.getPlayers()!= null )
{
for ( String s : team.players )
for ( String s : team.getPlayers() )
{
if ( team.mode == 0 || team.mode == 3 )
if ( team.getMode() == 0 || team.getMode() == 3 )
{
t.addPlayer( s );
} else
@ -182,20 +182,20 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
{
ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.data );
PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.tag, pluginMessage.data.clone() );
ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() );
PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() );
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
{
throw new CancelSendSignal();
}
if ( pluginMessage.tag.equals( "MC|TPack" ) && con.getPendingConnection().getListener().getTexturePack() != null )
if ( pluginMessage.getTag().equals( "MC|TPack" ) && con.getPendingConnection().getListener().getTexturePack() != null )
{
throw new CancelSendSignal();
}
if ( pluginMessage.tag.equals( "BungeeCord" ) )
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
{
ByteArrayDataOutput out = ByteStreams.newDataOutput();
String subChannel = in.readUTF();
@ -325,7 +325,7 @@ public class DownstreamBridge extends PacketHandler
{
def = null;
}
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, kick.message, def ) );
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, kick.getMessage(), def ) );
if ( event.isCancelled() && event.getCancelServer() != null )
{
con.connectNow( event.getCancelServer() );

View File

@ -34,16 +34,17 @@ import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.CipherDecoder;
import net.md_5.bungee.netty.CipherEncoder;
import net.md_5.bungee.netty.PacketDecoder;
import net.md_5.bungee.packet.Packet1Login;
import net.md_5.bungee.packet.Packet2Handshake;
import net.md_5.bungee.packet.PacketCDClientStatus;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.packet.PacketFEPing;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketHandler;
import net.md_5.bungee.protocol.PacketDefinitions;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.Forge;
import net.md_5.bungee.protocol.packet.Packet1Login;
import net.md_5.bungee.protocol.packet.Packet2Handshake;
import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
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.Vanilla;
@RequiredArgsConstructor
public class InitialHandler extends PacketHandler implements PendingConnection
@ -115,14 +116,14 @@ 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( Forge.getInstance() );
}
@Override
public void handle(Packet2Handshake handshake) throws Exception
{
Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" );
if ( handshake.username.length() > 16 )
if ( handshake.getUsername().length() > 16 )
{
disconnect( "Cannot have username longer than 16 characters" );
return;
@ -136,7 +137,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
// If offline mode and they are already on, don't allow connect
if ( !BungeeCord.getInstance().config.isOnlineMode() && bungee.getPlayer( handshake.username ) != null )
if ( !BungeeCord.getInstance().config.isOnlineMode() && bungee.getPlayer( handshake.getUsername() ) != null )
{
disconnect( bungee.getTranslation( "already_connected" ) );
return;
@ -164,7 +165,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
MessageDigest sha = MessageDigest.getInstance( "SHA-1" );
for ( byte[] bit : new byte[][]
{
request.serverId.getBytes( "ISO_8859_1" ), sharedKey.getEncoded(), EncryptionUtil.keys.getPublic().getEncoded()
request.getServerId().getBytes( "ISO_8859_1" ), sharedKey.getEncoded(), EncryptionUtil.keys.getPublic().getEncoded()
} )
{
sha.update( bit );
@ -202,7 +203,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private void finish() throws GeneralSecurityException
{
// Check for multiple connections
ProxiedPlayer old = bungee.getPlayer( handshake.username );
ProxiedPlayer old = bungee.getPlayer( handshake.getUsername() );
if ( old != null )
{
old.disconnect( bungee.getTranslation( "already_connected" ) );
@ -223,7 +224,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
thisState = InitialHandler.State.LOGIN;
ch.write( new PacketFCEncryptionResponse() );
ch.write( new PacketFCEncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) );
try
{
Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey );
@ -271,19 +272,19 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override
public String getName()
{
return ( handshake == null ) ? null : handshake.username;
return ( handshake == null ) ? null : handshake.getUsername();
}
@Override
public byte getVersion()
{
return ( handshake == null ) ? -1 : handshake.procolVersion;
return ( handshake == null ) ? -1 : handshake.getProcolVersion();
}
@Override
public InetSocketAddress getVirtualHost()
{
return ( handshake == null ) ? null : new InetSocketAddress( handshake.host, handshake.port );
return ( handshake == null ) ? null : new InetSocketAddress( handshake.getHost(), handshake.getPort() );
}
@Override

View File

@ -5,8 +5,8 @@ import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketHandler;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.packet.PacketFFKick;
@RequiredArgsConstructor
public class PingHandler extends PacketHandler
@ -34,7 +34,7 @@ public class PingHandler extends PacketHandler
@Override
public void handle(PacketFFKick kick) throws Exception
{
String[] split = kick.message.split( "\00" );
String[] split = kick.getMessage().split( "\00" );
ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
callback.done( ping, null );
}

View File

@ -10,11 +10,11 @@ import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.packet.Packet0KeepAlive;
import net.md_5.bungee.packet.Packet3Chat;
import net.md_5.bungee.packet.PacketCCSettings;
import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.packet.PacketHandler;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
import net.md_5.bungee.protocol.packet.Packet3Chat;
import net.md_5.bungee.protocol.packet.PacketCCSettings;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
public class UpstreamBridge extends PacketHandler
{
@ -72,7 +72,7 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(Packet0KeepAlive alive) throws Exception
{
if ( alive.id == con.getSentPingId() )
if ( alive.getRandomId() == con.getSentPingId() )
{
int newPing = (int) ( System.currentTimeMillis() - con.getSentPingTime() );
bungee.getTabListHandler().onPingChange( con, newPing );
@ -83,14 +83,14 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(Packet3Chat chat) throws Exception
{
ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.message );
ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() );
if ( bungee.getPluginManager().callEvent( chatEvent ).isCancelled() )
{
throw new CancelSendSignal();
}
if ( chatEvent.isCommand() )
{
if ( bungee.getPluginManager().dispatchCommand( con, chat.message.substring( 1 ) ) )
if ( bungee.getPluginManager().dispatchCommand( con, chat.getMessage().substring( 1 ) ) )
{
throw new CancelSendSignal();
}
@ -106,12 +106,12 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
{
if ( pluginMessage.tag.equals( "BungeeCord" ) )
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
{
throw new CancelSendSignal();
}
PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.tag, pluginMessage.data.clone() );
PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.getTag(), pluginMessage.getData().clone() );
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
{
throw new CancelSendSignal();

View File

@ -4,7 +4,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.protocol.packet.DefinedPacket;
@ChannelHandler.Sharable
public class DefinedPacketEncoder extends MessageToByteEncoder<DefinedPacket>
@ -13,6 +13,7 @@ public class DefinedPacketEncoder extends MessageToByteEncoder<DefinedPacket>
@Override
protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception
{
out.writeBytes( msg.getPacket() );
out.writeByte( msg.getId() );
msg.write( out );
}
}

View File

@ -8,15 +8,13 @@ import java.io.IOException;
import java.util.logging.Level;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.connection.CancelSendSignal;
import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.PacketHandler;
/**
* This class is a primitive wrapper for {@link PacketHandler} instances tied to
* channels to maintain simple states, and only call the required, adapted
* methods when the channel is connected.
*/
public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<byte[]>
public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
{
private ChannelWrapper channel;
@ -50,25 +48,27 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<byte[]>
}
@Override
public void messageReceived(ChannelHandlerContext ctx, byte[] msg) throws Exception
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception
{
if ( handler != null && ctx.channel().isActive() )
{
DefinedPacket packet = DefinedPacket.packet( msg );
boolean sendPacket = true;
if ( packet != null )
if ( msg instanceof PacketWrapper )
{
boolean sendPacket = true;
try
{
packet.handle( handler );
( (PacketWrapper) msg ).packet.handle( handler );
} catch ( CancelSendSignal ex )
{
sendPacket = false;
}
}
if ( sendPacket )
if ( sendPacket )
{
handler.handle( ( (PacketWrapper) msg ).buf );
}
} else
{
handler.handle( msg );
handler.handle( (byte[]) msg );
}
}
}

View File

@ -7,7 +7,9 @@ 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.Protocol;
import net.md_5.bungee.protocol.packet.DefinedPacket;
import net.md_5.bungee.protocol.skip.PacketReader;
/**
* This class will attempt to read a packet from {@link PacketReader}, with the
@ -23,7 +25,7 @@ public class PacketDecoder extends ReplayingDecoder<Void>
@Getter
@Setter
private int protocol;
private Protocol protocol;
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageBuf<Object> out) throws Exception
@ -34,7 +36,7 @@ public class PacketDecoder extends ReplayingDecoder<Void>
// Store our start index
int startIndex = in.readerIndex();
// Run packet through framer
PacketReader.readPacket( in, protocol );
DefinedPacket packet = protocol.read( in.readUnsignedByte(), in );
// If we got this far, it means we have formed a packet, so lets grab the end index
int endIndex = in.readerIndex();
// Allocate a buffer big enough for all bytes we have read
@ -47,8 +49,15 @@ public class PacketDecoder extends ReplayingDecoder<Void>
in.readerIndex( endIndex );
// Checkpoint our state incase we don't have enough data for another packet
checkpoint();
// Store our decoded message
out.add( buf );
if ( packet != null )
{
out.add( new PacketWrapper( packet, buf ) );
} else
{
out.add( buf );
}
}
}
}

View File

@ -0,0 +1,24 @@
package net.md_5.bungee.netty;
public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.AbstractPacketHandler
{
@Override
public abstract String toString();
public void exception(Throwable t) throws Exception
{
}
public void handle(byte[] buf) throws Exception
{
}
public void connected(ChannelWrapper channel) throws Exception
{
}
public void disconnected(ChannelWrapper channel) throws Exception
{
}
}

View File

@ -0,0 +1,16 @@
package net.md_5.bungee.netty;
import net.md_5.bungee.protocol.packet.DefinedPacket;
public class PacketWrapper
{
DefinedPacket packet;
byte[] buf;
public PacketWrapper(DefinedPacket packet, byte[] buf)
{
this.packet = packet;
this.buf = buf;
}
}

View File

@ -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.getInstance() ) );
ch.pipeline().addLast( "packet-encoder", packetEncoder );
ch.pipeline().addLast( "array-encoder", arrayEncoder );
ch.pipeline().addLast( "handler", new HandlerBoss() );

View File

@ -1,240 +0,0 @@
package net.md_5.bungee.packet;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import lombok.Delegate;
import net.md_5.bungee.Util;
/**
* This class represents a packet which has been given a special definition. All
* subclasses can read and write to the backing byte array which can be
* retrieved via the {@link #getPacket()} method.
*/
public abstract class DefinedPacket implements DataOutput
{
private static interface Overriden
{
void readUTF();
void writeUTF(String s);
}
private ByteArrayInputStream byteStream;
private DataInputStream in;
@Delegate(excludes = Overriden.class)
private ByteArrayDataOutput out;
private byte[] buf;
public DefinedPacket(int id, byte[] buf)
{
byteStream = new ByteArrayInputStream( buf );
in = new DataInputStream( byteStream );
if ( readUnsignedByte() != id )
{
throw new IllegalArgumentException( "Wasn't expecting packet id " + Util.hex( id ) );
}
this.buf = buf;
}
public DefinedPacket(int id)
{
out = ByteStreams.newDataOutput();
writeByte( id );
}
/**
* Gets the bytes that make up this packet.
*
* @return the bytes which make up this packet, either the original byte
* array or the newly written one.
*/
public byte[] getPacket()
{
return buf == null ? buf = out.toByteArray() : buf;
}
@Override
public void writeUTF(String s)
{
writeShort( s.length() );
writeChars( s );
}
public String readUTF()
{
short len = readShort();
char[] chars = new char[ len ];
for ( int i = 0; i < len; i++ )
{
chars[i] = this.readChar();
}
return new String( chars );
}
public void writeArray(byte[] b)
{
writeShort( b.length );
write( b );
}
public byte[] readArray()
{
short len = readShort();
byte[] ret = new byte[ len ];
readFully( ret );
return ret;
}
public final int available()
{
return byteStream.available();
}
public final void readFully(byte b[])
{
try
{
in.readFully( b );
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
public final boolean readBoolean()
{
try
{
return in.readBoolean();
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
public final byte readByte()
{
try
{
return in.readByte();
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
public final int readUnsignedByte()
{
try
{
return in.readUnsignedByte();
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
public final short readShort()
{
try
{
return in.readShort();
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
public final char readChar()
{
try
{
return in.readChar();
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
public final int readInt()
{
try
{
return in.readInt();
} catch ( IOException e )
{
throw new IllegalStateException( e );
}
}
@Override
public abstract boolean equals(Object obj);
@Override
public abstract int hashCode();
@Override
public abstract String toString();
public abstract void handle(PacketHandler handler) throws Exception;
@SuppressWarnings("unchecked")
private static Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
@SuppressWarnings("unchecked")
private static Constructor<? extends DefinedPacket>[] consructors = new Constructor[ 256 ];
public static DefinedPacket packet(byte[] buf)
{
int id = buf[0] & 0xFF;
Class<? extends DefinedPacket> clazz = classes[id];
DefinedPacket ret = null;
if ( clazz != null )
{
try
{
Constructor<? extends DefinedPacket> constructor = consructors[id];
if ( constructor == null )
{
constructor = clazz.getDeclaredConstructor( byte[].class );
consructors[id] = constructor;
}
if ( constructor != null )
{
ret = constructor.newInstance( buf );
}
} catch ( IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex )
{
}
}
return ret;
}
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

@ -1,24 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet0KeepAlive extends DefinedPacket
{
public int id;
Packet0KeepAlive(byte[] buf)
{
super( 0x00, buf );
id = readInt();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,70 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet1Login extends DefinedPacket
{
public int entityId;
public String levelType;
public byte gameMode;
public int dimension;
public byte difficulty;
public byte unused;
public byte maxPlayers;
public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers, boolean forge)
{
super( 0x01 );
writeInt( entityId );
writeUTF( levelType );
writeByte( gameMode );
if ( forge )
{
writeInt( dimension );
} else
{
writeByte( dimension );
}
writeByte( difficulty );
writeByte( unused );
writeByte( maxPlayers );
this.entityId = entityId;
this.levelType = levelType;
this.gameMode = gameMode;
this.dimension = dimension;
this.difficulty = difficulty;
this.unused = unused;
this.maxPlayers = maxPlayers;
}
Packet1Login(byte[] buf)
{
super( 0x01, buf );
this.entityId = readInt();
this.levelType = readUTF();
this.gameMode = readByte();
if ( available() == 4 )
{
this.dimension = readByte();
} else if ( available() == 7 )
{
this.dimension = readInt();
} else
{
throw new IllegalStateException();
}
this.difficulty = readByte();
this.unused = readByte();
this.maxPlayers = readByte();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,43 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet2Handshake extends DefinedPacket
{
public byte procolVersion;
public String username;
public String host;
public int port;
public Packet2Handshake(byte protocolVersion, String username, String host, int port)
{
super( 0x02 );
writeByte( protocolVersion );
writeUTF( username );
writeUTF( host );
writeInt( port );
this.procolVersion = protocolVersion;
this.username = username;
this.host = host;
this.port = port;
}
Packet2Handshake(byte[] buf)
{
super( 0x02, buf );
this.procolVersion = readByte();
this.username = readUTF();
this.host = readUTF();
this.port = readInt();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,31 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet3Chat extends DefinedPacket
{
public String message;
public Packet3Chat(String message)
{
super( 0x03 );
writeUTF( message );
this.message = message;
}
Packet3Chat(byte[] buf)
{
super( 0x03, buf );
this.message = readUTF();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,49 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class Packet9Respawn extends DefinedPacket
{
public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
public int dimension;
public byte difficulty;
public byte gameMode;
public short worldHeight;
public String levelType;
public Packet9Respawn(int dimension, byte difficulty, byte gameMode, short worldHeight, String levelType)
{
super( 0x09 );
writeInt( dimension );
writeByte( difficulty );
writeByte( gameMode );
writeShort( worldHeight );
writeUTF( levelType );
this.dimension = dimension;
this.difficulty = difficulty;
this.gameMode = gameMode;
this.worldHeight = worldHeight;
this.levelType = levelType;
}
Packet9Respawn(byte[] buf)
{
super( 0x09, buf );
this.dimension = readInt();
this.difficulty = readByte();
this.gameMode = readByte();
this.worldHeight = readShort();
this.levelType = readUTF();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,36 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketC9PlayerListItem extends DefinedPacket
{
public String username;
public boolean online;
public int ping;
PacketC9PlayerListItem(byte[] buf)
{
super( 0xC9, buf );
username = readUTF();
online = readBoolean();
ping = readShort();
}
public PacketC9PlayerListItem(String username, boolean online, int ping)
{
super( 0xC9 );
writeUTF( username );
writeBoolean( online );
writeShort( ping );
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,32 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCCSettings extends DefinedPacket
{
public String locale;
public byte viewDistance;
public byte chatFlags;
public byte difficulty;
public boolean showCape;
public PacketCCSettings(byte[] buf)
{
super( 0xCC, buf );
locale = readUTF();
viewDistance = readByte();
chatFlags = readByte();
difficulty = readByte();
showCape = readBoolean();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,38 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCDClientStatus extends DefinedPacket
{
/**
* Represents the packet the client sends to the server when it is ready to
* login.
*/
public static PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 );
/**
* 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 );
writeByte( payload );
}
PacketCDClientStatus(byte[] buf)
{
super( 0xCD, buf );
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,42 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCEScoreboardObjective extends DefinedPacket
{
public String name;
public String text;
/**
* 0 to create, 1 to remove.
*/
public byte action;
public PacketCEScoreboardObjective(String name, String text, byte status)
{
super( 0xCE );
writeUTF( name );
writeUTF( text );
writeByte( status );
this.name = name;
this.text = text;
this.action = status;
}
PacketCEScoreboardObjective(byte[] buf)
{
super( 0xCE, buf );
this.name = readUTF();
this.text = readUTF();
this.action = readByte();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,52 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketCFScoreboardScore extends DefinedPacket
{
public String itemName;
/**
* 0 = create / update, 1 = remove.
*/
public byte action;
public String scoreName;
public int value;
public PacketCFScoreboardScore(byte[] buf)
{
super( 0xCF, buf );
itemName = readUTF();
action = readByte();
if ( action == 0 )
{
scoreName = readUTF();
value = readInt();
}
}
public PacketCFScoreboardScore(String itemName, byte action, String scoreName, int value)
{
super( 0xCF );
writeUTF( itemName );
writeByte( action );
if ( action == 0 )
{
writeUTF( scoreName );
writeInt( value );
}
this.itemName = itemName;
this.action = action;
this.scoreName = scoreName;
this.value = value;
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,29 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketD0DisplayScoreboard extends DefinedPacket
{
/**
* 0 = list, 1 = side, 2 = below.
*/
public byte position;
public String name;
public PacketD0DisplayScoreboard(byte[] buf)
{
super( 0xD0, buf );
position = readByte();
name = readUTF();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,63 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketD1Team extends DefinedPacket
{
public String name;
/**
* 0 - create, 1 remove, 2 info update, 3 player add, 4 player remove.
*/
public byte mode;
public String displayName;
public String prefix;
public String suffix;
public byte friendlyFire;
public short playerCount;
public String[] players;
public PacketD1Team(byte[] buf)
{
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 );
}
public static PacketD1Team destroy(String name)
{
PacketD1Team packet = new PacketD1Team();
packet.writeUTF( name );
packet.writeByte( 1 );
return packet;
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,35 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFAPluginMessage extends DefinedPacket
{
public String tag;
public byte[] data;
public PacketFAPluginMessage(String tag, byte[] data)
{
super( 0xFA );
writeUTF( tag );
writeArray( data );
this.tag = tag;
this.data = data;
}
PacketFAPluginMessage(byte[] buf)
{
super( 0xFA, buf );
this.tag = readUTF();
this.data = readArray();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,42 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFCEncryptionResponse extends DefinedPacket
{
public byte[] sharedSecret;
public byte[] verifyToken;
public PacketFCEncryptionResponse()
{
super( 0xFC );
writeArray( new byte[ 0 ] );
writeArray( new byte[ 0 ] );
}
public PacketFCEncryptionResponse(byte[] sharedSecret, byte[] verifyToken)
{
super( 0xFC );
writeArray( sharedSecret );
writeArray( verifyToken );
this.sharedSecret = sharedSecret;
this.verifyToken = verifyToken;
}
PacketFCEncryptionResponse(byte[] buf)
{
super( 0xFC, buf );
this.sharedSecret = readArray();
this.verifyToken = readArray();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,40 +0,0 @@
package net.md_5.bungee.packet;
import io.netty.buffer.ByteBuf;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFDEncryptionRequest extends DefinedPacket
{
public String serverId;
public byte[] publicKey;
public byte[] verifyToken;
public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken)
{
super( 0xFD );
writeUTF( serverId );
writeArray( publicKey );
writeArray( verifyToken );
this.serverId = serverId;
this.publicKey = publicKey;
this.verifyToken = verifyToken;
}
PacketFDEncryptionRequest(byte[] buf)
{
super( 0xFD, buf );
serverId = readUTF();
publicKey = readArray();
verifyToken = readArray();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,24 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFEPing extends DefinedPacket
{
public byte version;
PacketFEPing(byte[] buffer)
{
super( 0xFE, buffer );
version = readByte();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -1,30 +0,0 @@
package net.md_5.bungee.packet;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ToString
@EqualsAndHashCode(callSuper = false)
public class PacketFFKick extends DefinedPacket
{
public String message;
public PacketFFKick(String message)
{
super( 0xFF );
writeUTF( message );
}
PacketFFKick(byte[] buf)
{
super( 0xFF, buf );
this.message = readUTF();
}
@Override
public void handle(PacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@ -7,7 +7,7 @@ import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.packet.PacketC9PlayerListItem;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
public class Global implements TabListHandler
{
@ -20,9 +20,9 @@ public class Global implements TabListHandler
UserConnection con = (UserConnection) player;
for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() )
{
con.sendPacket( new PacketC9PlayerListItem( p.getDisplayName(), true, p.getPing() ) );
con.sendPacket( new PacketC9PlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) );
}
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, player.getPing() ) );
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, (short) player.getPing() ) );
}
@Override
@ -30,7 +30,7 @@ public class Global implements TabListHandler
{
if ( !sentPings.contains( player ) )
{
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, player.getPing() ) );
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, (short) player.getPing() ) );
sentPings.add( player );
}
}
@ -38,7 +38,7 @@ public class Global implements TabListHandler
@Override
public void onDisconnect(ProxiedPlayer player)
{
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), false, 9999 ) );
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), false, (short) 9999 ) );
sentPings.remove( player );
}

View File

@ -4,7 +4,7 @@ import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.packet.PacketC9PlayerListItem;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
public class GlobalPing extends Global
{
@ -25,7 +25,7 @@ public class GlobalPing extends Global
int lastPing = lastPings.get( player );
if ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing )
{
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, ping ) );
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, (short) ping ) );
lastPings.put( player, ping );
}
}

View File

@ -7,7 +7,7 @@ import java.util.Collection;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.packet.PacketC9PlayerListItem;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
public class ServerUnique implements TabListHandler
{
@ -38,7 +38,7 @@ public class ServerUnique implements TabListHandler
{
for ( String username : usernames )
{
( (UserConnection) player ).sendPacket( new PacketC9PlayerListItem( username, false, 9999 ) );
( (UserConnection) player ).sendPacket( new PacketC9PlayerListItem( username, false, (short) 9999 ) );
}
usernames.clear();
}