From b1591208dc9479b1abc04727072849258e7cc729 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 29 Mar 2022 19:24:40 +0200 Subject: encodechat was empty, yeet --- webAO/client.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 8ced37a..993a230 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -8,7 +8,7 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs'; import { EventEmitter } from 'events'; import tryUrls from './utils/tryUrls' import { - escapeChat, encodeChat, prepChat, safeTags, + escapeChat, prepChat, safeTags, } from './encoding'; import mlConfig from './utils/aoml'; // Load some defaults for the background and evidence dropdowns @@ -320,8 +320,8 @@ class Client extends EventEmitter { */ sendOOC(message: string) { setCookie('OOC_name', (document.getElementById('OOC_name')).value); - const oocName = `${escapeChat(encodeChat((document.getElementById('OOC_name')).value))}`; - const oocMessage = `${escapeChat(encodeChat(message))}`; + const oocName = `${escapeChat((document.getElementById('OOC_name')).value)}`; + const oocMessage = `${escapeChat(message)}`; const commands = { '/save_chatlog': this.saveChatlogHandle @@ -400,18 +400,18 @@ class Client extends EventEmitter { other_emote = '##'; other_offset = '#0#0'; } - extra_cccc = `${showname}#${other_charid}${other_emote}#${self_offset}${other_offset}#${Number(noninterrupting_preanim)}#`; + extra_cccc = `${escapeChat(showname)}#${other_charid}${escapeChat(other_emote)}#${self_offset}${other_offset}#${Number(noninterrupting_preanim)}#`; if (extrafeatures.includes('looping_sfx')) { extra_27 = `${Number(looping_sfx)}#${Number(screenshake)}#${frame_screenshake}#${frame_realization}#${frame_sfx}#`; if (extrafeatures.includes('effects')) { - extra_28 = `${Number(additive)}#${effect}#`; + extra_28 = `${Number(additive)}#${escapeChat(effect)}#`; } } } - const serverMessage = `MS#${deskmod}#${preanim}#${name}#${emote}` - + `#${escapeChat(encodeChat(message))}#${side}#${sfx_name}#${emote_modifier}` + const serverMessage = `MS#${escapeChat(deskmod)}#${escapeChat(preanim)}#${escapeChat(name)}#${escapeChat(emote)}` + + `#${escapeChat(message)}#${escapeChat(side)}#${escapeChat(sfx_name)}#${emote_modifier}` + `#${this.charID}#${sfx_delay}#${Number(objection_modifier)}#${Number(evidence)}#${Number(flip)}#${Number(realization)}#${text_color}#${extra_cccc}${extra_27}${extra_28}%`; this.sendServer(serverMessage); @@ -427,7 +427,7 @@ class Client extends EventEmitter { * @param {string} evidence image filename */ sendPE(name: string, desc: string, img: string) { - this.sendServer(`PE#${escapeChat(encodeChat(name))}#${escapeChat(encodeChat(desc))}#${img}#%`); + this.sendServer(`PE#${escapeChat(name)}#${escapeChat(desc)}#${img}#%`); } /** @@ -438,7 +438,7 @@ class Client extends EventEmitter { * @param {string} evidence image filename */ sendEE(id: number, name: string, desc: string, img: string) { - this.sendServer(`EE#${id}#${escapeChat(encodeChat(name))}#${escapeChat(encodeChat(desc))}#${img}#%`); + this.sendServer(`EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${img}#%`); } /** @@ -2571,7 +2571,7 @@ export function onEnter(event: KeyboardEvent) { const noninterrupting_preanim = Boolean(((document.getElementById('check_nonint')).checked)); const looping_sfx = Boolean(((document.getElementById('check_loopsfx')).checked)); const color = Number((document.getElementById('textcolor')).value); - const showname = (document.getElementById('ic_chat_name')).value; + const showname = escapeChat((document.getElementById('ic_chat_name')).value); const text = (document.getElementById('client_inputbox')).value; const pairchar = (document.getElementById('pair_select')).value; const pairoffset = Number((document.getElementById('pair_offset')).value); -- cgit From ef11d76ef5300d921711228fa64afebf8f9a3131 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 5 Apr 2022 23:26:38 +0200 Subject: uncheck sfx after sending one --- webAO/client.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 993a230..a993266 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2637,6 +2637,7 @@ function resetICParams() { document.getElementById('button_shake').className = 'client_button'; (document.getElementById('sendpreanim')).checked = false; + (document.getElementById('sendsfx')).checked = false; if (selectedShout) { document.getElementById(`button_${selectedShout}`).className = 'client_button'; -- cgit From 9a175fa1ea4a2acaf109fcdd532f4663e8b594e5 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 6 Apr 2022 22:17:15 +0200 Subject: this is not supposed to be escaped --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index a993266..94083f1 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -400,7 +400,7 @@ class Client extends EventEmitter { other_emote = '##'; other_offset = '#0#0'; } - extra_cccc = `${escapeChat(showname)}#${other_charid}${escapeChat(other_emote)}#${self_offset}${other_offset}#${Number(noninterrupting_preanim)}#`; + extra_cccc = `${escapeChat(showname)}#${other_charid}${other_emote}#${self_offset}${other_offset}#${Number(noninterrupting_preanim)}#`; if (extrafeatures.includes('looping_sfx')) { extra_27 = `${Number(looping_sfx)}#${Number(screenshake)}#${frame_screenshake}#${frame_realization}#${frame_sfx}#`; -- cgit From 3e27e18149f9b89122edb639d9c00c78d270e4cd Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 6 Apr 2022 23:01:53 +0200 Subject: fix pantilt enabling on old bgs --- webAO/client.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 94083f1..10cafcd 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2796,19 +2796,23 @@ window.iniedit = iniedit; /** * Triggered by the pantilt checkbox */ -export async function switchPanTilt(addcheck: number) { - const background = document.getElementById('client_fullview'); - if (addcheck === 1) { - (document.getElementById('client_pantilt')).checked = true; - document.getElementById('client_court').style.display = ''; - } else if (addcheck === 2) { - (document.getElementById('client_pantilt')).checked = false; - document.getElementById('client_court').style.display = 'none'; - } - if ((document.getElementById('client_pantilt')).checked) { - background.style.transition = '0.5s ease-in-out'; +export async function switchPanTilt() { + const fullview = document.getElementById('client_fullview'); + const fullbg = document.getElementById('client_court'); + const checkbox = document.getElementById('client_pantilt'); + + if (fullbg.src = transparentPng) { + checkbox.checked = false; + fullbg.style.display = 'none'; } else { - background.style.transition = 'none'; + checkbox.checked = true; + fullbg.style.display = ''; + } + + if (checkbox.checked) { + fullview.style.transition = '0.5s ease-in-out'; + } else { + fullview.style.transition = 'none'; } } window.switchPanTilt = switchPanTilt; -- cgit From 945dc093c92dda971cc1d769c36fd6b3eb3a4236 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 6 Apr 2022 23:05:57 +0200 Subject: text speed chars were swapped --- webAO/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 10cafcd..d1a11a3 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2332,11 +2332,11 @@ class Viewport { const MAX_SLOW_CHATSPEED = 120 for(let i = this.textnow.length; i < this.chatmsg.content.length; i++) { const currentCharacter = this.chatmsg.parsed[i - 1].innerHTML - if (currentCharacter === '{') { + if (currentCharacter === '}') { if (this.chatmsg.speed > 0) { this.chatmsg.speed -= 20 } - } else if(currentCharacter === '}') { + } else if(currentCharacter === '{') { if(this.chatmsg.speed < MAX_SLOW_CHATSPEED) { this.chatmsg.speed += 20 } -- cgit From da5851d4ce782c60c24ff96006fb44d5ea6c6f79 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 9 Apr 2022 13:16:04 +0200 Subject: define demo at the beginning --- webAO/client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index d1a11a3..7df9133 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -911,9 +911,9 @@ class Client extends EventEmitter { * @param {Number} charid character ID */ async handleCharacterInfo(chargs: string[], charid: number) { + const img = document.getElementById(`demo_${charid}`); if (chargs[0]) { let cini: any = {}; - const img = document.getElementById(`demo_${charid}`); const getCharIcon = async () => { const extensions = [ '.png', @@ -986,7 +986,6 @@ class Client extends EventEmitter { iniedit_select.add(new Option(safeTags(chargs[0]))); } else { console.warn(`missing charid ${charid}`); - const img = document.getElementById(`demo_${charid}`); img.style.display = 'none'; } } -- cgit From 51c3567bb40016c3910d0c955cafe05ceb9c62d1 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 4 May 2022 19:32:00 +0200 Subject: do NOT reload the page --- webAO/client.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 7df9133..bcb3e35 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2622,6 +2622,7 @@ export function onEnter(event: KeyboardEvent) { effect, ); } + return false; } window.onEnter = onEnter; -- cgit From c01f37ef8e5f5472af9022445eee611706836963 Mon Sep 17 00:00:00 2001 From: AwesomeAim <30537683+AwesomeAim@users.noreply.github.com> Date: Tue, 10 May 2022 04:58:15 -0700 Subject: Reveal the textbox after the preanimation There may be a better fix since I really am unfamiliar with this language and codebase, but this fixed it well enough. --- webAO/client.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index bcb3e35..bd2407f 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2517,6 +2517,8 @@ class Viewport { return } } else if (this.textnow !== this.chatmsg.content) { + const chatContainerBox = document.getElementById('client_chatcontainer'); + chatContainerBox.style.opacity = '1'; await this.handleTextTick(charLayers) } } -- cgit From 611fa88bdba12a880cea62678da8b3addffcd462 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 14 May 2022 16:40:44 +0200 Subject: escape evidence image --- webAO/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index bd2407f..12b4197 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -427,7 +427,7 @@ class Client extends EventEmitter { * @param {string} evidence image filename */ sendPE(name: string, desc: string, img: string) { - this.sendServer(`PE#${escapeChat(name)}#${escapeChat(desc)}#${img}#%`); + this.sendServer(`PE#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%`); } /** @@ -438,7 +438,7 @@ class Client extends EventEmitter { * @param {string} evidence image filename */ sendEE(id: number, name: string, desc: string, img: string) { - this.sendServer(`EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${img}#%`); + this.sendServer(`EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%`); } /** -- cgit From 60cbb85ade595eed6e55430a8120c2d723a29f73 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 22 May 2022 12:58:21 +0200 Subject: fix female blips --- webAO/client.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 12b4197..e9c413f 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -706,21 +706,33 @@ class Client extends EventEmitter { let char_chatbox = 'default'; let char_muted = false; + if (this.chars[char_id].name !== char_name) { + console.info(`${this.chars[char_id].name} is iniediting to ${char_name}`); + const chargs = (`${char_name}&` + 'iniediter').split('&'); + this.handleCharacterInfo(chargs, char_id); + } + + try { + msg_nameplate = this.chars[char_id].showname; + } catch (e) { + msg_nameplate = args[3]; + } + try { - msg_nameplate = this.chars[char_id].showname; msg_blips = this.chars[char_id].blips; - char_chatbox = this.chars[char_id].chat; - char_muted = this.chars[char_id].muted; + } catch (e) { + ; + } - if (this.chars[char_id].name !== char_name) { - console.info(`${this.chars[char_id].name} is iniediting to ${char_name}`); - const chargs = (`${char_name}&` + 'iniediter').split('&'); - this.handleCharacterInfo(chargs, char_id); - } + try { + char_chatbox = this.chars[char_id].chat; } catch (e) { - msg_nameplate = args[3]; - msg_blips = 'male'; char_chatbox = 'default'; + } + + try { + char_muted = this.chars[char_id].muted; + } catch (e) { char_muted = false; console.error("we're still missing some character data"); } @@ -980,7 +992,7 @@ class Client extends EventEmitter { muted: false, }; - if (this.chars[charid].blips === '') { this.chars[charid].blips = this.chars[charid].gender; } + if (this.chars[charid].blips === 'male' && this.chars[charid].gender !== 'male' && this.chars[charid].gender !== '') { this.chars[charid].blips = this.chars[charid].gender; } const iniedit_select = document.getElementById('client_ininame'); iniedit_select.add(new Option(safeTags(chargs[0]))); -- cgit From e1cf45fa8ace00ef400235e09aca418d5094fc57 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 22 May 2022 13:17:28 +0200 Subject: reversed logic with chatboxes --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index e9c413f..9821ba0 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -985,7 +985,7 @@ class Client extends EventEmitter { blips: safeTags(cini.options.blips).toLowerCase(), gender: safeTags(cini.options.gender).toLowerCase(), side: safeTags(cini.options.side).toLowerCase(), - chat: (cini.options.chat === '') ? safeTags(cini.options.chat).toLowerCase() : safeTags(cini.options.category).toLowerCase(), + chat: (cini.options.chat === '' ) ? safeTags(cini.options.category).toLowerCase() : safeTags(cini.options.chat).toLowerCase(), evidence: chargs[3], icon: img.src, inifile: cini, -- cgit From a9635bb552d327b6e9c092d643d3857c5c8652ba Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 16 Jun 2022 14:21:55 +0200 Subject: send -1 for spectator --- webAO/client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 9821ba0..2163a1d 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -3018,9 +3018,8 @@ export function pickChar(ccharacter: number) { // Spectator document.getElementById('client_waiting').style.display = 'none'; document.getElementById('client_charselect').style.display = 'none'; - } else { - client.sendCharacter(ccharacter); } + client.sendCharacter(ccharacter); } window.pickChar = pickChar; -- cgit From 28aa78ebe7df1f64959d879e7a140ff513fcfa82 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Fri, 17 Jun 2022 18:08:27 +0200 Subject: close connection on cleanup --- webAO/client.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 2163a1d..07a35db 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -634,9 +634,7 @@ class Client extends EventEmitter { cleanup() { clearInterval(this.checkUpdater); - // the connection got rekt, get rid of the old musiclist - this.resetMusicList(); - document.getElementById('client_chartable').innerHTML = ''; + this.serv.close() } /** -- cgit From dfd0adff20c8a27a55d83c188e63fc59dd48a8d9 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Fri, 17 Jun 2022 19:36:18 +0200 Subject: send CC if charid is -1 --- webAO/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 07a35db..c668612 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -555,7 +555,9 @@ class Client extends EventEmitter { * @param {number} character the character ID */ sendCharacter(character: number) { - if (this.chars[character].name) { this.sendServer(`CC#${this.playerID}#${character}#web#%`); } + if (this.chars[character].name || character === -1) { + this.sendServer(`CC#${this.playerID}#${character}#web#%`); + } } /** -- cgit From cbac42d800ebc0696c5e37ed70cf89c444990dfd Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 23 Jun 2022 16:50:58 +0200 Subject: rename say and changeBG to match client --- webAO/client.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index c668612..a739705 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -842,7 +842,7 @@ class Client extends EventEmitter { if (chatmsg.charid === this.charID) { resetICParams(); } - viewport.say(chatmsg); // no await + viewport.handle_ic_speaking(chatmsg); // no await } } } @@ -1410,9 +1410,9 @@ class Client extends EventEmitter { tryUrls(`${bgfolder}prosecutorempty`).then(resp => {(document.getElementById('client_court_pro')).src = resp}); if (this.charID === -1) { - viewport.changeBackground('jud'); + viewport.set_side('jud'); } else { - viewport.changeBackground(this.chars[this.charID].side); + viewport.set_side(this.chars[this.charID].side); } } @@ -1934,7 +1934,7 @@ class Viewport { * Valid positions: `def, pro, hld, hlp, wit, jud, jur, sea` * @param {string} position the position to change into */ - async changeBackground(position: string) { + async set_side(position: string) { const bgfolder = viewport.bgFolder; const view = document.getElementById('client_fullview'); @@ -2135,7 +2135,7 @@ class Viewport { * TODO: the preanim logic, on the other hand, should probably be moved to tick() * @param {object} chatmsg the new chat message */ - async say(chatmsg: any) { + async handle_ic_speaking(chatmsg: any) { this.chatmsg = chatmsg; this.textnow = ''; @@ -2170,7 +2170,7 @@ class Viewport { } this.lastEvi = this.chatmsg.evidence; - const validSides = ['def', 'pro', 'wit']; + const validSides: string[] = ['def', 'pro', 'wit']; // these are for the full view pan, the other positions use 'client_char' if (validSides.includes(this.chatmsg.side)) { charLayers = document.getElementById(`client_${this.chatmsg.side}_char`); pairLayers = document.getElementById(`client_${this.chatmsg.side}_pair_char`); @@ -2226,7 +2226,7 @@ class Viewport { this.chatmsg.startpreanim = true; let gifLength = 0; - if (this.chatmsg.type === 1 && this.chatmsg.preanim !== '-') { + if (this.chatmsg.type === 1 && this.chatmsg.preanim !== '-') { //we have a preanim chatContainerBox.style.opacity = '0'; gifLength = await getAnimLength(`${AO_HOST}characters/${encodeURI(this.chatmsg.name.toLowerCase())}/${encodeURI(this.chatmsg.preanim)}`); this.chatmsg.startspeaking = false; @@ -2236,7 +2236,7 @@ class Viewport { } this.chatmsg.preanimdelay = gifLength; - this.changeBackground(chatmsg.side); + this.set_side(chatmsg.side); setChatbox(chatmsg.chatbox); resizeChatbox(); -- cgit From c4c4299fe5024af9f786ef34be4fa6594b6f4959 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 23 Jun 2022 17:17:17 +0200 Subject: fix blankposting?? --- webAO/client.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index a739705..e1b9dd1 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2288,6 +2288,8 @@ class Viewport { fg.src = transparentPng; } + charLayers.style.opacity = '1'; + const soundChecks = ['0', '1', '', undefined]; if (soundChecks.some((check) => this.chatmsg.sound === check)) { this.chatmsg.sound = this.chatmsg.effects[2]; @@ -2423,7 +2425,8 @@ class Viewport { let charLayers = document.getElementById('client_char'); let pairLayers = document.getElementById('client_pair_char'); - if ('def,pro,wit'.includes(this.chatmsg.side)) { + const validSides: string[] = ['def', 'pro', 'wit']; // these are for the full view pan, the other positions use 'client_char' + if (validSides.includes(this.chatmsg.side)) { charLayers = document.getElementById(`client_${this.chatmsg.side}_char`); pairLayers = document.getElementById(`client_${this.chatmsg.side}_pair_char`); } @@ -2456,7 +2459,6 @@ class Viewport { shoutSprite.style.animation = ''; const preanim = this.chatmsg.preanim.toLowerCase(); setEmote(AO_HOST, this, charName, preanim, '', false, this.chatmsg.side); - charLayers.style.opacity = '1'; } if (this.chatmsg.other_name) { @@ -2471,6 +2473,7 @@ class Viewport { this.chatmsg.startpreanim = false; this.chatmsg.startspeaking = true; } + const hasNonInterruptingPreAnim = this.chatmsg.noninterrupting_preanim === 1 if (this.textnow !== this.chatmsg.content && hasNonInterruptingPreAnim) { const chatContainerBox = document.getElementById('client_chatcontainer'); -- cgit From 601631bd4c0ca01e55e40848f755adc264997a26 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 23 Jun 2022 17:38:24 +0200 Subject: don't show chatbox on blankpost --- webAO/client.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index e1b9dd1..1646ed9 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2232,7 +2232,8 @@ class Viewport { this.chatmsg.startspeaking = false; } else { this.chatmsg.startspeaking = true; - chatContainerBox.style.opacity = '1'; + if(this.chatmsg.content !== "") + chatContainerBox.style.opacity = '1'; } this.chatmsg.preanimdelay = gifLength; @@ -2295,7 +2296,7 @@ class Viewport { this.chatmsg.sound = this.chatmsg.effects[2]; } this.chatmsg.parsed = await attorneyMarkdown.applyMarkdown(chatmsg.content, this.colors[this.chatmsg.color]) - this.tick(); + this.chat_tick(); } async handleTextTick(charLayers: HTMLImageElement) { @@ -2409,7 +2410,10 @@ class Viewport { * * XXX: This relies on a global variable `this.chatmsg`! */ - async tick() { + async chat_tick() { + // note: this is called fairly often + // do not perform heavy operations here + await delay(this.chatmsg.speed) if (this.textnow === this.chatmsg.content) { @@ -2545,7 +2549,7 @@ class Viewport { } } if (this._animating) { - this.tick() + this.chat_tick() } this.tickTimer += UPDATE_INTERVAL; } -- cgit From 3e8704e509f65bb5896e2efa4d49e8aaa5431799 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 23 Jun 2022 18:51:56 +0200 Subject: fix sending spectator --- webAO/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 1646ed9..54084b7 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -293,6 +293,7 @@ class Client extends EventEmitter { * @param {string} message the message to send */ sendServer(message: string) { + //console.log("C: "+message); mode === 'replay' ? this.sendSelf(message) : this.serv.send(message); } @@ -555,7 +556,8 @@ class Client extends EventEmitter { * @param {number} character the character ID */ sendCharacter(character: number) { - if (this.chars[character].name || character === -1) { + console.log("sending "+character); + if (character === -1 || this.chars[character].name) { this.sendServer(`CC#${this.playerID}#${character}#web#%`); } } -- cgit From 9ac75a06cd792074eaf7b3fbf3a1e5c482be60ac Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 12 Jul 2022 15:13:30 +0200 Subject: log preanim length --- webAO/client.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 54084b7..2af1ab9 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2231,6 +2231,7 @@ class Viewport { if (this.chatmsg.type === 1 && this.chatmsg.preanim !== '-') { //we have a preanim chatContainerBox.style.opacity = '0'; gifLength = await getAnimLength(`${AO_HOST}characters/${encodeURI(this.chatmsg.name.toLowerCase())}/${encodeURI(this.chatmsg.preanim)}`); + console.debug("preanim is "+gifLength+" long"); this.chatmsg.startspeaking = false; } else { this.chatmsg.startspeaking = true; -- cgit From a46ccf72cef30eccf4cb3f9cdea9c461bb44f8b2 Mon Sep 17 00:00:00 2001 From: Caleb Mabry Date: Fri, 15 Jul 2022 00:44:10 -0400 Subject: Resolving issue with name display and encoding issue --- webAO/client.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 2af1ab9..99462cd 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -8,7 +8,7 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs'; import { EventEmitter } from 'events'; import tryUrls from './utils/tryUrls' import { - escapeChat, prepChat, safeTags, + escapeChat, prepChat, safeTags, unescapeChat, } from './encoding'; import mlConfig from './utils/aoml'; // Load some defaults for the background and evidence dropdowns @@ -30,6 +30,7 @@ import getAnimLength from './utils/getAnimLength.js'; import getResources from './utils/getResources.js'; import transparentPng from './constants/transparentPng'; import downloadFile from './services/downloadFile' +import { getFilenameFromPath } from './utils/paths'; const version = process.env.npm_package_version; let client: Client; @@ -1180,7 +1181,9 @@ class Client extends EventEmitter { addTrack(trackname: string) { const newentry = document.createElement('OPTION'); - newentry.text = trackname; + const songName = getFilenameFromPath(trackname); + newentry.text = unescapeChat(songName); + newentry.value = trackname; (document.getElementById('client_musiclist')).options.add(newentry); this.musics.push(trackname); } @@ -1271,7 +1274,7 @@ class Client extends EventEmitter { for (let i = 1; i < args.length - 1; i++) { // Check when found the song for the first time - const trackname = safeTags(args[i]); + const trackname = args[i]; const trackindex = i - 1; document.getElementById('client_loadingtext').innerHTML = `Loading Music ${i}/${this.music_list_length}`; (document.getElementById('client_loadingbar')).value = this.char_list_length + this.evidence_list_length + i; -- cgit From b7ddd8990bdd8561e25a9114c389530c4f18b877 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 13:34:41 +0200 Subject: handle deskmod --- webAO/client.ts | 70 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 16 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 2af1ab9..407d09d 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -1412,9 +1412,9 @@ class Client extends EventEmitter { tryUrls(`${bgfolder}prosecutorempty`).then(resp => {(document.getElementById('client_court_pro')).src = resp}); if (this.charID === -1) { - viewport.set_side('jud'); + viewport.set_side('jud',false,true); } else { - viewport.set_side(this.chars[this.charID].side); + viewport.set_side(this.chars[this.charID].side,false,true); } } @@ -1936,7 +1936,7 @@ class Viewport { * Valid positions: `def, pro, hld, hlp, wit, jud, jur, sea` * @param {string} position the position to change into */ - async set_side(position: string) { + async set_side(position: string, showspeedlines: boolean, showdesk: boolean) { const bgfolder = viewport.bgFolder; const view = document.getElementById('client_fullview'); @@ -2026,21 +2026,18 @@ class Viewport { speedLines = 'defense_speedlines.gif'; } - if (viewport.chatmsg.type === 5) { - console.warn('this is a zoom'); + if (showspeedlines) { court.src = `${AO_HOST}themes/default/${encodeURI(speedLines)}`; - bench.style.opacity = '0'; } else { - // Set src here - court.src = await tryUrls(bgfolder + bg) - if (desk) { - const deskFilename = await fileExists(bgfolder + desk.ao2) ? desk.ao2 : desk.ao1; - bench.src = bgfolder + deskFilename; - bench.style.opacity = '1'; - } else { - bench.style.opacity = '0'; - } + } + + if (showdesk && desk) { + const deskFilename = await fileExists(bgfolder + desk.ao2) ? desk.ao2 : desk.ao1; + bench.src = bgfolder + deskFilename; + bench.style.opacity = '1'; + } else { + bench.style.opacity = '0'; } if ('def,pro,wit'.includes(position)) { @@ -2240,7 +2237,33 @@ class Viewport { } this.chatmsg.preanimdelay = gifLength; - this.set_side(chatmsg.side); + if (chatmsg.type === 5) { + this.set_side(chatmsg.side,true,false); + } else { + switch(chatmsg.deskmod) { + case 0: + this.set_side(chatmsg.side,false,false); + break; + case 1: + this.set_side(chatmsg.side,false,true); + break; + case 2: + this.set_side(chatmsg.side,false,false); + break; + case 3: + this.set_side(chatmsg.side,false,false); + break; + case 4: + this.set_side(chatmsg.side,false,false); + break; + case 5: + this.set_side(chatmsg.side,false,true); + break; + default: + this.set_side(chatmsg.side,false,true); + break; + } + } setChatbox(chatmsg.chatbox); resizeChatbox(); @@ -2520,6 +2543,21 @@ class Viewport { shoutSprite.style.animation = ''; } + switch(this.chatmsg.deskmod) { + case 2: + this.set_side(this.chatmsg.side,false,true); + break; + case 3: + this.set_side(this.chatmsg.side,false,false); + break; + case 4: + this.set_side(this.chatmsg.side,false,true); + break; + case 5: + this.set_side(this.chatmsg.side,false,false); + break; + } + if (this.chatmsg.other_name) { setEmote(AO_HOST, this, pairName, pairEmote, '(a)', true, this.chatmsg.side); pairLayers.style.opacity = '1'; -- cgit From b4d6d002509d928bcb1c57aa908059e0d946f18c Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 13:53:35 +0200 Subject: fix switch case --- webAO/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 407d09d..3da1dc8 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2026,13 +2026,13 @@ class Viewport { speedLines = 'defense_speedlines.gif'; } - if (showspeedlines) { + if (showspeedlines === true) { court.src = `${AO_HOST}themes/default/${encodeURI(speedLines)}`; } else { court.src = await tryUrls(bgfolder + bg) } - if (showdesk && desk) { + if (showdesk === true && desk) { const deskFilename = await fileExists(bgfolder + desk.ao2) ? desk.ao2 : desk.ao1; bench.src = bgfolder + deskFilename; bench.style.opacity = '1'; @@ -2240,7 +2240,7 @@ class Viewport { if (chatmsg.type === 5) { this.set_side(chatmsg.side,true,false); } else { - switch(chatmsg.deskmod) { + switch(Number(chatmsg.deskmod)) { case 0: this.set_side(chatmsg.side,false,false); break; @@ -2543,7 +2543,7 @@ class Viewport { shoutSprite.style.animation = ''; } - switch(this.chatmsg.deskmod) { + switch(Number(this.chatmsg.deskmod)) { case 2: this.set_side(this.chatmsg.side,false,true); break; -- cgit From abcba2ff9b3a884952492364fe6b5fe28a6c617f Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 13:57:59 +0200 Subject: send deskmod too --- webAO/client.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 3da1dc8..c73f975 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -342,7 +342,7 @@ class Client extends EventEmitter { /** * Sends an in-character chat message. - * @param {string} deskmod currently unused + * @param {string} deskmod controls the desk * @param {string} speaking who is speaking * @param {string} name the name of the current character * @param {string} silent whether or not it's silent @@ -1721,6 +1721,7 @@ class Client extends EventEmitter { 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: '', @@ -2656,7 +2657,7 @@ export function onEnter(event: KeyboardEvent) { client.sendIC( - 'chat', + myemo.deskmod, myemo.preanim, mychar.name, myemo.emote, -- cgit From f3359b60bde9014e3ee56daa3d4104d61d8ee149 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 14:00:35 +0200 Subject: deskmod is actually a number --- webAO/client.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 3876011..6c56950 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -343,7 +343,7 @@ class Client extends EventEmitter { /** * Sends an in-character chat message. - * @param {string} deskmod controls the desk + * @param {number} deskmod controls the desk * @param {string} speaking who is speaking * @param {string} name the name of the current character * @param {string} silent whether or not it's silent @@ -363,7 +363,7 @@ class Client extends EventEmitter { * @param {number} noninterrupting_preanim play the full preanim (optional) */ sendIC( - deskmod: string, + deskmod: number, preanim: string, name: string, emote: string, @@ -412,7 +412,7 @@ class Client extends EventEmitter { } } - const serverMessage = `MS#${escapeChat(deskmod)}#${escapeChat(preanim)}#${escapeChat(name)}#${escapeChat(emote)}` + const serverMessage = `MS#${deskmod}#${escapeChat(preanim)}#${escapeChat(name)}#${escapeChat(emote)}` + `#${escapeChat(message)}#${escapeChat(side)}#${escapeChat(sfx_name)}#${emote_modifier}` + `#${this.charID}#${sfx_delay}#${Number(objection_modifier)}#${Number(evidence)}#${Number(flip)}#${Number(realization)}#${text_color}#${extra_cccc}${extra_27}${extra_28}%`; -- cgit From b60b656fceee55f689de2bdb30a86b7fd42e6810 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 14:39:39 +0200 Subject: something weird was going on with pantilt, creating lag. removed onload --- webAO/client.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 6c56950..246d496 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2864,22 +2864,15 @@ window.iniedit = iniedit; */ export async function switchPanTilt() { const fullview = document.getElementById('client_fullview'); - const fullbg = document.getElementById('client_court'); const checkbox = document.getElementById('client_pantilt'); - if (fullbg.src = transparentPng) { - checkbox.checked = false; - fullbg.style.display = 'none'; - } else { - checkbox.checked = true; - fullbg.style.display = ''; - } - if (checkbox.checked) { fullview.style.transition = '0.5s ease-in-out'; } else { fullview.style.transition = 'none'; } + + return } window.switchPanTilt = switchPanTilt; @@ -2887,7 +2880,7 @@ window.switchPanTilt = switchPanTilt; * Triggered by the change aspect ratio checkbox */ export async function switchAspectRatio() { - const background = document.getElementById('client_background'); + const background = document.getElementById('client_gamewindow'); const offsetCheck = document.getElementById('client_hdviewport_offset'); if ((document.getElementById('client_hdviewport')).checked) { background.style.paddingBottom = '56.25%'; -- cgit From f7a94ed001f600994d4dbcd221463e2d77fca59d Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 15:08:05 +0200 Subject: hopefully fix banned message --- webAO/client.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 246d496..7696047 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -71,7 +71,7 @@ let selectedMenu = 1; let selectedShout = 0; let extrafeatures: string[] = []; - +let banned: boolean = false; let hdid: string; declare global { @@ -212,8 +212,6 @@ class Client extends EventEmitter { this.callwords = []; - this.banned = false; - this.resources = getResources(AO_HOST, THEME); this.selectedEmote = -1; @@ -591,7 +589,7 @@ class Client extends EventEmitter { */ onClose(e: CloseEvent) { console.error(`The connection was closed: ${e.reason} (${e.code})`); - if (extrafeatures.length == 0 && this.banned === false) { + if (extrafeatures.length == 0 && banned === false) { document.getElementById('client_errortext').textContent = 'Could not connect to the server'; } document.getElementById('client_waiting').style.display = 'block'; @@ -1353,7 +1351,7 @@ class Client extends EventEmitter { */ handleKB(args: string[]) { this.handleBans('Banned', safeTags(args[1])); - this.banned = true; + banned = true; } /** @@ -1372,7 +1370,7 @@ class Client extends EventEmitter { */ handleBD(args: string[]) { this.handleBans('Banned', safeTags(args[1])); - this.banned = true; + banned = true; } /** -- cgit From bde7f84ccc633af051bd84d6c563a9ced3052fe3 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 16 Jul 2022 15:17:10 +0200 Subject: 4 skips the offset --- webAO/client.ts | 59 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 7696047..db4c776 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2239,26 +2239,28 @@ class Viewport { } this.chatmsg.preanimdelay = gifLength; + let skipoffset: boolean = false; if (chatmsg.type === 5) { this.set_side(chatmsg.side,true,false); } else { switch(Number(chatmsg.deskmod)) { - case 0: + case 0: //desk is hidden this.set_side(chatmsg.side,false,false); break; - case 1: + case 1: //desk is shown this.set_side(chatmsg.side,false,true); break; - case 2: + case 2: //desk is hidden during preanim, but shown during idle/talk this.set_side(chatmsg.side,false,false); break; - case 3: + case 3: //opposite of 2 this.set_side(chatmsg.side,false,false); break; - case 4: + case 4: //desk is hidden, character offset is ignored, pair character is hidden during preanim, normal behavior during idle/talk this.set_side(chatmsg.side,false,false); + skipoffset = true; break; - case 5: + case 5: //opposite of 4 this.set_side(chatmsg.side,false,true); break; default: @@ -2270,31 +2272,32 @@ class Viewport { setChatbox(chatmsg.chatbox); resizeChatbox(); - // Flip the character - charLayers.style.transform = this.chatmsg.flip === 1 ? 'scaleX(-1)' : 'scaleX(1)'; + if (!skipoffset) { + // Flip the character + charLayers.style.transform = this.chatmsg.flip === 1 ? 'scaleX(-1)' : 'scaleX(1)'; + pairLayers.style.transform = this.chatmsg.other_flip === 1 ? 'scaleX(-1)' : 'scaleX(1)'; - // Shift by the horizontal offset - switch (this.chatmsg.side) { - case 'wit': - pairLayers.style.left = `${200 + Number(this.chatmsg.other_offset[0])}%`; - charLayers.style.left = `${200 + Number(this.chatmsg.self_offset[0])}%`; - break; - case 'pro': - pairLayers.style.left = `${400 + Number(this.chatmsg.other_offset[0])}%`; - charLayers.style.left = `${400 + Number(this.chatmsg.self_offset[0])}%`; - break; - default: - pairLayers.style.left = `${Number(this.chatmsg.other_offset[0])}%`; - charLayers.style.left = `${Number(this.chatmsg.self_offset[0])}%`; - break; - } + // Shift by the horizontal offset + switch (this.chatmsg.side) { + case 'wit': + pairLayers.style.left = `${200 + Number(this.chatmsg.other_offset[0])}%`; + charLayers.style.left = `${200 + Number(this.chatmsg.self_offset[0])}%`; + break; + case 'pro': + pairLayers.style.left = `${400 + Number(this.chatmsg.other_offset[0])}%`; + charLayers.style.left = `${400 + Number(this.chatmsg.self_offset[0])}%`; + break; + default: + pairLayers.style.left = `${Number(this.chatmsg.other_offset[0])}%`; + charLayers.style.left = `${Number(this.chatmsg.self_offset[0])}%`; + break; + } - // New vertical offsets - pairLayers.style.top = `${Number(this.chatmsg.other_offset[1])}%`; - charLayers.style.top = `${Number(this.chatmsg.self_offset[1])}%`; + // New vertical offsets + pairLayers.style.top = `${Number(this.chatmsg.other_offset[1])}%`; + charLayers.style.top = `${Number(this.chatmsg.self_offset[1])}%`; - // flip the paired character - pairLayers.style.transform = this.chatmsg.other_flip === 1 ? 'scaleX(-1)' : 'scaleX(1)'; + } this.blipChannels.forEach((channel: HTMLAudioElement) => channel.src = `${AO_HOST}sounds/general/sfx-blip${encodeURI(this.chatmsg.blips.toLowerCase())}.opus`); -- cgit From 25fe710c3b36b097502a5f3e0afb024312cbf7b9 Mon Sep 17 00:00:00 2001 From: Caleb Mabry <36182383+caleb-mabry@users.noreply.github.com> Date: Sun, 17 Jul 2022 00:56:15 -0400 Subject: Moved viewport out of client --- webAO/client.ts | 2944 +++++++++++++++++++++++-------------------------------- 1 file changed, 1231 insertions(+), 1713 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index db4c776..64ffab9 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2,62 +2,63 @@ * Glorious webAO * made by sD, refactored by oldmud0 and Qubrick * credits to aleks for original idea and source -*/ + */ -import FingerprintJS from '@fingerprintjs/fingerprintjs'; -import { EventEmitter } from 'events'; -import tryUrls from './utils/tryUrls' -import { - escapeChat, prepChat, safeTags, unescapeChat, -} from './encoding'; -import mlConfig from './utils/aoml'; +import FingerprintJS from "@fingerprintjs/fingerprintjs"; +import { EventEmitter } from "events"; +import tryUrls from "./utils/tryUrls"; +import { escapeChat, prepChat, safeTags, unescapeChat } from "./encoding"; +import mlConfig from "./utils/aoml"; // Load some defaults for the background and evidence dropdowns -import vanilla_character_arr from './constants/characters.js'; -import vanilla_music_arr from './constants/music.js'; -import vanilla_background_arr from './constants/backgrounds.js'; -import vanilla_evidence_arr from './constants/evidence.js'; - -import chatbox_arr from './styles/chatbox/chatboxes.js'; -import iniParse from './iniParse'; -import getCookie from './utils/getCookie.js'; -import setCookie from './utils/setCookie.js'; -import { request } from './services/request.js'; -import { changeShoutVolume, changeSFXVolume, changeTestimonyVolume } from './dom/changeVolume.js'; -import setEmote from './client/setEmote.js'; -import fileExists from './utils/fileExists.js'; -import queryParser from './utils/queryParser.js'; -import getAnimLength from './utils/getAnimLength.js'; -import getResources from './utils/getResources.js'; -import transparentPng from './constants/transparentPng'; -import downloadFile from './services/downloadFile' -import { getFilenameFromPath } from './utils/paths'; +import vanilla_character_arr from "./constants/characters.js"; +import vanilla_music_arr from "./constants/music.js"; +import vanilla_background_arr from "./constants/backgrounds.js"; +import vanilla_evidence_arr from "./constants/evidence.js"; + +import chatbox_arr from "./styles/chatbox/chatboxes.js"; +import iniParse from "./iniParse"; +import getCookie from "./utils/getCookie.js"; +import setCookie from "./utils/setCookie.js"; +import { request } from "./services/request.js"; +import { + changeShoutVolume, + changeSFXVolume, + changeTestimonyVolume, +} from "./dom/changeVolume.js"; +import setEmote from "./client/setEmote.js"; +import fileExists from "./utils/fileExists.js"; +import queryParser from "./utils/queryParser.js"; +import getAnimLength from "./utils/getAnimLength.js"; +import getResources from "./utils/getResources.js"; +import transparentPng from "./constants/transparentPng"; +import downloadFile from "./services/downloadFile"; +import { getFilenameFromPath } from "./utils/paths"; const version = process.env.npm_package_version; +import masterViewport, { Viewport } from "./viewport"; -let client: Client; -let viewport: Viewport; interface Testimony { - [key: number]: string + [key: number]: string; } // Get the arguments from the URL bar interface QueryParams { - ip: string - serverIP: string - mode: string - asset: string - theme: string + ip: string; + serverIP: string; + mode: string; + asset: string; + theme: string; } -let { - ip: serverIP, mode, asset, theme, -} = queryParser() as QueryParams; +let { ip: serverIP, mode, asset, theme } = queryParser() as QueryParams; // Unless there is an asset URL specified, use the wasabi one -const DEFAULT_HOST = 'http://attorneyoffline.de/base/'; +const DEFAULT_HOST = "http://attorneyoffline.de/base/"; let AO_HOST = asset || DEFAULT_HOST; -const THEME = theme || 'default'; +const THEME = theme || "default"; -const attorneyMarkdown = mlConfig(AO_HOST) +let client: Client; + +const attorneyMarkdown = mlConfig(AO_HOST); -const UPDATE_INTERVAL = 60; +export const UPDATE_INTERVAL = 60; /** * Toggles AO1-style loading using paginated music packets for mobile platforms. @@ -131,7 +132,11 @@ declare global { } function isLowMemory() { - if (/webOS|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|PlayStation|Nintendo|Opera Mini/i.test(navigator.userAgent)) { + if ( + /webOS|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|PlayStation|Nintendo|Opera Mini/i.test( + navigator.userAgent + ) + ) { oldLoading = true; } } @@ -141,12 +146,11 @@ fpPromise .then((result) => { hdid = result.visitorId; client = new Client(serverIP); - viewport = new Viewport(); isLowMemory(); client.loadResources(); }); -const delay = (ms: number) => new Promise(res => setTimeout(res, ms)); +export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)); let lastICMessageTime = new Date(0); @@ -172,24 +176,24 @@ class Client extends EventEmitter { selectedEvidence: number; checkUpdater: any; _lastTimeICReceived: any; - + viewport: Viewport; constructor(address: string) { super(); - if (mode !== 'replay') { + if (mode !== "replay") { this.serv = new WebSocket(`ws://${address}`); // Assign the websocket events - this.serv.addEventListener('open', this.emit.bind(this, 'open')); - this.serv.addEventListener('close', this.emit.bind(this, 'close')); - this.serv.addEventListener('message', this.emit.bind(this, 'message')); - this.serv.addEventListener('error', this.emit.bind(this, 'error')); + this.serv.addEventListener("open", this.emit.bind(this, "open")); + this.serv.addEventListener("close", this.emit.bind(this, "close")); + this.serv.addEventListener("message", this.emit.bind(this, "message")); + this.serv.addEventListener("error", this.emit.bind(this, "error")); } else { this.joinServer(); } - this.on('open', this.onOpen.bind(this)); - this.on('close', this.onClose.bind(this)); - this.on('message', this.onMessage.bind(this)); - this.on('error', this.onError.bind(this)); + this.on("open", this.onOpen.bind(this)); + this.on("close", this.onClose.bind(this)); + this.on("message", this.onMessage.bind(this)); + this.on("error", this.onError.bind(this)); // Preset some of the variables @@ -218,119 +222,128 @@ class Client extends EventEmitter { this.selectedEvidence = 0; this.checkUpdater = null; - + this.viewport = masterViewport(this, AO_HOST); /** - * Assign handlers for all commands - * If you implement a new command, you need to add it here - */ - this.on('MS', this.handleMS.bind(this)); - this.on('CT', this.handleCT.bind(this)); - this.on('MC', this.handleMC.bind(this)); - this.on('RMC', this.handleRMC.bind(this)); - this.on('CI', this.handleCI.bind(this)); - this.on('SC', this.handleSC.bind(this)); - this.on('EI', this.handleEI.bind(this)); - this.on('FL', this.handleFL.bind(this)); - this.on('LE', this.handleLE.bind(this)); - this.on('EM', this.handleEM.bind(this)); - this.on('FM', this.handleFM.bind(this)); - this.on('FA', this.handleFA.bind(this)); - this.on('SM', this.handleSM.bind(this)); - this.on('MM', this.handleMM.bind(this)); - this.on('BD', this.handleBD.bind(this)); - this.on('BB', this.handleBB.bind(this)); - this.on('KB', this.handleKB.bind(this)); - this.on('KK', this.handleKK.bind(this)); - this.on('DONE', this.handleDONE.bind(this)); - this.on('BN', this.handleBN.bind(this)); - this.on('HP', this.handleHP.bind(this)); - this.on('RT', this.handleRT.bind(this)); - this.on('TI', this.handleTI.bind(this)); - this.on('ZZ', this.handleZZ.bind(this)); - this.on('HI', this.handleHI.bind(this)); - this.on('ID', this.handleID.bind(this)); - this.on('PN', this.handlePN.bind(this)); - this.on('SI', this.handleSI.bind(this)); - this.on('ARUP', this.handleARUP.bind(this)); - this.on('askchaa', this.handleaskchaa.bind(this)); - this.on('CC', this.handleCC.bind(this)); - this.on('RC', this.handleRC.bind(this)); - this.on('RM', this.handleRM.bind(this)); - this.on('RD', this.handleRD.bind(this)); - this.on('CharsCheck', this.handleCharsCheck.bind(this)); - this.on('PV', this.handlePV.bind(this)); - this.on('ASS', this.handleASS.bind(this)); - this.on('CHECK', () => { }); - this.on('CH', () => { }); + * Assign handlers for all commands + * If you implement a new command, you need to add it here + */ + this.on("MS", this.handleMS.bind(this)); + this.on("CT", this.handleCT.bind(this)); + this.on("MC", this.handleMC.bind(this)); + this.on("RMC", this.handleRMC.bind(this)); + this.on("CI", this.handleCI.bind(this)); + this.on("SC", this.handleSC.bind(this)); + this.on("EI", this.handleEI.bind(this)); + this.on("FL", this.handleFL.bind(this)); + this.on("LE", this.handleLE.bind(this)); + this.on("EM", this.handleEM.bind(this)); + this.on("FM", this.handleFM.bind(this)); + this.on("FA", this.handleFA.bind(this)); + this.on("SM", this.handleSM.bind(this)); + this.on("MM", this.handleMM.bind(this)); + this.on("BD", this.handleBD.bind(this)); + this.on("BB", this.handleBB.bind(this)); + this.on("KB", this.handleKB.bind(this)); + this.on("KK", this.handleKK.bind(this)); + this.on("DONE", this.handleDONE.bind(this)); + this.on("BN", this.handleBN.bind(this)); + this.on("HP", this.handleHP.bind(this)); + this.on("RT", this.handleRT.bind(this)); + this.on("TI", this.handleTI.bind(this)); + this.on("ZZ", this.handleZZ.bind(this)); + this.on("HI", this.handleHI.bind(this)); + this.on("ID", this.handleID.bind(this)); + this.on("PN", this.handlePN.bind(this)); + this.on("SI", this.handleSI.bind(this)); + this.on("ARUP", this.handleARUP.bind(this)); + this.on("askchaa", this.handleaskchaa.bind(this)); + this.on("CC", this.handleCC.bind(this)); + this.on("RC", this.handleRC.bind(this)); + this.on("RM", this.handleRM.bind(this)); + this.on("RD", this.handleRD.bind(this)); + this.on("CharsCheck", this.handleCharsCheck.bind(this)); + this.on("PV", this.handlePV.bind(this)); + this.on("ASS", this.handleASS.bind(this)); + this.on("CHECK", () => {}); + this.on("CH", () => {}); this._lastTimeICReceived = new Date(0); } /** - * Gets the current player's character. - */ + * Gets the current player's character. + */ get character() { return this.chars[this.charID]; } /** - * Gets the player's currently selected emote. - */ + * Gets the player's currently selected emote. + */ get emote() { return this.emotes[this.selectedEmote]; } /** - * Gets the current evidence ID unless the player doesn't want to present any evidence - */ + * Gets the current evidence ID unless the player doesn't want to present any evidence + */ get evidence() { - return (document.getElementById('button_present').classList.contains('dark')) ? this.selectedEvidence : 0; + return document.getElementById("button_present").classList.contains("dark") + ? this.selectedEvidence + : 0; } /** - * Hook for sending messages to the server - * @param {string} message the message to send - */ + * Hook for sending messages to the server + * @param {string} message the message to send + */ sendServer(message: string) { //console.log("C: "+message); - mode === 'replay' ? this.sendSelf(message) : this.serv.send(message); + mode === "replay" ? this.sendSelf(message) : this.serv.send(message); } /** - * Hook for sending messages to the client - * @param {string} message the message to send - */ + * Hook for sending messages to the client + * @param {string} message the message to send + */ handleSelf(message: string) { - const message_event = new MessageEvent('websocket', { data: message }); + const message_event = new MessageEvent("websocket", { data: message }); setTimeout(() => this.onMessage(message_event), 1); } /** - * Hook for sending messages to the client - * @param {string} message the message to send - */ + * Hook for sending messages to the client + * @param {string} message the message to send + */ sendSelf(message: string) { - (document.getElementById('client_ooclog')).value += `${message}\r\n`; + (( + document.getElementById("client_ooclog") + )).value += `${message}\r\n`; this.handleSelf(message); } /** - * Sends an out-of-character chat message. - * @param {string} message the message to send - */ + * Sends an out-of-character chat message. + * @param {string} message the message to send + */ sendOOC(message: string) { - setCookie('OOC_name', (document.getElementById('OOC_name')).value); - const oocName = `${escapeChat((document.getElementById('OOC_name')).value)}`; + setCookie( + "OOC_name", + (document.getElementById("OOC_name")).value + ); + const oocName = `${escapeChat( + (document.getElementById("OOC_name")).value + )}`; const oocMessage = `${escapeChat(message)}`; const commands = { - '/save_chatlog': this.saveChatlogHandle - } - const commandsMap = new Map(Object.entries(commands)) + "/save_chatlog": this.saveChatlogHandle, + }; + const commandsMap = new Map(Object.entries(commands)); if (oocMessage && commandsMap.has(oocMessage.toLowerCase())) { try { - commandsMap.get(oocMessage.toLowerCase())() + commandsMap.get(oocMessage.toLowerCase())(); } catch (e) { // Command Not Recognized } @@ -340,26 +353,26 @@ class Client extends EventEmitter { } /** - * Sends an in-character chat message. - * @param {number} deskmod controls the desk - * @param {string} speaking who is speaking - * @param {string} name the name of the current character - * @param {string} silent whether or not it's silent - * @param {string} message the message to be sent - * @param {string} side the name of the side in the background - * @param {string} sfx_name the name of the sound effect - * @param {number} emote_modifier whether or not to zoom - * @param {number} sfx_delay the delay (in milliseconds) to play the sound effect - * @param {number} objection_modifier the number of the shout to play - * @param {string} evidence the filename of evidence to show - * @param {boolean} flip change to 1 to reverse sprite for position changes - * @param {boolean} realization screen flash effect - * @param {number} text_color text color - * @param {string} showname custom name to be displayed (optional) - * @param {number} other_charid paired character (optional) - * @param {number} self_offset offset to paired character (optional) - * @param {number} noninterrupting_preanim play the full preanim (optional) - */ + * Sends an in-character chat message. + * @param {number} deskmod controls the desk + * @param {string} speaking who is speaking + * @param {string} name the name of the current character + * @param {string} silent whether or not it's silent + * @param {string} message the message to be sent + * @param {string} side the name of the side in the background + * @param {string} sfx_name the name of the sound effect + * @param {number} emote_modifier whether or not to zoom + * @param {number} sfx_delay the delay (in milliseconds) to play the sound effect + * @param {number} objection_modifier the number of the shout to play + * @param {string} evidence the filename of evidence to show + * @param {boolean} flip change to 1 to reverse sprite for position changes + * @param {boolean} realization screen flash effect + * @param {number} text_color text color + * @param {string} showname custom name to be displayed (optional) + * @param {number} other_charid paired character (optional) + * @param {number} self_offset offset to paired character (optional) + * @param {number} noninterrupting_preanim play the full preanim (optional) + */ sendIC( deskmod: number, preanim: string, @@ -386,233 +399,283 @@ class Client extends EventEmitter { frame_realization: string, frame_sfx: string, additive: boolean, - effect: string, + effect: string ) { - let extra_cccc = ''; - let other_emote = ''; - let other_offset = ''; - let extra_27 = ''; - let extra_28 = ''; - - if (extrafeatures.includes('cccc_ic_support')) { - const self_offset = extrafeatures.includes('y_offset') ? `${self_hoffset}${self_yoffset}` : self_hoffset; // HACK: this should be an & but client fucked it up and all the servers adopted it - if (mode === 'replay') { - other_emote = '##'; - other_offset = '#0#0'; + let extra_cccc = ""; + let other_emote = ""; + let other_offset = ""; + let extra_27 = ""; + let extra_28 = ""; + + if (extrafeatures.includes("cccc_ic_support")) { + const self_offset = extrafeatures.includes("y_offset") + ? `${self_hoffset}${self_yoffset}` + : self_hoffset; // HACK: this should be an & but client fucked it up and all the servers adopted it + if (mode === "replay") { + other_emote = "##"; + other_offset = "#0#0"; } - extra_cccc = `${escapeChat(showname)}#${other_charid}${other_emote}#${self_offset}${other_offset}#${Number(noninterrupting_preanim)}#`; - - if (extrafeatures.includes('looping_sfx')) { - extra_27 = `${Number(looping_sfx)}#${Number(screenshake)}#${frame_screenshake}#${frame_realization}#${frame_sfx}#`; - if (extrafeatures.includes('effects')) { + extra_cccc = `${escapeChat( + showname + )}#${other_charid}${other_emote}#${self_offset}${other_offset}#${Number( + noninterrupting_preanim + )}#`; + + if (extrafeatures.includes("looping_sfx")) { + extra_27 = `${Number(looping_sfx)}#${Number( + screenshake + )}#${frame_screenshake}#${frame_realization}#${frame_sfx}#`; + if (extrafeatures.includes("effects")) { extra_28 = `${Number(additive)}#${escapeChat(effect)}#`; } } } - const serverMessage = `MS#${deskmod}#${escapeChat(preanim)}#${escapeChat(name)}#${escapeChat(emote)}` - + `#${escapeChat(message)}#${escapeChat(side)}#${escapeChat(sfx_name)}#${emote_modifier}` - + `#${this.charID}#${sfx_delay}#${Number(objection_modifier)}#${Number(evidence)}#${Number(flip)}#${Number(realization)}#${text_color}#${extra_cccc}${extra_27}${extra_28}%`; + const serverMessage = + `MS#${deskmod}#${escapeChat(preanim)}#${escapeChat(name)}#${escapeChat( + emote + )}` + + `#${escapeChat(message)}#${escapeChat(side)}#${escapeChat( + sfx_name + )}#${emote_modifier}` + + `#${this.charID}#${sfx_delay}#${Number(objection_modifier)}#${Number( + evidence + )}#${Number(flip)}#${Number( + realization + )}#${text_color}#${extra_cccc}${extra_27}${extra_28}%`; this.sendServer(serverMessage); - if (mode === 'replay') { - (document.getElementById('client_ooclog')).value += `wait#${(document.getElementById('client_replaytimer')).value}#%\r\n`; + if (mode === "replay") { + (( + document.getElementById("client_ooclog") + )).value += `wait#${ + (document.getElementById("client_replaytimer")).value + }#%\r\n`; } } /** - * Sends add evidence command. - * @param {string} evidence name - * @param {string} evidence description - * @param {string} evidence image filename - */ + * Sends add evidence command. + * @param {string} evidence name + * @param {string} evidence description + * @param {string} evidence image filename + */ sendPE(name: string, desc: string, img: string) { - this.sendServer(`PE#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%`); + this.sendServer( + `PE#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%` + ); } /** - * Sends edit evidence command. - * @param {number} evidence id - * @param {string} evidence name - * @param {string} evidence description - * @param {string} evidence image filename - */ + * Sends edit evidence command. + * @param {number} evidence id + * @param {string} evidence name + * @param {string} evidence description + * @param {string} evidence image filename + */ sendEE(id: number, name: string, desc: string, img: string) { - this.sendServer(`EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%`); + this.sendServer( + `EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%` + ); } /** - * Sends delete evidence command. - * @param {number} evidence id - */ + * Sends delete evidence command. + * @param {number} evidence id + */ sendDE(id: number) { this.sendServer(`DE#${id}#%`); } /** - * Sends health point command. - * @param {number} side the position - * @param {number} hp the health point - */ + * Sends health point command. + * @param {number} side the position + * @param {number} hp the health point + */ sendHP(side: number, hp: number) { this.sendServer(`HP#${side}#${hp}#%`); } /** - * Sends call mod command. - * @param {string} message to mod - */ + * Sends call mod command. + * @param {string} message to mod + */ sendZZ(msg: string) { - if (extrafeatures.includes('modcall_reason')) { + if (extrafeatures.includes("modcall_reason")) { this.sendServer(`ZZ#${msg}#%`); } else { - this.sendServer('ZZ#%'); + this.sendServer("ZZ#%"); } } /** - * Sends testimony command. - * @param {string} testimony type - */ + * Sends testimony command. + * @param {string} testimony type + */ sendRT(testimony: string) { - if (this.chars[this.charID].side === 'jud') { + if (this.chars[this.charID].side === "jud") { this.sendServer(`RT#${testimony}#%`); } } /** - * Requests to change the music to the specified track. - * @param {string} track the track ID - */ + * Requests to change the music to the specified track. + * @param {string} track the track ID + */ sendMusicChange(track: string) { this.sendServer(`MC#${track}#${this.charID}#%`); } /** - * Begins the handshake process by sending an identifier - * to the server. - */ + * Begins the handshake process by sending an identifier + * to the server. + */ joinServer() { this.sendServer(`HI#${hdid}#%`); - this.sendServer('ID#webAO#webAO#%'); - if (mode !== 'replay') { this.checkUpdater = setInterval(() => this.sendCheck(), 5000); } + this.sendServer("ID#webAO#webAO#%"); + if (mode !== "replay") { + this.checkUpdater = setInterval(() => this.sendCheck(), 5000); + } } /** - * Load game resources and stored settings. - */ + * Load game resources and stored settings. + */ loadResources() { - document.getElementById('client_version').innerText = `version ${version}`; + document.getElementById("client_version").innerText = `version ${version}`; // Load background array to select - const background_select = document.getElementById('bg_select'); - background_select.add(new Option('Custom', '0')); + const background_select = ( + document.getElementById("bg_select") + ); + background_select.add(new Option("Custom", "0")); vanilla_background_arr.forEach((background) => { background_select.add(new Option(background)); }); // Load evidence array to select - const evidence_select = document.getElementById('evi_select'); - evidence_select.add(new Option('Custom', '0')); + const evidence_select = ( + document.getElementById("evi_select") + ); + evidence_select.add(new Option("Custom", "0")); vanilla_evidence_arr.forEach((evidence) => { evidence_select.add(new Option(evidence)); }); // Read cookies and set the UI to its values - (document.getElementById('OOC_name')).value = getCookie('OOC_name') || `web${String(Math.round(Math.random() * 100 + 10))}`; + (document.getElementById("OOC_name")).value = + getCookie("OOC_name") || + `web${String(Math.round(Math.random() * 100 + 10))}`; // Read cookies and set the UI to its values - const cookietheme = getCookie('theme') || 'default'; + const cookietheme = getCookie("theme") || "default"; - (document.querySelector(`#client_themeselect [value="${cookietheme}"]`)).selected = true; - reloadTheme(); + (( + document.querySelector(`#client_themeselect [value="${cookietheme}"]`) + )).selected = true; + this.viewport.reloadTheme(); - const cookiechatbox = getCookie('chatbox') || 'dynamic'; + const cookiechatbox = getCookie("chatbox") || "dynamic"; - (document.querySelector(`#client_chatboxselect [value="${cookiechatbox}"]`)).selected = true; + (( + document.querySelector(`#client_chatboxselect [value="${cookiechatbox}"]`) + )).selected = true; setChatbox(cookiechatbox); - (document.getElementById('client_mvolume')).value = getCookie('musicVolume') || '1'; - changeMusicVolume(); - (document.getElementById('client_sfxaudio')).volume = Number(getCookie('sfxVolume')) || 1; + (document.getElementById("client_mvolume")).value = + getCookie("musicVolume") || "1"; + this.viewport.changeMusicVolume(); + (document.getElementById("client_sfxaudio")).volume = + Number(getCookie("sfxVolume")) || 1; changeSFXVolume(); - (document.getElementById('client_shoutaudio')).volume = Number(getCookie('shoutVolume')) || 1; + (document.getElementById("client_shoutaudio")).volume = + Number(getCookie("shoutVolume")) || 1; changeShoutVolume(); - (document.getElementById('client_testimonyaudio')).volume = Number(getCookie('testimonyVolume')) || 1; + (( + document.getElementById("client_testimonyaudio") + )).volume = Number(getCookie("testimonyVolume")) || 1; changeTestimonyVolume(); - (document.getElementById('client_bvolume')).value = getCookie('blipVolume') || '1'; - changeBlipVolume(); - - (document.getElementById('ic_chat_name')).value = getCookie('ic_chat_name'); - (document.getElementById('showname')).checked = Boolean(getCookie('showname')); + (document.getElementById("client_bvolume")).value = + getCookie("blipVolume") || "1"; + this.viewport.changeBlipVolume(); + + (document.getElementById("ic_chat_name")).value = + getCookie("ic_chat_name"); + (document.getElementById("showname")).checked = Boolean( + getCookie("showname") + ); showname_click(null); - (document.getElementById('client_callwords')).value = getCookie('callwords'); + (document.getElementById("client_callwords")).value = + getCookie("callwords"); } /** - * Requests to play as a specified character. - * @param {number} character the character ID - */ + * Requests to play as a specified character. + * @param {number} character the character ID + */ sendCharacter(character: number) { - console.log("sending "+character); + console.log("sending " + character); if (character === -1 || this.chars[character].name) { this.sendServer(`CC#${this.playerID}#${character}#web#%`); } } /** - * Requests to select a music track. - * @param {number?} song the song to be played - */ + * Requests to select a music track. + * @param {number?} song the song to be played + */ sendMusic(song: string) { this.sendServer(`MC#${song}#${this.charID}#%`); } /** - * Sends a keepalive packet. - */ + * Sends a keepalive packet. + */ sendCheck() { this.sendServer(`CH#${this.charID}#%`); } /** - * Triggered when a connection is established to the server. - */ + * Triggered when a connection is established to the server. + */ onOpen(_e: Event) { client.joinServer(); } /** - * Triggered when the connection to the server closes. - * @param {CloseEvent} e - */ + * Triggered when the connection to the server closes. + * @param {CloseEvent} e + */ onClose(e: CloseEvent) { console.error(`The connection was closed: ${e.reason} (${e.code})`); if (extrafeatures.length == 0 && banned === false) { - document.getElementById('client_errortext').textContent = 'Could not connect to the server'; + document.getElementById("client_errortext").textContent = + "Could not connect to the server"; } - document.getElementById('client_waiting').style.display = 'block'; - document.getElementById('client_error').style.display = 'flex'; - document.getElementById('client_loading').style.display = 'none'; - document.getElementById('error_id').textContent = String(e.code); + document.getElementById("client_waiting").style.display = "block"; + document.getElementById("client_error").style.display = "flex"; + document.getElementById("client_loading").style.display = "none"; + document.getElementById("error_id").textContent = String(e.code); this.cleanup(); } /** - * Triggered when a packet is received from the server. - * @param {MessageEvent} e - */ + * Triggered when a packet is received from the server. + * @param {MessageEvent} e + */ onMessage(e: MessageEvent) { const msg = e.data; console.debug(`S: ${msg}`); - const lines = msg.split('%'); + const lines = msg.split("%"); for (const msg of lines) { - if (msg === '') { break; } + if (msg === "") { + break; + } - const args = msg.split('#'); + const args = msg.split("#"); const header = args[0]; if (!this.emit(header, args)) { @@ -622,41 +685,43 @@ class Client extends EventEmitter { } /** - * Triggered when an network error occurs. - * @param {ErrorEvent} e - */ + * Triggered when an network error occurs. + * @param {ErrorEvent} e + */ onError(e: ErrorEvent) { console.error(`A network error occurred`); - document.getElementById('client_error').style.display = 'flex'; + document.getElementById("client_error").style.display = "flex"; this.cleanup(); } /** - * Stop sending keepalives to the server. - */ + * Stop sending keepalives to the server. + */ cleanup() { clearInterval(this.checkUpdater); - this.serv.close() + this.serv.close(); } /** - * Parse the lines in the OOC and play them - * @param {*} args packet arguments - */ + * Parse the lines in the OOC and play them + * @param {*} args packet arguments + */ handleReplay() { - const ooclog = document.getElementById('client_ooclog'); + const ooclog = document.getElementById("client_ooclog"); const rawLog = false; - let rtime: number = Number((document.getElementById('client_replaytimer')).value); + let rtime: number = Number( + (document.getElementById("client_replaytimer")).value + ); const clines = ooclog.value.split(/\r?\n/); if (clines[0]) { const currentLine = String(clines[0]); this.handleSelf(currentLine); - ooclog.value = clines.slice(1).join('\r\n'); - if (currentLine.substr(0, 4) === 'wait' && rawLog === false) { - rtime = Number(currentLine.split('#')[1]); - } else if (currentLine.substr(0, 2) !== 'MS') { + ooclog.value = clines.slice(1).join("\r\n"); + if (currentLine.substr(0, 4) === "wait" && rawLog === false) { + rtime = Number(currentLine.split("#")[1]); + } else if (currentLine.substr(0, 2) !== "MS") { rtime = 0; } @@ -665,70 +730,69 @@ class Client extends EventEmitter { } saveChatlogHandle = async () => { - const clientLog = document.getElementById('client_log') - const icMessageLogs = clientLog.getElementsByTagName('p') - const messages = [] + const clientLog = document.getElementById("client_log"); + const icMessageLogs = clientLog.getElementsByTagName("p"); + const messages = []; for (let i = 0; i < icMessageLogs.length; i++) { - const SHOWNAME_POSITION = 0 - const TEXT_POSITION = 2 - const showname = icMessageLogs[i].children[SHOWNAME_POSITION].innerHTML - const text = icMessageLogs[i].children[TEXT_POSITION].innerHTML - const message = `${showname}: ${text}` - messages.push(message) + const SHOWNAME_POSITION = 0; + const TEXT_POSITION = 2; + const showname = icMessageLogs[i].children[SHOWNAME_POSITION].innerHTML; + const text = icMessageLogs[i].children[TEXT_POSITION].innerHTML; + const message = `${showname}: ${text}`; + messages.push(message); } const d = new Date(); - let ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d); - let mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d); - let da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d); + let ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d); + let mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d); + let da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d); const filename = `chatlog-${da}-${mo}-${ye}`.toLowerCase(); - downloadFile(messages.join('\n'), filename); + downloadFile(messages.join("\n"), filename); // Reset Chatbox to Empty - (document.getElementById('client_inputbox')).value = ''; - } - + (document.getElementById("client_inputbox")).value = ""; + }; + /** - * Handles an in-character chat message. - * @param {*} args packet arguments - */ + * Handles an in-character chat message. + * @param {*} args packet arguments + */ handleMS(args: string[]) { - // TODO: this if-statement might be a bug. - if (args[4] !== viewport.chatmsg.content) { - document.getElementById('client_inner_chat').innerHTML = ''; + if (args[4] !== this.viewport.chatmsg.content) { + document.getElementById("client_inner_chat").innerHTML = ""; const char_id = Number(args[9]); const char_name = safeTags(args[3]); let msg_nameplate = args[3]; - let msg_blips = 'male'; - let char_chatbox = 'default'; + let msg_blips = "male"; + let char_chatbox = "default"; let char_muted = false; if (this.chars[char_id].name !== char_name) { - console.info(`${this.chars[char_id].name} is iniediting to ${char_name}`); - const chargs = (`${char_name}&` + 'iniediter').split('&'); + console.info( + `${this.chars[char_id].name} is iniediting to ${char_name}` + ); + const chargs = (`${char_name}&` + "iniediter").split("&"); this.handleCharacterInfo(chargs, char_id); } try { - msg_nameplate = this.chars[char_id].showname; + msg_nameplate = this.chars[char_id].showname; } catch (e) { msg_nameplate = args[3]; } try { msg_blips = this.chars[char_id].blips; - } catch (e) { - ; - } + } catch (e) {} try { char_chatbox = this.chars[char_id].chat; } catch (e) { - char_chatbox = 'default'; + char_chatbox = "default"; } try { @@ -758,23 +822,23 @@ class Client extends EventEmitter { flip: Number(args[13]), flash: Number(args[14]), color: Number(args[15]), - speed: UPDATE_INTERVAL + speed: UPDATE_INTERVAL, }; - if (extrafeatures.includes('cccc_ic_support')) { + 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(''), + 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')) { + if (extrafeatures.includes("looping_sfx")) { const extra_27 = { looping_sfx: Number(args[24]), screenshake: Number(args[25]), @@ -784,16 +848,16 @@ class Client extends EventEmitter { }; chatmsg = Object.assign(extra_27, chatmsg); - if (extrafeatures.includes('effects')) { + if (extrafeatures.includes("effects")) { const extra_28 = { additive: Number(args[29]), - effects: args[30].split('|'), + effects: args[30].split("|"), }; chatmsg = Object.assign(extra_28, chatmsg); } else { const extra_28 = { additive: 0, - effects: ['', '', ''], + effects: ["", "", ""], }; chatmsg = Object.assign(extra_28, chatmsg); } @@ -801,23 +865,23 @@ class Client extends EventEmitter { const extra_27 = { looping_sfx: 0, screenshake: 0, - frame_screenshake: '', - frame_realization: '', - frame_sfx: '', + frame_screenshake: "", + frame_realization: "", + frame_sfx: "", }; chatmsg = Object.assign(extra_27, chatmsg); const extra_28 = { additive: 0, - effects: ['', '', ''], + effects: ["", "", ""], }; chatmsg = Object.assign(extra_28, chatmsg); } } else { const extra_cccc = { - showname: '', + showname: "", other_charid: 0, - other_name: '', - other_emote: '', + other_name: "", + other_emote: "", self_offset: [0, 0], other_offset: [0, 0], other_flip: 0, @@ -827,14 +891,14 @@ class Client extends EventEmitter { const extra_27 = { looping_sfx: 0, screenshake: 0, - frame_screenshake: '', - frame_realization: '', - frame_sfx: '', + frame_screenshake: "", + frame_realization: "", + frame_sfx: "", }; chatmsg = Object.assign(extra_27, chatmsg); const extra_28 = { additive: 0, - effects: ['', '', ''], + effects: ["", "", ""], }; chatmsg = Object.assign(extra_28, chatmsg); } @@ -843,42 +907,42 @@ class Client extends EventEmitter { if (chatmsg.charid === this.charID) { resetICParams(); } - viewport.handle_ic_speaking(chatmsg); // no await + console.log(chatmsg); + this.viewport.handle_ic_speaking(chatmsg); // no await } } } /** - * Handles an out-of-character chat message. - * @param {Array} args packet arguments - */ + * Handles an out-of-character chat message. + * @param {Array} args packet arguments + */ handleCT(args: string[]) { - if (mode !== 'replay') { - const oocLog = document.getElementById('client_ooclog'); + 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; } } - } /** - * Handles a music change to an arbitrary resource. - * @param {Array} args packet arguments - */ + * Handles a music change to an arbitrary resource. + * @param {Array} args packet arguments + */ handleMC(args: string[]) { const track = prepChat(args[1]); let charID = Number(args[2]); - const showname = args[3] || ''; + 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 = viewport.music[channel]; + const music = this.viewport.music[channel]; let musicname; music.pause(); - if (track.startsWith('http')) { + if (track.startsWith("http")) { music.src = track; } else { music.src = `${AO_HOST}sounds/music/${encodeURI(track.toLowerCase())}`; @@ -899,41 +963,48 @@ class Client extends EventEmitter { appendICLog(`The music was changed to ${track}`); } - document.getElementById('client_trackstatustext').innerText = track; + document.getElementById("client_trackstatustext").innerText = track; } + // 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 - */ + * Handles a music change to an arbitrary resource, with an offset in seconds. + * @param {Array} args packet arguments + */ handleRMC(args: string[]) { - viewport.music.pause(); - const { music } = viewport; + this.viewport.music.pause(); + const { music } = this.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); + music.addEventListener( + "loadedmetadata", + () => { + music.currentTime += parseFloat( + music.totime + (new Date().getTime() / 1000 - music.offset) + ).toFixed(3); + music.play(); + }, + false + ); } /** - * Handles the incoming character information, and downloads the sprite + ini for it - * @param {Array} chargs packet arguments - * @param {Number} charid character ID - */ + * Handles the incoming character information, and downloads the sprite + ini for it + * @param {Array} chargs packet arguments + * @param {Number} charid character ID + */ async handleCharacterInfo(chargs: string[], charid: number) { const img = document.getElementById(`demo_${charid}`); if (chargs[0]) { let cini: any = {}; const getCharIcon = async () => { - const extensions = [ - '.png', - '.webp', - ]; + const extensions = [".png", ".webp"]; img.alt = chargs[0]; - const charIconBaseUrl = `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char_icon`; + const charIconBaseUrl = `${AO_HOST}characters/${encodeURI( + chargs[0].toLowerCase() + )}/char_icon`; for (let i = 0; i < extensions.length; i++) { const fileUrl = charIconBaseUrl + extensions[i]; const exists = await fileExists(fileUrl); @@ -948,28 +1019,34 @@ class Client extends EventEmitter { // If the ini doesn't exist on the server this will throw an error try { - const cinidata = await request(`${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char.ini`); + const cinidata = await request( + `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char.ini` + ); cini = iniParse(cinidata); } catch (err) { cini = {}; - img.classList.add('noini'); + img.classList.add("noini"); console.warn(`character ${chargs[0]} is missing from webAO`); // If it does, give the user a visual indication that the character is unusable } - const mute_select = document.getElementById('mute_select'); + const mute_select = ( + document.getElementById("mute_select") + ); mute_select.add(new Option(safeTags(chargs[0]), String(charid))); - const pair_select = document.getElementById('pair_select'); + const pair_select = ( + document.getElementById("pair_select") + ); pair_select.add(new Option(safeTags(chargs[0]), String(charid))); // sometimes ini files lack important settings const default_options = { name: chargs[0], showname: chargs[0], - side: 'def', - blips: 'male', - chat: '', - category: '', + side: "def", + blips: "male", + chat: "", + category: "", }; cini.options = Object.assign(default_options, cini.options); @@ -986,107 +1063,133 @@ class Client extends EventEmitter { blips: safeTags(cini.options.blips).toLowerCase(), gender: safeTags(cini.options.gender).toLowerCase(), side: safeTags(cini.options.side).toLowerCase(), - chat: (cini.options.chat === '' ) ? safeTags(cini.options.category).toLowerCase() : safeTags(cini.options.chat).toLowerCase(), + chat: + cini.options.chat === "" + ? safeTags(cini.options.category).toLowerCase() + : safeTags(cini.options.chat).toLowerCase(), evidence: chargs[3], icon: img.src, inifile: cini, muted: false, }; - if (this.chars[charid].blips === 'male' && this.chars[charid].gender !== 'male' && this.chars[charid].gender !== '') { this.chars[charid].blips = this.chars[charid].gender; } + if ( + this.chars[charid].blips === "male" && + this.chars[charid].gender !== "male" && + this.chars[charid].gender !== "" + ) { + this.chars[charid].blips = this.chars[charid].gender; + } - const iniedit_select = document.getElementById('client_ininame'); + const iniedit_select = ( + document.getElementById("client_ininame") + ); iniedit_select.add(new Option(safeTags(chargs[0]))); } else { console.warn(`missing charid ${charid}`); - img.style.display = 'none'; + img.style.display = "none"; } } /** - * Handles incoming character information, bundling multiple characters - * per packet. - * CI#0#Phoenix&description&&&&#Miles ... - * @param {Array} args packet arguments - */ + * Handles incoming character information, bundling multiple characters + * per packet. + * CI#0#Phoenix&description&&&&#Miles ... + * @param {Array} args packet arguments + */ 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]}/${this.char_list_length}`; - const chargs = args[i].split('&'); + document.getElementById( + "client_loadingtext" + ).innerHTML = `Loading Character ${args[1]}/${this.char_list_length}`; + const chargs = args[i].split("&"); const charid = Number(args[i - 1]); - (document.getElementById('client_loadingbar')).value = charid; + (( + document.getElementById("client_loadingbar") + )).value = charid; setTimeout(() => this.handleCharacterInfo(chargs, charid), 500); } } // Request the next pack - this.sendServer(`AN#${(Number(args[1]) / 10) + 1}#%`); + this.sendServer(`AN#${Number(args[1]) / 10 + 1}#%`); } /** - * Handles incoming character information, containing all characters - * in one packet. - * @param {Array} args packet arguments - */ + * Handles incoming character information, containing all characters + * in one packet. + * @param {Array} args packet arguments + */ async handleSC(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'; + 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_charselect").style.display = "block"; } - document.getElementById('client_loadingtext').innerHTML = 'Loading Characters'; + document.getElementById("client_loadingtext").innerHTML = + "Loading Characters"; for (let i = 1; i < args.length; i++) { - document.getElementById('client_loadingtext').innerHTML = `Loading Character ${i}/${this.char_list_length}`; - const chargs = args[i].split('&'); + document.getElementById( + "client_loadingtext" + ).innerHTML = `Loading Character ${i}/${this.char_list_length}`; + const chargs = args[i].split("&"); const charid = i - 1; - (document.getElementById('client_loadingbar')).value = charid; + (( + document.getElementById("client_loadingbar") + )).value = charid; await sleep(0.1); // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES this.handleCharacterInfo(chargs, charid); } // We're done with the characters, request the music - this.sendServer('RM#%'); + this.sendServer("RM#%"); } /** - * Handles incoming evidence information, containing only one evidence - * item per packet. - * - * EI#id#name&description&type&image&##% - * - * @param {Array} args packet arguments - */ + * Handles incoming evidence information, containing only one evidence + * item per packet. + * + * EI#id#name&description&type&image&##% + * + * @param {Array} args packet arguments + */ handleEI(args: string[]) { - document.getElementById('client_loadingtext').innerHTML = `Loading Evidence ${args[1]}/${this.evidence_list_length}`; + document.getElementById( + "client_loadingtext" + ).innerHTML = `Loading Evidence ${args[1]}/${this.evidence_list_length}`; const evidenceID = Number(args[1]); - (document.getElementById('client_loadingbar')).value = this.char_list_length + evidenceID; - - const arg = args[2].split('&'); - this.evidences[evidenceID] = { - name: prepChat(arg[0]), - desc: prepChat(arg[1]), - filename: safeTags(arg[3]), - icon: `${AO_HOST}evidence/${encodeURI(arg[3].toLowerCase())}`, - }; - - this.sendServer('AE'+(evidenceID+1)+'#%'); + (document.getElementById("client_loadingbar")).value = + this.char_list_length + evidenceID; + + const arg = args[2].split("&"); + this.evidences[evidenceID] = { + name: prepChat(arg[0]), + desc: prepChat(arg[1]), + filename: safeTags(arg[3]), + icon: `${AO_HOST}evidence/${encodeURI(arg[3].toLowerCase())}`, + }; + + this.sendServer("AE" + (evidenceID + 1) + "#%"); } /** - * Handles incoming evidence list, all evidences at once - * item per packet. - * - * @param {Array} args packet arguments - */ + * Handles incoming evidence list, all evidences at once + * item per packet. + * + * @param {Array} args packet arguments + */ handleLE(args: string[]) { this.evidences = []; for (let i = 1; i < args.length - 1; i++) { - (document.getElementById('client_loadingbar')).value = this.char_list_length + i; - const arg = args[i].split('&'); + (( + document.getElementById("client_loadingbar") + )).value = this.char_list_length + i; + const arg = args[i].split("&"); this.evidences[i - 1] = { name: prepChat(arg[0]), desc: prepChat(arg[1]), @@ -1095,8 +1198,8 @@ class Client extends EventEmitter { }; } - const evidence_box = document.getElementById('evidences'); - evidence_box.innerHTML = ''; + const evidence_box = document.getElementById("evidences"); + evidence_box.innerHTML = ""; for (let i = 1; i <= this.evidences.length; i++) { evidence_box.innerHTML += `document.getElementById('bg_select'); - bg_select.innerHTML = ''; + const bg_select = document.getElementById("bg_select"); + bg_select.innerHTML = ""; - bg_select.add(new Option('Custom', '0')); + bg_select.add(new Option("Custom", "0")); bg_array.forEach((background: string) => { bg_select.add(new Option(background)); }); } catch (err) { - console.warn('there was no backgrounds.json file'); + console.warn("there was no backgrounds.json file"); } } @@ -1143,14 +1246,16 @@ class Client extends EventEmitter { const char_array = JSON.parse(chardata); // the try catch will fail before here when there is no file - const char_select = document.getElementById('client_ininame'); - char_select.innerHTML = ''; + const char_select = ( + document.getElementById("client_ininame") + ); + char_select.innerHTML = ""; char_array.forEach((character: string) => { char_select.add(new Option(character)); }); } catch (err) { - console.warn('there was no characters.json file'); + console.warn("there was no characters.json file"); } } @@ -1160,29 +1265,35 @@ class Client extends EventEmitter { const evi_array = JSON.parse(evidata); // the try catch will fail before here when there is no file - const evi_select = document.getElementById('evi_select'); - evi_select.innerHTML = ''; + const evi_select = ( + document.getElementById("evi_select") + ); + evi_select.innerHTML = ""; evi_array.forEach((evi: string) => { evi_select.add(new Option(evi)); }); - evi_select.add(new Option('Custom', '0')); + evi_select.add(new Option("Custom", "0")); } catch (err) { - console.warn('there was no evidence.json file'); + console.warn("there was no evidence.json file"); } } isAudio(trackname: string) { - const audioEndings = ['.wav', '.mp3', '.ogg', '.opus']; - return audioEndings.filter((ending) => trackname.endsWith(ending)).length === 1; + const audioEndings = [".wav", ".mp3", ".ogg", ".opus"]; + return ( + audioEndings.filter((ending) => trackname.endsWith(ending)).length === 1 + ); } addTrack(trackname: string) { - const newentry = document.createElement('OPTION'); + const newentry = document.createElement("OPTION"); const songName = getFilenameFromPath(trackname); newentry.text = unescapeChat(songName); newentry.value = trackname; - (document.getElementById('client_musiclist')).options.add(newentry); + (( + document.getElementById("client_musiclist") + )).options.add(newentry); this.musics.push(trackname); } @@ -1190,49 +1301,50 @@ class Client extends EventEmitter { const thisarea = { name, players: 0, - status: 'IDLE', - cm: '', - locked: 'FREE', + status: "IDLE", + cm: "", + locked: "FREE", }; this.areas.push(thisarea); // Create area button - const newarea = document.createElement('SPAN'); - newarea.className = 'area-button area-default'; + const newarea = document.createElement("SPAN"); + newarea.className = "area-button area-default"; newarea.id = `area${id}`; newarea.innerText = thisarea.name; - newarea.title = `Players: ${thisarea.players}\n` - + `Status: ${thisarea.status}\n` - + `CM: ${thisarea.cm}\n` - + `Area lock: ${thisarea.locked}`; + newarea.title = + `Players: ${thisarea.players}\n` + + `Status: ${thisarea.status}\n` + + `CM: ${thisarea.cm}\n` + + `Area lock: ${thisarea.locked}`; newarea.onclick = function () { area_click(newarea); }; - document.getElementById('areas').appendChild(newarea); + document.getElementById("areas").appendChild(newarea); } /** - * Area list fuckery - */ + * Area list fuckery + */ fix_last_area() { if (this.areas.length > 0) { const malplaced = this.areas.pop().name; - const areas = document.getElementById('areas'); + const areas = document.getElementById("areas"); areas.removeChild(areas.lastChild); this.addTrack(malplaced); } } /** - * Handles incoming music information, containing multiple entries - * per packet. - * @param {Array} args packet arguments - */ + * Handles incoming music information, containing multiple entries + * per packet. + * @param {Array} args packet arguments + */ handleEM(args: string[]) { - document.getElementById('client_loadingtext').innerHTML = 'Loading Music'; - if (args[1] === '0') { + document.getElementById("client_loadingtext").innerHTML = "Loading Music"; + if (args[1] === "0") { this.resetMusicList(); this.resetAreaList(); this.musics_time = false; @@ -1242,29 +1354,32 @@ class Client extends EventEmitter { if (i % 2 === 0) { const trackname = safeTags(args[i]); const trackindex = Number(args[i - 1]); - (document.getElementById('client_loadingbar')).value = this.char_list_length + this.evidence_list_length + trackindex; + (( + document.getElementById("client_loadingbar") + )).value = + this.char_list_length + this.evidence_list_length + trackindex; if (this.musics_time) { - this.addTrack(trackname); - } else if (this.isAudio(trackname)) { - this.musics_time = true; - this.fix_last_area(); - this.addTrack(trackname); - } else { - this.createArea(trackindex, trackname); - } + this.addTrack(trackname); + } else if (this.isAudio(trackname)) { + this.musics_time = true; + this.fix_last_area(); + this.addTrack(trackname); + } else { + this.createArea(trackindex, trackname); + } } } // get the next batch of tracks - this.sendServer(`AM#${(Number(args[1]) / 10) + 1}#%`); + this.sendServer(`AM#${Number(args[1]) / 10 + 1}#%`); } /** - * Handles incoming music information, containing all music in one packet. - * @param {Array} args packet arguments - */ + * Handles incoming music information, containing all music in one packet. + * @param {Array} args packet arguments + */ handleSM(args: string[]) { - document.getElementById('client_loadingtext').innerHTML = 'Loading Music '; + document.getElementById("client_loadingtext").innerHTML = "Loading Music "; this.resetMusicList(); this.resetAreaList(); @@ -1274,8 +1389,12 @@ class Client extends EventEmitter { // 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}/${this.music_list_length}`; - (document.getElementById('client_loadingbar')).value = this.char_list_length + this.evidence_list_length + i; + document.getElementById( + "client_loadingtext" + ).innerHTML = `Loading Music ${i}/${this.music_list_length}`; + (( + document.getElementById("client_loadingbar") + )).value = this.char_list_length + this.evidence_list_length + i; if (this.musics_time) { this.addTrack(trackname); } else if (this.isAudio(trackname)) { @@ -1288,13 +1407,13 @@ class Client extends EventEmitter { } // Music done, carry on - this.sendServer('RD#%'); + this.sendServer("RD#%"); } /** - * Handles updated music list - * @param {Array} args packet arguments - */ + * Handles updated music list + * @param {Array} args packet arguments + */ handleFM(args: string[]) { this.resetMusicList(); @@ -1305,9 +1424,9 @@ class Client extends EventEmitter { } /** - * Handles updated area list - * @param {Array} args packet arguments - */ + * Handles updated area list + * @param {Array} args packet arguments + */ handleFA(args: string[]) { this.resetAreaList(); @@ -1317,249 +1436,306 @@ class Client extends EventEmitter { } /** - * Handles the "MusicMode" packet - * @param {Array} args packet arguments - */ + * Handles the "MusicMode" packet + * @param {Array} args packet arguments + */ handleMM(_args: string[]) { // It's unused nowadays, as preventing people from changing the music is now serverside } /** - * Handles the kicked packet - * @param {string} type is it a kick or a ban - * @param {string} reason why - */ + * Handles the kicked packet + * @param {string} type is it a kick or a ban + * @param {string} reason why + */ handleBans(type: string, reason: string) { - document.getElementById('client_error').style.display = 'flex'; - document.getElementById('client_errortext').innerHTML = `${type}:
${reason.replace(/\n/g, '
')}`; - (document.getElementsByClassName('client_reconnect')[0]).style.display = 'none'; - (document.getElementsByClassName('client_reconnect')[1]).style.display = 'none'; - } - - /** - * Handles the kicked packet - * @param {Array} args kick reason - */ + document.getElementById("client_error").style.display = "flex"; + document.getElementById( + "client_errortext" + ).innerHTML = `${type}:
${reason.replace(/\n/g, "
")}`; + (( + document.getElementsByClassName("client_reconnect")[0] + )).style.display = "none"; + (( + document.getElementsByClassName("client_reconnect")[1] + )).style.display = "none"; + } + + /** + * Handles the kicked packet + * @param {Array} args kick reason + */ handleKK(args: string[]) { - this.handleBans('Kicked', safeTags(args[1])); + this.handleBans("Kicked", safeTags(args[1])); } /** - * Handles the banned packet - * this one is sent when you are kicked off the server - * @param {Array} args ban reason - */ + * Handles the banned packet + * this one is sent when you are kicked off the server + * @param {Array} args ban reason + */ handleKB(args: string[]) { - this.handleBans('Banned', safeTags(args[1])); + this.handleBans("Banned", safeTags(args[1])); banned = true; } /** - * Handles the warning packet - * on client this spawns a message box you can't close for 2 seconds - * @param {Array} args ban reason - */ - handleBB(args: string[]) { + * Handles the warning packet + * on client this spawns a message box you can't close for 2 seconds + * @param {Array} args ban reason + */ + handleBB(args: string[]) { alert(safeTags(args[1])); } /** - * Handles the banned packet - * this one is sent when you try to reconnect but you're banned - * @param {Array} args ban reason - */ + * Handles the banned packet + * this one is sent when you try to reconnect but you're banned + * @param {Array} args ban reason + */ handleBD(args: string[]) { - this.handleBans('Banned', safeTags(args[1])); + this.handleBans("Banned", safeTags(args[1])); banned = true; } /** - * Handles the handshake completion packet, meaning the player - * is ready to select a character. - * - * @param {Array} args packet arguments - */ + * Handles the handshake completion packet, meaning the player + * is ready to select a character. + * + * @param {Array} args packet arguments + */ 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'; + 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"; } } - + /** - * Handles a background change. - * @param {Array} args packet arguments - */ - + * Handles a background change. + * @param {Array} args packet arguments + */ + handleBN(args: string[]) { - viewport.bgname = safeTags(args[1]); - const bgfolder = viewport.bgFolder; - const bg_index = getIndexFromSelect('bg_select', viewport.bgname); - (document.getElementById('bg_select')).selectedIndex = bg_index; + this.viewport.bgname = safeTags(args[1]); + const bgfolder = this.viewport.bgFolder; + const bg_index = getIndexFromSelect("bg_select", this.viewport.bgname); + (document.getElementById("bg_select")).selectedIndex = + bg_index; updateBackgroundPreview(); if (bg_index === 0) { - (document.getElementById('bg_filename')).value = viewport.bgname; - } - - 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}); + (document.getElementById("bg_filename")).value = + this.viewport.bgname; + } + + 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 (this.charID === -1) { - viewport.set_side('jud',false,true); + this.viewport.set_side({ + position: "jud", + showSpeedLines: false, + showDesk: true, + }); } else { - viewport.set_side(this.chars[this.charID].side,false,true); + this.viewport.set_side({ + position: this.chars[this.charID].side, + showSpeedLines: false, + showDesk: true, + }); } } /** - * Handles a change in the health bars' states. - * @param {Array} args packet arguments - */ + * Handles a change in the health bars' states. + * @param {Array} args packet arguments + */ handleHP(args: string[]) { const percent_hp = Number(args[2]) * 10; let healthbox; - if (args[1] === '1') { + if (args[1] === "1") { // Def hp this.hp[0] = Number(args[2]); - healthbox = document.getElementById('client_defense_hp'); + healthbox = document.getElementById("client_defense_hp"); } else { // Pro hp this.hp[1] = Number(args[2]); - healthbox = document.getElementById('client_prosecutor_hp'); + healthbox = document.getElementById("client_prosecutor_hp"); } - (healthbox.getElementsByClassName('health-bar')[0]).style.width = `${percent_hp}%`; + (( + healthbox.getElementsByClassName("health-bar")[0] + )).style.width = `${percent_hp}%`; } /** - * Handles a testimony states. - * @param {Array} args packet arguments - */ + * Handles a testimony states. + * @param {Array} args packet arguments + */ handleRT(args: string[]) { const judgeid = Number(args[2]); switch (args[1]) { - case 'testimony1': + case "testimony1": this.testimonyID = 1; break; - case 'testimony2': + case "testimony2": // Cross Examination this.testimonyID = 2; break; - case 'judgeruling': + case "judgeruling": this.testimonyID = 3 + judgeid; break; default: - console.warn('Invalid testimony'); + console.warn("Invalid testimony"); } - viewport.initTestimonyUpdater(); + this.viewport.initTestimonyUpdater(); } /** - * Handles a timer update - * @param {Array} args packet arguments - */ + * Handles a timer update + * @param {Array} args packet arguments + */ 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; + document.getElementById(`client_timer${timerid}`).innerText = + timer_value; case 2: - document.getElementById(`client_timer${timerid}`).style.display = ''; + document.getElementById(`client_timer${timerid}`).style.display = ""; case 3: - document.getElementById(`client_timer${timerid}`).style.display = 'none'; + document.getElementById(`client_timer${timerid}`).style.display = + "none"; } } /** - * Handles a modcall - * @param {Array} args packet arguments - */ + * Handles a modcall + * @param {Array} args packet arguments + */ handleZZ(args: string[]) { - const oocLog = document.getElementById('client_ooclog'); + const oocLog = document.getElementById("client_ooclog"); oocLog.innerHTML += `$Alert: ${prepChat(args[1])}\r\n`; if (oocLog.scrollTop > oocLog.scrollHeight - 60) { oocLog.scrollTop = oocLog.scrollHeight; } - viewport.sfxaudio.pause(); - const oldvolume = viewport.sfxaudio.volume; - viewport.sfxaudio.volume = 1; - viewport.sfxaudio.src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - viewport.sfxaudio.play(); - viewport.sfxaudio.volume = oldvolume; + + this.viewport.sfxaudio.pause(); + const oldvolume = this.viewport.sfxaudio.volume; + this.viewport.sfxaudio.volume = 1; + this.viewport.sfxaudio.src = `${AO_HOST}sounds/general/sfx-gallery.opus`; + this.viewport.sfxaudio.play(); + this.viewport.sfxaudio.volume = oldvolume; } /** - * Handle the player - * @param {Array} args packet arguments - */ + * Handle the player + * @param {Array} args packet arguments + */ handleHI(_args: string[]) { this.sendSelf(`ID#1#webAO#${version}#%`); - this.sendSelf('FL#fastloading#yellowtext#cccc_ic_support#flipping#looping_sfx#effects#%'); + this.sendSelf( + "FL#fastloading#yellowtext#cccc_ic_support#flipping#looping_sfx#effects#%" + ); } /** - * Identifies the server and issues a playerID - * @param {Array} args packet arguments - */ + * Identifies the server and issues a playerID + * @param {Array} args packet arguments + */ handleID(args: string[]) { this.playerID = Number(args[1]); - const serverSoftware = args[2].split('&')[0]; + const serverSoftware = args[2].split("&")[0]; let serverVersion; - if (serverSoftware === 'serverD') { - serverVersion = args[2].split('&')[1]; - } else if (serverSoftware === 'webAO') { + if (serverSoftware === "serverD") { + serverVersion = args[2].split("&")[1]; + } else if (serverSoftware === "webAO") { oldLoading = false; - this.sendSelf('PN#0#1#%'); - } else { - serverVersion = args[3]; + this.sendSelf("PN#0#1#%"); + } else { + serverVersion = args[3]; } - if (serverSoftware === 'serverD' && serverVersion === '1377.152') { oldLoading = true; } // bugged version + if (serverSoftware === "serverD" && serverVersion === "1377.152") { + oldLoading = true; + } // bugged version } /** - * Indicates how many users are on this server - * @param {Array} args packet arguments - */ + * Indicates how many users are on this server + * @param {Array} args packet arguments + */ handlePN(_args: string[]) { - this.sendServer('askchaa#%'); + this.sendServer("askchaa#%"); } /** - * What? you want a character?? - * @param {Array} args packet arguments - */ + * What? you want a character?? + * @param {Array} args packet arguments + */ handleCC(args: string[]) { this.sendSelf(`PV#1#CID#${args[2]}#%`); } /** - * What? you want a character list from me?? - * @param {Array} args packet arguments - */ + * What? you want a character list from me?? + * @param {Array} args packet arguments + */ handleaskchaa(_args: string[]) { this.sendSelf(`SI#${vanilla_character_arr.length}#0#0#%`); } /** - * Handle the change of players in an area. - * @param {Array} args packet arguments - */ + * Handle the change of players in an area. + * @param {Array} args packet arguments + */ handleARUP(args: string[]) { args = args.slice(1); for (let i = 0; i < args.length - 2; i++) { - if (this.areas[i]) { // the server sends us ARUP before we even get the area list + if (this.areas[i]) { + // the server sends us ARUP before we even get the area list const thisarea = document.getElementById(`area${i}`); switch (Number(args[0])) { case 0: // playercount @@ -1576,143 +1752,158 @@ class Client extends EventEmitter { break; } - thisarea.className = `area-button area-${this.areas[i].status.toLowerCase()}`; + thisarea.className = `area-button area-${this.areas[ + i + ].status.toLowerCase()}`; thisarea.innerText = `${this.areas[i].name} (${this.areas[i].players}) [${this.areas[i].status}]`; - thisarea.title = `Players: ${this.areas[i].players}\n` - + `Status: ${this.areas[i].status}\n` - + `CM: ${this.areas[i].cm}\n` - + `Area lock: ${this.areas[i].locked}`; + thisarea.title = + `Players: ${this.areas[i].players}\n` + + `Status: ${this.areas[i].status}\n` + + `CM: ${this.areas[i].cm}\n` + + `Area lock: ${this.areas[i].locked}`; } } } /** - * 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 + */ handleFL(args: string[]) { - console.info('Server-supported features:'); + console.info("Server-supported features:"); console.info(args); extrafeatures = args; - if (args.includes('yellowtext')) { - const colorselect = document.getElementById('textcolor'); + 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'); + 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("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("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("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("effects")) { + document.getElementById("2.8").style.display = ""; } - if (args.includes('y_offset')) { - document.getElementById('y_offset').style.display = ''; + if (args.includes("y_offset")) { + document.getElementById("y_offset").style.display = ""; } } /** - * Received when the server announces its server info, - * but we use it as a cue to begin retrieving characters. - * @param {Array} args packet arguments - */ + * Received when the server announces its server info, + * but we use it as a cue to begin retrieving characters. + * @param {Array} args packet arguments + */ handleSI(args: string[]) { this.char_list_length = Number(args[1]); this.char_list_length += 1; // some servers count starting from 0 some from 1... this.evidence_list_length = Number(args[2]); this.music_list_length = Number(args[3]); - - (document.getElementById('client_loadingbar')).max = this.char_list_length + this.evidence_list_length + this.music_list_length; + + (document.getElementById("client_loadingbar")).max = + this.char_list_length + + this.evidence_list_length + + this.music_list_length; // create the charselect grid, to be filled by the character loader - document.getElementById('client_chartable').innerHTML = ''; + document.getElementById("client_chartable").innerHTML = ""; for (let i = 0; i < this.char_list_length; i++) { - const demothing = document.createElement('img'); + const demothing = document.createElement("img"); - demothing.className = 'demothing'; + demothing.className = "demothing"; demothing.id = `demo_${i}`; - const demoonclick = document.createAttribute('onclick'); + const demoonclick = document.createAttribute("onclick"); demoonclick.value = `pickChar(${i})`; demothing.setAttributeNode(demoonclick); - document.getElementById('client_chartable').appendChild(demothing); + document.getElementById("client_chartable").appendChild(demothing); } // this is determined at the top of this file - if (!oldLoading && extrafeatures.includes('fastloading')) { - this.sendServer('RC#%'); + if (!oldLoading && extrafeatures.includes("fastloading")) { + this.sendServer("RC#%"); } else { - this.sendServer('askchar2#%'); + this.sendServer("askchar2#%"); } } /** - * 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 - */ + * Handles the list of all used and vacant characters. + * @param {Array} args list of all characters represented as a 0 for free or a -1 for taken + */ handleCharsCheck(args: string[]) { for (let i = 0; i < this.char_list_length; i++) { const img = document.getElementById(`demo_${i}`); - if (args[i + 1] === '-1') { img.style.opacity = '0.25'; } else if (args[i + 1] === '0') { img.style.opacity = '1'; } + if (args[i + 1] === "-1") { + img.style.opacity = "0.25"; + } else if (args[i + 1] === "0") { + img.style.opacity = "1"; + } } } /** - * Handles the server's assignment of a character for the player to use. - * PV # playerID (unused) # CID # character ID - * @param {Array} args packet arguments - */ + * Handles the server's assignment of a character for the player to use. + * PV # playerID (unused) # CID # character ID + * @param {Array} args packet arguments + */ async handlePV(args: string[]) { this.charID = Number(args[3]); - document.getElementById('client_waiting').style.display = 'none'; - document.getElementById('client_charselect').style.display = 'none'; + document.getElementById("client_waiting").style.display = "none"; + document.getElementById("client_charselect").style.display = "none"; const me = this.chars[this.charID]; this.selectedEmote = -1; const { emotes } = this; - const emotesList = document.getElementById('client_emo'); - emotesList.style.display = ''; - emotesList.innerHTML = ''; // Clear emote box + const 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('#'); + const emoteinfo = ini.emotions[i].split("#"); let esfx; let esfxd; try { - esfx = ini.soundn[i] || '0'; + esfx = ini.soundn[i] || "0"; esfxd = Number(ini.soundt[i]) || 0; } catch (e) { - console.warn('ini sound is completly missing'); - esfx = '0'; + 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 @@ -1725,13 +1916,14 @@ class Client extends EventEmitter { 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`, + frame_screenshake: "", + frame_realization: "", + frame_sfx: "", + button: `${AO_HOST}characters/${encodeURI( + me.name.toLowerCase() + )}/emotions/button${i}_off.png`, }; - emotesList.innerHTML - += `${emotes[i].desc}document.getElementById('client_ininame'); + const iniedit_select = ( + document.getElementById("client_ininame") + ); // Load iniswaps if there are any try { - const cswapdata = await request(`${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/iniswaps.ini`); - const cswap = cswapdata.split('\n'); + const cswapdata = await request( + `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/iniswaps.ini` + ); + const cswap = cswapdata.split("\n"); // most iniswaps don't list their original char if (cswap.length > 0) { - iniedit_select.innerHTML = ''; + iniedit_select.innerHTML = ""; iniedit_select.add(new Option(safeTags(me.name))); - cswap.forEach((inisw: string) => iniedit_select.add(new Option(safeTags(inisw)))); + cswap.forEach((inisw: string) => + iniedit_select.add(new Option(safeTags(inisw))) + ); } } catch (err) { console.info("character doesn't have iniswaps"); @@ -1767,837 +1973,43 @@ class Client extends EventEmitter { } /** - * new asset url!! - * @param {Array} args packet arguments - */ - handleASS(args: string[]) { + * new asset url!! + * @param {Array} args packet arguments + */ + handleASS(args: string[]) { AO_HOST = args[1]; } /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ handleRC(_args: string[]) { - this.sendSelf(`SC#${vanilla_character_arr.join('#')}#%`); + this.sendSelf(`SC#${vanilla_character_arr.join("#")}#%`); } /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ handleRM(_args: string[]) { - this.sendSelf(`SM#${vanilla_music_arr.join('#')}#%`); + this.sendSelf(`SM#${vanilla_music_arr.join("#")}#%`); } /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ handleRD(_args: string[]) { - this.sendSelf('BN#gs4#%'); - this.sendSelf('DONE#%'); - const ooclog = document.getElementById('client_ooclog'); - ooclog.value = ''; + this.sendSelf("BN#gs4#%"); + this.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'; - } -} - -class Viewport { - textnow: string; - chatmsg: any; - shouts: string[]; - colors: string[]; - blipChannels: any; - currentBlipChannel: number; - sfxaudio: any; - sfxplayed: number; - shoutaudio: any; - testimonyAudio: any; - music: any; - updater: any; - testimonyUpdater: any; - bgname: string; - lastChar: string; - lastEvi: number; - testimonyTimer: number; - shoutTimer: number; - tickTimer: number; - _animating: boolean; - startFirstTickCheck: boolean; - startSecondTickCheck: boolean; - startThirdTickCheck: boolean; - theme: string; - - constructor() { - this.textnow = ''; - this.chatmsg = { - content: '', - objection: 0, - sound: '', - startpreanim: true, - startspeaking: false, - side: null, - color: 0, - snddelay: 0, - preanimdelay: 0, - speed: UPDATE_INTERVAL - }; - - this.shouts = [ - undefined, - 'holdit', - 'objection', - 'takethat', - 'custom', - ]; - - this.colors = [ - 'white', - 'green', - 'red', - 'orange', - 'blue', - 'yellow', - 'pink', - 'cyan', - 'grey', - ]; - - // Allocate multiple blip audio channels to make blips less jittery - const blipSelectors = document.getElementsByClassName('blipSound') - this.blipChannels = [...blipSelectors]; - this.blipChannels.forEach((channel: HTMLAudioElement) => channel.volume = 0.5); - this.blipChannels.forEach((channel: HTMLAudioElement) => channel.onerror = opusCheck(channel)); - this.currentBlipChannel = 0; - - this.sfxaudio = document.getElementById('client_sfxaudio'); - this.sfxaudio.src = `${AO_HOST}sounds/general/sfx-realization.opus`; - - this.sfxplayed = 0; - - this.shoutaudio = document.getElementById('client_shoutaudio'); - this.shoutaudio.src = `${AO_HOST}misc/default/objection.opus`; - - this.testimonyAudio = document.getElementById('client_testimonyaudio'); - this.testimonyAudio.src = `${AO_HOST}sounds/general/sfx-guilty.opus`; - - const audioChannels = document.getElementsByClassName('audioChannel') - this.music = [...audioChannels]; - this.music.forEach((channel: HTMLAudioElement) => channel.volume = 0.5); - this.music.forEach((channel: HTMLAudioElement) => channel.onerror = opusCheck(channel)); - - this.updater = null; - this.testimonyUpdater = null; - - this.bgname = 'gs4'; - - this.lastChar = ''; - this.lastEvi = 0; - - this.testimonyTimer = 0; - this.shoutTimer = 0; - this.tickTimer = 0; - - this._animating = false; - } - - /** - * Sets the volume of the music. - * @param {number} volume - */ - set musicVolume(volume: number) { - this.music.forEach((channel: HTMLAudioElement) => channel.volume = volume); - } - - /** - * Returns the path which the background is located in. - */ - get bgFolder() { - return `${AO_HOST}background/${encodeURI(this.bgname.toLowerCase())}/`; - } - - /** - * Play any SFX - * - * @param {string} sfxname - */ - async playSFX(sfxname: string, looping: boolean) { - this.sfxaudio.pause(); - this.sfxaudio.loop = looping; - this.sfxaudio.src = sfxname; - this.sfxaudio.play(); - } - - /** - * Changes the viewport background based on a given position. - * - * Valid positions: `def, pro, hld, hlp, wit, jud, jur, sea` - * @param {string} position the position to change into - */ - async set_side(position: string, showspeedlines: boolean, showdesk: boolean) { - const bgfolder = viewport.bgFolder; - - const view = document.getElementById('client_fullview'); - - let bench: HTMLImageElement; - if ('def,pro,wit'.includes(position)) { - bench = document.getElementById(`client_${position}_bench`); - } else { - bench = document.getElementById('client_bench_classic'); - } - - let court: HTMLImageElement; - if ('def,pro,wit'.includes(position)) { - court = document.getElementById(`client_court_${position}`); - } else { - court = document.getElementById('client_court_classic'); - } - - interface Desk { - ao2?: string - ao1?: string - } - interface Position { - bg?: string - desk?: Desk - speedLines: string - } - - interface Positions { - [key: string]: Position - } - - const positions: Positions = { - def: { - bg: 'defenseempty', - desk: { ao2: 'defensedesk.png', ao1: 'bancodefensa.png' } as Desk, - speedLines: 'defense_speedlines.gif', - }, - pro: { - bg: 'prosecutorempty', - desk: { ao2: 'prosecutiondesk.png', ao1: 'bancoacusacion.png' } as Desk, - speedLines: 'prosecution_speedlines.gif', - }, - hld: { - bg: 'helperstand', - desk: null as Desk, - speedLines: 'defense_speedlines.gif', - }, - hlp: { - bg: 'prohelperstand', - desk: null as Desk, - speedLines: 'prosecution_speedlines.gif', - }, - wit: { - bg: 'witnessempty', - desk: { ao2: 'stand.png', ao1: 'estrado.png' } as Desk, - speedLines: 'prosecution_speedlines.gif', - }, - jud: { - bg: 'judgestand', - desk: { ao2: 'judgedesk.png', ao1: 'judgedesk.gif' } as Desk, - speedLines: 'prosecution_speedlines.gif', - }, - jur: { - bg: 'jurystand', - desk: { ao2: 'jurydesk.png', ao1: 'estrado.png' } as Desk, - speedLines: 'defense_speedlines.gif', - }, - sea: { - bg: 'seancestand', - desk: { ao2: 'seancedesk.png', ao1: 'estrado.png' } as Desk, - speedLines: 'prosecution_speedlines.gif', - }, - }; - - let bg; - let desk; - let speedLines; - - if ('def,pro,hld,hlp,wit,jud,jur,sea'.includes(position)) { - bg = positions[position].bg; - desk = positions[position].desk; - speedLines = positions[position].speedLines; - } else { - bg = `${position}`; - desk = { ao2: `${position}_overlay.png`, ao1: '_overlay.png' }; - speedLines = 'defense_speedlines.gif'; - } - - if (showspeedlines === true) { - court.src = `${AO_HOST}themes/default/${encodeURI(speedLines)}`; - } else { - court.src = await tryUrls(bgfolder + bg) - } - - if (showdesk === true && desk) { - const deskFilename = await fileExists(bgfolder + desk.ao2) ? desk.ao2 : desk.ao1; - bench.src = bgfolder + deskFilename; - bench.style.opacity = '1'; - } else { - bench.style.opacity = '0'; - } - - if ('def,pro,wit'.includes(position)) { - view.style.display = ''; - document.getElementById('client_classicview').style.display = 'none'; - switch (position) { - case 'def': - view.style.left = '0'; - break; - case 'wit': - view.style.left = '-200%'; - break; - case 'pro': - view.style.left = '-400%'; - break; - } - } else { - view.style.display = 'none'; - document.getElementById('client_classicview').style.display = ''; - } - } - - /** - * Intialize testimony updater - */ - initTestimonyUpdater() { - - const testimonyFilenames: Testimony = { - 1: 'witnesstestimony', - 2: 'crossexamination', - 3: 'notguilty', - 4: 'guilty', - }; - - const testimony = testimonyFilenames[client.testimonyID]; - if (!testimony) { - console.warn(`Invalid testimony ID ${client.testimonyID}`); - return; - } - - this.testimonyAudio.src = client.resources[testimony].sfx; - this.testimonyAudio.play(); - - const testimonyOverlay = document.getElementById('client_testimony'); - testimonyOverlay.src = client.resources[testimony].src; - testimonyOverlay.style.opacity = '1'; - - this.testimonyTimer = 0; - this.testimonyUpdater = setTimeout(() => this.updateTestimony(), UPDATE_INTERVAL); - } - - /** - * Updates the testimony overaly - */ - updateTestimony() { - const testimonyFilenames: Testimony = { - 1: 'witnesstestimony', - 2: 'crossexamination', - 3: 'notguilty', - 4: 'guilty', - }; - - // Update timer - this.testimonyTimer += UPDATE_INTERVAL; - - const testimony = testimonyFilenames[client.testimonyID]; - const resource = client.resources[testimony]; - if (!resource) { - this.disposeTestimony(); - return; - } - - if (this.testimonyTimer >= resource.duration) { - this.disposeTestimony(); - } else { - this.testimonyUpdater = setTimeout(() => this.updateTestimony(), UPDATE_INTERVAL); - } - } - - /** - * Dispose the testimony overlay - */ - disposeTestimony() { - client.testimonyID = 0; - this.testimonyTimer = 0; - document.getElementById('client_testimony').style.opacity = '0'; - clearTimeout(this.testimonyUpdater); - } - - /** - * Sets a new emote. - * This sets up everything before the tick() loops starts - * a lot of things can probably be moved here, like starting the shout animation if there is one - * TODO: the preanim logic, on the other hand, should probably be moved to tick() - * @param {object} chatmsg the new chat message - */ - async handle_ic_speaking(chatmsg: any) { - - this.chatmsg = chatmsg; - this.textnow = ''; - this.sfxplayed = 0; - this.tickTimer = 0; - this._animating = true; - this.startFirstTickCheck = true - this.startSecondTickCheck = false - this.startThirdTickCheck = false - let charLayers = document.getElementById('client_char'); - let pairLayers = document.getElementById('client_pair_char'); - - // stop updater - clearTimeout(this.updater); - - // stop last sfx from looping any longer - this.sfxaudio.loop = false; - - const fg = document.getElementById('client_fg'); - const gamewindow = document.getElementById('client_gamewindow'); - const waitingBox = document.getElementById('client_chatwaiting'); - - // Reset CSS animation - gamewindow.style.animation = ''; - waitingBox.style.opacity = '0'; - - const eviBox = document.getElementById('client_evi'); - - if (this.lastEvi !== this.chatmsg.evidence) { - eviBox.style.opacity = '0'; - eviBox.style.height = '0%'; - } - this.lastEvi = this.chatmsg.evidence; - - const validSides: string[] = ['def', 'pro', 'wit']; // these are for the full view pan, the other positions use 'client_char' - if (validSides.includes(this.chatmsg.side)) { - charLayers = document.getElementById(`client_${this.chatmsg.side}_char`); - pairLayers = document.getElementById(`client_${this.chatmsg.side}_pair_char`); - } - - const chatContainerBox = document.getElementById('client_chatcontainer'); - const nameBoxInner = document.getElementById('client_inner_name'); - const chatBoxInner = document.getElementById('client_inner_chat'); - - const displayname = ((document.getElementById('showname')).checked && this.chatmsg.showname !== '') ? this.chatmsg.showname : this.chatmsg.nameplate; - - // Clear out the last message - chatBoxInner.innerText = this.textnow; - nameBoxInner.innerText = displayname; - - if (this.lastChar !== this.chatmsg.name) { - charLayers.style.opacity = '0'; - pairLayers.style.opacity = '0'; - } - this.lastChar = this.chatmsg.name; - - appendICLog(this.chatmsg.content, this.chatmsg.showname, this.chatmsg.nameplate); - - checkCallword(this.chatmsg.content); - - setEmote(AO_HOST, this, this.chatmsg.name.toLowerCase(), this.chatmsg.sprite, '(a)', false, this.chatmsg.side); - - if (this.chatmsg.other_name) { - setEmote(AO_HOST, this, this.chatmsg.other_name.toLowerCase(), this.chatmsg.other_emote, '(a)', false, this.chatmsg.side); - } - - // gets which shout shall played - const shoutSprite = document.getElementById('client_shout'); - const shout = this.shouts[this.chatmsg.objection]; - if (shout) { - // Hide message box - chatContainerBox.style.opacity = '0'; - if (this.chatmsg.objection === 4) { - shoutSprite.src = `${AO_HOST}characters/${encodeURI(this.chatmsg.name.toLowerCase())}/custom.gif`; - } else { - shoutSprite.src = client.resources[shout].src; - shoutSprite.style.animation = 'bubble 700ms steps(10, jump-both)'; - } - shoutSprite.style.opacity = '1'; - - this.shoutaudio.src = `${AO_HOST}characters/${encodeURI(this.chatmsg.name.toLowerCase())}/${shout}.opus`; - this.shoutaudio.play(); - this.shoutTimer = client.resources[shout].duration; - } else { - this.shoutTimer = 0; - } - - this.chatmsg.startpreanim = true; - let gifLength = 0; - - if (this.chatmsg.type === 1 && this.chatmsg.preanim !== '-') { //we have a preanim - chatContainerBox.style.opacity = '0'; - gifLength = await getAnimLength(`${AO_HOST}characters/${encodeURI(this.chatmsg.name.toLowerCase())}/${encodeURI(this.chatmsg.preanim)}`); - console.debug("preanim is "+gifLength+" long"); - this.chatmsg.startspeaking = false; - } else { - this.chatmsg.startspeaking = true; - if(this.chatmsg.content !== "") - chatContainerBox.style.opacity = '1'; - } - this.chatmsg.preanimdelay = gifLength; - - let skipoffset: boolean = false; - if (chatmsg.type === 5) { - this.set_side(chatmsg.side,true,false); - } else { - switch(Number(chatmsg.deskmod)) { - case 0: //desk is hidden - this.set_side(chatmsg.side,false,false); - break; - case 1: //desk is shown - this.set_side(chatmsg.side,false,true); - break; - case 2: //desk is hidden during preanim, but shown during idle/talk - this.set_side(chatmsg.side,false,false); - break; - case 3: //opposite of 2 - this.set_side(chatmsg.side,false,false); - break; - case 4: //desk is hidden, character offset is ignored, pair character is hidden during preanim, normal behavior during idle/talk - this.set_side(chatmsg.side,false,false); - skipoffset = true; - break; - case 5: //opposite of 4 - this.set_side(chatmsg.side,false,true); - break; - default: - this.set_side(chatmsg.side,false,true); - break; - } - } - - setChatbox(chatmsg.chatbox); - resizeChatbox(); - - if (!skipoffset) { - // Flip the character - charLayers.style.transform = this.chatmsg.flip === 1 ? 'scaleX(-1)' : 'scaleX(1)'; - pairLayers.style.transform = this.chatmsg.other_flip === 1 ? 'scaleX(-1)' : 'scaleX(1)'; - - // Shift by the horizontal offset - switch (this.chatmsg.side) { - case 'wit': - pairLayers.style.left = `${200 + Number(this.chatmsg.other_offset[0])}%`; - charLayers.style.left = `${200 + Number(this.chatmsg.self_offset[0])}%`; - break; - case 'pro': - pairLayers.style.left = `${400 + Number(this.chatmsg.other_offset[0])}%`; - charLayers.style.left = `${400 + Number(this.chatmsg.self_offset[0])}%`; - break; - default: - pairLayers.style.left = `${Number(this.chatmsg.other_offset[0])}%`; - charLayers.style.left = `${Number(this.chatmsg.self_offset[0])}%`; - break; - } - - // New vertical offsets - pairLayers.style.top = `${Number(this.chatmsg.other_offset[1])}%`; - charLayers.style.top = `${Number(this.chatmsg.self_offset[1])}%`; - - } - - this.blipChannels.forEach((channel: HTMLAudioElement) => channel.src = `${AO_HOST}sounds/general/sfx-blip${encodeURI(this.chatmsg.blips.toLowerCase())}.opus`); - - // process markup - if (this.chatmsg.content.startsWith('~~')) { - chatBoxInner.style.textAlign = 'center'; - this.chatmsg.content = this.chatmsg.content.substring(2, this.chatmsg.content.length); - } else { - chatBoxInner.style.textAlign = 'inherit'; - } - - // apply effects - fg.style.animation = ''; - const badEffects = ['', '-', 'none']; - if (this.chatmsg.effects[0] && !badEffects.includes(this.chatmsg.effects[0].toLowerCase())) { - const baseEffectUrl = `${AO_HOST}themes/default/effects/`; - fg.src = `${baseEffectUrl}${encodeURI(this.chatmsg.effects[0].toLowerCase())}.webp`; - } else { - - fg.src = transparentPng; - } - - charLayers.style.opacity = '1'; - - const soundChecks = ['0', '1', '', undefined]; - if (soundChecks.some((check) => this.chatmsg.sound === check)) { - this.chatmsg.sound = this.chatmsg.effects[2]; - } - this.chatmsg.parsed = await attorneyMarkdown.applyMarkdown(chatmsg.content, this.colors[this.chatmsg.color]) - this.chat_tick(); - } - - async handleTextTick(charLayers: HTMLImageElement) { - const chatBox = document.getElementById('client_chat'); - const waitingBox = document.getElementById('client_chatwaiting'); - const chatBoxInner = document.getElementById('client_inner_chat'); - const charName = this.chatmsg.name.toLowerCase(); - const charEmote = this.chatmsg.sprite.toLowerCase(); - - - if (this.chatmsg.content.charAt(this.textnow.length) !== ' ') { - this.blipChannels[this.currentBlipChannel].play(); - this.currentBlipChannel++; - this.currentBlipChannel %= this.blipChannels.length; - } - this.textnow = this.chatmsg.content.substring(0, this.textnow.length + 1); - const characterElement = this.chatmsg.parsed[this.textnow.length - 1] - if (characterElement) { - const COMMAND_IDENTIFIER = '\\' - - const nextCharacterElement = this.chatmsg.parsed[this.textnow.length] - const flash = async () => { - const effectlayer = document.getElementById('client_fg'); - this.playSFX(`${AO_HOST}sounds/general/sfx-realization.opus`, false); - effectlayer.style.animation = 'flash 0.4s 1'; - await delay(400) - effectlayer.style.removeProperty('animation') - } - - const shake = async () => { - const gamewindow = document.getElementById('client_gamewindow'); - this.playSFX(`${AO_HOST}sounds/general/sfx-stab.opus`, false); - gamewindow.style.animation = 'shake 0.2s 1'; - await delay(200) - gamewindow.style.removeProperty('animation') - } - - const commands = new Map(Object.entries({ - 's': shake, - 'f': flash - })) - const textSpeeds = new Set(['{', '}']) - - // Changing Text Speed - if (textSpeeds.has(characterElement.innerHTML)) { - // Grab them all in a row - const MAX_SLOW_CHATSPEED = 120 - for(let i = this.textnow.length; i < this.chatmsg.content.length; i++) { - const currentCharacter = this.chatmsg.parsed[i - 1].innerHTML - if (currentCharacter === '}') { - if (this.chatmsg.speed > 0) { - this.chatmsg.speed -= 20 - } - } else if(currentCharacter === '{') { - if(this.chatmsg.speed < MAX_SLOW_CHATSPEED) { - this.chatmsg.speed += 20 - } - } else { - // No longer at a speed character - this.textnow = this.chatmsg.content.substring(0, i); - break - } - } - } - - if (characterElement.innerHTML === COMMAND_IDENTIFIER && commands.has(nextCharacterElement?.innerHTML)) { - this.textnow = this.chatmsg.content.substring(0, this.textnow.length + 1); - await commands.get(nextCharacterElement.innerHTML)() - } else { - chatBoxInner.appendChild(this.chatmsg.parsed[this.textnow.length - 1]); - } - } - - // scroll to bottom - chatBox.scrollTop = chatBox.scrollHeight; - - if (this.textnow === this.chatmsg.content) { - this._animating = false; - setEmote(AO_HOST, this, charName, charEmote, '(a)', false, this.chatmsg.side); - charLayers.style.opacity = '1'; - waitingBox.style.opacity = '1'; - clearTimeout(this.updater); - } - } - /** - * Updates the chatbox based on the given text. - * - * OK, here's the documentation on how this works: - * - * 1 _animating - * If we're not done with this characters animation, i.e. his text isn't fully there, set a timeout for the next tick/step to happen - * - * 2 startpreanim - * If the shout timer is over it starts with the preanim - * The first thing it checks for is the shake effect (TODO on client this is handled by the @ symbol and not a flag ) - * Then is the flash/realization effect - * After that, the shout image set to be transparent - * and the main characters preanim gif is loaded - * If pairing is supported the paired character will just stand around with his idle sprite - * - * 3 preanimdelay over - * this animates the evidence popup and finally shows the character name and message box - * it sets the text color and the character speaking sprite - * - * 4 textnow != content - * this adds a character to the textbox and stops the animations if the entire message is present in the textbox - * - * 5 sfx - * independent of the stuff above, this will play any sound effects specified by the emote the character sent. - * happens after the shout delay + an sfx delay that comes with the message packet - * - * XXX: This relies on a global variable `this.chatmsg`! - */ - async chat_tick() { - // note: this is called fairly often - // do not perform heavy operations here - - await delay(this.chatmsg.speed) - - if (this.textnow === this.chatmsg.content) { - return - } - - const gamewindow = document.getElementById('client_gamewindow'); - const waitingBox = document.getElementById('client_chatwaiting'); - const eviBox = document.getElementById('client_evi'); - const shoutSprite = document.getElementById('client_shout'); - const effectlayer = document.getElementById('client_fg'); - const chatBoxInner = document.getElementById('client_inner_chat'); - let charLayers = document.getElementById('client_char'); - let pairLayers = document.getElementById('client_pair_char'); - - const validSides: string[] = ['def', 'pro', 'wit']; // these are for the full view pan, the other positions use 'client_char' - if (validSides.includes(this.chatmsg.side)) { - charLayers = document.getElementById(`client_${this.chatmsg.side}_char`); - pairLayers = document.getElementById(`client_${this.chatmsg.side}_pair_char`); - } - - const charName = this.chatmsg.name.toLowerCase(); - const charEmote = this.chatmsg.sprite.toLowerCase(); - - const pairName = this.chatmsg.other_name.toLowerCase(); - const pairEmote = this.chatmsg.other_emote.toLowerCase(); - - // TODO: preanims sometimes play when they're not supposed to - const isShoutOver = this.tickTimer >= this.shoutTimer - const isShoutAndPreanimOver = this.tickTimer >= this.shoutTimer + this.chatmsg.preanimdelay - if (isShoutOver && this.startFirstTickCheck) { - // Effect stuff - if (this.chatmsg.screenshake === 1) { - // Shake screen - this.playSFX(`${AO_HOST}sounds/general/sfx-stab.opus`, false); - gamewindow.style.animation = 'shake 0.2s 1'; - } - if (this.chatmsg.flash === 1) { - // Flash screen - this.playSFX(`${AO_HOST}sounds/general/sfx-realization.opus`, false); - effectlayer.style.animation = 'flash 0.4s 1'; - } - - // Pre-animation stuff - if (this.chatmsg.preanimdelay > 0) { - shoutSprite.style.opacity = '0'; - shoutSprite.style.animation = ''; - const preanim = this.chatmsg.preanim.toLowerCase(); - setEmote(AO_HOST, this, charName, preanim, '', false, this.chatmsg.side); - } - - if (this.chatmsg.other_name) { - pairLayers.style.opacity = '1'; - } else { - pairLayers.style.opacity = '0'; - } - // Done with first check, move to second - this.startFirstTickCheck = false - this.startSecondTickCheck = true - - this.chatmsg.startpreanim = false; - this.chatmsg.startspeaking = true; - } - - const hasNonInterruptingPreAnim = this.chatmsg.noninterrupting_preanim === 1 - if (this.textnow !== this.chatmsg.content && hasNonInterruptingPreAnim) { - const chatContainerBox = document.getElementById('client_chatcontainer'); - chatContainerBox.style.opacity = '1'; - await this.handleTextTick(charLayers) - - }else if (isShoutAndPreanimOver && this.startSecondTickCheck) { - if (this.chatmsg.startspeaking) { - this.chatmsg.startspeaking = false; - - // Evidence Bullshit - if (this.chatmsg.evidence > 0) { - // Prepare evidence - eviBox.src = safeTags(client.evidences[this.chatmsg.evidence - 1].icon); - - eviBox.style.width = 'auto'; - eviBox.style.height = '36.5%'; - eviBox.style.opacity = '1'; - - this.testimonyAudio.src = `${AO_HOST}sounds/general/sfx-evidenceshoop.opus`; - this.testimonyAudio.play(); - - if (this.chatmsg.side === 'def') { - // Only def show evidence on right - eviBox.style.right = '1em'; - eviBox.style.left = 'initial'; - } else { - eviBox.style.right = 'initial'; - eviBox.style.left = '1em'; - } - } - chatBoxInner.className = `text_${this.colors[this.chatmsg.color]}`; - - - if (this.chatmsg.preanimdelay === 0) { - shoutSprite.style.opacity = '0'; - shoutSprite.style.animation = ''; - } - - switch(Number(this.chatmsg.deskmod)) { - case 2: - this.set_side(this.chatmsg.side,false,true); - break; - case 3: - this.set_side(this.chatmsg.side,false,false); - break; - case 4: - this.set_side(this.chatmsg.side,false,true); - break; - case 5: - this.set_side(this.chatmsg.side,false,false); - break; - } - - if (this.chatmsg.other_name) { - setEmote(AO_HOST, this, pairName, pairEmote, '(a)', true, this.chatmsg.side); - pairLayers.style.opacity = '1'; - } else { - pairLayers.style.opacity = '0'; - } - - setEmote(AO_HOST, this, charName, charEmote, '(b)', false, this.chatmsg.side); - charLayers.style.opacity = '1'; - - if (this.textnow === this.chatmsg.content) { - setEmote(AO_HOST, this, charName, charEmote, '(a)', false, this.chatmsg.side); - charLayers.style.opacity = '1'; - waitingBox.style.opacity = '1'; - this._animating = false; - clearTimeout(this.updater); - return - } - } else if (this.textnow !== this.chatmsg.content) { - const chatContainerBox = document.getElementById('client_chatcontainer'); - chatContainerBox.style.opacity = '1'; - await this.handleTextTick(charLayers) - } - } - - if (!this.sfxplayed && this.chatmsg.snddelay + this.shoutTimer >= this.tickTimer) { - this.sfxplayed = 1; - if (this.chatmsg.sound !== '0' && this.chatmsg.sound !== '1' && this.chatmsg.sound !== '' && this.chatmsg.sound !== undefined && (this.chatmsg.type == 1 || this.chatmsg.type == 2 || this.chatmsg.type == 6)) { - this.playSFX(`${AO_HOST}sounds/general/${encodeURI(this.chatmsg.sound.toLowerCase())}.opus`, this.chatmsg.looping_sfx); - } - } - if (this._animating) { - this.chat_tick() - } - this.tickTimer += UPDATE_INTERVAL; + document.getElementById("client_oocinput").style.display = "none"; + document.getElementById("client_replaycontrols").style.display = + "inline-block"; } } @@ -2607,8 +2019,11 @@ class Viewport { */ export function onOOCEnter(event: KeyboardEvent) { if (event.keyCode === 13) { - client.sendOOC((document.getElementById('client_oocinputbox')).value); - (document.getElementById('client_oocinputbox')).value = ''; + client.sendOOC( + (document.getElementById("client_oocinputbox")).value + ); + (document.getElementById("client_oocinputbox")).value = + ""; } } window.onOOCEnter = onOOCEnter; @@ -2631,34 +2046,63 @@ export function onEnter(event: KeyboardEvent) { const mychar = client.character; const myemo = client.emote; const evi = client.evidence; - const flip = Boolean((document.getElementById('button_flip').classList.contains('dark'))); - const flash = Boolean((document.getElementById('button_flash').classList.contains('dark'))); - const screenshake = Boolean((document.getElementById('button_shake').classList.contains('dark'))); - const noninterrupting_preanim = Boolean(((document.getElementById('check_nonint')).checked)); - const looping_sfx = Boolean(((document.getElementById('check_loopsfx')).checked)); - const color = Number((document.getElementById('textcolor')).value); - const showname = escapeChat((document.getElementById('ic_chat_name')).value); - const text = (document.getElementById('client_inputbox')).value; - const pairchar = (document.getElementById('pair_select')).value; - const pairoffset = Number((document.getElementById('pair_offset')).value); - const pairyoffset = Number((document.getElementById('pair_y_offset')).value); - const myrole = (document.getElementById('role_select')).value ? (document.getElementById('role_select')).value : mychar.side; - const additive = Boolean(((document.getElementById('check_additive')).checked)); - const effect = (document.getElementById('effect_select')).value; - - let sfxname = '0'; + const flip = Boolean( + document.getElementById("button_flip").classList.contains("dark") + ); + const flash = Boolean( + document.getElementById("button_flash").classList.contains("dark") + ); + const screenshake = Boolean( + document.getElementById("button_shake").classList.contains("dark") + ); + const noninterrupting_preanim = Boolean( + (document.getElementById("check_nonint")).checked + ); + const looping_sfx = Boolean( + (document.getElementById("check_loopsfx")).checked + ); + const color = Number( + (document.getElementById("textcolor")).value + ); + const showname = escapeChat( + (document.getElementById("ic_chat_name")).value + ); + const text = (document.getElementById("client_inputbox")) + .value; + const pairchar = (document.getElementById("pair_select")) + .value; + const pairoffset = Number( + (document.getElementById("pair_offset")).value + ); + const pairyoffset = Number( + (document.getElementById("pair_y_offset")).value + ); + const myrole = (document.getElementById("role_select")) + .value + ? (document.getElementById("role_select")).value + : mychar.side; + const additive = Boolean( + (document.getElementById("check_additive")).checked + ); + const effect = (document.getElementById("effect_select")) + .value; + + let sfxname = "0"; let sfxdelay = 0; let emote_mod = myemo.zoom; - if ((document.getElementById('sendsfx')).checked) { + if ((document.getElementById("sendsfx")).checked) { sfxname = myemo.sfx; sfxdelay = myemo.sfxdelay; } // not to overwrite a 5 from the ini or anything else - if ((document.getElementById('sendpreanim')).checked) { - if (emote_mod === 0) { emote_mod = 1; } - } else if (emote_mod === 1) { emote_mod = 0; } - + if ((document.getElementById("sendpreanim")).checked) { + if (emote_mod === 0) { + emote_mod = 1; + } + } else if (emote_mod === 1) { + emote_mod = 0; + } client.sendIC( myemo.deskmod, @@ -2682,11 +2126,11 @@ export function onEnter(event: KeyboardEvent) { noninterrupting_preanim, looping_sfx, screenshake, - '-', - '-', - '-', + "-", + "-", + "-", additive, - effect, + effect ); } return false; @@ -2699,22 +2143,23 @@ window.onEnter = onEnter; * was successfully sent/presented. */ function resetICParams() { - (document.getElementById('client_inputbox')).value = ''; - document.getElementById('button_flash').className = 'client_button'; - document.getElementById('button_shake').className = 'client_button'; + (document.getElementById("client_inputbox")).value = ""; + document.getElementById("button_flash").className = "client_button"; + document.getElementById("button_shake").className = "client_button"; - (document.getElementById('sendpreanim')).checked = false; - (document.getElementById('sendsfx')).checked = false; + (document.getElementById("sendpreanim")).checked = false; + (document.getElementById("sendsfx")).checked = false; if (selectedShout) { - document.getElementById(`button_${selectedShout}`).className = 'client_button'; + document.getElementById(`button_${selectedShout}`).className = + "client_button"; selectedShout = 0; } } export function resetOffset(_event: Event) { - (document.getElementById('pair_offset')).value = '0'; - (document.getElementById('pair_y_offset')).value = '0'; + (document.getElementById("pair_offset")).value = "0"; + (document.getElementById("pair_y_offset")).value = "0"; } window.resetOffset = resetOffset; @@ -2723,14 +2168,18 @@ window.resetOffset = resetOffset; * @param {MouseEvent} event */ export function musiclist_filter(_event: Event) { - const musiclist_element = document.getElementById('client_musiclist'); - const searchname = (document.getElementById('client_musicsearch')).value; + const musiclist_element = ( + document.getElementById("client_musiclist") + ); + const searchname = (( + document.getElementById("client_musicsearch") + )).value; - musiclist_element.innerHTML = ''; + musiclist_element.innerHTML = ""; for (const trackname of client.musics) { if (trackname.toLowerCase().indexOf(searchname.toLowerCase()) !== -1) { - const newentry = document.createElement('OPTION'); + const newentry = document.createElement("OPTION"); newentry.text = trackname; musiclist_element.options.add(newentry); } @@ -2743,12 +2192,16 @@ window.musiclist_filter = musiclist_filter; * @param {MouseEvent} event */ export function musiclist_click(_event: Event) { - const playtrack = (document.getElementById('client_musiclist')).value; + const playtrack = (( + document.getElementById("client_musiclist") + )).value; client.sendMusicChange(playtrack); // This is here so you can't actually select multiple tracks, // even though the select tag has the multiple option to render differently - const musiclist_elements = (document.getElementById('client_musiclist')).selectedOptions; + const musiclist_elements = (( + document.getElementById("client_musiclist") + )).selectedOptions; for (let i = 0; i < musiclist_elements.length; i++) { musiclist_elements[i].selected = false; } @@ -2760,12 +2213,14 @@ window.musiclist_click = musiclist_click; * @param {MouseEvent} event */ export function mutelist_click(_event: Event) { - const mutelist = document.getElementById('mute_select'); + const mutelist = document.getElementById("mute_select"); const selected_character = mutelist.options[mutelist.selectedIndex]; if (client.chars[selected_character.value].muted === false) { client.chars[selected_character.value].muted = true; - selected_character.text = `${client.chars[selected_character.value].name} (muted)`; + selected_character.text = `${ + client.chars[selected_character.value].name + } (muted)`; console.info(`muted ${client.chars[selected_character.value].name}`); } else { client.chars[selected_character.value].muted = false; @@ -2779,12 +2234,22 @@ window.mutelist_click = mutelist_click; * @param {MouseEvent} event */ export function showname_click(_event: Event) { - setCookie('showname', String((document.getElementById('showname')).checked)); - setCookie('ic_chat_name', (document.getElementById('ic_chat_name')).value); + setCookie( + "showname", + String((document.getElementById("showname")).checked) + ); + setCookie( + "ic_chat_name", + (document.getElementById("ic_chat_name")).value + ); - const css_s = document.getElementById('nameplate_setting'); + const css_s = document.getElementById("nameplate_setting"); - if ((document.getElementById('showname')).checked) { css_s.href = 'styles/shownames.css'; } else { css_s.href = 'styles/nameplates.css'; } + if ((document.getElementById("showname")).checked) { + css_s.href = "styles/shownames.css"; + } else { + css_s.href = "styles/nameplates.css"; + } } window.showname_click = showname_click; @@ -2796,48 +2261,21 @@ export function area_click(el: HTMLElement) { const area = client.areas[el.id.substr(4)].name; client.sendMusicChange(area); - const areaHr = document.createElement('div'); - areaHr.className = 'hrtext'; + const areaHr = document.createElement("div"); + areaHr.className = "hrtext"; areaHr.textContent = `switched to ${el.textContent}`; - document.getElementById('client_log').appendChild(areaHr); + document.getElementById("client_log").appendChild(areaHr); } window.area_click = area_click; -/** - * Triggered by the music volume slider. - */ -export function changeMusicVolume() { - viewport.musicVolume = Number((document.getElementById('client_mvolume')).value); - setCookie('musicVolume', String(viewport.musicVolume)); -} -window.changeMusicVolume = changeMusicVolume; - -/** - * Triggered by the blip volume slider. - */ -export function changeBlipVolume() { - const blipVolume = (document.getElementById('client_bvolume')).value; - viewport.blipChannels.forEach((channel: HTMLAudioElement) => channel.volume = Number(blipVolume)); - setCookie('blipVolume', blipVolume); -} -window.changeBlipVolume = changeBlipVolume; - -/** - * Triggered by the theme selector. - */ -export function reloadTheme() { - viewport.theme = (document.getElementById('client_themeselect')).value; - setCookie('theme', viewport.theme); - (document.getElementById('client_theme')).href = `styles/${viewport.theme}.css`; -} -window.reloadTheme = reloadTheme; - /** * Triggered by a changed callword list */ export function changeCallwords() { - client.callwords = (document.getElementById('client_callwords')).value.split('\n'); - setCookie('callwords', client.callwords.join('\n')); + client.callwords = (( + document.getElementById("client_callwords") + )).value.split("\n"); + setCookie("callwords", client.callwords.join("\n")); } window.changeCallwords = changeCallwords; @@ -2845,7 +2283,7 @@ window.changeCallwords = changeCallwords; * Triggered by the modcall sfx dropdown */ export function modcall_test() { - client.handleZZ('test#test'.split('#')); + client.handleZZ("test#test".split("#")); } window.modcall_test = modcall_test; @@ -2853,10 +2291,11 @@ window.modcall_test = modcall_test; * Triggered by the ini button. */ export async function iniedit() { - const ininame = (document.getElementById('client_ininame')).value; + const ininame = (document.getElementById("client_ininame")) + .value; const inicharID = client.charID; - await client.handleCharacterInfo(ininame.split('&'), inicharID); - client.handlePV((`PV#0#CID#${inicharID}`).split('#')); + await client.handleCharacterInfo(ininame.split("&"), inicharID); + client.handlePV(`PV#0#CID#${inicharID}`.split("#")); } window.iniedit = iniedit; @@ -2864,16 +2303,16 @@ window.iniedit = iniedit; * Triggered by the pantilt checkbox */ export async function switchPanTilt() { - const fullview = document.getElementById('client_fullview'); - const checkbox = document.getElementById('client_pantilt'); + const fullview = document.getElementById("client_fullview"); + const checkbox = document.getElementById("client_pantilt"); if (checkbox.checked) { - fullview.style.transition = '0.5s ease-in-out'; + fullview.style.transition = "0.5s ease-in-out"; } else { - fullview.style.transition = 'none'; + fullview.style.transition = "none"; } - return + return; } window.switchPanTilt = switchPanTilt; @@ -2881,13 +2320,17 @@ window.switchPanTilt = switchPanTilt; * Triggered by the change aspect ratio checkbox */ export async function switchAspectRatio() { - const background = document.getElementById('client_gamewindow'); - const offsetCheck = document.getElementById('client_hdviewport_offset'); - if ((document.getElementById('client_hdviewport')).checked) { - background.style.paddingBottom = '56.25%'; + const background = document.getElementById("client_gamewindow"); + const offsetCheck = ( + document.getElementById("client_hdviewport_offset") + ); + if ( + (document.getElementById("client_hdviewport")).checked + ) { + background.style.paddingBottom = "56.25%"; offsetCheck.disabled = false; } else { - background.style.paddingBottom = '75%'; + background.style.paddingBottom = "75%"; offsetCheck.disabled = true; } } @@ -2897,13 +2340,16 @@ window.switchAspectRatio = switchAspectRatio; * Triggered by the change aspect ratio checkbox */ export async function switchChatOffset() { - const container = document.getElementById('client_chatcontainer'); - if ((document.getElementById('client_hdviewport_offset')).checked) { - container.style.width = '80%'; - container.style.left = '10%'; + const container = document.getElementById("client_chatcontainer"); + if ( + (document.getElementById("client_hdviewport_offset")) + .checked + ) { + container.style.width = "80%"; + container.style.left = "10%"; } else { - container.style.width = '100%'; - container.style.left = '0'; + container.style.width = "100%"; + container.style.left = "0"; } } window.switchChatOffset = switchChatOffset; @@ -2913,9 +2359,9 @@ window.switchChatOffset = switchChatOffset; * @param {MouseEvent} event */ export function changeCharacter(_event: Event) { - document.getElementById('client_waiting').style.display = 'block'; - document.getElementById('client_charselect').style.display = 'block'; - document.getElementById('client_emo').innerHTML = ''; + document.getElementById("client_waiting").style.display = "block"; + document.getElementById("client_charselect").style.display = "block"; + document.getElementById("client_emo").innerHTML = ""; } window.changeCharacter = changeCharacter; @@ -2936,7 +2382,7 @@ window.charError = charError; */ export function imgError(image: HTMLImageElement) { image.onerror = null; - image.src = ''; // unload so the old sprite doesn't persist + image.src = ""; // unload so the old sprite doesn't persist return true; } window.imgError = imgError; @@ -2945,18 +2391,20 @@ window.imgError = imgError; * Triggered when there was an error loading a sound * @param {HTMLAudioElement} image the element containing the missing sound */ -export function opusCheck(channel: HTMLAudioElement): OnErrorEventHandlerNonNull{ - const audio = channel.src - if (audio === '') { - return +export function opusCheck( + channel: HTMLAudioElement +): OnErrorEventHandlerNonNull { + const audio = channel.src; + if (audio === "") { + return; } console.info(`failed to load sound ${channel.src}`); - let oldsrc = ''; - let newsrc = ''; + let oldsrc = ""; + let newsrc = ""; oldsrc = channel.src; - if (!oldsrc.endsWith('.opus')) { - newsrc = oldsrc.replace('.mp3', '.opus'); - newsrc = newsrc.replace('.wav', '.opus'); + if (!oldsrc.endsWith(".opus")) { + newsrc = oldsrc.replace(".mp3", ".opus"); + newsrc = newsrc.replace(".wav", ".opus"); channel.src = newsrc; // unload so the old sprite doesn't persist } } @@ -2968,9 +2416,9 @@ window.opusCheck = opusCheck; export function ReconnectButton() { client.cleanup(); client = new Client(serverIP); - + if (client) { - document.getElementById('client_error').style.display = 'none'; + document.getElementById("client_error").style.display = "none"; } } window.ReconnectButton = ReconnectButton; @@ -2980,18 +2428,27 @@ window.ReconnectButton = ReconnectButton; * @param {string} msg the string to be added * @param {string} name the name of the sender */ -function appendICLog(msg: string, showname = '', nameplate = '', time = new Date()) { - const entry = document.createElement('p'); - const shownameField = document.createElement('span'); - const nameplateField = document.createElement('span'); - const textField = document.createElement('span'); - nameplateField.className = 'iclog_name iclog_nameplate'; +export function appendICLog( + msg: string, + showname = "", + nameplate = "", + time = new Date() +) { + const entry = document.createElement("p"); + const shownameField = document.createElement("span"); + const nameplateField = document.createElement("span"); + const textField = document.createElement("span"); + nameplateField.className = "iclog_name iclog_nameplate"; nameplateField.appendChild(document.createTextNode(nameplate)); - shownameField.className = 'iclog_name iclog_showname'; - if (showname === '' || !showname) { shownameField.appendChild(document.createTextNode(nameplate)); } else { shownameField.appendChild(document.createTextNode(showname)); } + shownameField.className = "iclog_name iclog_showname"; + if (showname === "" || !showname) { + shownameField.appendChild(document.createTextNode(nameplate)); + } else { + shownameField.appendChild(document.createTextNode(showname)); + } - textField.className = 'iclog_text'; + textField.className = "iclog_text"; textField.appendChild(document.createTextNode(msg)); entry.appendChild(shownameField); @@ -3000,16 +2457,16 @@ function appendICLog(msg: string, showname = '', nameplate = '', time = new Date // Only put a timestamp if the minute has changed. if (lastICMessageTime.getMinutes() !== time.getMinutes()) { - const timeStamp = document.createElement('span'); - timeStamp.className = 'iclog_time'; + const timeStamp = document.createElement("span"); + timeStamp.className = "iclog_time"; timeStamp.innerText = time.toLocaleTimeString(undefined, { - hour: 'numeric', - minute: '2-digit', + hour: "numeric", + minute: "2-digit", }); entry.appendChild(timeStamp); } - const clientLog = document.getElementById('client_log'); + const clientLog = document.getElementById("client_log"); clientLog.appendChild(entry); /* This is a little buggy - some troubleshooting might be desirable */ @@ -3024,14 +2481,13 @@ function appendICLog(msg: string, showname = '', nameplate = '', time = new Date * check if the message contains an entry on our callword list * @param {string} message */ -export function checkCallword(message: string) { +export function checkCallword(message: string, sfxAudio: HTMLAudioElement) { client.callwords.forEach(testCallword); - function testCallword(item: string) { - if (item !== '' && message.toLowerCase().includes(item.toLowerCase())) { - viewport.sfxaudio.pause(); - viewport.sfxaudio.src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - viewport.sfxaudio.play(); + if (item !== "" && message.toLowerCase().includes(item.toLowerCase())) { + sfxAudio.pause(); + sfxAudio.src = `${AO_HOST}sounds/general/sfx-gallery.opus`; + sfxAudio.play(); } } } @@ -3041,14 +2497,16 @@ export function checkCallword(message: string) { * @param {MouseEvent} event */ export function chartable_filter(_event: Event) { - const searchname = (document.getElementById('client_charactersearch')).value; + const searchname = (( + document.getElementById("client_charactersearch") + )).value; client.chars.forEach((character: any, charid: number) => { const demothing = document.getElementById(`demo_${charid}`); if (character.name.toLowerCase().indexOf(searchname.toLowerCase()) === -1) { - demothing.style.display = 'none'; + demothing.style.display = "none"; } else { - demothing.style.display = 'inline-block'; + demothing.style.display = "inline-block"; } }); } @@ -3062,8 +2520,8 @@ window.chartable_filter = chartable_filter; export function pickChar(ccharacter: number) { if (ccharacter === -1) { // Spectator - document.getElementById('client_waiting').style.display = 'none'; - document.getElementById('client_charselect').style.display = 'none'; + document.getElementById("client_waiting").style.display = "none"; + document.getElementById("client_charselect").style.display = "none"; } client.sendCharacter(ccharacter); } @@ -3076,17 +2534,20 @@ window.pickChar = pickChar; export function pickEmotion(emo: number) { try { if (client.selectedEmote !== -1) { - document.getElementById(`emo_${client.selectedEmote}`).className = 'emote_button'; + document.getElementById(`emo_${client.selectedEmote}`).className = + "emote_button"; } } catch (err) { - // do nothing + // do nothing } client.selectedEmote = emo; - document.getElementById(`emo_${emo}`).className = 'emote_button dark'; + document.getElementById(`emo_${emo}`).className = "emote_button dark"; - (document.getElementById('sendsfx')).checked = (client.emote.sfx.length > 1); + (document.getElementById("sendsfx")).checked = + client.emote.sfx.length > 1; - (document.getElementById('sendpreanim')).checked = (client.emote.zoom == 1); + (document.getElementById("sendpreanim")).checked = + client.emote.zoom == 1; } window.pickEmotion = pickEmotion; @@ -3098,28 +2559,39 @@ export function pickEvidence(evidence: number) { if (client.selectedEvidence !== evidence) { // Update selected evidence if (client.selectedEvidence > 0) { - document.getElementById(`evi_${client.selectedEvidence}`).className = 'evi_icon'; + document.getElementById(`evi_${client.selectedEvidence}`).className = + "evi_icon"; } - document.getElementById(`evi_${evidence}`).className = 'evi_icon dark'; + document.getElementById(`evi_${evidence}`).className = "evi_icon dark"; client.selectedEvidence = evidence; // Show evidence on information window - (document.getElementById('evi_name')).value = client.evidences[evidence - 1].name; - (document.getElementById('evi_desc')).value = client.evidences[evidence - 1].desc; + (document.getElementById("evi_name")).value = + client.evidences[evidence - 1].name; + (document.getElementById("evi_desc")).value = + client.evidences[evidence - 1].desc; // Update icon - const icon_id = getIndexFromSelect('evi_select', client.evidences[evidence - 1].filename); - (document.getElementById('evi_select')).selectedIndex = icon_id; + const icon_id = getIndexFromSelect( + "evi_select", + client.evidences[evidence - 1].filename + ); + (document.getElementById("evi_select")).selectedIndex = + icon_id; if (icon_id === 0) { - (document.getElementById('evi_filename')).value = client.evidences[evidence - 1].filename; + (document.getElementById("evi_filename")).value = + client.evidences[evidence - 1].filename; } updateEvidenceIcon(); // Update button - document.getElementById('evi_add').className = 'client_button hover_button inactive'; - document.getElementById('evi_edit').className = 'client_button hover_button'; - document.getElementById('evi_cancel').className = 'client_button hover_button'; - document.getElementById('evi_del').className = 'client_button hover_button'; + document.getElementById("evi_add").className = + "client_button hover_button inactive"; + document.getElementById("evi_edit").className = + "client_button hover_button"; + document.getElementById("evi_cancel").className = + "client_button hover_button"; + document.getElementById("evi_del").className = "client_button hover_button"; } else { cancelEvidence(); } @@ -3130,13 +2602,15 @@ window.pickEvidence = pickEvidence; * Add evidence. */ export function addEvidence() { - const evidence_select = document.getElementById('evi_select'); + const evidence_select = ( + document.getElementById("evi_select") + ); client.sendPE( - (document.getElementById('evi_name')).value, - (document.getElementById('evi_desc')).value, + (document.getElementById("evi_name")).value, + (document.getElementById("evi_desc")).value, evidence_select.selectedIndex === 0 - ? (document.getElementById('evi_filename')).value - : evidence_select.options[evidence_select.selectedIndex].text, + ? (document.getElementById("evi_filename")).value + : evidence_select.options[evidence_select.selectedIndex].text ); cancelEvidence(); } @@ -3146,15 +2620,17 @@ window.addEvidence = addEvidence; * Edit selected evidence. */ export function editEvidence() { - const evidence_select = document.getElementById('evi_select'); + const evidence_select = ( + document.getElementById("evi_select") + ); const id = client.selectedEvidence - 1; client.sendEE( id, - (document.getElementById('evi_name')).value, - (document.getElementById('evi_desc')).value, + (document.getElementById("evi_name")).value, + (document.getElementById("evi_desc")).value, evidence_select.selectedIndex === 0 - ? (document.getElementById('evi_filename')).value - : evidence_select.options[evidence_select.selectedIndex].text, + ? (document.getElementById("evi_filename")).value + : evidence_select.options[evidence_select.selectedIndex].text ); cancelEvidence(); } @@ -3176,23 +2652,29 @@ window.deleteEvidence = deleteEvidence; export function cancelEvidence() { // Clear evidence data if (client.selectedEvidence > 0) { - document.getElementById(`evi_${client.selectedEvidence}`).className = 'evi_icon'; + document.getElementById(`evi_${client.selectedEvidence}`).className = + "evi_icon"; } client.selectedEvidence = 0; // Clear evidence on information window - (document.getElementById('evi_select')).selectedIndex = 0; + (document.getElementById("evi_select")).selectedIndex = 0; updateEvidenceIcon(); // Update icon widget - (document.getElementById('evi_filename')).value = ''; - (document.getElementById('evi_name')).value = ''; - (document.getElementById('evi_desc')).value = ''; - (document.getElementById('evi_preview')).src = `${AO_HOST}misc/empty.png`; // Clear icon + (document.getElementById("evi_filename")).value = ""; + (document.getElementById("evi_name")).value = ""; + (document.getElementById("evi_desc")).value = ""; + (( + document.getElementById("evi_preview") + )).src = `${AO_HOST}misc/empty.png`; // Clear icon // Update button - document.getElementById('evi_add').className = 'client_button hover_button'; - document.getElementById('evi_edit').className = 'client_button hover_button inactive'; - document.getElementById('evi_cancel').className = 'client_button hover_button inactive'; - document.getElementById('evi_del').className = 'client_button hover_button inactive'; + document.getElementById("evi_add").className = "client_button hover_button"; + document.getElementById("evi_edit").className = + "client_button hover_button inactive"; + document.getElementById("evi_cancel").className = + "client_button hover_button inactive"; + document.getElementById("evi_del").className = + "client_button hover_button inactive"; } window.cancelEvidence = cancelEvidence; @@ -3217,16 +2699,20 @@ window.getIndexFromSelect = getIndexFromSelect; * Set the style of the chatbox */ export function setChatbox(style: string) { - const chatbox_theme = document.getElementById('chatbox_theme'); - const themeselect = document.getElementById('client_chatboxselect'); + const chatbox_theme = ( + document.getElementById("chatbox_theme") + ); + const themeselect = ( + document.getElementById("client_chatboxselect") + ); const selected_theme = themeselect.value; - setCookie('chatbox', selected_theme); - if (selected_theme === 'dynamic') { + setCookie("chatbox", selected_theme); + if (selected_theme === "dynamic") { if (chatbox_arr.includes(style)) { chatbox_theme.href = `styles/chatbox/${style}.css`; } else { - chatbox_theme.href = 'styles/chatbox/aa.css'; + chatbox_theme.href = "styles/chatbox/aa.css"; } } else { chatbox_theme.href = `styles/chatbox/${selected_theme}.css`; @@ -3238,8 +2724,8 @@ window.setChatbox = setChatbox; * Set the font size for the chatbox */ export function resizeChatbox() { - const chatContainerBox = document.getElementById('client_chatcontainer'); - const gameHeight = document.getElementById('client_background').offsetHeight; + const chatContainerBox = document.getElementById("client_chatcontainer"); + const gameHeight = document.getElementById("client_background").offsetHeight; chatContainerBox.style.fontSize = `${(gameHeight * 0.0521).toFixed(1)}px`; } @@ -3249,16 +2735,26 @@ window.resizeChatbox = resizeChatbox; * Update evidence icon. */ export function updateEvidenceIcon() { - const evidence_select = document.getElementById('evi_select'); - const evidence_filename = document.getElementById('evi_filename'); - const evidence_iconbox = document.getElementById('evi_preview'); + const evidence_select = ( + document.getElementById("evi_select") + ); + const evidence_filename = ( + document.getElementById("evi_filename") + ); + const evidence_iconbox = ( + document.getElementById("evi_preview") + ); if (evidence_select.selectedIndex === 0) { - evidence_filename.style.display = 'initial'; - evidence_iconbox.src = `${AO_HOST}evidence/${encodeURI(evidence_filename.value.toLowerCase())}`; + evidence_filename.style.display = "initial"; + evidence_iconbox.src = `${AO_HOST}evidence/${encodeURI( + evidence_filename.value.toLowerCase() + )}`; } else { - evidence_filename.style.display = 'none'; - evidence_iconbox.src = `${AO_HOST}evidence/${encodeURI(evidence_select.value.toLowerCase())}`; + evidence_filename.style.display = "none"; + evidence_iconbox.src = `${AO_HOST}evidence/${encodeURI( + evidence_select.value.toLowerCase() + )}`; } } window.updateEvidenceIcon = updateEvidenceIcon; @@ -3267,16 +2763,21 @@ window.updateEvidenceIcon = updateEvidenceIcon; * Update evidence icon. */ export function updateActionCommands(side: string) { - if (side === 'jud') { - document.getElementById('judge_action').style.display = 'inline-table'; - document.getElementById('no_action').style.display = 'none'; + if (side === "jud") { + 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'; + document.getElementById("judge_action").style.display = "none"; + document.getElementById("no_action").style.display = "inline-table"; } // Update role selector - for (let i = 0, role_select = document.getElementById('role_select'); i < role_select.options.length; i++) { + for ( + let i = 0, + role_select = document.getElementById("role_select"); + i < role_select.options.length; + i++ + ) { if (side === role_select.options[i].value) { role_select.options.selectedIndex = i; return; @@ -3289,18 +2790,22 @@ window.updateActionCommands = updateActionCommands; * Change background via OOC. */ export function changeBackgroundOOC() { - const selectedBG = document.getElementById('bg_select'); + const selectedBG = document.getElementById("bg_select"); const changeBGCommand = "bg $1"; - const bgFilename = document.getElementById('bg_filename'); + const bgFilename = document.getElementById("bg_filename"); - let filename = ''; + let filename = ""; if (selectedBG.selectedIndex === 0) { filename = bgFilename.value; } else { filename = selectedBG.value; } - if (mode === 'join') { client.sendOOC(`/${changeBGCommand.replace('$1', filename)}`); } else if (mode === 'replay') { client.sendSelf(`BN#${filename}#%`); } + if (mode === "join") { + client.sendOOC(`/${changeBGCommand.replace("$1", filename)}`); + } else if (mode === "replay") { + client.sendSelf(`BN#${filename}#%`); + } } window.changeBackgroundOOC = changeBackgroundOOC; @@ -3308,7 +2813,7 @@ window.changeBackgroundOOC = changeBackgroundOOC; * Change role via OOC. */ export function changeRoleOOC() { - const roleselect = document.getElementById('role_select'); + const roleselect = document.getElementById("role_select"); client.sendOOC(`/pos ${roleselect.value}`); client.sendServer(`SP#${roleselect.value}#%`); @@ -3329,10 +2834,10 @@ window.randomCharacterOOC = randomCharacterOOC; */ export function callMod() { let modcall; - if (extrafeatures.includes('modcall_reason')) { - modcall = prompt('Please enter the reason for the modcall', ''); + if (extrafeatures.includes("modcall_reason")) { + modcall = prompt("Please enter the reason for the modcall", ""); } - if (modcall == null || modcall === '') { + if (modcall == null || modcall === "") { // cancel } else { client.sendZZ(modcall); @@ -3344,7 +2849,7 @@ window.callMod = callMod; * Declare witness testimony. */ export function initWT() { - client.sendRT('testimony1'); + client.sendRT("testimony1"); } window.initWT = initWT; @@ -3352,7 +2857,7 @@ window.initWT = initWT; * Declare cross examination. */ export function initCE() { - client.sendRT('testimony2'); + client.sendRT("testimony2"); } window.initCE = initCE; @@ -3360,7 +2865,7 @@ window.initCE = initCE; * Declare the defendant not guilty */ export function notguilty() { - client.sendRT('judgeruling#0'); + client.sendRT("judgeruling#0"); } window.notguilty = notguilty; @@ -3368,7 +2873,7 @@ window.notguilty = notguilty; * Declare the defendant not guilty */ export function guilty() { - client.sendRT('judgeruling#1'); + client.sendRT("judgeruling#1"); } window.guilty = guilty; @@ -3376,7 +2881,7 @@ window.guilty = guilty; * Increment defense health point. */ export function addHPD() { - client.sendHP(1, (client.hp[0] + 1)); + client.sendHP(1, client.hp[0] + 1); } window.addHPD = addHPD; @@ -3384,7 +2889,7 @@ window.addHPD = addHPD; * Decrement defense health point. */ export function redHPD() { - client.sendHP(1, (client.hp[0] - 1)); + client.sendHP(1, client.hp[0] - 1); } window.redHPD = redHPD; @@ -3392,7 +2897,7 @@ window.redHPD = redHPD; * Increment prosecution health point. */ export function addHPP() { - client.sendHP(2, (client.hp[1] + 1)); + client.sendHP(2, client.hp[1] + 1); } window.addHPP = addHPP; @@ -3400,7 +2905,7 @@ window.addHPP = addHPP; * Decrement prosecution health point. */ export function redHPP() { - client.sendHP(2, (client.hp[1] - 1)); + client.sendHP(2, client.hp[1] - 1); } window.redHPP = redHPP; @@ -3408,16 +2913,26 @@ window.redHPP = redHPP; * Update background preview. */ export function updateBackgroundPreview() { - const background_select = document.getElementById('bg_select'); - const background_filename = document.getElementById('bg_filename'); - const background_preview = document.getElementById('bg_preview'); + const background_select = ( + document.getElementById("bg_select") + ); + const background_filename = ( + document.getElementById("bg_filename") + ); + const background_preview = ( + document.getElementById("bg_preview") + ); if (background_select.selectedIndex === 0) { - background_filename.style.display = 'initial'; - background_preview.src = `${AO_HOST}background/${encodeURI(background_filename.value.toLowerCase())}/defenseempty.png`; + background_filename.style.display = "initial"; + background_preview.src = `${AO_HOST}background/${encodeURI( + background_filename.value.toLowerCase() + )}/defenseempty.png`; } else { - background_filename.style.display = 'none'; - background_preview.src = `${AO_HOST}background/${encodeURI(background_select.value.toLowerCase())}/defenseempty.png`; + background_filename.style.display = "none"; + background_preview.src = `${AO_HOST}background/${encodeURI( + background_select.value.toLowerCase() + )}/defenseempty.png`; } } window.updateBackgroundPreview = updateBackgroundPreview; @@ -3428,10 +2943,12 @@ window.updateBackgroundPreview = updateBackgroundPreview; */ export function toggleMenu(menu: number) { if (menu !== selectedMenu) { - document.getElementById(`menu_${menu}`).className = 'menu_button active'; - document.getElementById(`content_${menu}`).className = 'menu_content active'; - document.getElementById(`menu_${selectedMenu}`).className = 'menu_button'; - document.getElementById(`content_${selectedMenu}`).className = 'menu_content'; + document.getElementById(`menu_${menu}`).className = "menu_button active"; + document.getElementById(`content_${menu}`).className = + "menu_content active"; + document.getElementById(`menu_${selectedMenu}`).className = "menu_button"; + document.getElementById(`content_${selectedMenu}`).className = + "menu_content"; selectedMenu = menu; } } @@ -3444,15 +2961,16 @@ window.toggleMenu = toggleMenu; */ export function toggleShout(shout: number) { if (shout === selectedShout) { - document.getElementById(`button_${shout}`).className = 'client_button'; + document.getElementById(`button_${shout}`).className = "client_button"; selectedShout = 0; } else { - document.getElementById(`button_${shout}`).className = 'client_button dark'; + document.getElementById(`button_${shout}`).className = "client_button dark"; if (selectedShout) { - document.getElementById(`button_${selectedShout}`).className = 'client_button'; + document.getElementById(`button_${selectedShout}`).className = + "client_button"; } selectedShout = shout; } } window.toggleShout = toggleShout; -export default Client +export default Client; -- cgit From 03aa72eda907a1586baf3664a0be71191d898b9b Mon Sep 17 00:00:00 2001 From: Caleb Mabry <36182383+caleb-mabry@users.noreply.github.com> Date: Sun, 17 Jul 2022 13:43:25 -0400 Subject: Removing console logs --- webAO/client.ts | 3 --- 1 file changed, 3 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 64ffab9..18b173c 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -298,7 +298,6 @@ class Client extends EventEmitter { * @param {string} message the message to send */ sendServer(message: string) { - //console.log("C: "+message); mode === "replay" ? this.sendSelf(message) : this.serv.send(message); } @@ -615,7 +614,6 @@ class Client extends EventEmitter { * @param {number} character the character ID */ sendCharacter(character: number) { - console.log("sending " + character); if (character === -1 || this.chars[character].name) { this.sendServer(`CC#${this.playerID}#${character}#web#%`); } @@ -907,7 +905,6 @@ class Client extends EventEmitter { if (chatmsg.charid === this.charID) { resetICParams(); } - console.log(chatmsg); this.viewport.handle_ic_speaking(chatmsg); // no await } } -- cgit From 0a5641f1c437993cf49958a77831056792b0c872 Mon Sep 17 00:00:00 2001 From: Caleb Mabry <36182383+caleb-mabry@users.noreply.github.com> Date: Sun, 17 Jul 2022 20:23:38 -0400 Subject: Updating to use getters and setters --- webAO/client.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 18b173c..569b0e8 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -1515,15 +1515,16 @@ class Client extends EventEmitter { */ handleBN(args: string[]) { - this.viewport.bgname = safeTags(args[1]); - const bgfolder = this.viewport.bgFolder; - const bg_index = getIndexFromSelect("bg_select", this.viewport.bgname); + const bgFromArgs = safeTags(args[1]); + this.viewport.changeBgName(bgFromArgs); + const bgfolder = this.viewport.bgFolder(); + const bg_index = getIndexFromSelect("bg_select", this.viewport.bgName()); (document.getElementById("bg_select")).selectedIndex = bg_index; updateBackgroundPreview(); if (bg_index === 0) { (document.getElementById("bg_filename")).value = - this.viewport.bgname; + this.viewport.bgName(); } tryUrls( @@ -1659,12 +1660,12 @@ class Client extends EventEmitter { oocLog.scrollTop = oocLog.scrollHeight; } - this.viewport.sfxaudio.pause(); - const oldvolume = this.viewport.sfxaudio.volume; - this.viewport.sfxaudio.volume = 1; - this.viewport.sfxaudio.src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - this.viewport.sfxaudio.play(); - this.viewport.sfxaudio.volume = oldvolume; + this.viewport.sfxAudio().pause(); + const oldvolume = this.viewport.sfxAudio().volume; + this.viewport.sfxAudio().volume = 1; + this.viewport.sfxAudio().src = `${AO_HOST}sounds/general/sfx-gallery.opus`; + this.viewport.sfxAudio().play(); + this.viewport.sfxAudio().volume = oldvolume; } /** -- cgit From 151347b150e79bc01fcb8b8af0a173535df8b7fb Mon Sep 17 00:00:00 2001 From: Caleb Mabry <36182383+caleb-mabry@users.noreply.github.com> Date: Mon, 18 Jul 2022 13:24:21 -0400 Subject: Everything moved --- webAO/client.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 569b0e8..64b8f9a 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -51,7 +51,7 @@ interface QueryParams { let { ip: serverIP, mode, asset, theme } = queryParser() as QueryParams; // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; -let AO_HOST = asset || DEFAULT_HOST; +export let AO_HOST = asset || DEFAULT_HOST; const THEME = theme || "default"; let client: Client; @@ -222,7 +222,7 @@ class Client extends EventEmitter { this.selectedEvidence = 0; this.checkUpdater = null; - this.viewport = masterViewport(this, AO_HOST); + this.viewport = masterViewport(this); /** * Assign handlers for all commands * If you implement a new command, you need to add it here @@ -1516,15 +1516,18 @@ class Client extends EventEmitter { handleBN(args: string[]) { const bgFromArgs = safeTags(args[1]); - this.viewport.changeBgName(bgFromArgs); - const bgfolder = this.viewport.bgFolder(); - const bg_index = getIndexFromSelect("bg_select", this.viewport.bgName()); + this.viewport.setBackgroundName(bgFromArgs); + const bgfolder = this.viewport.getBackgroundFolder(); + const bg_index = getIndexFromSelect( + "bg_select", + this.viewport.getBackgroundName() + ); (document.getElementById("bg_select")).selectedIndex = bg_index; updateBackgroundPreview(); if (bg_index === 0) { (document.getElementById("bg_filename")).value = - this.viewport.bgName(); + this.viewport.getBackgroundName(); } tryUrls( @@ -1660,12 +1663,12 @@ class Client extends EventEmitter { oocLog.scrollTop = oocLog.scrollHeight; } - this.viewport.sfxAudio().pause(); - const oldvolume = this.viewport.sfxAudio().volume; - this.viewport.sfxAudio().volume = 1; - this.viewport.sfxAudio().src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - this.viewport.sfxAudio().play(); - this.viewport.sfxAudio().volume = oldvolume; + this.viewport.getSfxAudio().pause(); + const oldvolume = this.viewport.getSfxAudio().volume; + this.viewport.getSfxAudio().volume = 1; + this.viewport.getSfxAudio().src = `${AO_HOST}sounds/general/sfx-gallery.opus`; + this.viewport.getSfxAudio().play(); + this.viewport.getSfxAudio().volume = oldvolume; } /** -- cgit From 9727cb0f120f84f1d94df7d2a6c423ebd9862997 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Aug 2022 18:46:09 +0200 Subject: add new commands --- webAO/client.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 64b8f9a..9640b8e 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -264,6 +264,10 @@ class Client extends EventEmitter { this.on("CharsCheck", this.handleCharsCheck.bind(this)); this.on("PV", this.handlePV.bind(this)); this.on("ASS", this.handleASS.bind(this)); + this.on("ackMS", this.handleackMS.bind(this)); + this.on("SP", this.handleSP.bind(this)); + this.on("JD", this.handleJD.bind(this)); + this.on("decryptor", () => {}); this.on("CHECK", () => {}); this.on("CH", () => {}); @@ -1981,6 +1985,35 @@ class Client extends EventEmitter { AO_HOST = args[1]; } + /** + * server got our message + */ + handleackMS() { + resetICParams(); + } + + /** +* position change +* @param {string} pos new position +*/ + handleSP(pos: string) { + updateActionCommands(pos); + } + + /** +* show/hide judge controls +* @param {number} show either a 1 or a 0 +*/ + handleJD(show: number) { + if (show === 1) { + document.getElementById("judge_action").style.display = "inline-table"; + document.getElementById("no_action").style.display = "none"; + } else { + document.getElementById("judge_action").style.display = "none"; + document.getElementById("no_action").style.display = "inline-table"; + } + } + /** * we are asking ourselves what characters there are * @param {Array} args packet arguments -- cgit From 3f434f66d31d2d954eeca90e6206eb3e0c6fd045 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Aug 2022 18:55:47 +0200 Subject: SC is not a character --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 9640b8e..5444a1b 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -1135,7 +1135,7 @@ class Client extends EventEmitter { document.getElementById("client_loadingtext").innerHTML = "Loading Characters"; - for (let i = 1; i < args.length; i++) { + for (let i = 1; i < args.length-1; i++) { document.getElementById( "client_loadingtext" ).innerHTML = `Loading Character ${i}/${this.char_list_length}`; -- cgit From 73346f6e281bc59713381688f30325aea2039890 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 10 Aug 2022 00:09:40 +0200 Subject: add DR2 music to theme --- webAO/client.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 5444a1b..5cee9bf 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -2762,6 +2762,9 @@ export function resizeChatbox() { const gameHeight = document.getElementById("client_background").offsetHeight; chatContainerBox.style.fontSize = `${(gameHeight * 0.0521).toFixed(1)}px`; + + const trackstatus = (document.getElementById("client_trackstatustext")); + trackstatus.width = (trackstatus.offsetWidth-1)+"px"; } window.resizeChatbox = resizeChatbox; -- cgit From f4711674144923ba14de51af4d1c9e108deec4fc Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 21 Aug 2022 18:22:19 +0200 Subject: handle out of range char ids a little better --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 5cee9bf..94b80c1 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -773,7 +773,7 @@ class Client extends EventEmitter { let char_chatbox = "default"; let char_muted = false; - if (this.chars[char_id].name !== char_name) { + if (char_id < this.char_list_length && this.chars[char_id].name !== char_name) { console.info( `${this.chars[char_id].name} is iniediting to ${char_name}` ); -- cgit From 77e2da563b92bfac596caf0ee749f318e849786a Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 21 Aug 2022 18:32:18 +0200 Subject: wrap check in another if --- webAO/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 94b80c1..debd318 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -773,12 +773,14 @@ class Client extends EventEmitter { let char_chatbox = "default"; let char_muted = false; - if (char_id < this.char_list_length && this.chars[char_id].name !== char_name) { + if (char_id < this.char_list_length && char_id >= 0) { + if(this.chars[char_id].name !== char_name) { console.info( `${this.chars[char_id].name} is iniediting to ${char_name}` ); const chargs = (`${char_name}&` + "iniediter").split("&"); this.handleCharacterInfo(chargs, char_id); + } } try { -- cgit From a6186ff308c844b39d71cfd65e3d3117dbdbedb0 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 25 Aug 2022 19:06:50 +0200 Subject: fix judge actions for non-judges --- webAO/client.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index debd318..2f84277 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -516,9 +516,7 @@ class Client extends EventEmitter { * @param {string} testimony type */ sendRT(testimony: string) { - if (this.chars[this.charID].side === "jud") { - this.sendServer(`RT#${testimony}#%`); - } + this.sendServer(`RT#${testimony}#%`); } /** @@ -1998,16 +1996,16 @@ class Client extends EventEmitter { * position change * @param {string} pos new position */ - handleSP(pos: string) { - updateActionCommands(pos); + handleSP(args: string[]) { + updateActionCommands(args[1]); } /** * show/hide judge controls * @param {number} show either a 1 or a 0 */ - handleJD(show: number) { - if (show === 1) { + handleJD(args: string[]) { + if (Number(args[1]) === 1) { document.getElementById("judge_action").style.display = "inline-table"; document.getElementById("no_action").style.display = "none"; } else { -- cgit 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/client.ts | 186 +++----------------------------------------------------- 1 file changed, 8 insertions(+), 178 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 2f84277..f42f622 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -35,28 +35,15 @@ import downloadFile from "./services/downloadFile"; import { getFilenameFromPath } from "./utils/paths"; const version = process.env.npm_package_version; import masterViewport, { Viewport } from "./viewport"; +import { handleMS } from './packets/handlers/handleMS'; -interface Testimony { - [key: number]: string; -} - -// Get the arguments from the URL bar -interface QueryParams { - ip: string; - serverIP: string; - mode: string; - asset: string; - theme: string; -} -let { ip: serverIP, mode, asset, theme } = queryParser() as QueryParams; +let { ip: serverIP, mode, asset, theme } = queryParser() ; // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; export let AO_HOST = asset || DEFAULT_HOST; const THEME = theme || "default"; -let client: Client; - -const attorneyMarkdown = mlConfig(AO_HOST); +export let client: Client; export const UPDATE_INTERVAL = 60; @@ -71,7 +58,7 @@ let oldLoading = false; let selectedMenu = 1; let selectedShout = 0; -let extrafeatures: string[] = []; +export let extrafeatures: string[] = []; let banned: boolean = false; let hdid: string; @@ -220,14 +207,14 @@ class Client extends EventEmitter { this.selectedEmote = -1; this.selectedEvidence = 0; - + this.checkUpdater = null; this.viewport = masterViewport(this); /** * Assign handlers for all commands * If you implement a new command, you need to add it here */ - this.on("MS", this.handleMS.bind(this)); + this.on("MS", handleMS); this.on("CT", this.handleCT.bind(this)); this.on("MC", this.handleMC.bind(this)); this.on("RMC", this.handleRMC.bind(this)); @@ -754,165 +741,7 @@ class Client extends EventEmitter { (document.getElementById("client_inputbox")).value = ""; }; - /** - * Handles an in-character chat message. - * @param {*} args packet arguments - */ - handleMS(args: string[]) { - // TODO: this if-statement might be a bug. - if (args[4] !== this.viewport.chatmsg.content) { - document.getElementById("client_inner_chat").innerHTML = ""; - - const char_id = Number(args[9]); - const char_name = safeTags(args[3]); - - let msg_nameplate = args[3]; - let msg_blips = "male"; - let char_chatbox = "default"; - let char_muted = false; - - if (char_id < this.char_list_length && char_id >= 0) { - if(this.chars[char_id].name !== char_name) { - console.info( - `${this.chars[char_id].name} is iniediting to ${char_name}` - ); - const chargs = (`${char_name}&` + "iniediter").split("&"); - this.handleCharacterInfo(chargs, char_id); - } - } - - try { - msg_nameplate = this.chars[char_id].showname; - } catch (e) { - msg_nameplate = args[3]; - } - - try { - msg_blips = this.chars[char_id].blips; - } catch (e) {} - - try { - char_chatbox = this.chars[char_id].chat; - } catch (e) { - char_chatbox = "default"; - } - - try { - char_muted = this.chars[char_id].muted; - } catch (e) { - char_muted = false; - console.error("we're still missing some character data"); - } - - if (char_muted === false) { - let chatmsg = { - deskmod: safeTags(args[1]).toLowerCase(), - preanim: safeTags(args[2]).toLowerCase(), // get preanim - nameplate: msg_nameplate, - chatbox: char_chatbox, - name: char_name, - sprite: safeTags(args[4]).toLowerCase(), - content: prepChat(args[5]), // Escape HTML tags - side: args[6].toLowerCase(), - sound: safeTags(args[7]).toLowerCase(), - blips: safeTags(msg_blips), - type: Number(args[8]), - charid: char_id, - snddelay: Number(args[10]), - objection: Number(args[11]), - evidence: safeTags(args[12]), - flip: Number(args[13]), - flash: Number(args[14]), - color: Number(args[15]), - speed: UPDATE_INTERVAL, - }; - - if (extrafeatures.includes("cccc_ic_support")) { - const extra_cccc = { - showname: safeTags(args[16]), - other_charid: Number(args[17]), - other_name: safeTags(args[18]), - other_emote: safeTags(args[19]), - self_offset: args[20].split(""), // 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 === this.charID) { - resetICParams(); - } - this.viewport.handle_ic_speaking(chatmsg); // no await - } - } - } /** * Handles an out-of-character chat message. @@ -2176,7 +2005,7 @@ window.onEnter = onEnter; * This should only be called when the player's previous chat message * was successfully sent/presented. */ -function resetICParams() { +export function resetICParams() { (document.getElementById("client_inputbox")).value = ""; document.getElementById("button_flash").className = "client_button"; document.getElementById("button_shake").className = "client_button"; @@ -3010,4 +2839,5 @@ export function toggleShout(shout: number) { } } window.toggleShout = toggleShout; + export default Client; -- 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/client.ts | 3 --- 1 file changed, 3 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index f42f622..c0ea5a0 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -8,7 +8,6 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs"; import { EventEmitter } from "events"; import tryUrls from "./utils/tryUrls"; import { escapeChat, prepChat, safeTags, unescapeChat } from "./encoding"; -import mlConfig from "./utils/aoml"; // Load some defaults for the background and evidence dropdowns import vanilla_character_arr from "./constants/characters.js"; import vanilla_music_arr from "./constants/music.js"; @@ -25,10 +24,8 @@ import { changeSFXVolume, changeTestimonyVolume, } from "./dom/changeVolume.js"; -import setEmote from "./client/setEmote.js"; import fileExists from "./utils/fileExists.js"; import queryParser from "./utils/queryParser.js"; -import getAnimLength from "./utils/getAnimLength.js"; import getResources from "./utils/getResources.js"; import transparentPng from "./constants/transparentPng"; import downloadFile from "./services/downloadFile"; -- cgit From e412b63731d851e8b05e2c28510716b3e0ce6e51 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 27 Aug 2022 19:11:56 +0200 Subject: set the time --- webAO/client.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index c0ea5a0..53551e2 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -38,7 +38,8 @@ let { ip: serverIP, mode, asset, theme } = queryParser() ; // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; export let AO_HOST = asset || DEFAULT_HOST; -const THEME = theme || "default"; +let THEME: string = theme || "default"; +let CHATBOX: string; export let client: Client; @@ -2565,17 +2566,17 @@ export function setChatbox(style: string) { const themeselect = ( document.getElementById("client_chatboxselect") ); - const selected_theme = themeselect.value; + CHATBOX = themeselect.value; - setCookie("chatbox", selected_theme); - if (selected_theme === "dynamic") { + setCookie("chatbox", CHATBOX); + if (CHATBOX === "dynamic") { if (chatbox_arr.includes(style)) { chatbox_theme.href = `styles/chatbox/${style}.css`; } else { chatbox_theme.href = "styles/chatbox/aa.css"; } } else { - chatbox_theme.href = `styles/chatbox/${selected_theme}.css`; + chatbox_theme.href = `styles/chatbox/${CHATBOX}.css`; } } window.setChatbox = setChatbox; @@ -2591,6 +2592,25 @@ export function resizeChatbox() { const trackstatus = (document.getElementById("client_trackstatustext")); trackstatus.width = (trackstatus.offsetWidth-1)+"px"; + + + //clock + const now = new Date(); + let weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; + const month = ["January","February","March","April","May","June","July","August","September","October","November","December"]; + document.getElementById("client_clock_month").innerText = month[now.getMonth()]; + console.debug(CHATBOX); + if (CHATBOX == "acww") { + weekday = ["Su","Mo","Tu","We","Th","Fr","Sa"]; + document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; + document.getElementById("client_clock_date").innerText = now.getDay()+"/"+now.getMonth(); + document.getElementById("client_clock_time").innerText = now.getHours()+":"+now.getMinutes(); + } else if (CHATBOX == "key") { + weekday = ["Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat."]; + document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; + document.getElementById("client_clock_date").innerText = String(now.getDay()); + } + } window.resizeChatbox = resizeChatbox; -- cgit From 2b249fb0effd3893b70a8f9ce3383992ea43c63d Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 27 Aug 2022 19:16:54 +0200 Subject: change iniediting back to the old input box --- webAO/client.ts | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index c0ea5a0..069e323 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -908,10 +908,6 @@ class Client extends EventEmitter { this.chars[charid].blips = this.chars[charid].gender; } - const iniedit_select = ( - document.getElementById("client_ininame") - ); - iniedit_select.add(new Option(safeTags(chargs[0]))); } else { console.warn(`missing charid ${charid}`); img.style.display = "none"; @@ -1776,31 +1772,6 @@ class Client extends EventEmitter { document.getElementById("button_4").style.display = "none"; } - const iniedit_select = ( - document.getElementById("client_ininame") - ); - - // Load iniswaps if there are any - try { - const cswapdata = await request( - `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/iniswaps.ini` - ); - const cswap = cswapdata.split("\n"); - - // most iniswaps don't list their original char - if (cswap.length > 0) { - iniedit_select.innerHTML = ""; - - iniedit_select.add(new Option(safeTags(me.name))); - - cswap.forEach((inisw: string) => - iniedit_select.add(new Option(safeTags(inisw))) - ); - } - } catch (err) { - console.info("character doesn't have iniswaps"); - this.fetchCharacterList(); - } } /** -- cgit From 2838fbe91a270ed3d69ac708dac85b108b6f09dc Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 30 Aug 2022 20:53:31 +0200 Subject: use the typescript version of queryparser --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index edd5d13..918704d 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -25,7 +25,7 @@ import { changeTestimonyVolume, } from "./dom/changeVolume.js"; import fileExists from "./utils/fileExists.js"; -import queryParser from "./utils/queryParser.js"; +import queryParser from "./utils/queryParser"; import getResources from "./utils/getResources.js"; import transparentPng from "./constants/transparentPng"; import downloadFile from "./services/downloadFile"; -- cgit From 325aa41d1216facbb7228743930a8ad21afec7aa Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 30 Aug 2022 20:58:25 +0200 Subject: convert cookie stuff to ts --- webAO/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 918704d..a2735b2 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -16,8 +16,8 @@ import vanilla_evidence_arr from "./constants/evidence.js"; import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; -import getCookie from "./utils/getCookie.js"; -import setCookie from "./utils/setCookie.js"; +import getCookie from "./utils/getCookie"; +import setCookie from "./utils/setCookie"; import { request } from "./services/request.js"; import { changeShoutVolume, -- 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/client.ts | 102 +++++++++++++++----------------------------------------- 1 file changed, 26 insertions(+), 76 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index a2735b2..bc96703 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -13,7 +13,8 @@ import vanilla_character_arr from "./constants/characters.js"; import vanilla_music_arr from "./constants/music.js"; import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; - +import { handleCT } from './packets/handlers/handleCT' +import { handleMC } from './packets/handlers/handleMC' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -34,7 +35,7 @@ const version = process.env.npm_package_version; import masterViewport, { Viewport } from "./viewport"; import { handleMS } from './packets/handlers/handleMS'; -let { ip: serverIP, mode, asset, theme } = queryParser() ; +let { ip: serverIP, mode, asset, theme } = queryParser(); // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; export let AO_HOST = asset || DEFAULT_HOST; @@ -205,7 +206,7 @@ class Client extends EventEmitter { this.selectedEmote = -1; this.selectedEvidence = 0; - + this.checkUpdater = null; this.viewport = masterViewport(this); /** @@ -213,8 +214,8 @@ class Client extends EventEmitter { * If you implement a new command, you need to add it here */ this.on("MS", handleMS); - this.on("CT", this.handleCT.bind(this)); - this.on("MC", this.handleMC.bind(this)); + this.on("CT", handleCT); + this.on("MC", handleMC); this.on("RMC", this.handleRMC.bind(this)); this.on("CI", this.handleCI.bind(this)); this.on("SC", this.handleSC.bind(this)); @@ -252,9 +253,9 @@ class Client extends EventEmitter { this.on("ackMS", this.handleackMS.bind(this)); this.on("SP", this.handleSP.bind(this)); this.on("JD", this.handleJD.bind(this)); - this.on("decryptor", () => {}); - this.on("CHECK", () => {}); - this.on("CH", () => {}); + this.on("decryptor", () => { }); + this.on("CHECK", () => { }); + this.on("CH", () => { }); this._lastTimeICReceived = new Date(0); } @@ -436,9 +437,8 @@ class Client extends EventEmitter { if (mode === "replay") { (( document.getElementById("client_ooclog") - )).value += `wait#${ - (document.getElementById("client_replaytimer")).value - }#%\r\n`; + )).value += `wait#${(document.getElementById("client_replaytimer")).value + }#%\r\n`; } } @@ -741,58 +741,9 @@ class Client extends EventEmitter { - /** - * Handles an out-of-character chat message. - * @param {Array} args packet arguments - */ - 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; - } - } - } - - /** - * Handles a music change to an arbitrary resource. - * @param {Array} args packet arguments - */ - 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 = this.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 = this.chars[charID].name; - } catch (e) { - charID = -1; - } - if (charID >= 0) { - musicname = this.chars[charID].name; - appendICLog(`${musicname} changed music to ${track}`); - } else { - appendICLog(`The music was changed to ${track}`); - } - document.getElementById("client_trackstatustext").innerText = track; - } // TODO BUG: // this.viewport.music is an array. Therefore you must access elements @@ -958,7 +909,7 @@ class Client extends EventEmitter { document.getElementById("client_loadingtext").innerHTML = "Loading Characters"; - for (let i = 1; i < args.length-1; i++) { + for (let i = 1; i < args.length - 1; i++) { document.getElementById( "client_loadingtext" ).innerHTML = `Loading Character ${i}/${this.char_list_length}`; @@ -2050,9 +2001,8 @@ export function mutelist_click(_event: Event) { if (client.chars[selected_character.value].muted === false) { client.chars[selected_character.value].muted = true; - selected_character.text = `${ - client.chars[selected_character.value].name - } (muted)`; + selected_character.text = `${client.chars[selected_character.value].name + } (muted)`; console.info(`muted ${client.chars[selected_character.value].name}`); } else { client.chars[selected_character.value].muted = false; @@ -2562,26 +2512,26 @@ export function resizeChatbox() { chatContainerBox.style.fontSize = `${(gameHeight * 0.0521).toFixed(1)}px`; const trackstatus = (document.getElementById("client_trackstatustext")); - trackstatus.width = (trackstatus.offsetWidth-1)+"px"; + trackstatus.width = (trackstatus.offsetWidth - 1) + "px"; //clock const now = new Date(); - let weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; - const month = ["January","February","March","April","May","June","July","August","September","October","November","December"]; + let weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; + const month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; document.getElementById("client_clock_month").innerText = month[now.getMonth()]; console.debug(CHATBOX); if (CHATBOX == "acww") { - weekday = ["Su","Mo","Tu","We","Th","Fr","Sa"]; - document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; - document.getElementById("client_clock_date").innerText = now.getDay()+"/"+now.getMonth(); - document.getElementById("client_clock_time").innerText = now.getHours()+":"+now.getMinutes(); + weekday = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; + document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; + document.getElementById("client_clock_date").innerText = now.getDay() + "/" + now.getMonth(); + document.getElementById("client_clock_time").innerText = now.getHours() + ":" + now.getMinutes(); } else if (CHATBOX == "key") { - weekday = ["Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat."]; - document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; - document.getElementById("client_clock_date").innerText = String(now.getDay()); + weekday = ["Sun.", "Mon.", "Tue.", "Wed.", "Thu.", "Fri.", "Sat."]; + document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; + document.getElementById("client_clock_date").innerText = String(now.getDay()); } - + } window.resizeChatbox = resizeChatbox; @@ -2628,7 +2578,7 @@ export function updateActionCommands(side: string) { // Update role selector for ( let i = 0, - role_select = document.getElementById("role_select"); + role_select = document.getElementById("role_select"); i < role_select.options.length; i++ ) { -- 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/client.ts | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index bc96703..676aa3f 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -15,6 +15,7 @@ import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; import { handleCT } from './packets/handlers/handleCT' import { handleMC } from './packets/handlers/handleMC' +import { handleRMC } from './packets/handlers/handleRMC' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -216,7 +217,7 @@ class Client extends EventEmitter { this.on("MS", handleMS); this.on("CT", handleCT); this.on("MC", handleMC); - this.on("RMC", this.handleRMC.bind(this)); + this.on("RMC", handleRMC); this.on("CI", this.handleCI.bind(this)); this.on("SC", this.handleSC.bind(this)); this.on("EI", this.handleEI.bind(this)); @@ -438,7 +439,7 @@ class Client extends EventEmitter { (( document.getElementById("client_ooclog") )).value += `wait#${(document.getElementById("client_replaytimer")).value - }#%\r\n`; + }#%\r\n`; } } @@ -745,29 +746,7 @@ class Client extends EventEmitter { - // 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 - */ - handleRMC(args: string[]) { - this.viewport.music.pause(); - const { music } = this.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 - ); - } + /** * Handles the incoming character information, and downloads the sprite + ini for it -- 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/client.ts | 81 --------------------------------------------------------- 1 file changed, 81 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 676aa3f..17065ce 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -845,91 +845,10 @@ class Client extends EventEmitter { } } - /** - * Handles incoming character information, bundling multiple characters - * per packet. - * CI#0#Phoenix&description&&&&#Miles ... - * @param {Array} args packet arguments - */ - 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]}/${this.char_list_length}`; - const chargs = args[i].split("&"); - const charid = Number(args[i - 1]); - (( - document.getElementById("client_loadingbar") - )).value = charid; - setTimeout(() => this.handleCharacterInfo(chargs, charid), 500); - } - } - // Request the next pack - this.sendServer(`AN#${Number(args[1]) / 10 + 1}#%`); - } - /** - * Handles incoming character information, containing all characters - * in one packet. - * @param {Array} args packet arguments - */ - async handleSC(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}/${this.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 - this.handleCharacterInfo(chargs, charid); - } - // We're done with the characters, request the music - this.sendServer("RM#%"); - } - - /** - * Handles incoming evidence information, containing only one evidence - * item per packet. - * - * EI#id#name&description&type&image&##% - * - * @param {Array} args packet arguments - */ - handleEI(args: string[]) { - document.getElementById( - "client_loadingtext" - ).innerHTML = `Loading Evidence ${args[1]}/${this.evidence_list_length}`; - const evidenceID = Number(args[1]); - (document.getElementById("client_loadingbar")).value = - this.char_list_length + evidenceID; - - const arg = args[2].split("&"); - this.evidences[evidenceID] = { - name: prepChat(arg[0]), - desc: prepChat(arg[1]), - filename: safeTags(arg[3]), - icon: `${AO_HOST}evidence/${encodeURI(arg[3].toLowerCase())}`, - }; - - this.sendServer("AE" + (evidenceID + 1) + "#%"); - } /** * Handles incoming evidence list, all evidences at once -- cgit From c54b4545f663dc2ef4d62626360419a32ecf1f60 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 17:14:07 -0400 Subject: Beep bah boop three more down --- webAO/client.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 17065ce..4a1f3f3 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -16,6 +16,9 @@ import vanilla_evidence_arr from "./constants/evidence.js"; import { handleCT } from './packets/handlers/handleCT' import { handleMC } from './packets/handlers/handleMC' import { handleRMC } from './packets/handlers/handleRMC' +import {handleEI} from './packets/handlers/handleEI' +import {handleSC} from './packets/handlers/handleSC' +import {handleCI} from './packets/handlers/handleCI' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -218,9 +221,9 @@ class Client extends EventEmitter { this.on("CT", handleCT); this.on("MC", handleMC); this.on("RMC", handleRMC); - this.on("CI", this.handleCI.bind(this)); - this.on("SC", this.handleSC.bind(this)); - this.on("EI", this.handleEI.bind(this)); + this.on("CI", handleCI); + this.on("SC", handleSC); + this.on("EI", handleEI); this.on("FL", this.handleFL.bind(this)); this.on("LE", this.handleLE.bind(this)); this.on("EM", this.handleEM.bind(this)); -- 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/client.ts | 130 ++++++-------------------------------------------------- 1 file changed, 13 insertions(+), 117 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 4a1f3f3..636ac83 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -16,9 +16,12 @@ import vanilla_evidence_arr from "./constants/evidence.js"; import { handleCT } from './packets/handlers/handleCT' import { handleMC } from './packets/handlers/handleMC' import { handleRMC } from './packets/handlers/handleRMC' -import {handleEI} from './packets/handlers/handleEI' -import {handleSC} from './packets/handlers/handleSC' -import {handleCI} from './packets/handlers/handleCI' +import { handleFL } from './packets/handlers/handleFL' +import { handleLE } from './packets/handlers/handleLE' +import { handleEM } from './packets/handlers/handleEM' +import { handleEI } from './packets/handlers/handleEI' +import { handleSC } from './packets/handlers/handleSC' +import { handleCI } from './packets/handlers/handleCI' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -62,6 +65,10 @@ let selectedMenu = 1; let selectedShout = 0; export let extrafeatures: string[] = []; +export const setExtraFeatures = (val: any) => { + extrafeatures = val +} + let banned: boolean = false; let hdid: string; @@ -224,9 +231,9 @@ class Client extends EventEmitter { this.on("CI", handleCI); this.on("SC", handleSC); this.on("EI", handleEI); - this.on("FL", this.handleFL.bind(this)); - this.on("LE", this.handleLE.bind(this)); - this.on("EM", this.handleEM.bind(this)); + this.on("FL", handleFL); + this.on("LE", handleLE); + this.on("EM", handleEM); this.on("FM", this.handleFM.bind(this)); this.on("FA", this.handleFA.bind(this)); this.on("SM", this.handleSM.bind(this)); @@ -853,37 +860,6 @@ class Client extends EventEmitter { - /** - * Handles incoming evidence list, all evidences at once - * item per packet. - * - * @param {Array} args packet arguments - */ - handleLE(args: string[]) { - this.evidences = []; - for (let i = 1; i < args.length - 1; i++) { - (( - document.getElementById("client_loadingbar") - )).value = this.char_list_length + i; - const arg = args[i].split("&"); - this.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 <= this.evidences.length; i++) { - evidence_box.innerHTML += `${this.evidences[i - 1].name}`; - } - } resetMusicList() { this.musics = []; @@ -1013,42 +989,7 @@ class Client extends EventEmitter { } } - /** - * Handles incoming music information, containing multiple entries - * per packet. - * @param {Array} args packet arguments - */ - handleEM(args: string[]) { - document.getElementById("client_loadingtext").innerHTML = "Loading Music"; - if (args[1] === "0") { - this.resetMusicList(); - this.resetAreaList(); - this.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 = - this.char_list_length + this.evidence_list_length + trackindex; - if (this.musics_time) { - this.addTrack(trackname); - } else if (this.isAudio(trackname)) { - this.musics_time = true; - this.fix_last_area(); - this.addTrack(trackname); - } else { - this.createArea(trackindex, trackname); - } - } - } - - // get the next batch of tracks - this.sendServer(`AM#${Number(args[1]) / 10 + 1}#%`); - } /** * Handles incoming music information, containing all music in one packet. @@ -1447,51 +1388,6 @@ class Client extends EventEmitter { } } - /** - * With this the server tells us which features it supports - * @param {Array} args list of features - */ - handleFL(args: string[]) { - console.info("Server-supported features:"); - console.info(args); - extrafeatures = 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 = ""; - } - } /** * Received when the server announces its server info, -- 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/client.ts | 68 +++++---------------------------------------------------- 1 file changed, 6 insertions(+), 62 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 636ac83..c13a6e0 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -22,6 +22,9 @@ import { handleEM } from './packets/handlers/handleEM' import { handleEI } from './packets/handlers/handleEI' import { handleSC } from './packets/handlers/handleSC' import { handleCI } from './packets/handlers/handleCI' +import { handleFM } from './packets/handlers/handleFM' +import { handleFA } from './packets/handlers/handleFA' +import { handleSM } from './packets/handlers/handleSM' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -234,9 +237,9 @@ class Client extends EventEmitter { this.on("FL", handleFL); this.on("LE", handleLE); this.on("EM", handleEM); - this.on("FM", this.handleFM.bind(this)); - this.on("FA", this.handleFA.bind(this)); - this.on("SM", this.handleSM.bind(this)); + this.on("FM", handleFM); + this.on("FA", handleFA); + this.on("SM", handleSM); this.on("MM", this.handleMM.bind(this)); this.on("BD", this.handleBD.bind(this)); this.on("BB", this.handleBB.bind(this)); @@ -991,66 +994,7 @@ class Client extends EventEmitter { - /** - * Handles incoming music information, containing all music in one packet. - * @param {Array} args packet arguments - */ - handleSM(args: string[]) { - document.getElementById("client_loadingtext").innerHTML = "Loading Music "; - this.resetMusicList(); - this.resetAreaList(); - - this.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}/${this.music_list_length}`; - (( - document.getElementById("client_loadingbar") - )).value = this.char_list_length + this.evidence_list_length + i; - if (this.musics_time) { - this.addTrack(trackname); - } else if (this.isAudio(trackname)) { - this.musics_time = true; - this.fix_last_area(); - this.addTrack(trackname); - } else { - this.createArea(trackindex, trackname); - } - } - - // Music done, carry on - this.sendServer("RD#%"); - } - /** - * Handles updated music list - * @param {Array} args packet arguments - */ - handleFM(args: string[]) { - this.resetMusicList(); - - for (let i = 1; i < args.length - 1; i++) { - // Check when found the song for the first time - this.addTrack(safeTags(args[i])); - } - } - - /** - * Handles updated area list - * @param {Array} args packet arguments - */ - handleFA(args: string[]) { - this.resetAreaList(); - - for (let i = 1; i < args.length - 1; i++) { - this.createArea(i - 1, safeTags(args[i])); - } - } /** * Handles the "MusicMode" packet -- 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/client.ts | 62 +++++++++++++++------------------------------------------ 1 file changed, 16 insertions(+), 46 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index c13a6e0..1fdd3c5 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -25,6 +25,11 @@ import { handleCI } from './packets/handlers/handleCI' import { handleFM } from './packets/handlers/handleFM' import { handleFA } from './packets/handlers/handleFA' import { handleSM } from './packets/handlers/handleSM' +import { handleMM } from './packets/handlers/handleMM' +import { handleBD } from './packets/handlers/handleBD' +import { handleBB } from './packets/handlers/handleBB' +import { handleKB } from './packets/handlers/handleKB' +import { handleKK } from './packets/handlers/handleKK' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -72,7 +77,10 @@ export const setExtraFeatures = (val: any) => { extrafeatures = val } -let banned: boolean = false; +export let banned: boolean = false; +export const setBanned = (val: boolean) => { + banned = val +} let hdid: string; declare global { @@ -240,11 +248,11 @@ class Client extends EventEmitter { this.on("FM", handleFM); this.on("FA", handleFA); this.on("SM", handleSM); - this.on("MM", this.handleMM.bind(this)); - this.on("BD", this.handleBD.bind(this)); - this.on("BB", this.handleBB.bind(this)); - this.on("KB", this.handleKB.bind(this)); - this.on("KK", this.handleKK.bind(this)); + this.on("MM", handleMM); + this.on("BD", handleBD); + this.on("BB", handleBB); + this.on("KB", handleKB); + this.on("KK", handleKK); this.on("DONE", this.handleDONE.bind(this)); this.on("BN", this.handleBN.bind(this)); this.on("HP", this.handleHP.bind(this)); @@ -996,13 +1004,6 @@ class Client extends EventEmitter { - /** - * Handles the "MusicMode" packet - * @param {Array} args packet arguments - */ - handleMM(_args: string[]) { - // It's unused nowadays, as preventing people from changing the music is now serverside - } /** * Handles the kicked packet @@ -1022,42 +1023,11 @@ class Client extends EventEmitter { )).style.display = "none"; } - /** - * Handles the kicked packet - * @param {Array} args kick reason - */ - handleKK(args: string[]) { - this.handleBans("Kicked", safeTags(args[1])); - } - /** - * Handles the banned packet - * this one is sent when you are kicked off the server - * @param {Array} args ban reason - */ - handleKB(args: string[]) { - this.handleBans("Banned", safeTags(args[1])); - banned = true; - } - /** - * Handles the warning packet - * on client this spawns a message box you can't close for 2 seconds - * @param {Array} args ban reason - */ - handleBB(args: string[]) { - alert(safeTags(args[1])); - } - /** - * Handles the banned packet - * this one is sent when you try to reconnect but you're banned - * @param {Array} args ban reason - */ - handleBD(args: string[]) { - this.handleBans("Banned", safeTags(args[1])); - banned = true; - } + + /** * Handles the handshake completion packet, meaning the player -- 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/client.ts | 214 ++++---------------------------------------------------- 1 file changed, 15 insertions(+), 199 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 1fdd3c5..e871fce 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -30,6 +30,13 @@ import { handleBD } from './packets/handlers/handleBD' import { handleBB } from './packets/handlers/handleBB' import { handleKB } from './packets/handlers/handleKB' import { handleKK } from './packets/handlers/handleKK' +import { handleDONE } from './packets/handlers/handleDONE' +import { handleBN } from './packets/handlers/handleBN' +import { handleHP } from './packets/handlers/handleHP' +import { handleRT } from './packets/handlers/handleRT' +import { handleTI } from './packets/handlers/handleTI' +import { handleZZ } from './packets/handlers/handleZZ' +import { handleHI } from './packets/handlers/handleHI' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -253,13 +260,13 @@ class Client extends EventEmitter { this.on("BB", handleBB); this.on("KB", handleKB); this.on("KK", handleKK); - this.on("DONE", this.handleDONE.bind(this)); - this.on("BN", this.handleBN.bind(this)); - this.on("HP", this.handleHP.bind(this)); - this.on("RT", this.handleRT.bind(this)); - this.on("TI", this.handleTI.bind(this)); - this.on("ZZ", this.handleZZ.bind(this)); - this.on("HI", this.handleHI.bind(this)); + this.on("DONE", handleDONE); + this.on("BN", handleBN); + this.on("HP", handleHP); + this.on("RT", handleRT); + this.on("TI", handleTI); + this.on("ZZ", handleZZ); + this.on("HI", handleHI); this.on("ID", this.handleID.bind(this)); this.on("PN", this.handlePN.bind(this)); this.on("SI", this.handleSI.bind(this)); @@ -1025,197 +1032,6 @@ class Client extends EventEmitter { - - - - - /** - * Handles the handshake completion packet, meaning the player - * is ready to select a character. - * - * @param {Array} args packet arguments - */ - 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"; - } - } - - /** - * Handles a background change. - * @param {Array} args packet arguments - */ - - handleBN(args: string[]) { - const bgFromArgs = safeTags(args[1]); - this.viewport.setBackgroundName(bgFromArgs); - const bgfolder = this.viewport.getBackgroundFolder(); - const bg_index = getIndexFromSelect( - "bg_select", - this.viewport.getBackgroundName() - ); - (document.getElementById("bg_select")).selectedIndex = - bg_index; - updateBackgroundPreview(); - if (bg_index === 0) { - (document.getElementById("bg_filename")).value = - this.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 (this.charID === -1) { - this.viewport.set_side({ - position: "jud", - showSpeedLines: false, - showDesk: true, - }); - } else { - this.viewport.set_side({ - position: this.chars[this.charID].side, - showSpeedLines: false, - showDesk: true, - }); - } - } - - /** - * Handles a change in the health bars' states. - * @param {Array} args packet arguments - */ - handleHP(args: string[]) { - const percent_hp = Number(args[2]) * 10; - let healthbox; - if (args[1] === "1") { - // Def hp - this.hp[0] = Number(args[2]); - healthbox = document.getElementById("client_defense_hp"); - } else { - // Pro hp - this.hp[1] = Number(args[2]); - healthbox = document.getElementById("client_prosecutor_hp"); - } - (( - healthbox.getElementsByClassName("health-bar")[0] - )).style.width = `${percent_hp}%`; - } - - /** - * Handles a testimony states. - * @param {Array} args packet arguments - */ - handleRT(args: string[]) { - const judgeid = Number(args[2]); - switch (args[1]) { - case "testimony1": - this.testimonyID = 1; - break; - case "testimony2": - // Cross Examination - this.testimonyID = 2; - break; - case "judgeruling": - this.testimonyID = 3 + judgeid; - break; - default: - console.warn("Invalid testimony"); - } - this.viewport.initTestimonyUpdater(); - } - - /** - * Handles a timer update - * @param {Array} args packet arguments - */ - 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"; - } - } - - /** - * Handles a modcall - * @param {Array} args packet arguments - */ - 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; - } - - this.viewport.getSfxAudio().pause(); - const oldvolume = this.viewport.getSfxAudio().volume; - this.viewport.getSfxAudio().volume = 1; - this.viewport.getSfxAudio().src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - this.viewport.getSfxAudio().play(); - this.viewport.getSfxAudio().volume = oldvolume; - } - - /** - * Handle the player - * @param {Array} args packet arguments - */ - handleHI(_args: string[]) { - this.sendSelf(`ID#1#webAO#${version}#%`); - this.sendSelf( - "FL#fastloading#yellowtext#cccc_ic_support#flipping#looping_sfx#effects#%" - ); - } - /** * Identifies the server and issues a playerID * @param {Array} args packet arguments @@ -1776,7 +1592,7 @@ window.changeCallwords = changeCallwords; * Triggered by the modcall sfx dropdown */ export function modcall_test() { - client.handleZZ("test#test".split("#")); + handleZZ("test#test".split("#")); } window.modcall_test = modcall_test; -- 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/client.ts | 153 +++++++------------------------------------------------- 1 file changed, 18 insertions(+), 135 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index e871fce..cacfd77 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -37,6 +37,13 @@ import { handleRT } from './packets/handlers/handleRT' import { handleTI } from './packets/handlers/handleTI' import { handleZZ } from './packets/handlers/handleZZ' import { handleHI } from './packets/handlers/handleHI' +import { handleID } from './packets/handlers/handleID' +import { handlePN } from './packets/handlers/handlePN' +import { handleSI } from './packets/handlers/handleSI' +import { handleARUP } from './packets/handlers/handleARUP' +import { handleaskchaa } from './packets/handlers/handleaskchaa' +import { handleCC } from './packets/handlers/handleCC' +import { handleRC } from './packets/handlers/handleRC' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -73,7 +80,10 @@ export const UPDATE_INTERVAL = 60; * The old loading uses more smaller packets instead of a single big one, * which caused problems on low-memory devices in the past. */ -let oldLoading = false; +export let oldLoading = false; +export const setOldLoading = (val: boolean) => { + oldLoading = val +} // presettings let selectedMenu = 1; @@ -267,13 +277,13 @@ class Client extends EventEmitter { this.on("TI", handleTI); this.on("ZZ", handleZZ); this.on("HI", handleHI); - this.on("ID", this.handleID.bind(this)); - this.on("PN", this.handlePN.bind(this)); - this.on("SI", this.handleSI.bind(this)); - this.on("ARUP", this.handleARUP.bind(this)); - this.on("askchaa", this.handleaskchaa.bind(this)); - this.on("CC", this.handleCC.bind(this)); - this.on("RC", this.handleRC.bind(this)); + this.on("ID", handleID); + this.on("PN", handlePN); + this.on("SI", handleSI); + this.on("ARUP", handleARUP); + this.on("askchaa", handleaskchaa); + this.on("CC", handleCC); + this.on("RC", handleRC); this.on("RM", this.handleRM.bind(this)); this.on("RD", this.handleRD.bind(this)); this.on("CharsCheck", this.handleCharsCheck.bind(this)); @@ -1032,131 +1042,11 @@ class Client extends EventEmitter { - /** - * Identifies the server and issues a playerID - * @param {Array} args packet arguments - */ - handleID(args: string[]) { - this.playerID = Number(args[1]); - const serverSoftware = args[2].split("&")[0]; - let serverVersion; - if (serverSoftware === "serverD") { - serverVersion = args[2].split("&")[1]; - } else if (serverSoftware === "webAO") { - oldLoading = false; - this.sendSelf("PN#0#1#%"); - } else { - serverVersion = args[3]; - } - - if (serverSoftware === "serverD" && serverVersion === "1377.152") { - oldLoading = true; - } // bugged version - } - - /** - * Indicates how many users are on this server - * @param {Array} args packet arguments - */ - handlePN(_args: string[]) { - this.sendServer("askchaa#%"); - } - - /** - * What? you want a character?? - * @param {Array} args packet arguments - */ - handleCC(args: string[]) { - this.sendSelf(`PV#1#CID#${args[2]}#%`); - } - - /** - * What? you want a character list from me?? - * @param {Array} args packet arguments - */ - handleaskchaa(_args: string[]) { - this.sendSelf(`SI#${vanilla_character_arr.length}#0#0#%`); - } - - /** - * Handle the change of players in an area. - * @param {Array} args packet arguments - */ - handleARUP(args: string[]) { - args = args.slice(1); - for (let i = 0; i < args.length - 2; i++) { - if (this.areas[i]) { - // the server sends us ARUP before we even get the area list - const thisarea = document.getElementById(`area${i}`); - switch (Number(args[0])) { - case 0: // playercount - this.areas[i].players = Number(args[i + 1]); - break; - case 1: // status - this.areas[i].status = safeTags(args[i + 1]); - break; - case 2: - this.areas[i].cm = safeTags(args[i + 1]); - break; - case 3: - this.areas[i].locked = safeTags(args[i + 1]); - break; - } - - thisarea.className = `area-button area-${this.areas[ - i - ].status.toLowerCase()}`; - - thisarea.innerText = `${this.areas[i].name} (${this.areas[i].players}) [${this.areas[i].status}]`; - - thisarea.title = - `Players: ${this.areas[i].players}\n` + - `Status: ${this.areas[i].status}\n` + - `CM: ${this.areas[i].cm}\n` + - `Area lock: ${this.areas[i].locked}`; - } - } - } - /** - * Received when the server announces its server info, - * but we use it as a cue to begin retrieving characters. - * @param {Array} args packet arguments - */ - handleSI(args: string[]) { - this.char_list_length = Number(args[1]); - this.char_list_length += 1; // some servers count starting from 0 some from 1... - this.evidence_list_length = Number(args[2]); - this.music_list_length = Number(args[3]); - (document.getElementById("client_loadingbar")).max = - this.char_list_length + - this.evidence_list_length + - this.music_list_length; - // create the charselect grid, to be filled by the character loader - document.getElementById("client_chartable").innerHTML = ""; - for (let i = 0; i < this.char_list_length; i++) { - const demothing = document.createElement("img"); - - demothing.className = "demothing"; - demothing.id = `demo_${i}`; - const demoonclick = document.createAttribute("onclick"); - demoonclick.value = `pickChar(${i})`; - demothing.setAttributeNode(demoonclick); - - document.getElementById("client_chartable").appendChild(demothing); - } - - // this is determined at the top of this file - if (!oldLoading && extrafeatures.includes("fastloading")) { - this.sendServer("RC#%"); - } else { - this.sendServer("askchar2#%"); - } - } /** * Handles the list of all used and vacant characters. @@ -1290,13 +1180,6 @@ class Client extends EventEmitter { } } - /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ - handleRC(_args: string[]) { - this.sendSelf(`SC#${vanilla_character_arr.join("#")}#%`); - } /** * we are asking ourselves what characters there are -- 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/client.ts | 207 ++++++-------------------------------------------------- 1 file changed, 20 insertions(+), 187 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index cacfd77..f216bce 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -44,6 +44,14 @@ import { handleARUP } from './packets/handlers/handleARUP' import { handleaskchaa } from './packets/handlers/handleaskchaa' import { handleCC } from './packets/handlers/handleCC' import { handleRC } from './packets/handlers/handleRC' +import { handleRM } from './packets/handlers/handleRM' +import { handleRD } from './packets/handlers/handleRD' +import { handleCharsCheck } from './packets/handlers/handleCharsCheck' +import { handlePV } from './packets/handlers/handlePV' +import { handleASS } from './packets/handlers/handleASS' +import { handleackMS } from './packets/handlers/handleackMS' +import { handleSP } from './packets/handlers/handleSP' +import { handleJD } from './packets/handlers/handleJD' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -68,6 +76,9 @@ let { ip: serverIP, mode, asset, theme } = queryParser(); // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; export let AO_HOST = asset || DEFAULT_HOST; +export const setAOhost = (val: string) => { + AO_HOST = val +} let THEME: string = theme || "default"; let CHATBOX: string; @@ -284,14 +295,14 @@ class Client extends EventEmitter { this.on("askchaa", handleaskchaa); this.on("CC", handleCC); this.on("RC", handleRC); - this.on("RM", this.handleRM.bind(this)); - this.on("RD", this.handleRD.bind(this)); - this.on("CharsCheck", this.handleCharsCheck.bind(this)); - this.on("PV", this.handlePV.bind(this)); - this.on("ASS", this.handleASS.bind(this)); - this.on("ackMS", this.handleackMS.bind(this)); - this.on("SP", this.handleSP.bind(this)); - this.on("JD", this.handleJD.bind(this)); + this.on("RM", handleRM); + this.on("RD", handleRD); + this.on("CharsCheck", handleCharsCheck); + this.on("PV", handlePV); + this.on("ASS", handleASS); + this.on("ackMS", handleackMS); + this.on("SP", handleSP); + this.on("JD", handleJD); this.on("decryptor", () => { }); this.on("CHECK", () => { }); this.on("CH", () => { }); @@ -778,14 +789,6 @@ class Client extends EventEmitter { (document.getElementById("client_inputbox")).value = ""; }; - - - - - - - - /** * Handles the incoming character information, and downloads the sprite + ini for it * @param {Array} chargs packet arguments @@ -1017,11 +1020,6 @@ class Client extends EventEmitter { } } - - - - - /** * Handles the kicked packet * @param {string} type is it a kick or a ban @@ -1039,171 +1037,6 @@ class Client extends EventEmitter { document.getElementsByClassName("client_reconnect")[1] )).style.display = "none"; } - - - - - - - - - - /** - * Handles the list of all used and vacant characters. - * @param {Array} args list of all characters represented as a 0 for free or a -1 for taken - */ - handleCharsCheck(args: string[]) { - for (let i = 0; i < this.char_list_length; i++) { - const img = document.getElementById(`demo_${i}`); - - if (args[i + 1] === "-1") { - img.style.opacity = "0.25"; - } else if (args[i + 1] === "0") { - img.style.opacity = "1"; - } - } - } - - /** - * Handles the server's assignment of a character for the player to use. - * PV # playerID (unused) # CID # character ID - * @param {Array} args packet arguments - */ - async handlePV(args: string[]) { - this.charID = Number(args[3]); - document.getElementById("client_waiting").style.display = "none"; - document.getElementById("client_charselect").style.display = "none"; - - const me = this.chars[this.charID]; - this.selectedEmote = -1; - const { emotes } = this; - const emotesList = document.getElementById("client_emo"); - emotesList.style.display = ""; - emotesList.innerHTML = ""; // Clear emote box - const ini = me.inifile; - me.side = ini.options.side; - updateActionCommands(me.side); - if (ini.emotions.number === 0) { - emotesList.innerHTML = `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"; - } - - } - - /** - * new asset url!! - * @param {Array} args packet arguments - */ - handleASS(args: string[]) { - AO_HOST = args[1]; - } - - /** - * server got our message - */ - handleackMS() { - resetICParams(); - } - - /** -* position change -* @param {string} pos new position -*/ - handleSP(args: string[]) { - updateActionCommands(args[1]); - } - - /** -* show/hide judge controls -* @param {number} show either a 1 or a 0 -*/ - handleJD(args: string[]) { - if (Number(args[1]) === 1) { - document.getElementById("judge_action").style.display = "inline-table"; - document.getElementById("no_action").style.display = "none"; - } else { - document.getElementById("judge_action").style.display = "none"; - document.getElementById("no_action").style.display = "inline-table"; - } - } - - - /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ - handleRM(_args: string[]) { - this.sendSelf(`SM#${vanilla_music_arr.join("#")}#%`); - } - - /** - * we are asking ourselves what characters there are - * @param {Array} args packet arguments - */ - handleRD(_args: string[]) { - this.sendSelf("BN#gs4#%"); - this.sendSelf("DONE#%"); - const ooclog = document.getElementById("client_ooclog"); - ooclog.value = ""; - ooclog.readOnly = false; - - document.getElementById("client_oocinput").style.display = "none"; - document.getElementById("client_replaycontrols").style.display = - "inline-block"; - } } /** @@ -1487,7 +1320,7 @@ export async function iniedit() { .value; const inicharID = client.charID; await client.handleCharacterInfo(ininame.split("&"), inicharID); - client.handlePV(`PV#0#CID#${inicharID}`.split("#")); + handlePV(`PV#0#CID#${inicharID}`.split("#")); } window.iniedit = iniedit; -- 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/client.ts | 113 +++++--------------------------------------------------- 1 file changed, 10 insertions(+), 103 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index f216bce..ef3ab1a 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -13,45 +13,6 @@ import vanilla_character_arr from "./constants/characters.js"; import vanilla_music_arr from "./constants/music.js"; import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; -import { handleCT } from './packets/handlers/handleCT' -import { handleMC } from './packets/handlers/handleMC' -import { handleRMC } from './packets/handlers/handleRMC' -import { handleFL } from './packets/handlers/handleFL' -import { handleLE } from './packets/handlers/handleLE' -import { handleEM } from './packets/handlers/handleEM' -import { handleEI } from './packets/handlers/handleEI' -import { handleSC } from './packets/handlers/handleSC' -import { handleCI } from './packets/handlers/handleCI' -import { handleFM } from './packets/handlers/handleFM' -import { handleFA } from './packets/handlers/handleFA' -import { handleSM } from './packets/handlers/handleSM' -import { handleMM } from './packets/handlers/handleMM' -import { handleBD } from './packets/handlers/handleBD' -import { handleBB } from './packets/handlers/handleBB' -import { handleKB } from './packets/handlers/handleKB' -import { handleKK } from './packets/handlers/handleKK' -import { handleDONE } from './packets/handlers/handleDONE' -import { handleBN } from './packets/handlers/handleBN' -import { handleHP } from './packets/handlers/handleHP' -import { handleRT } from './packets/handlers/handleRT' -import { handleTI } from './packets/handlers/handleTI' -import { handleZZ } from './packets/handlers/handleZZ' -import { handleHI } from './packets/handlers/handleHI' -import { handleID } from './packets/handlers/handleID' -import { handlePN } from './packets/handlers/handlePN' -import { handleSI } from './packets/handlers/handleSI' -import { handleARUP } from './packets/handlers/handleARUP' -import { handleaskchaa } from './packets/handlers/handleaskchaa' -import { handleCC } from './packets/handlers/handleCC' -import { handleRC } from './packets/handlers/handleRC' -import { handleRM } from './packets/handlers/handleRM' -import { handleRD } from './packets/handlers/handleRD' -import { handleCharsCheck } from './packets/handlers/handleCharsCheck' -import { handlePV } from './packets/handlers/handlePV' -import { handleASS } from './packets/handlers/handleASS' -import { handleackMS } from './packets/handlers/handleackMS' -import { handleSP } from './packets/handlers/handleSP' -import { handleJD } from './packets/handlers/handleJD' import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; @@ -70,8 +31,7 @@ import downloadFile from "./services/downloadFile"; import { getFilenameFromPath } from "./utils/paths"; const version = process.env.npm_package_version; import masterViewport, { Viewport } from "./viewport"; -import { handleMS } from './packets/handlers/handleMS'; - +import { packetHandler } from './packets/packetHandler' let { ip: serverIP, mode, asset, theme } = queryParser(); // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; @@ -259,53 +219,6 @@ class Client extends EventEmitter { this.checkUpdater = null; this.viewport = masterViewport(this); - /** - * Assign handlers for all commands - * If you implement a new command, you need to add it here - */ - this.on("MS", handleMS); - this.on("CT", handleCT); - this.on("MC", handleMC); - this.on("RMC", handleRMC); - this.on("CI", handleCI); - this.on("SC", handleSC); - this.on("EI", handleEI); - this.on("FL", handleFL); - this.on("LE", handleLE); - this.on("EM", handleEM); - this.on("FM", handleFM); - this.on("FA", handleFA); - this.on("SM", handleSM); - this.on("MM", handleMM); - this.on("BD", handleBD); - this.on("BB", handleBB); - this.on("KB", handleKB); - this.on("KK", handleKK); - this.on("DONE", handleDONE); - this.on("BN", handleBN); - this.on("HP", handleHP); - this.on("RT", handleRT); - this.on("TI", handleTI); - this.on("ZZ", handleZZ); - this.on("HI", handleHI); - this.on("ID", handleID); - this.on("PN", handlePN); - this.on("SI", handleSI); - this.on("ARUP", handleARUP); - this.on("askchaa", handleaskchaa); - this.on("CC", handleCC); - this.on("RC", handleRC); - this.on("RM", handleRM); - this.on("RD", handleRD); - this.on("CharsCheck", handleCharsCheck); - this.on("PV", handlePV); - this.on("ASS", handleASS); - this.on("ackMS", handleackMS); - this.on("SP", handleSP); - this.on("JD", handleJD); - this.on("decryptor", () => { }); - this.on("CHECK", () => { }); - this.on("CH", () => { }); this._lastTimeICReceived = new Date(0); } @@ -703,20 +616,14 @@ class Client extends EventEmitter { const msg = e.data; console.debug(`S: ${msg}`); - const lines = msg.split("%"); - - for (const msg of lines) { - if (msg === "") { - break; - } - - const args = msg.split("#"); - const header = args[0]; + const data = msg.split("%")[0]; + const splitPacket = data.split('#') + const packetHeader = splitPacket[0]; + + packetHandler.has(packetHeader) + ? packetHandler.get(packetHeader)(splitPacket) + : console.warn(`Invalid packet header ${packetHeader}`); - if (!this.emit(header, args)) { - console.warn(`Invalid packet header ${header}`); - } - } } /** @@ -1308,7 +1215,7 @@ window.changeCallwords = changeCallwords; * Triggered by the modcall sfx dropdown */ export function modcall_test() { - handleZZ("test#test".split("#")); + packetHandler.get("ZZ")("test#test".split("#")); } window.modcall_test = modcall_test; @@ -1320,7 +1227,7 @@ export async function iniedit() { .value; const inicharID = client.charID; await client.handleCharacterInfo(ininame.split("&"), inicharID); - handlePV(`PV#0#CID#${inicharID}`.split("#")); + packetHandler.get("PV")(`PV#0#CID#${inicharID}`.split("#")); } window.iniedit = iniedit; -- cgit From d37c8330a8e70fcd74549ec52cde8b4be3ad3250 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 3 Sep 2022 17:11:47 +0200 Subject: provide mouseover for charicons --- webAO/client.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index ef3ab1a..980fadd 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -716,6 +716,7 @@ class Client extends EventEmitter { const exists = await fileExists(fileUrl); if (exists) { img.alt = chargs[0]; + img.title = chargs[0]; img.src = fileUrl; return; } -- 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/client.ts | 202 +++----------------------------------------------------- 1 file changed, 8 insertions(+), 194 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 980fadd..806c0a5 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -35,6 +35,9 @@ import { packetHandler } from './packets/packetHandler' let { ip: serverIP, mode, asset, theme } = queryParser(); // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; +import { showname_click } from './dom/showNameClick' +import { onReplayGo } from './dom/onReplayGo' +import { updateActionCommands } from './dom/updateActionCommands' export let AO_HOST = asset || DEFAULT_HOST; export const setAOhost = (val: string) => { AO_HOST = val @@ -619,10 +622,10 @@ class Client extends EventEmitter { const data = msg.split("%")[0]; const splitPacket = data.split('#') const packetHeader = splitPacket[0]; - - packetHandler.has(packetHeader) - ? packetHandler.get(packetHeader)(splitPacket) - : console.warn(`Invalid packet header ${packetHeader}`); + + packetHandler.has(packetHeader) + ? packetHandler.get(packetHeader)(splitPacket) + : console.warn(`Invalid packet header ${packetHeader}`); } @@ -947,29 +950,8 @@ class Client extends EventEmitter { } } -/** - * Triggered when the Return key is pressed on the out-of-character chat input box. - * @param {KeyboardEvent} event - */ -export function onOOCEnter(event: KeyboardEvent) { - if (event.keyCode === 13) { - client.sendOOC( - (document.getElementById("client_oocinputbox")).value - ); - (document.getElementById("client_oocinputbox")).value = - ""; - } -} -window.onOOCEnter = onOOCEnter; -/** - * Triggered when the user click replay GOOOOO - * @param {KeyboardEvent} event - */ -export function onReplayGo(_event: Event) { - client.handleReplay(); -} -window.onReplayGo = onReplayGo; + /** * Triggered when the Return key is pressed on the in-character chat input box. @@ -1091,100 +1073,6 @@ export function resetICParams() { } } -export function resetOffset(_event: Event) { - (document.getElementById("pair_offset")).value = "0"; - (document.getElementById("pair_y_offset")).value = "0"; -} -window.resetOffset = resetOffset; - -/** - * Triggered when the music search bar is changed - * @param {MouseEvent} event - */ -export function musiclist_filter(_event: Event) { - const musiclist_element = ( - document.getElementById("client_musiclist") - ); - const searchname = (( - document.getElementById("client_musicsearch") - )).value; - - musiclist_element.innerHTML = ""; - - for (const trackname of client.musics) { - if (trackname.toLowerCase().indexOf(searchname.toLowerCase()) !== -1) { - const newentry = document.createElement("OPTION"); - newentry.text = trackname; - musiclist_element.options.add(newentry); - } - } -} -window.musiclist_filter = musiclist_filter; - -/** - * Triggered when an item on the music list is clicked. - * @param {MouseEvent} event - */ -export function musiclist_click(_event: Event) { - const playtrack = (( - document.getElementById("client_musiclist") - )).value; - client.sendMusicChange(playtrack); - - // This is here so you can't actually select multiple tracks, - // even though the select tag has the multiple option to render differently - const musiclist_elements = (( - document.getElementById("client_musiclist") - )).selectedOptions; - for (let i = 0; i < musiclist_elements.length; i++) { - musiclist_elements[i].selected = false; - } -} -window.musiclist_click = musiclist_click; - -/** - * Triggered when a character in the mute list is clicked - * @param {MouseEvent} event - */ -export function mutelist_click(_event: Event) { - const mutelist = document.getElementById("mute_select"); - const selected_character = mutelist.options[mutelist.selectedIndex]; - - if (client.chars[selected_character.value].muted === false) { - client.chars[selected_character.value].muted = true; - selected_character.text = `${client.chars[selected_character.value].name - } (muted)`; - console.info(`muted ${client.chars[selected_character.value].name}`); - } else { - client.chars[selected_character.value].muted = false; - selected_character.text = client.chars[selected_character.value].name; - } -} -window.mutelist_click = mutelist_click; - -/** - * Triggered when the showname checkboc is clicked - * @param {MouseEvent} event - */ -export function showname_click(_event: Event) { - setCookie( - "showname", - String((document.getElementById("showname")).checked) - ); - setCookie( - "ic_chat_name", - (document.getElementById("ic_chat_name")).value - ); - - const css_s = document.getElementById("nameplate_setting"); - - if ((document.getElementById("showname")).checked) { - css_s.href = "styles/shownames.css"; - } else { - css_s.href = "styles/nameplates.css"; - } -} -window.showname_click = showname_click; /** * Triggered when an item on the area list is clicked. @@ -1714,55 +1602,9 @@ export function updateEvidenceIcon() { } window.updateEvidenceIcon = updateEvidenceIcon; -/** - * Update evidence icon. - */ -export function updateActionCommands(side: string) { - if (side === "jud") { - 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"; - } - // Update role selector - for ( - let i = 0, - role_select = document.getElementById("role_select"); - i < role_select.options.length; - i++ - ) { - if (side === role_select.options[i].value) { - role_select.options.selectedIndex = i; - return; - } - } -} -window.updateActionCommands = updateActionCommands; -/** - * Change background via OOC. - */ -export function changeBackgroundOOC() { - const selectedBG = document.getElementById("bg_select"); - const changeBGCommand = "bg $1"; - const bgFilename = document.getElementById("bg_filename"); - - let filename = ""; - if (selectedBG.selectedIndex === 0) { - filename = bgFilename.value; - } else { - filename = selectedBG.value; - } - if (mode === "join") { - client.sendOOC(`/${changeBGCommand.replace("$1", filename)}`); - } else if (mode === "replay") { - client.sendSelf(`BN#${filename}#%`); - } -} -window.changeBackgroundOOC = changeBackgroundOOC; /** * Change role via OOC. @@ -1864,34 +1706,6 @@ export function redHPP() { } window.redHPP = redHPP; -/** - * Update background preview. - */ -export function updateBackgroundPreview() { - const background_select = ( - document.getElementById("bg_select") - ); - const background_filename = ( - document.getElementById("bg_filename") - ); - const background_preview = ( - document.getElementById("bg_preview") - ); - - if (background_select.selectedIndex === 0) { - background_filename.style.display = "initial"; - background_preview.src = `${AO_HOST}background/${encodeURI( - background_filename.value.toLowerCase() - )}/defenseempty.png`; - } else { - background_filename.style.display = "none"; - background_preview.src = `${AO_HOST}background/${encodeURI( - background_select.value.toLowerCase() - )}/defenseempty.png`; - } -} -window.updateBackgroundPreview = updateBackgroundPreview; - /** * Highlights and selects a menu. * @param {number} menu the menu to be selected -- 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/client.ts | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 2 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 806c0a5..33f1802 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -36,7 +36,6 @@ let { ip: serverIP, mode, asset, theme } = queryParser(); // Unless there is an asset URL specified, use the wasabi one const DEFAULT_HOST = "http://attorneyoffline.de/base/"; import { showname_click } from './dom/showNameClick' -import { onReplayGo } from './dom/onReplayGo' import { updateActionCommands } from './dom/updateActionCommands' export let AO_HOST = asset || DEFAULT_HOST; export const setAOhost = (val: string) => { @@ -139,16 +138,20 @@ function isLowMemory() { oldLoading = true; } } + const fpPromise = FingerprintJS.load(); + fpPromise .then((fp) => fp.get()) .then((result) => { hdid = result.visitorId; + console.log("NEW CLIENT"); client = new Client(serverIP); isLowMemory(); client.loadResources(); }); + export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)); let lastICMessageTime = new Date(0); @@ -950,7 +953,29 @@ class Client extends EventEmitter { } } +/** + * Triggered when the Return key is pressed on the out-of-character chat input box. + * @param {KeyboardEvent} event + */ + export function onOOCEnter(event: KeyboardEvent) { + if (event.keyCode === 13) { + client.sendOOC( + (document.getElementById("client_oocinputbox")).value + ); + (document.getElementById("client_oocinputbox")).value = + ""; + } +} +window.onOOCEnter = onOOCEnter; +/** + * Triggered when the user click replay GOOOOO + * @param {KeyboardEvent} event + */ + export function onReplayGo(_event: Event) { + client.handleReplay(); +} +window.onReplayGo = onReplayGo; /** @@ -1073,6 +1098,70 @@ export function resetICParams() { } } +/** + * Triggered when the music search bar is changed + * @param {MouseEvent} event + */ + export function musiclist_filter(_event: Event) { + const musiclist_element = ( + document.getElementById("client_musiclist") + ); + const searchname = (( + document.getElementById("client_musicsearch") + )).value; + + musiclist_element.innerHTML = ""; + + for (const trackname of client.musics) { + if (trackname.toLowerCase().indexOf(searchname.toLowerCase()) !== -1) { + const newentry = document.createElement("OPTION"); + newentry.text = trackname; + musiclist_element.options.add(newentry); + } + } +} +window.musiclist_filter = musiclist_filter; + +/** + * Triggered when an item on the music list is clicked. + * @param {MouseEvent} event + */ +export function musiclist_click(_event: Event) { + const playtrack = (( + document.getElementById("client_musiclist") + )).value; + client.sendMusicChange(playtrack); + + // This is here so you can't actually select multiple tracks, + // even though the select tag has the multiple option to render differently + const musiclist_elements = (( + document.getElementById("client_musiclist") + )).selectedOptions; + for (let i = 0; i < musiclist_elements.length; i++) { + musiclist_elements[i].selected = false; + } +} +window.musiclist_click = musiclist_click; + +/** + * Triggered when a character in the mute list is clicked + * @param {MouseEvent} event + */ +export function mutelist_click(_event: Event) { + const mutelist = document.getElementById("mute_select"); + const selected_character = mutelist.options[mutelist.selectedIndex]; + + if (client.chars[selected_character.value].muted === false) { + client.chars[selected_character.value].muted = true; + selected_character.text = `${client.chars[selected_character.value].name + } (muted)`; + console.info(`muted ${client.chars[selected_character.value].name}`); + } else { + client.chars[selected_character.value].muted = false; + selected_character.text = client.chars[selected_character.value].name; + } +} +window.mutelist_click = mutelist_click; /** * Triggered when an item on the area list is clicked. @@ -1602,9 +1691,29 @@ export function updateEvidenceIcon() { } window.updateEvidenceIcon = updateEvidenceIcon; +/** + * Change background via OOC. + */ + export function changeBackgroundOOC() { + const selectedBG = document.getElementById("bg_select"); + const changeBGCommand = "bg $1"; + const bgFilename = document.getElementById("bg_filename"); + + let filename = ""; + if (selectedBG.selectedIndex === 0) { + filename = bgFilename.value; + } else { + filename = selectedBG.value; + } - + if (mode === "join") { + client.sendOOC(`/${changeBGCommand.replace("$1", filename)}`); + } else if (mode === "replay") { + client.sendSelf(`BN#${filename}#%`); + } +} +window.changeBackgroundOOC = changeBackgroundOOC; /** * Change role via OOC. @@ -1706,6 +1815,34 @@ export function redHPP() { } window.redHPP = redHPP; +/** + * Update background preview. + */ + export function updateBackgroundPreview() { + const background_select = ( + document.getElementById("bg_select") + ); + const background_filename = ( + document.getElementById("bg_filename") + ); + const background_preview = ( + document.getElementById("bg_preview") + ); + + if (background_select.selectedIndex === 0) { + background_filename.style.display = "initial"; + background_preview.src = `${AO_HOST}background/${encodeURI( + background_filename.value.toLowerCase() + )}/defenseempty.png`; + } else { + background_filename.style.display = "none"; + background_preview.src = `${AO_HOST}background/${encodeURI( + background_select.value.toLowerCase() + )}/defenseempty.png`; + } +} +window.updateBackgroundPreview = updateBackgroundPreview; + /** * Highlights and selects a menu. * @param {number} menu the menu to be selected -- 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/client.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 33f1802..5d5eb2c 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -37,10 +37,7 @@ let { ip: serverIP, mode, asset, theme } = queryParser(); const DEFAULT_HOST = "http://attorneyoffline.de/base/"; import { showname_click } from './dom/showNameClick' import { updateActionCommands } from './dom/updateActionCommands' -export let AO_HOST = asset || DEFAULT_HOST; -export const setAOhost = (val: string) => { - AO_HOST = val -} +import { AO_HOST } from './client/aoHost' let THEME: string = theme || "default"; let CHATBOX: string; -- cgit From fb3590ad774a07f45eaaaeb2b443ae264c302f3b Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 4 Sep 2022 20:45:52 -0400 Subject: Prep folder with example --- webAO/client.ts | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 5d5eb2c..3bf8854 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -1119,26 +1119,6 @@ export function resetICParams() { } window.musiclist_filter = musiclist_filter; -/** - * Triggered when an item on the music list is clicked. - * @param {MouseEvent} event - */ -export function musiclist_click(_event: Event) { - const playtrack = (( - document.getElementById("client_musiclist") - )).value; - client.sendMusicChange(playtrack); - - // This is here so you can't actually select multiple tracks, - // even though the select tag has the multiple option to render differently - const musiclist_elements = (( - document.getElementById("client_musiclist") - )).selectedOptions; - for (let i = 0; i < musiclist_elements.length; i++) { - musiclist_elements[i].selected = false; - } -} -window.musiclist_click = musiclist_click; /** * Triggered when a character in the mute list is clicked -- cgit From 34aba3b5b9572b707971d1fda9216ebcf91909ba Mon Sep 17 00:00:00 2001 From: Caleb Date: Mon, 5 Sep 2022 21:47:38 -0400 Subject: Moving some functions --- webAO/client.ts | 178 ++++++-------------------------------------------------- 1 file changed, 19 insertions(+), 159 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 3bf8854..d57f437 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -6,11 +6,10 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs"; import { EventEmitter } from "events"; -import tryUrls from "./utils/tryUrls"; +import { area_click } from './dom/areaClick' +import { onReplayGo } from './dom/onReplayGo' import { escapeChat, prepChat, safeTags, unescapeChat } from "./encoding"; // Load some defaults for the background and evidence dropdowns -import vanilla_character_arr from "./constants/characters.js"; -import vanilla_music_arr from "./constants/music.js"; import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; import chatbox_arr from "./styles/chatbox/chatboxes.js"; @@ -34,10 +33,9 @@ import masterViewport, { Viewport } from "./viewport"; import { packetHandler } from './packets/packetHandler' let { ip: serverIP, mode, asset, theme } = queryParser(); // Unless there is an asset URL specified, use the wasabi one -const DEFAULT_HOST = "http://attorneyoffline.de/base/"; import { showname_click } from './dom/showNameClick' import { updateActionCommands } from './dom/updateActionCommands' -import { AO_HOST } from './client/aoHost' +import { AO_HOST } from './client/aoHost' let THEME: string = theme || "default"; let CHATBOX: string; @@ -57,7 +55,7 @@ export const setOldLoading = (val: boolean) => { // presettings let selectedMenu = 1; -let selectedShout = 0; +export let selectedShout = 0; export let extrafeatures: string[] = []; export const setExtraFeatures = (val: any) => { @@ -950,131 +948,6 @@ class Client extends EventEmitter { } } -/** - * Triggered when the Return key is pressed on the out-of-character chat input box. - * @param {KeyboardEvent} event - */ - export function onOOCEnter(event: KeyboardEvent) { - if (event.keyCode === 13) { - client.sendOOC( - (document.getElementById("client_oocinputbox")).value - ); - (document.getElementById("client_oocinputbox")).value = - ""; - } -} -window.onOOCEnter = onOOCEnter; - -/** - * Triggered when the user click replay GOOOOO - * @param {KeyboardEvent} event - */ - export function onReplayGo(_event: Event) { - client.handleReplay(); -} -window.onReplayGo = onReplayGo; - - -/** - * Triggered when the Return key is pressed on the in-character chat input box. - * @param {KeyboardEvent} event - */ -export function onEnter(event: KeyboardEvent) { - if (event.keyCode === 13) { - const mychar = client.character; - const myemo = client.emote; - const evi = client.evidence; - const flip = Boolean( - document.getElementById("button_flip").classList.contains("dark") - ); - const flash = Boolean( - document.getElementById("button_flash").classList.contains("dark") - ); - const screenshake = Boolean( - document.getElementById("button_shake").classList.contains("dark") - ); - const noninterrupting_preanim = Boolean( - (document.getElementById("check_nonint")).checked - ); - const looping_sfx = Boolean( - (document.getElementById("check_loopsfx")).checked - ); - const color = Number( - (document.getElementById("textcolor")).value - ); - const showname = escapeChat( - (document.getElementById("ic_chat_name")).value - ); - const text = (document.getElementById("client_inputbox")) - .value; - const pairchar = (document.getElementById("pair_select")) - .value; - const pairoffset = Number( - (document.getElementById("pair_offset")).value - ); - const pairyoffset = Number( - (document.getElementById("pair_y_offset")).value - ); - const myrole = (document.getElementById("role_select")) - .value - ? (document.getElementById("role_select")).value - : mychar.side; - const additive = Boolean( - (document.getElementById("check_additive")).checked - ); - const effect = (document.getElementById("effect_select")) - .value; - - let sfxname = "0"; - let sfxdelay = 0; - let emote_mod = myemo.zoom; - if ((document.getElementById("sendsfx")).checked) { - sfxname = myemo.sfx; - sfxdelay = myemo.sfxdelay; - } - - // not to overwrite a 5 from the ini or anything else - if ((document.getElementById("sendpreanim")).checked) { - if (emote_mod === 0) { - emote_mod = 1; - } - } else if (emote_mod === 1) { - emote_mod = 0; - } - - client.sendIC( - myemo.deskmod, - myemo.preanim, - mychar.name, - myemo.emote, - text, - myrole, - sfxname, - emote_mod, - sfxdelay, - selectedShout, - evi, - flip, - flash, - color, - showname, - pairchar, - pairoffset, - pairyoffset, - noninterrupting_preanim, - looping_sfx, - screenshake, - "-", - "-", - "-", - additive, - effect - ); - } - return false; -} -window.onEnter = onEnter; - /** * Resets the IC parameters for the player to enter a new chat message. * This should only be called when the player's previous chat message @@ -1099,7 +972,7 @@ export function resetICParams() { * Triggered when the music search bar is changed * @param {MouseEvent} event */ - export function musiclist_filter(_event: Event) { +export function musiclist_filter(_event: Event) { const musiclist_element = ( document.getElementById("client_musiclist") ); @@ -1140,20 +1013,7 @@ export function mutelist_click(_event: Event) { } window.mutelist_click = mutelist_click; -/** - * Triggered when an item on the area list is clicked. - * @param {HTMLElement} el - */ -export function area_click(el: HTMLElement) { - const area = client.areas[el.id.substr(4)].name; - client.sendMusicChange(area); - - const areaHr = document.createElement("div"); - areaHr.className = "hrtext"; - areaHr.textContent = `switched to ${el.textContent}`; - document.getElementById("client_log").appendChild(areaHr); -} -window.area_click = area_click; + /** * Triggered by a changed callword list @@ -1671,7 +1531,7 @@ window.updateEvidenceIcon = updateEvidenceIcon; /** * Change background via OOC. */ - export function changeBackgroundOOC() { +export function changeBackgroundOOC() { const selectedBG = document.getElementById("bg_select"); const changeBGCommand = "bg $1"; const bgFilename = document.getElementById("bg_filename"); @@ -1795,27 +1655,27 @@ window.redHPP = redHPP; /** * Update background preview. */ - export function updateBackgroundPreview() { +export function updateBackgroundPreview() { const background_select = ( - document.getElementById("bg_select") + document.getElementById("bg_select") ); const background_filename = ( - document.getElementById("bg_filename") + document.getElementById("bg_filename") ); const background_preview = ( - document.getElementById("bg_preview") + document.getElementById("bg_preview") ); if (background_select.selectedIndex === 0) { - background_filename.style.display = "initial"; - background_preview.src = `${AO_HOST}background/${encodeURI( - background_filename.value.toLowerCase() - )}/defenseempty.png`; + background_filename.style.display = "initial"; + background_preview.src = `${AO_HOST}background/${encodeURI( + background_filename.value.toLowerCase() + )}/defenseempty.png`; } else { - background_filename.style.display = "none"; - background_preview.src = `${AO_HOST}background/${encodeURI( - background_select.value.toLowerCase() - )}/defenseempty.png`; + background_filename.style.display = "none"; + background_preview.src = `${AO_HOST}background/${encodeURI( + background_select.value.toLowerCase() + )}/defenseempty.png`; } } window.updateBackgroundPreview = updateBackgroundPreview; -- 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/client.ts | 238 ++------------------------------------------------------ 1 file changed, 5 insertions(+), 233 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index d57f437..321872f 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -32,12 +32,13 @@ const version = process.env.npm_package_version; import masterViewport, { Viewport } from "./viewport"; import { packetHandler } from './packets/packetHandler' let { ip: serverIP, mode, asset, theme } = queryParser(); +import { cancelEvidence } from './dom/cancelEvidence' // Unless there is an asset URL specified, use the wasabi one import { showname_click } from './dom/showNameClick' import { updateActionCommands } from './dom/updateActionCommands' import { AO_HOST } from './client/aoHost' let THEME: string = theme || "default"; -let CHATBOX: string; +export let CHATBOX: string; export let client: Client; @@ -56,7 +57,9 @@ export const setOldLoading = (val: boolean) => { // presettings let selectedMenu = 1; export let selectedShout = 0; - +export const setSelectedShout = (val: number) => { + selectedShout = val +} export let extrafeatures: string[] = []; export const setExtraFeatures = (val: any) => { extrafeatures = val @@ -795,12 +798,6 @@ class Client extends EventEmitter { } } - - - - - - resetMusicList() { this.musics = []; document.getElementById("client_musiclist").innerHTML = ""; @@ -968,53 +965,6 @@ export function resetICParams() { } } -/** - * Triggered when the music search bar is changed - * @param {MouseEvent} event - */ -export function musiclist_filter(_event: Event) { - const musiclist_element = ( - document.getElementById("client_musiclist") - ); - const searchname = (( - document.getElementById("client_musicsearch") - )).value; - - musiclist_element.innerHTML = ""; - - for (const trackname of client.musics) { - if (trackname.toLowerCase().indexOf(searchname.toLowerCase()) !== -1) { - const newentry = document.createElement("OPTION"); - newentry.text = trackname; - musiclist_element.options.add(newentry); - } - } -} -window.musiclist_filter = musiclist_filter; - - -/** - * Triggered when a character in the mute list is clicked - * @param {MouseEvent} event - */ -export function mutelist_click(_event: Event) { - const mutelist = document.getElementById("mute_select"); - const selected_character = mutelist.options[mutelist.selectedIndex]; - - if (client.chars[selected_character.value].muted === false) { - client.chars[selected_character.value].muted = true; - selected_character.text = `${client.chars[selected_character.value].name - } (muted)`; - console.info(`muted ${client.chars[selected_character.value].name}`); - } else { - client.chars[selected_character.value].muted = false; - selected_character.text = client.chars[selected_character.value].name; - } -} -window.mutelist_click = mutelist_click; - - - /** * Triggered by a changed callword list */ @@ -1134,29 +1084,6 @@ export function imgError(image: HTMLImageElement) { } window.imgError = imgError; -/** - * Triggered when there was an error loading a sound - * @param {HTMLAudioElement} image the element containing the missing sound - */ -export function opusCheck( - channel: HTMLAudioElement -): OnErrorEventHandlerNonNull { - const audio = channel.src; - if (audio === "") { - return; - } - console.info(`failed to load sound ${channel.src}`); - let oldsrc = ""; - let newsrc = ""; - oldsrc = channel.src; - if (!oldsrc.endsWith(".opus")) { - newsrc = oldsrc.replace(".mp3", ".opus"); - newsrc = newsrc.replace(".wav", ".opus"); - channel.src = newsrc; // unload so the old sprite doesn't persist - } -} -window.opusCheck = opusCheck; - /** * Triggered when the reconnect button is pushed. */ @@ -1298,52 +1225,6 @@ export function pickEmotion(emo: number) { } window.pickEmotion = pickEmotion; -/** - * Highlights and selects an evidence for in-character chat. - * @param {string} evidence the evidence to be presented - */ -export function pickEvidence(evidence: number) { - if (client.selectedEvidence !== evidence) { - // Update selected evidence - if (client.selectedEvidence > 0) { - document.getElementById(`evi_${client.selectedEvidence}`).className = - "evi_icon"; - } - document.getElementById(`evi_${evidence}`).className = "evi_icon dark"; - client.selectedEvidence = evidence; - - // Show evidence on information window - (document.getElementById("evi_name")).value = - client.evidences[evidence - 1].name; - (document.getElementById("evi_desc")).value = - client.evidences[evidence - 1].desc; - - // Update icon - const icon_id = getIndexFromSelect( - "evi_select", - client.evidences[evidence - 1].filename - ); - (document.getElementById("evi_select")).selectedIndex = - icon_id; - if (icon_id === 0) { - (document.getElementById("evi_filename")).value = - client.evidences[evidence - 1].filename; - } - updateEvidenceIcon(); - - // Update button - document.getElementById("evi_add").className = - "client_button hover_button inactive"; - document.getElementById("evi_edit").className = - "client_button hover_button"; - document.getElementById("evi_cancel").className = - "client_button hover_button"; - document.getElementById("evi_del").className = "client_button hover_button"; - } else { - cancelEvidence(); - } -} -window.pickEvidence = pickEvidence; /** * Add evidence. @@ -1393,37 +1274,6 @@ export function deleteEvidence() { } window.deleteEvidence = deleteEvidence; -/** - * Cancel evidence selection. - */ -export function cancelEvidence() { - // Clear evidence data - if (client.selectedEvidence > 0) { - document.getElementById(`evi_${client.selectedEvidence}`).className = - "evi_icon"; - } - client.selectedEvidence = 0; - - // Clear evidence on information window - (document.getElementById("evi_select")).selectedIndex = 0; - updateEvidenceIcon(); // Update icon widget - (document.getElementById("evi_filename")).value = ""; - (document.getElementById("evi_name")).value = ""; - (document.getElementById("evi_desc")).value = ""; - (( - document.getElementById("evi_preview") - )).src = `${AO_HOST}misc/empty.png`; // Clear icon - - // Update button - document.getElementById("evi_add").className = "client_button hover_button"; - document.getElementById("evi_edit").className = - "client_button hover_button inactive"; - document.getElementById("evi_cancel").className = - "client_button hover_button inactive"; - document.getElementById("evi_del").className = - "client_button hover_button inactive"; -} -window.cancelEvidence = cancelEvidence; /** * Find index of anything in select box. @@ -1467,38 +1317,7 @@ export function setChatbox(style: string) { } window.setChatbox = setChatbox; -/** - * Set the font size for the chatbox - */ -export function resizeChatbox() { - const chatContainerBox = document.getElementById("client_chatcontainer"); - const gameHeight = document.getElementById("client_background").offsetHeight; - - chatContainerBox.style.fontSize = `${(gameHeight * 0.0521).toFixed(1)}px`; - - const trackstatus = (document.getElementById("client_trackstatustext")); - trackstatus.width = (trackstatus.offsetWidth - 1) + "px"; - - - //clock - const now = new Date(); - let weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; - const month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - document.getElementById("client_clock_month").innerText = month[now.getMonth()]; - console.debug(CHATBOX); - if (CHATBOX == "acww") { - weekday = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; - document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; - document.getElementById("client_clock_date").innerText = now.getDay() + "/" + now.getMonth(); - document.getElementById("client_clock_time").innerText = now.getHours() + ":" + now.getMinutes(); - } else if (CHATBOX == "key") { - weekday = ["Sun.", "Mon.", "Tue.", "Wed.", "Thu.", "Fri.", "Sat."]; - document.getElementById("client_clock_weekday").innerText = weekday[now.getDay()]; - document.getElementById("client_clock_date").innerText = String(now.getDay()); - } -} -window.resizeChatbox = resizeChatbox; /** * Update evidence icon. @@ -1652,33 +1471,6 @@ export function redHPP() { } window.redHPP = redHPP; -/** - * Update background preview. - */ -export function updateBackgroundPreview() { - const background_select = ( - document.getElementById("bg_select") - ); - const background_filename = ( - document.getElementById("bg_filename") - ); - const background_preview = ( - document.getElementById("bg_preview") - ); - - if (background_select.selectedIndex === 0) { - background_filename.style.display = "initial"; - background_preview.src = `${AO_HOST}background/${encodeURI( - background_filename.value.toLowerCase() - )}/defenseempty.png`; - } else { - background_filename.style.display = "none"; - background_preview.src = `${AO_HOST}background/${encodeURI( - background_select.value.toLowerCase() - )}/defenseempty.png`; - } -} -window.updateBackgroundPreview = updateBackgroundPreview; /** * Highlights and selects a menu. @@ -1697,24 +1489,4 @@ export function toggleMenu(menu: number) { } window.toggleMenu = toggleMenu; -/** - * Highlights and selects a shout for in-character chat. - * If the same shout button is selected, then the shout is canceled. - * @param {number} shout the new shout to be selected - */ -export function toggleShout(shout: number) { - if (shout === selectedShout) { - document.getElementById(`button_${shout}`).className = "client_button"; - selectedShout = 0; - } else { - document.getElementById(`button_${shout}`).className = "client_button dark"; - if (selectedShout) { - document.getElementById(`button_${selectedShout}`).className = - "client_button"; - } - selectedShout = shout; - } -} -window.toggleShout = toggleShout; - export default Client; -- 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/client.ts | 158 +------------------------------------------------------- 1 file changed, 2 insertions(+), 156 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 321872f..5618f3e 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -965,54 +965,6 @@ export function resetICParams() { } } -/** - * Triggered by a changed callword list - */ -export function changeCallwords() { - client.callwords = (( - document.getElementById("client_callwords") - )).value.split("\n"); - setCookie("callwords", client.callwords.join("\n")); -} -window.changeCallwords = changeCallwords; - -/** - * Triggered by the modcall sfx dropdown - */ -export function modcall_test() { - packetHandler.get("ZZ")("test#test".split("#")); -} -window.modcall_test = modcall_test; - -/** - * Triggered by the ini button. - */ -export async function iniedit() { - const ininame = (document.getElementById("client_ininame")) - .value; - const inicharID = client.charID; - await client.handleCharacterInfo(ininame.split("&"), inicharID); - packetHandler.get("PV")(`PV#0#CID#${inicharID}`.split("#")); -} -window.iniedit = iniedit; - -/** - * Triggered by the pantilt checkbox - */ -export async function switchPanTilt() { - const fullview = document.getElementById("client_fullview"); - const checkbox = document.getElementById("client_pantilt"); - - if (checkbox.checked) { - fullview.style.transition = "0.5s ease-in-out"; - } else { - fullview.style.transition = "none"; - } - - return; -} -window.switchPanTilt = switchPanTilt; - /** * Triggered by the change aspect ratio checkbox */ @@ -1201,29 +1153,7 @@ export function pickChar(ccharacter: number) { } window.pickChar = pickChar; -/** - * Highlights and selects an emotion for in-character chat. - * @param {string} emo the new emotion to be selected - */ -export function pickEmotion(emo: number) { - try { - if (client.selectedEmote !== -1) { - document.getElementById(`emo_${client.selectedEmote}`).className = - "emote_button"; - } - } catch (err) { - // do nothing - } - client.selectedEmote = emo; - document.getElementById(`emo_${emo}`).className = "emote_button dark"; - - (document.getElementById("sendsfx")).checked = - client.emote.sfx.length > 1; - (document.getElementById("sendpreanim")).checked = - client.emote.zoom == 1; -} -window.pickEmotion = pickEmotion; /** @@ -1244,25 +1174,7 @@ export function addEvidence() { } window.addEvidence = addEvidence; -/** - * Edit selected evidence. - */ -export function editEvidence() { - const evidence_select = ( - document.getElementById("evi_select") - ); - const id = client.selectedEvidence - 1; - client.sendEE( - id, - (document.getElementById("evi_name")).value, - (document.getElementById("evi_desc")).value, - evidence_select.selectedIndex === 0 - ? (document.getElementById("evi_filename")).value - : evidence_select.options[evidence_select.selectedIndex].text - ); - cancelEvidence(); -} -window.editEvidence = editEvidence; + /** * Delete selected evidence. @@ -1275,22 +1187,7 @@ export function deleteEvidence() { window.deleteEvidence = deleteEvidence; -/** - * Find index of anything in select box. - * @param {string} select_box the select element name - * @param {string} value the value that need to be compared - */ -export function getIndexFromSelect(select_box: string, value: string) { - // Find if icon alraedy existed in select box - const select_element = document.getElementById(select_box); - for (let i = 1; i < select_element.length; ++i) { - if (select_element.options[i].value === value) { - return i; - } - } - return 0; -} -window.getIndexFromSelect = getIndexFromSelect; + /** * Set the style of the chatbox @@ -1319,57 +1216,6 @@ window.setChatbox = setChatbox; -/** - * Update evidence icon. - */ -export function updateEvidenceIcon() { - const evidence_select = ( - document.getElementById("evi_select") - ); - const evidence_filename = ( - document.getElementById("evi_filename") - ); - const evidence_iconbox = ( - document.getElementById("evi_preview") - ); - - if (evidence_select.selectedIndex === 0) { - evidence_filename.style.display = "initial"; - evidence_iconbox.src = `${AO_HOST}evidence/${encodeURI( - evidence_filename.value.toLowerCase() - )}`; - } else { - evidence_filename.style.display = "none"; - evidence_iconbox.src = `${AO_HOST}evidence/${encodeURI( - evidence_select.value.toLowerCase() - )}`; - } -} -window.updateEvidenceIcon = updateEvidenceIcon; - -/** - * Change background via OOC. - */ -export function changeBackgroundOOC() { - const selectedBG = document.getElementById("bg_select"); - const changeBGCommand = "bg $1"; - const bgFilename = document.getElementById("bg_filename"); - - let filename = ""; - if (selectedBG.selectedIndex === 0) { - filename = bgFilename.value; - } else { - filename = selectedBG.value; - } - - - if (mode === "join") { - client.sendOOC(`/${changeBGCommand.replace("$1", filename)}`); - } else if (mode === "replay") { - client.sendSelf(`BN#${filename}#%`); - } -} -window.changeBackgroundOOC = changeBackgroundOOC; /** * Change role via OOC. -- cgit From d99a619e26f38c729d74d8dc585e8ce13236ffb7 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 8 Sep 2022 00:51:31 -0400 Subject: Removed all window functions from client --- webAO/client.ts | 402 ++++---------------------------------------------------- 1 file changed, 25 insertions(+), 377 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 5618f3e..62539ea 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -5,42 +5,44 @@ */ import FingerprintJS from "@fingerprintjs/fingerprintjs"; -import { EventEmitter } from "events"; -import { area_click } from './dom/areaClick' -import { onReplayGo } from './dom/onReplayGo' -import { escapeChat, prepChat, safeTags, unescapeChat } from "./encoding"; -// Load some defaults for the background and evidence dropdowns import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; -import chatbox_arr from "./styles/chatbox/chatboxes.js"; import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; import setCookie from "./utils/setCookie"; +import fileExists from "./utils/fileExists.js"; +import queryParser from "./utils/queryParser"; +import getResources from "./utils/getResources.js"; +import downloadFile from "./services/downloadFile"; +import masterViewport, { Viewport } from "./viewport"; +import { EventEmitter } from "events"; +import { area_click } from './dom/areaClick' +import { onReplayGo } from './dom/onReplayGo' +import { escapeChat, safeTags, unescapeChat } from "./encoding"; +import { setChatbox } from "./dom/setChatbox"; import { request } from "./services/request.js"; import { changeShoutVolume, changeSFXVolume, changeTestimonyVolume, } from "./dom/changeVolume.js"; -import fileExists from "./utils/fileExists.js"; -import queryParser from "./utils/queryParser"; -import getResources from "./utils/getResources.js"; -import transparentPng from "./constants/transparentPng"; -import downloadFile from "./services/downloadFile"; import { getFilenameFromPath } from "./utils/paths"; -const version = process.env.npm_package_version; -import masterViewport, { Viewport } from "./viewport"; import { packetHandler } from './packets/packetHandler' -let { ip: serverIP, mode, asset, theme } = queryParser(); -import { cancelEvidence } from './dom/cancelEvidence' -// Unless there is an asset URL specified, use the wasabi one import { showname_click } from './dom/showNameClick' -import { updateActionCommands } from './dom/updateActionCommands' import { AO_HOST } from './client/aoHost' + +const version = process.env.npm_package_version; +let { ip: serverIP, mode, theme } = queryParser(); + let THEME: string = theme || "default"; export let CHATBOX: string; - +export const setCHATBOX = (val: string) => { + CHATBOX = val +} export let client: Client; +export const setClient = (val: Client) => { + client = val +} export const UPDATE_INTERVAL = 60; @@ -55,7 +57,10 @@ export const setOldLoading = (val: boolean) => { } // presettings -let selectedMenu = 1; +export let selectedMenu = 1; +export const setSelectedMenu = (val: number) => { + selectedMenu = val +} export let selectedShout = 0; export const setSelectedShout = (val: number) => { selectedShout = val @@ -71,62 +76,6 @@ export const setBanned = (val: boolean) => { } let hdid: string; -declare global { - interface Window { - toggleShout: (shout: number) => void; - toggleMenu: (menu: number) => void; - updateBackgroundPreview: () => void; - redHPP: () => void; - addHPP: () => void; - redHPD: () => void; - addHPD: () => void; - guilty: () => void; - notguilty: () => void; - initCE: () => void; - initWT: () => void; - callMod: () => void; - randomCharacterOOC: () => void; - changeRoleOOC: () => void; - changeBackgroundOOC: () => void; - updateActionCommands: (side: string) => void; - updateEvidenceIcon: () => void; - resizeChatbox: () => void; - setChatbox: (style: string) => void; - getIndexFromSelect: (select_box: string, value: string) => Number; - cancelEvidence: () => void; - deleteEvidence: () => void; - editEvidence: () => void; - addEvidence: () => void; - pickEvidence: (evidence: any) => void; - pickEmotion: (emo: any) => void; - pickChar: (ccharacter: any) => void; - chartable_filter: (_event: any) => void; - ReconnectButton: (_event: any) => void; - opusCheck: (channel: HTMLAudioElement) => OnErrorEventHandlerNonNull; - imgError: (image: any) => void; - charError: (image: any) => void; - changeCharacter: (_event: any) => void; - switchChatOffset: () => void; - switchAspectRatio: () => void; - switchPanTilt: (addcheck: number) => void; - iniedit: () => void; - modcall_test: () => void; - reloadTheme: () => void; - changeCallwords: () => void; - changeBlipVolume: () => void; - changeMusicVolume: () => void; - area_click: (el: any) => void; - showname_click: (_event: any) => void; - mutelist_click: (_event: any) => void; - musiclist_click: (_event: any) => void; - musiclist_filter: (_event: any) => void; - resetOffset: (_event: any) => void; - onEnter: (event: any) => void; - onReplayGo: (_event: any) => void; - onOOCEnter: (_event: any) => void; - } -} - function isLowMemory() { if ( /webOS|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|PlayStation|Nintendo|Opera Mini/i.test( @@ -965,90 +914,6 @@ export function resetICParams() { } } -/** - * Triggered by the change aspect ratio checkbox - */ -export async function switchAspectRatio() { - const background = document.getElementById("client_gamewindow"); - const offsetCheck = ( - document.getElementById("client_hdviewport_offset") - ); - if ( - (document.getElementById("client_hdviewport")).checked - ) { - background.style.paddingBottom = "56.25%"; - offsetCheck.disabled = false; - } else { - background.style.paddingBottom = "75%"; - offsetCheck.disabled = true; - } -} -window.switchAspectRatio = switchAspectRatio; - -/** - * Triggered by the change aspect ratio checkbox - */ -export async function switchChatOffset() { - const container = document.getElementById("client_chatcontainer"); - if ( - (document.getElementById("client_hdviewport_offset")) - .checked - ) { - container.style.width = "80%"; - container.style.left = "10%"; - } else { - container.style.width = "100%"; - container.style.left = "0"; - } -} -window.switchChatOffset = switchChatOffset; - -/** - * Triggered when a character icon is clicked in the character selection menu. - * @param {MouseEvent} event - */ -export function changeCharacter(_event: Event) { - document.getElementById("client_waiting").style.display = "block"; - document.getElementById("client_charselect").style.display = "block"; - document.getElementById("client_emo").innerHTML = ""; -} -window.changeCharacter = changeCharacter; - -/** - * Triggered when there was an error loading a character sprite. - * @param {HTMLImageElement} image the element containing the missing image - */ -export function charError(image: HTMLImageElement) { - console.warn(`${image.src} is missing from webAO`); - image.src = transparentPng; - return true; -} -window.charError = charError; - -/** - * Triggered when there was an error loading a generic sprite. - * @param {HTMLImageElement} image the element containing the missing image - */ -export function imgError(image: HTMLImageElement) { - image.onerror = null; - image.src = ""; // unload so the old sprite doesn't persist - return true; -} -window.imgError = imgError; - -/** - * Triggered when the reconnect button is pushed. - */ -export function ReconnectButton() { - client.cleanup(); - client = new Client(serverIP); - - if (client) { - document.getElementById("client_error").style.display = "none"; - } -} -window.ReconnectButton = ReconnectButton; - /** * Appends a message to the in-character chat log. * @param {string} msg the string to be added @@ -1118,221 +983,4 @@ export function checkCallword(message: string, sfxAudio: HTMLAudioElement) { } } -/** - * Triggered when the music search bar is changed - * @param {MouseEvent} event - */ -export function chartable_filter(_event: Event) { - const searchname = (( - document.getElementById("client_charactersearch") - )).value; - - client.chars.forEach((character: any, charid: number) => { - const demothing = document.getElementById(`demo_${charid}`); - if (character.name.toLowerCase().indexOf(searchname.toLowerCase()) === -1) { - demothing.style.display = "none"; - } else { - demothing.style.display = "inline-block"; - } - }); -} -window.chartable_filter = chartable_filter; - -/** - * Requests to play as a character. - * @param {number} ccharacter the character ID; if this is a large number, - * then spectator is chosen instead. - */ -export function pickChar(ccharacter: number) { - if (ccharacter === -1) { - // Spectator - document.getElementById("client_waiting").style.display = "none"; - document.getElementById("client_charselect").style.display = "none"; - } - client.sendCharacter(ccharacter); -} -window.pickChar = pickChar; - - - - -/** - * Add evidence. - */ -export function addEvidence() { - const evidence_select = ( - document.getElementById("evi_select") - ); - client.sendPE( - (document.getElementById("evi_name")).value, - (document.getElementById("evi_desc")).value, - evidence_select.selectedIndex === 0 - ? (document.getElementById("evi_filename")).value - : evidence_select.options[evidence_select.selectedIndex].text - ); - cancelEvidence(); -} -window.addEvidence = addEvidence; - - - -/** - * Delete selected evidence. - */ -export function deleteEvidence() { - const id = client.selectedEvidence - 1; - client.sendDE(id); - cancelEvidence(); -} -window.deleteEvidence = deleteEvidence; - - - - -/** - * Set the style of the chatbox - */ -export function setChatbox(style: string) { - const chatbox_theme = ( - document.getElementById("chatbox_theme") - ); - const themeselect = ( - document.getElementById("client_chatboxselect") - ); - CHATBOX = themeselect.value; - - setCookie("chatbox", CHATBOX); - if (CHATBOX === "dynamic") { - if (chatbox_arr.includes(style)) { - chatbox_theme.href = `styles/chatbox/${style}.css`; - } else { - chatbox_theme.href = "styles/chatbox/aa.css"; - } - } else { - chatbox_theme.href = `styles/chatbox/${CHATBOX}.css`; - } -} -window.setChatbox = setChatbox; - - - - -/** - * Change role via OOC. - */ -export function changeRoleOOC() { - const roleselect = document.getElementById("role_select"); - - client.sendOOC(`/pos ${roleselect.value}`); - client.sendServer(`SP#${roleselect.value}#%`); - updateActionCommands(roleselect.value); -} -window.changeRoleOOC = changeRoleOOC; - -/** - * Random character via OOC. - */ -export function randomCharacterOOC() { - client.sendOOC(`/randomchar`); -} -window.randomCharacterOOC = randomCharacterOOC; - -/** - * Call mod. - */ -export function callMod() { - let modcall; - if (extrafeatures.includes("modcall_reason")) { - modcall = prompt("Please enter the reason for the modcall", ""); - } - if (modcall == null || modcall === "") { - // cancel - } else { - client.sendZZ(modcall); - } -} -window.callMod = callMod; - -/** - * Declare witness testimony. - */ -export function initWT() { - client.sendRT("testimony1"); -} -window.initWT = initWT; - -/** - * Declare cross examination. - */ -export function initCE() { - client.sendRT("testimony2"); -} -window.initCE = initCE; - -/** - * Declare the defendant not guilty - */ -export function notguilty() { - client.sendRT("judgeruling#0"); -} -window.notguilty = notguilty; - -/** - * Declare the defendant not guilty - */ -export function guilty() { - client.sendRT("judgeruling#1"); -} -window.guilty = guilty; - -/** - * Increment defense health point. - */ -export function addHPD() { - client.sendHP(1, client.hp[0] + 1); -} -window.addHPD = addHPD; - -/** - * Decrement defense health point. - */ -export function redHPD() { - client.sendHP(1, client.hp[0] - 1); -} -window.redHPD = redHPD; - -/** - * Increment prosecution health point. - */ -export function addHPP() { - client.sendHP(2, client.hp[1] + 1); -} -window.addHPP = addHPP; - -/** - * Decrement prosecution health point. - */ -export function redHPP() { - client.sendHP(2, client.hp[1] - 1); -} -window.redHPP = redHPP; - - -/** - * Highlights and selects a menu. - * @param {number} menu the menu to be selected - */ -export function toggleMenu(menu: number) { - if (menu !== selectedMenu) { - document.getElementById(`menu_${menu}`).className = "menu_button active"; - document.getElementById(`content_${menu}`).className = - "menu_content active"; - document.getElementById(`menu_${selectedMenu}`).className = "menu_button"; - document.getElementById(`content_${selectedMenu}`).className = - "menu_content"; - selectedMenu = menu; - } -} -window.toggleMenu = toggleMenu; - -export default Client; +export default Client; \ No newline at end of file -- 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/client.ts | 199 ++++++++++++-------------------------------------------- 1 file changed, 43 insertions(+), 156 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 62539ea..4d01cfd 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -7,6 +7,7 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs"; import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; +import {sender, ISender} from './client/sender/index' import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; import setCookie from "./utils/setCookie"; @@ -87,13 +88,18 @@ function isLowMemory() { } const fpPromise = FingerprintJS.load(); +const connect = (address: string) => { +} fpPromise .then((fp) => fp.get()) .then((result) => { hdid = result.visitorId; console.log("NEW CLIENT"); + + // Create the new client and connect it client = new Client(serverIP); + client.connect() isLowMemory(); client.loadResources(); @@ -123,56 +129,51 @@ class Client extends EventEmitter { resources: any; selectedEmote: number; selectedEvidence: number; + sender: ISender; checkUpdater: any; _lastTimeICReceived: any; viewport: Viewport; + connect: () => void; constructor(address: string) { super(); - if (mode !== "replay") { - this.serv = new WebSocket(`ws://${address}`); - // Assign the websocket events - this.serv.addEventListener("open", this.emit.bind(this, "open")); - this.serv.addEventListener("close", this.emit.bind(this, "close")); - this.serv.addEventListener("message", this.emit.bind(this, "message")); - this.serv.addEventListener("error", this.emit.bind(this, "error")); - } else { - this.joinServer(); - } - this.on("open", this.onOpen.bind(this)); - this.on("close", this.onClose.bind(this)); - this.on("message", this.onMessage.bind(this)); - this.on("error", this.onError.bind(this)); - - // Preset some of the variables + this.connect = () => { + this.on("open", this.onOpen.bind(this)); + this.on("close", this.onClose.bind(this)); + this.on("message", this.onMessage.bind(this)); + this.on("error", this.onError.bind(this)); + if (mode !== "replay") { + this.serv = new WebSocket(`ws://${address}`); + // Assign the websocket events + this.serv.addEventListener("open", this.emit.bind(this, "open")); + this.serv.addEventListener("close", this.emit.bind(this, "close")); + this.serv.addEventListener("message", this.emit.bind(this, "message")); + this.serv.addEventListener("error", this.emit.bind(this, "error")); + } else { + this.joinServer(); + } + } this.hp = [0, 0]; - this.playerID = 1; this.charID = -1; this.char_list_length = 0; this.evidence_list_length = 0; this.music_list_length = 0; this.testimonyID = 0; - this.chars = []; this.emotes = []; this.evidences = []; this.areas = []; this.musics = []; - this.musics_time = false; - this.callwords = []; - this.resources = getResources(AO_HOST, THEME); - this.selectedEmote = -1; this.selectedEvidence = 0; - this.checkUpdater = null; + this.sender = sender this.viewport = masterViewport(this); - this._lastTimeICReceived = new Date(0); } @@ -199,13 +200,7 @@ class Client extends EventEmitter { : 0; } - /** - * Hook for sending messages to the server - * @param {string} message the message to send - */ - sendServer(message: string) { - mode === "replay" ? this.sendSelf(message) : this.serv.send(message); - } + /** * Hook for sending messages to the client @@ -216,17 +211,6 @@ class Client extends EventEmitter { setTimeout(() => this.onMessage(message_event), 1); } - /** - * Hook for sending messages to the client - * @param {string} message the message to send - */ - sendSelf(message: string) { - (( - document.getElementById("client_ooclog") - )).value += `${message}\r\n`; - this.handleSelf(message); - } - /** * Sends an out-of-character chat message. * @param {string} message the message to send @@ -253,110 +237,11 @@ class Client extends EventEmitter { // Command Not Recognized } } else { - this.sendServer(`CT#${oocName}#${oocMessage}#%`); + this.sender.sendServer(`CT#${oocName}#${oocMessage}#%`); } } - /** - * Sends an in-character chat message. - * @param {number} deskmod controls the desk - * @param {string} speaking who is speaking - * @param {string} name the name of the current character - * @param {string} silent whether or not it's silent - * @param {string} message the message to be sent - * @param {string} side the name of the side in the background - * @param {string} sfx_name the name of the sound effect - * @param {number} emote_modifier whether or not to zoom - * @param {number} sfx_delay the delay (in milliseconds) to play the sound effect - * @param {number} objection_modifier the number of the shout to play - * @param {string} evidence the filename of evidence to show - * @param {boolean} flip change to 1 to reverse sprite for position changes - * @param {boolean} realization screen flash effect - * @param {number} text_color text color - * @param {string} showname custom name to be displayed (optional) - * @param {number} other_charid paired character (optional) - * @param {number} self_offset offset to paired character (optional) - * @param {number} noninterrupting_preanim play the full preanim (optional) - */ - sendIC( - deskmod: number, - preanim: string, - name: string, - emote: string, - message: string, - side: string, - sfx_name: string, - emote_modifier: number, - sfx_delay: number, - objection_modifier: number, - evidence: number, - flip: boolean, - realization: boolean, - text_color: number, - showname: string, - other_charid: string, - self_hoffset: number, - self_yoffset: number, - noninterrupting_preanim: boolean, - looping_sfx: boolean, - screenshake: boolean, - frame_screenshake: string, - frame_realization: string, - frame_sfx: string, - additive: boolean, - effect: string - ) { - let extra_cccc = ""; - let other_emote = ""; - let other_offset = ""; - let extra_27 = ""; - let extra_28 = ""; - - if (extrafeatures.includes("cccc_ic_support")) { - const self_offset = extrafeatures.includes("y_offset") - ? `${self_hoffset}${self_yoffset}` - : self_hoffset; // HACK: this should be an & but client fucked it up and all the servers adopted it - if (mode === "replay") { - other_emote = "##"; - other_offset = "#0#0"; - } - extra_cccc = `${escapeChat( - showname - )}#${other_charid}${other_emote}#${self_offset}${other_offset}#${Number( - noninterrupting_preanim - )}#`; - - if (extrafeatures.includes("looping_sfx")) { - extra_27 = `${Number(looping_sfx)}#${Number( - screenshake - )}#${frame_screenshake}#${frame_realization}#${frame_sfx}#`; - if (extrafeatures.includes("effects")) { - extra_28 = `${Number(additive)}#${escapeChat(effect)}#`; - } - } - } - const serverMessage = - `MS#${deskmod}#${escapeChat(preanim)}#${escapeChat(name)}#${escapeChat( - emote - )}` + - `#${escapeChat(message)}#${escapeChat(side)}#${escapeChat( - sfx_name - )}#${emote_modifier}` + - `#${this.charID}#${sfx_delay}#${Number(objection_modifier)}#${Number( - evidence - )}#${Number(flip)}#${Number( - realization - )}#${text_color}#${extra_cccc}${extra_27}${extra_28}%`; - - this.sendServer(serverMessage); - if (mode === "replay") { - (( - document.getElementById("client_ooclog") - )).value += `wait#${(document.getElementById("client_replaytimer")).value - }#%\r\n`; - } - } /** * Sends add evidence command. @@ -365,7 +250,7 @@ class Client extends EventEmitter { * @param {string} evidence image filename */ sendPE(name: string, desc: string, img: string) { - this.sendServer( + this.sender.sendServer( `PE#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%` ); } @@ -378,7 +263,7 @@ class Client extends EventEmitter { * @param {string} evidence image filename */ sendEE(id: number, name: string, desc: string, img: string) { - this.sendServer( + this.sender.sendServer( `EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%` ); } @@ -388,16 +273,17 @@ class Client extends EventEmitter { * @param {number} evidence id */ sendDE(id: number) { - this.sendServer(`DE#${id}#%`); + this.sender.sendServer(`DE#${id}#%`); + } - + /** * Sends health point command. * @param {number} side the position * @param {number} hp the health point */ sendHP(side: number, hp: number) { - this.sendServer(`HP#${side}#${hp}#%`); + this.sender.sendServer(`HP#${side}#${hp}#%`); } /** @@ -406,9 +292,9 @@ class Client extends EventEmitter { */ sendZZ(msg: string) { if (extrafeatures.includes("modcall_reason")) { - this.sendServer(`ZZ#${msg}#%`); + this.sender.sendServer(`ZZ#${msg}#%`); } else { - this.sendServer("ZZ#%"); + this.sender.sendServer("ZZ#%"); } } @@ -417,7 +303,7 @@ class Client extends EventEmitter { * @param {string} testimony type */ sendRT(testimony: string) { - this.sendServer(`RT#${testimony}#%`); + this.sender.sendServer(`RT#${testimony}#%`); } /** @@ -425,7 +311,7 @@ class Client extends EventEmitter { * @param {string} track the track ID */ sendMusicChange(track: string) { - this.sendServer(`MC#${track}#${this.charID}#%`); + this.sender.sendServer(`MC#${track}#${this.charID}#%`); } /** @@ -433,8 +319,9 @@ class Client extends EventEmitter { * to the server. */ joinServer() { - this.sendServer(`HI#${hdid}#%`); - this.sendServer("ID#webAO#webAO#%"); + console.log(this.sender) + this.sender.sendServer(`HI#${hdid}#%`); + this.sender.sendServer("ID#webAO#webAO#%"); if (mode !== "replay") { this.checkUpdater = setInterval(() => this.sendCheck(), 5000); } @@ -518,7 +405,7 @@ class Client extends EventEmitter { */ sendCharacter(character: number) { if (character === -1 || this.chars[character].name) { - this.sendServer(`CC#${this.playerID}#${character}#web#%`); + this.sender.sendServer(`CC#${this.playerID}#${character}#web#%`); } } @@ -527,14 +414,14 @@ class Client extends EventEmitter { * @param {number?} song the song to be played */ sendMusic(song: string) { - this.sendServer(`MC#${song}#${this.charID}#%`); + this.sender.sendServer(`MC#${song}#${this.charID}#%`); } /** * Sends a keepalive packet. */ sendCheck() { - this.sendServer(`CH#${this.charID}#%`); + this.sender.sendServer(`CH#${this.charID}#%`); } /** -- cgit From 776fe2f4241a67be354908df546f300f413a7d42 Mon Sep 17 00:00:00 2001 From: Caleb Date: Thu, 8 Sep 2022 22:20:32 -0400 Subject: I'm so sorry --- webAO/client.ts | 130 +------------------------------------------------------- 1 file changed, 1 insertion(+), 129 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 4d01cfd..e92489c 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -211,109 +211,6 @@ class Client extends EventEmitter { setTimeout(() => this.onMessage(message_event), 1); } - /** - * Sends an out-of-character chat message. - * @param {string} message the message to send - */ - sendOOC(message: string) { - setCookie( - "OOC_name", - (document.getElementById("OOC_name")).value - ); - const oocName = `${escapeChat( - (document.getElementById("OOC_name")).value - )}`; - const oocMessage = `${escapeChat(message)}`; - - const commands = { - "/save_chatlog": this.saveChatlogHandle, - }; - const commandsMap = new Map(Object.entries(commands)); - - if (oocMessage && commandsMap.has(oocMessage.toLowerCase())) { - try { - commandsMap.get(oocMessage.toLowerCase())(); - } catch (e) { - // Command Not Recognized - } - } else { - this.sender.sendServer(`CT#${oocName}#${oocMessage}#%`); - } - } - - - - /** - * Sends add evidence command. - * @param {string} evidence name - * @param {string} evidence description - * @param {string} evidence image filename - */ - sendPE(name: string, desc: string, img: string) { - this.sender.sendServer( - `PE#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%` - ); - } - - /** - * Sends edit evidence command. - * @param {number} evidence id - * @param {string} evidence name - * @param {string} evidence description - * @param {string} evidence image filename - */ - sendEE(id: number, name: string, desc: string, img: string) { - this.sender.sendServer( - `EE#${id}#${escapeChat(name)}#${escapeChat(desc)}#${escapeChat(img)}#%` - ); - } - - /** - * Sends delete evidence command. - * @param {number} evidence id - */ - sendDE(id: number) { - this.sender.sendServer(`DE#${id}#%`); - - } - - /** - * Sends health point command. - * @param {number} side the position - * @param {number} hp the health point - */ - sendHP(side: number, hp: number) { - this.sender.sendServer(`HP#${side}#${hp}#%`); - } - - /** - * Sends call mod command. - * @param {string} message to mod - */ - sendZZ(msg: string) { - if (extrafeatures.includes("modcall_reason")) { - this.sender.sendServer(`ZZ#${msg}#%`); - } else { - this.sender.sendServer("ZZ#%"); - } - } - - /** - * Sends testimony command. - * @param {string} testimony type - */ - sendRT(testimony: string) { - this.sender.sendServer(`RT#${testimony}#%`); - } - - /** - * Requests to change the music to the specified track. - * @param {string} track the track ID - */ - sendMusicChange(track: string) { - this.sender.sendServer(`MC#${track}#${this.charID}#%`); - } - /** * Begins the handshake process by sending an identifier * to the server. @@ -323,7 +220,7 @@ class Client extends EventEmitter { this.sender.sendServer(`HI#${hdid}#%`); this.sender.sendServer("ID#webAO#webAO#%"); if (mode !== "replay") { - this.checkUpdater = setInterval(() => this.sendCheck(), 5000); + this.checkUpdater = setInterval(() => this.sender.sendCheck(), 5000); } } @@ -399,31 +296,6 @@ class Client extends EventEmitter { getCookie("callwords"); } - /** - * Requests to play as a specified character. - * @param {number} character the character ID - */ - sendCharacter(character: number) { - if (character === -1 || this.chars[character].name) { - this.sender.sendServer(`CC#${this.playerID}#${character}#web#%`); - } - } - - /** - * Requests to select a music track. - * @param {number?} song the song to be played - */ - sendMusic(song: string) { - this.sender.sendServer(`MC#${song}#${this.charID}#%`); - } - - /** - * Sends a keepalive packet. - */ - sendCheck() { - this.sender.sendServer(`CH#${this.charID}#%`); - } - /** * Triggered when a connection is established to the server. */ -- cgit From 1e3f34e03c9dd8fda7e2b24e4533e23fcb7e1de7 Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 9 Sep 2022 18:12:48 -0400 Subject: Moved more functions out of client --- webAO/client.ts | 113 +++----------------------------------------------------- 1 file changed, 6 insertions(+), 107 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index e92489c..9588812 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -3,14 +3,13 @@ * made by sD, refactored by oldmud0 and Qubrick * credits to aleks for original idea and source */ - +import {isLowMemory} from './client/isLowMemory' import FingerprintJS from "@fingerprintjs/fingerprintjs"; import vanilla_background_arr from "./constants/backgrounds.js"; import vanilla_evidence_arr from "./constants/evidence.js"; import {sender, ISender} from './client/sender/index' import iniParse from "./iniParse"; import getCookie from "./utils/getCookie"; -import setCookie from "./utils/setCookie"; import fileExists from "./utils/fileExists.js"; import queryParser from "./utils/queryParser"; import getResources from "./utils/getResources.js"; @@ -19,7 +18,7 @@ import masterViewport, { Viewport } from "./viewport"; import { EventEmitter } from "events"; import { area_click } from './dom/areaClick' import { onReplayGo } from './dom/onReplayGo' -import { escapeChat, safeTags, unescapeChat } from "./encoding"; +import { safeTags, unescapeChat } from "./encoding"; import { setChatbox } from "./dom/setChatbox"; import { request } from "./services/request.js"; import { @@ -77,20 +76,8 @@ export const setBanned = (val: boolean) => { } let hdid: string; -function isLowMemory() { - if ( - /webOS|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|PlayStation|Nintendo|Opera Mini/i.test( - navigator.userAgent - ) - ) { - oldLoading = true; - } -} - const fpPromise = FingerprintJS.load(); -const connect = (address: string) => { -} fpPromise .then((fp) => fp.get()) .then((result) => { @@ -100,15 +87,16 @@ fpPromise // Create the new client and connect it client = new Client(serverIP); client.connect() - isLowMemory(); client.loadResources(); }); export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)); -let lastICMessageTime = new Date(0); - +export let lastICMessageTime = new Date(0); +export const setLastICMessageTime = (val: Date) => { + lastICMessageTime = val +} class Client extends EventEmitter { serv: any; hp: number[]; @@ -335,7 +323,6 @@ class Client extends EventEmitter { packetHandler.has(packetHeader) ? packetHandler.get(packetHeader)(splitPacket) : console.warn(`Invalid packet header ${packetHeader}`); - } /** @@ -353,7 +340,6 @@ class Client extends EventEmitter { */ cleanup() { clearInterval(this.checkUpdater); - this.serv.close(); } @@ -653,93 +639,6 @@ class Client extends EventEmitter { } } -/** - * Resets the IC parameters for the player to enter a new chat message. - * This should only be called when the player's previous chat message - * was successfully sent/presented. - */ -export function resetICParams() { - (document.getElementById("client_inputbox")).value = ""; - document.getElementById("button_flash").className = "client_button"; - document.getElementById("button_shake").className = "client_button"; - - (document.getElementById("sendpreanim")).checked = false; - (document.getElementById("sendsfx")).checked = false; - - if (selectedShout) { - document.getElementById(`button_${selectedShout}`).className = - "client_button"; - selectedShout = 0; - } -} -/** - * Appends a message to the in-character chat log. - * @param {string} msg the string to be added - * @param {string} name the name of the sender - */ -export function appendICLog( - msg: string, - showname = "", - nameplate = "", - time = new Date() -) { - const entry = document.createElement("p"); - const shownameField = document.createElement("span"); - const nameplateField = document.createElement("span"); - const textField = document.createElement("span"); - nameplateField.className = "iclog_name iclog_nameplate"; - nameplateField.appendChild(document.createTextNode(nameplate)); - - shownameField.className = "iclog_name iclog_showname"; - if (showname === "" || !showname) { - shownameField.appendChild(document.createTextNode(nameplate)); - } else { - shownameField.appendChild(document.createTextNode(showname)); - } - - textField.className = "iclog_text"; - textField.appendChild(document.createTextNode(msg)); - - entry.appendChild(shownameField); - entry.appendChild(nameplateField); - entry.appendChild(textField); - - // Only put a timestamp if the minute has changed. - if (lastICMessageTime.getMinutes() !== time.getMinutes()) { - const timeStamp = document.createElement("span"); - timeStamp.className = "iclog_time"; - timeStamp.innerText = time.toLocaleTimeString(undefined, { - hour: "numeric", - minute: "2-digit", - }); - entry.appendChild(timeStamp); - } - - const clientLog = document.getElementById("client_log"); - clientLog.appendChild(entry); - - /* This is a little buggy - some troubleshooting might be desirable */ - if (clientLog.scrollTop > clientLog.scrollHeight - 800) { - clientLog.scrollTop = clientLog.scrollHeight; - } - - lastICMessageTime = new Date(); -} - -/** - * check if the message contains an entry on our callword list - * @param {string} message - */ -export function checkCallword(message: string, sfxAudio: HTMLAudioElement) { - client.callwords.forEach(testCallword); - function testCallword(item: string) { - if (item !== "" && message.toLowerCase().includes(item.toLowerCase())) { - sfxAudio.pause(); - sfxAudio.src = `${AO_HOST}sounds/general/sfx-gallery.opus`; - sfxAudio.play(); - } - } -} export default Client; \ No newline at end of file -- cgit From e50167a8077b0ada769cdf785971972c3ad865f7 Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 9 Sep 2022 18:30:07 -0400 Subject: Pulled out everything I wanted --- webAO/client.ts | 369 ++------------------------------------------------------ 1 file changed, 11 insertions(+), 358 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 9588812..8b2f691 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -3,35 +3,18 @@ * made by sD, refactored by oldmud0 and Qubrick * credits to aleks for original idea and source */ -import {isLowMemory} from './client/isLowMemory' +import { isLowMemory } from './client/isLowMemory' import FingerprintJS from "@fingerprintjs/fingerprintjs"; -import vanilla_background_arr from "./constants/backgrounds.js"; -import vanilla_evidence_arr from "./constants/evidence.js"; -import {sender, ISender} from './client/sender/index' -import iniParse from "./iniParse"; -import getCookie from "./utils/getCookie"; -import fileExists from "./utils/fileExists.js"; +import { sender, ISender } from './client/sender/index' import queryParser from "./utils/queryParser"; import getResources from "./utils/getResources.js"; -import downloadFile from "./services/downloadFile"; import masterViewport, { Viewport } from "./viewport"; import { EventEmitter } from "events"; -import { area_click } from './dom/areaClick' import { onReplayGo } from './dom/onReplayGo' -import { safeTags, unescapeChat } from "./encoding"; -import { setChatbox } from "./dom/setChatbox"; -import { request } from "./services/request.js"; -import { - changeShoutVolume, - changeSFXVolume, - changeTestimonyVolume, -} from "./dom/changeVolume.js"; -import { getFilenameFromPath } from "./utils/paths"; import { packetHandler } from './packets/packetHandler' -import { showname_click } from './dom/showNameClick' +import { loadResources } from './client/loadResources' import { AO_HOST } from './client/aoHost' - -const version = process.env.npm_package_version; +import { fetchBackgroundList, fetchEvidenceList } from './client/fetchLists' let { ip: serverIP, mode, theme } = queryParser(); let THEME: string = theme || "default"; @@ -82,12 +65,10 @@ fpPromise .then((fp) => fp.get()) .then((result) => { hdid = result.visitorId; - console.log("NEW CLIENT"); - // Create the new client and connect it client = new Client(serverIP); client.connect() - isLowMemory(); + client.isLowMemory(); client.loadResources(); }); @@ -122,6 +103,8 @@ class Client extends EventEmitter { _lastTimeICReceived: any; viewport: Viewport; connect: () => void; + loadResources: () => void + isLowMemory: () => void constructor(address: string) { super(); @@ -163,6 +146,8 @@ class Client extends EventEmitter { this.sender = sender this.viewport = masterViewport(this); this._lastTimeICReceived = new Date(0); + loadResources + isLowMemory } /** @@ -188,8 +173,6 @@ class Client extends EventEmitter { : 0; } - - /** * Hook for sending messages to the client * @param {string} message the message to send @@ -204,7 +187,6 @@ class Client extends EventEmitter { * to the server. */ joinServer() { - console.log(this.sender) this.sender.sendServer(`HI#${hdid}#%`); this.sender.sendServer("ID#webAO#webAO#%"); if (mode !== "replay") { @@ -212,78 +194,6 @@ class Client extends EventEmitter { } } - /** - * Load game resources and stored settings. - */ - loadResources() { - document.getElementById("client_version").innerText = `version ${version}`; - - // Load background array to select - const background_select = ( - document.getElementById("bg_select") - ); - background_select.add(new Option("Custom", "0")); - vanilla_background_arr.forEach((background) => { - background_select.add(new Option(background)); - }); - - // Load evidence array to select - const evidence_select = ( - document.getElementById("evi_select") - ); - evidence_select.add(new Option("Custom", "0")); - vanilla_evidence_arr.forEach((evidence) => { - evidence_select.add(new Option(evidence)); - }); - - // Read cookies and set the UI to its values - (document.getElementById("OOC_name")).value = - getCookie("OOC_name") || - `web${String(Math.round(Math.random() * 100 + 10))}`; - - // Read cookies and set the UI to its values - const cookietheme = getCookie("theme") || "default"; - - (( - document.querySelector(`#client_themeselect [value="${cookietheme}"]`) - )).selected = true; - this.viewport.reloadTheme(); - - const cookiechatbox = getCookie("chatbox") || "dynamic"; - - (( - document.querySelector(`#client_chatboxselect [value="${cookiechatbox}"]`) - )).selected = true; - setChatbox(cookiechatbox); - - (document.getElementById("client_mvolume")).value = - getCookie("musicVolume") || "1"; - this.viewport.changeMusicVolume(); - (document.getElementById("client_sfxaudio")).volume = - Number(getCookie("sfxVolume")) || 1; - changeSFXVolume(); - (document.getElementById("client_shoutaudio")).volume = - Number(getCookie("shoutVolume")) || 1; - changeShoutVolume(); - (( - document.getElementById("client_testimonyaudio") - )).volume = Number(getCookie("testimonyVolume")) || 1; - changeTestimonyVolume(); - (document.getElementById("client_bvolume")).value = - getCookie("blipVolume") || "1"; - this.viewport.changeBlipVolume(); - - (document.getElementById("ic_chat_name")).value = - getCookie("ic_chat_name"); - (document.getElementById("showname")).checked = Boolean( - getCookie("showname") - ); - showname_click(null); - - (document.getElementById("client_callwords")).value = - getCookie("callwords"); - } - /** * Triggered when a connection is established to the server. */ @@ -369,129 +279,6 @@ class Client extends EventEmitter { } } - saveChatlogHandle = async () => { - const clientLog = document.getElementById("client_log"); - const icMessageLogs = clientLog.getElementsByTagName("p"); - const messages = []; - - for (let i = 0; i < icMessageLogs.length; i++) { - const SHOWNAME_POSITION = 0; - const TEXT_POSITION = 2; - const showname = icMessageLogs[i].children[SHOWNAME_POSITION].innerHTML; - const text = icMessageLogs[i].children[TEXT_POSITION].innerHTML; - const message = `${showname}: ${text}`; - messages.push(message); - } - const d = new Date(); - let ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d); - let mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d); - let da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d); - - const filename = `chatlog-${da}-${mo}-${ye}`.toLowerCase(); - downloadFile(messages.join("\n"), filename); - - // Reset Chatbox to Empty - (document.getElementById("client_inputbox")).value = ""; - }; - - /** - * Handles the incoming character information, and downloads the sprite + ini for it - * @param {Array} chargs packet arguments - * @param {Number} charid character ID - */ - async handleCharacterInfo(chargs: string[], charid: number) { - const img = document.getElementById(`demo_${charid}`); - if (chargs[0]) { - let cini: any = {}; - const getCharIcon = async () => { - const extensions = [".png", ".webp"]; - img.alt = chargs[0]; - const charIconBaseUrl = `${AO_HOST}characters/${encodeURI( - chargs[0].toLowerCase() - )}/char_icon`; - for (let i = 0; i < extensions.length; i++) { - const fileUrl = charIconBaseUrl + extensions[i]; - const exists = await fileExists(fileUrl); - if (exists) { - img.alt = chargs[0]; - img.title = chargs[0]; - img.src = fileUrl; - return; - } - } - }; - getCharIcon(); - - // If the ini doesn't exist on the server this will throw an error - try { - const cinidata = await request( - `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char.ini` - ); - cini = iniParse(cinidata); - } catch (err) { - cini = {}; - img.classList.add("noini"); - console.warn(`character ${chargs[0]} is missing from webAO`); - // If it does, give the user a visual indication that the character is unusable - } - - const mute_select = ( - document.getElementById("mute_select") - ); - mute_select.add(new Option(safeTags(chargs[0]), String(charid))); - const pair_select = ( - document.getElementById("pair_select") - ); - pair_select.add(new Option(safeTags(chargs[0]), String(charid))); - - // sometimes ini files lack important settings - const default_options = { - name: chargs[0], - showname: chargs[0], - side: "def", - blips: "male", - chat: "", - category: "", - }; - cini.options = Object.assign(default_options, cini.options); - - // sometimes ini files lack important settings - const default_emotions = { - number: 0, - }; - cini.emotions = Object.assign(default_emotions, cini.emotions); - - this.chars[charid] = { - name: safeTags(chargs[0]), - showname: safeTags(cini.options.showname), - desc: safeTags(chargs[1]), - blips: safeTags(cini.options.blips).toLowerCase(), - gender: safeTags(cini.options.gender).toLowerCase(), - side: safeTags(cini.options.side).toLowerCase(), - chat: - cini.options.chat === "" - ? safeTags(cini.options.category).toLowerCase() - : safeTags(cini.options.chat).toLowerCase(), - evidence: chargs[3], - icon: img.src, - inifile: cini, - muted: false, - }; - - if ( - this.chars[charid].blips === "male" && - this.chars[charid].gender !== "male" && - this.chars[charid].gender !== "" - ) { - this.chars[charid].blips = this.chars[charid].gender; - } - - } else { - console.warn(`missing charid ${charid}`); - img.style.display = "none"; - } - } - resetMusicList() { this.musics = []; document.getElementById("client_musiclist").innerHTML = ""; @@ -501,144 +288,10 @@ class Client extends EventEmitter { this.areas = []; document.getElementById("areas").innerHTML = ""; - this.fetchBackgroundList(); - this.fetchEvidenceList(); - } - - async fetchBackgroundList() { - try { - const bgdata = await request(`${AO_HOST}backgrounds.json`); - const bg_array = JSON.parse(bgdata); - // the try catch will fail before here when there is no file - - const bg_select = document.getElementById("bg_select"); - bg_select.innerHTML = ""; - - bg_select.add(new Option("Custom", "0")); - bg_array.forEach((background: string) => { - bg_select.add(new Option(background)); - }); - } catch (err) { - console.warn("there was no backgrounds.json file"); - } - } - - async fetchCharacterList() { - try { - const chardata = await request(`${AO_HOST}characters.json`); - const char_array = JSON.parse(chardata); - // the try catch will fail before here when there is no file - - const char_select = ( - document.getElementById("client_ininame") - ); - char_select.innerHTML = ""; - - char_array.forEach((character: string) => { - char_select.add(new Option(character)); - }); - } catch (err) { - console.warn("there was no characters.json file"); - } - } - - async fetchEvidenceList() { - try { - const evidata = await request(`${AO_HOST}evidence.json`); - const evi_array = JSON.parse(evidata); - // the try catch will fail before here when there is no file - - const evi_select = ( - document.getElementById("evi_select") - ); - evi_select.innerHTML = ""; - - evi_array.forEach((evi: string) => { - evi_select.add(new Option(evi)); - }); - evi_select.add(new Option("Custom", "0")); - } catch (err) { - console.warn("there was no evidence.json file"); - } - } - - isAudio(trackname: string) { - const audioEndings = [".wav", ".mp3", ".ogg", ".opus"]; - return ( - audioEndings.filter((ending) => trackname.endsWith(ending)).length === 1 - ); - } - - addTrack(trackname: string) { - const newentry = document.createElement("OPTION"); - const songName = getFilenameFromPath(trackname); - newentry.text = unescapeChat(songName); - newentry.value = trackname; - (( - document.getElementById("client_musiclist") - )).options.add(newentry); - this.musics.push(trackname); + fetchBackgroundList(); + fetchEvidenceList(); } - createArea(id: number, name: string) { - const thisarea = { - name, - players: 0, - status: "IDLE", - cm: "", - locked: "FREE", - }; - - this.areas.push(thisarea); - - // Create area button - const newarea = document.createElement("SPAN"); - newarea.className = "area-button area-default"; - newarea.id = `area${id}`; - newarea.innerText = thisarea.name; - newarea.title = - `Players: ${thisarea.players}\n` + - `Status: ${thisarea.status}\n` + - `CM: ${thisarea.cm}\n` + - `Area lock: ${thisarea.locked}`; - newarea.onclick = function () { - area_click(newarea); - }; - - document.getElementById("areas").appendChild(newarea); - } - - /** - * Area list fuckery - */ - fix_last_area() { - if (this.areas.length > 0) { - const malplaced = this.areas.pop().name; - const areas = document.getElementById("areas"); - areas.removeChild(areas.lastChild); - this.addTrack(malplaced); - } - } - - /** - * Handles the kicked packet - * @param {string} type is it a kick or a ban - * @param {string} reason why - */ - handleBans(type: string, reason: string) { - document.getElementById("client_error").style.display = "flex"; - document.getElementById( - "client_errortext" - ).innerHTML = `${type}:
${reason.replace(/\n/g, "
")}`; - (( - document.getElementsByClassName("client_reconnect")[0] - )).style.display = "none"; - (( - document.getElementsByClassName("client_reconnect")[1] - )).style.display = "none"; - } } - - export default Client; \ No newline at end of file -- cgit From 108636666d474119892c4b3a2f3beadb767b006e Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 10 Sep 2022 11:09:49 -0400 Subject: Structured viewport a little differently --- webAO/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 8b2f691..b908b62 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -8,7 +8,8 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs"; import { sender, ISender } from './client/sender/index' import queryParser from "./utils/queryParser"; import getResources from "./utils/getResources.js"; -import masterViewport, { Viewport } from "./viewport"; +import masterViewport from "./viewport/viewport"; +import { Viewport } from './viewport/interfaces/Viewport'; import { EventEmitter } from "events"; import { onReplayGo } from './dom/onReplayGo' import { packetHandler } from './packets/packetHandler' -- cgit From 7c67d6e8009fd054466b26f33b63b7c9c74606f9 Mon Sep 17 00:00:00 2001 From: Caleb Date: Sun, 11 Sep 2022 15:41:30 -0400 Subject: Viewport can import client --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index b908b62..f3711e9 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -145,7 +145,7 @@ class Client extends EventEmitter { this.selectedEvidence = 0; this.checkUpdater = null; this.sender = sender - this.viewport = masterViewport(this); + this.viewport = masterViewport(); this._lastTimeICReceived = new Date(0); loadResources isLowMemory -- cgit