mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 09:37:50 -05:00
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.
This commit is contained in:
1 parent
08780d7e69
commit
8e7b193621
2 files changed
+40
No files matched your search
@@ -138,6 +138,11 @@ const LANG_ENG = 0;
|
|||||||
const IDLE_ANIM_LAND = 14;
|
const IDLE_ANIM_LAND = 14;
|
||||||
const IDLE_ANIM_OCEAN = 29;
|
const IDLE_ANIM_OCEAN = 29;
|
||||||
const MAX_PATH_POINTS = 12;
|
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 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 MAX_BLOCKED = 1000; // from the account page; the game's own button has no limit
|
||||||
const TYPED_CHAT_TYPES = ["0", "9"];
|
const TYPED_CHAT_TYPES = ["0", "9"];
|
||||||
@@ -467,6 +472,12 @@ const sendAvatarCreate = (to, target) => {
|
|||||||
if (target.petPlayerMode) {
|
if (target.petPlayerMode) {
|
||||||
to.sendXt("uc", room.id, target.id, "on", "13");
|
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);
|
minigames.showBubble(to, target);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -671,6 +682,9 @@ const handlers = {
|
|||||||
const teleport = params[params.length - 1] === "1" ? 1 : 0;
|
const teleport = params[params.length - 1] === "1" ? 1 : 0;
|
||||||
const firstUpdate = !session.pos;
|
const firstUpdate = !session.pos;
|
||||||
session.pos = {x: coords[coords.length - 2], y: coords[coords.length - 1]};
|
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) {
|
if (!session.greeted) {
|
||||||
// the first room has loaded: the client can show a popup now.
|
// the first room has loaded: the client can show a popup now.
|
||||||
session.greeted = true;
|
session.greeted = true;
|
||||||
@@ -1302,6 +1316,7 @@ const leaveRoom = session => {
|
|||||||
room.sessions.delete(session);
|
room.sessions.delete(session);
|
||||||
session.room = null;
|
session.room = null;
|
||||||
session.pos = null;
|
session.pos = null;
|
||||||
|
delete session.activeAction;
|
||||||
minigames.roomLeft(session);
|
minigames.roomLeft(session);
|
||||||
for (const other of room.sessions) {
|
for (const other of room.sessions) {
|
||||||
// AvatarManager.avatarRemoveResponse
|
// AvatarManager.avatarRemoveResponse
|
||||||
@@ -1768,6 +1783,16 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
return;
|
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
|
// Attachment messages carry an emoticon *definition* id from the
|
||||||
// sender, while the recipient's avatar view needs that definition's
|
// sender, while the recipient's avatar view needs that definition's
|
||||||
// media id. This is the normal path used by den attachments and
|
// media id. This is the normal path used by den attachments and
|
||||||
|
|||||||
@@ -85,6 +85,21 @@ const run = async () => {
|
|||||||
await a.untilXt("ac");
|
await a.untilXt("ac");
|
||||||
await a.nextXt("il");
|
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),
|
// 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
|
// 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,
|
// path. a scout goes in first and comes back until the file has been read,
|
||||||
|
|||||||
Reference in new issue
Block a user