From 9bec7d0fba8c80284e260469ed3045e9dfdb5d79 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 25 Aug 2022 21:34:08 -0400 Subject: Remove handleMS and separate queryParser --- webAO/packets/handlers/handleMS.ts | 163 +++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 webAO/packets/handlers/handleMS.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleMS.ts b/webAO/packets/handlers/handleMS.ts new file mode 100644 index 0000000..f3554ca --- /dev/null +++ b/webAO/packets/handlers/handleMS.ts @@ -0,0 +1,163 @@ +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[]) => { + console.log(args) + // 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(""), // HACK: here as well, client is fucked and uses this instead of & + other_offset: args[21].split(""), + 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 -- cgit From a96a2b8c914e55f12d49b1287b445f89d32926ea Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 25 Aug 2022 21:34:47 -0400 Subject: Removing unused imports --- webAO/packets/handlers/handleMS.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleMS.ts b/webAO/packets/handlers/handleMS.ts index f3554ca..0aad19a 100644 --- a/webAO/packets/handlers/handleMS.ts +++ b/webAO/packets/handlers/handleMS.ts @@ -6,7 +6,6 @@ import { prepChat, safeTags } from "../../encoding"; * @param {*} args packet arguments */ export const handleMS = (args: string[]) => { - console.log(args) // TODO: this if-statement might be a bug. if (args[4] !== client.viewport.chatmsg.content) { document.getElementById("client_inner_chat")!.innerHTML = ""; -- cgit From be5bd2e466951a3b525a97d595e577f3194913db Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 16:14:31 -0400 Subject: Format and move two packets --- webAO/packets/handlers/handleCT.ts | 17 ++++++++++++++++ webAO/packets/handlers/handleMC.ts | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 webAO/packets/handlers/handleCT.ts create mode 100644 webAO/packets/handlers/handleMC.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleCT.ts b/webAO/packets/handlers/handleCT.ts new file mode 100644 index 0000000..cff9b24 --- /dev/null +++ b/webAO/packets/handlers/handleCT.ts @@ -0,0 +1,17 @@ +import queryParser from '../../utils/queryParser' +import { prepChat } from '../../encoding' +let { mode } = queryParser(); + +/** + * Handles an out-of-character chat message. + * @param {Array} args packet arguments + */ +export const handleCT = (args: string[]) => { + if (mode !== "replay") { + const oocLog = document.getElementById("client_ooclog")!; + oocLog.innerHTML += `${prepChat(args[1])}: ${prepChat(args[2])}\r\n`; + if (oocLog.scrollTop > oocLog.scrollHeight - 600) { + oocLog.scrollTop = oocLog.scrollHeight; + } + } +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleMC.ts b/webAO/packets/handlers/handleMC.ts new file mode 100644 index 0000000..28254ba --- /dev/null +++ b/webAO/packets/handlers/handleMC.ts @@ -0,0 +1,41 @@ +import { prepChat } from "../../encoding"; +import { AO_HOST, appendICLog, client } from '../../client' + +/** + * Handles a music change to an arbitrary resource. + * @param {Array} args packet arguments + */ +export const handleMC = (args: string[]) => { + const track = prepChat(args[1]); + let charID = Number(args[2]); + const showname = args[3] || ""; + const looping = Boolean(args[4]); + const channel = Number(args[5]) || 0; + // const fading = Number(args[6]) || 0; // unused in web + + const music = client.viewport.music[channel]; + let musicname; + music.pause(); + if (track.startsWith("http")) { + music.src = track; + } else { + music.src = `${AO_HOST}sounds/music/${encodeURI(track.toLowerCase())}`; + } + music.loop = looping; + music.play(); + + try { + musicname = client.chars[charID].name; + } catch (e) { + charID = -1; + } + + if (charID >= 0) { + musicname = client.chars[charID].name; + appendICLog(`${musicname} changed music to ${track}`); + } else { + appendICLog(`The music was changed to ${track}`); + } + + document.getElementById("client_trackstatustext")!.innerText = track; +} \ No newline at end of file -- cgit From 3d6e61c6b0962cea539c6d780d68a7ad0b64bee1 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 16:20:08 -0400 Subject: One more handler --- webAO/packets/handlers/handleRMC.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 webAO/packets/handlers/handleRMC.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleRMC.ts b/webAO/packets/handlers/handleRMC.ts new file mode 100644 index 0000000..ada1ad2 --- /dev/null +++ b/webAO/packets/handlers/handleRMC.ts @@ -0,0 +1,24 @@ +import { client } from '../../client' +// TODO BUG: +// this.viewport.music is an array. Therefore you must access elements +/** + * Handles a music change to an arbitrary resource, with an offset in seconds. + * @param {Array} args packet arguments + */ +export const handleRMC = (args: string[]) => { + client.viewport.music.pause(); + const { music } = client.viewport; + // Music offset + drift from song loading + music.totime = args[1]; + music.offset = new Date().getTime() / 1000; + music.addEventListener( + "loadedmetadata", + () => { + music.currentTime += parseFloat( + music.totime + (new Date().getTime() / 1000 - music.offset) + ).toFixed(3); + music.play(); + }, + false + ); +} \ No newline at end of file -- cgit From 39861acb94feaed7c7833597b14ab99e5acea42f Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 17:12:52 -0400 Subject: Three more packets moved --- webAO/packets/handlers/handleCI.ts | 26 ++++++++++++++++++++++++++ webAO/packets/handlers/handleEI.ts | 29 +++++++++++++++++++++++++++++ webAO/packets/handlers/handleSC.ts | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 webAO/packets/handlers/handleCI.ts create mode 100644 webAO/packets/handlers/handleEI.ts create mode 100644 webAO/packets/handlers/handleSC.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleCI.ts b/webAO/packets/handlers/handleCI.ts new file mode 100644 index 0000000..74d3039 --- /dev/null +++ b/webAO/packets/handlers/handleCI.ts @@ -0,0 +1,26 @@ +import { client } from '../../client' +/** + * Handles incoming character information, bundling multiple characters + * per packet. + * CI#0#Phoenix&description&&&&#Miles ... + * @param {Array} args packet arguments + */ +export const handleCI = (args: string[]) => { + // Loop through the 10 characters that were sent + + for (let i = 2; i <= args.length - 2; i++) { + if (i % 2 === 0) { + document.getElementById( + "client_loadingtext" + )!.innerHTML = `Loading Character ${args[1]}/${client.char_list_length}`; + const chargs = args[i].split("&"); + const charid = Number(args[i - 1]); + (( + document.getElementById("client_loadingbar") + )).value = charid; + setTimeout(() => client.handleCharacterInfo(chargs, charid), 500); + } + } + // Request the next pack + client.sendServer(`AN#${Number(args[1]) / 10 + 1}#%`); +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleEI.ts b/webAO/packets/handlers/handleEI.ts new file mode 100644 index 0000000..e96f0c9 --- /dev/null +++ b/webAO/packets/handlers/handleEI.ts @@ -0,0 +1,29 @@ +import { AO_HOST, client } from '../../client' +import { prepChat, safeTags } from '../../encoding'; + +/** + * Handles incoming evidence information, containing only one evidence + * item per packet. + * + * EI#id#name&description&type&image&##% + * + * @param {Array} args packet arguments + */ +export const handleEI = (args: string[]) => { + document.getElementById( + "client_loadingtext" + )!.innerHTML = `Loading Evidence ${args[1]}/${client.evidence_list_length}`; + const evidenceID = Number(args[1]); + (document.getElementById("client_loadingbar")).value = + client.char_list_length + evidenceID; + + const arg = args[2].split("&"); + client.evidences[evidenceID] = { + name: prepChat(arg[0]), + desc: prepChat(arg[1]), + filename: safeTags(arg[3]), + icon: `${AO_HOST}evidence/${encodeURI(arg[3].toLowerCase())}`, + }; + + client.sendServer("AE" + (evidenceID + 1) + "#%"); +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleSC.ts b/webAO/packets/handlers/handleSC.ts new file mode 100644 index 0000000..3689a17 --- /dev/null +++ b/webAO/packets/handlers/handleSC.ts @@ -0,0 +1,37 @@ +import queryParser from "../../utils/queryParser"; + +import { client } from '../../client' +let { mode } = queryParser(); + +/** + * Handles incoming character information, containing all characters + * in one packet. + * @param {Array} args packet arguments + */ +export const handleSC = async (args: string[]) => { + const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); + + if (mode === "watch") { + // Spectators don't need to pick a character + document.getElementById("client_charselect")!.style.display = "none"; + } else { + document.getElementById("client_charselect")!.style.display = "block"; + } + + document.getElementById("client_loadingtext")!.innerHTML = + "Loading Characters"; + for (let i = 1; i < args.length - 1; i++) { + document.getElementById( + "client_loadingtext" + )!.innerHTML = `Loading Character ${i}/${client.char_list_length}`; + const chargs = args[i].split("&"); + const charid = i - 1; + (( + document.getElementById("client_loadingbar") + )).value = charid; + await sleep(0.1); // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES + client.handleCharacterInfo(chargs, charid); + } + // We're done with the characters, request the music + client.sendServer("RM#%"); +} \ No newline at end of file -- cgit From 5d5cb58412bd663aed4897ef7b0f0bd7f263d096 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 17:28:30 -0400 Subject: Add more --- webAO/packets/handlers/handleEM.ts | 39 +++++++++++++++++++++++++++++++ webAO/packets/handlers/handleFL.ts | 48 ++++++++++++++++++++++++++++++++++++++ webAO/packets/handlers/handleLE.ts | 34 +++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 webAO/packets/handlers/handleEM.ts create mode 100644 webAO/packets/handlers/handleFL.ts create mode 100644 webAO/packets/handlers/handleLE.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleEM.ts b/webAO/packets/handlers/handleEM.ts new file mode 100644 index 0000000..973d2af --- /dev/null +++ b/webAO/packets/handlers/handleEM.ts @@ -0,0 +1,39 @@ +import { client } from '../../client' +import { safeTags } from '../../encoding'; + +/** + * Handles incoming music information, containing multiple entries + * per packet. + * @param {Array} args packet arguments + */ +export const handleEM = (args: string[]) => { + document.getElementById("client_loadingtext")!.innerHTML = "Loading Music"; + if (args[1] === "0") { + client.resetMusicList(); + client.resetAreaList(); + client.musics_time = false; + } + + for (let i = 2; i < args.length - 1; i++) { + if (i % 2 === 0) { + const trackname = safeTags(args[i]); + const trackindex = Number(args[i - 1]); + (( + document.getElementById("client_loadingbar") + )).value = + client.char_list_length + client.evidence_list_length + trackindex; + if (client.musics_time) { + client.addTrack(trackname); + } else if (client.isAudio(trackname)) { + client.musics_time = true; + client.fix_last_area(); + client.addTrack(trackname); + } else { + client.createArea(trackindex, trackname); + } + } + } + + // get the next batch of tracks + client.sendServer(`AM#${Number(args[1]) / 10 + 1}#%`); +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleFL.ts b/webAO/packets/handlers/handleFL.ts new file mode 100644 index 0000000..d9e67e5 --- /dev/null +++ b/webAO/packets/handlers/handleFL.ts @@ -0,0 +1,48 @@ +import { setExtraFeatures } from "../../client"; + + + /** + * With this the server tells us which features it supports + * @param {Array} args list of features + */ +export const handleFL = (args: string[]) => { + console.info("Server-supported features:"); + console.info(args); + setExtraFeatures(args); + + if (args.includes("yellowtext")) { + const colorselect = ( + document.getElementById("textcolor") + ); + + colorselect.options[colorselect.options.length] = new Option( + "Yellow", + "5" + ); + colorselect.options[colorselect.options.length] = new Option("Grey", "6"); + colorselect.options[colorselect.options.length] = new Option("Pink", "7"); + colorselect.options[colorselect.options.length] = new Option("Cyan", "8"); + } + + if (args.includes("cccc_ic_support")) { + document.getElementById("cccc")!.style.display = ""; + document.getElementById("pairing")!.style.display = ""; + } + + if (args.includes("flipping")) { + document.getElementById("button_flip")!.style.display = ""; + } + + if (args.includes("looping_sfx")) { + document.getElementById("button_shake")!.style.display = ""; + document.getElementById("2.7")!.style.display = ""; + } + + if (args.includes("effects")) { + document.getElementById("2.8")!.style.display = ""; + } + + if (args.includes("y_offset")) { + document.getElementById("y_offset")!.style.display = ""; + } + } diff --git a/webAO/packets/handlers/handleLE.ts b/webAO/packets/handlers/handleLE.ts new file mode 100644 index 0000000..28f0b40 --- /dev/null +++ b/webAO/packets/handlers/handleLE.ts @@ -0,0 +1,34 @@ +import { AO_HOST, client } from '../../client' +import { prepChat, safeTags } from '../../encoding'; + +/** + * Handles incoming evidence list, all evidences at once + * item per packet. + * + * @param {Array} args packet arguments + */ +export const handleLE = (args: string[]) => { + client.evidences = []; + for (let i = 1; i < args.length - 1; i++) { + (( + document.getElementById("client_loadingbar") + )).value = client.char_list_length + i; + const arg = args[i].split("&"); + client.evidences[i - 1] = { + name: prepChat(arg[0]), + desc: prepChat(arg[1]), + filename: safeTags(arg[2]), + icon: `${AO_HOST}evidence/${encodeURI(arg[2].toLowerCase())}`, + }; + } + + const evidence_box = document.getElementById("evidences")!; + evidence_box.innerHTML = ""; + for (let i = 1; i <= client.evidences.length; i++) { + evidence_box.innerHTML += `${client.evidences[i - 1].name}`; + } +} \ No newline at end of file -- cgit From c95c943938b2254bdb9581fc4b00e72d15e91436 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 17:39:51 -0400 Subject: More packets moved --- webAO/packets/handlers/handleFA.ts | 14 ++++++ webAO/packets/handlers/handleFL.ts | 88 +++++++++++++++++++------------------- webAO/packets/handlers/handleFM.ts | 16 +++++++ webAO/packets/handlers/handleSM.ts | 36 ++++++++++++++++ 4 files changed, 110 insertions(+), 44 deletions(-) create mode 100644 webAO/packets/handlers/handleFA.ts create mode 100644 webAO/packets/handlers/handleFM.ts create mode 100644 webAO/packets/handlers/handleSM.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleFA.ts b/webAO/packets/handlers/handleFA.ts new file mode 100644 index 0000000..ccfe923 --- /dev/null +++ b/webAO/packets/handlers/handleFA.ts @@ -0,0 +1,14 @@ +import { client } from '../../client' +import { safeTags } from '../../encoding'; + +/** + * Handles updated area list + * @param {Array} args packet arguments + */ +export const handleFA = (args: string[]) => { + client.resetAreaList(); + + for (let i = 1; i < args.length - 1; i++) { + client.createArea(i - 1, safeTags(args[i])); + } +} diff --git a/webAO/packets/handlers/handleFL.ts b/webAO/packets/handlers/handleFL.ts index d9e67e5..378d5a9 100644 --- a/webAO/packets/handlers/handleFL.ts +++ b/webAO/packets/handlers/handleFL.ts @@ -1,48 +1,48 @@ import { setExtraFeatures } from "../../client"; - - /** - * With this the server tells us which features it supports - * @param {Array} args list of features - */ + +/** + * With this the server tells us which features it supports + * @param {Array} args list of features + */ export const handleFL = (args: string[]) => { - console.info("Server-supported features:"); - console.info(args); - setExtraFeatures(args); - - if (args.includes("yellowtext")) { - const colorselect = ( - document.getElementById("textcolor") - ); - - colorselect.options[colorselect.options.length] = new Option( - "Yellow", - "5" - ); - colorselect.options[colorselect.options.length] = new Option("Grey", "6"); - colorselect.options[colorselect.options.length] = new Option("Pink", "7"); - colorselect.options[colorselect.options.length] = new Option("Cyan", "8"); - } - - if (args.includes("cccc_ic_support")) { - document.getElementById("cccc")!.style.display = ""; - document.getElementById("pairing")!.style.display = ""; - } - - if (args.includes("flipping")) { - document.getElementById("button_flip")!.style.display = ""; - } - - if (args.includes("looping_sfx")) { - document.getElementById("button_shake")!.style.display = ""; - document.getElementById("2.7")!.style.display = ""; - } - - if (args.includes("effects")) { - document.getElementById("2.8")!.style.display = ""; - } - - if (args.includes("y_offset")) { - document.getElementById("y_offset")!.style.display = ""; - } + console.info("Server-supported features:"); + console.info(args); + setExtraFeatures(args); + + if (args.includes("yellowtext")) { + const colorselect = ( + document.getElementById("textcolor") + ); + + colorselect.options[colorselect.options.length] = new Option( + "Yellow", + "5" + ); + colorselect.options[colorselect.options.length] = new Option("Grey", "6"); + colorselect.options[colorselect.options.length] = new Option("Pink", "7"); + colorselect.options[colorselect.options.length] = new Option("Cyan", "8"); + } + + if (args.includes("cccc_ic_support")) { + document.getElementById("cccc")!.style.display = ""; + document.getElementById("pairing")!.style.display = ""; + } + + if (args.includes("flipping")) { + document.getElementById("button_flip")!.style.display = ""; + } + + if (args.includes("looping_sfx")) { + document.getElementById("button_shake")!.style.display = ""; + document.getElementById("2.7")!.style.display = ""; + } + + if (args.includes("effects")) { + document.getElementById("2.8")!.style.display = ""; + } + + if (args.includes("y_offset")) { + document.getElementById("y_offset")!.style.display = ""; } +} diff --git a/webAO/packets/handlers/handleFM.ts b/webAO/packets/handlers/handleFM.ts new file mode 100644 index 0000000..630477b --- /dev/null +++ b/webAO/packets/handlers/handleFM.ts @@ -0,0 +1,16 @@ +import { client } from "../../client"; +import { safeTags } from "../../encoding"; + + +/** + * Handles updated music list + * @param {Array} args packet arguments + */ +export const handleFM = (args: string[]) => { + client.resetMusicList(); + + for (let i = 1; i < args.length - 1; i++) { + // Check when found the song for the first time + client.addTrack(safeTags(args[i])); + } +} diff --git a/webAO/packets/handlers/handleSM.ts b/webAO/packets/handlers/handleSM.ts new file mode 100644 index 0000000..5dab83e --- /dev/null +++ b/webAO/packets/handlers/handleSM.ts @@ -0,0 +1,36 @@ +import { client } from '../../client' +/** + * Handles incoming music information, containing all music in one packet. + * @param {Array} args packet arguments + */ +export const handleSM = (args: string[]) => { + document.getElementById("client_loadingtext")!.innerHTML = "Loading Music "; + client.resetMusicList(); + client.resetAreaList(); + + client.musics_time = false; + + for (let i = 1; i < args.length - 1; i++) { + // Check when found the song for the first time + const trackname = args[i]; + const trackindex = i - 1; + document.getElementById( + "client_loadingtext" + )!.innerHTML = `Loading Music ${i}/${client.music_list_length}`; + (( + document.getElementById("client_loadingbar") + )).value = client.char_list_length + client.evidence_list_length + i; + if (client.musics_time) { + client.addTrack(trackname); + } else if (client.isAudio(trackname)) { + client.musics_time = true; + client.fix_last_area(); + client.addTrack(trackname); + } else { + client.createArea(trackindex, trackname); + } + } + + // Music done, carry on + client.sendServer("RD#%"); +} -- cgit From 56026c522ba84bc0211a896398d701cb79725b54 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 17:50:08 -0400 Subject: Five packets --- webAO/packets/handlers/handleBB.ts | 11 +++++++++++ webAO/packets/handlers/handleBD.ts | 13 +++++++++++++ webAO/packets/handlers/handleKB.ts | 12 ++++++++++++ webAO/packets/handlers/handleKK.ts | 11 +++++++++++ webAO/packets/handlers/handleMM.ts | 8 ++++++++ 5 files changed, 55 insertions(+) create mode 100644 webAO/packets/handlers/handleBB.ts create mode 100644 webAO/packets/handlers/handleBD.ts create mode 100644 webAO/packets/handlers/handleKB.ts create mode 100644 webAO/packets/handlers/handleKK.ts create mode 100644 webAO/packets/handlers/handleMM.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBB.ts b/webAO/packets/handlers/handleBB.ts new file mode 100644 index 0000000..c12c4f6 --- /dev/null +++ b/webAO/packets/handlers/handleBB.ts @@ -0,0 +1,11 @@ +import { safeTags } from "../../encoding"; + + +/** + * Handles the warning packet + * on client this spawns a message box you can't close for 2 seconds + * @param {Array} args ban reason + */ +export const handleBB = (args: string[]) => { + alert(safeTags(args[1])); +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleBD.ts b/webAO/packets/handlers/handleBD.ts new file mode 100644 index 0000000..4ec291e --- /dev/null +++ b/webAO/packets/handlers/handleBD.ts @@ -0,0 +1,13 @@ +import { client, setBanned } from "../../client"; +import { safeTags } from "../../encoding"; + + +/** + * Handles the banned packet + * this one is sent when you try to reconnect but you're banned + * @param {Array} args ban reason + */ +export const handleBD = (args: string[]) => { + client.handleBans("Banned", safeTags(args[1])); + setBanned(true); +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleKB.ts b/webAO/packets/handlers/handleKB.ts new file mode 100644 index 0000000..8705b83 --- /dev/null +++ b/webAO/packets/handlers/handleKB.ts @@ -0,0 +1,12 @@ +import { client, setBanned } from "../../client"; +import { safeTags } from "../../encoding"; + +/** + * Handles the banned packet + * this one is sent when you are kicked off the server + * @param {Array} args ban reason + */ +export const handleKB = (args: string[]) => { + client.handleBans("Banned", safeTags(args[1])); + setBanned(true); +} diff --git a/webAO/packets/handlers/handleKK.ts b/webAO/packets/handlers/handleKK.ts new file mode 100644 index 0000000..fd9a88c --- /dev/null +++ b/webAO/packets/handlers/handleKK.ts @@ -0,0 +1,11 @@ +import { client } from "../../client"; +import { safeTags } from "../../encoding"; + + +/** + * Handles the kicked packet + * @param {Array} args kick reason + */ +export const handleKK = (args: string[]) => { + client.handleBans("Kicked", safeTags(args[1])); +} diff --git a/webAO/packets/handlers/handleMM.ts b/webAO/packets/handlers/handleMM.ts new file mode 100644 index 0000000..077140f --- /dev/null +++ b/webAO/packets/handlers/handleMM.ts @@ -0,0 +1,8 @@ + +/** + * Handles the "MusicMode" packet + * @param {Array} args packet arguments + */ +export const handleMM = (_args: string[]) => { + // It's unused nowadays, as preventing people from changing the music is now serverside +} \ No newline at end of file -- cgit From 357b27c0aae95031a5d94bdbc504d82b797b22e2 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 18:08:05 -0400 Subject: Several packets added --- webAO/packets/handlers/handleBN.ts | 81 ++++++++++++++++++++++++++++++++++++ webAO/packets/handlers/handleDONE.ts | 16 +++++++ webAO/packets/handlers/handleHI.ts | 14 +++++++ webAO/packets/handlers/handleHP.ts | 23 ++++++++++ webAO/packets/handlers/handleRT.ts | 25 +++++++++++ webAO/packets/handlers/handleTI.ts | 21 ++++++++++ webAO/packets/handlers/handleZZ.ts | 22 ++++++++++ 7 files changed, 202 insertions(+) create mode 100644 webAO/packets/handlers/handleBN.ts create mode 100644 webAO/packets/handlers/handleDONE.ts create mode 100644 webAO/packets/handlers/handleHI.ts create mode 100644 webAO/packets/handlers/handleHP.ts create mode 100644 webAO/packets/handlers/handleRT.ts create mode 100644 webAO/packets/handlers/handleTI.ts create mode 100644 webAO/packets/handlers/handleZZ.ts (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts new file mode 100644 index 0000000..3cd3c5a --- /dev/null +++ b/webAO/packets/handlers/handleBN.ts @@ -0,0 +1,81 @@ +import { AO_HOST, client, getIndexFromSelect, updateBackgroundPreview } from "../../client"; +import { safeTags } from "../../encoding"; +import tryUrls from "../../utils/tryUrls"; + + + /** + * Handles a background change. + * @param {Array} args packet arguments + */ + +export const handleBN = (args: string[]) => { + const bgFromArgs = safeTags(args[1]); + client.viewport.setBackgroundName(bgFromArgs); + const bgfolder = client.viewport.getBackgroundFolder(); + const bg_index = getIndexFromSelect( + "bg_select", + client.viewport.getBackgroundName() + ); + (document.getElementById("bg_select")).selectedIndex = + bg_index; + updateBackgroundPreview(); + if (bg_index === 0) { + (document.getElementById("bg_filename")).value = + client.viewport.getBackgroundName(); + } + + tryUrls( + `${AO_HOST}background/${encodeURI(args[1].toLowerCase())}/defenseempty` + ).then((resp) => { + (document.getElementById("bg_preview")).src = resp; + }); + tryUrls(`${bgfolder}defensedesk`).then((resp) => { + (document.getElementById("client_def_bench")).src = + resp; + }); + tryUrls(`${bgfolder}stand`).then((resp) => { + (document.getElementById("client_wit_bench")).src = + resp; + }); + tryUrls(`${bgfolder}prosecutiondesk`).then((resp) => { + (document.getElementById("client_pro_bench")).src = + resp; + }); + tryUrls(`${bgfolder}full`).then((resp) => { + (document.getElementById("client_court")).src = resp; + }); + tryUrls(`${bgfolder}defenseempty`).then((resp) => { + (document.getElementById("client_court_def")).src = + resp; + }); + tryUrls(`${bgfolder}transition_def`).then((resp) => { + (document.getElementById("client_court_deft")).src = + resp; + }); + tryUrls(`${bgfolder}witnessempty`).then((resp) => { + (document.getElementById("client_court_wit")).src = + resp; + }); + tryUrls(`${bgfolder}transition_pro`).then((resp) => { + (document.getElementById("client_court_prot")).src = + resp; + }); + tryUrls(`${bgfolder}prosecutorempty`).then((resp) => { + (document.getElementById("client_court_pro")).src = + resp; + }); + + if (client.charID === -1) { + client.viewport.set_side({ + position: "jud", + showSpeedLines: false, + showDesk: true, + }); + } else { + client.viewport.set_side({ + position: client.chars[client.charID].side, + showSpeedLines: false, + showDesk: true, + }); + } + } \ No newline at end of file diff --git a/webAO/packets/handlers/handleDONE.ts b/webAO/packets/handlers/handleDONE.ts new file mode 100644 index 0000000..3cafd5e --- /dev/null +++ b/webAO/packets/handlers/handleDONE.ts @@ -0,0 +1,16 @@ +import queryParser from "../../utils/queryParser"; + +let { mode } = queryParser() + /** + * Handles the handshake completion packet, meaning the player + * is ready to select a character. + * + * @param {Array} args packet arguments + */ +export const handleDONE = (_args: string[]) => { + document.getElementById("client_loading")!.style.display = "none"; + if (mode === "watch") { + // Spectators don't need to pick a character + document.getElementById("client_waiting")!.style.display = "none"; + } + } \ No newline at end of file diff --git a/webAO/packets/handlers/handleHI.ts b/webAO/packets/handlers/handleHI.ts new file mode 100644 index 0000000..d15be0d --- /dev/null +++ b/webAO/packets/handlers/handleHI.ts @@ -0,0 +1,14 @@ +import { client } from "../../client"; +const version = process.env.npm_package_version; + + +/** + * Handle the player + * @param {Array} args packet arguments + */ +export const handleHI = (_args: string[]) => { + client.sendSelf(`ID#1#webAO#${version}#%`); + client.sendSelf( + "FL#fastloading#yellowtext#cccc_ic_support#flipping#looping_sfx#effects#%" + ); +} diff --git a/webAO/packets/handlers/handleHP.ts b/webAO/packets/handlers/handleHP.ts new file mode 100644 index 0000000..f365590 --- /dev/null +++ b/webAO/packets/handlers/handleHP.ts @@ -0,0 +1,23 @@ +import { client } from "../../client"; + + + /** + * Handles a change in the health bars' states. + * @param {Array} args packet arguments + */ +export const handleHP = (args: string[]) => { + const percent_hp = Number(args[2]) * 10; + let healthbox; + if (args[1] === "1") { + // Def hp + client.hp[0] = Number(args[2]); + healthbox = document.getElementById("client_defense_hp"); + } else { + // Pro hp + client.hp[1] = Number(args[2]); + healthbox = document.getElementById("client_prosecutor_hp"); + } + (( + healthbox.getElementsByClassName("health-bar")[0] + )).style.width = `${percent_hp}%`; + } \ No newline at end of file diff --git a/webAO/packets/handlers/handleRT.ts b/webAO/packets/handlers/handleRT.ts new file mode 100644 index 0000000..5bbf2b2 --- /dev/null +++ b/webAO/packets/handlers/handleRT.ts @@ -0,0 +1,25 @@ +import { client } from "../../client"; + + +/** + * Handles a testimony states. + * @param {Array} args packet arguments + */ +export const handleRT = (args: string[]) => { + const judgeid = Number(args[2]); + switch (args[1]) { + case "testimony1": + client.testimonyID = 1; + break; + case "testimony2": + // Cross Examination + client.testimonyID = 2; + break; + case "judgeruling": + client.testimonyID = 3 + judgeid; + break; + default: + console.warn("Invalid testimony"); + } + client.viewport.initTestimonyUpdater(); +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleTI.ts b/webAO/packets/handlers/handleTI.ts new file mode 100644 index 0000000..e418088 --- /dev/null +++ b/webAO/packets/handlers/handleTI.ts @@ -0,0 +1,21 @@ +/** + * Handles a timer update + * @param {Array} args packet arguments + */ +export const handleTI = (args: string[]) => { + const timerid = Number(args[1]); + const type = Number(args[2]); + const timer_value = args[3]; + switch (type) { + case 0: + // + case 1: + document.getElementById(`client_timer${timerid}`)!.innerText = + timer_value; + case 2: + document.getElementById(`client_timer${timerid}`)!.style.display = ""; + case 3: + document.getElementById(`client_timer${timerid}`)!.style.display = + "none"; + } +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleZZ.ts b/webAO/packets/handlers/handleZZ.ts new file mode 100644 index 0000000..1a56e49 --- /dev/null +++ b/webAO/packets/handlers/handleZZ.ts @@ -0,0 +1,22 @@ +import { AO_HOST, client } from "../../client"; +import { prepChat } from "../../encoding"; + + +/** + * Handles a modcall + * @param {Array} args packet arguments + */ +export const handleZZ = (args: string[]) => { + const oocLog = document.getElementById("client_ooclog")!; + oocLog.innerHTML += `$Alert: ${prepChat(args[1])}\r\n`; + if (oocLog.scrollTop > oocLog.scrollHeight - 60) { + oocLog.scrollTop = oocLog.scrollHeight; + } + + client.viewport.getSfxAudio().pause(); + const oldvolume = client.viewport.getSfxAudio().volume; + client.viewport.getSfxAudio().volume = 1; + client.viewport.getSfxAudio().src = `${AO_HOST}sounds/general/sfx-gallery.opus`; + client.viewport.getSfxAudio().play(); + client.viewport.getSfxAudio().volume = oldvolume; +} \ No newline at end of file -- cgit From e66a37a62b06df5b0f48d64f6b9a14b9f81bd15d Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 18:32:27 -0400 Subject: A buncha more --- webAO/packets/handlers/handleARUP.ts | 42 +++++++++++++++++++++++++++++++++ webAO/packets/handlers/handleCC.ts | 9 +++++++ webAO/packets/handlers/handleID.ts | 24 +++++++++++++++++++ webAO/packets/handlers/handlePN.ts | 9 +++++++ webAO/packets/handlers/handleRC.ts | 10 ++++++++ webAO/packets/handlers/handleSI.ts | 41 ++++++++++++++++++++++++++++++++ webAO/packets/handlers/handleaskchaa.ts | 10 ++++++++ 7 files changed, 145 insertions(+) create mode 100644 webAO/packets/handlers/handleARUP.ts create mode 100644 webAO/packets/handlers/handleCC.ts create mode 100644 webAO/packets/handlers/handleID.ts create mode 100644 webAO/packets/handlers/handlePN.ts create mode 100644 webAO/packets/handlers/handleRC.ts create mode 100644 webAO/packets/handlers/handleSI.ts create mode 100644 webAO/packets/handlers/handleaskchaa.ts (limited to 'webAO/packets') 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]); + + (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#%`); +} -- cgit From 86b493b881bde4a11214929ebe4317289a7f1da3 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 1 Sep 2022 22:36:22 -0400 Subject: Moved rest of the handlers --- webAO/packets/handlers/handleASS.ts | 10 ++++ webAO/packets/handlers/handleCharsCheck.ts | 17 +++++++ webAO/packets/handlers/handleJD.ts | 13 +++++ webAO/packets/handlers/handlePV.ts | 82 ++++++++++++++++++++++++++++++ webAO/packets/handlers/handleRD.ts | 18 +++++++ webAO/packets/handlers/handleRM.ts | 10 ++++ webAO/packets/handlers/handleSP.ts | 9 ++++ webAO/packets/handlers/handleackMS.ts | 8 +++ 8 files changed, 167 insertions(+) create mode 100644 webAO/packets/handlers/handleASS.ts create mode 100644 webAO/packets/handlers/handleCharsCheck.ts create mode 100644 webAO/packets/handlers/handleJD.ts create mode 100644 webAO/packets/handlers/handlePV.ts create mode 100644 webAO/packets/handlers/handleRD.ts create mode 100644 webAO/packets/handlers/handleRM.ts create mode 100644 webAO/packets/handlers/handleSP.ts create mode 100644 webAO/packets/handlers/handleackMS.ts (limited to 'webAO/packets') 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 = `No emotes available`; + } 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 += `${emotes[i].desc}`; + } 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 = 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 -- cgit From 2bfa8207ce40a853d0f62a72e006c9b2b90d69b6 Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 2 Sep 2022 21:50:34 -0400 Subject: New handler --- webAO/packets/ms.js | 28 -------------- webAO/packets/packetHandler.ts | 87 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 28 deletions(-) delete mode 100644 webAO/packets/ms.js create mode 100644 webAO/packets/packetHandler.ts (limited to 'webAO/packets') diff --git a/webAO/packets/ms.js b/webAO/packets/ms.js deleted file mode 100644 index 26851bd..0000000 --- a/webAO/packets/ms.js +++ /dev/null @@ -1,28 +0,0 @@ -export default { - deskmod, - preanim, - name, - emote, - message, - side, - sfx_name, - emote_modifier, - sfx_delay, - objection_modifier, - evidence, - flip, - realization, - text_color, - showname, - other_charid, - self_hoffset, - self_yoffset, - noninterrupting_preanim, - looping_sfx, - screenshake, - frame_screenshake, - frame_realization, - frame_sfx, - additive, - effect, -}; diff --git a/webAO/packets/packetHandler.ts b/webAO/packets/packetHandler.ts new file mode 100644 index 0000000..b98eef9 --- /dev/null +++ b/webAO/packets/packetHandler.ts @@ -0,0 +1,87 @@ +import { handleMS } from './handlers/handleMS'; +import { handleCT } from './handlers/handleCT' +import { handleMC } from './handlers/handleMC' +import { handleRMC } from './handlers/handleRMC' +import { handleFL } from './handlers/handleFL' +import { handleLE } from './handlers/handleLE' +import { handleEM } from './handlers/handleEM' +import { handleEI } from './handlers/handleEI' +import { handleSC } from './handlers/handleSC' +import { handleCI } from './handlers/handleCI' +import { handleFM } from './handlers/handleFM' +import { handleFA } from './handlers/handleFA' +import { handleSM } from './handlers/handleSM' +import { handleMM } from './handlers/handleMM' +import { handleBD } from './handlers/handleBD' +import { handleBB } from './handlers/handleBB' +import { handleKB } from './handlers/handleKB' +import { handleKK } from './handlers/handleKK' +import { handleDONE } from './handlers/handleDONE' +import { handleBN } from './handlers/handleBN' +import { handleHP } from './handlers/handleHP' +import { handleRT } from './handlers/handleRT' +import { handleTI } from './handlers/handleTI' +import { handleZZ } from './handlers/handleZZ' +import { handleHI } from './handlers/handleHI' +import { handleID } from './handlers/handleID' +import { handlePN } from './handlers/handlePN' +import { handleSI } from './handlers/handleSI' +import { handleARUP } from './handlers/handleARUP' +import { handleaskchaa } from './handlers/handleaskchaa' +import { handleCC } from './handlers/handleCC' +import { handleRC } from './handlers/handleRC' +import { handleRM } from './handlers/handleRM' +import { handleRD } from './handlers/handleRD' +import { handleCharsCheck } from './handlers/handleCharsCheck' +import { handlePV } from './handlers/handlePV' +import { handleASS } from './handlers/handleASS' +import { handleackMS } from './handlers/handleackMS' +import { handleSP } from './handlers/handleSP' +import { handleJD } from './handlers/handleJD' + +export const packetHandler = new Map([ + ["MS", handleMS], + ["CT", handleCT], + ["MC", handleMC], + ["RMC", handleRMC], + ["CI", handleCI], + ["SC", handleSC], + ["EI", handleEI], + ["FL", handleFL], + ["LE", handleLE], + ["EM", handleEM], + ["FM", handleFM], + ["FA", handleFA], + ["SM", handleSM], + ["MM", handleMM], + ["BD", handleBD], + ["BB", handleBB], + ["KB", handleKB], + ["KK", handleKK], + ["DONE", handleDONE], + ["BN", handleBN], + ["HP", handleHP], + ["RT", handleRT], + ["TI", handleTI], + ["ZZ", handleZZ], + ["HI", handleHI], + ["ID", handleID], + ["PN", handlePN], + ["SI", handleSI], + ["ARUP", handleARUP], + ["askchaa", handleaskchaa], + ["CC", handleCC], + ["RC", handleRC], + ["RM", handleRM], + ["RD", handleRD], + ["CharsCheck", handleCharsCheck], + ["PV", handlePV], + ["ASS", handleASS], + ["ackMS", handleackMS], + ["SP", handleSP], + ["JD", handleJD], + ["decryptor", () => { }], + ["CHECK", () => { }], + ["CH", () => { }], +] +) \ No newline at end of file -- cgit From 317708a352376a31f1410d57e08a2e1a1ceb6812 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 3 Sep 2022 00:46:33 -0400 Subject: Maybe overkill, but I like it more --- webAO/packets/packetHandler.ts | 88 +----------------------------------------- webAO/packets/packets.ts | 86 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 86 deletions(-) create mode 100644 webAO/packets/packets.ts (limited to 'webAO/packets') diff --git a/webAO/packets/packetHandler.ts b/webAO/packets/packetHandler.ts index b98eef9..a9b567a 100644 --- a/webAO/packets/packetHandler.ts +++ b/webAO/packets/packetHandler.ts @@ -1,87 +1,3 @@ -import { handleMS } from './handlers/handleMS'; -import { handleCT } from './handlers/handleCT' -import { handleMC } from './handlers/handleMC' -import { handleRMC } from './handlers/handleRMC' -import { handleFL } from './handlers/handleFL' -import { handleLE } from './handlers/handleLE' -import { handleEM } from './handlers/handleEM' -import { handleEI } from './handlers/handleEI' -import { handleSC } from './handlers/handleSC' -import { handleCI } from './handlers/handleCI' -import { handleFM } from './handlers/handleFM' -import { handleFA } from './handlers/handleFA' -import { handleSM } from './handlers/handleSM' -import { handleMM } from './handlers/handleMM' -import { handleBD } from './handlers/handleBD' -import { handleBB } from './handlers/handleBB' -import { handleKB } from './handlers/handleKB' -import { handleKK } from './handlers/handleKK' -import { handleDONE } from './handlers/handleDONE' -import { handleBN } from './handlers/handleBN' -import { handleHP } from './handlers/handleHP' -import { handleRT } from './handlers/handleRT' -import { handleTI } from './handlers/handleTI' -import { handleZZ } from './handlers/handleZZ' -import { handleHI } from './handlers/handleHI' -import { handleID } from './handlers/handleID' -import { handlePN } from './handlers/handlePN' -import { handleSI } from './handlers/handleSI' -import { handleARUP } from './handlers/handleARUP' -import { handleaskchaa } from './handlers/handleaskchaa' -import { handleCC } from './handlers/handleCC' -import { handleRC } from './handlers/handleRC' -import { handleRM } from './handlers/handleRM' -import { handleRD } from './handlers/handleRD' -import { handleCharsCheck } from './handlers/handleCharsCheck' -import { handlePV } from './handlers/handlePV' -import { handleASS } from './handlers/handleASS' -import { handleackMS } from './handlers/handleackMS' -import { handleSP } from './handlers/handleSP' -import { handleJD } from './handlers/handleJD' +import { packets } from './packets' -export const packetHandler = new Map([ - ["MS", handleMS], - ["CT", handleCT], - ["MC", handleMC], - ["RMC", handleRMC], - ["CI", handleCI], - ["SC", handleSC], - ["EI", handleEI], - ["FL", handleFL], - ["LE", handleLE], - ["EM", handleEM], - ["FM", handleFM], - ["FA", handleFA], - ["SM", handleSM], - ["MM", handleMM], - ["BD", handleBD], - ["BB", handleBB], - ["KB", handleKB], - ["KK", handleKK], - ["DONE", handleDONE], - ["BN", handleBN], - ["HP", handleHP], - ["RT", handleRT], - ["TI", handleTI], - ["ZZ", handleZZ], - ["HI", handleHI], - ["ID", handleID], - ["PN", handlePN], - ["SI", handleSI], - ["ARUP", handleARUP], - ["askchaa", handleaskchaa], - ["CC", handleCC], - ["RC", handleRC], - ["RM", handleRM], - ["RD", handleRD], - ["CharsCheck", handleCharsCheck], - ["PV", handlePV], - ["ASS", handleASS], - ["ackMS", handleackMS], - ["SP", handleSP], - ["JD", handleJD], - ["decryptor", () => { }], - ["CHECK", () => { }], - ["CH", () => { }], -] -) \ No newline at end of file +export const packetHandler = new Map(Object.entries(packets)) \ No newline at end of file diff --git a/webAO/packets/packets.ts b/webAO/packets/packets.ts new file mode 100644 index 0000000..79c43c1 --- /dev/null +++ b/webAO/packets/packets.ts @@ -0,0 +1,86 @@ +import { handleMS } from './handlers/handleMS'; +import { handleCT } from './handlers/handleCT' +import { handleMC } from './handlers/handleMC' +import { handleRMC } from './handlers/handleRMC' +import { handleFL } from './handlers/handleFL' +import { handleLE } from './handlers/handleLE' +import { handleEM } from './handlers/handleEM' +import { handleEI } from './handlers/handleEI' +import { handleSC } from './handlers/handleSC' +import { handleCI } from './handlers/handleCI' +import { handleFM } from './handlers/handleFM' +import { handleFA } from './handlers/handleFA' +import { handleSM } from './handlers/handleSM' +import { handleMM } from './handlers/handleMM' +import { handleBD } from './handlers/handleBD' +import { handleBB } from './handlers/handleBB' +import { handleKB } from './handlers/handleKB' +import { handleKK } from './handlers/handleKK' +import { handleDONE } from './handlers/handleDONE' +import { handleBN } from './handlers/handleBN' +import { handleHP } from './handlers/handleHP' +import { handleRT } from './handlers/handleRT' +import { handleTI } from './handlers/handleTI' +import { handleZZ } from './handlers/handleZZ' +import { handleHI } from './handlers/handleHI' +import { handleID } from './handlers/handleID' +import { handlePN } from './handlers/handlePN' +import { handleSI } from './handlers/handleSI' +import { handleARUP } from './handlers/handleARUP' +import { handleaskchaa } from './handlers/handleaskchaa' +import { handleCC } from './handlers/handleCC' +import { handleRC } from './handlers/handleRC' +import { handleRM } from './handlers/handleRM' +import { handleRD } from './handlers/handleRD' +import { handleCharsCheck } from './handlers/handleCharsCheck' +import { handlePV } from './handlers/handlePV' +import { handleASS } from './handlers/handleASS' +import { handleackMS } from './handlers/handleackMS' +import { handleSP } from './handlers/handleSP' +import { handleJD } from './handlers/handleJD' + +export const packets = { + "MS": handleMS, + "CT": handleCT, + "MC": handleMC, + "RMC": handleRMC, + "CI": handleCI, + "SC": handleSC, + "EI": handleEI, + "FL": handleFL, + "LE": handleLE, + "EM": handleEM, + "FM": handleFM, + "FA": handleFA, + "SM": handleSM, + "MM": handleMM, + "BD": handleBD, + "BB": handleBB, + "KB": handleKB, + "KK": handleKK, + "DONE": handleDONE, + "BN": handleBN, + "HP": handleHP, + "RT": handleRT, + "TI": handleTI, + "ZZ": handleZZ, + "HI": handleHI, + "ID": handleID, + "PN": handlePN, + "SI": handleSI, + "ARUP": handleARUP, + "askchaa": handleaskchaa, + "CC": handleCC, + "RC": handleRC, + "RM": handleRM, + "RD": handleRD, + "CharsCheck": handleCharsCheck, + "PV": handlePV, + "ASS": handleASS, + "ackMS": handleackMS, + "SP": handleSP, + "JD": handleJD, + "decryptor": () => { }, + "CHECK": () => { }, + "CH": () => { }, +} \ No newline at end of file -- cgit From d20994bd7c244cc84ab138cec441b05c261a83e4 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 3 Sep 2022 17:13:39 +0200 Subject: also provide mouseover for emotes --- webAO/packets/handlers/handlePV.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index 18947c5..ea57331 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -60,6 +60,7 @@ export const handlePV = async (args: string[]) => { emotesList.innerHTML += `${emotes[i].desc}`; } catch (e) { -- cgit From 67314a8bc22ea198b8e3de788282a0ca0151cb1e Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 4 Sep 2022 00:02:19 -0400 Subject: Several functions moved --- webAO/packets/handlers/handleBN.ts | 146 ++++++++++++++++++------------------- webAO/packets/handlers/handlePV.ts | 130 ++++++++++++++++----------------- webAO/packets/handlers/handleSP.ts | 3 +- 3 files changed, 139 insertions(+), 140 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index 3cd3c5a..9dabc15 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -1,81 +1,81 @@ -import { AO_HOST, client, getIndexFromSelect, updateBackgroundPreview } from "../../client"; +import { AO_HOST, client, getIndexFromSelect } from "../../client"; import { safeTags } from "../../encoding"; import tryUrls from "../../utils/tryUrls"; +import { updateBackgroundPreview } from '../../dom/updateBackgroundPreview' - - /** - * Handles a background change. - * @param {Array} args packet arguments - */ +/** + * Handles a background change. + * @param {Array} args packet arguments + */ export const handleBN = (args: string[]) => { - const bgFromArgs = safeTags(args[1]); - client.viewport.setBackgroundName(bgFromArgs); - const bgfolder = client.viewport.getBackgroundFolder(); - const bg_index = getIndexFromSelect( - "bg_select", - client.viewport.getBackgroundName() - ); - (document.getElementById("bg_select")).selectedIndex = - bg_index; - updateBackgroundPreview(); - if (bg_index === 0) { - (document.getElementById("bg_filename")).value = - client.viewport.getBackgroundName(); - } + const bgFromArgs = safeTags(args[1]); + client.viewport.setBackgroundName(bgFromArgs); + const bgfolder = client.viewport.getBackgroundFolder(); + const bg_index = getIndexFromSelect( + "bg_select", + client.viewport.getBackgroundName() + ); + (document.getElementById("bg_select")).selectedIndex = + bg_index; + updateBackgroundPreview(); + if (bg_index === 0) { + (document.getElementById("bg_filename")).value = + client.viewport.getBackgroundName(); + } - tryUrls( - `${AO_HOST}background/${encodeURI(args[1].toLowerCase())}/defenseempty` - ).then((resp) => { - (document.getElementById("bg_preview")).src = resp; - }); - tryUrls(`${bgfolder}defensedesk`).then((resp) => { - (document.getElementById("client_def_bench")).src = - resp; - }); - tryUrls(`${bgfolder}stand`).then((resp) => { - (document.getElementById("client_wit_bench")).src = - resp; - }); - tryUrls(`${bgfolder}prosecutiondesk`).then((resp) => { - (document.getElementById("client_pro_bench")).src = - resp; - }); - tryUrls(`${bgfolder}full`).then((resp) => { - (document.getElementById("client_court")).src = resp; - }); - tryUrls(`${bgfolder}defenseempty`).then((resp) => { - (document.getElementById("client_court_def")).src = - resp; - }); - tryUrls(`${bgfolder}transition_def`).then((resp) => { - (document.getElementById("client_court_deft")).src = - resp; - }); - tryUrls(`${bgfolder}witnessempty`).then((resp) => { - (document.getElementById("client_court_wit")).src = - resp; - }); - tryUrls(`${bgfolder}transition_pro`).then((resp) => { - (document.getElementById("client_court_prot")).src = - resp; + tryUrls( + `${AO_HOST}background/${encodeURI(args[1].toLowerCase())}/defenseempty` + ).then((resp) => { + (document.getElementById("bg_preview")).src = resp; + }); + tryUrls(`${bgfolder}defensedesk`).then((resp) => { + (document.getElementById("client_def_bench")).src = + resp; + }); + tryUrls(`${bgfolder}stand`).then((resp) => { + (document.getElementById("client_wit_bench")).src = + resp; + }); + tryUrls(`${bgfolder}prosecutiondesk`).then((resp) => { + (document.getElementById("client_pro_bench")).src = + resp; + }); + tryUrls(`${bgfolder}full`).then((resp) => { + (document.getElementById("client_court")).src = resp; + }); + tryUrls(`${bgfolder}defenseempty`).then((resp) => { + (document.getElementById("client_court_def")).src = + resp; + }); + tryUrls(`${bgfolder}transition_def`).then((resp) => { + (document.getElementById("client_court_deft")).src = + resp; + }); + tryUrls(`${bgfolder}witnessempty`).then((resp) => { + (document.getElementById("client_court_wit")).src = + resp; + }); + tryUrls(`${bgfolder}transition_pro`).then((resp) => { + (document.getElementById("client_court_prot")).src = + resp; + }); + tryUrls(`${bgfolder}prosecutorempty`).then((resp) => { + (document.getElementById("client_court_pro")).src = + resp; + }); + + if (client.charID === -1) { + client.viewport.set_side({ + position: "jud", + showSpeedLines: false, + showDesk: true, }); - tryUrls(`${bgfolder}prosecutorempty`).then((resp) => { - (document.getElementById("client_court_pro")).src = - resp; + } else { + client.viewport.set_side({ + position: client.chars[client.charID].side, + showSpeedLines: false, + showDesk: true, }); - - if (client.charID === -1) { - client.viewport.set_side({ - position: "jud", - showSpeedLines: false, - showDesk: true, - }); - } else { - client.viewport.set_side({ - position: client.chars[client.charID].side, - showSpeedLines: false, - showDesk: true, - }); - } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index ea57331..5bdb702 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -1,83 +1,83 @@ -import { AO_HOST, client, pickEmotion, updateActionCommands } from "../../client"; +import { AO_HOST, client, pickEmotion } from "../../client"; import fileExists from "../../utils/fileExists"; +import { updateActionCommands } from '../../dom/updateActionCommands' - - /** - * Handles the server's assignment of a character for the player to use. - * PV # playerID (unused) # CID # character ID - * @param {Array} args packet arguments - */ +/** + * 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"; + 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 = `No emotes available`; - } else { - for (let i = 1; i <= ini.emotions.number; i++) { + } else { + for (let i = 1; i <= ini.emotions.number; i++) { + try { + const emoteinfo = ini.emotions[i].split("#"); + let esfx; + let esfxd; 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 + 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 += `${emotes[i].desc}`; - } catch (e) { - console.error(`missing emote ${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"; } + 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/handleSP.ts b/webAO/packets/handlers/handleSP.ts index e2cad18..e176eeb 100644 --- a/webAO/packets/handlers/handleSP.ts +++ b/webAO/packets/handlers/handleSP.ts @@ -1,5 +1,4 @@ -import { updateActionCommands } from "../../client"; - +import { updateActionCommands } from '../../dom/updateActionCommands' /** * position change * @param {string} pos new position -- cgit From 1e3fde25b9f6d8adbdf087a51a34dc35cc1907d8 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 4 Sep 2022 22:30:31 +0200 Subject: undo dom stuff --- webAO/packets/handlers/handleBN.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index 9dabc15..f7b8447 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -1,7 +1,6 @@ -import { AO_HOST, client, getIndexFromSelect } from "../../client"; +import { AO_HOST, client, getIndexFromSelect, updateBackgroundPreview } from "../../client"; import { safeTags } from "../../encoding"; import tryUrls from "../../utils/tryUrls"; -import { updateBackgroundPreview } from '../../dom/updateBackgroundPreview' /** * Handles a background change. -- cgit From ce708f69ed7878422a6a6371e44faed6857cb79a Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 4 Sep 2022 20:22:35 -0400 Subject: Fix AO Host --- webAO/packets/handlers/handleASS.ts | 2 +- webAO/packets/handlers/handleBN.ts | 4 +++- webAO/packets/handlers/handleEI.ts | 3 ++- webAO/packets/handlers/handleLE.ts | 3 ++- webAO/packets/handlers/handleMC.ts | 3 ++- webAO/packets/handlers/handlePV.ts | 3 ++- webAO/packets/handlers/handleZZ.ts | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleASS.ts b/webAO/packets/handlers/handleASS.ts index d0dfbd5..ea8a0d3 100644 --- a/webAO/packets/handlers/handleASS.ts +++ b/webAO/packets/handlers/handleASS.ts @@ -1,4 +1,4 @@ -import { setAOhost } from "../../client"; +import { setAOhost } from "../../client/aoHost"; /** diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index f7b8447..067130d 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -1,7 +1,9 @@ -import { AO_HOST, client, getIndexFromSelect, updateBackgroundPreview } from "../../client"; +import { client, getIndexFromSelect, updateBackgroundPreview } from "../../client"; +import { AO_HOST } from "../../client/aoHost"; import { safeTags } from "../../encoding"; import tryUrls from "../../utils/tryUrls"; + /** * Handles a background change. * @param {Array} args packet arguments diff --git a/webAO/packets/handlers/handleEI.ts b/webAO/packets/handlers/handleEI.ts index e96f0c9..c74e4d4 100644 --- a/webAO/packets/handlers/handleEI.ts +++ b/webAO/packets/handlers/handleEI.ts @@ -1,4 +1,5 @@ -import { AO_HOST, client } from '../../client' +import { client } from '../../client' +import { AO_HOST } from '../../client/aoHost'; import { prepChat, safeTags } from '../../encoding'; /** diff --git a/webAO/packets/handlers/handleLE.ts b/webAO/packets/handlers/handleLE.ts index 28f0b40..1eaeb27 100644 --- a/webAO/packets/handlers/handleLE.ts +++ b/webAO/packets/handlers/handleLE.ts @@ -1,4 +1,5 @@ -import { AO_HOST, client } from '../../client' +import { client } from '../../client' +import { AO_HOST } from '../../client/aoHost'; import { prepChat, safeTags } from '../../encoding'; /** diff --git a/webAO/packets/handlers/handleMC.ts b/webAO/packets/handlers/handleMC.ts index 28254ba..bf60eb9 100644 --- a/webAO/packets/handlers/handleMC.ts +++ b/webAO/packets/handlers/handleMC.ts @@ -1,5 +1,6 @@ import { prepChat } from "../../encoding"; -import { AO_HOST, appendICLog, client } from '../../client' +import { appendICLog, client } from '../../client' +import { AO_HOST } from "../../client/aoHost"; /** * Handles a music change to an arbitrary resource. diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index 5bdb702..fba2a3c 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -1,6 +1,7 @@ -import { AO_HOST, client, pickEmotion } from "../../client"; +import { client, pickEmotion } from "../../client"; import fileExists from "../../utils/fileExists"; import { updateActionCommands } from '../../dom/updateActionCommands' +import { AO_HOST } from "../../client/aoHost"; /** * Handles the server's assignment of a character for the player to use. diff --git a/webAO/packets/handlers/handleZZ.ts b/webAO/packets/handlers/handleZZ.ts index 1a56e49..1c1cb1d 100644 --- a/webAO/packets/handlers/handleZZ.ts +++ b/webAO/packets/handlers/handleZZ.ts @@ -1,4 +1,5 @@ -import { AO_HOST, client } from "../../client"; +import { client } from "../../client"; +import { AO_HOST } from "../../client/aoHost"; import { prepChat } from "../../encoding"; -- cgit From ccec95a9d3b68e25e24a9168400fc47099a85c81 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 6 Sep 2022 21:55:10 -0400 Subject: More window functions --- webAO/packets/handlers/handleBN.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index 067130d..94029b3 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -1,6 +1,7 @@ -import { client, getIndexFromSelect, updateBackgroundPreview } from "../../client"; +import { client, getIndexFromSelect } from "../../client"; import { AO_HOST } from "../../client/aoHost"; import { safeTags } from "../../encoding"; +import { updateBackgroundPreview } from '../../dom/updateBackgroundPreview' import tryUrls from "../../utils/tryUrls"; -- cgit From 3f8d0974b327e663328bc36cd97f1ba1855a2269 Mon Sep 17 00:00:00 2001 From: Caleb Date: Wed, 7 Sep 2022 17:01:25 -0400 Subject: Added more functions --- webAO/packets/handlers/handleBN.ts | 3 ++- webAO/packets/handlers/handlePV.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index 94029b3..3c5d95f 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -1,7 +1,8 @@ -import { client, getIndexFromSelect } from "../../client"; +import { client } from "../../client"; import { AO_HOST } from "../../client/aoHost"; import { safeTags } from "../../encoding"; import { updateBackgroundPreview } from '../../dom/updateBackgroundPreview' +import { getIndexFromSelect } from '../../dom/getIndexFromSelect' import tryUrls from "../../utils/tryUrls"; diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index fba2a3c..3c669b9 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -1,6 +1,7 @@ -import { client, pickEmotion } from "../../client"; +import { client } from "../../client"; import fileExists from "../../utils/fileExists"; import { updateActionCommands } from '../../dom/updateActionCommands' +import { pickEmotion } from '../../dom/pickEmotion' import { AO_HOST } from "../../client/aoHost"; /** -- cgit From 9b8f8c3f5310b6af15edf8ff933e2d63e05707a7 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 8 Sep 2022 12:13:14 -0400 Subject: Add Sender support --- webAO/packets/handlers/handleCC.ts | 2 +- webAO/packets/handlers/handleCI.ts | 2 +- webAO/packets/handlers/handleEI.ts | 2 +- webAO/packets/handlers/handleEM.ts | 2 +- webAO/packets/handlers/handleHI.ts | 4 ++-- webAO/packets/handlers/handleID.ts | 2 +- webAO/packets/handlers/handlePN.ts | 2 +- webAO/packets/handlers/handleRC.ts | 2 +- webAO/packets/handlers/handleRD.ts | 4 ++-- webAO/packets/handlers/handleRM.ts | 2 +- webAO/packets/handlers/handleSC.ts | 2 +- webAO/packets/handlers/handleSI.ts | 4 ++-- webAO/packets/handlers/handleSM.ts | 2 +- webAO/packets/handlers/handleaskchaa.ts | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleCC.ts b/webAO/packets/handlers/handleCC.ts index 84e6ec0..36bcdc7 100644 --- a/webAO/packets/handlers/handleCC.ts +++ b/webAO/packets/handlers/handleCC.ts @@ -5,5 +5,5 @@ import { client } from "../../client"; * @param {Array} args packet arguments */ export const handleCC = (args: string[]) => { - client.sendSelf(`PV#1#CID#${args[2]}#%`); + client.sender.sendSelf(`PV#1#CID#${args[2]}#%`); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleCI.ts b/webAO/packets/handlers/handleCI.ts index 74d3039..53e42f7 100644 --- a/webAO/packets/handlers/handleCI.ts +++ b/webAO/packets/handlers/handleCI.ts @@ -22,5 +22,5 @@ export const handleCI = (args: string[]) => { } } // Request the next pack - client.sendServer(`AN#${Number(args[1]) / 10 + 1}#%`); + client.sender.sendServer(`AN#${Number(args[1]) / 10 + 1}#%`); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleEI.ts b/webAO/packets/handlers/handleEI.ts index c74e4d4..428baf1 100644 --- a/webAO/packets/handlers/handleEI.ts +++ b/webAO/packets/handlers/handleEI.ts @@ -26,5 +26,5 @@ export const handleEI = (args: string[]) => { icon: `${AO_HOST}evidence/${encodeURI(arg[3].toLowerCase())}`, }; - client.sendServer("AE" + (evidenceID + 1) + "#%"); + client.sender.sendServer("AE" + (evidenceID + 1) + "#%"); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleEM.ts b/webAO/packets/handlers/handleEM.ts index 973d2af..9f3cb87 100644 --- a/webAO/packets/handlers/handleEM.ts +++ b/webAO/packets/handlers/handleEM.ts @@ -35,5 +35,5 @@ export const handleEM = (args: string[]) => { } // get the next batch of tracks - client.sendServer(`AM#${Number(args[1]) / 10 + 1}#%`); + client.sender.sendServer(`AM#${Number(args[1]) / 10 + 1}#%`); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleHI.ts b/webAO/packets/handlers/handleHI.ts index d15be0d..b4f00a8 100644 --- a/webAO/packets/handlers/handleHI.ts +++ b/webAO/packets/handlers/handleHI.ts @@ -7,8 +7,8 @@ const version = process.env.npm_package_version; * @param {Array} args packet arguments */ export const handleHI = (_args: string[]) => { - client.sendSelf(`ID#1#webAO#${version}#%`); - client.sendSelf( + client.sender.sendSelf(`ID#1#webAO#${version}#%`); + client.sender.sendSelf( "FL#fastloading#yellowtext#cccc_ic_support#flipping#looping_sfx#effects#%" ); } diff --git a/webAO/packets/handlers/handleID.ts b/webAO/packets/handlers/handleID.ts index 7def483..cd7b6ed 100644 --- a/webAO/packets/handlers/handleID.ts +++ b/webAO/packets/handlers/handleID.ts @@ -13,7 +13,7 @@ export const handleID = (args: string[]) => { serverVersion = args[2].split("&")[1]; } else if (serverSoftware === "webAO") { setOldLoading(false); - client.sendSelf("PN#0#1#%"); + client.sender.sendSelf("PN#0#1#%"); } else { serverVersion = args[3]; } diff --git a/webAO/packets/handlers/handlePN.ts b/webAO/packets/handlers/handlePN.ts index b16f77d..1b66fb9 100644 --- a/webAO/packets/handlers/handlePN.ts +++ b/webAO/packets/handlers/handlePN.ts @@ -5,5 +5,5 @@ import { client } from "../../client"; * @param {Array} args packet arguments */ export const handlePN = (_args: string[]) => { - client.sendServer("askchaa#%"); + client.sender.sendServer("askchaa#%"); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleRC.ts b/webAO/packets/handlers/handleRC.ts index 92c1e8e..0b5679f 100644 --- a/webAO/packets/handlers/handleRC.ts +++ b/webAO/packets/handlers/handleRC.ts @@ -6,5 +6,5 @@ import vanilla_character_arr from "../../constants/characters.js"; * @param {Array} args packet arguments */ export const handleRC = (_args: string[]) => { - client.sendSelf(`SC#${vanilla_character_arr.join("#")}#%`); + client.sender.sendSelf(`SC#${vanilla_character_arr.join("#")}#%`); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleRD.ts b/webAO/packets/handlers/handleRD.ts index 780b43f..dde994c 100644 --- a/webAO/packets/handlers/handleRD.ts +++ b/webAO/packets/handlers/handleRD.ts @@ -6,8 +6,8 @@ import { client } from "../../client"; * @param {Array} args packet arguments */ export const handleRD = (_args: string[]) => { - client.sendSelf("BN#gs4#%"); - client.sendSelf("DONE#%"); + client.sender.sendSelf("BN#gs4#%"); + client.sender.sendSelf("DONE#%"); const ooclog = document.getElementById("client_ooclog"); ooclog.value = ""; ooclog.readOnly = false; diff --git a/webAO/packets/handlers/handleRM.ts b/webAO/packets/handlers/handleRM.ts index 41a78b4..c18821b 100644 --- a/webAO/packets/handlers/handleRM.ts +++ b/webAO/packets/handlers/handleRM.ts @@ -6,5 +6,5 @@ import vanilla_music_arr from "../../constants/music.js"; * @param {Array} args packet arguments */ export const handleRM = (_args: string[]) => { - client.sendSelf(`SM#${vanilla_music_arr.join("#")}#%`); + client.sender.sendSelf(`SM#${vanilla_music_arr.join("#")}#%`); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleSC.ts b/webAO/packets/handlers/handleSC.ts index 3689a17..f4953e0 100644 --- a/webAO/packets/handlers/handleSC.ts +++ b/webAO/packets/handlers/handleSC.ts @@ -33,5 +33,5 @@ export const handleSC = async (args: string[]) => { client.handleCharacterInfo(chargs, charid); } // We're done with the characters, request the music - client.sendServer("RM#%"); + client.sender.sendServer("RM#%"); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleSI.ts b/webAO/packets/handlers/handleSI.ts index e040c83..b32fbc1 100644 --- a/webAO/packets/handlers/handleSI.ts +++ b/webAO/packets/handlers/handleSI.ts @@ -34,8 +34,8 @@ export const handleSI = (args: string[]) => { // this is determined at the top of this file if (!oldLoading && extrafeatures.includes("fastloading")) { - client.sendServer("RC#%"); + client.sender.sendServer("RC#%"); } else { - client.sendServer("askchar2#%"); + client.sender.sendServer("askchar2#%"); } } \ No newline at end of file diff --git a/webAO/packets/handlers/handleSM.ts b/webAO/packets/handlers/handleSM.ts index 5dab83e..48f9cd9 100644 --- a/webAO/packets/handlers/handleSM.ts +++ b/webAO/packets/handlers/handleSM.ts @@ -32,5 +32,5 @@ export const handleSM = (args: string[]) => { } // Music done, carry on - client.sendServer("RD#%"); + client.sender.sendServer("RD#%"); } diff --git a/webAO/packets/handlers/handleaskchaa.ts b/webAO/packets/handlers/handleaskchaa.ts index 5930bf0..0f9e730 100644 --- a/webAO/packets/handlers/handleaskchaa.ts +++ b/webAO/packets/handlers/handleaskchaa.ts @@ -6,5 +6,5 @@ import vanilla_character_arr from "../../constants/characters.js"; * @param {Array} args packet arguments */ export const handleaskchaa = (_args: string[]) => { - client.sendSelf(`SI#${vanilla_character_arr.length}#0#0#%`); + client.sender.sendSelf(`SI#${vanilla_character_arr.length}#0#0#%`); } -- cgit From 93979636fb5d1c60f0da3290e80eb3ca9ead992f Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 9 Sep 2022 18:46:42 -0400 Subject: Migrated functions --- webAO/packets/handlers/handleBD.ts | 5 +- webAO/packets/handlers/handleCI.ts | 3 +- webAO/packets/handlers/handleEM.ts | 14 ++- webAO/packets/handlers/handleFA.ts | 3 +- webAO/packets/handlers/handleFM.ts | 4 +- webAO/packets/handlers/handleKB.ts | 5 +- webAO/packets/handlers/handleKK.ts | 5 +- webAO/packets/handlers/handleMC.ts | 3 +- webAO/packets/handlers/handleMS.ts | 226 +++++++++++++++++----------------- webAO/packets/handlers/handleSC.ts | 3 +- webAO/packets/handlers/handleSM.ts | 15 ++- webAO/packets/handlers/handleackMS.ts | 2 +- 12 files changed, 152 insertions(+), 136 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleBD.ts b/webAO/packets/handlers/handleBD.ts index 4ec291e..dbfb54b 100644 --- a/webAO/packets/handlers/handleBD.ts +++ b/webAO/packets/handlers/handleBD.ts @@ -1,5 +1,6 @@ -import { client, setBanned } from "../../client"; +import { setBanned } from "../../client"; import { safeTags } from "../../encoding"; +import { handleBans } from '../../client/handleBans' /** @@ -8,6 +9,6 @@ import { safeTags } from "../../encoding"; * @param {Array} args ban reason */ export const handleBD = (args: string[]) => { - client.handleBans("Banned", safeTags(args[1])); + handleBans("Banned", safeTags(args[1])); setBanned(true); } \ No newline at end of file diff --git a/webAO/packets/handlers/handleCI.ts b/webAO/packets/handlers/handleCI.ts index 53e42f7..cb693bc 100644 --- a/webAO/packets/handlers/handleCI.ts +++ b/webAO/packets/handlers/handleCI.ts @@ -1,4 +1,5 @@ import { client } from '../../client' +import { handleCharacterInfo } from '../../client/handleCharacterInfo' /** * Handles incoming character information, bundling multiple characters * per packet. @@ -18,7 +19,7 @@ export const handleCI = (args: string[]) => { (( document.getElementById("client_loadingbar") )).value = charid; - setTimeout(() => client.handleCharacterInfo(chargs, charid), 500); + setTimeout(() => handleCharacterInfo(chargs, charid), 500); } } // Request the next pack diff --git a/webAO/packets/handlers/handleEM.ts b/webAO/packets/handlers/handleEM.ts index 9f3cb87..5e49ea4 100644 --- a/webAO/packets/handlers/handleEM.ts +++ b/webAO/packets/handlers/handleEM.ts @@ -1,4 +1,8 @@ import { client } from '../../client' +import { addTrack } from '../../client/addTrack'; +import { createArea } from '../../client/createArea'; +import { fix_last_area } from '../../client/fixLastArea'; +import { isAudio } from '../../client/isAudio'; import { safeTags } from '../../encoding'; /** @@ -23,13 +27,13 @@ export const handleEM = (args: string[]) => { )).value = client.char_list_length + client.evidence_list_length + trackindex; if (client.musics_time) { - client.addTrack(trackname); - } else if (client.isAudio(trackname)) { + addTrack(trackname); + } else if (isAudio(trackname)) { client.musics_time = true; - client.fix_last_area(); - client.addTrack(trackname); + fix_last_area(); + addTrack(trackname); } else { - client.createArea(trackindex, trackname); + createArea(trackindex, trackname); } } } diff --git a/webAO/packets/handlers/handleFA.ts b/webAO/packets/handlers/handleFA.ts index ccfe923..7a373e8 100644 --- a/webAO/packets/handlers/handleFA.ts +++ b/webAO/packets/handlers/handleFA.ts @@ -1,4 +1,5 @@ import { client } from '../../client' +import { createArea } from '../../client/createArea'; import { safeTags } from '../../encoding'; /** @@ -9,6 +10,6 @@ export const handleFA = (args: string[]) => { client.resetAreaList(); for (let i = 1; i < args.length - 1; i++) { - client.createArea(i - 1, safeTags(args[i])); + createArea(i - 1, safeTags(args[i])); } } diff --git a/webAO/packets/handlers/handleFM.ts b/webAO/packets/handlers/handleFM.ts index 630477b..fce10e3 100644 --- a/webAO/packets/handlers/handleFM.ts +++ b/webAO/packets/handlers/handleFM.ts @@ -1,7 +1,7 @@ import { client } from "../../client"; +import { addTrack } from "../../client/addTrack"; import { safeTags } from "../../encoding"; - /** * Handles updated music list * @param {Array} args packet arguments @@ -11,6 +11,6 @@ export const handleFM = (args: string[]) => { for (let i = 1; i < args.length - 1; i++) { // Check when found the song for the first time - client.addTrack(safeTags(args[i])); + addTrack(safeTags(args[i])); } } diff --git a/webAO/packets/handlers/handleKB.ts b/webAO/packets/handlers/handleKB.ts index 8705b83..b0aa2b2 100644 --- a/webAO/packets/handlers/handleKB.ts +++ b/webAO/packets/handlers/handleKB.ts @@ -1,5 +1,6 @@ -import { client, setBanned } from "../../client"; +import { setBanned } from "../../client"; import { safeTags } from "../../encoding"; +import { handleBans } from '../../client/handleBans' /** * Handles the banned packet @@ -7,6 +8,6 @@ import { safeTags } from "../../encoding"; * @param {Array} args ban reason */ export const handleKB = (args: string[]) => { - client.handleBans("Banned", safeTags(args[1])); + handleBans("Banned", safeTags(args[1])); setBanned(true); } diff --git a/webAO/packets/handlers/handleKK.ts b/webAO/packets/handlers/handleKK.ts index fd9a88c..c8a97b1 100644 --- a/webAO/packets/handlers/handleKK.ts +++ b/webAO/packets/handlers/handleKK.ts @@ -1,11 +1,10 @@ -import { client } from "../../client"; import { safeTags } from "../../encoding"; - +import { handleBans } from '../../client/handleBans' /** * Handles the kicked packet * @param {Array} args kick reason */ export const handleKK = (args: string[]) => { - client.handleBans("Kicked", safeTags(args[1])); + handleBans("Kicked", safeTags(args[1])); } diff --git a/webAO/packets/handlers/handleMC.ts b/webAO/packets/handlers/handleMC.ts index bf60eb9..aeb178d 100644 --- a/webAO/packets/handlers/handleMC.ts +++ b/webAO/packets/handlers/handleMC.ts @@ -1,6 +1,7 @@ import { prepChat } from "../../encoding"; -import { appendICLog, client } from '../../client' +import { client } from '../../client' import { AO_HOST } from "../../client/aoHost"; +import { appendICLog } from '../../client/appendICLog' /** * Handles a music change to an arbitrary resource. diff --git a/webAO/packets/handlers/handleMS.ts b/webAO/packets/handlers/handleMS.ts index 0aad19a..1256900 100644 --- a/webAO/packets/handlers/handleMS.ts +++ b/webAO/packets/handlers/handleMS.ts @@ -1,4 +1,6 @@ -import { client, extrafeatures, resetICParams, UPDATE_INTERVAL } from "../../client"; +import { client, extrafeatures, UPDATE_INTERVAL } from "../../client"; +import { handleCharacterInfo } from "../../client/handleCharacterInfo"; +import { resetICParams } from "../../client/resetICParams"; import { prepChat, safeTags } from "../../encoding"; /** @@ -6,119 +8,104 @@ import { prepChat, safeTags } from "../../encoding"; * @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 = ""; + // 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]); + 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; + 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) { + 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); - } + handleCharacterInfo(chargs, char_id); } + } - try { - msg_nameplate = client.chars[char_id].showname; - } catch (e) { - msg_nameplate = args[3]; - } + 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 { + msg_blips = client.chars[char_id].blips; + } catch (e) { } - try { - char_chatbox = client.chars[char_id].chat; - } catch (e) { - char_chatbox = "default"; - } + 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"); - } + 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 (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(""), // HACK: here as well, client is fucked and uses this instead of & + other_offset: args[21].split(""), + other_flip: Number(args[22]), + noninterrupting_preanim: Number(args[23]), }; + chatmsg = Object.assign(extra_cccc, chatmsg); - 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(""), // HACK: here as well, client is fucked and uses this instead of & - other_offset: args[21].split(""), - other_flip: Number(args[22]), - noninterrupting_preanim: Number(args[23]), + 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_cccc, chatmsg); + chatmsg = Object.assign(extra_27, 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]), + if (extrafeatures.includes("effects")) { + const extra_28 = { + additive: Number(args[29]), + effects: args[30].split("|"), }; - 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); - } + 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: ["", "", ""], @@ -126,17 +113,6 @@ export const handleMS = (args: string[]) => { 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, @@ -151,12 +127,38 @@ export const handleMS = (args: string[]) => { }; 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 + // 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 + } +} \ No newline at end of file diff --git a/webAO/packets/handlers/handleSC.ts b/webAO/packets/handlers/handleSC.ts index f4953e0..b42a4cd 100644 --- a/webAO/packets/handlers/handleSC.ts +++ b/webAO/packets/handlers/handleSC.ts @@ -1,6 +1,7 @@ import queryParser from "../../utils/queryParser"; import { client } from '../../client' +import { handleCharacterInfo } from "../../client/handleCharacterInfo"; let { mode } = queryParser(); /** @@ -30,7 +31,7 @@ export const handleSC = async (args: string[]) => { document.getElementById("client_loadingbar") )).value = charid; await sleep(0.1); // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES - client.handleCharacterInfo(chargs, charid); + handleCharacterInfo(chargs, charid); } // We're done with the characters, request the music client.sender.sendServer("RM#%"); diff --git a/webAO/packets/handlers/handleSM.ts b/webAO/packets/handlers/handleSM.ts index 48f9cd9..08bf7e0 100644 --- a/webAO/packets/handlers/handleSM.ts +++ b/webAO/packets/handlers/handleSM.ts @@ -1,4 +1,8 @@ import { client } from '../../client' +import { addTrack } from '../../client/addTrack' +import { isAudio } from '../../client/isAudio' +import { fix_last_area } from '../../client/fixLastArea' +import { createArea } from '../../client/createArea' /** * Handles incoming music information, containing all music in one packet. * @param {Array} args packet arguments @@ -21,14 +25,15 @@ export const handleSM = (args: string[]) => { document.getElementById("client_loadingbar") )).value = client.char_list_length + client.evidence_list_length + i; if (client.musics_time) { - client.addTrack(trackname); - } else if (client.isAudio(trackname)) { + addTrack(trackname); + } else if (isAudio(trackname)) { client.musics_time = true; - client.fix_last_area(); - client.addTrack(trackname); + fix_last_area(); + addTrack(trackname); } else { - client.createArea(trackindex, trackname); + createArea(trackindex, trackname); } + } // Music done, carry on diff --git a/webAO/packets/handlers/handleackMS.ts b/webAO/packets/handlers/handleackMS.ts index 2b971b0..dcca118 100644 --- a/webAO/packets/handlers/handleackMS.ts +++ b/webAO/packets/handlers/handleackMS.ts @@ -1,4 +1,4 @@ -import { resetICParams } from "../../client"; +import { resetICParams } from '../../client/resetICParams' /** * server got our message -- cgit From 383991dd82af6bd867ef29af37fb694d64c28450 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 11 Sep 2022 15:42:52 -0400 Subject: Typechecking changed --- webAO/packets/handlers/handleMS.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleMS.ts b/webAO/packets/handlers/handleMS.ts index 1256900..22bbab6 100644 --- a/webAO/packets/handlers/handleMS.ts +++ b/webAO/packets/handlers/handleMS.ts @@ -2,7 +2,7 @@ import { client, extrafeatures, UPDATE_INTERVAL } from "../../client"; import { handleCharacterInfo } from "../../client/handleCharacterInfo"; import { resetICParams } from "../../client/resetICParams"; import { prepChat, safeTags } from "../../encoding"; - +import { handle_ic_speaking } from '../../viewport/utils/handleICSpeaking' /** * Handles an in-character chat message. * @param {*} args packet arguments @@ -55,7 +55,7 @@ export const handleMS = (args: string[]) => { if (char_muted === false) { let chatmsg = { - deskmod: safeTags(args[1]).toLowerCase(), + deskmod: Number(safeTags(args[1]).toLowerCase()), preanim: safeTags(args[2]).toLowerCase(), // get preanim nameplate: msg_nameplate, chatbox: char_chatbox, @@ -69,7 +69,7 @@ export const handleMS = (args: string[]) => { charid: char_id, snddelay: Number(args[10]), objection: Number(args[11]), - evidence: safeTags(args[12]), + evidence: Number(safeTags(args[12])), flip: Number(args[13]), flash: Number(args[14]), color: Number(args[15]), @@ -158,7 +158,8 @@ export const handleMS = (args: string[]) => { if (chatmsg.charid === client.charID) { resetICParams(); } - client.viewport.handle_ic_speaking(chatmsg); // no await + + handle_ic_speaking(chatmsg); // no await } } } \ No newline at end of file -- cgit From b3229eb72ba04152f1df97cd3800e1bc17c5646c Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 11 Sep 2022 15:43:05 -0400 Subject: Function movement --- webAO/packets/handlers/handleRT.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleRT.ts b/webAO/packets/handlers/handleRT.ts index 5bbf2b2..62ebb1e 100644 --- a/webAO/packets/handlers/handleRT.ts +++ b/webAO/packets/handlers/handleRT.ts @@ -1,5 +1,5 @@ import { client } from "../../client"; - +import { initTestimonyUpdater } from '../../viewport/utils/initTestimonyUpdater' /** * Handles a testimony states. @@ -21,5 +21,5 @@ export const handleRT = (args: string[]) => { default: console.warn("Invalid testimony"); } - client.viewport.initTestimonyUpdater(); + initTestimonyUpdater(); } \ No newline at end of file -- cgit From 3bc1d8ca5bc74f40d96c9f4edf7f5b1adee188a4 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 11 Sep 2022 16:26:49 -0400 Subject: Refactor getChatmsg --- webAO/packets/handlers/handleMS.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/packets') diff --git a/webAO/packets/handlers/handleMS.ts b/webAO/packets/handlers/handleMS.ts index 22bbab6..92d65db 100644 --- a/webAO/packets/handlers/handleMS.ts +++ b/webAO/packets/handlers/handleMS.ts @@ -9,7 +9,7 @@ import { handle_ic_speaking } from '../../viewport/utils/handleICSpeaking' */ export const handleMS = (args: string[]) => { // TODO: this if-statement might be a bug. - if (args[4] !== client.viewport.chatmsg.content) { + if (args[4] !== client.viewport.getChatmsg().content) { document.getElementById("client_inner_chat")!.innerHTML = ""; const char_id = Number(args[9]); -- cgit