aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-03-23 22:25:15 +0100
committerGitHub <noreply@github.com>2022-03-23 22:25:15 +0100
commitffa23343e0a0badd9e50a005359fdb79efead995 (patch)
treeb5991b499685bd94890fae7f321570044fafaf2c
parent30b4e3e8c84ce3f980fe895d4c64800fc7f00ece (diff)
parent93212647c7775358ecd7366423d706a5efae95dc (diff)
Merge pull request #128 from AttorneyOnline/sypetcript
Sypetcript
-rw-r--r--package.json1
-rw-r--r--public/client.html27
-rw-r--r--tsconfig.json2
-rw-r--r--webAO/client.js6
-rw-r--r--webAO/encoding.ts (renamed from webAO/encoding.js)33
-rw-r--r--webAO/master.ts26
-rw-r--r--webAO/utils/aoml.ts2
7 files changed, 26 insertions, 71 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/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()"></textarea>
<br>
<br>
- <span style="color:red">&#8595; Only touch these settings if you know what you are doing. &#8595;</span>
- <br>
- <br>
- <label for="client_encoding">Client side chat encoding:</label>
- <select id="client_encoding" name="client_encoding">
- <option value="none" selected>None</option>
- <option value="unicode">Unicode</option>
- <option value="utf16">UTF-16</option>
- </select>
- <br>
- <br>
- <label for="client_decoding">Client side chat decoding:</label>
- <select id="client_decoding" name="client_decoding">
- <option value="none">None</option>
- <option value="unicode" selected>Unicode</option>
- <option value="utf16">UTF-16</option>
- </select>
- <br>
- <br>
- <label for="bg_command">Change background command:</label>
- <input id="bg_command" name="bg_command" type="text" value="bg $1">
- <br>
- <br>
- <label for="randomchar_command">Random character command:</label>
- <input id="randomchar_command" name="randomchar_command" type="text" value="randomchar">
- <br>
- <br>
<span style="color:blue">Changing these settings will save them as a cookie.<br>
By doing so, you agree to it being saved.<br>
If you don't agree, disable cookies for this site in your browser.</span>
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/*"]
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;
diff --git a/webAO/encoding.js b/webAO/encoding.ts
index e6cc3ae..1018144 100644
--- a/webAO/encoding.js
+++ 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) {
+export function escapeChat(estring: string): string {
return estring
.replace(/#/g, '<num>')
.replace(/&/g, '<and>')
@@ -14,7 +14,7 @@ export function escapeChat(estring) {
* Unescapes a string to AO1 escape codes.
* @param {string} estring the string to be unescaped
*/
-export function unescapeChat(estring) {
+export function unescapeChat(estring: string): string {
return estring
.replace(/<num>/g, '#')
.replace(/<and>/g, '&')
@@ -28,7 +28,7 @@ export function unescapeChat(estring) {
* XXX: This is unnecessary if we use `createTextNode` instead!
* @param {string} unsafe an unsanitized string
*/
-export function safeTags(unsafe) {
+export function safeTags(unsafe: string): string {
if (unsafe) {
return unsafe
.replace(/>/g, '&gt;')
@@ -41,21 +41,7 @@ export function safeTags(unsafe) {
* Encode text on client side.
* @param {string} estring the string to be encoded
*/
-export function encodeChat(estring) {
- const selectedEncoding = document.getElementById('client_encoding').value;
- if (selectedEncoding === 'unicode') {
- // This approach works by escaping all special characters to Unicode escape sequences.
- // Source: https://gist.github.com/mathiasbynens/1243213
- return estring.replace(/[^\0-~]/g, (ch) => `\\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);
- }
+export function encodeChat(estring: string): string {
return estring;
}
@@ -63,23 +49,16 @@ export function encodeChat(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') {
+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)));
- } 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) {
+export function prepChat(msg: string): string {
// TODO: make this less awful
return unescapeChat(decodeChat(msg));
}
diff --git a/webAO/master.ts b/webAO/master.ts
index 8fd8779..a48f4e9 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 {
@@ -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';
};
}
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));