LazyRequest on mobile + socket not closed fixes

This commit is contained in:
Madeline
2022-08-22 15:33:06 +10:00
parent d993d9c155
commit ee98101e4c
8 changed files with 204 additions and 26 deletions
+5 -6
View File
@@ -8,6 +8,8 @@ import OPCodeHandlers from "../opcodes";
import { Tuple } from "lambert-server";
import { check } from "../opcodes/instanceOf";
import WS from "ws";
import BigIntJson from "json-bigint";
const bigIntJson = BigIntJson({ storeAsString: true });
const PayloadSchema = {
op: Number,
@@ -30,16 +32,13 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
buffer = buffer.toString() as any;
}
}
data = JSON.parse(buffer as string);
data = bigIntJson.parse(buffer as string);
}
else if (typeof buffer == "string") {
data = JSON.parse(buffer as string);
data = bigIntJson.parse(buffer as string)
}
else return;
// TODO: find a way to properly convert a funny number to string
if (data?.op == 14 && typeof data.d.guild_id == "number") return;
check.call(this, PayloadSchema, data);
// @ts-ignore
@@ -54,7 +53,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
try {
return await OPCodeHandler.call(this, data);
} catch (error) {
console.error(error);
console.error(`Error: Op ${data.op}`, error);
// if (!this.CLOSED && this.CLOSING)
return this.close(CLOSECODES.Unknown_error);
}
+1 -1
View File
@@ -241,7 +241,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
break;
}
Send(this, {
await Send(this, {
op: OPCODES.Dispatch,
t: event,
d: data,
+2 -1
View File
@@ -137,12 +137,13 @@ export async function onIdentify(this: WebSocket, data: Payload) {
guilds = guilds.map((guild) => {
if (user.bot) {
setTimeout(() => {
Send(this, {
var promise = Send(this, {
op: OPCODES.Dispatch,
t: EVENTEnum.GuildCreate,
s: this.sequence++,
d: guild,
});
if (promise) promise.catch(console.error);
}, 500);
return { id: guild.id, unavailable: true };
}
+6 -3
View File
@@ -39,13 +39,16 @@ async function getMembers(guild_id: string, range: [number, number]) {
}
catch (e) {
console.error(`LazyRequest`, e);
}
if (!members) {
return {
items: [],
groups: [],
range: [],
members: [],
}
}
};
}
const groups = [] as any[];
const items = [];
@@ -157,7 +160,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
.flat()
.unique();
return Send(this, {
return await Send(this, {
op: OPCODES.Dispatch,
s: this.sequence++,
t: "GUILD_MEMBER_LIST_UPDATE",