From 530d8cd8a6c2d28c1f358dc369613eb9e0e10a71 Mon Sep 17 00:00:00 2001 From: Test_User Date: Wed, 9 Aug 2023 00:52:47 -0400 Subject: Fix quit, kill, squit --- general_network.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'general_network.c') diff --git a/general_network.c b/general_network.c index 9da36ce..861fadc 100644 --- a/general_network.c +++ b/general_network.c @@ -28,6 +28,7 @@ #include #include +#include #include "network.h" #include "tls.h" @@ -137,3 +138,44 @@ int PRIVMSG(struct string source, struct string target, struct string message) { return 0; } + +int remove_user(struct string uid, struct string reason) { // If disconnecting the local client, set client_connected = 0 *before* calling this + struct user_info *info = remove_table_index(&user_list, uid); + if (!info) + return 1; + + for (uint64_t i = 0; i < channel_list.len; i++) { // TODO: Use channel list attached to the user (doesn't exist yet) + struct channel_info *chan_info = channel_list.array[i].ptr; + if (has_table_index(chan_info->user_list, uid)) { + if (client_connected && has_table_index(chan_info->user_list, STRING("1HC000001"))) { + SENDCLIENT(STRING(":")); + SENDCLIENT(info->nick); + SENDCLIENT(STRING("!")); + SENDCLIENT(info->ident); + SENDCLIENT(STRING("@")); + SENDCLIENT(info->vhost); + if (reason.len != 0) { + SENDCLIENT(STRING(" QUIT :")); + SENDCLIENT(reason); + SENDCLIENT(STRING("\r\n")); + } else { + SENDCLIENT(STRING(" QUIT\r\n")); + } + } + + remove_table_index(&(chan_info->user_list), uid); + } + } + + free(info->server.data); + free(info->nick.data); + free(info->opertype.data); + free(info->metadata.array); + free(info->realname.data); + free(info->hostname.data); + free(info->ip.data); + free(info->vhost.data); + free(info); + + return 0; +} -- cgit v1.2.3