mirror of
https://github.com/burrow-dev/burrow-client.git
synced 2026-11-18 17:37:50 -05:00
Compare commits
8
Commits
17347462cc
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22ed8c6792 | ||
|
|
8a1b60ad42 | ||
|
|
77be498599 | ||
|
|
b52c9194f5 | ||
|
|
b1dd733a9d | ||
|
|
96774f9f5b | ||
|
|
3cb8764603 | ||
|
|
ab8bfd5a9d |
No files matched your search
+101
-12
@@ -168,11 +168,11 @@
|
||||
a { color: inherit; text-underline-offset: 3px; }
|
||||
a:hover { color: var(--text); }
|
||||
|
||||
#ban-popup, #rename-popup { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.85); }
|
||||
#rename-box { width: 100%; max-width: 400px; padding: 28px 28px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
|
||||
#rename-box h2 { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
|
||||
#rename-box .buttons { display: flex; gap: 10px; margin-top: 6px; }
|
||||
#rename-box .buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; }
|
||||
#ban-popup, #rename-popup, #link-popup { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.85); }
|
||||
#rename-box, #link-box { width: 100%; max-width: 400px; padding: 28px 28px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
|
||||
#rename-box h2, #link-box h2 { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
|
||||
#rename-box .buttons, #link-box .buttons { display: flex; gap: 10px; margin-top: 6px; }
|
||||
#rename-box .buttons button, #link-box .buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; }
|
||||
#ban-box { width: 100%; max-width: 480px; max-height: 100%; overflow-y: auto; padding: 30px 30px 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
|
||||
#ban-head { display: flex; align-items: center; gap: 14px; }
|
||||
#ban-head img { flex: none; width: 48px; height: 48px; }
|
||||
@@ -193,8 +193,9 @@
|
||||
#ban-buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; }
|
||||
|
||||
#saved { margin: 0 0 16px; padding: 0; list-style: none; }
|
||||
#saved li { display: flex; gap: 6px; margin: 0 0 6px; }
|
||||
#saved .account {
|
||||
#saved li, #link-accounts li { display: flex; gap: 6px; margin: 0 0 6px; }
|
||||
#link-accounts { margin: 0 0 16px; padding: 0; list-style: none; }
|
||||
#saved .account, #link-accounts .account {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
@@ -204,10 +205,10 @@
|
||||
text-align: left;
|
||||
font-weight: 700;
|
||||
}
|
||||
#saved .account::after { content: "→"; margin-left: auto; color: var(--muted); font-weight: 400; }
|
||||
#saved .account:hover { background: var(--text); border-color: var(--text); color: #000; }
|
||||
#saved .account::after, #link-accounts .account::after { content: "→"; margin-left: auto; color: var(--muted); font-weight: 400; }
|
||||
#saved .account:hover, #link-accounts .account:hover { background: var(--text); border-color: var(--text); color: #000; }
|
||||
#saved .account:hover::after, #saved .account:hover .where { color: #000; }
|
||||
#saved .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
#saved .name, #link-accounts .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
#saved .where { font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
|
||||
#saved .forget { flex: none; width: 40px; padding: 0; border-color: transparent; color: var(--muted); font-size: 18px; }
|
||||
#saved .forget:hover { color: var(--text); border-color: var(--line); }
|
||||
@@ -370,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>
|
||||
@@ -390,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>
|
||||
@@ -401,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>
|
||||
@@ -440,6 +443,16 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="link-popup" role="dialog" aria-modal="true" aria-labelledby="link-title" hidden>
|
||||
<div id="link-box">
|
||||
<h2 id="link-title">Sign in to the account page as</h2>
|
||||
<ul id="link-accounts"></ul>
|
||||
<div class="buttons">
|
||||
<button id="link-cancel" type="button">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="game" hidden>
|
||||
<div id="bar">
|
||||
<span id="who"></span>
|
||||
@@ -503,6 +516,7 @@
|
||||
username_taken: "That username is already taken.",
|
||||
name_not_allowed: "That username is not allowed.",
|
||||
invalid_password: "Passwords need 10 characters or more, with a capital letter, a small letter and a digit.",
|
||||
weak_password: "That password is too easy to guess: it is a common one, or has your username in it.",
|
||||
choose_animal: "Choose an animal first.",
|
||||
too_many_registrations: "Too many accounts were created from your address. Try again in an hour.",
|
||||
address_banned: "Your address is banned.",
|
||||
@@ -517,6 +531,11 @@
|
||||
const METRICS_EVERY_MS = 2000;
|
||||
// the game says when it is drawn; if it never does, show it anyway.
|
||||
const LOADING_AT_MOST_MS = 25000;
|
||||
// a game not drawn this long after it started, with the graphics card
|
||||
// in use, is taken for one the card keeps from drawing (main.js
|
||||
// gpuFallback): the client starts again without it.
|
||||
const GPU_WATCH_MS = 60000;
|
||||
let gpuWatch = null;
|
||||
|
||||
let info = null;
|
||||
let session = null; // {server, flashVars, since} while the game is open
|
||||
@@ -1077,6 +1096,7 @@
|
||||
};
|
||||
|
||||
const closeGame = message => {
|
||||
clearTimeout(gpuWatch);
|
||||
window.client.presence(null);
|
||||
$("fps").textContent = "";
|
||||
if (webview) {
|
||||
@@ -1260,6 +1280,7 @@
|
||||
$("fps").textContent = `· ${Number(event.args[0]) || 0} fps`;
|
||||
}
|
||||
if (event.channel === "initialized") {
|
||||
clearTimeout(gpuWatch);
|
||||
gameIsDrawn();
|
||||
}
|
||||
else if (event.channel === "reloadGame") {
|
||||
@@ -1276,6 +1297,10 @@
|
||||
else if (event.channel === "reportError") {
|
||||
reportError(event.args[0]);
|
||||
}
|
||||
else if (event.channel === "printImage") {
|
||||
// the game's print kits and art studios (game.html ajPrint)
|
||||
window.client.printImage(event.args[0]);
|
||||
}
|
||||
else if (event.channel === "openPage") {
|
||||
// main.js opens http and https addresses only
|
||||
window.client.openPage(String(event.args[0]));
|
||||
@@ -1300,6 +1325,13 @@
|
||||
$("loading").hidden = false;
|
||||
clearTimeout(loadingTimer);
|
||||
loadingTimer = setTimeout(gameIsDrawn, LOADING_AT_MOST_MS);
|
||||
clearTimeout(gpuWatch);
|
||||
if (info && info.gpu) {
|
||||
gpuWatch = setTimeout(() => {
|
||||
closeGame("The game did not start with the graphics card. Burrow is restarting without it (Use GPU, under Advanced, turns it back on).");
|
||||
setTimeout(() => window.client.gpuFallback(), 4000);
|
||||
}, GPU_WATCH_MS);
|
||||
}
|
||||
$("stage").prepend(webview);
|
||||
$("who").textContent = `${session.flashVars.username} · ${new URL(session.server).host}`;
|
||||
$("stats-tip").textContent = fieldValue("account-type") === "4"
|
||||
@@ -1340,6 +1372,62 @@
|
||||
setStatus("");
|
||||
});
|
||||
|
||||
// "Sign in with the Burrow client" on the server's account page (its
|
||||
// lib/manage.js; the link comes through main.js): the account played
|
||||
// now, or one remembered here, gets a ticket from the server that
|
||||
// opens the page signed in, in the browser that asked. the browser
|
||||
// already asked whether to open Burrow, so with one account there is
|
||||
// nothing more to ask.
|
||||
const tellAccountPage = (text, bad) => (session ? note(text) : setStatus(text, bad));
|
||||
const pickAccount = choices => new Promise(resolve => {
|
||||
const list = $("link-accounts");
|
||||
list.textContent = "";
|
||||
const done = choice => {
|
||||
$("link-popup").hidden = true;
|
||||
$("link-cancel").onclick = null;
|
||||
resolve(choice);
|
||||
};
|
||||
for (const choice of choices) {
|
||||
const row = document.createElement("li");
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "account";
|
||||
const name = document.createElement("span");
|
||||
name.className = "name";
|
||||
name.textContent = choice.username;
|
||||
button.append(name);
|
||||
button.addEventListener("click", () => done(choice));
|
||||
row.append(button);
|
||||
list.append(row);
|
||||
}
|
||||
$("link-cancel").onclick = () => done(null);
|
||||
$("link-popup").hidden = false;
|
||||
list.querySelector("button").focus();
|
||||
});
|
||||
window.client.onAccountLink(async nonce => {
|
||||
if (!$("link-popup").hidden) {
|
||||
return;
|
||||
}
|
||||
const choices = session
|
||||
? [{server: session.server, username: session.flashVars.username, token: session.flashVars.auth_token}]
|
||||
: remembered().filter(entry => entry.server === serverUrl());
|
||||
if (choices.length === 0) {
|
||||
tellAccountPage("Log in here first, then try the account page again.", true);
|
||||
return;
|
||||
}
|
||||
const choice = choices.length === 1 ? choices[0] : await pickAccount(choices);
|
||||
if (!choice) {
|
||||
return;
|
||||
}
|
||||
const answer = await window.client.api(choice.server, "accountTicket", {token: choice.token, nonce});
|
||||
if (answer.status !== 200 || !/^https?:\/\//.test(String(answer.body.url))) {
|
||||
tellAccountPage(answer.body.error || "The account page could not be signed in.", true);
|
||||
return;
|
||||
}
|
||||
window.client.openPage(answer.body.url);
|
||||
tellAccountPage(`Account page signed in as ${answer.body.username}.`, false);
|
||||
});
|
||||
|
||||
// another name is another account: its code is not this one's.
|
||||
$("username").addEventListener("input", () => showCodePart(false));
|
||||
|
||||
@@ -1565,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};
|
||||
+129
-2
@@ -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");
|
||||
|
||||
@@ -24,10 +25,24 @@ if (!app.commandLine.hasSwitch("user-data-dir")) {
|
||||
app.setPath("userData", path.join(app.getPath("appData"), "AJ Private Client"));
|
||||
}
|
||||
|
||||
// burrow:// links: the server's account page asks the client to sign it in
|
||||
// ("Sign in with the Burrow client", burrow://account?n=<nonce>; index.html
|
||||
// does the rest). windows and linux start a new copy with the link: the copy
|
||||
// already running takes it, and the new one goes at once. a copy started to
|
||||
// play beside the first still plays; only one that came with a link gives way.
|
||||
// macOS hands the link to the running app (open-url) instead.
|
||||
const LINK_PROTOCOL = "burrow";
|
||||
const linkIn = argv => argv.find(arg => String(arg).toLowerCase().startsWith(`${LINK_PROTOCOL}://`)) || null;
|
||||
let pendingLink = linkIn(process.argv);
|
||||
if (!app.requestSingleInstanceLock() && pendingLink) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// the folder the client was installed with. this one may be an update
|
||||
// (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 = () => {
|
||||
@@ -198,6 +213,17 @@ let updateState = null; // the last thing the updater said, for a page loaded af
|
||||
ipcMain.handle("setGpu", (event, on) => {
|
||||
fs.writeFileSync(SETTINGS_FILE, JSON.stringify({...readSettings(), gpu: on === true}));
|
||||
});
|
||||
// some graphics cards (or their drivers) leave the game on its loading
|
||||
// screen for good; players got past it by turning "Use GPU" off. the page
|
||||
// asks for that itself when the game has not drawn in time (index.html).
|
||||
ipcMain.on("gpuFallback", () => {
|
||||
if (!usesGpu || app.commandLine.hasSwitch("aj-gpu")) {
|
||||
return;
|
||||
}
|
||||
fs.writeFileSync(SETTINGS_FILE, JSON.stringify({...readSettings(), gpu: false}));
|
||||
app.relaunch();
|
||||
app.exit(0);
|
||||
});
|
||||
|
||||
// what the server is told about this computer at sign-in (device.js).
|
||||
ipcMain.handle("device", () => device.device());
|
||||
@@ -307,7 +333,8 @@ ipcMain.handle("ownVideo", (event, link) => {
|
||||
// the server's /api only answers its own pages (it checks the Origin
|
||||
// header), and this client's page is a file. so the calls the page
|
||||
// needs are made from here, where a request carries no origin.
|
||||
const API_CALLS = {status: ["GET", "/api/status"], register: ["POST", "/api/register"], ban: ["POST", "/api/ban"]};
|
||||
const API_CALLS = {status: ["GET", "/api/status"], register: ["POST", "/api/register"], ban: ["POST", "/api/ban"],
|
||||
accountTicket: ["POST", "/account/api/client-ticket"]};
|
||||
const apiRequest = (serverUrl, call, body) => new Promise(resolve => {
|
||||
const [method, apiPath] = API_CALLS[call];
|
||||
const started = Date.now();
|
||||
@@ -420,7 +447,12 @@ ipcMain.handle("captcha", (event, serverUrl, action) => new Promise(resolve => {
|
||||
captchaServer = null;
|
||||
answer("");
|
||||
});
|
||||
box.loadURL(new URL(`/captcha?action=${action === "signup" ? "signup" : "login"}`, server).href);
|
||||
box.loadURL(new URL(`/captcha?action=${action === "signup" ? "signup" : "login"}`, server).href).catch(() => {
|
||||
answer("");
|
||||
if (!box.isDestroyed()) {
|
||||
box.close();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// what the client's processes use: the game is the "Pepper Plugin" one.
|
||||
@@ -488,12 +520,100 @@ 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));
|
||||
}
|
||||
});
|
||||
|
||||
// a picture the game prints (its print kits and art studios, through the
|
||||
// game page's ajPrint): {image, a JPEG in base64; width; height}. it goes on
|
||||
// a page of its own, in a window that is never shown and runs no script,
|
||||
// and the system's print dialog opens for it; nothing of it is kept after.
|
||||
const MAX_PRINT_BASE64 = 40 * 1024 * 1024;
|
||||
ipcMain.on("printImage", (event, picture) => {
|
||||
const image = picture && typeof picture.image === "string" ? picture.image : "";
|
||||
if (!image || image.length > MAX_PRINT_BASE64 || !/^[A-Za-z0-9+/=\r\n]+$/.test(image)) {
|
||||
return;
|
||||
}
|
||||
const landscape = Number(picture.width) > Number(picture.height);
|
||||
let folder;
|
||||
try {
|
||||
folder = fs.mkdtempSync(path.join(app.getPath("temp"), "burrow-print-"));
|
||||
fs.writeFileSync(path.join(folder, "picture.jpg"), Buffer.from(image, "base64"));
|
||||
fs.writeFileSync(path.join(folder, "print.html"), "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>"
|
||||
+ `@page { margin: 0; size: ${landscape ? "landscape" : "portrait"}; } html, body { margin: 0; height: 100%; }`
|
||||
+ " img { display: block; width: 100%; height: 100%; object-fit: contain; }</style></head><body><img src=\"picture.jpg\"></body></html>");
|
||||
}
|
||||
catch (error) {
|
||||
return;
|
||||
}
|
||||
const cleanUp = () => {
|
||||
try {
|
||||
fs.rmdirSync(folder, {recursive: true});
|
||||
}
|
||||
catch (error) {
|
||||
// the temporary folder goes another time
|
||||
}
|
||||
};
|
||||
const page = new BrowserWindow({show: false, webPreferences: {javascript: false, sandbox: true, contextIsolation: true}});
|
||||
page.webContents.once("did-finish-load", () => {
|
||||
page.webContents.print({silent: false, printBackground: true}, () => {
|
||||
page.destroy();
|
||||
cleanUp();
|
||||
});
|
||||
});
|
||||
page.webContents.once("did-fail-load", () => {
|
||||
page.destroy();
|
||||
cleanUp();
|
||||
});
|
||||
page.loadFile(path.join(folder, "print.html"));
|
||||
});
|
||||
|
||||
// a burrow:// link (above), once the login page is there to take it: only
|
||||
// the account page's nonce goes on, and the window comes to the front.
|
||||
const accountNonce = link => {
|
||||
try {
|
||||
const url = new URL(link);
|
||||
const nonce = url.searchParams.get("n") || "";
|
||||
return url.protocol === `${LINK_PROTOCOL}:` && url.hostname === "account" && /^[0-9a-f]{48}$/.test(nonce) ? nonce : null;
|
||||
}
|
||||
catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const takeLink = () => {
|
||||
if (!pendingLink || !win || win.webContents.isLoading()) {
|
||||
return;
|
||||
}
|
||||
const nonce = accountNonce(pendingLink);
|
||||
pendingLink = null;
|
||||
if (nonce) {
|
||||
if (win.isMinimized()) {
|
||||
win.restore();
|
||||
}
|
||||
win.show();
|
||||
win.focus();
|
||||
win.webContents.send("accountLink", nonce);
|
||||
}
|
||||
};
|
||||
app.on("second-instance", (event, argv) => {
|
||||
pendingLink = linkIn(argv) || pendingLink;
|
||||
takeLink();
|
||||
});
|
||||
app.on("open-url", (event, link) => {
|
||||
event.preventDefault();
|
||||
pendingLink = link;
|
||||
takeLink();
|
||||
});
|
||||
|
||||
// Discord rich presence (discord.js): {appId, state, start, url} while the
|
||||
// game is open, null when it is not.
|
||||
ipcMain.on("presence", (event, info) => {
|
||||
@@ -644,7 +764,14 @@ app.whenReady().then(() => {
|
||||
},
|
||||
});
|
||||
win.setMenu(null);
|
||||
win.webContents.on("did-finish-load", takeLink);
|
||||
win.loadFile(path.join(__dirname, "index.html"));
|
||||
// an installed copy answers burrow:// links (the installers say so too;
|
||||
// this keeps it so after an update or a move). a copy run from the
|
||||
// repository leaves them to the installed one.
|
||||
if (builtFor() && !app.isDefaultProtocolClient(LINK_PROTOCOL)) {
|
||||
app.setAsDefaultProtocolClient(LINK_PROTOCOL);
|
||||
}
|
||||
if (builtFor() && global.burrow) {
|
||||
updates = updater.start({
|
||||
server: builtFor(),
|
||||
|
||||
+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"
|
||||
|
||||
@@ -13,6 +13,9 @@ contextBridge.exposeInMainWorld("client", {
|
||||
// the server's captcha ("login" or "signup") in a window of its own: its answer, or "" when there is none.
|
||||
captcha: (serverUrl, action) => ipcRenderer.invoke("captcha", serverUrl, action),
|
||||
setGpu: on => ipcRenderer.invoke("setGpu", on),
|
||||
// the game did not start drawing with the graphics card: it is turned off
|
||||
// (as "Use GPU" would) and the client starts again.
|
||||
gpuFallback: () => ipcRenderer.send("gpuFallback"),
|
||||
setAutoUpdate: on => ipcRenderer.invoke("setAutoUpdate", on),
|
||||
restartToUpdate: () => ipcRenderer.send("restartToUpdate"),
|
||||
// {state: "ready" | "download", version} from updater.js
|
||||
@@ -24,12 +27,18 @@ 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}
|
||||
printImage: picture => ipcRenderer.send("printImage", picture),
|
||||
// the player's own theatre video file, which the game page may then load; "" when stopped.
|
||||
ownVideo: link => ipcRenderer.invoke("ownVideo", link),
|
||||
// Discord rich presence (discord.js): {appId, state, start, url}, or null.
|
||||
presence: info => ipcRenderer.send("presence", info),
|
||||
onFullscreen: listener => ipcRenderer.on("fullscreen", (event, on) => listener(on)),
|
||||
onShortcut: listener => ipcRenderer.on("shortcut", (event, key) => listener(key)),
|
||||
// the server's account page asking to be signed in (main.js): its nonce.
|
||||
onAccountLink: listener => ipcRenderer.on("accountLink", (event, nonce) => listener(String(nonce))),
|
||||
});
|
||||
@@ -30,6 +30,10 @@ module.exports = {
|
||||
desktopName: "burrow.desktop",
|
||||
},
|
||||
|
||||
// burrow:// links, from the account page's "Sign in with the Burrow
|
||||
// client" (the .desktop file's MimeType; app/main.js asks for them too)
|
||||
protocols: [{name: "Burrow", schemes: ["burrow"]}],
|
||||
|
||||
linux: {
|
||||
target: [{target: "AppImage", arch: ["x64"]}, {target: "deb", arch: ["x64"]}, {target: "rpm", arch: ["x64"]}],
|
||||
icon: path.join(root, "app", "icon.png"),
|
||||
|
||||
@@ -53,6 +53,12 @@ Section "Burrow"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Burrow.exe"'
|
||||
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
|
||||
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
|
||||
|
||||
; burrow:// links, from the account page's "Sign in with the Burrow client"
|
||||
; (app/main.js writes the same when it starts)
|
||||
WriteRegStr HKCU "Software\Classes\burrow" "" "URL:burrow"
|
||||
WriteRegStr HKCU "Software\Classes\burrow" "URL Protocol" ""
|
||||
WriteRegStr HKCU "Software\Classes\burrow\shell\open\command" "" '"$INSTDIR\Burrow.exe" "%1"'
|
||||
SectionEnd
|
||||
|
||||
; only what was installed goes: the folder may be one the player chose, with
|
||||
@@ -66,4 +72,5 @@ Section "Uninstall"
|
||||
Delete "$DESKTOP\Burrow.lnk"
|
||||
DeleteRegKey HKCU "${UNINSTALL_KEY}"
|
||||
DeleteRegKey HKCU "Software\Burrow"
|
||||
DeleteRegKey HKCU "Software\Classes\burrow"
|
||||
SectionEnd
|
||||
@@ -53,6 +53,11 @@ fi
|
||||
|
||||
plist=Burrow.app/Contents/Info.plist
|
||||
/usr/libexec/PlistBuddy -c "Set :CFBundleName Burrow" -c "Set :CFBundleDisplayName Burrow" -c "Set :CFBundleIdentifier software.burrow.client" "$plist"
|
||||
# burrow:// links (the account page's "Sign in with the Burrow client"):
|
||||
# macOS takes only those the app names here.
|
||||
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" -c "Add :CFBundleURLTypes:0 dict" \
|
||||
-c "Add :CFBundleURLTypes:0:CFBundleURLName string Burrow" -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" \
|
||||
-c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string burrow" "$plist"
|
||||
|
||||
mkdir icon.iconset
|
||||
for size in 16 32 128 256; do
|
||||
|
||||
Reference in new issue
Block a user