From 0ece65e94041ccdca5724ea44513611266c3ca56 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Thu, 1 Feb 2024 08:31:34 -0500 Subject: [PATCH] Add bye message --- src/ws/Socket.ts | 4 +++- src/ws/events/user/handlers/bye.ts | 9 +++++++++ src/ws/events/user/index.ts | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/ws/events/user/handlers/bye.ts diff --git a/src/ws/Socket.ts b/src/ws/Socket.ts index d290adb..f093a8d 100644 --- a/src/ws/Socket.ts +++ b/src/ws/Socket.ts @@ -409,7 +409,9 @@ export class Socket extends EventEmitter { public subscribeToChannelList() { ChannelList.subscribe(this.id); - const firstList = ChannelList.getPublicList().map(v => v.getInfo(this._id)); + const firstList = ChannelList.getPublicList().map(v => + v.getInfo(this._id) + ); this.sendChannelList(firstList); } diff --git a/src/ws/events/user/handlers/bye.ts b/src/ws/events/user/handlers/bye.ts new file mode 100644 index 0000000..6f2ea12 --- /dev/null +++ b/src/ws/events/user/handlers/bye.ts @@ -0,0 +1,9 @@ +import { ServerEventListener } from "../../../../util/types"; + +export const bye: ServerEventListener<"bye"> = { + id: "bye", + callback: (msg, socket) => { + // Leave server + socket.destroy(); + } +}; diff --git a/src/ws/events/user/index.ts b/src/ws/events/user/index.ts index 1589f9a..081e42f 100644 --- a/src/ws/events/user/index.ts +++ b/src/ws/events/user/index.ts @@ -14,6 +14,7 @@ import { minus_ls } from "./handlers/-ls"; import { admin_message } from "./handlers/admin_message"; import { chset } from "./handlers/chset"; import { kickban } from "./handlers/kickban"; +import { bye } from "./handlers/bye"; // Imagine not having an "addMany" function... @@ -42,7 +43,8 @@ EVENTGROUP_USER.addMany( minus_ls, admin_message, chset, - kickban + kickban, + bye ); eventGroups.push(EVENTGROUP_USER);