diff --git a/gateway/src/schema/VoiceStateUpdateSchema.ts b/gateway/src/schema/VoiceStateUpdateSchema.ts
deleted file mode 100644
index 9efa191e..00000000
--- a/gateway/src/schema/VoiceStateUpdateSchema.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-export const VoiceStateUpdateSchema = {
- $guild_id: String,
- $channel_id: String,
- self_mute: Boolean,
- self_deaf: Boolean,
- self_video: Boolean,
-};
-
-export interface VoiceStateUpdateSchema {
- guild_id?: string;
- channel_id?: string;
- self_mute: boolean;
- self_deaf: boolean;
- self_video: boolean;
-}
diff --git a/gateway/src/Server.ts b/src/gateway/Server.ts
index 82fbeba2..82fbeba2 100644
--- a/gateway/src/Server.ts
+++ b/src/gateway/Server.ts
diff --git a/gateway/src/events/Close.ts b/src/gateway/events/Close.ts
index 5b7c512c..5b7c512c 100644
--- a/gateway/src/events/Close.ts
+++ b/src/gateway/events/Close.ts
diff --git a/gateway/src/events/Connection.ts b/src/gateway/events/Connection.ts
index 508b4741..508b4741 100644
--- a/gateway/src/events/Connection.ts
+++ b/src/gateway/events/Connection.ts
diff --git a/gateway/src/events/Message.ts b/src/gateway/events/Message.ts
index 7ed1dd06..569f5fc7 100644
--- a/gateway/src/events/Message.ts
+++ b/src/gateway/events/Message.ts
@@ -6,7 +6,6 @@ try {
} catch (error) {}
import OPCodeHandlers from "../opcodes";
import { check } from "../opcodes/instanceOf";
-import WS from "ws";
const PayloadSchema = {
op: Number,
@@ -15,7 +14,7 @@ const PayloadSchema = {
$t: String,
};
-export async function Message(this: WebSocket, buffer: WS.RawData) {
+export async function Message(this: WebSocket, buffer: Buffer) {
// TODO: compression
let data: Payload;
diff --git a/gateway/src/index.ts b/src/gateway/index.ts
index d77ce931..d77ce931 100644
--- a/gateway/src/index.ts
+++ b/src/gateway/index.ts
diff --git a/gateway/src/listener/listener.ts b/src/gateway/listener/listener.ts
index 8c69e193..8c69e193 100644
--- a/gateway/src/listener/listener.ts
+++ b/src/gateway/listener/listener.ts
diff --git a/gateway/src/opcodes/Heartbeat.ts b/src/gateway/opcodes/Heartbeat.ts
index 42b72d4b..42b72d4b 100644
--- a/gateway/src/opcodes/Heartbeat.ts
+++ b/src/gateway/opcodes/Heartbeat.ts
diff --git a/gateway/src/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts
index 03fff796..44db598c 100644
--- a/gateway/src/opcodes/Identify.ts
+++ b/src/gateway/opcodes/Identify.ts
@@ -18,12 +18,13 @@ import {
PrivateSessionProjection,
MemberPrivateProjection,
PresenceUpdateEvent,
+ UserSettings,
+ IdentifySchema,
} from "@fosscord/util";
import { Send } from "../util/Send";
import { CLOSECODES, OPCODES } from "../util/Constants";
import { genSessionId } from "../util/SessionUtils";
import { setupListener } from "../listener/listener";
-import { IdentifySchema } from "../schema/Identify";
// import experiments from "./experiments.json";
const experiments: any = [];
import { check } from "./instanceOf";
@@ -56,7 +57,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
await Promise.all([
User.findOneOrFail({
where: { id: this.user_id },
- relations: ["relationships", "relationships.to"],
+ relations: ["relationships", "relationships.to", "settings"],
select: [...PrivateUserProjection, "relationships"],
}),
ReadState.find({ where: { user_id: this.user_id } }),
@@ -101,8 +102,13 @@ export async function onIdentify(this: WebSocket, data: Payload) {
]);
if (!user) return this.close(CLOSECODES.Authentication_failed);
+ if (!user.settings) { //settings may not exist after updating...
+ user.settings = new UserSettings();
+ user.settings.id = user.id;
+ //await (user.settings as UserSettings).save();
+ }
- if (!identify.intents) identify.intents = BigInt("0x6ffffffff");
+ if (!identify.intents) identify.intents = "30064771071";
this.intents = new Intents(identify.intents);
if (identify.shard) {
this.shard_id = identify.shard[0];
diff --git a/gateway/src/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index 5ba65cdd..74996f5b 100644
--- a/gateway/src/opcodes/LazyRequest.ts
+++ b/src/gateway/opcodes/LazyRequest.ts
@@ -1,5 +1,4 @@
-import { getPermission, listenEvent, Member, Role, getOrInitialiseDatabase } from "@fosscord/util";
-import { LazyRequest } from "../schema/LazyRequest";
+import { getPermission, listenEvent, Member, Role, getOrInitialiseDatabase, LazyRequest } from "@fosscord/util";
import { Send } from "../util/Send";
import { OPCODES } from "../util/Constants";
import { WebSocket, Payload, handlePresenceUpdate } from "@fosscord/gateway";
@@ -17,7 +16,7 @@ async function getMembers(guild_id: string, range: [number, number]) {
// TODO: wait for typeorm to implement ordering for .find queries https://github.com/typeorm/typeorm/issues/2620
// TODO: rewrite this, released in 0.3.0
- let members = await (await getOrInitialiseDatabase()).getRepository(Member)
+ let members: Member[] = await (await getOrInitialiseDatabase()).getRepository(Member)
.createQueryBuilder("member")
.where("member.guild_id = :guild_id", { guild_id })
.leftJoinAndSelect("member.roles", "role")
diff --git a/gateway/src/opcodes/PresenceUpdate.ts b/src/gateway/opcodes/PresenceUpdate.ts
index 415df6ee..f31c9161 100644
--- a/gateway/src/opcodes/PresenceUpdate.ts
+++ b/src/gateway/opcodes/PresenceUpdate.ts
@@ -1,6 +1,5 @@
import { WebSocket, Payload } from "@fosscord/gateway";
-import { emitEvent, PresenceUpdateEvent, Session, User } from "@fosscord/util";
-import { ActivitySchema } from "../schema/Activity";
+import { ActivitySchema, emitEvent, PresenceUpdateEvent, Session, User } from "@fosscord/util";
import { check } from "./instanceOf";
export async function onPresenceUpdate(this: WebSocket, { d }: Payload) {
diff --git a/gateway/src/opcodes/RequestGuildMembers.ts b/src/gateway/opcodes/RequestGuildMembers.ts
index b80721dc..b80721dc 100644
--- a/gateway/src/opcodes/RequestGuildMembers.ts
+++ b/src/gateway/opcodes/RequestGuildMembers.ts
diff --git a/gateway/src/opcodes/Resume.ts b/src/gateway/opcodes/Resume.ts
index 42dc586d..42dc586d 100644
--- a/gateway/src/opcodes/Resume.ts
+++ b/src/gateway/opcodes/Resume.ts
diff --git a/gateway/src/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts
index d62425f3..c4297a68 100644
--- a/gateway/src/opcodes/VoiceStateUpdate.ts
+++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -1,4 +1,3 @@
-import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema";
import { Payload, WebSocket } from "@fosscord/gateway";
import { genVoiceToken } from "../util/SessionUtils";
import { check } from "./instanceOf";
@@ -7,12 +6,13 @@ import {
emitEvent,
Guild,
Member,
- Region,
VoiceServerUpdateEvent,
VoiceState,
VoiceStateUpdateEvent,
+ VoiceStateUpdateSchema,
} from "@fosscord/util";
import { OrmUtils } from "@fosscord/util";
+import { Region } from "@fosscord/util";
// TODO: check if a voice server is setup
// Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
@@ -20,6 +20,11 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
check.call(this, VoiceStateUpdateSchema, data.d);
const body = data.d as VoiceStateUpdateSchema;
+ if(body.guild_id == null) {
+ console.log(`[Gateway] VoiceStateUpdate called with guild_id == null by user ${this.user_id}!`);
+ return;
+ }
+
let voiceState: VoiceState;
try {
voiceState = await VoiceState.findOneOrFail({
diff --git a/gateway/src/opcodes/experiments.json b/src/gateway/opcodes/experiments.json
index 0370b5da..0370b5da 100644
--- a/gateway/src/opcodes/experiments.json
+++ b/src/gateway/opcodes/experiments.json
diff --git a/gateway/src/opcodes/index.ts b/src/gateway/opcodes/index.ts
index 027739db..027739db 100644
--- a/gateway/src/opcodes/index.ts
+++ b/src/gateway/opcodes/index.ts
diff --git a/gateway/src/opcodes/instanceOf.ts b/src/gateway/opcodes/instanceOf.ts
index eb6f6ea1..eb6f6ea1 100644
--- a/gateway/src/opcodes/instanceOf.ts
+++ b/src/gateway/opcodes/instanceOf.ts
diff --git a/gateway/src/start.ts b/src/gateway/start.ts
index 2000522a..2000522a 100644
--- a/gateway/src/start.ts
+++ b/src/gateway/start.ts
diff --git a/gateway/src/util/Constants.ts b/src/gateway/util/Constants.ts
index 692f9028..692f9028 100644
--- a/gateway/src/util/Constants.ts
+++ b/src/gateway/util/Constants.ts
diff --git a/gateway/src/util/Heartbeat.ts b/src/gateway/util/Heartbeat.ts
index f6871cfe..f6871cfe 100644
--- a/gateway/src/util/Heartbeat.ts
+++ b/src/gateway/util/Heartbeat.ts
diff --git a/gateway/src/util/Send.ts b/src/gateway/util/Send.ts
index 2a28d8e0..2a28d8e0 100644
--- a/gateway/src/util/Send.ts
+++ b/src/gateway/util/Send.ts
diff --git a/gateway/src/util/SessionUtils.ts b/src/gateway/util/SessionUtils.ts
index bf854042..bf854042 100644
--- a/gateway/src/util/SessionUtils.ts
+++ b/src/gateway/util/SessionUtils.ts
diff --git a/gateway/src/util/WebSocket.ts b/src/gateway/util/WebSocket.ts
index e3313f40..9496da85 100644
--- a/gateway/src/util/WebSocket.ts
+++ b/src/gateway/util/WebSocket.ts
@@ -8,8 +8,8 @@ export interface WebSocket extends WS {
session_id: string;
encoding: "etf" | "json";
compress?: "zlib-stream";
- shard_count?: bigint;
- shard_id?: bigint;
+ shard_count?: number;
+ shard_id?: number;
deflate?: Deflate;
heartbeatTimeout: NodeJS.Timeout;
readyTimeout: NodeJS.Timeout;
diff --git a/gateway/src/util/index.ts b/src/gateway/util/index.ts
index 0be5ecee..0be5ecee 100644
--- a/gateway/src/util/index.ts
+++ b/src/gateway/util/index.ts
diff --git a/gateway/src/schema/Activity.ts b/src/util/schemas/ActivitySchema.ts
index e18f66c8..e18f66c8 100644
--- a/gateway/src/schema/Activity.ts
+++ b/src/util/schemas/ActivitySchema.ts
diff --git a/gateway/src/schema/Identify.ts b/src/util/schemas/IdentifySchema.ts
index 21141321..f3d60fb3 100644
--- a/gateway/src/schema/Identify.ts
+++ b/src/util/schemas/IdentifySchema.ts
@@ -1,8 +1,8 @@
-import { ActivitySchema } from "./Activity";
+import { ActivitySchema } from "./ActivitySchema";
export const IdentifySchema = {
token: String,
- $intents: BigInt, // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
+ $intents: String, // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
$properties: Object,
// {
// // discord uses $ in the property key for bots, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key
@@ -33,7 +33,7 @@ export const IdentifySchema = {
$presence: ActivitySchema,
$compress: Boolean,
$large_threshold: Number,
- $shard: [BigInt, BigInt],
+ $shard: [Number, Number],
$guild_subscriptions: Boolean,
$capabilities: Number,
$client_state: {
@@ -71,11 +71,11 @@ export interface IdentifySchema {
client_version?: string;
system_locale?: string;
};
- intents?: bigint; // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
+ intents?: string; // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
presence?: ActivitySchema;
compress?: boolean;
large_threshold?: number;
- shard?: [bigint, bigint];
+ shard?: [number, number];
guild_subscriptions?: boolean;
capabilities?: number;
client_state?: {
diff --git a/gateway/src/schema/LazyRequest.ts b/src/util/schemas/LazyRequestSchema.ts
index 1fe658bb..1fe658bb 100644
--- a/gateway/src/schema/LazyRequest.ts
+++ b/src/util/schemas/LazyRequestSchema.ts
|