summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-08-09 00:52:47 -0400
committerTest_User <hax@andrewyu.org>2023-08-09 00:52:47 -0400
commit530d8cd8a6c2d28c1f358dc369613eb9e0e10a71 (patch)
treef814029e41f0fbf45be36df78ee379f0ac69c968
parentb557bac23688b304fbab0a766a2e3e93db78f429 (diff)
downloadcoupserv-530d8cd8a6c2d28c1f358dc369613eb9e0e10a71.tar.gz
coupserv-530d8cd8a6c2d28c1f358dc369613eb9e0e10a71.zip
Fix quit, kill, squit
-rw-r--r--client_network.c1
-rw-r--r--general_network.c42
-rw-r--r--network.h1
-rw-r--r--server_network.c66
4 files changed, 54 insertions, 56 deletions
diff --git a/client_network.c b/client_network.c
index e2a7c24..e6df67b 100644
--- a/client_network.c
+++ b/client_network.c
@@ -128,6 +128,7 @@ int add_local_client(struct string uid, struct string nick_arg, struct string vh
.ident = ident,
.ip = ip,
.realname = realname,
+ .opertype = {.data = malloc(0), .len = 0},
.metadata = {.array = malloc(0), .len = 0},
};
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;
+}
diff --git a/network.h b/network.h
index bdaa2a8..e08a289 100644
--- a/network.h
+++ b/network.h
@@ -110,3 +110,4 @@ extern char channel_mode_types[UCHAR_MAX];
extern int PRIVMSG(struct string source, struct string target, struct string message);
extern int add_local_client(struct string uid, struct string nick_arg, struct string vhost_arg, struct string ident_arg, struct string realname_arg, time_t timestamp);
+extern int remove_user(struct string uid, struct string reason);
diff --git a/server_network.c b/server_network.c
index 6fc84d7..b7694b1 100644
--- a/server_network.c
+++ b/server_network.c
@@ -289,7 +289,8 @@ int uid_handler(struct string sender, uint64_t argc, struct string *argv) {
.ident = ident,
.ip = ip,
.realname = realname,
- .metadata = (struct table){.array = malloc(0), .len = 0},
+ .opertype = {.data = malloc(0), .len = 0},
+ .metadata = {.array = malloc(0), .len = 0},
};
if (set_table_index(&user_list, argv[0], user) != 0)
@@ -338,6 +339,7 @@ int opertype_handler(struct string sender, uint64_t argc, struct string *argv) {
return 1;
}
+ free(user->opertype.data);
struct string opertype = {.data = malloc(argv[0].len), .len = argv[0].len};
if (!opertype.data) {
WRITES(2, STRING("OOM! (opertype_handler)\n"));
@@ -354,47 +356,10 @@ int opertype_handler(struct string sender, uint64_t argc, struct string *argv) {
}
int quit_handler(struct string sender, uint64_t argc, struct string *argv) {
- struct user_info *info = remove_table_index(&user_list, sender);
- if (!info) {
- WRITES(2, STRING("QUIT: Unknown user!\n"));
- 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, STRING("1HC000001"))) {
- SENDCLIENT(STRING(":"));
- SENDCLIENT(info->nick);
- SENDCLIENT(STRING("!"));
- SENDCLIENT(info->ident);
- SENDCLIENT(STRING("@"));
- SENDCLIENT(info->vhost);
- if (argc >= 1) {
- SENDCLIENT(STRING(" QUIT :"));
- SENDCLIENT(argv[0]);
- SENDCLIENT(STRING("\r\n"));
- } else {
- SENDCLIENT(STRING(" QUIT\r\n"));
- }
- }
-
- remove_table_index(&(chan_info->user_list), sender);
- }
-
- free(info->server.data);
- free(info->nick.data);
- if (info->opertype.len)
- free(info->opertype.data);
-
- // TODO: metadata
- free(info->metadata.array);
- free(info->realname.data);
- free(info->hostname.data);
- free(info->ip.data);
- free(info->vhost.data);
- free(info);
-
- return 0;
+ if (argc < 1)
+ return remove_user(sender, (struct string){0});
+ else
+ return remove_user(sender, argv[0]);
}
int kill_handler(struct string sender, uint64_t argc, struct string *argv) {
@@ -452,6 +417,8 @@ int kill_handler(struct string sender, uint64_t argc, struct string *argv) {
SEND(STRING("\n"));
}
}
+ } else {
+ return remove_user(argv[0], argv[1]);
}
return 0;
@@ -620,20 +587,7 @@ int squit_handler(struct string sender, uint64_t argc, struct string *argv) {
for (uint64_t i = 0; i < user_list.len;) {
struct user_info *info = user_list.array[i].ptr;
if (argv[0].len == info->server.len && memcmp(argv[0].data, info->server.data, argv[0].len) == 0) {
- remove_table_index(&user_list, user_list.array[i].name);
-
- free(info->server.data);
- free(info->nick.data);
- if (info->opertype.len)
- free(info->opertype.data);
-
- // TODO: metadata
- free(info->metadata.array);
- free(info->realname.data);
- free(info->hostname.data);
- free(info->ip.data);
- free(info->vhost.data);
- free(info);
+ remove_user(user_list.array[i].name, STRING("*.net *.split"));
} else {
i++; // removal of the user from the table shifts the next user into place for us
}