Server: run a dead player's chat commands, as vanilla does (#973)

A dead guest's packets were all dropped but the respawn request, so a command typed on
the death screen never ran. ServerGamePacketListenerImpl.handleChatCommand and
handleSignedChatCommand don't look at the player's health: the commands now run.

The dedicated-server harness sends `/trigger nope` from the death screen and compares
the reply with vanilla's before respawning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-19 10:34:02 +02:00
parent ee59df13a9
commit 4953305c7b
3 changed files with 33 additions and 6 deletions
@@ -656,7 +656,15 @@ impl Game<'_> {
let Some(gi) = host.hub.guests.iter().position(|g| g.conn == conn) else {
return;
};
if host.hub.guests[gi].dead && !matches!(packet, S::ClientCommand(_)) {
// A dead player acts no more, but the death screen still respawns and chats: its
// commands run as anyone's (ServerGamePacketListenerImpl.handleChatCommand doesn't
// look at the player's health).
if host.hub.guests[gi].dead
&& !matches!(
packet,
S::ClientCommand(_) | S::ChatCommand(_) | S::ChatCommandSigned(_)
)
{
return;
}
let spectator = host.hub.guests[gi].spectator();
@@ -465,6 +465,9 @@ public final class VanillaProtocolClient {
// The villager the server's console summoned beside the spawn.
int villager = -1;
net.minecraft.world.phys.Vec3 villagerAt = null;
// When the dead player sent a command (ServerGamePacketListenerImpl.handleChatCommand runs it
// whether the player is alive or not); it respawns once the reply came, or 3 s later.
long deadCommandAt = 0;
while (System.currentTimeMillis() < deadline) {
Received r;
try {
@@ -543,9 +546,12 @@ public final class VanillaProtocolClient {
} else if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerCombatKillPacket p && step > 0) {
// The death message is left out: guests' death messages aren't Horizon's yet.
record("play-death", "death screen");
send(new net.minecraft.network.protocol.game.ServerboundClientCommandPacket(
net.minecraft.network.protocol.game.ServerboundClientCommandPacket.Action.PERFORM_RESPAWN));
respawning = true;
send(new ServerboundChatCommandPacket("trigger nope"));
deadCommandAt = now;
} else if (packet instanceof ClientboundSystemChatPacket p && deadCommandAt > 0 && !respawning
&& json(p.content()).contains("nope")) {
record("play-death", "command reply " + json(p.content()));
respawning = respawn();
} else if (packet instanceof ClientboundSystemChatPacket p && step > 0 && step < 5 + REPLIES.length) {
record("play-chat", "system " + p.overlay() + " " + json(p.content()));
} else if (packet instanceof ClientboundPlayerChatPacket p && step > 0 && step < 5 + REPLIES.length) {
@@ -660,6 +666,9 @@ public final class VanillaProtocolClient {
new LastSeenMessages.Update(0, new BitSet(), (byte) 0)));
step++;
stepAt = now;
} else if (deadCommandAt > 0 && !respawning && now - deadCommandAt > 3000) {
record("play-death", "no command reply");
respawning = respawn();
} else if (step == 6 + REPLIES.length && loadStart && respawnChunk) {
// LevelLoadTracker is done: the vanilla client leaves the loading screen.
if (runType != null) record("play-respawn", runLine(runType, run));
@@ -710,6 +719,13 @@ public final class VanillaProtocolClient {
record("error", "timed out in play, step " + step + ", chunks " + chunks.size());
}
/** The death screen's Respawn button: true, the respawn being under way. */
private boolean respawn() throws Exception {
send(new net.minecraft.network.protocol.game.ServerboundClientCommandPacket(
net.minecraft.network.protocol.game.ServerboundClientCommandPacket.Action.PERFORM_RESPAWN));
return true;
}
/**
* A run of the same packet: counted, but for the entities removed with the dead player
* (which mobs are tracked near the spawn at that moment varies).
+5 -2
View File
@@ -11,8 +11,9 @@ login, configuration and play, accepts the spawn teleport, receives the
chunks around the spawn (their bytes are compared: the world is loaded from
the same files), chats, runs /list and commands that fail (`/random value
7..7`, `/random value x`, `/trigger nope`), trades, is made an operator by
the console, runs /kill, respawns (as vanilla's LevelLoadTracker waits: until the "level
chunks load start" event and the chunk under the player), sets a furnace
the console, runs /kill, runs a command while dead, respawns (as vanilla's
LevelLoadTracker waits: until the "level chunks load start" event and the
chunk under the player), sets a furnace
beside itself, gives itself raw iron and coal, sets and asks its own score
(`@s`), opens the furnace, shift-clicks
the ore and the coal in and the ingot out, and leaves. The
@@ -28,6 +29,8 @@ exactly:
advancements, which vanilla keeps in hash maps, sorted); the command tree
node by node; the chunks sent and their bytes; the replies to the chat
message, /list and the failing commands, as text components;
- the reply to the command run while dead (ServerGamePacketListenerImpl
runs a dead player's commands, #973);
- after /kill, the packets from the death screen to the respawned
inventory (PlayerList.respawn; chat, chunk data, light and keep-alives
left out, runs of a packet counted), then that the level loads where the