diff options
| author | Caleb <caleb.mabry.15@cnu.edu> | 2022-09-01 22:36:22 -0400 |
|---|---|---|
| committer | Caleb <caleb.mabry.15@cnu.edu> | 2022-09-01 22:36:22 -0400 |
| commit | 86b493b881bde4a11214929ebe4317289a7f1da3 (patch) | |
| tree | 9d1b03e1d67278a42796de8e2f4d6e4a3df5d78c | |
| parent | cac2c72288572fe2e635b4e8f49b52fac5c8dd90 (diff) | |
Moved rest of the handlers
| -rw-r--r-- | webAO/client.ts | 207 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleASS.ts | 10 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleCharsCheck.ts | 17 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleJD.ts | 13 | ||||
| -rw-r--r-- | webAO/packets/handlers/handlePV.ts | 82 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleRD.ts | 18 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleRM.ts | 10 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleSP.ts | 9 | ||||
| -rw-r--r-- | webAO/packets/handlers/handleackMS.ts | 8 |
9 files changed, 187 insertions, 187 deletions
diff --git a/webAO/client.ts b/webAO/client.ts index cacfd77..f216bce 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -44,6 +44,14 @@ 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 { handleRM } from './packets/handlers/handleRM' +import { handleRD } from './packets/handlers/handleRD' +import { handleCharsCheck } from './packets/handlers/handleCharsCheck' +import { handlePV } from './packets/handlers/handlePV' +import { handleASS } from './packets/handlers/handleASS' +import { handleackMS } from './packets/handlers/handleackMS' +import { handleSP } from './packets/handlers/handleSP' +import { handleJD } from './packets/handlers/handleJD' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -68,6 +76,9 @@ 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; +export const setAOhost = (val: string) => { + AO_HOST = val +} let THEME: string = theme || "default"; let CHATBOX: string; @@ -284,14 +295,14 @@ class Client extends EventEmitter { 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)); - this.on("PV", this.handlePV.bind(this)); - this.on("ASS", this.handleASS.bind(this)); - this.on("ackMS", this.handleackMS.bind(this)); - this.on("SP", this.handleSP.bind(this)); - this.on("JD", this.handleJD.bind(this)); + this.on("RM", handleRM); + this.on("RD", handleRD); + this.on("CharsCheck", handleCharsCheck); + this.on("PV", handlePV); + this.on("ASS", handleASS); + this.on("ackMS", handleackMS); + this.on("SP", handleSP); + this.on("JD", handleJD); this.on("decryptor", () => { }); this.on("CHECK", () => { }); this.on("CH", () => { }); @@ -778,14 +789,6 @@ class Client extends EventEmitter { (<HTMLInputElement>document.getElementById("client_inputbox")).value = ""; }; - - - - - - - - /** * Handles the incoming character information, and downloads the sprite + ini for it * @param {Array} chargs packet arguments @@ -1017,11 +1020,6 @@ class Client extends EventEmitter { } } - - - - - /** * Handles the kicked packet * @param {string} type is it a kick or a ban @@ -1039,171 +1037,6 @@ class Client extends EventEmitter { document.getElementsByClassName("client_reconnect")[1] )).style.display = "none"; } - - - - - - - - - - /** - * Handles the list of all used and vacant characters. - * @param {Array} args list of all characters represented as a 0 for free or a -1 for taken - */ - handleCharsCheck(args: string[]) { - for (let i = 0; i < this.char_list_length; i++) { - const img = document.getElementById(`demo_${i}`); - - if (args[i + 1] === "-1") { - img.style.opacity = "0.25"; - } else if (args[i + 1] === "0") { - img.style.opacity = "1"; - } - } - } - - /** - * Handles the server's assignment of a character for the player to use. - * PV # playerID (unused) # CID # character ID - * @param {Array} args packet arguments - */ - async handlePV(args: string[]) { - this.charID = Number(args[3]); - document.getElementById("client_waiting").style.display = "none"; - document.getElementById("client_charselect").style.display = "none"; - - const me = this.chars[this.charID]; - this.selectedEmote = -1; - const { emotes } = this; - const emotesList = document.getElementById("client_emo"); - emotesList.style.display = ""; - emotesList.innerHTML = ""; // Clear emote box - const ini = me.inifile; - me.side = ini.options.side; - updateActionCommands(me.side); - if (ini.emotions.number === 0) { - emotesList.innerHTML = `<span - id="emo_0" - alt="unavailable" - class="emote_button">No emotes available</span>`; - } else { - for (let i = 1; i <= ini.emotions.number; i++) { - try { - const emoteinfo = ini.emotions[i].split("#"); - let esfx; - let esfxd; - try { - esfx = ini.soundn[i] || "0"; - esfxd = Number(ini.soundt[i]) || 0; - } catch (e) { - console.warn("ini sound is completly missing"); - esfx = "0"; - esfxd = 0; - } - // Make sure the asset server is case insensitive, or that everything on it is lowercase - - emotes[i] = { - desc: emoteinfo[0].toLowerCase(), - preanim: emoteinfo[1].toLowerCase(), - emote: emoteinfo[2].toLowerCase(), - zoom: Number(emoteinfo[3]) || 0, - deskmod: Number(emoteinfo[4]) || 1, - sfx: esfx.toLowerCase(), - sfxdelay: esfxd, - frame_screenshake: "", - frame_realization: "", - frame_sfx: "", - button: `${AO_HOST}characters/${encodeURI( - me.name.toLowerCase() - )}/emotions/button${i}_off.png`, - }; - emotesList.innerHTML += `<img src=${emotes[i].button} - id="emo_${i}" - alt="${emotes[i].desc}" - class="emote_button" - onclick="pickEmotion(${i})">`; - } catch (e) { - console.error(`missing emote ${i}`); - } - } - pickEmotion(1); - } - - if ( - await fileExists( - `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/custom.gif` - ) - ) { - document.getElementById("button_4").style.display = ""; - } else { - document.getElementById("button_4").style.display = "none"; - } - - } - - /** - * new asset url!! - * @param {Array} args packet arguments - */ - handleASS(args: string[]) { - AO_HOST = args[1]; - } - - /** - * server got our message - */ - handleackMS() { - resetICParams(); - } - - /** -* position change -* @param {string} pos new position -*/ - handleSP(args: string[]) { - updateActionCommands(args[1]); - } - - /** -* show/hide judge controls -* @param {number} show either a 1 or a 0 -*/ - handleJD(args: string[]) { - if (Number(args[1]) === 1) { - document.getElementById("judge_action").style.display = "inline-table"; - document.getElementById("no_action").style.display = "none"; - } else { - document.getElementById("judge_action").style.display = "none"; - document.getElementById("no_action").style.display = "inline-table"; - } - } - - - /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ - handleRM(_args: string[]) { - this.sendSelf(`SM#${vanilla_music_arr.join("#")}#%`); - } - - /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ - handleRD(_args: string[]) { - this.sendSelf("BN#gs4#%"); - this.sendSelf("DONE#%"); - const ooclog = <HTMLInputElement>document.getElementById("client_ooclog"); - ooclog.value = ""; - ooclog.readOnly = false; - - document.getElementById("client_oocinput").style.display = "none"; - document.getElementById("client_replaycontrols").style.display = - "inline-block"; - } } /** @@ -1487,7 +1320,7 @@ export async function iniedit() { .value; const inicharID = client.charID; await client.handleCharacterInfo(ininame.split("&"), inicharID); - client.handlePV(`PV#0#CID#${inicharID}`.split("#")); + handlePV(`PV#0#CID#${inicharID}`.split("#")); } window.iniedit = iniedit; diff --git a/webAO/packets/handlers/handleASS.ts b/webAO/packets/handlers/handleASS.ts new file mode 100644 index 0000000..d0dfbd5 --- /dev/null +++ b/webAO/packets/handlers/handleASS.ts @@ -0,0 +1,10 @@ +import { setAOhost } from "../../client"; + + +/** +* new asset url!! +* @param {Array} args packet arguments +*/ +export const handleASS = (args: string[]) => { + setAOhost(args[1]); +} diff --git a/webAO/packets/handlers/handleCharsCheck.ts b/webAO/packets/handlers/handleCharsCheck.ts new file mode 100644 index 0000000..2d891ef --- /dev/null +++ b/webAO/packets/handlers/handleCharsCheck.ts @@ -0,0 +1,17 @@ +import { client } from "../../client"; + +/** + * Handles the list of all used and vacant characters. + * @param {Array} args list of all characters represented as a 0 for free or a -1 for taken + */ +export const handleCharsCheck = (args: string[]) => { + for (let i = 0; i < client.char_list_length; i++) { + const img = document.getElementById(`demo_${i}`)!; + + if (args[i + 1] === "-1") { + img.style.opacity = "0.25"; + } else if (args[i + 1] === "0") { + img.style.opacity = "1"; + } + } +}
\ No newline at end of file diff --git a/webAO/packets/handlers/handleJD.ts b/webAO/packets/handlers/handleJD.ts new file mode 100644 index 0000000..98d7988 --- /dev/null +++ b/webAO/packets/handlers/handleJD.ts @@ -0,0 +1,13 @@ +/** +* show/hide judge controls +* @param {number} show either a 1 or a 0 +*/ +export const handleJD = (args: string[]) => { + if (Number(args[1]) === 1) { + document.getElementById("judge_action")!.style.display = "inline-table"; + document.getElementById("no_action")!.style.display = "none"; + } else { + document.getElementById("judge_action")!.style.display = "none"; + document.getElementById("no_action")!.style.display = "inline-table"; + } +}
\ No newline at end of file diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts new file mode 100644 index 0000000..18947c5 --- /dev/null +++ b/webAO/packets/handlers/handlePV.ts @@ -0,0 +1,82 @@ +import { AO_HOST, client, pickEmotion, updateActionCommands } from "../../client"; +import fileExists from "../../utils/fileExists"; + + + /** + * Handles the server's assignment of a character for the player to use. + * PV # playerID (unused) # CID # character ID + * @param {Array} args packet arguments + */ +export const handlePV = async (args: string[]) => { + client.charID = Number(args[3]); + document.getElementById("client_waiting")!.style.display = "none"; + document.getElementById("client_charselect")!.style.display = "none"; + + const me = client.chars[client.charID]; + client.selectedEmote = -1; + const { emotes } = client; + const emotesList = document.getElementById("client_emo")!; + emotesList.style.display = ""; + emotesList.innerHTML = ""; // Clear emote box + const ini = me.inifile; + me.side = ini.options.side; + updateActionCommands(me.side); + if (ini.emotions.number === 0) { + emotesList.innerHTML = `<span + id="emo_0" + alt="unavailable" + class="emote_button">No emotes available</span>`; + } else { + for (let i = 1; i <= ini.emotions.number; i++) { + try { + const emoteinfo = ini.emotions[i].split("#"); + let esfx; + let esfxd; + try { + esfx = ini.soundn[i] || "0"; + esfxd = Number(ini.soundt[i]) || 0; + } catch (e) { + console.warn("ini sound is completly missing"); + esfx = "0"; + esfxd = 0; + } + // Make sure the asset server is case insensitive, or that everything on it is lowercase + + emotes[i] = { + desc: emoteinfo[0].toLowerCase(), + preanim: emoteinfo[1].toLowerCase(), + emote: emoteinfo[2].toLowerCase(), + zoom: Number(emoteinfo[3]) || 0, + deskmod: Number(emoteinfo[4]) || 1, + sfx: esfx.toLowerCase(), + sfxdelay: esfxd, + frame_screenshake: "", + frame_realization: "", + frame_sfx: "", + button: `${AO_HOST}characters/${encodeURI( + me.name.toLowerCase() + )}/emotions/button${i}_off.png`, + }; + emotesList.innerHTML += `<img src=${emotes[i].button} + id="emo_${i}" + alt="${emotes[i].desc}" + class="emote_button" + onclick="pickEmotion(${i})">`; + } catch (e) { + console.error(`missing emote ${i}`); + } + } + pickEmotion(1); + } + + if ( + await fileExists( + `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/custom.gif` + ) + ) { + document.getElementById("button_4")!.style.display = ""; + } else { + document.getElementById("button_4")!.style.display = "none"; + } + + } diff --git a/webAO/packets/handlers/handleRD.ts b/webAO/packets/handlers/handleRD.ts new file mode 100644 index 0000000..780b43f --- /dev/null +++ b/webAO/packets/handlers/handleRD.ts @@ -0,0 +1,18 @@ +import { client } from "../../client"; + + +/** + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ +export const handleRD = (_args: string[]) => { + client.sendSelf("BN#gs4#%"); + client.sendSelf("DONE#%"); + const ooclog = <HTMLInputElement>document.getElementById("client_ooclog"); + ooclog.value = ""; + ooclog.readOnly = false; + + document.getElementById("client_oocinput")!.style.display = "none"; + document.getElementById("client_replaycontrols")!.style.display = + "inline-block"; +}
\ No newline at end of file diff --git a/webAO/packets/handlers/handleRM.ts b/webAO/packets/handlers/handleRM.ts new file mode 100644 index 0000000..41a78b4 --- /dev/null +++ b/webAO/packets/handlers/handleRM.ts @@ -0,0 +1,10 @@ +import {client} from '../../client' +import vanilla_music_arr from "../../constants/music.js"; + + /** + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ +export const handleRM = (_args: string[]) => { + client.sendSelf(`SM#${vanilla_music_arr.join("#")}#%`); + }
\ No newline at end of file diff --git a/webAO/packets/handlers/handleSP.ts b/webAO/packets/handlers/handleSP.ts new file mode 100644 index 0000000..e2cad18 --- /dev/null +++ b/webAO/packets/handlers/handleSP.ts @@ -0,0 +1,9 @@ +import { updateActionCommands } from "../../client"; + +/** +* position change +* @param {string} pos new position +*/ +export const handleSP = (args: string[]) => { + updateActionCommands(args[1]); +}
\ No newline at end of file diff --git a/webAO/packets/handlers/handleackMS.ts b/webAO/packets/handlers/handleackMS.ts new file mode 100644 index 0000000..2b971b0 --- /dev/null +++ b/webAO/packets/handlers/handleackMS.ts @@ -0,0 +1,8 @@ +import { resetICParams } from "../../client"; + +/** +* server got our message +*/ +export const handleackMS = () => { + resetICParams(); +}
\ No newline at end of file |
