Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
Log the protocol phase in case of trying to obtain a packet id not existing in the phase (#1107)
Dieser Commit ist enthalten in:
Ursprung
eb594fc799
Commit
f884e049c0
@ -550,8 +550,8 @@ public enum StateRegistry {
|
|||||||
|
|
||||||
public static final int STATUS_ID = 1;
|
public static final int STATUS_ID = 1;
|
||||||
public static final int LOGIN_ID = 2;
|
public static final int LOGIN_ID = 2;
|
||||||
protected final PacketRegistry clientbound = new PacketRegistry(CLIENTBOUND);
|
protected final PacketRegistry clientbound = new PacketRegistry(CLIENTBOUND, this);
|
||||||
protected final PacketRegistry serverbound = new PacketRegistry(SERVERBOUND);
|
protected final PacketRegistry serverbound = new PacketRegistry(SERVERBOUND, this);
|
||||||
|
|
||||||
public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(Direction direction,
|
public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(Direction direction,
|
||||||
ProtocolVersion version) {
|
ProtocolVersion version) {
|
||||||
@ -562,11 +562,13 @@ public enum StateRegistry {
|
|||||||
public static class PacketRegistry {
|
public static class PacketRegistry {
|
||||||
|
|
||||||
private final Direction direction;
|
private final Direction direction;
|
||||||
|
private final StateRegistry registry;
|
||||||
private final Map<ProtocolVersion, ProtocolRegistry> versions;
|
private final Map<ProtocolVersion, ProtocolRegistry> versions;
|
||||||
private boolean fallback = true;
|
private boolean fallback = true;
|
||||||
|
|
||||||
PacketRegistry(Direction direction) {
|
PacketRegistry(Direction direction, StateRegistry registry) {
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
this.registry = registry;
|
||||||
|
|
||||||
Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
|
Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
|
||||||
for (ProtocolVersion version : ProtocolVersion.values()) {
|
for (ProtocolVersion version : ProtocolVersion.values()) {
|
||||||
@ -693,8 +695,9 @@ public enum StateRegistry {
|
|||||||
final int id = this.packetClassToId.getInt(packet.getClass());
|
final int id = this.packetClassToId.getInt(packet.getClass());
|
||||||
if (id == Integer.MIN_VALUE) {
|
if (id == Integer.MIN_VALUE) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"Unable to find id for packet of type %s in %s protocol %s",
|
"Unable to find id for packet of type %s in %s protocol %s phase %s",
|
||||||
packet.getClass().getName(), PacketRegistry.this.direction, this.version
|
packet.getClass().getName(), PacketRegistry.this.direction,
|
||||||
|
this.version, PacketRegistry.this.registry
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
|
@ -44,7 +44,7 @@ class PacketRegistryTest {
|
|||||||
|
|
||||||
private StateRegistry.PacketRegistry setupRegistry() {
|
private StateRegistry.PacketRegistry setupRegistry() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||||
ProtocolUtils.Direction.CLIENTBOUND);
|
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
|
||||||
registry.register(Handshake.class, Handshake::new,
|
registry.register(Handshake.class, Handshake::new,
|
||||||
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, null, false),
|
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, null, false),
|
||||||
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false),
|
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false),
|
||||||
@ -84,7 +84,7 @@ class PacketRegistryTest {
|
|||||||
@Test
|
@Test
|
||||||
void failOnNoMappings() {
|
void failOnNoMappings() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||||
ProtocolUtils.Direction.CLIENTBOUND);
|
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
|
||||||
assertThrows(IllegalArgumentException.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
() -> registry.register(Handshake.class, Handshake::new));
|
() -> registry.register(Handshake.class, Handshake::new));
|
||||||
assertThrows(IllegalArgumentException.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
@ -94,7 +94,7 @@ class PacketRegistryTest {
|
|||||||
@Test
|
@Test
|
||||||
void failOnWrongOrder() {
|
void failOnWrongOrder() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||||
ProtocolUtils.Direction.CLIENTBOUND);
|
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
|
||||||
assertThrows(IllegalArgumentException.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
() -> registry.register(Handshake.class, Handshake::new,
|
() -> registry.register(Handshake.class, Handshake::new,
|
||||||
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, null, false),
|
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, null, false),
|
||||||
@ -115,7 +115,7 @@ class PacketRegistryTest {
|
|||||||
@Test
|
@Test
|
||||||
void failOnDuplicate() {
|
void failOnDuplicate() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||||
ProtocolUtils.Direction.CLIENTBOUND);
|
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
|
||||||
registry.register(Handshake.class, Handshake::new,
|
registry.register(Handshake.class, Handshake::new,
|
||||||
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false));
|
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false));
|
||||||
assertThrows(IllegalArgumentException.class,
|
assertThrows(IllegalArgumentException.class,
|
||||||
@ -129,7 +129,7 @@ class PacketRegistryTest {
|
|||||||
@Test
|
@Test
|
||||||
void shouldNotFailWhenRegisterLatestProtocolVersion() {
|
void shouldNotFailWhenRegisterLatestProtocolVersion() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||||
ProtocolUtils.Direction.CLIENTBOUND);
|
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
|
||||||
assertDoesNotThrow(() -> registry.register(Handshake.class, Handshake::new,
|
assertDoesNotThrow(() -> registry.register(Handshake.class, Handshake::new,
|
||||||
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false),
|
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false),
|
||||||
new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS),
|
new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS),
|
||||||
@ -139,7 +139,7 @@ class PacketRegistryTest {
|
|||||||
@Test
|
@Test
|
||||||
void registrySuppliesCorrectPacketsByProtocol() {
|
void registrySuppliesCorrectPacketsByProtocol() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
|
||||||
ProtocolUtils.Direction.CLIENTBOUND);
|
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
|
||||||
registry.register(Handshake.class, Handshake::new,
|
registry.register(Handshake.class, Handshake::new,
|
||||||
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false),
|
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false),
|
||||||
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, null, false),
|
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, null, false),
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren