summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-12-31 14:53:56 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-12-31 14:53:56 +1100
commit09b0eeb2dd0921dc4afc0d7d9459ad89d35f619f (patch)
treed9d7de04beee6e52c9b038c4fd5ac6868e27cd4f
parentPatch body-parser to use json-bigint (diff)
parentAllow Bearer tokens through, like Bot (diff)
downloadserver-09b0eeb2dd0921dc4afc0d7d9459ad89d35f619f.tar.xz
Merge branch 'maddy/refactor' into maddy/bodyParserPatch
-rw-r--r--.github/workflows/build.yml4
-rw-r--r--src/gateway/events/Connection.ts16
-rw-r--r--src/gateway/events/Message.ts2
-rw-r--r--src/util/util/Token.ts1
4 files changed, 20 insertions, 3 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c8a9cee7..e3bcc81f 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -17,9 +17,9 @@ jobs:
         # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
     - name: Use Node.js ${{ matrix.node-version }}
-      uses: actions/setup-node@v2
+      uses: actions/setup-node@v3
       with:
         node-version: ${{ matrix.node-version }}
         cache: 'npm'
diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts
index ee75212f..d47ac314 100644
--- a/src/gateway/events/Connection.ts
+++ b/src/gateway/events/Connection.ts
@@ -12,7 +12,7 @@ import { Config } from "@fosscord/util";
 var erlpack: any;
 try {
 	erlpack = require("@yukikaze-bot/erlpack");
-} catch (error) {}
+} catch (error) { }
 
 // TODO: check rate limit
 // TODO: specify rate limit in config
@@ -39,6 +39,20 @@ export async function Connection(
 		// 	`[Gateway] New connection from ${socket.ipAddress}, total ${this.clients.size}`,
 		// );
 
+		if (process.env.WS_LOGEVENTS)
+			[
+				"close",
+				"error",
+				"upgrade",
+				//"message",
+				"open",
+				"ping",
+				"pong",
+				"unexpected-response"
+			].forEach((x) => {
+				socket.on(x, (y) => console.log(x, y));
+			});
+
 		const { searchParams } = new URL(`http://localhost${request.url}`);
 		// @ts-ignore
 		socket.encoding = searchParams.get("encoding") || "json";
diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts
index a88495f6..57af0c69 100644
--- a/src/gateway/events/Message.ts
+++ b/src/gateway/events/Message.ts
@@ -33,6 +33,8 @@ 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)}`);
+
 	check.call(this, PayloadSchema, data);
 
 	// @ts-ignore
diff --git a/src/util/util/Token.ts b/src/util/util/Token.ts
index 19e64f47..ab323f2a 100644
--- a/src/util/util/Token.ts
+++ b/src/util/util/Token.ts
@@ -7,6 +7,7 @@ export const JWTOptions: VerifyOptions = { algorithms: ["HS256"] };
 export function checkToken(token: string, jwtSecret: string): Promise<any> {
 	return new Promise((res, rej) => {
 		token = token.replace("Bot ", "");
+		token = token.replace("Bearer ", "");
 		/**
 		in fosscord, even with instances that have bot distinction; we won't enforce "Bot" prefix,
 		as we don't really have separate pathways for bots