diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts
index 07a5706c..8e16ee46 100644
--- a/src/gateway/events/Connection.ts
+++ b/src/gateway/events/Connection.ts
@@ -84,7 +84,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
// @ts-ignore
socket.on("message", Message);
- socket.on("error", (err) => console.error("[Gateway]", err));
+ socket.on("error", (err) => console.error(`[Gateway/${socket.user_id ?? socket.ipAddress}]`, err));
console.log(`[Gateway] New connection from ${ipAddress}, total ${this.clients.size}`);
@@ -106,7 +106,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
// @ts-ignore
socket.encoding = searchParams.get("encoding") || "json";
if (!["json", "etf"].includes(socket.encoding)) {
- console.error(`[Gateway] Unknown encoding: ${socket.encoding}`);
+ console.error(`[Gateway/${socket.ipAddress}] Unknown encoding: ${socket.encoding}`);
return socket.close(CLOSECODES.Decode_error);
}
@@ -114,7 +114,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
socket.version = Number(searchParams.get("version")) || 8;
if (socket.version != 8) {
- console.error(`[Gateway] Invalid API version: ${socket.version}`);
+ console.error(`[Gateway/${socket.ipAddress}] Invalid API version: ${socket.version}`);
return socket.close(CLOSECODES.Invalid_API_version);
}
@@ -128,7 +128,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
socket.zstdEncoder = new Encoder(6);
socket.zstdDecoder = new Decoder();
} else {
- console.error(`[Gateway] Unknown compression: ${socket.compress}`);
+ console.error(`[Gateway/${socket.user_id}] Unknown compression: ${socket.compress}`);
return socket.close(CLOSECODES.Decode_error);
}
}
diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts
index 532d765f..ba6a7b17 100644
--- a/src/gateway/events/Message.ts
+++ b/src/gateway/events/Message.ts
@@ -63,11 +63,11 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
try {
data = erlpack.unpack(buffer);
} catch {
- console.error("[Gateway] Failed to decode ETF payload");
+ console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Failed to decode ETF payload`);
return this.close(CLOSECODES.Decode_error);
}
} else {
- console.error("[Gateway] Unknown payload format");
+ console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Unknown payload format`);
return this.close(CLOSECODES.Decode_error);
}
@@ -79,14 +79,14 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
await fs.mkdir(path.join("dump", id), { recursive: true });
await fs.writeFile(path.join("dump", id, `${Date.now()}.in.json`), JSON.stringify(data, null, 2));
- if (!this.session_id) console.log("[Gateway] Unknown session id, dumping to unknown folder");
+ if (!this.session_id) console.log(`[Gateway/${this.user_id ?? this.ipAddress}] Unknown session id, dumping to unknown folder`);
}
check.call(this, PayloadSchema, data);
const OPCodeHandler = OPCodeHandlers[data.op];
if (!OPCodeHandler) {
- console.error("[Gateway] Unknown opcode " + data.op);
+ console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Unknown opcode`, data.op);
// TODO: if all opcodes are implemented comment this out:
// this.close(CLOSECODES.Unknown_opcode);
return;
@@ -95,7 +95,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
try {
return await OPCodeHandler.call(this, data);
} catch (error) {
- console.error(`Error: Op ${data.op}`, error);
+ console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Error: Op ${data.op}`, error);
// if (!this.CLOSED && this.CLOSING)
return this.close(CLOSECODES.Unknown_error);
}
diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts
index b4951492..02d171fe 100644
--- a/src/gateway/listener/listener.ts
+++ b/src/gateway/listener/listener.ts
@@ -340,7 +340,12 @@ async function consume(this: WebSocket, opts: EventOpts) {
if (event === "GUILD_MEMBER_ADD") {
if ((data as PublicMember).roles === undefined || (data as PublicMember).roles === null) {
- console.log(bgRedBright("[Gateway]"), "[GUILD_MEMBER_ADD] roles is undefined, setting to empty array!", opts.origin ?? "(Event origin not defined)", data);
+ console.log(
+ bgRedBright(`[Gateway/${this.user_id}]`),
+ "[GUILD_MEMBER_ADD] roles is undefined, setting to empty array!",
+ opts.origin ?? "(Event origin not defined)",
+ data,
+ );
(data as PublicMember).roles = [];
}
}
diff --git a/src/gateway/opcodes/GuildSubscriptionsBulk.ts b/src/gateway/opcodes/GuildSubscriptionsBulk.ts
index be693574..ec232829 100644
--- a/src/gateway/opcodes/GuildSubscriptionsBulk.ts
+++ b/src/gateway/opcodes/GuildSubscriptionsBulk.ts
@@ -19,5 +19,7 @@ export async function onGuildSubscriptionsBulk(this: WebSocket, payload: Payload
},
});
}
- console.log(`[Gateway] GuildSubscriptionsBulk processed ${Object.keys(body.subscriptions).length} subscriptions for user ${this.user_id} in ${Date.now() - startTime}ms`);
+ console.log(
+ `[Gateway/${this.user_id}] GuildSubscriptionsBulk processed ${Object.keys(body.subscriptions).length} subscriptions for user ${this.user_id} in ${Date.now() - startTime}ms`,
+ );
}
diff --git a/src/gateway/opcodes/GuildSync.ts b/src/gateway/opcodes/GuildSync.ts
index ab279639..770e62c8 100644
--- a/src/gateway/opcodes/GuildSync.ts
+++ b/src/gateway/opcodes/GuildSync.ts
@@ -71,14 +71,14 @@ export async function onGuildSync(this: WebSocket, { d }: Payload) {
// not awaiting lol
Promise.all(tasks)
.then((res) => {
- console.log(`[Gateway] GUILD_SYNC processed ${guild_ids.length} guilds in ${sw.elapsed().totalMilliseconds}ms:`, {
+ console.log(`[Gateway/${this.user_id}] GUILD_SYNC processed ${guild_ids.length} guilds in ${sw.elapsed().totalMilliseconds}ms:`, {
...Object.fromEntries(
res.map((r) => [r.result.id, `${r.result.id}: ${r.result.members.length}U/${r.result.presences.length}P in ${r.elapsed.totalMilliseconds}ms`]),
),
});
})
.catch((err) => {
- console.error("[Gateway] Error processing GUILD_SYNC:", err);
+ console.error(`[Gateway/${this.user_id}] Error processing GUILD_SYNC:`, err);
});
}
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts
index a46b0513..9b9e1d14 100644
--- a/src/gateway/opcodes/Identify.ts
+++ b/src/gateway/opcodes/Identify.ts
@@ -103,7 +103,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
const user = tokenData.user;
if (!user) {
- console.log("[Gateway] Failed to identify user");
+ console.log(`[Gateway/${this.ipAddress}] Failed to identify user`);
return this.close(CLOSECODES.Authentication_failed);
}
@@ -124,7 +124,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] Invalid sharding from ${user.id}: ${identify.shard}`);
+ console.log(`[Gateway/${this.user_id}] Invalid sharding from ${user.id}: ${identify.shard}`);
return this.close(CLOSECODES.Invalid_shard);
}
}
@@ -374,7 +374,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
trace.micros = totalSw.elapsed().totalMicroseconds;
mergeMemberGuildsTrace.calls!.push(`guild_${m.guild_id}`, trace);
} else {
- console.error(`[Gateway] Member ${m.id} has invalid guild_id ${m.guild_id}`);
+ console.error(`[Gateway/${this.user_id}] Member ${m.id} has invalid guild_id ${m.guild_id}`);
mergeMemberGuildsTrace.calls!.push(`guild_~~${m.guild_id}~~`, trace);
}
});
@@ -781,7 +781,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
]
: [],
},
- })?.catch((e) => console.error(`[Gateway] error when sending bot guilds`, e));
+ })?.catch((e) => console.error(`[Gateway/${this.user_id}] error when sending bot guilds`, e));
}),
);
@@ -815,5 +815,8 @@ export async function onIdentify(this: WebSocket, data: Payload) {
//TODO send GUILD_MEMBER_LIST_UPDATE
//TODO send VOICE_STATE_UPDATE to let the client know if another device is already connected to a voice channel
await setupListener.call(this);
- console.log(`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, process.env.LOG_GATEWAY_TRACES ? JSON.stringify(d._trace, null, 2) : "");
+ console.log(
+ `[Gateway/${this.user_id}] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`,
+ process.env.LOG_GATEWAY_TRACES ? JSON.stringify(d._trace, null, 2) : "",
+ );
}
diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index 3a56a0c8..4b916ac6 100644
--- a/src/gateway/opcodes/LazyRequest.ts
+++ b/src/gateway/opcodes/LazyRequest.ts
@@ -275,5 +275,5 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
},
});
- console.log(`[Gateway] LAZY_REQUEST ${guild_id} ${channel_id} took ${Date.now() - startTime}ms`);
+ console.log(`[Gateway/${this.user_id}] LAZY_REQUEST ${guild_id} ${channel_id} took ${Date.now() - startTime}ms`);
}
diff --git a/src/gateway/opcodes/RequestGuildMembers.ts b/src/gateway/opcodes/RequestGuildMembers.ts
index 8fa90179..fa3724ad 100644
--- a/src/gateway/opcodes/RequestGuildMembers.ts
+++ b/src/gateway/opcodes/RequestGuildMembers.ts
@@ -184,5 +184,5 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
});
});
- console.log(`[Gateway] REQUEST_GUILD_MEMBERS took ${Date.now() - startTime}ms for guild ${guild_id} with ${members.length} members`);
+ console.log(`[Gateway/${this.user_id}] REQUEST_GUILD_MEMBERS took ${Date.now() - startTime}ms for guild ${guild_id} with ${members.length} members`);
}
diff --git a/src/gateway/opcodes/StreamCreate.ts b/src/gateway/opcodes/StreamCreate.ts
index 0c6c8c2d..1b8fa7ea 100644
--- a/src/gateway/opcodes/StreamCreate.ts
+++ b/src/gateway/opcodes/StreamCreate.ts
@@ -109,7 +109,7 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
channel_id: voiceState.channel_id,
} as VoiceStateUpdateEvent);
- console.log(`[Gateway] STREAM_CREATE for user ${this.user_id} in channel ${body.channel_id} with stream key ${streamKey} in ${Date.now() - startTime}ms`);
+ console.log(`[Gateway/${this.user_id}] STREAM_CREATE for user ${this.user_id} in channel ${body.channel_id} with stream key ${streamKey} in ${Date.now() - startTime}ms`);
}
//stream key:
diff --git a/src/gateway/opcodes/StreamDelete.ts b/src/gateway/opcodes/StreamDelete.ts
index c684b6c7..c5d8bec3 100644
--- a/src/gateway/opcodes/StreamDelete.ts
+++ b/src/gateway/opcodes/StreamDelete.ts
@@ -69,5 +69,5 @@ export async function onStreamDelete(this: WebSocket, data: Payload) {
channel_id: channelId,
} as StreamDeleteEvent);
- console.log(`[Gateway] STREAM_DELETE for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
+ console.log(`[Gateway/${this.user_id}] STREAM_DELETE for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
}
diff --git a/src/gateway/opcodes/StreamWatch.ts b/src/gateway/opcodes/StreamWatch.ts
index 3a3c553e..92588a9d 100644
--- a/src/gateway/opcodes/StreamWatch.ts
+++ b/src/gateway/opcodes/StreamWatch.ts
@@ -82,5 +82,5 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
user_id: this.user_id,
} as StreamServerUpdateEvent);
- console.log(`[Gateway] STREAM_WATCH for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
+ console.log(`[Gateway/${this.user_id}] STREAM_WATCH for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
}
diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts
index 5d363825..e267461e 100644
--- a/src/gateway/opcodes/VoiceStateUpdate.ts
+++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -141,5 +141,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
} as VoiceServerUpdateEvent);
}
- console.log(`[Gateway] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`);
+ console.log(
+ `[Gateway/${this.user_id}] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`,
+ );
}
|