mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(rules): the game's rules window shows data/rules.txt
The rules were written into the client, so changing them meant a new build. GET /rules.txt reads data/rules.txt on every ask (no restart needed; data/ is what prod keeps between deploys and lets the server write), making it with "Example" when there is none. The rules window fetches it each time it opens: a line starting "# " is a heading in the old rules' heading style, the rest is shown as it is written (escaped, never HTML). 64 KB at most. buildVersion 75. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
0c3bfd97b3
commit
da9f2fd5a6
4 files changed
+73
-4
No files matched your search
+22
@@ -432,6 +432,7 @@ const CAPTCHA_PAGE_HEADERS = {...PAGE_HEADERS, "Content-Security-Policy": captch
|
||||
// write, from config.js.
|
||||
const LEGAL_VALUES = {legalEmail: config.legalEmail, adminEmail: config.adminEmail, operator: config.operator, hostedIn: config.hostedIn,
|
||||
version: config.termsVersion, site: new URL(config.siteUrl).host};
|
||||
const MAX_RULES_LENGTH = 65536; // characters of data/rules.txt the game is sent
|
||||
const escapeHtml = text => String(text).replace(/[&<>"]/g, sign => ({"&": "&", "<": "<", ">": ">", "\"": """})[sign]);
|
||||
const sendLegalPage = async (res, file) => {
|
||||
for (const [name, value] of Object.entries(PAGE_HEADERS)) {
|
||||
@@ -1071,6 +1072,27 @@ const handle = async (req, res) => {
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user