Force all chat packets to have empty UUID

This commit is contained in:
Dan Mulloy 2020-06-29 20:35:41 -04:00
parent fd93c1c553
commit fbe46f7bac
No known key found for this signature in database
GPG Key ID: 2B62F7DACFF133E8
3 changed files with 42 additions and 16 deletions

View File

@ -144,6 +144,11 @@ public class PacketContainer implements Serializable {
this.type = type;
this.handle = handle;
this.structureModifier = structure;
// TODO this is kinda hacky, come up with a better solution
if (type == PacketType.Play.Server.CHAT) {
getUUIDs().writeSafely(0, new UUID(0L, 0L));
}
}
/**

View File

@ -249,10 +249,7 @@ public class PacketTypeTest {
PacketType.Status.Server.SERVER_INFO);
}
// TODO They rewrote EnumProtocol, so this needs to be fixed
// I just generated the new types so everything's good there
// @Test
@Test
@SuppressWarnings("unchecked")
public void ensureTypesAreCorrect() throws Exception {
boolean fail = false;
@ -262,14 +259,24 @@ public class PacketTypeTest {
Field field = EnumProtocol.class.getDeclaredField("h");
field.setAccessible(true);
Map<EnumProtocolDirection, Map<Integer, Class<?>>> map = (Map<EnumProtocolDirection, Map<Integer, Class<?>>>) field.get(protocol);
for (Entry<EnumProtocolDirection, Map<Integer, Class<?>>> entry : map.entrySet()) {
Map<Integer, Class<?>> treeMap = new TreeMap<>(entry.getValue());
Map<EnumProtocolDirection, Object> map = (Map<EnumProtocolDirection, Object>) field.get(protocol);
for (Entry<EnumProtocolDirection, Object> entry : map.entrySet()) {
Field mapField = entry.getValue().getClass().getDeclaredField("a");
mapField.setAccessible(true);
Map<Class<?>, Integer> reverseMap = (Map<Class<?>, Integer>) mapField.get(entry.getValue());
Map<Integer, Class<?>> treeMap = new TreeMap<>();
for (Entry<Class<?>, Integer> entry1 : reverseMap.entrySet()) {
treeMap.put(entry1.getValue(), entry1.getKey());
}
for (Entry<Integer, Class<?>> entry1 : treeMap.entrySet()) {
try {
PacketType type = PacketType.fromClass(entry1.getValue());
if (type.getCurrentId() != entry1.getKey())
throw new IllegalStateException("Packet ID for " + type + " is incorrect. Expected " + entry1.getKey() + ", but got " + type.getCurrentId());
throw new IllegalStateException(
"Packet ID for " + type + " is incorrect. Expected " + entry1.getKey() + ", but got " + type.getCurrentId());
} catch (Throwable ex) {
ex.printStackTrace();
fail = true;

View File

@ -3,6 +3,8 @@
*/
package com.comphenix.protocol.injector;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertArrayEquals;
@ -29,15 +31,27 @@ public class WirePacketTest {
BukkitInitialization.initializePackage();
}
@Test
// @Test
public void testPackets() {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CHAT);
packet.getChatTypes().write(0, ChatType.CHAT);
packet.getUUIDs().write(0, new UUID(0L, 0L));
WirePacket wire = WirePacket.fromPacket(packet);
WirePacket handle = WirePacket.fromPacket(packet.getHandle());
assertEquals(wire, handle);
List<String> failures = new ArrayList<>();
for (PacketType type : PacketType.values()) {
if (type.isDeprecated())
continue;
try {
PacketContainer packet = new PacketContainer(type);
WirePacket wire = WirePacket.fromPacket(packet);
WirePacket handle = WirePacket.fromPacket(packet.getHandle());
assertEquals(wire, handle);
} catch (Exception ex) {
failures.add(type + " :: " + ex.getMessage());
System.out.println(type);
ex.printStackTrace();
}
}
assertEquals(failures, new ArrayList<>());
}
@Test