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 25 additions and 17 deletions

BIN
bundle/package-lock.json generated

Binary file not shown.

View File

@ -37,12 +37,14 @@
"@types/i18next-node-fs-backend": "^2.1.0", "@types/i18next-node-fs-backend": "^2.1.0",
"@types/jest": "^27.0.1", "@types/jest": "^27.0.1",
"@types/jest-expect-message": "^1.0.3", "@types/jest-expect-message": "^1.0.3",
"@types/json-bigint": "^1.0.1",
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/morgan": "^1.9.3", "@types/morgan": "^1.9.3",
"@types/multer": "^1.4.7", "@types/multer": "^1.4.7",
"@types/node": "^14.18.24", "@types/node": "^14.18.24",
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
"@types/node-os-utils": "^1.2.0", "@types/node-os-utils": "^1.2.0",
"@types/sharp": "^0.30.4",
"@types/supertest": "^2.0.11", "@types/supertest": "^2.0.11",
"@types/ws": "^7.4.0", "@types/ws": "^7.4.0",
"@zerollup/ts-transform-paths": "^1.7.18", "@zerollup/ts-transform-paths": "^1.7.18",
@ -54,8 +56,7 @@
"ts-patch": "^1.4.4", "ts-patch": "^1.4.4",
"tsconfig-paths": "^3.12.0", "tsconfig-paths": "^3.12.0",
"typescript": "^4.2.3", "typescript": "^4.2.3",
"typescript-json-schema": "0.50.1", "typescript-json-schema": "0.50.1"
"@types/sharp": "^0.30.4"
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.36.1", "@aws-sdk/client-s3": "^3.36.1",
@ -81,6 +82,7 @@
"exif-be-gone": "^1.2.0", "exif-be-gone": "^1.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-async-errors": "^3.1.1", "express-async-errors": "^3.1.1",
"fast-zlib": "^2.0.1",
"file-type": "^16.5.4", "file-type": "^16.5.4",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"fs-extra": "^10.0.0", "fs-extra": "^10.0.0",
@ -89,6 +91,7 @@
"i18next-node-fs-backend": "^2.1.3", "i18next-node-fs-backend": "^2.1.3",
"image-size": "^1.0.0", "image-size": "^1.0.0",
"jest": "^27.0.6", "jest": "^27.0.6",
"json-bigint": "^1.0.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lambert-db": "^1.2.3", "lambert-db": "^1.2.3",
"lambert-server": "^1.2.11", "lambert-server": "^1.2.11",
@ -97,6 +100,7 @@
"multer": "^1.4.2", "multer": "^1.4.2",
"nan": "^2.15.0", "nan": "^2.15.0",
"nanocolors": "^0.2.12", "nanocolors": "^0.2.12",
"node-2fa": "^2.0.3",
"node-fetch": "^2.6.2", "node-fetch": "^2.6.2",
"node-os-utils": "^1.3.5", "node-os-utils": "^1.3.5",
"patch-package": "^6.4.7", "patch-package": "^6.4.7",
@ -104,6 +108,7 @@
"picocolors": "^1.0.0", "picocolors": "^1.0.0",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"sharp": "^0.30.7",
"sqlite3": "^4.2.0", "sqlite3": "^4.2.0",
"supertest": "^6.1.6", "supertest": "^6.1.6",
"tslib": "^2.3.1", "tslib": "^2.3.1",
@ -111,8 +116,6 @@
"typescript": "^4.1.2", "typescript": "^4.1.2",
"typescript-cached-transpile": "^0.0.6", "typescript-cached-transpile": "^0.0.6",
"typescript-json-schema": "^0.50.1", "typescript-json-schema": "^0.50.1",
"ws": "^7.4.2", "ws": "^7.4.2"
"sharp": "^0.30.7",
"fast-zlib": "^2.0.1"
} }
} }

Binary file not shown.

View File

@ -16,6 +16,7 @@
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"devDependencies": { "devDependencies": {
"@types/amqplib": "^0.8.1", "@types/amqplib": "^0.8.1",
"@types/json-bigint": "^1.0.1",
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/node": "^14.18.24", "@types/node": "^14.18.24",
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
@ -30,6 +31,7 @@
"amqplib": "^0.8.0", "amqplib": "^0.8.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"fast-zlib": "^2.0.1", "fast-zlib": "^2.0.1",
"json-bigint": "^1.0.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.11", "lambert-server": "^1.2.11",
"missing-native-js-functions": "^1.2.18", "missing-native-js-functions": "^1.2.18",

View File

@ -8,6 +8,8 @@ import OPCodeHandlers from "../opcodes";
import { Tuple } from "lambert-server"; import { Tuple } from "lambert-server";
import { check } from "../opcodes/instanceOf"; import { check } from "../opcodes/instanceOf";
import WS from "ws"; import WS from "ws";
import BigIntJson from "json-bigint";
const bigIntJson = BigIntJson({ storeAsString: true });
const PayloadSchema = { const PayloadSchema = {
op: Number, op: Number,
@ -30,16 +32,13 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
buffer = buffer.toString() as any; buffer = buffer.toString() as any;
} }
} }
data = JSON.parse(buffer as string); data = bigIntJson.parse(buffer as string);
} }
else if (typeof buffer == "string") { else if (typeof buffer == "string") {
data = JSON.parse(buffer as string); data = bigIntJson.parse(buffer as string)
} }
else return; 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); check.call(this, PayloadSchema, data);
// @ts-ignore // @ts-ignore
@ -54,7 +53,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
try { try {
return await OPCodeHandler.call(this, data); return await OPCodeHandler.call(this, data);
} catch (error) { } catch (error) {
console.error(error); console.error(`Error: Op ${data.op}`, error);
// if (!this.CLOSED && this.CLOSING) // if (!this.CLOSED && this.CLOSING)
return this.close(CLOSECODES.Unknown_error); return this.close(CLOSECODES.Unknown_error);
} }

View File

@ -241,7 +241,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
break; break;
} }
Send(this, { await Send(this, {
op: OPCODES.Dispatch, op: OPCODES.Dispatch,
t: event, t: event,
d: data, d: data,

View File

@ -137,12 +137,13 @@ export async function onIdentify(this: WebSocket, data: Payload) {
guilds = guilds.map((guild) => { guilds = guilds.map((guild) => {
if (user.bot) { if (user.bot) {
setTimeout(() => { setTimeout(() => {
Send(this, { var promise = Send(this, {
op: OPCODES.Dispatch, op: OPCODES.Dispatch,
t: EVENTEnum.GuildCreate, t: EVENTEnum.GuildCreate,
s: this.sequence++, s: this.sequence++,
d: guild, d: guild,
}); });
if (promise) promise.catch(console.error);
}, 500); }, 500);
return { id: guild.id, unavailable: true }; return { id: guild.id, unavailable: true };
} }

View File

@ -39,12 +39,15 @@ async function getMembers(guild_id: string, range: [number, number]) {
} }
catch (e) { catch (e) {
console.error(`LazyRequest`, e); console.error(`LazyRequest`, e);
}
if (!members) {
return { return {
items: [], items: [],
groups: [], groups: [],
range: [], range: [],
members: [], members: [],
} };
} }
const groups = [] as any[]; const groups = [] as any[];
@ -157,7 +160,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
.flat() .flat()
.unique(); .unique();
return Send(this, { return await Send(this, {
op: OPCODES.Dispatch, op: OPCODES.Dispatch,
s: this.sequence++, s: this.sequence++,
t: "GUILD_MEMBER_LIST_UPDATE", t: "GUILD_MEMBER_LIST_UPDATE",