Only check for correct protocol version once

This commit is contained in:
Camotoy 2022-09-18 15:18:48 -04:00
parent bb2f4644be
commit f71fa9ccac
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 31 additions and 11 deletions

View file

@ -62,8 +62,34 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
return translateAndDefault(packet); return translateAndDefault(packet);
} }
private boolean newProtocol = false; // TEMPORARY
private boolean setCorrectCodec(int protocolVersion) {
BedrockPacketCodec packetCodec = GameProtocol.getBedrockCodec(protocolVersion);
if (packetCodec == null) {
String supportedVersions = GameProtocol.getAllSupportedBedrockVersions();
if (protocolVersion > GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
// Too early to determine session locale
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.server", supportedVersions));
return false;
} else if (protocolVersion < GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", supportedVersions));
return false;
}
}
session.getUpstream().getSession().setPacketCodec(packetCodec);
return true;
}
@Override @Override
public boolean handle(RequestNetworkSettingsPacket packet) { public boolean handle(RequestNetworkSettingsPacket packet) {
if (setCorrectCodec(packet.getProtocolVersion())) {
newProtocol = true;
} else {
return true;
}
// New since 1.19.30 - sent before login packet // New since 1.19.30 - sent before login packet
PacketCompressionAlgorithm algorithm = PacketCompressionAlgorithm.ZLIB; PacketCompressionAlgorithm algorithm = PacketCompressionAlgorithm.ZLIB;
@ -84,21 +110,12 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
return true; return true;
} }
BedrockPacketCodec packetCodec = GameProtocol.getBedrockCodec(loginPacket.getProtocolVersion()); if (!newProtocol) {
if (packetCodec == null) { if (!setCorrectCodec(loginPacket.getProtocolVersion())) { // REMOVE WHEN ONLY 1.19.30 IS SUPPORTED OR 1.20
String supportedVersions = GameProtocol.getAllSupportedBedrockVersions();
if (loginPacket.getProtocolVersion() > GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
// Too early to determine session locale
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.server", supportedVersions));
return true;
} else if (loginPacket.getProtocolVersion() < GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
session.disconnect(GeyserLocale.getLocaleStringLog("geyser.network.outdated.client", supportedVersions));
return true; return true;
} }
} }
session.getUpstream().getSession().setPacketCodec(packetCodec);
// Set the block translation based off of version // Set the block translation based off of version
session.setBlockMappings(BlockRegistries.BLOCKS.forVersion(loginPacket.getProtocolVersion())); session.setBlockMappings(BlockRegistries.BLOCKS.forVersion(loginPacket.getProtocolVersion()));
session.setItemMappings(Registries.ITEMS.forVersion(loginPacket.getProtocolVersion())); session.setItemMappings(Registries.ITEMS.forVersion(loginPacket.getProtocolVersion()));

View file

@ -38,6 +38,9 @@ dependencyResolutionManagement {
maven("https://jitpack.io") { maven("https://jitpack.io") {
content { includeGroupByRegex("com\\.github\\..*") } content { includeGroupByRegex("com\\.github\\..*") }
} }
// For Adventure snapshots
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} }
} }