diff options
Diffstat (limited to '')
-rw-r--r-- | general_network.c | 42 |
1 files changed, 42 insertions, 0 deletions
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 <string.h> #include <limits.h> +#include <stdlib.h> #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; +} |