Skip to content

Commit

Permalink
migrated pre-hard-fork patch 0011-do-not-break-message-chain-if-proxy…
Browse files Browse the repository at this point in the history
…-cancels-a-chat-m.patch
  • Loading branch information
TrainmasterHD committed Jan 5, 2025
1 parent 81c6c78 commit 452373d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2130,12 +_,23 @@
}

@Override
- public void handleChat(ServerboundChatPacket packet) {
+ public void handleChat(ServerboundChatPacket originalPacket) {
// CraftBukkit start - async chat
// SPIGOT-3638
if (this.server.isStopped()) {
return;
}
+ // Cheetah start - Do not break message chain if proxy cancels a chat message
+ boolean cancelled = originalPacket.lastSeenMessages().offset() < 0; // Canceling the signed chat packet on bungeecord side will break the chat chain on spigot side. Thus, the server will no longer be able to validate subsequent chat messages.
+ // We implement a little hack here: If the offset in the lastSeenMessages field is negative, the message will be correctly validated and the chat chain will be updated
+ // but the server will ignore the chat message, i.e. no events are called, it is not logged, and no player will see the message
+ final ServerboundChatPacket packet;
+ if (cancelled) {
+ packet = new ServerboundChatPacket(originalPacket.message(), originalPacket.timeStamp(), originalPacket.salt(), originalPacket.signature(), new LastSeenMessages.Update(originalPacket.lastSeenMessages().offset() == Integer.MIN_VALUE ? 0 : -originalPacket.lastSeenMessages().offset(), originalPacket.lastSeenMessages().acknowledged())); // Restore the correct offset (copy packet here, packet itself is immutable record)
+ } else {
+ packet = originalPacket;
+ }
+ // Cheetah end
// CraftBukkit end
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
if (!optional.isEmpty()) {
@@ -2148,6 +_,13 @@
return;
}

+ // Cheetah start - Do not break message chain if proxy cancels a chat message
+ if (cancelled) {
+ LOGGER.info("Skipping message of " + player.getScoreboardName() + ": '" + signedMessage.signedContent() + " because it was cancelled by BungeeCord.");
+ return;
+ }
+ // Cheetah end
+
CompletableFuture<FilteredText> completableFuture = this.filterTextPacket(signedMessage.signedContent()).thenApplyAsync(Function.identity(), this.server.chatExecutor); // CraftBukkit - async chat
CompletableFuture<Component> componentFuture = this.server.getChatDecorator().decorate(this.player, null, signedMessage.decoratedContent()); // Paper - Adventure

@@ -2200,8 +_,23 @@

@Override
public void handleSignedChatCommand(ServerboundChatCommandSignedPacket packet) {
+ // Cheetah start - Do not break message chain if proxy cancels a chat message
+ boolean cancelled = packet.lastSeenMessages().offset() < 0; // Same behavior as for ServerboundChatPacket
+ ServerboundChatCommandSignedPacket packet1;
+ if (cancelled) {
+ packet1 = new ServerboundChatCommandSignedPacket(packet.command(), packet.timeStamp(), packet.salt(), packet.argumentSignatures(), new LastSeenMessages.Update(packet.lastSeenMessages().offset() == Integer.MIN_VALUE ? 0 : -packet.lastSeenMessages().offset(), packet.lastSeenMessages().acknowledged())); // Restore the correct offset (copy packet here, packet itself is immutable record)
+ } else {
+ packet1 = packet;
+ }
+ // Cheetah end
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
if (!optional.isEmpty()) {
+ // Cheetah start - Do not break message chain if proxy cancels a chat message
+ if (cancelled) {
+ LOGGER.info("Skipping command of " + player.getScoreboardName() + ": '" + packet1.command() + " because it was cancelled by BungeeCord.");
+ return;
+ }
+ // Cheetah end
this.tryHandleChat(packet.command(), () -> {
// CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands
if (this.player.hasDisconnected()) {
@@ -2310,9 +_,20 @@
return new SignedMessageChain.DecodeException(INVALID_COMMAND_SIGNATURE);
}
Expand Down

This file was deleted.

0 comments on commit 452373d

Please sign in to comment.