WIP
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import net.md_5.bungee.protocol.handshake.Packet0Handshake;
|
||||
import net.md_5.bungee.protocol.login.Packet0Kick;
|
||||
import net.md_5.bungee.protocol.login.Packet1EncryptionResponse;
|
||||
import net.md_5.bungee.protocol.login.Packet2LoginSuccess;
|
||||
|
||||
public abstract class AbstractPacketHandler
|
||||
{
|
||||
|
||||
/*========================================================================*/
|
||||
// Handshake Start
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
// Handshake End
|
||||
/*========================================================================*/
|
||||
// Game Start
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet0Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
// Game End
|
||||
/*========================================================================*/
|
||||
// Ping Start
|
||||
// Ping End
|
||||
/*========================================================================*/
|
||||
// Login Start
|
||||
|
||||
public void handle(Packet0Kick kick) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet1EncryptionResponse encryptionResponse) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet2LoginSuccess loginSuccess) throws Exception
|
||||
{
|
||||
}
|
||||
// Login End
|
||||
/*========================================================================*/
|
||||
}
|
@@ -7,4 +7,9 @@ public class BadPacketException extends RuntimeException
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public BadPacketException(String message, Throwable cause)
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,105 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class DefinedPacket
|
||||
{
|
||||
|
||||
public void writeString(String s, ByteBuf buf)
|
||||
{
|
||||
// TODO: Check len - use Guava?
|
||||
byte[] b = s.getBytes( Charsets.UTF_8 );
|
||||
writeVarInt( b.length, buf );
|
||||
buf.writeBytes( b );
|
||||
}
|
||||
|
||||
public String readString(ByteBuf buf)
|
||||
{
|
||||
int len = readVarInt( buf );
|
||||
byte[] b = new byte[ len ];
|
||||
buf.readBytes( b );
|
||||
|
||||
return new String( b, Charsets.UTF_8 );
|
||||
}
|
||||
|
||||
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 int readVarInt(ByteBuf input)
|
||||
{
|
||||
int out = 0;
|
||||
int bytes = 0;
|
||||
byte in;
|
||||
while ( true )
|
||||
{
|
||||
in = input.readByte();
|
||||
|
||||
out |= ( in & 0x7F ) << ( bytes++ * 7 );
|
||||
|
||||
if ( bytes > 32 )
|
||||
{
|
||||
throw new RuntimeException( "VarInt too big" );
|
||||
}
|
||||
|
||||
if ( ( in & 0x80 ) != 0x80 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public void writeVarInt(int value, ByteBuf output)
|
||||
{
|
||||
int part;
|
||||
while ( true )
|
||||
{
|
||||
part = value & 0x7F;
|
||||
|
||||
value >>>= 7;
|
||||
if ( value != 0 )
|
||||
{
|
||||
part |= 0x80;
|
||||
}
|
||||
|
||||
output.writeByte( part );
|
||||
|
||||
if ( value == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
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, OPTIONAL_WINDOW
|
||||
}
|
@@ -1,20 +1,78 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import gnu.trove.map.TObjectIntMap;
|
||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||
import java.lang.reflect.Constructor;
|
||||
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.skip.PacketReader;
|
||||
import net.md_5.bungee.protocol.handshake.HandshakeProtocol;
|
||||
|
||||
public interface Protocol
|
||||
public class Protocol
|
||||
{
|
||||
|
||||
PacketReader getSkipper();
|
||||
private static final int MAX_PACKET_ID = 0xFF;
|
||||
private static final int MAX_PROTOCOLS = 0xF;
|
||||
/*========================================================================*/
|
||||
private static final Protocol[] protocols = new Protocol[ MAX_PROTOCOLS ];
|
||||
/*========================================================================*/
|
||||
private final TObjectIntMap<Class<? extends DefinedPacket>> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID );
|
||||
private final Class<? extends DefinedPacket>[] packetClasses = new Class[ MAX_PACKET_ID ];
|
||||
private final Constructor<? extends DefinedPacket>[] packetConstructors = new Constructor[ MAX_PACKET_ID ];
|
||||
|
||||
DefinedPacket read(short packetId, ByteBuf buf);
|
||||
static
|
||||
{
|
||||
|
||||
OpCode[][] getOpCodes();
|
||||
}
|
||||
|
||||
Class<? extends DefinedPacket>[] getClasses();
|
||||
public Protocol(int protocolId)
|
||||
{
|
||||
}
|
||||
|
||||
Constructor<? extends DefinedPacket>[] getConstructors();
|
||||
public static Protocol getProtocol(int id)
|
||||
{
|
||||
return protocols[id];
|
||||
}
|
||||
|
||||
public final DefinedPacket createPacket(int id)
|
||||
{
|
||||
if ( id > MAX_PACKET_ID )
|
||||
{
|
||||
throw new BadPacketException( "Packet with id " + id + " outside of range " );
|
||||
}
|
||||
if ( packetConstructors[id] == null )
|
||||
{
|
||||
throw new BadPacketException( "No packet with id " + id );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return packetClasses[id].newInstance();
|
||||
} catch ( ReflectiveOperationException ex )
|
||||
{
|
||||
throw new BadPacketException( "Could not construct packet with id " + id, ex );
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerPacket(int id, Class<? extends DefinedPacket> packetClass)
|
||||
{
|
||||
try
|
||||
{
|
||||
packetConstructors[id] = packetClass.getDeclaredConstructor();
|
||||
} catch ( NoSuchMethodException ex )
|
||||
{
|
||||
throw new BadPacketException( "No NoArgsConstructor for packet class " + packetClass );
|
||||
}
|
||||
packetClasses[id] = packetClass;
|
||||
packetMap.put( packetClass, id );
|
||||
}
|
||||
|
||||
protected final void unregisterPacket(int id)
|
||||
{
|
||||
packetMap.remove( packetClasses[id] );
|
||||
packetClasses[id] = null;
|
||||
packetConstructors[id] = null;
|
||||
}
|
||||
|
||||
final int getId(Class<? extends DefinedPacket> packet)
|
||||
{
|
||||
return packetMap.get( packet );
|
||||
}
|
||||
}
|
||||
|
@@ -1,382 +0,0 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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.Packet2CEntityProperties;
|
||||
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.PacketCBTabComplete;
|
||||
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 Vanilla implements Protocol
|
||||
{
|
||||
|
||||
public static final byte PROTOCOL_VERSION = 80;
|
||||
public static final String GAME_VERSION = "13w39b";
|
||||
@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 Vanilla()
|
||||
{
|
||||
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[0x2C] = Packet2CEntityProperties.class;
|
||||
classes[0xCC] = PacketCCSettings.class;
|
||||
classes[0xCB] = PacketCBTabComplete.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 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefinedPacket read(short packetId, ByteBuf buf)
|
||||
{
|
||||
int start = buf.readerIndex();
|
||||
DefinedPacket packet = read( packetId, buf, this );
|
||||
if ( buf.readerIndex() == start )
|
||||
{
|
||||
throw new BadPacketException( "Unknown packet id " + packetId );
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static DefinedPacket read(short id, ByteBuf buf, Protocol protocol)
|
||||
{
|
||||
DefinedPacket packet = packet( id, protocol );
|
||||
if ( packet != null )
|
||||
{
|
||||
packet.read( buf );
|
||||
return packet;
|
||||
}
|
||||
protocol.getSkipper().tryRead( id, buf );
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DefinedPacket packet(short id, Protocol protocol)
|
||||
{
|
||||
DefinedPacket ret = null;
|
||||
Class<? extends DefinedPacket> clazz = protocol.getClasses()[id];
|
||||
|
||||
if ( clazz != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
Constructor<? extends DefinedPacket> constructor = protocol.getConstructors()[id];
|
||||
if ( constructor == null )
|
||||
{
|
||||
constructor = clazz.getDeclaredConstructor();
|
||||
constructor.setAccessible( true );
|
||||
protocol.getConstructors()[id] = constructor;
|
||||
}
|
||||
|
||||
if ( constructor != null )
|
||||
{
|
||||
ret = constructor.newInstance();
|
||||
}
|
||||
} catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
opCodes[0x04] = new OpCode[]
|
||||
{
|
||||
LONG, LONG
|
||||
};
|
||||
opCodes[0x05] = new OpCode[]
|
||||
{
|
||||
INT, SHORT, ITEM
|
||||
};
|
||||
opCodes[0x06] = new OpCode[]
|
||||
{
|
||||
INT, INT, INT
|
||||
};
|
||||
opCodes[0x07] = new OpCode[]
|
||||
{
|
||||
INT, INT, BOOLEAN
|
||||
};
|
||||
opCodes[0x08] = new OpCode[]
|
||||
{
|
||||
FLOAT, SHORT, FLOAT
|
||||
};
|
||||
opCodes[0x0A] = new OpCode[]
|
||||
{
|
||||
BOOLEAN
|
||||
};
|
||||
opCodes[0x0B] = new OpCode[]
|
||||
{
|
||||
DOUBLE, DOUBLE, DOUBLE, DOUBLE, BOOLEAN
|
||||
};
|
||||
opCodes[0x0C] = new OpCode[]
|
||||
{
|
||||
FLOAT, FLOAT, BOOLEAN
|
||||
};
|
||||
opCodes[0x0D] = new OpCode[]
|
||||
{
|
||||
DOUBLE, DOUBLE, DOUBLE, DOUBLE, FLOAT, FLOAT, BOOLEAN
|
||||
};
|
||||
opCodes[0x0E] = new OpCode[]
|
||||
{
|
||||
BYTE, INT, BYTE, INT, BYTE
|
||||
};
|
||||
opCodes[0x0F] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT, BYTE, ITEM, BYTE, BYTE, BYTE
|
||||
};
|
||||
opCodes[0x10] = new OpCode[]
|
||||
{
|
||||
SHORT
|
||||
};
|
||||
opCodes[0x11] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT, BYTE, INT
|
||||
};
|
||||
opCodes[0x12] = new OpCode[]
|
||||
{
|
||||
INT, BYTE
|
||||
};
|
||||
opCodes[0x13] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT
|
||||
};
|
||||
opCodes[0x14] = new OpCode[]
|
||||
{
|
||||
INT, STRING, STRING, INT, INT, INT, BYTE, BYTE, SHORT, METADATA
|
||||
};
|
||||
opCodes[0x16] = new OpCode[]
|
||||
{
|
||||
INT, INT
|
||||
};
|
||||
opCodes[0x17] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT, INT, INT, BYTE, BYTE, OPTIONAL_MOTION
|
||||
};
|
||||
opCodes[0x18] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT, INT, INT, BYTE, BYTE, BYTE, SHORT, SHORT, SHORT, METADATA
|
||||
};
|
||||
opCodes[0x19] = new OpCode[]
|
||||
{
|
||||
INT, STRING, INT, INT, INT, INT
|
||||
};
|
||||
opCodes[0x1A] = new OpCode[]
|
||||
{
|
||||
INT, INT, INT, INT, SHORT
|
||||
};
|
||||
opCodes[0x1B] = new OpCode[]
|
||||
{
|
||||
FLOAT, FLOAT, BOOLEAN, BOOLEAN
|
||||
};
|
||||
opCodes[0x1C] = new OpCode[]
|
||||
{
|
||||
INT, SHORT, SHORT, SHORT
|
||||
};
|
||||
opCodes[0x1D] = new OpCode[]
|
||||
{
|
||||
BYTE_INT
|
||||
};
|
||||
opCodes[0x1E] = new OpCode[]
|
||||
{
|
||||
INT
|
||||
};
|
||||
opCodes[0x1F] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, BYTE, BYTE
|
||||
};
|
||||
opCodes[0x20] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, BYTE
|
||||
};
|
||||
opCodes[0x21] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, BYTE, BYTE, BYTE, BYTE
|
||||
};
|
||||
opCodes[0x22] = new OpCode[]
|
||||
{
|
||||
INT, INT, INT, INT, BYTE, BYTE
|
||||
};
|
||||
opCodes[0x23] = new OpCode[]
|
||||
{
|
||||
INT, BYTE
|
||||
};
|
||||
opCodes[0x26] = new OpCode[]
|
||||
{
|
||||
INT, BYTE
|
||||
};
|
||||
opCodes[0x27] = new OpCode[]
|
||||
{
|
||||
INT, INT, BOOLEAN
|
||||
};
|
||||
opCodes[0x28] = new OpCode[]
|
||||
{
|
||||
INT, METADATA
|
||||
};
|
||||
opCodes[0x29] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, BYTE, SHORT
|
||||
};
|
||||
opCodes[0x2A] = new OpCode[]
|
||||
{
|
||||
INT, BYTE
|
||||
};
|
||||
opCodes[0x2B] = new OpCode[]
|
||||
{
|
||||
FLOAT, SHORT, SHORT
|
||||
};
|
||||
opCodes[0x33] = new OpCode[]
|
||||
{
|
||||
INT, INT, BOOLEAN, SHORT, SHORT, INT_BYTE
|
||||
};
|
||||
opCodes[0x34] = new OpCode[]
|
||||
{
|
||||
INT, INT, SHORT, INT_BYTE
|
||||
};
|
||||
opCodes[0x35] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT, SHORT, BYTE
|
||||
};
|
||||
opCodes[0x36] = new OpCode[]
|
||||
{
|
||||
INT, SHORT, INT, BYTE, BYTE, SHORT
|
||||
};
|
||||
opCodes[0x37] = new OpCode[]
|
||||
{
|
||||
INT, INT, INT, INT, BYTE
|
||||
};
|
||||
opCodes[0x38] = new OpCode[]
|
||||
{
|
||||
BULK_CHUNK
|
||||
};
|
||||
opCodes[0x3C] = new OpCode[]
|
||||
{
|
||||
DOUBLE, DOUBLE, DOUBLE, FLOAT, INT_3, FLOAT, FLOAT, FLOAT
|
||||
};
|
||||
opCodes[0x3D] = new OpCode[]
|
||||
{
|
||||
INT, INT, BYTE, INT, INT, BOOLEAN
|
||||
};
|
||||
opCodes[0x3E] = new OpCode[]
|
||||
{
|
||||
STRING, INT, INT, INT, FLOAT, BYTE, BYTE
|
||||
};
|
||||
opCodes[0x3F] = new OpCode[]
|
||||
{
|
||||
STRING, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, INT
|
||||
};
|
||||
opCodes[0x46] = new OpCode[]
|
||||
{
|
||||
BYTE, FLOAT
|
||||
};
|
||||
opCodes[0x47] = new OpCode[]
|
||||
{
|
||||
INT, BYTE, INT, INT, INT
|
||||
};
|
||||
opCodes[0x64] = new OpCode[]
|
||||
{
|
||||
OPTIONAL_WINDOW
|
||||
};
|
||||
opCodes[0x65] = new OpCode[]
|
||||
{
|
||||
BYTE
|
||||
};
|
||||
opCodes[0x66] = new OpCode[]
|
||||
{
|
||||
BYTE, SHORT, BYTE, SHORT, BOOLEAN, ITEM
|
||||
};
|
||||
opCodes[0x67] = new OpCode[]
|
||||
{
|
||||
BYTE, SHORT, ITEM
|
||||
};
|
||||
opCodes[0x68] = new OpCode[]
|
||||
{
|
||||
BYTE, SHORT_ITEM
|
||||
};
|
||||
opCodes[0x69] = new OpCode[]
|
||||
{
|
||||
BYTE, SHORT, SHORT
|
||||
};
|
||||
opCodes[0x6A] = new OpCode[]
|
||||
{
|
||||
BYTE, SHORT, BOOLEAN
|
||||
};
|
||||
opCodes[0x6B] = new OpCode[]
|
||||
{
|
||||
SHORT, ITEM
|
||||
};
|
||||
opCodes[0x6C] = new OpCode[]
|
||||
{
|
||||
BYTE, BYTE
|
||||
};
|
||||
opCodes[0x82] = new OpCode[]
|
||||
{
|
||||
INT, SHORT, INT, STRING, STRING, STRING, STRING
|
||||
};
|
||||
opCodes[0x83] = new OpCode[]
|
||||
{
|
||||
SHORT, SHORT, USHORT_BYTE
|
||||
};
|
||||
opCodes[0x84] = new OpCode[]
|
||||
{
|
||||
INT, SHORT, INT, BYTE, SHORT_BYTE
|
||||
};
|
||||
opCodes[0x85] = new OpCode[]
|
||||
{
|
||||
BYTE, INT, INT, INT
|
||||
};
|
||||
opCodes[0xC3] = new OpCode[]
|
||||
{
|
||||
SHORT, SHORT, INT_BYTE
|
||||
};
|
||||
opCodes[0xCA] = new OpCode[]
|
||||
{
|
||||
BYTE, FLOAT, FLOAT
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
|
||||
public class GameProtocol extends Protocol
|
||||
{
|
||||
|
||||
@Getter
|
||||
private static final GameProtocol instance = new GameProtocol();
|
||||
|
||||
private GameProtocol()
|
||||
{
|
||||
super( 0 );
|
||||
}
|
||||
}
|
@@ -1,23 +1,22 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet0KeepAlive extends DefinedPacket
|
||||
{
|
||||
|
||||
private int randomId;
|
||||
|
||||
private Packet0KeepAlive()
|
||||
{
|
||||
super( 0x00 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
@@ -1,31 +1,34 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketCCSettings extends DefinedPacket
|
||||
public class Packet15Settings extends DefinedPacket
|
||||
{
|
||||
|
||||
private String locale;
|
||||
private byte viewDistance;
|
||||
private byte chatFlags;
|
||||
private boolean unknown;
|
||||
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();
|
||||
unknown = buf.readBoolean();
|
||||
difficulty = buf.readByte();
|
||||
showCape = buf.readBoolean();
|
||||
}
|
||||
@@ -36,6 +39,7 @@ public class PacketCCSettings extends DefinedPacket
|
||||
writeString( locale, buf );
|
||||
buf.writeByte( viewDistance );
|
||||
buf.writeByte( chatFlags );
|
||||
buf.writeBoolean( unknown );
|
||||
buf.writeByte( difficulty );
|
||||
buf.writeBoolean( showCape );
|
||||
}
|
@@ -1,27 +1,22 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketCDClientStatus extends DefinedPacket
|
||||
public class Packet16ClientStatus extends DefinedPacket
|
||||
{
|
||||
|
||||
private byte payload;
|
||||
|
||||
private PacketCDClientStatus()
|
||||
{
|
||||
super( 0xCD );
|
||||
}
|
||||
|
||||
public PacketCDClientStatus(byte payload)
|
||||
{
|
||||
this();
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
@@ -1,24 +1,29 @@
|
||||
package net.md_5.bungee.protocol.packet.forge;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.packet.*;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Forge1Login extends Packet1Login
|
||||
public class Packet1Login extends DefinedPacket
|
||||
{
|
||||
|
||||
private Forge1Login()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public Forge1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers)
|
||||
{
|
||||
super( entityId, levelType, gameMode, dimension, difficulty, unused, maxPlayers );
|
||||
}
|
||||
private int entityId;
|
||||
private String levelType;
|
||||
private byte gameMode;
|
||||
private int dimension;
|
||||
private byte difficulty;
|
||||
private byte unused;
|
||||
private byte maxPlayers;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
@@ -26,7 +31,7 @@ public class Forge1Login extends Packet1Login
|
||||
entityId = buf.readInt();
|
||||
levelType = readString( buf );
|
||||
gameMode = buf.readByte();
|
||||
dimension = buf.readInt();
|
||||
dimension = buf.readByte();
|
||||
difficulty = buf.readByte();
|
||||
unused = buf.readByte();
|
||||
maxPlayers = buf.readByte();
|
||||
@@ -38,7 +43,7 @@ public class Forge1Login extends Packet1Login
|
||||
buf.writeInt( entityId );
|
||||
writeString( levelType, buf );
|
||||
buf.writeByte( gameMode );
|
||||
buf.writeInt( dimension );
|
||||
buf.writeByte( dimension );
|
||||
buf.writeByte( difficulty );
|
||||
buf.writeByte( unused );
|
||||
buf.writeByte( maxPlayers );
|
@@ -1,29 +1,22 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketFFKick extends DefinedPacket
|
||||
public class Packet2Chat extends DefinedPacket
|
||||
{
|
||||
|
||||
private String message;
|
||||
|
||||
private PacketFFKick()
|
||||
{
|
||||
super( 0xFF );
|
||||
}
|
||||
|
||||
public PacketFFKick(String message)
|
||||
{
|
||||
this();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
@@ -1,33 +1,24 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketC9PlayerListItem extends DefinedPacket
|
||||
public class Packet3BPlayerListItem 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)
|
||||
{
|
@@ -1,27 +1,25 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketCBTabComplete extends DefinedPacket
|
||||
public class Packet3DTabComplete extends DefinedPacket
|
||||
{
|
||||
|
||||
private String cursor;
|
||||
private String[] commands;
|
||||
|
||||
private PacketCBTabComplete()
|
||||
public Packet3DTabComplete(String[] alternatives)
|
||||
{
|
||||
super( 0xCB );
|
||||
}
|
||||
|
||||
public PacketCBTabComplete(String[] alternatives)
|
||||
{
|
||||
this();
|
||||
commands = alternatives;
|
||||
}
|
||||
|
@@ -1,14 +1,18 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketCEScoreboardObjective extends DefinedPacket
|
||||
public class Packet3EScoreboardObjective extends DefinedPacket
|
||||
{
|
||||
|
||||
private String name;
|
||||
@@ -18,19 +22,6 @@ public class PacketCEScoreboardObjective extends DefinedPacket
|
||||
*/
|
||||
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)
|
||||
{
|
@@ -1,14 +1,20 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketCFScoreboardScore extends DefinedPacket
|
||||
public class Packet3FScoreboardScore extends DefinedPacket
|
||||
{
|
||||
|
||||
private String itemName;
|
||||
@@ -19,11 +25,6 @@ public class PacketCFScoreboardScore extends DefinedPacket
|
||||
private String scoreName;
|
||||
private int value;
|
||||
|
||||
private PacketCFScoreboardScore()
|
||||
{
|
||||
super( 0xCF );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
@@ -1,14 +1,18 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketD0DisplayScoreboard extends DefinedPacket
|
||||
public class Packet40DisplayScoreboard extends DefinedPacket
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -17,11 +21,6 @@ public class PacketD0DisplayScoreboard extends DefinedPacket
|
||||
private byte position;
|
||||
private String name;
|
||||
|
||||
private PacketD0DisplayScoreboard()
|
||||
{
|
||||
super( 0xD0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
@@ -1,14 +1,18 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketD1Team extends DefinedPacket
|
||||
public class Packet41Team extends DefinedPacket
|
||||
{
|
||||
|
||||
private String name;
|
||||
@@ -23,17 +27,12 @@ public class PacketD1Team extends DefinedPacket
|
||||
private short playerCount;
|
||||
private String[] players;
|
||||
|
||||
private PacketD1Team()
|
||||
{
|
||||
super( 0xD1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Packet to destroy a team.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public PacketD1Team(String name)
|
||||
public Packet41Team(String name)
|
||||
{
|
||||
this();
|
||||
this.name = name;
|
@@ -1,37 +1,28 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.MinecraftInput;
|
||||
import net.md_5.bungee.protocol.MinecraftOutput;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketFAPluginMessage extends DefinedPacket
|
||||
public class Packet42PluginMessage 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)
|
||||
{
|
@@ -1,31 +1,22 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet3Chat extends DefinedPacket
|
||||
public class Packet43Kick extends DefinedPacket
|
||||
{
|
||||
|
||||
private String message;
|
||||
|
||||
private Packet3Chat()
|
||||
{
|
||||
super( 0x03 );
|
||||
}
|
||||
|
||||
public Packet3Chat(String message)
|
||||
{
|
||||
this();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
@@ -1,12 +1,19 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.game;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet9Respawn extends DefinedPacket
|
||||
public class Packet7Respawn extends DefinedPacket
|
||||
{
|
||||
|
||||
private int dimension;
|
||||
@@ -15,21 +22,6 @@ public class Packet9Respawn extends DefinedPacket
|
||||
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)
|
||||
{
|
@@ -0,0 +1,17 @@
|
||||
package net.md_5.bungee.protocol.handshake;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
|
||||
public class HandshakeProtocol extends Protocol
|
||||
{
|
||||
|
||||
@Getter
|
||||
private static final HandshakeProtocol instance = new HandshakeProtocol();
|
||||
|
||||
private HandshakeProtocol()
|
||||
{
|
||||
super( 0xF );
|
||||
registerPacket( 0, Packet0Handshake.class );
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package net.md_5.bungee.protocol.handshake;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet0Handshake extends DefinedPacket
|
||||
{
|
||||
|
||||
private int protocolVersion;
|
||||
private String serverAddress;
|
||||
private int serverPort;
|
||||
private int requestedProtocol;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
protocolVersion = readVarInt( buf );
|
||||
serverAddress = readString( buf );
|
||||
serverPort = readVarInt( buf );
|
||||
requestedProtocol = readVarInt( buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
{
|
||||
writeVarInt( protocolVersion, buf );
|
||||
writeString( serverAddress, buf );
|
||||
writeVarInt( serverPort, buf );
|
||||
writeVarInt( requestedProtocol, buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package net.md_5.bungee.protocol.login;
|
||||
|
||||
import net.md_5.bungee.protocol.ping.*;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
|
||||
public class LoginProtocol extends Protocol
|
||||
{
|
||||
|
||||
@Getter
|
||||
private static final LoginProtocol instance = new LoginProtocol();
|
||||
|
||||
private LoginProtocol()
|
||||
{
|
||||
super( 2 );
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package net.md_5.bungee.protocol.login;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet0Kick extends DefinedPacket
|
||||
{
|
||||
|
||||
private String 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 );
|
||||
}
|
||||
}
|
@@ -1,31 +1,23 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
package net.md_5.bungee.protocol.login;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PacketFCEncryptionResponse extends DefinedPacket
|
||||
public class Packet1EncryptionResponse 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)
|
||||
{
|
@@ -0,0 +1,37 @@
|
||||
package net.md_5.bungee.protocol.login;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet2LoginSuccess extends DefinedPacket
|
||||
{
|
||||
|
||||
private String data;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
data = readString( buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
{
|
||||
writeString( data, buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
public abstract class AbstractPacketHandler
|
||||
{
|
||||
|
||||
public void handle(Packet0KeepAlive alive) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet1Login login) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet2Handshake handshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet3Chat chat) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet9Respawn respawn) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(Packet2CEntityProperties properties) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketC8Statistic statistic) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketC9PlayerListItem playerList) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketCCSettings settings) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketCDClientStatus clientStatus) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketCEScoreboardObjective objective) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketCFScoreboardScore score) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketD0DisplayScoreboard displayScoreboard) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketD1Team team) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketFEPing ping) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketFFKick kick) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(PacketCBTabComplete tabComplete) throws Exception
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
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();
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
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 );
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
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 Packet2CEntityProperties extends DefinedPacket
|
||||
{
|
||||
|
||||
public Packet2CEntityProperties()
|
||||
{
|
||||
super( 0x2C );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
buf.readInt();
|
||||
int recordCount = buf.readInt();
|
||||
for ( int i = 0; i < recordCount; i++ )
|
||||
{
|
||||
readString( buf );
|
||||
buf.readDouble();
|
||||
short size = buf.readShort();
|
||||
for ( short s = 0; s < size; s++ )
|
||||
{
|
||||
buf.skipBytes( 25 ); // long, long, double, byte
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Packet2Handshake extends DefinedPacket
|
||||
{
|
||||
|
||||
private byte protocolVersion;
|
||||
private String username;
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
private Packet2Handshake()
|
||||
{
|
||||
super( 0x02 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
protocolVersion = buf.readByte();
|
||||
username = readString( buf );
|
||||
host = readString( buf );
|
||||
port = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
{
|
||||
buf.writeByte( protocolVersion );
|
||||
writeString( username, buf );
|
||||
writeString( host, buf );
|
||||
buf.writeInt( port );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
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 PacketC8Statistic extends DefinedPacket
|
||||
{
|
||||
|
||||
public PacketC8Statistic()
|
||||
{
|
||||
super( 0xC8 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
int len = buf.readInt();
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
readString( buf );
|
||||
buf.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
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 );
|
||||
}
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
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 );
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package net.md_5.bungee.protocol.ping;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
|
||||
public class PingProtocol extends Protocol
|
||||
{
|
||||
|
||||
@Getter
|
||||
private static final PingProtocol instance = new PingProtocol();
|
||||
|
||||
private PingProtocol()
|
||||
{
|
||||
super( 1 );
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class BulkChunk extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
short count = in.readShort();
|
||||
int size = in.readInt();
|
||||
in.readBoolean();
|
||||
in.skipBytes( size + count * 12 );
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class ByteHeader extends Instruction
|
||||
{
|
||||
|
||||
private final Instruction child;
|
||||
|
||||
ByteHeader(Instruction child)
|
||||
{
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
byte size = in.readByte();
|
||||
for ( byte b = 0; b < size; b++ )
|
||||
{
|
||||
child.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
abstract class Instruction
|
||||
{
|
||||
|
||||
static final Instruction BOOLEAN = new Jump( 1 );
|
||||
static final Instruction BULK_CHUNK = new BulkChunk();
|
||||
static final Instruction BYTE = new Jump( 1 );
|
||||
// BYTE_INT moved down
|
||||
static final Instruction DOUBLE = new Jump( 8 );
|
||||
static final Instruction FLOAT = new Jump( 4 );
|
||||
static final Instruction INT = new Jump( 4 );
|
||||
static final Instruction INT_3 = new IntHeader( new Jump( 3 ) );
|
||||
static final Instruction INT_BYTE = new IntHeader( BYTE );
|
||||
static final Instruction ITEM = new Item();
|
||||
static final Instruction LONG = new Jump( 8 );
|
||||
static final Instruction METADATA = new MetaData();
|
||||
static final Instruction OPTIONAL_MOTION = new OptionalMotion();
|
||||
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 USHORT_BYTE = new UnsignedShortByte();
|
||||
static final Instruction OPTIONAL_WINDOW = new OptionalWindow();
|
||||
// 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);
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class IntHeader extends Instruction
|
||||
{
|
||||
|
||||
private final Instruction child;
|
||||
|
||||
IntHeader(Instruction child)
|
||||
{
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int size = in.readInt();
|
||||
for ( int i = 0; i < size; i++ )
|
||||
{
|
||||
child.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class Item extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
short type = in.readShort();
|
||||
if ( type >= 0 )
|
||||
{
|
||||
in.skipBytes( 3 );
|
||||
SHORT_BYTE.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class Jump extends Instruction
|
||||
{
|
||||
|
||||
final int len;
|
||||
|
||||
Jump(int len)
|
||||
{
|
||||
if ( len < 0 )
|
||||
{
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
this.len = len;
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
in.skipBytes( len );
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class MetaData extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int x = in.readUnsignedByte();
|
||||
while ( x != 127 )
|
||||
{
|
||||
int type = x >> 5;
|
||||
switch ( type )
|
||||
{
|
||||
case 0:
|
||||
BYTE.read( in );
|
||||
break;
|
||||
case 1:
|
||||
SHORT.read( in );
|
||||
break;
|
||||
case 2:
|
||||
INT.read( in );
|
||||
break;
|
||||
case 3:
|
||||
FLOAT.read( in );
|
||||
break;
|
||||
case 4:
|
||||
STRING.read( in );
|
||||
break;
|
||||
case 5:
|
||||
ITEM.read( in );
|
||||
break;
|
||||
case 6:
|
||||
in.skipBytes( 12 ); // int, int, int
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown metadata type " + type );
|
||||
}
|
||||
x = in.readUnsignedByte();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class OptionalMotion extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int data = in.readInt();
|
||||
if ( data > 0 )
|
||||
{
|
||||
in.skipBytes( 6 );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class OptionalWindow extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
BYTE.read( in );
|
||||
byte type = in.readByte();
|
||||
STRING.read( in );
|
||||
BYTE.read( in );
|
||||
BOOLEAN.read( in );
|
||||
if ( type == 11 )
|
||||
{
|
||||
INT.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.protocol.OpCode;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
|
||||
public class PacketReader
|
||||
{
|
||||
|
||||
private final Instruction[][] instructions;
|
||||
|
||||
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 = protocol.getOpCodes()[i];
|
||||
if ( enums != null )
|
||||
{
|
||||
for ( OpCode struct : enums )
|
||||
{
|
||||
try
|
||||
{
|
||||
output.add( (Instruction) Instruction.class.getDeclaredField( struct.name() ).get( null ) );
|
||||
} catch ( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex )
|
||||
{
|
||||
throw new UnsupportedOperationException( "No definition for " + struct.name() );
|
||||
}
|
||||
}
|
||||
|
||||
List<Instruction> crushed = new ArrayList<>();
|
||||
int nextJumpSize = 0;
|
||||
for ( Instruction child : output )
|
||||
{
|
||||
if ( child instanceof Jump )
|
||||
{
|
||||
nextJumpSize += ( (Jump) child ).len;
|
||||
} else
|
||||
{
|
||||
if ( nextJumpSize != 0 )
|
||||
{
|
||||
crushed.add( new Jump( nextJumpSize ) );
|
||||
}
|
||||
crushed.add( child );
|
||||
nextJumpSize = 0;
|
||||
}
|
||||
}
|
||||
if ( nextJumpSize != 0 )
|
||||
{
|
||||
crushed.add( new Jump( nextJumpSize ) );
|
||||
}
|
||||
|
||||
instructions[i] = crushed.toArray( new Instruction[ crushed.size() ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tryRead(short packetId, ByteBuf in)
|
||||
{
|
||||
Instruction[] packetDef = instructions[packetId];
|
||||
|
||||
if ( packetDef != null )
|
||||
{
|
||||
for ( Instruction instruction : packetDef )
|
||||
{
|
||||
instruction.read( in );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class ShortHeader extends Instruction
|
||||
{
|
||||
|
||||
private final Instruction child;
|
||||
|
||||
ShortHeader(Instruction child)
|
||||
{
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
short size = in.readShort();
|
||||
for ( short s = 0; s < size; s++ )
|
||||
{
|
||||
child.read( in );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
package net.md_5.bungee.protocol.skip;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
class UnsignedShortByte extends Instruction
|
||||
{
|
||||
|
||||
@Override
|
||||
void read(ByteBuf in)
|
||||
{
|
||||
int size = in.readUnsignedShort();
|
||||
in.skipBytes( size );
|
||||
}
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
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] );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user