Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signed chat state de-sync caused by execute run say #222

Merged

Conversation

sciwhiz12
Copy link
Member

This PR fixes #186 by generalizing the check in SignableCommand#of to account for any root command node, rather than only the original/dispatcher's root command node.

SignableCommand#of goes down the command parse results to find signed arguments which will form part of the signed chat state. This allows commands like /say to have their messages be signed by the client.

When running through /execute (or any other similar command) however, the message shouldn't be signed, as the command may be run by another player, making the signature on the message meaningless.

To prevent this, SignableCommand stops searching when a command node redirection loops back to the root command node (where it might go to a command like /say). This allows other commands which use redirection to still retain signed arguments, while disallowing /execute and similar commands.

However, because of NeoForge's client commands system, the root command node of the dispatcher and the root command node pointed by /execute run for redirection are different, causing the stop check above to never trigger, thus causing the client to sign the arguments.

As the server disregards the signatures, this now causes a de-sync between the signed chat state of the client and the server; thus, the client will be kicked by the server upon the next chat message, when it realizes a de-sync happened.

To fix this, we generalize the check from being the original root command node, to being any RootCommandNode. This retains compatibility with the original vanilla check, while allowing for our custom root command nodes to also count for the check.

`SignableCommand#of` goes down the command parse results to find signed
arguments which will form part of the signed chat state. This allows
commands like `/say` to have their messages be signed by the client.

When running through `/execute` (or any other similar command) however,
the message shouldn't be signed, as the command may be run by another
player, making the signature on the message meaningless.

To prevent this, `SignableCommand` stops searching when a command node
redirection loops back to the root command node (where it might go to a
command like `/say`). This allows other commands which use redirection
to still retain signed arguments, while disallowing `/execute` and
similar commands.

However, because of NeoForge's client commands system, the root command
node of the dispatcher and the root command node pointed by `/execute
run` for redirection are different, causing the stop check above to
never trigger, thus causing the client to sign the arguments.

As the server disregards the signatures, this now causes a de-sync
between the signed chat state of the client and the server; thus, the
client will be kicked by the server upon the next chat message, when it
realizes a de-sync happened.

To fix this, we generalize the check from being the original root
command node, to being *any* RootCommandNode. This retains compatibility
with the original vanilla check, while allowing for our custom root
command nodes to also count for the check.

Fixes neoforged#186
@sciwhiz12 sciwhiz12 added bug A bug or error 1.20 Targeted at Minecraft 1.20 labels Oct 31, 2023
@AterAnimAvis AterAnimAvis merged commit ec768db into neoforged:1.20.x Nov 2, 2023
2 checks passed
@sciwhiz12 sciwhiz12 deleted the 1.20/GH-186-commands-signed-chat branch November 2, 2023 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.20 Targeted at Minecraft 1.20 bug A bug or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disconnect due to broken chat state after using /execute run say
2 participants