diff --git a/bundle/package-lock.json b/bundle/package-lock.json index 4046e7b6..644a3a3c 100644 Binary files a/bundle/package-lock.json and b/bundle/package-lock.json differ diff --git a/bundle/package.json b/bundle/package.json index b8678f81..484c0f05 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -37,12 +37,14 @@ "@types/i18next-node-fs-backend": "^2.1.0", "@types/jest": "^27.0.1", "@types/jest-expect-message": "^1.0.3", + "@types/json-bigint": "^1.0.1", "@types/jsonwebtoken": "^8.5.0", "@types/morgan": "^1.9.3", "@types/multer": "^1.4.7", "@types/node": "^14.18.24", "@types/node-fetch": "^2.5.12", "@types/node-os-utils": "^1.2.0", + "@types/sharp": "^0.30.4", "@types/supertest": "^2.0.11", "@types/ws": "^7.4.0", "@zerollup/ts-transform-paths": "^1.7.18", @@ -54,8 +56,7 @@ "ts-patch": "^1.4.4", "tsconfig-paths": "^3.12.0", "typescript": "^4.2.3", - "typescript-json-schema": "0.50.1", - "@types/sharp": "^0.30.4" + "typescript-json-schema": "0.50.1" }, "dependencies": { "@aws-sdk/client-s3": "^3.36.1", @@ -81,6 +82,7 @@ "exif-be-gone": "^1.2.0", "express": "^4.17.1", "express-async-errors": "^3.1.1", + "fast-zlib": "^2.0.1", "file-type": "^16.5.4", "form-data": "^4.0.0", "fs-extra": "^10.0.0", @@ -89,6 +91,7 @@ "i18next-node-fs-backend": "^2.1.3", "image-size": "^1.0.0", "jest": "^27.0.6", + "json-bigint": "^1.0.0", "jsonwebtoken": "^8.5.1", "lambert-db": "^1.2.3", "lambert-server": "^1.2.11", @@ -97,6 +100,7 @@ "multer": "^1.4.2", "nan": "^2.15.0", "nanocolors": "^0.2.12", + "node-2fa": "^2.0.3", "node-fetch": "^2.6.2", "node-os-utils": "^1.3.5", "patch-package": "^6.4.7", @@ -104,6 +108,7 @@ "picocolors": "^1.0.0", "proxy-agent": "^5.0.0", "reflect-metadata": "^0.1.13", + "sharp": "^0.30.7", "sqlite3": "^4.2.0", "supertest": "^6.1.6", "tslib": "^2.3.1", @@ -111,8 +116,6 @@ "typescript": "^4.1.2", "typescript-cached-transpile": "^0.0.6", "typescript-json-schema": "^0.50.1", - "ws": "^7.4.2", - "sharp": "^0.30.7", - "fast-zlib": "^2.0.1" + "ws": "^7.4.2" } -} \ No newline at end of file +} diff --git a/gateway/package-lock.json b/gateway/package-lock.json index 38bdab90..e39901de 100644 Binary files a/gateway/package-lock.json and b/gateway/package-lock.json differ diff --git a/gateway/package.json b/gateway/package.json index 205cd9c1..ad500897 100644 --- a/gateway/package.json +++ b/gateway/package.json @@ -16,6 +16,7 @@ "license": "AGPL-3.0-only", "devDependencies": { "@types/amqplib": "^0.8.1", + "@types/json-bigint": "^1.0.1", "@types/jsonwebtoken": "^8.5.0", "@types/node": "^14.18.24", "@types/node-fetch": "^2.5.12", @@ -30,6 +31,7 @@ "amqplib": "^0.8.0", "dotenv": "^8.2.0", "fast-zlib": "^2.0.1", + "json-bigint": "^1.0.0", "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.11", "missing-native-js-functions": "^1.2.18", diff --git a/gateway/src/events/Message.ts b/gateway/src/events/Message.ts index e9271da4..1a177e0c 100644 --- a/gateway/src/events/Message.ts +++ b/gateway/src/events/Message.ts @@ -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); } diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts index 060de65b..8a90ce0c 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts @@ -241,7 +241,7 @@ async function consume(this: WebSocket, opts: EventOpts) { break; } - Send(this, { + await Send(this, { op: OPCODES.Dispatch, t: event, d: data, diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index 041512c5..57c45d1f 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -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 }; } diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts index 0db35286..54b06eb2 100644 --- a/gateway/src/opcodes/LazyRequest.ts +++ b/gateway/src/opcodes/LazyRequest.ts @@ -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",