mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat(ws): scope guest WebSocket feed to allowed bots
This commit is contained in:
1 parent
0073d7d612
commit
d2ab888114
3 files changed
+83
-13
No files matched your search
+15
-1
@@ -175,8 +175,22 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
// Guest sessions are only valid while guest mode is enabled.
|
||||
if (result.role === "guest" && !options.config.guestMode.enabled) {
|
||||
socket.write("HTTP/1.1 401 Unauthorized\r\nConnection: close\r\n\r\n");
|
||||
socket.destroy();
|
||||
return;
|
||||
}
|
||||
const guestBots = options.config.guestMode.bots;
|
||||
const botScope: "all" | Set<string> =
|
||||
result.role === "guest"
|
||||
? guestBots === "all" ? "all" : new Set(guestBots)
|
||||
: "all";
|
||||
wss.handleUpgrade(req, socket, head, (ws) => {
|
||||
(ws as unknown as { userId: string }).userId = result.userId;
|
||||
const w = ws as unknown as { userId: string; isGuest: boolean; botScope: "all" | Set<string> };
|
||||
w.userId = result.userId;
|
||||
w.isGuest = result.role === "guest";
|
||||
w.botScope = botScope;
|
||||
wss.emit("connection", ws, req);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user