summary refs log tree commit diff
path: root/src/gateway
diff options
context:
space:
mode:
Diffstat (limited to 'src/gateway')
-rw-r--r--src/gateway/events/Close.ts5
-rw-r--r--src/gateway/listener/listener.ts23
-rw-r--r--src/gateway/opcodes/GuildSync.ts5
-rw-r--r--src/gateway/opcodes/Heartbeat.ts4
-rw-r--r--src/gateway/opcodes/Identify.ts34
-rw-r--r--src/gateway/opcodes/LazyRequest.ts4
-rw-r--r--src/gateway/opcodes/PresenceUpdate.ts5
-rw-r--r--src/gateway/opcodes/RequestChannelInfo.ts3
-rw-r--r--src/gateway/opcodes/RequestGuildMembers.ts4
-rw-r--r--src/gateway/opcodes/StreamCreate.ts33
-rw-r--r--src/gateway/opcodes/StreamDelete.ts21
-rw-r--r--src/gateway/opcodes/StreamWatch.ts25
-rw-r--r--src/gateway/opcodes/VoiceStateUpdate.ts5
-rw-r--r--src/gateway/util/Utils.ts4
-rw-r--r--src/gateway/util/WebSocket.ts5
15 files changed, 110 insertions, 70 deletions
diff --git a/src/gateway/events/Close.ts b/src/gateway/events/Close.ts

