From bd29a273cb56120db6f7d05ce45ac0933ee298d6 Mon Sep 17 00:00:00 2001 From: sD Date: Mon, 20 Jul 2020 10:28:21 +0200 Subject: only connect to network when it's not a replay --- webAO/client.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index d9acaad..76300ec 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -92,12 +92,14 @@ let lastICMessageTime = new Date(0); class Client extends EventEmitter { constructor(address) { super(); - 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")); + 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.on("open", this.onOpen.bind(this)); this.on("close", this.onClose.bind(this)); -- cgit From 9f3806fed2b99f67a5b38941cd902634f6676d23 Mon Sep 17 00:00:00 2001 From: sD Date: Mon, 20 Jul 2020 16:08:46 +0200 Subject: send stuff back to the client --- webAO/client.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 76300ec..1532633 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -92,6 +92,7 @@ let lastICMessageTime = new Date(0); class Client extends EventEmitter { constructor(address) { super(); + console.log("mode: " + mode); if (mode !== "replay") { this.serv = new WebSocket("ws://" + address); // Assign the websocket events @@ -99,6 +100,8 @@ class Client extends EventEmitter { 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)); @@ -197,6 +200,7 @@ class Client extends EventEmitter { this.on("decryptor", this.handleDecryptor.bind(this)); this.on("PV", this.handlePV.bind(this)); this.on("CHECK", () => { }); + this.on("CH", () => { }); this._lastTimeICReceived = new Date(0); } @@ -227,8 +231,22 @@ class Client extends EventEmitter { * @param {string} message the message to send */ sendServer(message) { - // console.log(message); - this.serv.send(message); + console.debug("C: " + message); + if (mode === "replay") { + this.sendSelf(message); + } else { + this.serv.send(message); + } + } + + /** + * Hook for sending messages to the client + * @param {string} message the message to send + */ + sendSelf(message) { + document.getElementById("client_ooclog").innerHTML += message + "\r\n"; + const message_event = new MessageEvent('websocket', { data: message }); + this.onMessage(message_event); } /** @@ -281,8 +299,6 @@ class Client extends EventEmitter { `#${escapeChat(encodeChat(message))}#${side}#${sfx_name}#${emote_modifier}` + `#${this.charID}#${sfx_delay}#${objection_modifier}#${evidence}#${flip}#${realization}#${text_color}#${extra_cccc}${extra_27}%`; - console.log(serverMessage); - this.sendServer(serverMessage); } @@ -484,7 +500,7 @@ class Client extends EventEmitter { */ onMessage(e) { const msg = e.data; - console.debug(msg); + console.debug("S: " + msg); const lines = msg.split("%"); const args = lines[0].split("#"); @@ -1082,6 +1098,8 @@ class Client extends EventEmitter { this.serverSoftware = args[2].split("&")[0]; if (this.serverSoftware === "serverD") this.serverVersion = args[2].split("&")[1]; + else if (this.serverSoftware === "webAO") + this.sendSelf("PN#0#0#%"); else this.serverVersion = args[3]; @@ -1284,6 +1302,14 @@ class Client extends EventEmitter { pickEmotion(1); } } + + /** + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ + handleaskChaa(_args) { + this.onMessage("SC#Phoenix#PhoenixSOJ#Young Mia#Grossberg#%"); + } } class Viewport { -- cgit From c78c998a91d57fd5c80c4ac23753ffccd931c9cd Mon Sep 17 00:00:00 2001 From: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:24:14 +0200 Subject: add 6 self-server commands --- webAO/client.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 7 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index ac1c28b..7f9b394 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -9,6 +9,7 @@ import Fingerprint2 from 'fingerprintjs2'; import { escapeChat, encodeChat, prepChat, safe_tags } from './encoding.js'; // Load some defaults for the background and evidence dropdowns +import character_arr from "./characters.js"; import background_arr from "./backgrounds.js"; import evidence_arr from "./evidence.js"; import sfx_arr from "./sounds.js"; @@ -191,10 +192,16 @@ class Client extends EventEmitter { this.on("HP", this.handleHP.bind(this)); this.on("RT", this.handleRT.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("decryptor", this.handleDecryptor.bind(this)); this.on("PV", this.handlePV.bind(this)); @@ -245,7 +252,7 @@ class Client extends EventEmitter { sendSelf(message) { document.getElementById("client_ooclog").innerHTML += message + "\r\n"; const message_event = new MessageEvent('websocket', { data: message }); - this.onMessage(message_event); + setTimeout(() => this.onMessage(message_event), 1); } /** @@ -1123,6 +1130,15 @@ class Client extends EventEmitter { viewport.sfxaudio.volume = oldvolume; } + /** + * Handle the player + * @param {Array} args packet arguments + */ + handleHI(args) { + this.sendSelf("ID#1#webAO#" + version + "#%"); + this.sendSelf("FL#fastloading#yellowtext#ccc_ic_support#flipping#looping_sfx#%"); + } + /** * Identifies the server and issues a playerID * @param {Array} args packet arguments @@ -1132,9 +1148,10 @@ class Client extends EventEmitter { this.serverSoftware = args[2].split("&")[0]; if (this.serverSoftware === "serverD") this.serverVersion = args[2].split("&")[1]; - else if (this.serverSoftware === "webAO") - this.sendSelf("PN#0#0#%"); - else + else if (this.serverSoftware === "webAO") { + oldLoading = false; + this.sendSelf("PN#0#1#%"); + } else this.serverVersion = args[3]; if (this.serverSoftware === "serverD" && this.serverVersion === "1377.152") @@ -1149,6 +1166,22 @@ class Client extends EventEmitter { this.sendServer("askchaa#%"); } + /** + * What? you want a character?? + * @param {Array} args packet arguments + */ + handleCC(args) { + this.sendSelf("PV#1#CID#" + args[2] + "#%"); + } + + /** + * What? you want a character list from me?? + * @param {Array} args packet arguments + */ + handleaskchaa(_args) { + this.sendSelf("SI#" + character_arr.length + "#0#0#%"); + } + /** * Handle the change of players in an area. * @param {Array} args packet arguments @@ -1341,8 +1374,26 @@ class Client extends EventEmitter { * we are asking ourselves what characters there are * @param {Array} args packet arguments */ - handleaskChaa(_args) { - this.onMessage("SC#Phoenix#PhoenixSOJ#Young Mia#Grossberg#%"); + handleRC(_args) { + this.sendSelf("SC#" + character_arr.join("#") + "#%"); + } + + /** + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ + handleRM(_args) { + this.sendSelf("SM#stop.mp3#%"); + } + + /** + * we are asking ourselves what characters there are + * @param {Array} args packet arguments + */ + handleRD(_args) { + this.sendSelf("DONE#%"); + document.getElementById("client_ooclog").innerHTML = ""; + } } @@ -2797,7 +2848,11 @@ export function changeBackgroundOOC() { } else { filename = selectedBG.value; } - client.sendOOC("/" + changeBGCommand.replace("$1", filename)); + + if (mode==="join") + client.sendOOC("/" + changeBGCommand.replace("$1", filename)); + else if (mode==="replay") + client.sendSelf("BN#" + filename + "#%"); } window.changeBackgroundOOC = changeBackgroundOOC; -- cgit From 2c3e9fa5c310e25d67b0227e849e4b98572296e5 Mon Sep 17 00:00:00 2001 From: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:43:11 +0200 Subject: stop the CH spam and have a music list --- webAO/client.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 7f9b394..64bdd38 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -10,6 +10,7 @@ import { escapeChat, encodeChat, prepChat, safe_tags } from './encoding.js'; // Load some defaults for the background and evidence dropdowns import character_arr from "./characters.js"; +import music_arr from "./music.js"; import background_arr from "./backgrounds.js"; import evidence_arr from "./evidence.js"; import sfx_arr from "./sounds.js"; @@ -402,7 +403,8 @@ class Client extends EventEmitter { this.sendServer(`HI#${hdid}#%`); this.sendServer(`ID#webAO#webAO#%`); - this.checkUpdater = setInterval(() => this.sendCheck(), 5000); + if (mode !== "replay") + this.checkUpdater = setInterval(() => this.sendCheck(), 5000); } /** @@ -1383,7 +1385,7 @@ class Client extends EventEmitter { * @param {Array} args packet arguments */ handleRM(_args) { - this.sendSelf("SM#stop.mp3#%"); + this.sendSelf("SM#" + music_arr.join("#") + "#%"); } /** @@ -1391,9 +1393,14 @@ class Client extends EventEmitter { * @param {Array} args packet arguments */ handleRD(_args) { + this.sendSelf("BN#gs4#%"); this.sendSelf("DONE#%"); - document.getElementById("client_ooclog").innerHTML = ""; - + const ooclog = document.getElementById("client_ooclog"); + ooclog.innerHTML = ""; + ooclog.readOnly = false; + + document.getElementById("client_oocinput").style.display = "none"; + document.getElementById("client_replaycontrols").style.display = "inline-block"; } } -- cgit From dfab9f6c78a62428fccd3d5becec404858211e2f Mon Sep 17 00:00:00 2001 From: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:49:16 +0200 Subject: user can't edit it with innerHTML --- webAO/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 64bdd38..9817390 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -251,7 +251,7 @@ class Client extends EventEmitter { * @param {string} message the message to send */ sendSelf(message) { - document.getElementById("client_ooclog").innerHTML += message + "\r\n"; + document.getElementById("client_ooclog").value += message + "\r\n"; const message_event = new MessageEvent('websocket', { data: message }); setTimeout(() => this.onMessage(message_event), 1); } @@ -1396,7 +1396,7 @@ class Client extends EventEmitter { this.sendSelf("BN#gs4#%"); this.sendSelf("DONE#%"); const ooclog = document.getElementById("client_ooclog"); - ooclog.innerHTML = ""; + ooclog.value = ""; ooclog.readOnly = false; document.getElementById("client_oocinput").style.display = "none"; -- cgit From 770681945b4a3ceccd89634b974ac0a4e6bfb9d3 Mon Sep 17 00:00:00 2001 From: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:08:48 +0200 Subject: make the button work and play automatically --- webAO/client.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index 9817390..de22a0e 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -250,12 +250,21 @@ class Client extends EventEmitter { * Hook for sending messages to the client * @param {string} message the message to send */ - sendSelf(message) { - document.getElementById("client_ooclog").value += message + "\r\n"; + handleSelf(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 + */ + sendSelf(message) { + 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 @@ -542,6 +551,22 @@ class Client extends EventEmitter { document.getElementById("client_chartable").innerHTML = ""; } + /** + * Parse the lines in the OOC and play them + * @param {*} args packet arguments + */ + handleReplay() { + const ooclog = document.getElementById("client_ooclog"); + const rtime = document.getElementById("client_replaytimer").value; + + const clines = ooclog.value.split(/\r?\n/); + if (clines[0]) { + this.handleSelf(clines[0]); + ooclog.value = clines.slice(1).join("\r\n"); + setTimeout(() => onReplayGo(""), rtime); + } + } + /** * Handles an in-character chat message. * @param {*} args packet arguments @@ -2159,6 +2184,15 @@ export function onOOCEnter(event) { } window.onOOCEnter = onOOCEnter; +/** + * Triggered when the user click replay GOOOOO + * @param {KeyboardEvent} event + */ +export function onReplayGo(_event) { + client.handleReplay(); +} +window.onReplayGo = onReplayGo; + /** * Triggered when the Return key is pressed on the in-character chat input box. * @param {KeyboardEvent} event -- cgit