mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
- egg stands sell an egg again; a bought egg hatches and is named at once - pets whose bits name no pet the game has no longer stop loading - the adopt-a-pet gift path opens with nothing adopted yet - Spider Zapper and Wind Rider start with their players: spiders can be shot, and Wind Rider is played; Spider Zapper's waves are answered - Phantom's Treasure can be left from its title screen and level choice - the Touch Pool's fact window always closes - the last key in Return of the Phantoms lies where it can be reached - the Alpha HQ's bios and relics open and close - a land animal in water (and a sea one on land) is drawn when it stands - a seasonal theme's room has today's shops in it (lib/themerooms.js) - the Forgotten Archive sells its own stock, not unfinished pieces - custom items whose def is gone stay out of trade lists - the captcha is always shown, and tried again when it fails - builds 85
68 lines
2.4 KiB
JavaScript
68 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
const zlib = require("zlib");
|
|
const amf3 = require("./amf3.js");
|
|
|
|
// a room file of a seasonal theme comes from an older build (lib/http.js,
|
|
// roomAsSeenBy in lib/world.js), and so do its clickable spots: a shop there
|
|
// names the generic list it had then, which today's lists may have as
|
|
// something else or as nothing, so one theme's shops worked and another's
|
|
// did not. each spot the room has today too (by its name) is given today's
|
|
// list, kind and message; what only the old room has stays as it was.
|
|
|
|
// the volume fields that say what a click does (RoomManagerWorld: type 1 a
|
|
// minigame by typeDefId, 7 a message, 12 a generic list)
|
|
const ACTION_FIELDS = ["type", "typeDefId", "message"];
|
|
const MAX_KEPT = 40; // rooms remembered, made once each (files of up to a few MB)
|
|
|
|
const kept = new Map(); // old file's path -> the file with today's spots, or null for "as it was"
|
|
|
|
const volumes = room => (room && room.actors && Array.isArray(room.actors.ActorVolume) ? room.actors.ActorVolume : []);
|
|
|
|
const withTodaysSpots = (oldBody, currentBody) => {
|
|
const old = amf3.decode(zlib.inflateSync(oldBody));
|
|
const today = new Map(volumes(amf3.decode(zlib.inflateSync(currentBody))).filter(volume => volume && volume.name).map(volume => [volume.name, volume]));
|
|
let changed = false;
|
|
for (const volume of volumes(old)) {
|
|
const now = volume && today.get(volume.name);
|
|
if (now && ACTION_FIELDS.some(field => volume[field] !== now[field])) {
|
|
for (const field of ACTION_FIELDS) {
|
|
if (now[field] === undefined) {
|
|
delete volume[field];
|
|
}
|
|
else {
|
|
volume[field] = now[field];
|
|
}
|
|
}
|
|
changed = true;
|
|
}
|
|
}
|
|
return changed ? zlib.deflateSync(amf3.encode(old)) : oldBody;
|
|
};
|
|
|
|
// `oldBody` with today's spots, `current` giving today's file (or null);
|
|
// the old one as it was when that cannot be had or read.
|
|
const fix = async (key, oldBody, current) => {
|
|
if (kept.has(key)) {
|
|
return kept.get(key) || oldBody;
|
|
}
|
|
let body = oldBody;
|
|
try {
|
|
const currentBody = await current();
|
|
if (currentBody) {
|
|
body = withTodaysSpots(oldBody, currentBody);
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.log(`[themes] ${key}: ${err.message}`);
|
|
body = oldBody;
|
|
}
|
|
if (kept.size >= MAX_KEPT) {
|
|
kept.delete(kept.keys().next().value);
|
|
}
|
|
kept.set(key, body === oldBody ? null : body);
|
|
return body;
|
|
};
|
|
|
|
module.exports = {fix};
|