index 6a3c6cb3..c227c33d 100644 --- a/src/gateway/events/Close.ts +++ b/src/gateway/events/Close.ts
@@ -16,9 +16,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { WebSocket } from "@spacebar/gateway"; -import { emitEvent, Member, PresenceUpdateEvent, Session, SessionsReplace, User, VoiceState, VoiceStateUpdateEvent, distributePresenceUpdate } from "@spacebar/util"; import { randomString } from "@spacebar/api"; +import { Member, Session, User, VoiceState } from "@spacebar/database"; +import { WebSocket } from "@spacebar/gateway"; +import { emitEvent, PresenceUpdateEvent, SessionsReplace, VoiceStateUpdateEvent, distributePresenceUpdate } from "@spacebar/util"; import { ProcessLifecycle } from "../../util/util/ProcessLifecycle"; export async function Close(this: WebSocket, code: number, reason: Buffer) { diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts
index 70571e5f..226859a8 100644 --- a/src/gateway/listener/listener.ts +++ b/src/gateway/listener/listener.ts
@@ -16,26 +16,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { - Ban, - EVENTEnum, - EventOpts, - getPermission, - listenEvent, - ListenEventOpts, - Member, - Message, - NewUrlUserSignatureData, - Permissions, - RabbitMQ, - Recipient, - Relationship, -} from "@spacebar/util"; -import { CLOSECODES, OPCODES, Send } from "../util"; -import { WebSocket } from "@spacebar/gateway"; import { Channel as AMQChannel } from "amqplib"; -import { PublicMember, RelationshipType } from "@spacebar/schemas"; import { bgRedBright } from "picocolors"; +import { Ban, Member, Message, Recipient, Relationship } from "@spacebar/database"; +import { EVENTEnum, EventOpts, getPermission, listenEvent, ListenEventOpts, NewUrlUserSignatureData, Permissions, RabbitMQ } from "@spacebar/util"; +import { WebSocket } from "@spacebar/gateway"; +import { PublicMember, RelationshipType } from "@spacebar/schemas"; +import { CLOSECODES, OPCODES, Send } from "../util"; // TODO: close connection on Invalidated Token // TODO: check intent diff --git a/src/gateway/opcodes/GuildSync.ts b/src/gateway/opcodes/GuildSync.ts
index 04d3de56..f075028b 100644 --- a/src/gateway/opcodes/GuildSync.ts +++ b/src/gateway/opcodes/GuildSync.ts
@@ -16,10 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Member, Session, Presence, timePromise, Stopwatch, Config, getMostRelevantSession } from "@spacebar/util"; +import { In } from "typeorm"; +import { Member, Session } from "@spacebar/database"; import { WebSocket, Payload, OPCODES, Send, handleOffloadedGatewayRequest } from "@spacebar/gateway"; import { PublicMember } from "@spacebar/schemas"; -import { In } from "typeorm"; +import { Presence, timePromise, Stopwatch, Config, getMostRelevantSession } from "@spacebar/util"; // TODO: only show roles/members that have access to this channel // TODO: config: to list all members (even those who are offline) sorted by role, or just those who are online diff --git a/src/gateway/opcodes/Heartbeat.ts b/src/gateway/opcodes/Heartbeat.ts
index 5e60a65a..a02e3b67 100644 --- a/src/gateway/opcodes/Heartbeat.ts +++ b/src/gateway/opcodes/Heartbeat.ts
@@ -16,11 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { FindOptionsWhere } from "typeorm"; import { OPCODES, Payload, WebSocket } from "@spacebar/gateway"; +import { Session } from "@spacebar/database"; import { setHeartbeat } from "../util/Heartbeat"; import { Send } from "../util/Send"; -import { Session } from "@spacebar/util"; -import { FindOptionsWhere } from "typeorm"; interface QoSData { seq: number | null; diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts
index b4b127e5..9c87aec9 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -20,46 +20,48 @@ import { In, Not } from "typeorm"; import { PreloadedUserSettings } from "discord-protos"; import { Capabilities, CLOSECODES, OPCODES, Payload, Send, setupListener, WebSocket } from "@spacebar/gateway"; import { arrayGroupBy } from "@spacebar/extensions"; -import { getDatabase } from "@spacebar/database"; import { + getDatabase, Application, Channel, + Emoji, + Guild, + Member, + MemberPrivateProjection, + ReadState, + Recipient, + Relationship, + Role, + Session, + Sticker, + ThreadMember, + UserSettings, + UserSettingsProtos, + VoiceState, +} from "@spacebar/database"; +import { checkToken, Config, CurrentTokenFormatVersion, ElapsedTime, emitEvent, - Emoji, EVENTEnum, generateToken, - Guild, GuildOrUnavailable, Intents, - Member, - MemberPrivateProjection, OPCodes, PresenceUpdateEvent, - ReadState, ReadyEventData, ReadyGuildDTO, ReadyUserGuildSettingsEntries, - Recipient, - Relationship, - Role, - Session, SessionsReplace, - Sticker, Stopwatch, - ThreadMember, timeFunction, timePromise, TraceNode, TraceRoot, - UserSettings, - UserSettingsProtos, - VoiceState, } from "@spacebar/util"; -import { ChannelType, DefaultUserGuildSettings, DMChannel, IdentifySchema, PrivateUserProjection, PublicUser, PublicUserProjection, RelationshipType } from "@spacebar/schemas"; +import { ChannelType, DefaultUserGuildSettings, DMChannel, IdentifySchema, PrivateUserProjection, PublicUser, PublicUserProjection } from "@spacebar/schemas"; import { randomString } from "@spacebar/api"; import { check } from "./instanceOf"; diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index d8900d9e..d8f4cb5a 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts
@@ -17,11 +17,11 @@ */ import murmur from "murmurhash-js/murmurhash3_gc"; -import { getDatabase } from "@spacebar/database"; +import { getDatabase, Member, Role, Session, User, Channel } from "@spacebar/database"; import { arrayPartition } from "@spacebar/extensions"; import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send } from "@spacebar/gateway"; import { LazyRequestSchema } from "@spacebar/schemas"; -import { getPermission, listenEvent, Member, Role, Session, User, Presence, Channel, Permissions, getMostRelevantSession } from "@spacebar/util"; +import { getPermission, listenEvent, Presence, Permissions, getMostRelevantSession } from "@spacebar/util"; import { check } from "./instanceOf"; // TODO: only show roles/members that have access to this channel diff --git a/src/gateway/opcodes/PresenceUpdate.ts b/src/gateway/opcodes/PresenceUpdate.ts
index 47f84fa9..a0be5f65 100644 --- a/src/gateway/opcodes/PresenceUpdate.ts +++ b/src/gateway/opcodes/PresenceUpdate.ts
@@ -16,10 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { Session, User } from "@spacebar/database"; import { WebSocket, Payload } from "@spacebar/gateway"; -import { emitEvent, InternalStatusOrder, PresenceUpdateEvent, PrivateStatus, PublicStatus, PublicStatusOrder, Session, User } from "@spacebar/util"; -import { check } from "./instanceOf"; +import { emitEvent, InternalStatusOrder, PresenceUpdateEvent, PrivateStatus } from "@spacebar/util"; import { ActivitySchema } from "@spacebar/schemas"; +import { check } from "./instanceOf"; export async function onPresenceUpdate(this: WebSocket, { d }: Payload) { const startTime = Date.now(); diff --git a/src/gateway/opcodes/RequestChannelInfo.ts b/src/gateway/opcodes/RequestChannelInfo.ts
index efa3e728..8cb9098d 100644 --- a/src/gateway/opcodes/RequestChannelInfo.ts +++ b/src/gateway/opcodes/RequestChannelInfo.ts
@@ -16,9 +16,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { Channel } from "@spacebar/database"; import { WebSocket, Payload, OPCODES, Send, handleOffloadedGatewayRequest } from "@spacebar/gateway"; import { ChannelType } from "@spacebar/schemas"; -import { Channel, Config } from "@spacebar/util"; +import { Config } from "@spacebar/util"; export async function onRequestChannelInfo(this: WebSocket, { d }: Payload) { // Schema validation can only accept either string or array, so transforming it here to support both diff --git a/src/gateway/opcodes/RequestGuildMembers.ts b/src/gateway/opcodes/RequestGuildMembers.ts
index 88b24d6c..ec8e17cf 100644 --- a/src/gateway/opcodes/RequestGuildMembers.ts +++ b/src/gateway/opcodes/RequestGuildMembers.ts
@@ -17,10 +17,10 @@ */ import { FindManyOptions, ILike, In, MoreThan } from "typeorm"; -import { getDatabase } from "@spacebar/database"; +import { getDatabase, Member, Session } from "@spacebar/database"; import { WebSocket, Payload, OPCODES, Send, handleOffloadedGatewayRequest } from "@spacebar/gateway"; import { RequestGuildMembersSchema } from "@spacebar/schemas"; -import { Config, DateBuilder, getPermission, GuildMembersChunkEvent, Member, Presence, Session } from "@spacebar/util"; +import { Config, DateBuilder, getPermission, GuildMembersChunkEvent, Presence } from "@spacebar/util"; import { check } from "./instanceOf"; export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) { diff --git a/src/gateway/opcodes/StreamCreate.ts b/src/gateway/opcodes/StreamCreate.ts
index d1faffb1..6fc222ab 100644 --- a/src/gateway/opcodes/StreamCreate.ts +++ b/src/gateway/opcodes/StreamCreate.ts
@@ -1,17 +1,24 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import { Channel, Member, Stream, StreamSession, VoiceState } from "@spacebar/database"; import { genVoiceToken, Payload, WebSocket, generateStreamKey } from "@spacebar/gateway"; -import { - Channel, - Config, - emitEvent, - Member, - Snowflake, - Stream, - StreamCreateEvent, - StreamServerUpdateEvent, - StreamSession, - VoiceState, - VoiceStateUpdateEvent, -} from "@spacebar/util"; +import { Config, emitEvent, Snowflake, StreamCreateEvent, StreamServerUpdateEvent, VoiceStateUpdateEvent } from "@spacebar/util"; import { check } from "./instanceOf"; import { StreamCreateSchema } from "@spacebar/schemas"; diff --git a/src/gateway/opcodes/StreamDelete.ts b/src/gateway/opcodes/StreamDelete.ts
index 1ccc5ca6..82d09538 100644 --- a/src/gateway/opcodes/StreamDelete.ts +++ b/src/gateway/opcodes/StreamDelete.ts
@@ -1,5 +1,24 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2026 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import { Member, Stream, VoiceState } from "@spacebar/database"; import { parseStreamKey, Payload, WebSocket } from "@spacebar/gateway"; -import { emitEvent, Member, Stream, StreamDeleteEvent, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util"; +import { emitEvent, StreamDeleteEvent, VoiceStateUpdateEvent } from "@spacebar/util"; import { check } from "./instanceOf"; import { StreamDeleteSchema } from "@spacebar/schemas"; diff --git a/src/gateway/opcodes/StreamWatch.ts b/src/gateway/opcodes/StreamWatch.ts
index 040fb954..f63e4a15 100644 --- a/src/gateway/opcodes/StreamWatch.ts +++ b/src/gateway/opcodes/StreamWatch.ts
@@ -1,8 +1,27 @@ -import { genVoiceToken, parseStreamKey, Payload, WebSocket } from "@spacebar/gateway"; -import { Config, emitEvent, Stream, StreamCreateEvent, StreamServerUpdateEvent, StreamSession } from "@spacebar/util"; -import { check } from "./instanceOf"; +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2026 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + import { Not } from "typeorm"; +import { Stream, StreamSession } from "@spacebar/database"; +import { genVoiceToken, parseStreamKey, Payload, WebSocket } from "@spacebar/gateway"; +import { Config, emitEvent, StreamCreateEvent, StreamServerUpdateEvent } from "@spacebar/util"; import { StreamWatchSchema } from "@spacebar/schemas"; +import { check } from "./instanceOf"; export async function onStreamWatch(this: WebSocket, data: Payload) { const startTime = Date.now(); diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts
index 0bc09852..e6975358 100644 --- a/src/gateway/opcodes/VoiceStateUpdate.ts +++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -16,10 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { Guild, Member, VoiceState } from "@spacebar/database"; import { Payload, WebSocket, genVoiceToken } from "@spacebar/gateway"; -import { Config, emitEvent, Guild, Member, VoiceServerUpdateEvent, VoiceState, VoiceStateUpdateEvent } from "@spacebar/util"; -import { check } from "./instanceOf"; +import { Config, emitEvent, VoiceServerUpdateEvent, VoiceStateUpdateEvent } from "@spacebar/util"; import { Region, VoiceStateUpdateSchema } from "@spacebar/schemas"; +import { check } from "./instanceOf"; // TODO: check if a voice server is setup // Notice: Bot users respect the voice channel's user limit, if set. diff --git a/src/gateway/util/Utils.ts b/src/gateway/util/Utils.ts
index 20880622..23e9569b 100644 --- a/src/gateway/util/Utils.ts +++ b/src/gateway/util/Utils.ts
@@ -16,8 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { sleep } from "@spacebar/extensions"; -import { Event, Session, TimeSpan, VoiceState } from "@spacebar/util"; +import { Session, VoiceState } from "@spacebar/database"; +import { Event, TimeSpan } from "@spacebar/util"; import { WebSocket } from "./WebSocket"; import { OPCODES } from "./Constants"; import { Send } from "./Send"; diff --git a/src/gateway/util/WebSocket.ts b/src/gateway/util/WebSocket.ts
index 41dc93c1..50c7bbb1 100644 --- a/src/gateway/util/WebSocket.ts +++ b/src/gateway/util/WebSocket.ts
@@ -16,12 +16,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Intents, ListenEventOpts, Permissions, Session } from "@spacebar/util"; import WS from "ws"; import { Deflate, Inflate } from "fast-zlib"; -import { Capabilities } from "./Capabilities"; import { Decoder, Encoder } from "@toondepauw/node-zstd"; +import { Session } from "@spacebar/database"; +import { Intents, ListenEventOpts, Permissions } from "@spacebar/util"; import { QoSPayload } from "../opcodes/Heartbeat"; +import { Capabilities } from "./Capabilities"; export interface WebSocket extends WS { recentTransactions: string[];