From 9343cffa8c032d5b44fce89af7fc5d8709acd9aa Mon Sep 17 00:00:00 2001 From: Test_User Date: Fri, 5 May 2023 03:37:09 -0400 Subject: Add more commands, remove trailing ; from macro --- network.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'network.c') diff --git a/network.c b/network.c index 268f2e1..3f4d8fa 100644 --- a/network.c +++ b/network.c @@ -198,6 +198,11 @@ int uid_handler(struct string sender, uint64_t argc, struct string *argv) { return 1; } + if (get_table_index(user_list, argv[0])) { + WRITES(2, STRING("Invalid UID revieved! (Attempted to create already-existing user)\n")); + return 1; + } + // TODO: modes uint8_t err; @@ -339,6 +344,70 @@ int opertype_handler(struct string sender, uint64_t argc, struct string *argv) { return 0; } +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; + } + + 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; +} + +int kill_handler(struct string sender, uint64_t argc, struct string *argv) { + if (argc < 2) { + WRITES(2, STRING("Invalid KILL recieved! (Missing parameters)\n")); + return 1; + } + +// 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) { + WRITES(2, STRING("Invalid KILL recieved! (Unknown user)\n")); + return 1; + } + + uint8_t current_time[21]; // C HaxServ will be deprecated long before we reach 20-digit timestamps + snprintf(current_time, 21, "%d", time(NULL)); + SEND(STRING("UID 1HC000000 ")); + SEND(((struct string){current_time, strlen(current_time)})); + SEND(STRING(" ")); + SEND(nick); + SEND(STRING(" ")); + SEND(hostmask); + SEND(STRING(" ")); + SEND(hostmask); + SEND(STRING(" HaxServ 192.168.1.1 ")); + SEND(((struct string){current_time, strlen(current_time)})); + SEND(STRING(" +k :HaxServ\n:1HC000000 OPERTYPE Admin\n")); + + for (uint64_t i = 0; i < num_prejoin_channels; i++) { + SEND(STRING("FJOIN ")); + SEND(prejoin_channels[i]); + SEND(STRING(" ")); + SEND(((struct string){current_time, strlen(current_time)})); + SEND(STRING(" + :,1HC000000\nMODE ")); + SEND(prejoin_channels[i]); + SEND(STRING(" +o 1HC000000\n")); + } + + 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")); @@ -446,6 +515,8 @@ int initservernetwork(void) { set_table_index(&network_commands, STRING("UID"), &uid_handler); set_table_index(&network_commands, STRING("OPERTYPE"), &opertype_handler); set_table_index(&network_commands, STRING("PRIVMSG"), &privmsg_handler); + set_table_index(&network_commands, STRING("QUIT"), &quit_handler); + set_table_index(&network_commands, STRING("KILL"), &kill_handler); init_user_commands(); -- cgit v1.2.3