Coming soon.
', sums: sums ? `Checksums` : "", }; const page = (await fs.promises.readFile(path.join(config.publicDir, "download.html"), "utf8")) .replace(/\{\{(\w+)\}\}/g, (whole, name) => (Object.hasOwn(values, name) ? values[name] : whole)); send(res, 200, page, MIME[".html"]); }; // one installer, read from disk as it goes out: they are tens of MB. const sendDownload = async (req, res, file) => { const full = path.join(config.downloadsDir, file); const stat = await statOf(file); if (!stat || !stat.isFile()) { send(res, 404, "Not found", "text/plain"); return; } res.writeHead(200, { "Content-Type": file === "SHA256SUMS" ? "text/plain; charset=utf-8" : "application/octet-stream", "Content-Length": stat.size, "Content-Disposition": file === "SHA256SUMS" ? "inline" : `attachment; filename="${file}"`, "Cache-Control": "public, max-age=86400", }); if (req.method === "HEAD") { res.end(); return; } const stream = fs.createReadStream(full); stream.on("error", () => res.destroy()); res.on("close", () => stream.destroy()); stream.pipe(res); }; const sendPage = async (res, file, headers = PAGE_HEADERS) => { for (const [name, value] of Object.entries(headers)) { res.setHeader(name, value); } send(res, 200, captcha.withScriptVersion(await fs.promises.readFile(path.join(config.publicDir, file))), MIME[".html"]); }; // A username that was rejected (lib/moderation.js) is replaced as part of // signing in: the sign-in that proved who it is gets a ticket in place of a // login token, and the ticket with a new name finishes the sign-in. A ticket // is good for a few minutes and a few tries. const RENAME_TICKET_MS = 600000; const RENAME_TRIES = 20; const renameTickets = new Map(); // SHA-256 of a ticket -> {id, expiry, tries, deviceToken} const ticketHash = ticket => crypto.createHash("sha256").update(String(ticket)).digest("hex"); const renameTicket = (account, deviceToken) => { for (const [hash, entry] of renameTickets) { if (entry.expiry < Date.now() || entry.id === account.id) { renameTickets.delete(hash); } } const ticket = crypto.randomBytes(24).toString("hex"); renameTickets.set(ticketHash(ticket), {id: account.id, expiry: Date.now() + RENAME_TICKET_MS, tries: 0, deviceToken}); return ticket; }; // the second half of such a sign-in: {rename_ticket, new_username}. const renameAndSignIn = (res, body, from) => { const hash = ticketHash(body.rename_ticket); const entry = renameTickets.get(hash); const account = entry && entry.expiry > Date.now() ? accounts.byId(entry.id) : null; if (!account || !account.nameRejected || account.locked || world.moderation.banRemaining(account) !== 0 || bans.addressBan(from.address) || ++entry.tries > RENAME_TRIES) { renameTickets.delete(hash); send(res, 401, {error_code: 101, error: "rename_expired"}); return; } const wanted = typeof body.new_username === "string" ? body.new_username.trim() : ""; world.disconnect(account); const problem = wanted.toLowerCase() === account.username.toLowerCase() ? "same_name" : accounts.rename(account, wanted); if (problem) { send(res, 401, {error_code: 101, error: "name_rejected", rename_ticket: body.rename_ticket, name_error: problem}); return; } renameTickets.delete(hash); delete account.nameRejected; manage.forget(account); accounts.recordLogin(account, "launcher", from.address); accounts.save(account); console.log(`[accounts] a rejected username was replaced by "${logText(account.username)}"`); accounts.setLoginChoices(account, body.login_choices); const token = accounts.issueToken(account); devices.noteLauncher(token, Boolean(devices.read(body.device))); send(res, 200, {auth_token: token, refresh_token: token, device_token: entry.deviceToken}); }; const authenticate = async (req, res, from) => { const body = await readJson(req); if (body.rename_ticket !== undefined) { renameAndSignIn(res, body, from); return; } // the computer it is on (lib/devices.js): a client that does not say is // out of date (before 1.3.0) or not ours. it is signed in all the same, // and its token noted (signInChecked): with config.requireDevice the game // then loads and its login popup says to update (lib/world.js), where a // refusal here only ever showed "The server refused the login (426)". const device = devices.read(body.device); const accountKey = String(body.username).trim().toLowerCase(); if (!from.local && failuresByAddress.blocked(from.key)) { send(res, 429, {error_code: 429, error: "too_many_attempts"}); return; } // A saved sign-in ("remember me"): the account its token is good for, // which is what the rest goes by. a token is only ever given after a // whole sign-in (password, captcha and 2FA code), so one that is good // stands in for them; one that is not is refused here, whatever else // the request says. (Whether the request offers a token is not what // decides: only the server's own answer for it.) const saved = accounts.byToken(body.refresh_token); // null for none, or for one that is not good if (saved) { await signInChecked(res, body, from, saved, true, device); return; } if (body.refresh_token !== undefined) { failuresByAddress.record(from.key); // error_code 100 = expired refresh token send(res, 401, {error_code: 100}); return; } // a password is not looked at before the captcha. the custom client // knows these errors; the official launcher shows them as a wrong password. const captchaProblem = await captcha.check(body, from, "login", accounts.byName(accountKey)); if (captchaProblem) { send(res, captchaProblem === "captcha_unavailable" ? 503 : 401, {error_code: 101, error: captchaProblem}); return; } const account = await accounts.authenticateAsync(body.username, body.password); if (!account) { failuresByAddress.record(from.key); // A wrong password shows in the account's own login history. const tried = accounts.byName(accountKey); if (tried) { accounts.recordLogin(tried, "launcher", from.address, false); accounts.save(tried); } // error_code 101 = wrong credentials send(res, 401, {error_code: 101}); return; } await signInChecked(res, body, from, account, false, device); }; // the rest of a sign-in, for an account whose password was right (`saved` // false) or whose saved sign-in's token was good (`saved` true; then it is // not asked for a 2FA code again, and the token it has is the one it keeps). // `device`: the computer it is on (lib/devices.js), or null for a client that does not say. const signInChecked = async (res, body, from, account, saved, device) => { const byRefresh = saved === true; // banned: said here, with how long is left (-1 for good), where a client // can show it. the game itself would only be refused at its socket with // the one line it has for that, which says neither. the password (or the // saved sign-in) was right, so this tells nobody anything a player's card // does not. // the reason goes with it: whoever got this far is the banned player. const ban = world.moderation.banOf(account); if (ban) { send(res, 401, {error_code: 101, error: "account_banned", banned_seconds: ban.seconds, ban_reason: ban.reason}); return; } // A banned address (lib/bans.js): for good, whoever signs in from it. const addressBan = bans.addressBan(from.address); if (addressBan) { send(res, 401, {error_code: 101, error: "address_banned", banned_seconds: world.moderation.PERMANENT, ban_reason: addressBan.reason}); return; } // A banned computer (lib/devices.js): for good, whichever account. a // client that sent no ids (before 1.3.0) is judged by the hardware the // account was seen on. const deviceBan = device ? devices.banOf(device) : devices.banOfAccount(account); if (deviceBan) { console.log(`[devices] "${logText(account.username)}" refused: hardware banned (ban ${logText(deviceBan.id)})`); send(res, 401, {error_code: 101, error: "device_banned", banned_seconds: world.moderation.PERMANENT, ban_reason: deviceBan.reason}); return; } // locked by its owner on the account page: the password is right, and // still nobody gets in. the launcher shows this as a failed sign-in. if (account.locked) { send(res, 401, {error_code: 101, error: "account_locked"}); return; } // two-step sign-in (lib/totp.js): after the password, a code from the // player's authenticator app, unless this device gave one in the last 30 // days and kept the token it got for it. A saved sign-in is not asked: // it was given after a code, and lasts no longer than such a token. the // custom client knows these errors; the official launcher shows them as a // wrong password, and cannot give a code. let deviceToken; if (!byRefresh && totp.isOn(account) && !totp.deviceTrusted(account, body.device_token)) { if (body.totp === undefined || body.totp === "") { send(res, 401, {error_code: 101, error: "totp_required", captcha_pass: captcha.issuePass(account, from)}); return; } if (!totp.verify(account, String(body.totp))) { failuresByAddress.record(from.key); accounts.recordLogin(account, "launcher", from.address, false); accounts.save(account); send(res, 401, {error_code: 101, error: "totp_wrong", captcha_pass: captcha.issuePass(account, from)}); return; } if (body.remember_device === true) { deviceToken = totp.trustDevice(account, "launcher"); } } // its username was rejected: a new one first (above). the official // launcher shows this as a wrong password; the account page asks too. if (account.nameRejected) { accounts.save(account); // a two-step code just used stays used send(res, 401, {error_code: 101, error: "name_rejected", rename_ticket: renameTicket(account, deviceToken)}); return; } if (device) { devices.seen(account, device, other => world.moderation.banRemaining(other) !== 0); } if (!byRefresh) { accounts.recordLogin(account, "launcher", from.address); } accounts.save(account); // the custom client's advanced settings; the official launcher sends none. accounts.setLoginChoices(account, body.login_choices); const token = byRefresh ? body.refresh_token : accounts.issueToken(account); devices.noteLauncher(token, Boolean(device)); send(res, 200, {auth_token: token, refresh_token: token, device_token: deviceToken}); }; const player = (req, res) => { const match = /^Bearer (.+)$/.exec(req.headers.authorization || ""); const account = match && accounts.byToken(match[1]); if (!account) { send(res, 401, {error: "invalid_token"}); return; } send(res, 200, { id: account.id, screen_name: account.username, game_account_type: account.accountType, language: "en", game_server: config.host, }); }; const handle = async (req, res) => { // over https, browsers are told to keep to it (a year) if (config.secureCookies) { res.setHeader("Strict-Transport-Security", "max-age=31536000"); } const url = new URL(req.url, config.baseUrl); const route = `${req.method} ${url.pathname}`; const from = limits.clientOf(req); // the web pages live under the site's name (config.siteUrl): one asked // for under the game server's name is sent there. what the game and the // client load stays here, the client's captcha page among it. if ((req.method === "GET" || req.method === "HEAD") && config.siteUrl !== config.baseUrl && String(req.headers.host || "").toLowerCase() === new URL(config.baseUrl).host && SITE_PAGES.test(url.pathname)) { res.writeHead(301, {Location: new URL(url.pathname + url.search, config.siteUrl).href, "Content-Length": 0}); res.end(); return; } const dashboardAdmin = url.pathname === "/dashboard/admin" || url.pathname.startsWith("/dashboard/admin/") || url.pathname === "/dashboard/api/admin" || url.pathname.startsWith("/dashboard/api/admin/"); const dashboardStaff = url.pathname === "/dashboard/staff" || url.pathname.startsWith("/dashboard/staff/") || url.pathname === "/dashboard/api/staff" || url.pathname.startsWith("/dashboard/api/staff/"); const isDashboard = url.pathname === "/dashboard" || dashboardAdmin || dashboardStaff; const isAdmin = url.pathname === "/admin" || url.pathname.startsWith("/admin/") || dashboardAdmin; const isAccount = url.pathname === "/account" || url.pathname.startsWith("/account/"); const isMod = url.pathname === "/mod" || url.pathname.startsWith("/mod/") || dashboardStaff; // the pages that keep a cookie answer only under this server's own names: // a request sent here by a page of another name (one whose name was made // to point at this machine, say) is not theirs to make. nor is such a // request ever this machine's own, wherever it came from. if (!limits.hostAllowed(req)) { if (isDashboard || isAdmin || isAccount || isMod) { send(res, 421, {error: "wrong_host"}); return; } from.local = false; } // GitHub sends signed push events here for optional Discord update cards. if (url.pathname === "/discord/github") { await discordBot.handleGithubWebhook(req, res); return; } // One entry point for the owner and staff dashboards. The old addresses // stay as bookmark-friendly redirects; their APIs remain available for // installed tools and are not redirected. if (req.method === "GET" && url.pathname === "/dashboard/") { res.writeHead(302, {Location: `/dashboard${url.search}`, "Content-Length": 0}); res.end(); return; } if (req.method === "GET" && url.pathname === "/dashboard") { res.setHeader("Cache-Control", "no-store"); res.setHeader("X-Frame-Options", "DENY"); res.setHeader("X-Content-Type-Options", "nosniff"); res.setHeader("Referrer-Policy", "no-referrer"); send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "dashboard.html")), "text/html; charset=utf-8"); return; } if (req.method === "GET" && url.pathname === "/admin") { res.writeHead(302, {Location: "/dashboard/admin", "Content-Length": 0}); res.end(); return; } if (req.method === "GET" && url.pathname === "/mod") { res.writeHead(302, {Location: "/dashboard/staff", "Content-Length": 0}); res.end(); return; } // the admin panel sets its own, stricter headers: none of the cross-origin // allowances below apply to it. on a public server it is not there at all // for anyone but this machine and the addresses named (config.adminAllow). if (isAdmin) { if (config.isPublic && !from.direct && !config.adminAllow.includes(from.address)) { send(res, 404, "Not found", "text/plain"); return; } if (dashboardAdmin) { url.pathname = url.pathname.startsWith("/dashboard/api/admin") ? url.pathname.replace("/dashboard/api/admin", "/admin/api") : url.pathname.replace("/dashboard/admin", "/admin"); } if (url.pathname === "/admin/api/itemart") { res.setHeader("Cache-Control", "no-store"); await itemArtUpload(req, res, url, from, null, panel.signedIn); return; } if (url.pathname === "/admin/api/music") { await musicRoute(req, res, url, from, null, panel.signedIn); return; } await panel.handle(req, res, url, from, {send, readJson}); return; } if (isAccount && url.pathname === "/account/api/itemart") { res.setHeader("Cache-Control", "no-store"); await itemArtUpload(req, res, url, from, manage.signedInAs); return; } if (isAccount) { await manage.handle(req, res, url, from, {send, readJson}); return; } // and the moderator panel (lib/modpanel.js), which is there for anyone to // reach: its moderators are players, wherever they are. if (dashboardStaff) { url.pathname = url.pathname.startsWith("/dashboard/api/staff") ? url.pathname.replace("/dashboard/api/staff", "/mod/api") : url.pathname.replace("/dashboard/staff", "/mod"); } if (isMod && url.pathname === "/mod/api/itemart") { res.setHeader("Cache-Control", "no-store"); await itemArtUpload(req, res, url, from, modpanel.signedInAs); return; } if (isMod && url.pathname === "/mod/api/music") { await musicRoute(req, res, url, from, modpanel.signedInAs); return; } if (isMod) { await modpanel.handle(req, res, url, from, {send, readJson}); return; } // the clients' own pages are files, which browsers call the origin "null": // those and this server's pages may read what the rest answers. no cookie // is used outside /account and /admin. const {origin} = req.headers; if (origin && (CLIENT_ORIGINS.includes(origin) || limits.originAllowed(req))) { res.setHeader("Access-Control-Allow-Origin", origin); res.setHeader("Access-Control-Allow-Credentials", "true"); res.setHeader("Vary", "Origin"); } res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); res.setHeader("Cache-Control", "no-cache"); res.setHeader("X-Content-Type-Options", "nosniff"); if (req.method === "OPTIONS") { res.writeHead(204); res.end(); return; } // custom items' own pictures (lib/itemart.js): served as the picture // they are and nothing else. const artPath = /^\/itemart\/(clothing|den)\/(\d{1,9})\.png$/.exec(url.pathname); if (artPath && (req.method === "GET" || req.method === "HEAD")) { const picture = itemArt.file(artPath[1], artPath[2]); if (!picture) { send(res, 404, "Not found", "text/plain"); return; } res.setHeader("Cache-Control", "public, max-age=31536000, immutable"); res.setHeader("Content-Security-Policy", "default-src 'none'; sandbox"); res.setHeader("Content-Disposition", "inline"); send(res, 200, picture.data, `image/${picture.type}`); return; } // emoji pictures for chat bubbles (lib/emoji.js) const emojiPath = /^\/emoji\/([0-9a-f-]{2,80})\.png$/.exec(url.pathname); if (emojiPath && (req.method === "GET" || req.method === "HEAD")) { const picture = await emoji.get(emojiPath[1], () => from.local || emojiFetches.allow(from.key)); if (!picture) { send(res, 404, "Not found", "text/plain"); return; } res.setHeader("Cache-Control", "public, max-age=31536000, immutable"); res.setHeader("Content-Security-Policy", "default-src 'none'; sandbox"); send(res, 200, picture, "image/png"); return; } if (url.pathname === "/api/itemart") { await itemArtUpload(req, res, url, from); return; } if (url.pathname.startsWith("/api/")) { // the item finder's API changes accounts, so other sites open in a // browser on this machine must not be able to call it. if (!limits.originAllowed(req)) { send(res, 403, {error: "forbidden"}); return; } if (url.pathname === "/api/search" && !from.local && !searches.allow(from.key)) { send(res, 429, {error: "too_many_requests"}); return; } const result = await admin.handle(route, url.searchParams, req.method === "POST" ? await readJson(req) : null, from); send(res, result.status, result.body); return; } const signupArt = req.method === "GET" && /^\/signup\/((?:thumb|hero)_[a-z]+\.svg)$/.exec(url.pathname); if (signupArt) { const art = await fs.promises.readFile(path.join(config.publicDir, "signup", signupArt[1])).catch(() => null); res.setHeader("Cache-Control", "public, max-age=86400"); send(res, art ? 200 : 404, art || "Not found", art ? MIME[".svg"] : "text/plain"); return; } // the font of the web pages, which is the game's own text font and the // client's (public/fonts/). const font = req.method === "GET" && /^\/fonts\/(CCDigitalDelivery-(?:Regular|Bold)\.otf)$/.exec(url.pathname); if (font) { res.setHeader("Cache-Control", "public, max-age=604800"); send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "fonts", font[1])), MIME[".otf"]); return; } // the chat filter's two word lists (public/filter/), which each player's // game fetches and applies itself. read from disk each time, so that a // change to a list is there for the next player to start the game. const wordList = req.method === "GET" && /^\/filter\/(level[12]\.txt)$/.exec(url.pathname); if (wordList) { const list = await fs.promises.readFile(path.join(config.publicDir, "filter", wordList[1])).catch(() => null); send(res, list ? 200 : 404, list || "Not found", "text/plain; charset=utf-8"); return; } // updates for the installed clients (config.clientUpdatesDir). each is // signed, and the clients check that themselves; the bundle's name // carries its version, so it never changes once published. const clientUpdate = req.method === "GET" && /^\/client\/(latest\.json|app-\d+\.\d+\.\d+\.burrow)$/.exec(url.pathname); if (clientUpdate) { const file = await fs.promises.readFile(path.join(config.clientUpdatesDir, clientUpdate[1])).catch(() => null); const manifest = clientUpdate[1] === "latest.json"; res.setHeader("Cache-Control", manifest ? "no-cache" : "public, max-age=31536000, immutable"); send(res, file ? 200 : 404, file || "Not found", file ? (manifest ? MIME[".json"] : "application/octet-stream") : "text/plain"); return; } const download = (req.method === "GET" || req.method === "HEAD") && DOWNLOAD_PATH.exec(url.pathname); if (download) { await sendDownload(req, res, download[1]); return; } // the badges and the Discord mark on player cards (public/badges/, lib/badges.js). const badgeArt = req.method === "GET" && /^\/badges\/([a-z0-9]{1,30}\.png)$/.exec(url.pathname); if (badgeArt) { const art = await fs.promises.readFile(path.join(config.publicDir, "badges", badgeArt[1])).catch(() => null); res.setHeader("Cache-Control", "public, max-age=3600"); send(res, art ? 200 : 404, art || "Not found", art ? MIME[".png"] : "text/plain"); return; } switch (route) { case "GET /download": await sendDownloadPage(res); return; case "GET /register": await sendPage(res, "register.html", CAPTCHA_PAGE_HEADERS); return; // the captcha on its own, for the client, whose login page is a file // that cloudflare's widget does not run in. case "GET /captcha": await sendPage(res, "captcha.html", CAPTCHA_PAGE_HEADERS); return; case "GET /captcha.js": { const text = await fs.promises.readFile(path.join(config.publicDir, "captcha.js"), "utf8"); send(res, 200, captcha.script(text), "text/javascript; charset=utf-8"); return; } case "GET /terms": await sendLegalPage(res, "terms.html"); return; case "GET /privacy": await sendLegalPage(res, "privacy.html"); return; case "GET /": await sendHomePage(res); return; case "GET /logo.png": case "GET /logo-square.png": case "GET /favicon.ico": res.setHeader("Cache-Control", "public, max-age=86400"); send(res, 200, await fs.promises.readFile(path.join(config.publicDir, url.pathname === "/logo.png" ? "logo.png" : "logo-square.png")), MIME[".png"]); return; case "GET /ban-icon.png": // the banned label on player cards (swf-src/BuddyCard.as) res.setHeader("Cache-Control", "public, max-age=86400"); send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "ban-icon.png")), MIME[".png"]); return; case "GET /bio-icon.png": // the button of the card's Bio tab res.setHeader("Cache-Control", "public, max-age=86400"); send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "bio-icon.png")), MIME[".png"]); return; case "GET /commands": await sendPage(res, "commands.html"); return; case "GET /shop": await sendPage(res, "shop.html"); return; case "GET /flashvars": send(res, 200, flashVars()); return; case "POST /authenticate": await authenticate(req, res, from); return; case "GET /player": player(req, res); return; case "POST /v1/login": await readJson(req); send(res, 200, {}); return; case "POST /v1/reportError": { // the launcher and the SWF both report crashes here; they are the best // clue for what the server got wrong. the patched SWF also sends // progress traces for media loads this way, which are only worth // having while debugging locally. const report = await readJson(req); // later lines are indented so a report cannot pass off its own text as // one of the server's log lines. const message = String(report.message).slice(0, MAX_REPORT_LENGTH).replace(/[^\x20-\x7e\n\t]/g, "?").replace(/\n\s*/g, "\n\t"); const section = String(report.section).slice(0, 20).replace(/[^\w-]/g, "?"); const trace = message.startsWith("media "); if (trace ? config.logPackets : from.local || errorReports.allow(from.key)) { const again = trace ? "" : repeatedError(`${section} ${message}`); if (again !== null) { console.log(`[${logText(trace ? "client-trace" : "client-error")}] (${logText(section)}) ${logText(message)}${logText(again)}`); if (!trace) { keepClientError(`${new Date().toISOString()} (${section}) ${message}${again}\n`); } } } send(res, 200, {}); return; } // the Jammer Wall service (playerWallHost in the flashvars); every // command carries a token the game socket handed out, see lib/walls.js. case "POST /wall": send(res, 200, world.walls.http(await readJson(req))); return; // the Art Studio posts a painting to be made a masterpiece of (the // mdUrl flashvar + "mp"): a form with the token the game socket handed // out and the picture. ArtStudioPainting.onSendComplete reads the reply. case "POST /game/mp": { if (!from.local && !paintingPosts.allow(from.key)) { send(res, 429, {success: false}); return; } const parts = formParts(req.headers["content-type"], await readBody(req, masterpieces.MAX_IMAGE_BYTES + 16 * 1024)); const {uuid, refusal, maker} = await masterpieces.upload(String(parts.get("authToken") || ""), parts.get("image")); // the game only says it could not be sent: HQ says why if (refusal && maker) { world.tellAccount(maker, refusal); } send(res, 200, uuid ? {success: true, uuid} : {success: false}); return; } case "GET /crossdomain.xml": send(res, 200, CROSS_DOMAIN, "text/xml"); return; // the game's rules window (AJClient.showRules) shows this file, read // again on every ask so it can be changed on a running server; made // with a placeholder when there is none. case "GET /rules.txt": { const file = path.join(config.dataDir, "rules.txt"); let text; try { text = await fs.promises.readFile(file, "utf8"); } catch (err) { if (err.code !== "ENOENT") { throw err; } text = "Example\n"; await fs.promises.writeFile(file, text, {flag: "wx"}).catch(() => {}); } res.setHeader("Cache-Control", "no-cache"); res.setHeader("X-Content-Type-Options", "nosniff"); send(res, 200, text.slice(0, MAX_RULES_LENGTH), "text/plain; charset=utf-8"); return; } case "GET /gameClient/game/index.html": // not to be put in a frame of anyone's; the client shows it in a view of its own. res.setHeader("X-Frame-Options", "DENY"); res.setHeader("Referrer-Policy", "no-referrer"); // the admin's switch for the theatre browser (lib/panel.js), for the page to read send(res, 200, String(await fs.promises.readFile(path.join(config.publicDir, "game.html"))) .replace("", panel.theatreBrowserOn() ? '' : ""), MIME[".html"]); return; } if (req.method !== "GET" && req.method !== "HEAD") { console.log(`[http] unhandled ${logText(route)}`); send(res, 404, {error: "not_found"}); return; } if (config.logPackets) { console.log(`[http] GET ${logText(url.pathname)}`); } // asset SWFs import their fonts from this fixed path next to the game page; // the launcher ships its own copy. if (url.pathname === "/gameClient/sharedFonts.swf") { send(res, 200, await fs.promises.readFile(config.sharedFontsSwf), MIME[".swf"]); return; } // the patched client is served in place of the CDN's own copy. if (url.pathname.endsWith("/ajclient.swf")) { send(res, 200, await fs.promises.readFile(config.clientSwf), MIME[".swf"]); return; } // A painting, by its id (MasterpieceFileServer). const painting = PAINTING_PATH.exec(url.pathname); if (painting) { const playingFrom = account => { const session = world.findOnline(account.username); return session ? limits.key(session.address) : null; }; const picture = masterpieces.mayView(painting[1], from.key, playingFrom) || from.local ? masterpieces.image(painting[1]) : null; send(res, picture ? 200 : 404, picture || "Not found", picture ? MIME[".jpg"] : "text/plain"); return; } const relPath = decodeURIComponent(url.pathname).replace(/^\/+/, ""); if (relPath === HUD_ASSETS_PATH) { send(res, 200, await fs.promises.readFile(config.hudAssetsSwf), MIME[".swf"]); return; } // the name tag badges of ours and the card's Bio tab, which the CDN has no file for. const badgeMedia = badges.mediaFile(relPath) || badges.cardMedia(relPath); if (badgeMedia) { const body = await fs.promises.readFile(badgeMedia).catch(() => null); send(res, body ? 200 : 404, body || "Not found", body ? MIME[".swf"] : "text/plain"); return; } // the extra den music tracks, which the CDN does not have as files, and // those uploaded by staff. const extra = await extraMusic.asset(relPath) || await customMusic.asset(relPath); if (extra) { send(res, extra.body ? 200 : 404, extra.body || "Not found", extra.body ? extra.type : "text/plain"); return; } const clientPack = await defpacks.clientPack(relPath); if (clientPack) { // what custom items this game has from its packs (customItems.sendAll) const packKind = defpacks.customPackKind(relPath); if (packKind) { customItems.sawPack(from.key, packKind, clientPack.version); } send(res, 200, clientPack.body, "application/octet-stream"); return; } // A room file in a seasonal theme ("