diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-13 22:57:46 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-13 22:57:46 +0200 |
commit | 194ef5478eb48d870c5d8844f1be6393dcd37ffa (patch) | |
tree | df2f00bad728d42771e7c7131ee408455117f6ea /gateway/src | |
parent | Merge branch 'master' of https://github.com/fosscord/fosscord-api (diff) | |
download | server-194ef5478eb48d870c5d8844f1be6393dcd37ffa.tar.xz |
:construction: fix server bundle
Diffstat (limited to 'gateway/src')
-rw-r--r-- | gateway/src/Server.ts | 2 | ||||
-rw-r--r-- | gateway/src/listener/listener.ts | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/gateway/src/Server.ts b/gateway/src/Server.ts index c2bc9c47..a50c24a6 100644 --- a/gateway/src/Server.ts +++ b/gateway/src/Server.ts @@ -23,6 +23,8 @@ export class Server { }); this.server.on("upgrade", (request, socket, head) => { + console.log("socket requests upgrade", request.url); + // @ts-ignore this.ws.handleUpgrade(request, socket, head, (socket) => { this.ws.emit("connection", socket, request); }); diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts index 708bfe5c..51082586 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts @@ -58,13 +58,14 @@ export async function setupListener(this: WebSocket) { this.permissions[guild] = x; this.listeners; this.events[guild] = await listenEvent(guild, consumer, opts); - for (const channel of guild_channels) { + + for (const channel of guild_channels.filter((c) => c.guild_id === guild)) { if (x.overwriteChannel(channel.permission_overwrites).has("VIEW_CHANNEL")) { this.events[channel.id] = await listenEvent(channel.id, consumer, opts); } } }) - .catch((e) => {}); + .catch((e) => console.log("couldn't get permission for guild " + guild, e)); } this.once("close", () => { @@ -74,14 +75,14 @@ export async function setupListener(this: WebSocket) { } // TODO: only subscribe for events that are in the connection intents -function consume(this: WebSocket, opts: EventOpts) { +async function consume(this: WebSocket, opts: EventOpts) { const { data, event } = opts; const id = data.id as string; const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm const consumer = consume.bind(this); const listenOpts = opts as ListenEventOpts; - console.log("event", event); + // console.log("event", event); // subscription managment switch (event) { @@ -94,14 +95,14 @@ function consume(this: WebSocket, opts: EventOpts) { if (!permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) return; // TODO: check if user has permission to channel case "GUILD_CREATE": - listenEvent(id, consumer, listenOpts); + this.events[id] = await listenEvent(id, consumer, listenOpts); break; case "CHANNEL_UPDATE": const exists = this.events[id]; // @ts-ignore if (permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) { if (exists) break; - listenEvent(id, consumer, listenOpts); + this.events[id] = await listenEvent(id, consumer, listenOpts); } else { if (!exists) return; // return -> do not send channel update events for hidden channels opts.cancel(id); |