aboutsummaryrefslogtreecommitdiff
path: root/webAO
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2023-07-17 03:07:57 +0200
committerstonedDiscord <Tukz@gmx.de>2023-07-17 03:07:57 +0200
commitf6bff005201e8c038d5ccf350df5467e724561b6 (patch)
tree19cbbace1903513dd7940bd6e616d72c66434d7a /webAO
parent59180c50063a0f32eec572b5b1e8adb82f59e013 (diff)
parent15c2e53af870504e6669b22531bddf1115a1c056 (diff)
Merge branch 'master' of https://github.com/AttorneyOnline/webAO
Diffstat (limited to 'webAO')
-rw-r--r--webAO/client.ts67
-rw-r--r--webAO/encoding.ts2
2 files changed, 59 insertions, 10 deletions
diff --git a/webAO/client.ts b/webAO/client.ts
index 0cc89cf..e5c5e2b 100644
--- a/webAO/client.ts
+++ b/webAO/client.ts
@@ -38,6 +38,7 @@ export const UPDATE_INTERVAL = 60;
*/
export let oldLoading = false;
export const setOldLoading = (val: boolean) => {
+ console.warn("old loading set to "+val)
oldLoading = val
}
@@ -105,6 +106,8 @@ class Client extends EventEmitter {
_lastTimeICReceived: any;
manifest: string[];
viewport: Viewport;
+ partial_packet: boolean;
+ temp_packet: String;
connect: () => void;
loadResources: () => void
isLowMemory: () => void
@@ -150,6 +153,8 @@ class Client extends EventEmitter {
this.sender = sender
this.viewport = masterViewport();
this._lastTimeICReceived = new Date(0);
+ this.partial_packet = false;
+ this.temp_packet = "";
loadResources
isLowMemory
}
@@ -229,19 +234,63 @@ class Client extends EventEmitter {
const msg = e.data;
console.debug(`S: ${msg}`);
- const packets = Array(msg.split("%"));
+ this.handle_server_packet(msg);
+
+ }
- packets.forEach(function(data: String){
- const splitPacket = String(data).split('#')
- const packetHeader = splitPacket[0];
+ /**
+ * Decode the packet
+ * @param {MessageEvent} e
+ */
+ handle_server_packet(p_data: string)
+{
+ let in_data = p_data;
+
+ if (!p_data.endsWith("%")) {
+ this.partial_packet = true;
+ this.temp_packet = this.temp_packet + in_data
+ console.log("Partial packet")
+ return;
+ }
- packetHandler.has(packetHeader)
- ? packetHandler.get(packetHeader)(splitPacket)
- : console.warn(`Invalid packet header ${packetHeader}`);
- });
-
+ else {
+ if (this.partial_packet) {
+ in_data = this.temp_packet + in_data
+ this.temp_packet = "";
+ this.partial_packet = false;
+ }
}
+ const packet_list = in_data.split("%");
+
+ for (var packet of packet_list) {
+ let f_contents;
+ // Packet should *always* end with #
+ if (packet.endsWith("#")) {
+ f_contents = packet.slice(0, -1).split("#");
+ }
+ // But, if it somehow doesn't, we should still be able to handle it
+ else {
+ f_contents = packet.split("#");
+ }
+ // Empty packets are suspicious!
+ if (f_contents.length == 0) {
+ console.warn("WARNING: Empty packet received from server, skipping...");
+ continue;
+ }
+ // Take the first arg as the command
+ const command = f_contents[0];
+ if(command!=="")
+ {
+ // The rest is contents of the packet
+ packetHandler.has(command)
+ ? packetHandler.get(command)(f_contents)
+ : console.warn(`Invalid packet header ${command}`);
+ };
+ }
+ }
+
+
/**
* Triggered when an network error occurs.
* @param {ErrorEvent} e
diff --git a/webAO/encoding.ts b/webAO/encoding.ts
index 3477d7b..697e1d0 100644
--- a/webAO/encoding.ts
+++ b/webAO/encoding.ts
@@ -52,5 +52,5 @@ export function decodeChat(estring: string): string {
*/
export function prepChat(msg: string): string {
// TODO: make this less awful
- return unescapeChat(decodeChat(msg));
+ return safeTags(unescapeChat(decodeChat(msg)));
}