mirror of
https://github.com/burrow-dev/burrow-client.git
synced 2026-11-18 17:37:50 -05:00
Client 1.4.0: a client log for bug reports, and sign-up is for players 18 and over
- the client keeps a log (app/log.js): its own messages, the pages' and the game's warnings and errors, pages that would not load, crashes. at most two files of 1 MB; sign-in tokens and passwords are kept out. "Show client log" in the settings opens its folder - the sign-up box says 18 or older - "Guide (client side)" is just "Guide"
This commit is contained in:
1 parent
8a1b60ad42
commit
22ed8c6792
5 files changed
+156
-3
No files matched your search
+5
-2
@@ -371,7 +371,7 @@
|
||||
</label>
|
||||
<label class="check"><input id="new-remember" type="checkbox"> Remember me</label>
|
||||
<label class="check agree"><input id="new-agreed" type="checkbox">
|
||||
<span>I am 16 or older, and old enough in my country to agree to this myself. I agree to the <a href="#" id="terms-signup">Terms of Service</a> and the <a href="#" id="privacy-signup">Privacy Policy</a>.</span></label>
|
||||
<span>I am 18 or older, and old enough in my country to agree to this myself. I agree to the <a href="#" id="terms-signup">Terms of Service</a> and the <a href="#" id="privacy-signup">Privacy Policy</a>.</span></label>
|
||||
<button id="sign-up" class="main" type="submit">Create account</button>
|
||||
</div>
|
||||
<p id="signup-status" class="status" role="status"></p>
|
||||
@@ -391,7 +391,7 @@
|
||||
<option value="4">Developer</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="check"><input id="guide" type="checkbox" data-choice> Guide (client side)</label>
|
||||
<label class="check"><input id="guide" type="checkbox" data-choice> Guide</label>
|
||||
<label>Starting room
|
||||
<input id="starting-room" type="text" spellcheck="false" placeholder="jamaa_township.room_main">
|
||||
</label>
|
||||
@@ -402,6 +402,8 @@
|
||||
<label class="check"><input id="allow-unencrypted" type="checkbox"> Allow unencrypted</label>
|
||||
<label class="check" id="auto-update-part" hidden><input id="auto-update" type="checkbox"> Automatic updates</label>
|
||||
<p class="hint" id="version-hint"></p>
|
||||
<button type="button" id="show-log">Show client log</button>
|
||||
<p class="hint">Attach client.log to a bug report.</p>
|
||||
</details>
|
||||
</div>
|
||||
</main>
|
||||
@@ -1651,6 +1653,7 @@
|
||||
}
|
||||
});
|
||||
$("auto-update").addEventListener("change", () => window.client.setAutoUpdate($("auto-update").checked));
|
||||
$("show-log").addEventListener("click", () => window.client.showLog());
|
||||
|
||||
window.client.info().then(result => {
|
||||
info = result;
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
|
||||
const {app} = require("electron");
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
|
||||
// the client's log, for players to attach to a bug report: what the client
|
||||
// itself says, what its pages and the game print to their consoles
|
||||
// (warnings and errors), and crashes and pages that would not load. it is
|
||||
// <data folder>/logs/client.log; once that is MAX_BYTES it becomes
|
||||
// client.old.log (the one before it goes) and a new one starts, so the two
|
||||
// are never more than twice that. "Show client log" in the client's
|
||||
// settings (index.html) opens the folder.
|
||||
//
|
||||
// what could let someone into an account is kept out: an address's query
|
||||
// (where sign-in tokens travel) and anything written as password=, token=
|
||||
// and the like.
|
||||
|
||||
const MAX_BYTES = 1024 * 1024;
|
||||
const MAX_ENTRY = 4000; // characters of one entry; a long stack is cut
|
||||
// a page printing in a loop fills the log with one thing: past this many
|
||||
// entries in BURST_MS the rest are counted, not written
|
||||
const BURST_ENTRIES = 200;
|
||||
const BURST_MS = 10000;
|
||||
|
||||
let file = null;
|
||||
let oldFile = null;
|
||||
let size = 0;
|
||||
let header = ""; // which client and computer: the first line of each file
|
||||
let burstStart = 0;
|
||||
let burstCount = 0;
|
||||
let leftOut = 0;
|
||||
|
||||
const SECRET = /\b(password|passwd|pass|token|session|secret|auth|nonce|code|key)(["']?\s*[:=]\s*["']?)[^\s&"',;}]+/gi;
|
||||
const QUERY = /\b(https?:\/\/[^\s?#"'<>]+)\?[^\s"'<>]*/gi;
|
||||
const scrub = text => text.replace(QUERY, "$1?…").replace(SECRET, "$1$2[hidden]");
|
||||
|
||||
const stamp = () => new Date().toISOString();
|
||||
|
||||
const append = text => {
|
||||
if (file === null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const bytes = Buffer.byteLength(text);
|
||||
if (size + bytes > MAX_BYTES) {
|
||||
fs.renameSync(file, oldFile);
|
||||
fs.writeFileSync(file, header);
|
||||
size = Buffer.byteLength(header);
|
||||
}
|
||||
fs.appendFileSync(file, text);
|
||||
size += bytes;
|
||||
}
|
||||
catch (err) {
|
||||
// a log that cannot be written is no reason to stop the client
|
||||
}
|
||||
};
|
||||
|
||||
// `level` "info", "warn" or "error"; `source` what said it ("main", "page",
|
||||
// "game"); `parts` as console.log takes them.
|
||||
const write = (level, source, ...parts) => {
|
||||
const now = Date.now();
|
||||
if (now - burstStart > BURST_MS) {
|
||||
if (leftOut > 0) {
|
||||
append(`${stamp()} warn [log] ${leftOut} more entries in ${BURST_MS / 1000} seconds were left out\n`);
|
||||
}
|
||||
burstStart = now;
|
||||
burstCount = 0;
|
||||
leftOut = 0;
|
||||
}
|
||||
if (++burstCount > BURST_ENTRIES) {
|
||||
leftOut++;
|
||||
return;
|
||||
}
|
||||
let text = scrub(util.format(...parts));
|
||||
if (text.length > MAX_ENTRY) {
|
||||
text = `${text.slice(0, MAX_ENTRY)}… (${text.length - MAX_ENTRY} more characters)`;
|
||||
}
|
||||
append(`${stamp()} ${level.padEnd(5)} [${source}] ${text.replace(/\r?\n/g, "\n ")}\n`);
|
||||
};
|
||||
|
||||
// Chromium's console levels: 0 verbose, 1 info, 2 warning, 3 error
|
||||
const CONSOLE_LEVELS = [null, null, "warn", "error"];
|
||||
|
||||
const watchContents = contents => {
|
||||
const source = contents.getType() === "webview" ? "game" : "page";
|
||||
contents.on("console-message", (event, level, message, line, sourceId) => {
|
||||
if (CONSOLE_LEVELS[level]) {
|
||||
write(CONSOLE_LEVELS[level], source, `${message}${sourceId ? ` (${path.basename(String(sourceId).split("?")[0])}:${line})` : ""}`);
|
||||
}
|
||||
});
|
||||
contents.on("did-fail-load", (event, code, description, url, isMainFrame) => {
|
||||
if (code !== -3) { // -3: the load was stopped for another, not a failure
|
||||
write("warn", source, `could not load ${url}${isMainFrame ? "" : " (part of the page)"}: ${description} (${code})`);
|
||||
}
|
||||
});
|
||||
contents.on("plugin-crashed", (event, name, version) => write("error", source, `the ${name} plugin ${version} crashed`));
|
||||
contents.on("unresponsive", () => write("warn", source, "stopped responding"));
|
||||
contents.on("responsive", () => write("info", source, "responding again"));
|
||||
};
|
||||
|
||||
// starts the log; the data folder must be chosen by then
|
||||
const start = version => {
|
||||
const dir = path.join(app.getPath("userData"), "logs");
|
||||
try {
|
||||
fs.mkdirSync(dir, {recursive: true});
|
||||
file = path.join(dir, "client.log");
|
||||
oldFile = path.join(dir, "client.old.log");
|
||||
size = fs.existsSync(file) ? fs.statSync(file).size : 0;
|
||||
}
|
||||
catch (err) {
|
||||
file = null;
|
||||
return;
|
||||
}
|
||||
header = `${stamp()} info [main] Burrow ${version}, Electron ${process.versions.electron}, ${os.type()} ${os.release()} ${process.arch}, ${Math.round(os.totalmem() / 1048576)} MB\n`;
|
||||
append(header);
|
||||
// the main process's own console goes to the log as well
|
||||
for (const [method, level] of [["log", "info"], ["info", "info"], ["warn", "warn"], ["error", "error"]]) {
|
||||
const original = console[method].bind(console);
|
||||
console[method] = (...parts) => {
|
||||
original(...parts);
|
||||
write(level, "main", ...parts);
|
||||
};
|
||||
}
|
||||
process.on("uncaughtExceptionMonitor", err => write("error", "main", `uncaught: ${err && err.stack ? err.stack : err}`));
|
||||
process.on("unhandledRejection", err => write("error", "main", `unhandled rejection: ${err && err.stack ? err.stack : err}`));
|
||||
app.on("web-contents-created", (event, contents) => watchContents(contents));
|
||||
app.on("render-process-gone", (event, contents, details) => write("error", "main", `a page's process ended: ${details.reason} (exit code ${details.exitCode})`));
|
||||
app.on("child-process-gone", (event, details) => {
|
||||
if (details.reason !== "clean-exit") {
|
||||
write("error", "main", `the ${details.name || details.type} process ended: ${details.reason} (exit code ${details.exitCode})`);
|
||||
}
|
||||
});
|
||||
app.on("will-quit", () => write("info", "main", "quit"));
|
||||
};
|
||||
|
||||
module.exports = {start, write, file: () => file};
|
||||
@@ -5,6 +5,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const device = require("./device.js");
|
||||
const discord = require("./discord.js");
|
||||
const log = require("./log.js");
|
||||
const relay = require("./relay.js");
|
||||
const updater = require("./updater.js");
|
||||
|
||||
@@ -41,6 +42,7 @@ if (!app.requestSingleInstanceLock() && pendingLink) {
|
||||
// (boot.js), kept elsewhere; the plugin and build.json stay beside that one.
|
||||
const SHIPPED = global.burrow ? global.burrow.shipped : __dirname;
|
||||
const VERSION = require("./package.json").version;
|
||||
log.start(VERSION);
|
||||
|
||||
// a packaged build names its server in build.json (tools/build.sh --server)
|
||||
const builtFor = () => {
|
||||
@@ -518,6 +520,13 @@ ipcMain.on("showFile", (event, file) => {
|
||||
}
|
||||
});
|
||||
|
||||
// the client's log (log.js), shown in its folder for a bug report
|
||||
ipcMain.on("showLog", event => {
|
||||
if (win && event.sender === win.webContents && log.file()) {
|
||||
shell.showItemInFolder(log.file());
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on("openPage", (event, url) => {
|
||||
if (/^https?:\/\//.test(String(url))) {
|
||||
shell.openExternal(String(url));
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "aj-private-client",
|
||||
"productName": "Burrow",
|
||||
"version": "1.3.3",
|
||||
"version": "1.4.0",
|
||||
"description": "The client for the Burrow private server",
|
||||
"main": "boot.js",
|
||||
"license": "UNLICENSED"
|
||||
|
||||
@@ -27,6 +27,8 @@ contextBridge.exposeInMainWorld("client", {
|
||||
// saves a picture of the game; resolves to the file's path, or null.
|
||||
screenshot: gameContentsId => ipcRenderer.invoke("screenshot", gameContentsId),
|
||||
showFile: file => ipcRenderer.send("showFile", file),
|
||||
// the client's log file in its folder, to attach to a bug report (log.js)
|
||||
showLog: () => ipcRenderer.send("showLog"),
|
||||
toggleFullscreen: () => ipcRenderer.send("toggleFullscreen"),
|
||||
openPage: url => ipcRenderer.send("openPage", url),
|
||||
// a picture from the game to print (main.js): {image, width, height}
|
||||
|
||||
Reference in new issue
Block a user