summary refs log tree commit diff
path: root/src/events
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 14:15:13 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 14:15:13 +0200
commit7279df5efbb785e8353c65c793fbce41c4f86859 (patch)
tree59552a56859e3d0d66e36ada68151a7b7d525c0d /src/events
parentadd .lean to mongodb queries (diff)
downloadserver-7279df5efbb785e8353c65c793fbce41c4f86859.tar.xz
:bug: fix hearbeat gateway
Diffstat (limited to 'src/events')
-rw-r--r--src/events/Message.ts15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/events/Message.ts b/src/events/Message.ts

index 6aa62a22..2d461e1d 100644 --- a/src/events/Message.ts +++ b/src/events/Message.ts
@@ -3,6 +3,7 @@ import erlpack from "erlpack"; import OPCodeHandlers from "../opcodes"; import { Payload, CLOSECODES } from "../util/Constants"; import { instanceOf, Tuple } from "lambert-server"; +import { check } from "../opcodes/instanceOf"; const PayloadSchema = { op: Number, @@ -15,14 +16,12 @@ export async function Message(this: WebSocket, buffer: Data) { // TODO: compression var data: Payload; - try { - if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer); - else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer); - const result = instanceOf(PayloadSchema, data); - if (result !== true) throw "invalid data"; - } catch (error) { - return this.close(CLOSECODES.Decode_error); - } + if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer); + else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer); + + check.call(this, PayloadSchema, data); + + console.log(data); // @ts-ignore const OPCodeHandler = OPCodeHandlers[data.op];