mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
🐛 fix hearbeat gateway
This commit is contained in:
parent
509394b592
commit
7279df5efb
18
package-lock.json
generated
18
package-lock.json
generated
@ -14,7 +14,7 @@
|
||||
"fosscord-server-util": "github:fosscord/fosscord-server-util",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-db": "^1.1.8",
|
||||
"lambert-server": "^1.1.6",
|
||||
"lambert-server": "^1.1.7",
|
||||
"missing-native-js-functions": "^1.2.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"uuid": "^8.3.2",
|
||||
@ -550,7 +550,7 @@
|
||||
},
|
||||
"node_modules/fosscord-server-util": {
|
||||
"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",
|
||||
"dependencies": {
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
@ -783,9 +783,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/lambert-server": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.6.tgz",
|
||||
"integrity": "sha512-dNfSmzgue+BwFRbCGvSxMhBIXGspOcFt2r1fAf3tdPDHvgZY2nuDBcEAYFNC2Yy3yXbxiFdVykFWQvxDRrUxtA==",
|
||||
"version": "1.1.7",
|
||||
"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.7.tgz",
|
||||
"integrity": "sha512-zb1aR4JbBt7E13dZTGL5yl+zOV+tq6Givi2DliAEdFdPdoNBiR46z04dDnesu6HtNDfbXbfM91MlxwIO9+Lnqg==",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
@ -2226,7 +2226,7 @@
|
||||
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
||||
},
|
||||
"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",
|
||||
"requires": {
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
@ -2405,9 +2405,9 @@
|
||||
}
|
||||
},
|
||||
"lambert-server": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.6.tgz",
|
||||
"integrity": "sha512-dNfSmzgue+BwFRbCGvSxMhBIXGspOcFt2r1fAf3tdPDHvgZY2nuDBcEAYFNC2Yy3yXbxiFdVykFWQvxDRrUxtA==",
|
||||
"version": "1.1.7",
|
||||
"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.1.7.tgz",
|
||||
"integrity": "sha512-zb1aR4JbBt7E13dZTGL5yl+zOV+tq6Givi2DliAEdFdPdoNBiR46z04dDnesu6HtNDfbXbfM91MlxwIO9+Lnqg==",
|
||||
"requires": {
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
|
@ -17,7 +17,7 @@
|
||||
"fosscord-server-util": "github:fosscord/fosscord-server-util",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-db": "^1.1.8",
|
||||
"lambert-server": "^1.1.6",
|
||||
"lambert-server": "^1.1.7",
|
||||
"missing-native-js-functions": "^1.2.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"uuid": "^8.3.2",
|
||||
|
@ -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];
|
||||
|
@ -3,10 +3,10 @@ import { Send } from "../util/Send";
|
||||
import { setHeartbeat } from "../util/setHeartbeat";
|
||||
import WebSocket from "../util/WebSocket";
|
||||
|
||||
export function onHeartbeat(this: WebSocket, data: Payload) {
|
||||
export async function onHeartbeat(this: WebSocket, data: Payload) {
|
||||
// TODO: validate payload
|
||||
|
||||
setHeartbeat(this);
|
||||
|
||||
Send(this, { op: 11 });
|
||||
await Send(this, { op: 11 });
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ import { CLOSECODES, Payload } from "../util/Constants";
|
||||
import WebSocket from "../util/WebSocket";
|
||||
|
||||
export function onResume(this: WebSocket, data: Payload) {
|
||||
return this.close(CLOSECODES.Session_timed_out);
|
||||
return this.close(CLOSECODES.Invalid_session);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ export function check(this: WebSocket, schema: any, data: any) {
|
||||
try {
|
||||
if (instanceOf(schema, data) !== true) throw "invalid";
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
// invalid payload
|
||||
this.close(CLOSECODES.Decode_error);
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user