1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-13 14:12:41 +01:00

🐛 fix hearbeat gateway

This commit is contained in:
Flam3rboy 2021-04-06 14:15:13 +02:00
parent 509394b592
commit 7279df5efb
6 changed files with 21 additions and 21 deletions

18
package-lock.json generated
View File

@ -14,7 +14,7 @@
"fosscord-server-util": "github:fosscord/fosscord-server-util", "fosscord-server-util": "github:fosscord/fosscord-server-util",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.8", "lambert-db": "^1.1.8",
"lambert-server": "^1.1.6", "lambert-server": "^1.1.7",
"missing-native-js-functions": "^1.2.3", "missing-native-js-functions": "^1.2.3",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"uuid": "^8.3.2", "uuid": "^8.3.2",
@ -550,7 +550,7 @@
}, },
"node_modules/fosscord-server-util": { "node_modules/fosscord-server-util": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#a888147dfc44710b0e7c70d04b7a841a181fb71d", "resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#6fbfcac1ba72ad123700824535c1e076190f4630",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
@ -783,9 +783,9 @@
} }
}, },
"node_modules/lambert-server": { "node_modules/lambert-server": {
"version": "1.1.6", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.6.tgz", "resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.7.tgz",
"integrity": "sha512-dNfSmzgue+BwFRbCGvSxMhBIXGspOcFt2r1fAf3tdPDHvgZY2nuDBcEAYFNC2Yy3yXbxiFdVykFWQvxDRrUxtA==", "integrity": "sha512-zb1aR4JbBt7E13dZTGL5yl+zOV+tq6Givi2DliAEdFdPdoNBiR46z04dDnesu6HtNDfbXbfM91MlxwIO9+Lnqg==",
"dependencies": { "dependencies": {
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"express": "^4.17.1", "express": "^4.17.1",
@ -2226,7 +2226,7 @@
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
}, },
"fosscord-server-util": { "fosscord-server-util": {
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#a888147dfc44710b0e7c70d04b7a841a181fb71d", "version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#6fbfcac1ba72ad123700824535c1e076190f4630",
"from": "fosscord-server-util@github:fosscord/fosscord-server-util", "from": "fosscord-server-util@github:fosscord/fosscord-server-util",
"requires": { "requires": {
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
@ -2405,9 +2405,9 @@
} }
}, },
"lambert-server": { "lambert-server": {
"version": "1.1.6", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.6.tgz", "resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.7.tgz",
"integrity": "sha512-dNfSmzgue+BwFRbCGvSxMhBIXGspOcFt2r1fAf3tdPDHvgZY2nuDBcEAYFNC2Yy3yXbxiFdVykFWQvxDRrUxtA==", "integrity": "sha512-zb1aR4JbBt7E13dZTGL5yl+zOV+tq6Givi2DliAEdFdPdoNBiR46z04dDnesu6HtNDfbXbfM91MlxwIO9+Lnqg==",
"requires": { "requires": {
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"express": "^4.17.1", "express": "^4.17.1",

View File

@ -17,7 +17,7 @@
"fosscord-server-util": "github:fosscord/fosscord-server-util", "fosscord-server-util": "github:fosscord/fosscord-server-util",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.8", "lambert-db": "^1.1.8",
"lambert-server": "^1.1.6", "lambert-server": "^1.1.7",
"missing-native-js-functions": "^1.2.3", "missing-native-js-functions": "^1.2.3",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"uuid": "^8.3.2", "uuid": "^8.3.2",

View File

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

View File

@ -3,10 +3,10 @@ import { Send } from "../util/Send";
import { setHeartbeat } from "../util/setHeartbeat"; import { setHeartbeat } from "../util/setHeartbeat";
import WebSocket from "../util/WebSocket"; import WebSocket from "../util/WebSocket";
export function onHeartbeat(this: WebSocket, data: Payload) { export async function onHeartbeat(this: WebSocket, data: Payload) {
// TODO: validate payload // TODO: validate payload
setHeartbeat(this); setHeartbeat(this);
Send(this, { op: 11 }); await Send(this, { op: 11 });
} }

View File

@ -3,5 +3,5 @@ import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket"; import WebSocket from "../util/WebSocket";
export function onResume(this: WebSocket, data: Payload) { export function onResume(this: WebSocket, data: Payload) {
return this.close(CLOSECODES.Session_timed_out); return this.close(CLOSECODES.Invalid_session);
} }

View File

@ -6,6 +6,7 @@ export function check(this: WebSocket, schema: any, data: any) {
try { try {
if (instanceOf(schema, data) !== true) throw "invalid"; if (instanceOf(schema, data) !== true) throw "invalid";
} catch (error) { } catch (error) {
console.error(error);
// invalid payload // invalid payload
this.close(CLOSECODES.Decode_error); this.close(CLOSECODES.Decode_error);
return false; return false;