summary refs log tree commit diff
diff options
context:
space:
mode:
authordank074 <torresefrain10@gmail.com>2026-03-06 18:13:03 -0600
committerRory& <root@rory.gay>2026-03-07 01:40:12 +0100
commit43f2b8de58210944dd0954810f5fe781b6ed6190 (patch)
treea240f94e1a7b8f2b840c6c295f1274173cab584b
parentgateway should not crash for clients that send Op 37 with missing channel ran... (diff)
downloadserver-ts-43f2b8de58210944dd0954810f5fe781b6ed6190.tar.xz
when guild region is misconfigured, fallback to default region
-rw-r--r--src/gateway/opcodes/StreamCreate.ts6
-rw-r--r--src/gateway/opcodes/VoiceStateUpdate.ts16
2 files changed, 18 insertions, 4 deletions
diff --git a/src/gateway/opcodes/StreamCreate.ts b/src/gateway/opcodes/StreamCreate.ts

index 1b8fa7ea..cd3c4b77 100644 --- a/src/gateway/opcodes/StreamCreate.ts +++ b/src/gateway/opcodes/StreamCreate.ts
@@ -46,7 +46,11 @@ export async function onStreamCreate(this: WebSocket, data: Payload) { // TODO: actually apply preferred_region from the event payload const regions = Config.get().regions; - const guildRegion = regions.available.filter((r) => r.id === regions.default)[0]; + const guildRegion = regions.available.find((r) => r.id === regions.default); + + if (!guildRegion) { + throw new Error("No default region configured"); + } // first make sure theres no other streams for this user that somehow didnt get cleared await Stream.delete({ diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts
index a128ee3e..89ead6e7 100644 --- a/src/gateway/opcodes/VoiceStateUpdate.ts +++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -127,11 +127,21 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { where: { id: voiceState.guild_id }, }); const regions = Config.get().regions; - let guildRegion: Region; + let guildRegion: Region | undefined; + + const defaultRegion = regions.available.find((r) => r.id === regions.default); + if (guild && guild.region) { - guildRegion = regions.available.filter((r) => r.id === guild.region)[0]; + // in case the configured guild region does not exist (which can + // happen when server regions config is updated after guild creation), + // fallback to default region + guildRegion = regions.available.find((r) => r.id === guild.region) ?? defaultRegion; } else { - guildRegion = regions.available.filter((r) => r.id === regions.default)[0]; + guildRegion = defaultRegion; + } + + if (!guildRegion) { + throw new Error("Unable to find suitable region due to misconfiguration of regions"); } await emitEvent({