aboutsummaryrefslogtreecommitdiff
path: root/webAO
diff options
context:
space:
mode:
Diffstat (limited to 'webAO')
-rw-r--r--webAO/client.ts189
-rw-r--r--webAO/packets/handlers/handleMS.ts162
-rw-r--r--webAO/utils/queryParser.ts22
3 files changed, 192 insertions, 181 deletions
diff --git a/webAO/client.ts b/webAO/client.ts
index 2f84277..c0ea5a0 100644
--- a/webAO/client.ts
+++ b/webAO/client.ts
@@ -8,7 +8,6 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs";
import { EventEmitter } from "events";
import tryUrls from "./utils/tryUrls";
import { escapeChat, prepChat, safeTags, unescapeChat } from "./encoding";
-import mlConfig from "./utils/aoml";
// Load some defaults for the background and evidence dropdowns
import vanilla_character_arr from "./constants/characters.js";
import vanilla_music_arr from "./constants/music.js";
@@ -25,38 +24,23 @@ import {
changeSFXVolume,
changeTestimonyVolume,
} from "./dom/changeVolume.js";
-import setEmote from "./client/setEmote.js";
import fileExists from "./utils/fileExists.js";
import queryParser from "./utils/queryParser.js";
-import getAnimLength from "./utils/getAnimLength.js";
import getResources from "./utils/getResources.js";
import transparentPng from "./constants/transparentPng";
import downloadFile from "./services/downloadFile";
import { getFilenameFromPath } from "./utils/paths";
const version = process.env.npm_package_version;
import masterViewport, { Viewport } from "./viewport";
+import { handleMS } from './packets/handlers/handleMS';
-interface Testimony {
- [key: number]: string;
-}
-
-// Get the arguments from the URL bar
-interface QueryParams {
- ip: string;
- serverIP: string;
- mode: string;
- asset: string;
- theme: string;
-}
-let { ip: serverIP, mode, asset, theme } = queryParser() as QueryParams;
+let { ip: serverIP, mode, asset, theme } = queryParser() ;
// Unless there is an asset URL specified, use the wasabi one
const DEFAULT_HOST = "http://attorneyoffline.de/base/";
export let AO_HOST = asset || DEFAULT_HOST;
const THEME = theme || "default";
-let client: Client;
-
-const attorneyMarkdown = mlConfig(AO_HOST);
+export let client: Client;
export const UPDATE_INTERVAL = 60;
@@ -71,7 +55,7 @@ let oldLoading = false;
let selectedMenu = 1;
let selectedShout = 0;
-let extrafeatures: string[] = [];
+export let extrafeatures: string[] = [];
let banned: boolean = false;
let hdid: string;
@@ -220,14 +204,14 @@ class Client extends EventEmitter {
this.selectedEmote = -1;
this.selectedEvidence = 0;
-
+
this.checkUpdater = null;
this.viewport = masterViewport(this);
/**
* Assign handlers for all commands
* If you implement a new command, you need to add it here
*/
- this.on("MS", this.handleMS.bind(this));
+ this.on("MS", handleMS);
this.on("CT", this.handleCT.bind(this));
this.on("MC", this.handleMC.bind(this));
this.on("RMC", this.handleRMC.bind(this));
@@ -754,165 +738,7 @@ class Client extends EventEmitter {
(<HTMLInputElement>document.getElementById("client_inputbox")).value = "";
};
- /**
- * Handles an in-character chat message.
- * @param {*} args packet arguments
- */
- handleMS(args: string[]) {
- // TODO: this if-statement might be a bug.
- if (args[4] !== this.viewport.chatmsg.content) {
- document.getElementById("client_inner_chat").innerHTML = "";
-
- const char_id = Number(args[9]);
- const char_name = safeTags(args[3]);
-
- let msg_nameplate = args[3];
- let msg_blips = "male";
- let char_chatbox = "default";
- let char_muted = false;
-
- if (char_id < this.char_list_length && char_id >= 0) {
- if(this.chars[char_id].name !== char_name) {
- console.info(
- `${this.chars[char_id].name} is iniediting to ${char_name}`
- );
- const chargs = (`${char_name}&` + "iniediter").split("&");
- this.handleCharacterInfo(chargs, char_id);
- }
- }
-
- try {
- msg_nameplate = this.chars[char_id].showname;
- } catch (e) {
- msg_nameplate = args[3];
- }
-
- try {
- msg_blips = this.chars[char_id].blips;
- } catch (e) {}
-
- try {
- char_chatbox = this.chars[char_id].chat;
- } catch (e) {
- char_chatbox = "default";
- }
-
- try {
- char_muted = this.chars[char_id].muted;
- } catch (e) {
- char_muted = false;
- console.error("we're still missing some character data");
- }
-
- if (char_muted === false) {
- let chatmsg = {
- deskmod: safeTags(args[1]).toLowerCase(),
- preanim: safeTags(args[2]).toLowerCase(), // get preanim
- nameplate: msg_nameplate,
- chatbox: char_chatbox,
- name: char_name,
- sprite: safeTags(args[4]).toLowerCase(),
- content: prepChat(args[5]), // Escape HTML tags
- side: args[6].toLowerCase(),
- sound: safeTags(args[7]).toLowerCase(),
- blips: safeTags(msg_blips),
- type: Number(args[8]),
- charid: char_id,
- snddelay: Number(args[10]),
- objection: Number(args[11]),
- evidence: safeTags(args[12]),
- flip: Number(args[13]),
- flash: Number(args[14]),
- color: Number(args[15]),
- speed: UPDATE_INTERVAL,
- };
-
- if (extrafeatures.includes("cccc_ic_support")) {
- const extra_cccc = {
- showname: safeTags(args[16]),
- other_charid: Number(args[17]),
- other_name: safeTags(args[18]),
- other_emote: safeTags(args[19]),
- self_offset: args[20].split("<and>"), // HACK: here as well, client is fucked and uses this instead of &
- other_offset: args[21].split("<and>"),
- other_flip: Number(args[22]),
- noninterrupting_preanim: Number(args[23]),
- };
- chatmsg = Object.assign(extra_cccc, chatmsg);
-
- if (extrafeatures.includes("looping_sfx")) {
- const extra_27 = {
- looping_sfx: Number(args[24]),
- screenshake: Number(args[25]),
- frame_screenshake: safeTags(args[26]),
- frame_realization: safeTags(args[27]),
- frame_sfx: safeTags(args[28]),
- };
- chatmsg = Object.assign(extra_27, chatmsg);
-
- if (extrafeatures.includes("effects")) {
- const extra_28 = {
- additive: Number(args[29]),
- effects: args[30].split("|"),
- };
- chatmsg = Object.assign(extra_28, chatmsg);
- } else {
- const extra_28 = {
- additive: 0,
- effects: ["", "", ""],
- };
- chatmsg = Object.assign(extra_28, chatmsg);
- }
- } else {
- const extra_27 = {
- looping_sfx: 0,
- screenshake: 0,
- frame_screenshake: "",
- frame_realization: "",
- frame_sfx: "",
- };
- chatmsg = Object.assign(extra_27, chatmsg);
- const extra_28 = {
- additive: 0,
- effects: ["", "", ""],
- };
- chatmsg = Object.assign(extra_28, chatmsg);
- }
- } else {
- const extra_cccc = {
- showname: "",
- other_charid: 0,
- other_name: "",
- other_emote: "",
- self_offset: [0, 0],
- other_offset: [0, 0],
- other_flip: 0,
- noninterrupting_preanim: 0,
- };
- chatmsg = Object.assign(extra_cccc, chatmsg);
- const extra_27 = {
- looping_sfx: 0,
- screenshake: 0,
- frame_screenshake: "",
- frame_realization: "",
- frame_sfx: "",
- };
- chatmsg = Object.assign(extra_27, chatmsg);
- const extra_28 = {
- additive: 0,
- effects: ["", "", ""],
- };
- chatmsg = Object.assign(extra_28, chatmsg);
- }
- // our own message appeared, reset the buttons
- if (chatmsg.charid === this.charID) {
- resetICParams();
- }
- this.viewport.handle_ic_speaking(chatmsg); // no await
- }
- }
- }
/**
* Handles an out-of-character chat message.
@@ -2176,7 +2002,7 @@ window.onEnter = onEnter;
* This should only be called when the player's previous chat message
* was successfully sent/presented.
*/
-function resetICParams() {
+export function resetICParams() {
(<HTMLInputElement>document.getElementById("client_inputbox")).value = "";
document.getElementById("button_flash").className = "client_button";
document.getElementById("button_shake").className = "client_button";
@@ -3010,4 +2836,5 @@ export function toggleShout(shout: number) {
}
}
window.toggleShout = toggleShout;
+
export default Client;
diff --git a/webAO/packets/handlers/handleMS.ts b/webAO/packets/handlers/handleMS.ts
new file mode 100644
index 0000000..0aad19a
--- /dev/null
+++ b/webAO/packets/handlers/handleMS.ts
@@ -0,0 +1,162 @@
+import { client, extrafeatures, resetICParams, UPDATE_INTERVAL } from "../../client";
+import { prepChat, safeTags } from "../../encoding";
+
+/**
+ * Handles an in-character chat message.
+ * @param {*} args packet arguments
+ */
+export const handleMS = (args: string[]) => {
+ // TODO: this if-statement might be a bug.
+ if (args[4] !== client.viewport.chatmsg.content) {
+ document.getElementById("client_inner_chat")!.innerHTML = "";
+
+ const char_id = Number(args[9]);
+ const char_name = safeTags(args[3]);
+
+ let msg_nameplate = args[3];
+ let msg_blips = "male";
+ let char_chatbox = "default";
+ let char_muted = false;
+
+ if (char_id < client.char_list_length && char_id >= 0) {
+ if(client.chars[char_id].name !== char_name) {
+ console.info(
+ `${client.chars[char_id].name} is iniediting to ${char_name}`
+ );
+ const chargs = (`${char_name}&` + "iniediter").split("&");
+ client.handleCharacterInfo(chargs, char_id);
+ }
+ }
+
+ try {
+ msg_nameplate = client.chars[char_id].showname;
+ } catch (e) {
+ msg_nameplate = args[3];
+ }
+
+ try {
+ msg_blips = client.chars[char_id].blips;
+ } catch (e) {}
+
+ try {
+ char_chatbox = client.chars[char_id].chat;
+ } catch (e) {
+ char_chatbox = "default";
+ }
+
+ try {
+ char_muted = client.chars[char_id].muted;
+ } catch (e) {
+ char_muted = false;
+ console.error("we're still missing some character data");
+ }
+
+ if (char_muted === false) {
+ let chatmsg = {
+ deskmod: safeTags(args[1]).toLowerCase(),
+ preanim: safeTags(args[2]).toLowerCase(), // get preanim
+ nameplate: msg_nameplate,
+ chatbox: char_chatbox,
+ name: char_name,
+ sprite: safeTags(args[4]).toLowerCase(),
+ content: prepChat(args[5]), // Escape HTML tags
+ side: args[6].toLowerCase(),
+ sound: safeTags(args[7]).toLowerCase(),
+ blips: safeTags(msg_blips),
+ type: Number(args[8]),
+ charid: char_id,
+ snddelay: Number(args[10]),
+ objection: Number(args[11]),
+ evidence: safeTags(args[12]),
+ flip: Number(args[13]),
+ flash: Number(args[14]),
+ color: Number(args[15]),
+ speed: UPDATE_INTERVAL,
+ };
+
+ if (extrafeatures.includes("cccc_ic_support")) {
+ const extra_cccc = {
+ showname: safeTags(args[16]),
+ other_charid: Number(args[17]),
+ other_name: safeTags(args[18]),
+ other_emote: safeTags(args[19]),
+ self_offset: args[20].split("<and>"), // HACK: here as well, client is fucked and uses this instead of &
+ other_offset: args[21].split("<and>"),
+ other_flip: Number(args[22]),
+ noninterrupting_preanim: Number(args[23]),
+ };
+ chatmsg = Object.assign(extra_cccc, chatmsg);
+
+ if (extrafeatures.includes("looping_sfx")) {
+ const extra_27 = {
+ looping_sfx: Number(args[24]),
+ screenshake: Number(args[25]),
+ frame_screenshake: safeTags(args[26]),
+ frame_realization: safeTags(args[27]),
+ frame_sfx: safeTags(args[28]),
+ };
+ chatmsg = Object.assign(extra_27, chatmsg);
+
+ if (extrafeatures.includes("effects")) {
+ const extra_28 = {
+ additive: Number(args[29]),
+ effects: args[30].split("|"),
+ };
+ chatmsg = Object.assign(extra_28, chatmsg);
+ } else {
+ const extra_28 = {
+ additive: 0,
+ effects: ["", "", ""],
+ };
+ chatmsg = Object.assign(extra_28, chatmsg);
+ }
+ } else {
+ const extra_27 = {
+ looping_sfx: 0,
+ screenshake: 0,
+ frame_screenshake: "",
+ frame_realization: "",
+ frame_sfx: "",
+ };
+ chatmsg = Object.assign(extra_27, chatmsg);
+ const extra_28 = {
+ additive: 0,
+ effects: ["", "", ""],
+ };
+ chatmsg = Object.assign(extra_28, chatmsg);
+ }
+ } else {
+ const extra_cccc = {
+ showname: "",
+ other_charid: 0,
+ other_name: "",
+ other_emote: "",
+ self_offset: [0, 0],
+ other_offset: [0, 0],
+ other_flip: 0,
+ noninterrupting_preanim: 0,
+ };
+ chatmsg = Object.assign(extra_cccc, chatmsg);
+ const extra_27 = {
+ looping_sfx: 0,
+ screenshake: 0,
+ frame_screenshake: "",
+ frame_realization: "",
+ frame_sfx: "",
+ };
+ chatmsg = Object.assign(extra_27, chatmsg);
+ const extra_28 = {
+ additive: 0,
+ effects: ["", "", ""],
+ };
+ chatmsg = Object.assign(extra_28, chatmsg);
+ }
+
+ // our own message appeared, reset the buttons
+ if (chatmsg.charid === client.charID) {
+ resetICParams();
+ }
+ client.viewport.handle_ic_speaking(chatmsg); // no await
+ }
+ }
+ } \ No newline at end of file
diff --git a/webAO/utils/queryParser.ts b/webAO/utils/queryParser.ts
new file mode 100644
index 0000000..3110c14
--- /dev/null
+++ b/webAO/utils/queryParser.ts
@@ -0,0 +1,22 @@
+interface QueryParams {
+ ip: string;
+ serverIP: string;
+ mode: string;
+ asset: string;
+ theme: string;
+}
+interface StringMap {
+ [key: string]: any;
+}
+
+const queryParser = (): QueryParams => {
+ const queryDict: StringMap = {};
+ location.search
+ .substr(1)
+ .split("&")
+ .forEach((item) => {
+ queryDict[item.split("=")[0]] = item.split("=")[1];
+ });
+ return queryDict as QueryParams;
+};
+export default queryParser;