How to escape "Chat message validation failure" after PLAYER_INFO Update?
nakanotti opened this issue · 6 comments
Make sure you're doing the following
- You're using the latest build for your server version
- This isn't an issue caused by another plugin
- You've checked for duplicate issues
- You didn't use
/reload
Describe the question
After updating PLAYER_INFO in 1.19.4, when trying to chat, the multiplayer client crashes with "Chat message validation failure".
When INITIALIZE_CHAT is included in the action, I could get around it by doing nothing, but I don't want that.
Please teach me the correct way to handle INITIALIZE_CHAT.
API method(s) used
PacketType.Play.Server.PLAYER_INFO
Expected behavior
I have "ADD_PLAYER+INITIALIZE_CHAT+UPDATE_DISPLAY_NAME" actions should be handled correctly.
Code
public class PacketListener {
private static PacketAdapter playServerPlayerInfo;
public static void init() {
playServerPlayerInfo = new PacketAdapter(Constants.plugin, PacketType.Play.Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
Set<EnumWrappers.PlayerInfoAction> actions = event.getPacket().getPlayerInfoActions().read(0);
if (actions.contains(EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME) {
if (actions.contains(EnumWrappers.PlayerInfoAction.INITIALIZE_CHAT)) {
// Escape from "Chat message validation error."
return; // HELP: I don't know how to create correctly PlayerInfoData for INITIALIZE_CHAT.
}
List<PlayerInfoData> playerInfoDataList = event.getPacket().getPlayerInfoDataLists().read(1);
List<PlayerInfoData> newPlayerInfoDataList = new ArrayList<>();
for (PlayerInfoData pid : playerInfoDataList) {
// Change Display Name to "TEST"
PlayerInfoData newPid = new PlayerInfoData(pid.getProfile(), pid.getLatency(), pid.getGameMode(), WrappedChatComponent.fromText("TEST"));
newPlayerInfoDataList.add(newPid);
}
event.getPacket().getPlayerInfoDataLists().write(1, newPlayerInfoDataList);
}
}
};
ProtocolLibrary.getProtocolManager().addPacketListener(playServerPlayerInfo);
}
Additional context
nothing.
if (actions.contains(EnumWrappers.PlayerInfoAction.INITIALIZE_CHAT)) {
// Escape from "Chat message validation error."
return; // HELP: I don't know how to create correctly PlayerInfoData for INITIALIZE_CHAT.
}
You need to remove the INITIALIZE_CHAT from the actions, i.e.,
actions.remove(EnumWrappers.PlayerInfoAction.INITIALIZE_CHAT);
event.getPacket().getPlayerInfoActions().write(0, actions);
@lukalt
Thank you for your help.
I tried it your code.
But after chatting to "Chat message validation failure" occurred.
Perhaps we should keep the original packet parameters for INITIALIZE_CHAT?
Oh, I'm sorry. I completely misunderstood your question. As long as you are only changing the Display Name of the player (i.e. not changing the name in the GameProfile), just use another constructor for the PlayerInfoData:
PlayerInfoData newPid = new PlayerInfoData(pid.getProfileId(), pid.getLatency(), pid.isListed(), pid.getGameMode(), pid.getProfile(), WrappedChatComponent.fromText("TEST"), pid.getProfileKeyData());
This should correctly copy the Chat Session Data. And in this case, do not remove INITIALIZE_CHAT from the action set.
@lukalt
Thank you for your help.
I tried it your code.
But after chatting to "Chat message validation failure" occurred.
I have same problem with the following code.
public void onPacketSending(PacketEvent event) {
Set<EnumWrappers.PlayerInfoAction> actions = event.getPacket().getPlayerInfoActions().read(0);
if (actions.contains(EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME) {
List<PlayerInfoData> playerInfoDataList = event.getPacket().getPlayerInfoDataLists().read(1);
// NO MODIFY, but "Chat message validation failure" occurred.
event.getPacket().getPlayerInfoDataLists().write(1, playerInfoDataList);
}
}
@lukalt
I pulled your commits and tested the new ProtocolLib.
I replaced it with the new PlayerInfoData and it worked fine.
Thank you very much!
I will close this issue after confirming that the pull request has been merged.