From 0e67fb52cf4a59b320cafa403e9060cd19f5afc3 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Mon, 11 Sep 2023 00:55:26 -0400 Subject: [PATCH] Attempt to fix race condition on channel join --- src/ws/Socket.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ws/Socket.ts b/src/ws/Socket.ts index 7c9ab04..9c234a4 100644 --- a/src/ws/Socket.ts +++ b/src/ws/Socket.ts @@ -93,14 +93,16 @@ export class Socket extends EventEmitter { this.id = foundSocket.id; } - this.loadUser(); + (async () => { + await this.loadUser(); - // TODO Permissions - let isAdmin = false; + // TODO Permissions + let isAdmin = false; - this.setRateLimits(isAdmin ? adminLimits : userLimits); + this.setRateLimits(isAdmin ? adminLimits : userLimits); - this.bindEventListeners(); + this.bindEventListeners(); + })(); } public getIP() { @@ -133,7 +135,10 @@ export class Socket extends EventEmitter { // Does channel exist? if (channel) { // Exists, join normally - channel.join(this); + (async () => { + await this.loadUser(); + channel.join(this); + })(); } else { // Doesn't exist, create channel = new Channel(