summary refs log tree commit diff
path: root/src/gateway/opcodes
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-08-15 17:09:40 +0200
committerRory& <root@rory.gay>2026-08-15 17:15:40 +0200
commit9f5f2a2c3b71550f21f75500534bf1332b94f771 (patch)
tree4572ef19b7e25fee06da36a62105b197cb45fade /src/gateway/opcodes
parentAllow avatar_description field in profile update (diff)
downloadserver-ts-dev/gwsep.tar.xz
Decouple gateway connection state from inner ws object github/dev/gwsep dev/gwsep
Diffstat (limited to 'src/gateway/opcodes')
-rw-r--r--src/gateway/opcodes/Identify.ts6
-rw-r--r--src/gateway/opcodes/StreamCreate.ts2
-rw-r--r--src/gateway/opcodes/StreamDelete.ts2
-rw-r--r--src/gateway/opcodes/StreamWatch.ts8
-rw-r--r--src/gateway/opcodes/instanceOf.ts2
5 files changed, 10 insertions, 10 deletions
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts

index 48fd3a20..48e24afa 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -83,7 +83,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { if (this.user_id) { // we've already identified - return this.close(CLOSECODES.Already_authenticated); + return this.rawSocket.close(CLOSECODES.Already_authenticated); } clearTimeout(this.readyTimeout); @@ -111,7 +111,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { const user = tokenData.user; if (!user) { console.log(`[Gateway/${this.ipAddress}] Failed to identify user`); - return this.close(CLOSECODES.Authentication_failed); + return this.rawSocket.close(CLOSECODES.Authentication_failed); } this.user_id = user.id; @@ -132,7 +132,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { if (this.shard_count == null || this.shard_id == null || this.shard_id > this.shard_count || this.shard_id < 0 || this.shard_count <= 0) { // TODO: why do we even care about this right now? console.log(`[Gateway/${this.user_id}] Invalid sharding from ${user.id}: ${identify.shard}`); - return this.close(CLOSECODES.Invalid_shard); + return this.rawSocket.close(CLOSECODES.Invalid_shard); } } const validateIntentsAndShardingTime = taskSw.getElapsedAndReset(); diff --git a/src/gateway/opcodes/StreamCreate.ts b/src/gateway/opcodes/StreamCreate.ts
index 6fc222ab..b1695250 100644 --- a/src/gateway/opcodes/StreamCreate.ts +++ b/src/gateway/opcodes/StreamCreate.ts
@@ -49,7 +49,7 @@ export async function onStreamCreate(this: WebSocket, data: Payload) { where: { id: body.channel_id }, }); - if (!channel || (body.type === "guild" && channel.guild_id != body.guild_id)) return this.close(4000, "invalid channel"); + if (!channel || (body.type === "guild" && channel.guild_id != body.guild_id)) return this.rawSocket.close(4000, "invalid channel"); // TODO: actually apply preferred_region from the event payload const regions = Config.get().regions; diff --git a/src/gateway/opcodes/StreamDelete.ts b/src/gateway/opcodes/StreamDelete.ts
index 82d09538..773b6508 100644 --- a/src/gateway/opcodes/StreamDelete.ts +++ b/src/gateway/opcodes/StreamDelete.ts
@@ -37,7 +37,7 @@ export async function onStreamDelete(this: WebSocket, data: Payload) { try { parsedKey = parseStreamKey(body.stream_key); } catch (e) { - return this.close(4000, "Invalid stream key"); + return this.rawSocket.close(4000, "Invalid stream key"); } // noinspection JSUnusedLocalSymbols - TODO: what is type here? diff --git a/src/gateway/opcodes/StreamWatch.ts b/src/gateway/opcodes/StreamWatch.ts
index f63e4a15..5237e766 100644 --- a/src/gateway/opcodes/StreamWatch.ts +++ b/src/gateway/opcodes/StreamWatch.ts
@@ -40,7 +40,7 @@ export async function onStreamWatch(this: WebSocket, data: Payload) { try { parsedKey = parseStreamKey(body.stream_key); } catch (e) { - return this.close(4000, "Invalid stream key"); + return this.rawSocket.close(4000, "Invalid stream key"); } const { type, channelId, guildId, userId } = parsedKey; @@ -50,14 +50,14 @@ export async function onStreamWatch(this: WebSocket, data: Payload) { relations: { channel: true }, }); - if (!stream) return this.close(4000, "Invalid stream key"); + if (!stream) return this.rawSocket.close(4000, "Invalid stream key"); - if (type === "guild" && stream.channel.guild_id != guildId) return this.close(4000, "Invalid stream key"); + if (type === "guild" && stream.channel.guild_id != guildId) return this.rawSocket.close(4000, "Invalid stream key"); const regions = Config.get().regions; const guildRegion = regions.available.find((r) => r.endpoint === stream.endpoint); - if (!guildRegion) return this.close(4000, "Unknown region"); + if (!guildRegion) return this.rawSocket.close(4000, "Unknown region"); const streamSession = StreamSession.create({ stream_id: stream.id, diff --git a/src/gateway/opcodes/instanceOf.ts b/src/gateway/opcodes/instanceOf.ts
index 7bebf49e..683feeb5 100644 --- a/src/gateway/opcodes/instanceOf.ts +++ b/src/gateway/opcodes/instanceOf.ts
@@ -30,7 +30,7 @@ export function check(this: WebSocket, schema: unknown, data: unknown) { } catch (error) { console.error(error); // invalid payload - this.close(CLOSECODES.Decode_error); + this.rawSocket.close(CLOSECODES.Decode_error); throw error; } }