From ef8638d389a34fbad9f2dd0dae026fc79408654c Mon Sep 17 00:00:00 2001 From: Test_User Date: Thu, 18 May 2023 04:12:47 -0400 Subject: Handle SQUIT --- server_network.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'server_network.c') diff --git a/server_network.c b/server_network.c index 7f8b8a9..b241f62 100644 --- a/server_network.c +++ b/server_network.c @@ -125,6 +125,11 @@ int server_handler(struct string sender, uint64_t argc, struct string *argv) { distance += from->distance + 1; } + if (get_table_index(server_list, argv[3]) != 0) { + WRITES(2, STRING("Invalid SERVER recieved! (Duplicate SID already connected)")); + return 1; + } + struct string address; address.data = malloc(argv[0].len); if (address.data == 0) @@ -376,7 +381,7 @@ int kill_handler(struct string sender, uint64_t argc, struct string *argv) { return 1; } -// TODO: Get accurate list of what got killed, what to rejoin, etc + // TODO: Get accurate list of what got killed, what to rejoin, etc struct string id = STRING("1HC000000"); if (argv[0].len != id.len || memcmp(argv[0].data, id.data, id.len) != 0) { @@ -450,7 +455,7 @@ int nick_handler(struct string sender, uint64_t argc, struct string *argv) { return 0; } -int fjoin_handler(struct string sender, uint64_t argc, struct string **argv) { +int fjoin_handler(struct string sender, uint64_t argc, struct string *argv) { if (argc < 4) { WRITES(2, STRING("Invalid FJOIN recieved! (Missing parameters")); return 1; @@ -459,6 +464,44 @@ int fjoin_handler(struct string sender, uint64_t argc, struct string **argv) { return 0; } +int squit_handler(struct string sender, uint64_t argc, struct string *argv) { + if (argc < 1) { + WRITES(2, STRING("Invalid SQUIT recieved! (Missing parameters)")); + return 1; + } + + 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); + } else { + i++; // removal of the user from the table shifts the next user into place for us + } + } + + struct remote_server *server = remove_table_index(&server_list, argv[0]); + free(server->name.data); + free(server->address.data); + if (server->via.data != 0) + free(server->via.data); + free(server); + + return 0; +} + int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) { if (argc < 2) { WRITES(2, STRING("Invalid PRIVMSG recieved (Missing parameters)\n")); @@ -598,6 +641,7 @@ int initservernetwork(void) { set_table_index(&server_network_commands, STRING("KILL"), &kill_handler); set_table_index(&server_network_commands, STRING("NICK"), &nick_handler); set_table_index(&server_network_commands, STRING("FJOIN"), &fjoin_handler); + set_table_index(&server_network_commands, STRING("SQUIT"), &squit_handler); init_user_commands(); -- cgit v1.2.3