summary refs log tree commit diff
path: root/src/opcodes
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-08 04:45:28 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-08 04:45:28 +0200
commitf3f11adb38994472f1e08e28659991f9cc6edf90 (patch)
tree783e803eec33252d407cf621b6fecb5b6ddad3cc /src/opcodes
parent:zap: use mongoose autopopulate (diff)
downloadserver-f3f11adb38994472f1e08e28659991f9cc6edf90.tar.xz
:page_facing_up: use Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
Diffstat (limited to 'src/opcodes')
-rw-r--r--src/opcodes/Identify.ts20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/opcodes/Identify.ts b/src/opcodes/Identify.ts

index 1fa75ec1..584965af 100644 --- a/src/opcodes/Identify.ts +++ b/src/opcodes/Identify.ts
@@ -38,6 +38,19 @@ export async function onIdentify(this: WebSocket, data: Payload) { this.user_id = decoded.id; if (!identify.intents) identify.intents = 0b11111111111111n; this.intents = new Intents(identify.intents); + if (identify.shard) { + this.shard_id = identify.shard[0]; + this.shard_count = identify.shard[1]; + if ( + !this.shard_count || + !this.shard_id || + this.shard_id >= this.shard_count || + this.shard_id < 0 || + this.shard_count <= 0 + ) { + return this.close(CLOSECODES.Invalid_shard); + } + } const members = toObject(await MemberModel.find({ id: this.user_id }).exec()); const merged_members = members.map((x: any) => { @@ -48,8 +61,8 @@ export async function onIdentify(this: WebSocket, data: Payload) { }) as MemberDocument[][]; const user_guild_settings_entries = members.map((x) => x.settings); - const channels = await ChannelModel.find({ recipients: this.user_id }).lean().exec(); - const user = await UserModel.findOne({ id: this.user_id }).lean().exec(); + const channels = await ChannelModel.find({ recipients: this.user_id }).exec(); + const user = await UserModel.findOne({ id: this.user_id }).exec(); if (!user) return this.close(CLOSECODES.Authentication_failed); const public_user = { @@ -113,7 +126,8 @@ export async function onIdentify(this: WebSocket, data: Payload) { partial: false, // TODO partial version: 642, }, - private_channels: channels, + // @ts-ignore + private_channels: toObject(channels), session_id: "", // TODO analytics_token: "", // TODO connected_accounts: [], // TODO