aboutsummaryrefslogtreecommitdiff
path: root/webAO
diff options
context:
space:
mode:
authorCaleb <caleb.mabry.15@cnu.edu>2022-08-30 18:32:27 -0400
committerCaleb <caleb.mabry.15@cnu.edu>2022-08-30 18:32:27 -0400
commite66a37a62b06df5b0f48d64f6b9a14b9f81bd15d (patch)
treeab39b1eb75f215e4bca85b5fabe60d4c7ebe3c8a /webAO
parentfbe2a62fd081a60860df4169f6f74425b3ff833e (diff)
A buncha more
Diffstat (limited to 'webAO')
-rw-r--r--webAO/client.ts153
-rw-r--r--webAO/packets/handlers/handleARUP.ts42
-rw-r--r--webAO/packets/handlers/handleCC.ts9
-rw-r--r--webAO/packets/handlers/handleID.ts24
-rw-r--r--webAO/packets/handlers/handlePN.ts9
-rw-r--r--webAO/packets/handlers/handleRC.ts10
-rw-r--r--webAO/packets/handlers/handleSI.ts41
-rw-r--r--webAO/packets/handlers/handleaskchaa.ts10
8 files changed, 163 insertions, 135 deletions
diff --git a/webAO/client.ts b/webAO/client.ts
index e871fce..cacfd77 100644
--- a/webAO/client.ts
+++ b/webAO/client.ts
@@ -37,6 +37,13 @@ import { handleRT } from './packets/handlers/handleRT'
import { handleTI } from './packets/handlers/handleTI'
import { handleZZ } from './packets/handlers/handleZZ'
import { handleHI } from './packets/handlers/handleHI'
+import { handleID } from './packets/handlers/handleID'
+import { handlePN } from './packets/handlers/handlePN'
+import { handleSI } from './packets/handlers/handleSI'
+import { handleARUP } from './packets/handlers/handleARUP'
+import { handleaskchaa } from './packets/handlers/handleaskchaa'
+import { handleCC } from './packets/handlers/handleCC'
+import { handleRC } from './packets/handlers/handleRC'
import chatbox_arr from "./styles/chatbox/chatboxes.js";
import iniParse from "./iniParse";
import getCookie from "./utils/getCookie";
@@ -73,7 +80,10 @@ export const UPDATE_INTERVAL = 60;
* The old loading uses more smaller packets instead of a single big one,
* which caused problems on low-memory devices in the past.
*/
-let oldLoading = false;
+export let oldLoading = false;
+export const setOldLoading = (val: boolean) => {
+ oldLoading = val
+}
// presettings
let selectedMenu = 1;
@@ -267,13 +277,13 @@ class Client extends EventEmitter {
this.on("TI", handleTI);
this.on("ZZ", handleZZ);
this.on("HI", handleHI);
- this.on("ID", this.handleID.bind(this));
- this.on("PN", this.handlePN.bind(this));
- this.on("SI", this.handleSI.bind(this));
- this.on("ARUP", this.handleARUP.bind(this));
- this.on("askchaa", this.handleaskchaa.bind(this));
- this.on("CC", this.handleCC.bind(this));
- this.on("RC", this.handleRC.bind(this));
+ this.on("ID", handleID);
+ this.on("PN", handlePN);
+ this.on("SI", handleSI);
+ this.on("ARUP", handleARUP);
+ this.on("askchaa", handleaskchaa);
+ this.on("CC", handleCC);
+ this.on("RC", handleRC);
this.on("RM", this.handleRM.bind(this));
this.on("RD", this.handleRD.bind(this));
this.on("CharsCheck", this.handleCharsCheck.bind(this));
@@ -1032,131 +1042,11 @@ class Client extends EventEmitter {
- /**
- * Identifies the server and issues a playerID
- * @param {Array} args packet arguments
- */
- handleID(args: string[]) {
- this.playerID = Number(args[1]);
- const serverSoftware = args[2].split("&")[0];
- let serverVersion;
- if (serverSoftware === "serverD") {
- serverVersion = args[2].split("&")[1];
- } else if (serverSoftware === "webAO") {
- oldLoading = false;
- this.sendSelf("PN#0#1#%");
- } else {
- serverVersion = args[3];
- }
-
- if (serverSoftware === "serverD" && serverVersion === "1377.152") {
- oldLoading = true;
- } // bugged version
- }
-
- /**
- * Indicates how many users are on this server
- * @param {Array} args packet arguments
- */
- handlePN(_args: string[]) {
- this.sendServer("askchaa#%");
- }
-
- /**
- * What? you want a character??
- * @param {Array} args packet arguments
- */
- handleCC(args: string[]) {
- this.sendSelf(`PV#1#CID#${args[2]}#%`);
- }
-
- /**
- * What? you want a character list from me??
- * @param {Array} args packet arguments
- */
- handleaskchaa(_args: string[]) {
- this.sendSelf(`SI#${vanilla_character_arr.length}#0#0#%`);
- }
-
- /**
- * Handle the change of players in an area.
- * @param {Array} args packet arguments
- */
- handleARUP(args: string[]) {
- args = args.slice(1);
- for (let i = 0; i < args.length - 2; i++) {
- if (this.areas[i]) {
- // the server sends us ARUP before we even get the area list
- const thisarea = document.getElementById(`area${i}`);
- switch (Number(args[0])) {
- case 0: // playercount
- this.areas[i].players = Number(args[i + 1]);
- break;
- case 1: // status
- this.areas[i].status = safeTags(args[i + 1]);
- break;
- case 2:
- this.areas[i].cm = safeTags(args[i + 1]);
- break;
- case 3:
- this.areas[i].locked = safeTags(args[i + 1]);
- break;
- }
-
- thisarea.className = `area-button area-${this.areas[
- i
- ].status.toLowerCase()}`;
-
- thisarea.innerText = `${this.areas[i].name} (${this.areas[i].players}) [${this.areas[i].status}]`;
-
- thisarea.title =
- `Players: ${this.areas[i].players}\n` +
- `Status: ${this.areas[i].status}\n` +
- `CM: ${this.areas[i].cm}\n` +
- `Area lock: ${this.areas[i].locked}`;
- }
- }
- }
- /**
- * Received when the server announces its server info,
- * but we use it as a cue to begin retrieving characters.
- * @param {Array} args packet arguments
- */
- handleSI(args: string[]) {
- this.char_list_length = Number(args[1]);
- this.char_list_length += 1; // some servers count starting from 0 some from 1...
- this.evidence_list_length = Number(args[2]);
- this.music_list_length = Number(args[3]);
- (<HTMLProgressElement>document.getElementById("client_loadingbar")).max =
- this.char_list_length +
- this.evidence_list_length +
- this.music_list_length;
- // create the charselect grid, to be filled by the character loader
- document.getElementById("client_chartable").innerHTML = "";
- for (let i = 0; i < this.char_list_length; i++) {
- const demothing = document.createElement("img");
-
- demothing.className = "demothing";
- demothing.id = `demo_${i}`;
- const demoonclick = document.createAttribute("onclick");
- demoonclick.value = `pickChar(${i})`;
- demothing.setAttributeNode(demoonclick);
-
- document.getElementById("client_chartable").appendChild(demothing);
- }
-
- // this is determined at the top of this file
- if (!oldLoading && extrafeatures.includes("fastloading")) {
- this.sendServer("RC#%");
- } else {
- this.sendServer("askchar2#%");
- }
- }
/**
* Handles the list of all used and vacant characters.
@@ -1290,13 +1180,6 @@ class Client extends EventEmitter {
}
}
- /**
- * we are asking ourselves what characters there are
- * @param {Array} args packet arguments
- */
- handleRC(_args: string[]) {
- this.sendSelf(`SC#${vanilla_character_arr.join("#")}#%`);
- }
/**
* we are asking ourselves what characters there are
diff --git a/webAO/packets/handlers/handleARUP.ts b/webAO/packets/handlers/handleARUP.ts
new file mode 100644
index 0000000..97db9cc
--- /dev/null
+++ b/webAO/packets/handlers/handleARUP.ts
@@ -0,0 +1,42 @@
+import { client } from "../../client";
+import { safeTags } from "../../encoding";
+
+/**
+ * Handle the change of players in an area.
+ * @param {Array} args packet arguments
+ */
+export const handleARUP = (args: string[]) => {
+ args = args.slice(1);
+ for (let i = 0; i < args.length - 2; i++) {
+ if (client.areas[i]) {
+ // the server sends us ARUP before we even get the area list
+ const thisarea = document.getElementById(`area${i}`)!;
+ switch (Number(args[0])) {
+ case 0: // playercount
+ client.areas[i].players = Number(args[i + 1]);
+ break;
+ case 1: // status
+ client.areas[i].status = safeTags(args[i + 1]);
+ break;
+ case 2:
+ client.areas[i].cm = safeTags(args[i + 1]);
+ break;
+ case 3:
+ client.areas[i].locked = safeTags(args[i + 1]);
+ break;
+ }
+
+ thisarea.className = `area-button area-${client.areas[
+ i
+ ].status.toLowerCase()}`;
+
+ thisarea.innerText = `${client.areas[i].name} (${client.areas[i].players}) [${client.areas[i].status}]`;
+
+ thisarea.title =
+ `Players: ${client.areas[i].players}\n` +
+ `Status: ${client.areas[i].status}\n` +
+ `CM: ${client.areas[i].cm}\n` +
+ `Area lock: ${client.areas[i].locked}`;
+ }
+ }
+} \ No newline at end of file
diff --git a/webAO/packets/handlers/handleCC.ts b/webAO/packets/handlers/handleCC.ts
new file mode 100644
index 0000000..84e6ec0
--- /dev/null
+++ b/webAO/packets/handlers/handleCC.ts
@@ -0,0 +1,9 @@
+import { client } from "../../client";
+
+/**
+ * What? you want a character??
+ * @param {Array} args packet arguments
+ */
+export const handleCC = (args: string[]) => {
+ client.sendSelf(`PV#1#CID#${args[2]}#%`);
+} \ No newline at end of file
diff --git a/webAO/packets/handlers/handleID.ts b/webAO/packets/handlers/handleID.ts
new file mode 100644
index 0000000..7def483
--- /dev/null
+++ b/webAO/packets/handlers/handleID.ts
@@ -0,0 +1,24 @@
+import { client, setOldLoading } from "../../client";
+
+
+/**
+ * Identifies the server and issues a playerID
+ * @param {Array} args packet arguments
+ */
+export const handleID = (args: string[]) => {
+ client.playerID = Number(args[1]);
+ const serverSoftware = args[2].split("&")[0];
+ let serverVersion;
+ if (serverSoftware === "serverD") {
+ serverVersion = args[2].split("&")[1];
+ } else if (serverSoftware === "webAO") {
+ setOldLoading(false);
+ client.sendSelf("PN#0#1#%");
+ } else {
+ serverVersion = args[3];
+ }
+
+ if (serverSoftware === "serverD" && serverVersion === "1377.152") {
+ setOldLoading(true);
+ } // bugged version
+} \ No newline at end of file
diff --git a/webAO/packets/handlers/handlePN.ts b/webAO/packets/handlers/handlePN.ts
new file mode 100644
index 0000000..b16f77d
--- /dev/null
+++ b/webAO/packets/handlers/handlePN.ts
@@ -0,0 +1,9 @@
+import { client } from "../../client";
+
+/**
+ * Indicates how many users are on this server
+ * @param {Array} args packet arguments
+ */
+export const handlePN = (_args: string[]) => {
+ client.sendServer("askchaa#%");
+} \ No newline at end of file
diff --git a/webAO/packets/handlers/handleRC.ts b/webAO/packets/handlers/handleRC.ts
new file mode 100644
index 0000000..92c1e8e
--- /dev/null
+++ b/webAO/packets/handlers/handleRC.ts
@@ -0,0 +1,10 @@
+import { client } from "../../client";
+import vanilla_character_arr from "../../constants/characters.js";
+
+/**
+ * we are asking ourselves what characters there are
+ * @param {Array} args packet arguments
+ */
+export const handleRC = (_args: string[]) => {
+ client.sendSelf(`SC#${vanilla_character_arr.join("#")}#%`);
+} \ No newline at end of file
diff --git a/webAO/packets/handlers/handleSI.ts b/webAO/packets/handlers/handleSI.ts
new file mode 100644
index 0000000..e040c83
--- /dev/null
+++ b/webAO/packets/handlers/handleSI.ts
@@ -0,0 +1,41 @@
+import { client, extrafeatures, oldLoading } from "../../client";
+
+
+/**
+ * Received when the server announces its server info,
+ * but we use it as a cue to begin retrieving characters.
+ * @param {Array} args packet arguments
+ */
+export const handleSI = (args: string[]) => {
+ client.char_list_length = Number(args[1]);
+ client.char_list_length += 1; // some servers count starting from 0 some from 1...
+ client.evidence_list_length = Number(args[2]);
+ client.music_list_length = Number(args[3]);
+
+ (<HTMLProgressElement>document.getElementById("client_loadingbar")).max =
+ client.char_list_length +
+ client.evidence_list_length +
+ client.music_list_length;
+
+ // create the charselect grid, to be filled by the character loader
+ document.getElementById("client_chartable")!.innerHTML = "";
+
+ for (let i = 0; i < client.char_list_length; i++) {
+ const demothing = document.createElement("img");
+
+ demothing.className = "demothing";
+ demothing.id = `demo_${i}`;
+ const demoonclick = document.createAttribute("onclick");
+ demoonclick.value = `pickChar(${i})`;
+ demothing.setAttributeNode(demoonclick);
+
+ document.getElementById("client_chartable")!.appendChild(demothing);
+ }
+
+ // this is determined at the top of this file
+ if (!oldLoading && extrafeatures.includes("fastloading")) {
+ client.sendServer("RC#%");
+ } else {
+ client.sendServer("askchar2#%");
+ }
+} \ No newline at end of file
diff --git a/webAO/packets/handlers/handleaskchaa.ts b/webAO/packets/handlers/handleaskchaa.ts
new file mode 100644
index 0000000..5930bf0
--- /dev/null
+++ b/webAO/packets/handlers/handleaskchaa.ts
@@ -0,0 +1,10 @@
+import { client } from "../../client";
+import vanilla_character_arr from "../../constants/characters.js";
+
+/**
+ * What? you want a character list from me??
+ * @param {Array} args packet arguments
+ */
+export const handleaskchaa = (_args: string[]) => {
+ client.sendSelf(`SI#${vanilla_character_arr.length}#0#0#%`);
+}