summary refs log tree commit diff
path: root/src/gateway/events
diff options
context:
space:
mode:
Diffstat (limited to 'src/gateway/events')
-rw-r--r--src/gateway/events/Connection.ts22
-rw-r--r--src/gateway/events/Message.ts15
2 files changed, 10 insertions, 27 deletions
diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts

index 1991ebbe..2150ec7b 100644 --- a/src/gateway/events/Connection.ts +++ b/src/gateway/events/Connection.ts
@@ -40,15 +40,9 @@ try { // TODO: specify rate limit in config // TODO: check msg max size -export async function Connection( - this: WS.Server, - socket: WebSocket, - request: IncomingMessage, -) { +export async function Connection(this: WS.Server, socket: WebSocket, request: IncomingMessage) { const forwardedFor = Config.get().security.forwardedFor; - const ipAddress = forwardedFor - ? (request.headers[forwardedFor] as string) - : request.socket.remoteAddress; + const ipAddress = forwardedFor ? (request.headers[forwardedFor] as string) : request.socket.remoteAddress; socket.ipAddress = ipAddress; @@ -85,21 +79,17 @@ export async function Connection( const { searchParams } = new URL(`http://localhost${request.url}`); // @ts-ignore socket.encoding = searchParams.get("encoding") || "json"; - if (!["json", "etf"].includes(socket.encoding)) - return socket.close(CLOSECODES.Decode_error); + if (!["json", "etf"].includes(socket.encoding)) return socket.close(CLOSECODES.Decode_error); - if (socket.encoding === "etf" && !erlpack) - throw new Error("Erlpack is not installed: 'npm i erlpack'"); + if (socket.encoding === "etf" && !erlpack) throw new Error("Erlpack is not installed: 'npm i erlpack'"); socket.version = Number(searchParams.get("version")) || 8; - if (socket.version != 8) - return socket.close(CLOSECODES.Invalid_API_version); + if (socket.version != 8) return socket.close(CLOSECODES.Invalid_API_version); // @ts-ignore socket.compress = searchParams.get("compress") || ""; if (socket.compress) { - if (socket.compress !== "zlib-stream") - return socket.close(CLOSECODES.Decode_error); + if (socket.compress !== "zlib-stream") return socket.close(CLOSECODES.Decode_error); socket.deflate = new Deflate(); socket.inflate = new Inflate(); } diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts
index 52d9edd8..8415d04e 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts
@@ -60,22 +60,15 @@ export async function Message(this: WebSocket, buffer: WS.Data) { } } else return this.close(CLOSECODES.Decode_error); - if (process.env.WS_VERBOSE) - console.log(`[Websocket] Incomming message: ${JSON.stringify(data)}`); + if (process.env.WS_VERBOSE) console.log(`[Websocket] Incomming message: ${JSON.stringify(data)}`); if (process.env.WS_DUMP) { const id = this.session_id || "unknown"; await fs.mkdir(path.join("dump", id), { recursive: true }); - await fs.writeFile( - path.join("dump", id, `${Date.now()}.in.json`), - JSON.stringify(data, null, 2), - ); + await fs.writeFile(path.join("dump", id, `${Date.now()}.in.json`), JSON.stringify(data, null, 2)); - if (!this.session_id) - console.log( - "[Gateway] Unknown session id, dumping to unknown folder", - ); + if (!this.session_id) console.log("[Gateway] Unknown session id, dumping to unknown folder"); } check.call(this, PayloadSchema, data); @@ -102,7 +95,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) { const ret = await OPCodeHandler.call(this, data); Sentry.setUser({ id: this.user_id }); return ret; - }, + } ); } catch (error) { Sentry.captureException(error, {