Skip to content

Commit

Permalink
add: Detection for legacy packet serializations, 1.4.0.alpha3 for real
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 21, 2024
1 parent 0148ea8 commit a39d2bc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ private void logPacket(boolean isOutGoingPacket, Player player, String channel,
private final CommandRegistries registries = new CommandRegistries();
private final Bindable<Boolean> modifyBoundingBoxes = new Bindable<>(false);
private final Bindable<Boolean> useClientRenderer = new Bindable<>(false);
private final Bindable<Boolean> debugOutput = new Bindable<>(false);

private static final String newProtocolIdentify = "1_21_3_packetbuf";

@Initializer
private void load(MorphPlugin plugin, MorphConfigManager configManager)
Expand All @@ -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频道处理
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/feathermorph/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"hint.skill_hint": "Hint: You can activate skills by using <item> while sneaking",
"hint.skill_hint_client": "Hint: Press <key:key.morphclient.skill> to activate disguise skill",
"morph.client_version_mismatch": "<color:red>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": "<color:red>Client mod version mismatch",
"morph.cooling_down": "<color:red>Please wait before disguising again",
"morph.disguise_banned_or_not_supported": "<color:red>This disguise is not supported or disabled by server",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/feathermorph/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"hint.skill_hint" : "小提示: 手持<item>下蹲使用可以激活当前伪装的主动技能",
"hint.skill_hint_client" : "小提示:按下<key:key.morphclient.skill>键可以激活当前伪装的主动技能",
"morph.client_version_mismatch" : "<color:red>客户端模组版本不匹配,将不会启用增强功能!",
"morph.unsupported_client_behavior": "<color:red>检测到不支持的客户端行为,将不会启用增强功能!",
"morph.client_version_mismatch_kick" : "<color:red>客户端模组版本不匹配",
"morph.cooling_down" : "<color:red>请等一会再进行伪装",
"morph.disguise_banned_or_not_supported" : "<color:red>服务器不支持或已禁用此伪装",
Expand Down

0 comments on commit a39d2bc

Please sign in to comment.