From 8e7b1936210793fb3f927aefb67d217a80a2050c Mon Sep 17 00:00:00 2001 From: Snipzil Date: Mon, 19 Oct 2026 12:14:02 -0400 Subject: [PATCH] fix(world): replay active actions for late room joins Remember a standing avatar's valid action and mirror marker, replay it after avatar creation for players entering or reloading a room, and clear it on movement or exit. Add an end-to-end regression test for late join animation sync. --- lib/world.js | 25 +++++++++++++++++++++++++ test/features.js | 15 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/world.js b/lib/world.js index 9c17bd8..670f04f 100644 --- a/lib/world.js +++ b/lib/world.js @@ -138,6 +138,11 @@ const LANG_ENG = 0; const IDLE_ANIM_LAND = 14; const IDLE_ANIM_OCEAN = 29; const MAX_PATH_POINTS = 12; +// Action messages are client-side animation names (":dance:", ":sitNW:", +// etc.). Keep the currently playing one only while the avatar is standing +// still, so someone who enters the room can see it once their client has +// created that avatar. +const ACTION_NAME = /^:[A-Za-z][A-Za-z0-9]*:$/; const TYPED_NAME = /^[A-Za-z0-9][A-Za-z0-9 '.-]{0,19}$/; // an animal's or pet's name typed by its owner const MAX_BLOCKED = 1000; // from the account page; the game's own button has no limit const TYPED_CHAT_TYPES = ["0", "9"]; @@ -467,6 +472,12 @@ const sendAvatarCreate = (to, target) => { if (target.petPlayerMode) { to.sendXt("uc", room.id, target.id, "on", "13"); } + // `ac` only creates the avatar. Actions normally travel as live `uc` + // type-3 packets, so replay a standing player's current action after `ac` + // for a player who has just entered (or reloaded) the room. + if (target.activeAction) { + to.sendXt("uc", room.id, target.id, target.activeAction.name, "3", target.activeAction.extra); + } minigames.showBubble(to, target); }; @@ -671,6 +682,9 @@ const handlers = { const teleport = params[params.length - 1] === "1" ? 1 : 0; const firstUpdate = !session.pos; session.pos = {x: coords[coords.length - 2], y: coords[coords.length - 1]}; + // Walking, swimming, or a teleport replaces a looping action on every + // client. Do not replay it to somebody entering later. + delete session.activeAction; if (!session.greeted) { // the first room has loaded: the client can show a popup now. session.greeted = true; @@ -1302,6 +1316,7 @@ const leaveRoom = session => { room.sessions.delete(session); session.room = null; session.pos = null; + delete session.activeAction; minigames.roomLeft(session); for (const other of room.sessions) { // AvatarManager.avatarRemoveResponse @@ -1768,6 +1783,16 @@ module.exports = { } return; } + // Type 3 is the action packet. It used to be sent only to people + // already in the room, leaving late arrivals with an idle avatar + // until the player performed the action again. Save the safe action + // name and its mirror marker for the next avatar-create packet. + if (fields[1] === "3") { + if (!ACTION_NAME.test(fields[0])) { + return; + } + session.activeAction = {name: fields[0], extra: fields[2] || ""}; + } // Attachment messages carry an emoticon *definition* id from the // sender, while the recipient's avatar view needs that definition's // media id. This is the normal path used by den attachments and diff --git a/test/features.js b/test/features.js index 78e0e2c..ae9e721 100644 --- a/test/features.js +++ b/test/features.js @@ -85,6 +85,21 @@ const run = async () => { await a.untilXt("ac"); await a.nextXt("il"); + // Actions are normally live type-3 chat packets. A player who enters after + // one has started must receive the current action after the avatar itself, + // including its mirror marker, rather than seeing an idle animal. + say(a, roomId, ":dance:%3%m1"); + assert.deepStrictEqual((await b.untilXt("uc")).slice(2), [String(annLogin.params.userId), ":dance:", "3", "m1"]); + const {client: c} = await arrive("Cat", "KettlePass01"); + assert.deepStrictEqual((await c.untilXt("uc")).slice(2), [String(annLogin.params.userId), ":dance:", "3", "m1"]); + await a.untilXt("ac"); // Cat appearing in the room + await a.nextXt("il"); + await b.untilXt("ac"); + await b.nextXt("il"); + c.socket.destroy(); + await a.untilXt("ar"); + await b.untilXt("ar"); + // the shop's name and stalls come from its room file (lib/roominfo.js), // read the first time anyone goes in; until then the name is made from its // path. a scout goes in first and comes back until the file has been read,