Dev/post refactor fixes (#927)
* Re-introduce outgoing message logging Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Websocket dumping * Sentry user count on API * Generate session ID upon opening websocket, fix gateway dumps * Async file io in src/gateway/events/Message.ts Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Async file io in src/util/util/Config.ts Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Make pre-commit hook executable Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Fixed sync file io in src/util/util/Config.ts Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Fixed missing await call in src/util/util/AutoUpdate.ts Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Add comment to src/gateway/events/Connection.ts Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> * Clean up gateway dumping code Signed-off-by: TheArcaneBrony <myrainbowdash949@gmail.com> Co-authored-by: Madeline <46743919+MaddyUnderStars@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Madeline
parent
da9ce34933
commit
6122374e4d
@@ -1,5 +1,5 @@
|
||||
import WS from "ws";
|
||||
import { WebSocket } from "@fosscord/gateway";
|
||||
import { genSessionId, WebSocket } from "@fosscord/gateway";
|
||||
import { Send } from "../util/Send";
|
||||
import { CLOSECODES, OPCODES } from "../util/Constants";
|
||||
import { setHeartbeat } from "../util/Heartbeat";
|
||||
@@ -30,6 +30,10 @@ export async function Connection(
|
||||
|
||||
socket.ipAddress = ipAddress;
|
||||
|
||||
//Create session ID when the connection is opened. This allows gateway dump to group the initial websocket messages with the rest of the conversation.
|
||||
const session_id = genSessionId();
|
||||
socket.session_id = session_id; //Set the session of the WebSocket object
|
||||
|
||||
try {
|
||||
// @ts-ignore
|
||||
socket.on("close", Close);
|
||||
|
||||
@@ -5,6 +5,8 @@ import WS from "ws";
|
||||
import { PayloadSchema } from "@fosscord/util";
|
||||
import * as Sentry from "@sentry/node";
|
||||
import BigIntJson from "json-bigint";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
const bigIntJson = BigIntJson({ storeAsString: true });
|
||||
|
||||
var erlpack: any;
|
||||
@@ -41,6 +43,21 @@ export async function Message(this: WebSocket, buffer: WS.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", this.session_id), { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join("dump", this.session_id, `${Date.now()}.in.json`),
|
||||
JSON.stringify(data, null, 2),
|
||||
);
|
||||
|
||||
if (!this.session_id)
|
||||
console.log(
|
||||
"[Gateway] Unknown session id, dumping to unknown folder",
|
||||
);
|
||||
}
|
||||
|
||||
check.call(this, PayloadSchema, data);
|
||||
|
||||
// @ts-ignore
|
||||
|
||||
Reference in New Issue
Block a user