diff --git a/src/main/java/xyz/nifeather/morph/network/server/MorphClientHandler.java b/src/main/java/xyz/nifeather/morph/network/server/MorphClientHandler.java index dd9efa5e..68aab559 100644 --- a/src/main/java/xyz/nifeather/morph/network/server/MorphClientHandler.java +++ b/src/main/java/xyz/nifeather/morph/network/server/MorphClientHandler.java @@ -151,6 +151,9 @@ private void logPacket(boolean isOutGoingPacket, Player player, String channel, private final CommandRegistries registries = new CommandRegistries(); private final Bindable modifyBoundingBoxes = new Bindable<>(false); private final Bindable useClientRenderer = new Bindable<>(false); + private final Bindable debugOutput = new Bindable<>(false); + + private static final String newProtocolIdentify = "1_21_3_packetbuf"; @Initializer private void load(MorphPlugin plugin, MorphConfigManager configManager) @@ -176,9 +179,37 @@ private void load(MorphPlugin plugin, MorphConfigManager configManager) if (logInComingPackets.get()) logPacket(false, player, initializeChannel, data); + try + { + var buffer = new FriendlyByteBuf(Unpooled.wrappedBuffer(data)); + + var utfData = Arrays.stream(buffer.readUtf().split(" ")).toList(); + if (utfData.stream().noneMatch(s -> s.equals(newProtocolIdentify))) + { + logger.info("'%s' is using a legacy client, which is not supported by now。".formatted(player.getName())); + rejectPlayer(player); + return; + } + + buffer.clear(); + } + catch (Throwable t) + { + logger.info("'%s' is using a legacy client, which is not supported by now。".formatted(player.getName())); + + if (debugOutput.get()) + { + logger.info("Unable to decode packet. Is '%s' using a legacy client? %s".formatted(player.getName(), t.getMessage())); + t.printStackTrace(); + } + + rejectPlayer(player); + return; + } + playerConnectionStates.put(player, InitializeState.HANDSHAKE); - this.sendPacket(initializeChannel, player, ""); + this.sendPacket(initializeChannel, player, newProtocolIdentify); }); // 注册api频道处理 @@ -330,6 +361,8 @@ private void load(MorphPlugin plugin, MorphConfigManager configManager) configManager.bind(useClientRenderer, ConfigOption.USE_CLIENT_RENDERER); + configManager.bind(debugOutput, ConfigOption.DEBUG_OUTPUT); + modifyBoundingBoxes.onValueChanged((o, n) -> { var players = Bukkit.getOnlinePlayers(); diff --git a/src/main/resources/assets/feathermorph/lang/en_us.json b/src/main/resources/assets/feathermorph/lang/en_us.json index 8a5aad66..1b1b0fe1 100644 --- a/src/main/resources/assets/feathermorph/lang/en_us.json +++ b/src/main/resources/assets/feathermorph/lang/en_us.json @@ -135,6 +135,7 @@ "hint.skill_hint": "Hint: You can activate skills by using while sneaking", "hint.skill_hint_client": "Hint: Press to activate disguise skill", "morph.client_version_mismatch": "Client mod version mismatch, not activating enhanced features!", + "morph.unsupported_client_behavior": "Detected unsupported client behavior, not activating enhanced features!", "morph.client_version_mismatch_kick": "Client mod version mismatch", "morph.cooling_down": "Please wait before disguising again", "morph.disguise_banned_or_not_supported": "This disguise is not supported or disabled by server", diff --git a/src/main/resources/assets/feathermorph/lang/zh_cn.json b/src/main/resources/assets/feathermorph/lang/zh_cn.json index 55f64996..88e91564 100644 --- a/src/main/resources/assets/feathermorph/lang/zh_cn.json +++ b/src/main/resources/assets/feathermorph/lang/zh_cn.json @@ -135,6 +135,7 @@ "hint.skill_hint" : "小提示: 手持下蹲使用可以激活当前伪装的主动技能", "hint.skill_hint_client" : "小提示:按下键可以激活当前伪装的主动技能", "morph.client_version_mismatch" : "客户端模组版本不匹配,将不会启用增强功能!", + "morph.unsupported_client_behavior": "检测到不支持的客户端行为,将不会启用增强功能!", "morph.client_version_mismatch_kick" : "客户端模组版本不匹配", "morph.cooling_down" : "请等一会再进行伪装", "morph.disguise_banned_or_not_supported" : "服务器不支持或已禁用此伪装",