From 415eff55a9db8da9077e0e1dd5d3c3672ff66e8a Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 21:45:57 +0100 Subject: remove unused settings --- public/client.html | 27 --------------------------- webAO/client.js | 6 +++--- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/public/client.html b/public/client.html index f30e708..28a0bf1 100644 --- a/public/client.html +++ b/public/client.html @@ -507,33 +507,6 @@ placeholder="Put 1 callword per line here" onchange="changeCallwords()">

- ↓ Only touch these settings if you know what you are doing. ↓ -
-
- - -
-
- - -
-
- - -
-
- - -
-
Changing these settings will save them as a cookie.
By doing so, you agree to it being saved.
If you don't agree, disable cookies for this site in your browser.
diff --git a/webAO/client.js b/webAO/client.js index dfba169..6a2947c 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -9,7 +9,7 @@ import { EventEmitter } from 'events'; import fileExistsSync from './utils/fileExistsSync'; import { escapeChat, encodeChat, prepChat, safeTags, -} from './encoding.js'; +} from './encoding'; import mlConfig from './utils/aoml'; // Load some defaults for the background and evidence dropdowns import vanilla_character_arr from './constants/characters.js'; @@ -2957,7 +2957,7 @@ window.updateActionCommands = updateActionCommands; */ export function changeBackgroundOOC() { const selectedBG = document.getElementById('bg_select'); - const changeBGCommand = document.getElementById('bg_command').value; + const changeBGCommand = "bg $1"; const bgFilename = document.getElementById('bg_filename'); let filename = ''; @@ -2987,7 +2987,7 @@ window.changeRoleOOC = changeRoleOOC; * Random character via OOC. */ export function randomCharacterOOC() { - client.sendOOC(`/${document.getElementById('randomchar_command').value}`); + client.sendOOC(`/randomchar`); } window.randomCharacterOOC = randomCharacterOOC; -- cgit From 89a7862ed462bd952a9814d9d4be078524bcf18c Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 21:46:09 +0100 Subject: add strict with a comment --- tsconfig.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tsconfig.json b/tsconfig.json index c2f6882..7803fbe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,8 @@ "outDir": "./dist", "allowJs": true, "target": "es5", + //"strict": true, + "strictNullChecks": false, //document.getElementBy "downlevelIteration": true }, "include": ["./webAO/*"] -- cgit From e93fa6110bfe510216b558e1b256fac4c267b1a2 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 21:46:28 +0100 Subject: sort of convert encoding to typescript --- webAO/encoding.js | 85 ------------------------------------------------------- webAO/encoding.ts | 64 +++++++++++++++++++++++++++++++++++++++++ webAO/master.ts | 2 +- 3 files changed, 65 insertions(+), 86 deletions(-) delete mode 100644 webAO/encoding.js create mode 100644 webAO/encoding.ts diff --git a/webAO/encoding.js b/webAO/encoding.js deleted file mode 100644 index e6cc3ae..0000000 --- a/webAO/encoding.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Escapes a string to AO1 escape codes. - * @param {string} estring the string to be escaped - */ -export function escapeChat(estring) { - return estring - .replace(/#/g, '') - .replace(/&/g, '') - .replace(/%/g, '') - .replace(/\$/g, ''); -} - -/** - * Unescapes a string to AO1 escape codes. - * @param {string} estring the string to be unescaped - */ -export function unescapeChat(estring) { - return estring - .replace(//g, '#') - .replace(//g, '&') - .replace(//g, '%') - .replace(//g, '$'); -} - -/** - * Escapes a string to be HTML-safe. - * - * XXX: This is unnecessary if we use `createTextNode` instead! - * @param {string} unsafe an unsanitized string - */ -export function safeTags(unsafe) { - if (unsafe) { - return unsafe - .replace(/>/g, '>') - .replace(/ `\\u${(`000${ch.charCodeAt().toString(16)}`).slice(-4)}`); - } if (selectedEncoding === 'utf16') { - // Source: https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String - const buffer = new ArrayBuffer(estring.length * 2); - const result = new Uint16Array(buffer); - for (let i = 0, strLen = estring.length; i < strLen; i++) { - result[i] = estring.charCodeAt(i); - } - return String(result); - } - return estring; -} - -/** - * Decodes text on client side. - * @param {string} estring the string to be decoded - */ -export function decodeChat(estring) { - const selectedDecoding = document.getElementById('client_decoding').value; - if (selectedDecoding === 'unicode') { - // Source: https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode - return estring.replace(/\\u([\d\w]{1,})/gi, (match, group) => String.fromCharCode(parseInt(group, 16))); - } if (selectedDecoding === 'utf16') { - // Source: https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String - return String.fromCharCode.apply(null, new Uint16Array(estring.split(','))); - } - return estring; -} - -/** - * XXX: a nasty hack made by gameboyprinter. - * @param {string} msg chat message to prepare for display - */ -export function prepChat(msg) { - // TODO: make this less awful - return unescapeChat(decodeChat(msg)); -} diff --git a/webAO/encoding.ts b/webAO/encoding.ts new file mode 100644 index 0000000..930886f --- /dev/null +++ b/webAO/encoding.ts @@ -0,0 +1,64 @@ +/** + * Escapes a string to AO1 escape codes. + * @param {string} estring the string to be escaped + */ +export function escapeChat(estring: string) { + return estring + .replace(/#/g, '') + .replace(/&/g, '') + .replace(/%/g, '') + .replace(/\$/g, ''); +} + +/** + * Unescapes a string to AO1 escape codes. + * @param {string} estring the string to be unescaped + */ +export function unescapeChat(estring: string) { + return estring + .replace(//g, '#') + .replace(//g, '&') + .replace(//g, '%') + .replace(//g, '$'); +} + +/** + * Escapes a string to be HTML-safe. + * + * XXX: This is unnecessary if we use `createTextNode` instead! + * @param {string} unsafe an unsanitized string + */ +export function safeTags(unsafe: string) { + if (unsafe) { + return unsafe + .replace(/>/g, '>') + .replace(/ String.fromCharCode(parseInt(group, 16))); +} + +/** + * XXX: a nasty hack made by gameboyprinter. + * @param {string} msg chat message to prepare for display + */ +export function prepChat(msg: string) { + // TODO: make this less awful + return unescapeChat(decodeChat(msg)); +} diff --git a/webAO/master.ts b/webAO/master.ts index 8fd8779..8c850c2 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -1,6 +1,6 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs'; -import { unescapeChat, safeTags } from './encoding.js'; +import { unescapeChat, safeTags } from './encoding'; declare global { interface Window { -- cgit From 810c1d22b1e52c1662bb3cac518ebfa14ea2d59f Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 21:52:05 +0100 Subject: type the encoding functions --- webAO/encoding.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webAO/encoding.ts b/webAO/encoding.ts index 930886f..1018144 100644 --- a/webAO/encoding.ts +++ b/webAO/encoding.ts @@ -2,7 +2,7 @@ * Escapes a string to AO1 escape codes. * @param {string} estring the string to be escaped */ -export function escapeChat(estring: string) { +export function escapeChat(estring: string): string { return estring .replace(/#/g, '') .replace(/&/g, '') @@ -14,7 +14,7 @@ export function escapeChat(estring: string) { * Unescapes a string to AO1 escape codes. * @param {string} estring the string to be unescaped */ -export function unescapeChat(estring: string) { +export function unescapeChat(estring: string): string { return estring .replace(//g, '#') .replace(//g, '&') @@ -28,7 +28,7 @@ export function unescapeChat(estring: string) { * XXX: This is unnecessary if we use `createTextNode` instead! * @param {string} unsafe an unsanitized string */ -export function safeTags(unsafe: string) { +export function safeTags(unsafe: string): string { if (unsafe) { return unsafe .replace(/>/g, '>') @@ -41,7 +41,7 @@ export function safeTags(unsafe: string) { * Encode text on client side. * @param {string} estring the string to be encoded */ -export function encodeChat(estring: string) { +export function encodeChat(estring: string): string { return estring; } @@ -49,7 +49,7 @@ export function encodeChat(estring: string) { * Decodes text on client side. * @param {string} estring the string to be decoded */ -export function decodeChat(estring: string) { +export function decodeChat(estring: string): string { // Source: https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode return estring.replace(/\\u([\d\w]{1,})/gi, (match, group) => String.fromCharCode(parseInt(group, 16))); } @@ -58,7 +58,7 @@ export function decodeChat(estring: string) { * XXX: a nasty hack made by gameboyprinter. * @param {string} msg chat message to prepare for display */ -export function prepChat(msg: string) { +export function prepChat(msg: string): string { // TODO: make this less awful return unescapeChat(decodeChat(msg)); } -- cgit From 63410fd71e31e0de21aed41016983146405e2e9d Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 21:52:13 +0100 Subject: ao host is a string --- webAO/utils/aoml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index da66d0c..154274d 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -32,7 +32,7 @@ const aomlParser = (text: string) => { return parsed } -const mlConfig = (AO_HOST) => { +const mlConfig = (AO_HOST: string) => { const defaultUrl = `${AO_HOST}themes/default/chat_config.ini` let aomlParsed: Promise<{[key: string]: Aoml}> = request(defaultUrl).then((data) => aomlParser(data)); -- cgit From 93212647c7775358ecd7366423d706a5efae95dc Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 23 Mar 2022 22:04:45 +0100 Subject: fix strict errors in master.ts --- package.json | 1 + webAO/master.ts | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index b8e1512..2467ff6 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ }, "dependencies": { "@fingerprintjs/fingerprintjs": "^3.3.3", + "@types/websocket": "^1.0.5", "core-js": "^3.21.1", "golden-layout": "^2.5.0", "regenerator-runtime": "^0.13.9", diff --git a/webAO/master.ts b/webAO/master.ts index 8c850c2..a48f4e9 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -67,10 +67,10 @@ export function setServ(ID: number) { window.setServ = setServ; function checkOnline(serverID: number, coIP: string) { - let oserv; + let serverConnection: WebSocket; if (serverID !== -2) { try { - oserv = new WebSocket(`ws://${coIP}`); + serverConnection = new WebSocket(`ws://${coIP}`); } catch (SecurityError) { document.getElementById(`server${serverID}`).className = 'unavailable'; return; @@ -78,24 +78,24 @@ function checkOnline(serverID: number, coIP: string) { } // define what the callbacks do - function onCOOpen(_e) { + function onCOOpen() { document.getElementById(`server${serverID}`).className = 'available'; - oserv.send(`HI#${hdid}#%`); - oserv.send('ID#webAO#webAO#%'); + serverConnection.send(`HI#${hdid}#%`); + serverConnection.send('ID#webAO#webAO#%'); } - function onCOMessage(e) { + function onCOMessage(e: MessageEvent) { const comsg = e.data; const coheader = comsg.split('#', 2)[0]; const coarguments = comsg.split('#').slice(1); if (coheader === 'PN') { servers[serverID].online = `Online: ${Number(coarguments[0])}/${Number(coarguments[1])}`; - oserv.close(); + serverConnection.close(); return; } if (coheader === 'BD') { servers[serverID].online = 'Banned'; servers[serverID].description = coarguments[0]; - oserv.close(); + serverConnection.close(); return; } if (serverID === selectedServer) { @@ -104,15 +104,15 @@ function checkOnline(serverID: number, coIP: string) { } // assign the callbacks - oserv.onopen = function (evt) { - onCOOpen(evt); + serverConnection.onopen = function () { + onCOOpen(); }; - oserv.onmessage = function (evt) { + serverConnection.onmessage = function (evt: MessageEvent) { onCOMessage(evt); }; - oserv.onerror = function (_evt) { + serverConnection.onerror = function (_evt: Event) { document.getElementById(`server${serverID}`).className = 'unavailable'; }; } -- cgit