2022-06-08 15:12:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2022-08-01 16:01:20 +02:00
From: Nassim Jahnke <nassim@njahnke.dev>
2022-06-08 15:12:28 +02:00
Date: Mon, 17 Jan 2022 19:47:19 +0100
2022-06-12 03:11:18 +02:00
Subject: [PATCH] Kick on main for illegal chat
2022-06-08 15:12:28 +02:00
2022-06-12 03:11:18 +02:00
Makes the PlayerKickEvent fire on the main thread for
illegal characters or chat out-of-order errors.
2022-06-08 15:12:28 +02:00
2023-12-06 17:00:26 +01:00
TODO: Check all the missing schedule on mains? (1.20.3)
2023-12-09 00:14:42 +01:00
- not needed anymore, there is a check inside disconnect if off main
2023-12-06 17:00:26 +01:00
2022-06-08 15:12:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-12-06 18:47:45 +01:00
index b650e7b53bea147be0b5d88449d41f03a971ca97..09465bee578a440c0da6961dde66083cd097f5e5 100644
2022-06-08 15:12:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-12-06 17:00:26 +01:00
@@ -2049,7 +2049,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-06-08 15:12:28 +02:00
}
// CraftBukkit end
2022-07-27 23:32:15 +02:00
if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.message())) {
2022-06-08 15:12:28 +02:00
+ this.server.scheduleOnMain(() -> { // Paper - push to main for event firing
this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - add cause
+ }); // Paper - push to main for event firing
} else {
2023-12-06 17:00:26 +01:00
Optional<LastSeenMessages> optional = this.tryHandleChat(packet.lastSeenMessages());
2022-12-07 22:35:34 +01:00
2023-12-06 17:00:26 +01:00
@@ -2081,7 +2083,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-06-08 15:12:28 +02:00
@Override
public void handleChatCommand(ServerboundChatCommandPacket packet) {
if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.command())) {
+ this.server.scheduleOnMain(() -> { // Paper - push to main for event firing
2022-07-29 18:31:02 +02:00
this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper
2022-06-08 15:12:28 +02:00
+ }); // Paper - push to main for event firing
} else {
2023-12-06 17:00:26 +01:00
Optional<LastSeenMessages> optional = this.tryHandleChat(packet.lastSeenMessages());
2022-12-07 22:35:34 +01:00
2023-12-06 17:00:26 +01:00
@@ -2137,7 +2141,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
ServerGamePacketListenerImpl.LOGGER.warn("Failed to update secure chat state for {}: '{}'", this.player.getGameProfile().getName(), exception.getComponent().getString());
if (exception.shouldDisconnect()) {
2022-06-12 03:11:18 +02:00
+ this.server.scheduleOnMain(() -> { // Paper - push to main
2023-12-06 17:00:26 +01:00
this.disconnect(exception.getComponent(), exception.kickCause); // Paper - kick event causes
2022-06-12 03:11:18 +02:00
+ }); // Paper - push to main
2023-03-14 21:55:49 +01:00
} else {
2023-12-06 17:00:26 +01:00
this.player.sendSystemMessage(exception.getComponent().copy().withStyle(ChatFormatting.RED));
}