Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Merge pull request #39 from Leymooo/packet-handle
Fix PacketMapping toString/equals/hashCode, do not handle Chat and Ta…
Dieser Commit ist enthalten in:
Commit
8e836a5066
@ -17,6 +17,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MinecraftPacket packet) {
|
public void handle(MinecraftPacket packet) {
|
||||||
|
//Not handleable packets: Chat, TabCompleteResponse, Respawn, Scoreboard*
|
||||||
if (!connection.getProxyPlayer().isActive()) {
|
if (!connection.getProxyPlayer().isActive()) {
|
||||||
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
|
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
|
||||||
// errors.
|
// errors.
|
||||||
|
@ -13,6 +13,7 @@ import java.util.function.Supplier;
|
|||||||
import static com.velocitypowered.proxy.protocol.ProtocolConstants.*;
|
import static com.velocitypowered.proxy.protocol.ProtocolConstants.*;
|
||||||
|
|
||||||
public enum StateRegistry {
|
public enum StateRegistry {
|
||||||
|
|
||||||
HANDSHAKE {
|
HANDSHAKE {
|
||||||
{
|
{
|
||||||
SERVERBOUND.register(Handshake.class, Handshake::new,
|
SERVERBOUND.register(Handshake.class, Handshake::new,
|
||||||
@ -35,99 +36,99 @@ public enum StateRegistry {
|
|||||||
PLAY {
|
PLAY {
|
||||||
{
|
{
|
||||||
SERVERBOUND.register(TabCompleteRequest.class, TabCompleteRequest::new,
|
SERVERBOUND.register(TabCompleteRequest.class, TabCompleteRequest::new,
|
||||||
map(0x14, MINECRAFT_1_8),
|
map(0x14, MINECRAFT_1_8, false),
|
||||||
map(0x01, MINECRAFT_1_9),
|
map(0x01, MINECRAFT_1_9, false),
|
||||||
map(0x02, MINECRAFT_1_12),
|
map(0x02, MINECRAFT_1_12, false),
|
||||||
map(0x01, MINECRAFT_1_12_1),
|
map(0x01, MINECRAFT_1_12_1, false),
|
||||||
map(0x05, MINECRAFT_1_13));
|
map(0x05, MINECRAFT_1_13, false));
|
||||||
SERVERBOUND.register(Chat.class, Chat::new,
|
SERVERBOUND.register(Chat.class, Chat::new,
|
||||||
map(0x01, MINECRAFT_1_8),
|
map(0x01, MINECRAFT_1_8, false),
|
||||||
map(0x02, MINECRAFT_1_9),
|
map(0x02, MINECRAFT_1_9, false),
|
||||||
map(0x03, MINECRAFT_1_12),
|
map(0x03, MINECRAFT_1_12, false),
|
||||||
map(0x02, MINECRAFT_1_12_2),
|
map(0x02, MINECRAFT_1_12_2, false),
|
||||||
map(0x02, MINECRAFT_1_13));
|
map(0x02, MINECRAFT_1_13, false));
|
||||||
SERVERBOUND.register(ClientSettings.class, ClientSettings::new,
|
SERVERBOUND.register(ClientSettings.class, ClientSettings::new,
|
||||||
map(0x15, MINECRAFT_1_8),
|
map(0x15, MINECRAFT_1_8, false),
|
||||||
map(0x04, MINECRAFT_1_9),
|
map(0x04, MINECRAFT_1_9, false),
|
||||||
map(0x05, MINECRAFT_1_12),
|
map(0x05, MINECRAFT_1_12, false),
|
||||||
map(0x04, MINECRAFT_1_12_1),
|
map(0x04, MINECRAFT_1_12_1, false),
|
||||||
map(0x04, MINECRAFT_1_13));
|
map(0x04, MINECRAFT_1_13, false));
|
||||||
SERVERBOUND.register(PluginMessage.class, PluginMessage::new,
|
SERVERBOUND.register(PluginMessage.class, PluginMessage::new,
|
||||||
map(0x17, MINECRAFT_1_8),
|
map(0x17, MINECRAFT_1_8, false),
|
||||||
map(0x09, MINECRAFT_1_9),
|
map(0x09, MINECRAFT_1_9, false),
|
||||||
map(0x0A, MINECRAFT_1_12),
|
map(0x0A, MINECRAFT_1_12, false),
|
||||||
map(0x09, MINECRAFT_1_12_1),
|
map(0x09, MINECRAFT_1_12_1, false),
|
||||||
map(0x0A, MINECRAFT_1_13));
|
map(0x0A, MINECRAFT_1_13, false));
|
||||||
SERVERBOUND.register(KeepAlive.class, KeepAlive::new,
|
SERVERBOUND.register(KeepAlive.class, KeepAlive::new,
|
||||||
map(0x00, MINECRAFT_1_8),
|
map(0x00, MINECRAFT_1_8, false),
|
||||||
map(0x0B, MINECRAFT_1_9),
|
map(0x0B, MINECRAFT_1_9, false),
|
||||||
map(0x0C, MINECRAFT_1_12),
|
map(0x0C, MINECRAFT_1_12, false),
|
||||||
map(0x0B, MINECRAFT_1_12_1),
|
map(0x0B, MINECRAFT_1_12_1, false),
|
||||||
map(0x0E, MINECRAFT_1_13));
|
map(0x0E, MINECRAFT_1_13, false));
|
||||||
|
|
||||||
CLIENTBOUND.register(BossBar.class, BossBar::new,
|
CLIENTBOUND.register(BossBar.class, BossBar::new,
|
||||||
map(0x0C, MINECRAFT_1_9),
|
map(0x0C, MINECRAFT_1_9, false),
|
||||||
map(0x0C, MINECRAFT_1_12));
|
map(0x0C, MINECRAFT_1_12, false));
|
||||||
CLIENTBOUND.register(Chat.class, Chat::new,
|
CLIENTBOUND.register(Chat.class, Chat::new,
|
||||||
map(0x02, MINECRAFT_1_8),
|
map(0x02, MINECRAFT_1_8, true),
|
||||||
map(0x0F, MINECRAFT_1_9),
|
map(0x0F, MINECRAFT_1_9, true),
|
||||||
map(0x0F, MINECRAFT_1_12),
|
map(0x0F, MINECRAFT_1_12, true),
|
||||||
map(0x0E, MINECRAFT_1_13));
|
map(0x0E, MINECRAFT_1_13, true));
|
||||||
CLIENTBOUND.register(TabCompleteResponse.class, TabCompleteResponse::new,
|
CLIENTBOUND.register(TabCompleteResponse.class, TabCompleteResponse::new,
|
||||||
map(0x3A, MINECRAFT_1_8),
|
map(0x3A, MINECRAFT_1_8, true),
|
||||||
map(0x0E, MINECRAFT_1_9),
|
map(0x0E, MINECRAFT_1_9, true),
|
||||||
map(0x0E, MINECRAFT_1_12),
|
map(0x0E, MINECRAFT_1_12, true),
|
||||||
map(0x10, MINECRAFT_1_13));
|
map(0x10, MINECRAFT_1_13, true));
|
||||||
CLIENTBOUND.register(PluginMessage.class, PluginMessage::new,
|
CLIENTBOUND.register(PluginMessage.class, PluginMessage::new,
|
||||||
map(0x3F, MINECRAFT_1_8),
|
map(0x3F, MINECRAFT_1_8, false),
|
||||||
map(0x18, MINECRAFT_1_9),
|
map(0x18, MINECRAFT_1_9, false),
|
||||||
map(0x18, MINECRAFT_1_12),
|
map(0x18, MINECRAFT_1_12, false),
|
||||||
map(0x19, MINECRAFT_1_13));
|
map(0x19, MINECRAFT_1_13, false));
|
||||||
CLIENTBOUND.register(Disconnect.class, Disconnect::new,
|
CLIENTBOUND.register(Disconnect.class, Disconnect::new,
|
||||||
map(0x40, MINECRAFT_1_8),
|
map(0x40, MINECRAFT_1_8, false),
|
||||||
map(0x1A, MINECRAFT_1_9),
|
map(0x1A, MINECRAFT_1_9, false),
|
||||||
map(0x1A, MINECRAFT_1_12),
|
map(0x1A, MINECRAFT_1_12, false),
|
||||||
map(0x1B, MINECRAFT_1_13));
|
map(0x1B, MINECRAFT_1_13, false));
|
||||||
CLIENTBOUND.register(KeepAlive.class, KeepAlive::new,
|
CLIENTBOUND.register(KeepAlive.class, KeepAlive::new,
|
||||||
map(0x00, MINECRAFT_1_8),
|
map(0x00, MINECRAFT_1_8, false),
|
||||||
map(0x1F, MINECRAFT_1_9),
|
map(0x1F, MINECRAFT_1_9, false),
|
||||||
map(0x1F, MINECRAFT_1_12),
|
map(0x1F, MINECRAFT_1_12, false),
|
||||||
map(0x21, MINECRAFT_1_13));
|
map(0x21, MINECRAFT_1_13, false));
|
||||||
CLIENTBOUND.register(JoinGame.class, JoinGame::new,
|
CLIENTBOUND.register(JoinGame.class, JoinGame::new,
|
||||||
map(0x01, MINECRAFT_1_8),
|
map(0x01, MINECRAFT_1_8, false),
|
||||||
map(0x23, MINECRAFT_1_9),
|
map(0x23, MINECRAFT_1_9, false),
|
||||||
map(0x23, MINECRAFT_1_12),
|
map(0x23, MINECRAFT_1_12, false),
|
||||||
map(0x25, MINECRAFT_1_13));
|
map(0x25, MINECRAFT_1_13, false));
|
||||||
CLIENTBOUND.register(Respawn.class, Respawn::new,
|
CLIENTBOUND.register(Respawn.class, Respawn::new,
|
||||||
map(0x07, MINECRAFT_1_8, false),
|
map(0x07, MINECRAFT_1_8, true),
|
||||||
map(0x33, MINECRAFT_1_9, false),
|
map(0x33, MINECRAFT_1_9, true),
|
||||||
map(0x34, MINECRAFT_1_12, false),
|
map(0x34, MINECRAFT_1_12, true),
|
||||||
map(0x35, MINECRAFT_1_12_2, false),
|
map(0x35, MINECRAFT_1_12_2, true),
|
||||||
map(0x38, MINECRAFT_1_13, false));
|
map(0x38, MINECRAFT_1_13, true));
|
||||||
CLIENTBOUND.register(ScoreboardDisplay.class, ScoreboardDisplay::new,
|
CLIENTBOUND.register(ScoreboardDisplay.class, ScoreboardDisplay::new,
|
||||||
map(0x3D, MINECRAFT_1_8, false),
|
map(0x3D, MINECRAFT_1_8, true),
|
||||||
map(0x38, MINECRAFT_1_9, false),
|
map(0x38, MINECRAFT_1_9, true),
|
||||||
map(0x3A, MINECRAFT_1_12, false),
|
map(0x3A, MINECRAFT_1_12, true),
|
||||||
map(0x3B, MINECRAFT_1_12_1, false),
|
map(0x3B, MINECRAFT_1_12_1, true),
|
||||||
map(0x3E, MINECRAFT_1_13, false));
|
map(0x3E, MINECRAFT_1_13, true));
|
||||||
CLIENTBOUND.register(ScoreboardObjective.class, ScoreboardObjective::new,
|
CLIENTBOUND.register(ScoreboardObjective.class, ScoreboardObjective::new,
|
||||||
map(0x3B, MINECRAFT_1_8, false),
|
map(0x3B, MINECRAFT_1_8, true),
|
||||||
map(0x3F, MINECRAFT_1_9, false),
|
map(0x3F, MINECRAFT_1_9, true),
|
||||||
map(0x41, MINECRAFT_1_12, false),
|
map(0x41, MINECRAFT_1_12, true),
|
||||||
map(0x42, MINECRAFT_1_12_1, false),
|
map(0x42, MINECRAFT_1_12_1, true),
|
||||||
map(0x45, MINECRAFT_1_13, false));
|
map(0x45, MINECRAFT_1_13, true));
|
||||||
CLIENTBOUND.register(ScoreboardTeam.class, ScoreboardTeam::new,
|
CLIENTBOUND.register(ScoreboardTeam.class, ScoreboardTeam::new,
|
||||||
map(0x3E, MINECRAFT_1_8, false),
|
map(0x3E, MINECRAFT_1_8, true),
|
||||||
map(0x41, MINECRAFT_1_9, false),
|
map(0x41, MINECRAFT_1_9, true),
|
||||||
map(0x43, MINECRAFT_1_12, false),
|
map(0x43, MINECRAFT_1_12, true),
|
||||||
map(0x44, MINECRAFT_1_12_1, false),
|
map(0x44, MINECRAFT_1_12_1, true),
|
||||||
map(0x47, MINECRAFT_1_13, false));
|
map(0x47, MINECRAFT_1_13, true));
|
||||||
CLIENTBOUND.register(ScoreboardSetScore.class, ScoreboardSetScore::new,
|
CLIENTBOUND.register(ScoreboardSetScore.class, ScoreboardSetScore::new,
|
||||||
map(0x3C, MINECRAFT_1_8, false),
|
map(0x3C, MINECRAFT_1_8, true),
|
||||||
map(0x42, MINECRAFT_1_9, false),
|
map(0x42, MINECRAFT_1_9, true),
|
||||||
map(0x44, MINECRAFT_1_12, false),
|
map(0x44, MINECRAFT_1_12, true),
|
||||||
map(0x45, MINECRAFT_1_12_1, false),
|
map(0x45, MINECRAFT_1_12_1, true),
|
||||||
map(0x48, MINECRAFT_1_13, false));
|
map(0x48, MINECRAFT_1_13, true));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LOGIN {
|
LOGIN {
|
||||||
@ -137,7 +138,7 @@ public enum StateRegistry {
|
|||||||
SERVERBOUND.register(EncryptionResponse.class, EncryptionResponse::new,
|
SERVERBOUND.register(EncryptionResponse.class, EncryptionResponse::new,
|
||||||
genericMappings(0x01));
|
genericMappings(0x01));
|
||||||
SERVERBOUND.register(LoginPluginResponse.class, LoginPluginResponse::new,
|
SERVERBOUND.register(LoginPluginResponse.class, LoginPluginResponse::new,
|
||||||
map(0x02, MINECRAFT_1_13));
|
map(0x02, MINECRAFT_1_13, false));
|
||||||
|
|
||||||
CLIENTBOUND.register(Disconnect.class, Disconnect::new,
|
CLIENTBOUND.register(Disconnect.class, Disconnect::new,
|
||||||
genericMappings(0x00));
|
genericMappings(0x00));
|
||||||
@ -148,7 +149,7 @@ public enum StateRegistry {
|
|||||||
CLIENTBOUND.register(SetCompression.class, SetCompression::new,
|
CLIENTBOUND.register(SetCompression.class, SetCompression::new,
|
||||||
genericMappings(0x03));
|
genericMappings(0x03));
|
||||||
CLIENTBOUND.register(LoginPluginMessage.class, LoginPluginMessage::new,
|
CLIENTBOUND.register(LoginPluginMessage.class, LoginPluginMessage::new,
|
||||||
map(0x04, MINECRAFT_1_13));
|
map(0x04, MINECRAFT_1_13, false));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -199,7 +200,7 @@ public enum StateRegistry {
|
|||||||
if (version == null) {
|
if (version == null) {
|
||||||
throw new IllegalArgumentException("Unknown protocol version " + mapping.protocolVersion);
|
throw new IllegalArgumentException("Unknown protocol version " + mapping.protocolVersion);
|
||||||
}
|
}
|
||||||
if (mapping.needPacketDecode) {
|
if (!mapping.encodeOnly) {
|
||||||
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
||||||
}
|
}
|
||||||
version.packetClassToId.put(clazz, mapping.id);
|
version.packetClassToId.put(clazz, mapping.id);
|
||||||
@ -212,7 +213,7 @@ public enum StateRegistry {
|
|||||||
for (PacketMapping m : mappings) {
|
for (PacketMapping m : mappings) {
|
||||||
if (linkedVersion == m.protocolVersion) continue links;
|
if (linkedVersion == m.protocolVersion) continue links;
|
||||||
}
|
}
|
||||||
register(clazz, packetSupplier, map(mapping.id, linkedVersion, mapping.needPacketDecode));
|
register(clazz, packetSupplier, map(mapping.id, linkedVersion, mapping.encodeOnly));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,12 +261,12 @@ public enum StateRegistry {
|
|||||||
public static class PacketMapping {
|
public static class PacketMapping {
|
||||||
private final int id;
|
private final int id;
|
||||||
private final int protocolVersion;
|
private final int protocolVersion;
|
||||||
private final boolean needPacketDecode;
|
private final boolean encodeOnly;
|
||||||
|
|
||||||
public PacketMapping(int id, int protocolVersion, boolean needPacketDecode) {
|
public PacketMapping(int id, int protocolVersion, boolean packetDecoding) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.protocolVersion = protocolVersion;
|
this.protocolVersion = protocolVersion;
|
||||||
this.needPacketDecode = needPacketDecode;
|
this.encodeOnly = packetDecoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -273,6 +274,7 @@ public enum StateRegistry {
|
|||||||
return "PacketMapping{" +
|
return "PacketMapping{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", protocolVersion=" + protocolVersion +
|
", protocolVersion=" + protocolVersion +
|
||||||
|
", encodeOnly=" + encodeOnly +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,29 +284,33 @@ public enum StateRegistry {
|
|||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
PacketMapping that = (PacketMapping) o;
|
PacketMapping that = (PacketMapping) o;
|
||||||
return id == that.id &&
|
return id == that.id &&
|
||||||
protocolVersion == that.protocolVersion;
|
protocolVersion == that.protocolVersion &&
|
||||||
|
encodeOnly == that.encodeOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, protocolVersion);
|
return Objects.hash(id, protocolVersion, encodeOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PacketMapping map(int id, int version, boolean handleFromBackend) {
|
/**
|
||||||
return new PacketMapping(id, version, handleFromBackend);
|
* Creates a PacketMapping using the provided arguments
|
||||||
}
|
* @param id Packet Id
|
||||||
|
* @param version Protocol version
|
||||||
private static PacketMapping map(int id, int version) {
|
* @param encodeOnly When true packet decoding will be disabled
|
||||||
return map(id, version, true);
|
* @return PacketMapping with the provided arguments
|
||||||
|
*/
|
||||||
|
private static PacketMapping map(int id, int version, boolean encodeOnly) {
|
||||||
|
return new PacketMapping(id, version, encodeOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PacketMapping[] genericMappings(int id) {
|
private static PacketMapping[] genericMappings(int id) {
|
||||||
return new PacketMapping[]{
|
return new PacketMapping[]{
|
||||||
map(id, MINECRAFT_1_8),
|
map(id, MINECRAFT_1_8, false),
|
||||||
map(id, MINECRAFT_1_9),
|
map(id, MINECRAFT_1_9, false),
|
||||||
map(id, MINECRAFT_1_12),
|
map(id, MINECRAFT_1_12, false),
|
||||||
map(id, MINECRAFT_1_13)
|
map(id, MINECRAFT_1_13, false)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
class PacketRegistryTest {
|
class PacketRegistryTest {
|
||||||
private StateRegistry.PacketRegistry setupRegistry() {
|
private StateRegistry.PacketRegistry setupRegistry() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.CLIENTBOUND, StateRegistry.HANDSHAKE);
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.CLIENTBOUND, StateRegistry.HANDSHAKE);
|
||||||
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, true));
|
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false));
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +44,8 @@ class PacketRegistryTest {
|
|||||||
@Test
|
@Test
|
||||||
void registrySuppliesCorrectPacketsByProtocol() {
|
void registrySuppliesCorrectPacketsByProtocol() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.CLIENTBOUND, StateRegistry.HANDSHAKE);
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.CLIENTBOUND, StateRegistry.HANDSHAKE);
|
||||||
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, true),
|
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false),
|
||||||
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, true));
|
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false));
|
||||||
assertEquals(Handshake.class, registry.getVersion(MINECRAFT_1_12).createPacket(0x00).getClass());
|
assertEquals(Handshake.class, registry.getVersion(MINECRAFT_1_12).createPacket(0x00).getClass());
|
||||||
assertEquals(Handshake.class, registry.getVersion(MINECRAFT_1_12_1).createPacket(0x01).getClass());
|
assertEquals(Handshake.class, registry.getVersion(MINECRAFT_1_12_1).createPacket(0x01).getClass());
|
||||||
assertEquals(Handshake.class, registry.getVersion(MINECRAFT_1_12_2).createPacket(0x01).getClass());
|
assertEquals(Handshake.class, registry.getVersion(MINECRAFT_1_12_2).createPacket(0x01).getClass());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren