From a25d22a1c26203b7c9e2dcd33f4c602b0f82684d Mon Sep 17 00:00:00 2001 From: Test_User Date: Mon, 7 Aug 2023 19:43:57 -0400 Subject: A bunch of stuff, mostly related to client support --- server_network.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'server_network.c') diff --git a/server_network.c b/server_network.c index b241f62..cba827d 100644 --- a/server_network.c +++ b/server_network.c @@ -68,6 +68,7 @@ int resolve(char *address, char *port, struct sockaddr *sockaddr) { struct table server_network_commands = {0}; struct table server_list = {0}; struct table user_list = {0}; +struct table channel_list = {0}; int ping_handler(struct string sender, uint64_t argc, struct string *argv) { if (argc < 2) { @@ -401,7 +402,9 @@ int kill_handler(struct string sender, uint64_t argc, struct string *argv) { 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")); + SEND(STRING(" +k :HaxServ\n:1HC000000 ")); + SEND(opertype); + SEND(STRING("\n")); for (uint64_t i = 0; i < num_prejoin_channels; i++) { SEND(STRING("FJOIN ")); @@ -461,6 +464,32 @@ int fjoin_handler(struct string sender, uint64_t argc, struct string *argv) { return 1; } +// uint8_t err; +// uint64_t timestamp = str_to_unsigned(argv[1], &err); +// if (err) { +// WRITES(2, STRING("Invalid FJOIN recieved! (Invalid timestamp given)\n")); +// return 1; +// } +// +// // TODO: Parse modes, then make the rest of this work +// +// +// struct channel_info *channel = get_table_index(channel_list, argv[0]); +// if (!channel) { +// channel = malloc(sizeof(*channel)); +// if (!channel) { +// WRITES(2, STRING("OOM! (fjoin_handler)\n")); +// return 1; +// } +// *channel = (struct channel_info){ +// .ts = timestamp, +// +// +// set_table_index(&channel_list, argv[0], channel); +// +// +// } + return 0; } @@ -513,6 +542,38 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) { return 1; } + struct user_info *user = get_table_index(user_list, sender); + if (user) { + if (argv[0].data[0] == '#') { + struct channel_info *channel = get_table_index(channel_list, argv[0]); + if (channel && has_table_index(channel->user_list, STRING("1HC000001"))) { + SENDCLIENT(STRING(":")); + SENDCLIENT(user->nick); + SENDCLIENT(STRING("!")); + SENDCLIENT(user->ident); + SENDCLIENT(STRING("@")); + SENDCLIENT(user->vhost); + SENDCLIENT(STRING(" PRIVMSG ")); + SENDCLIENT(argv[0]); + SENDCLIENT(STRING(" :")); + SENDCLIENT(argv[1]); + SENDCLIENT(STRING("\r\n")); + } + } else if (argv[0].len == 9 && memcmp(argv[0].data, "1HC000001", 9) == 0) { + SENDCLIENT(STRING(":")); + SENDCLIENT(user->nick); + SENDCLIENT(STRING("!")); + SENDCLIENT(user->ident); + SENDCLIENT(STRING("@")); + SENDCLIENT(user->vhost); + SENDCLIENT(STRING(" PRIVMSG ")); + SENDCLIENT(client_nick); + SENDCLIENT(STRING(" :")); + SENDCLIENT(argv[1]); + SENDCLIENT(STRING("\r\n")); + } + } + uint64_t offset; if (argv[0].data[0] == '#') { if (argv[1].len < command_prefix.len || memcmp(argv[1].data, command_prefix.data, command_prefix.len) != 0) @@ -562,7 +623,6 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) { if (cmd) { if (!cmd->local_only) { if (cmd->privs.len != 0 && sender.len != 3) { // servers always count as oper :P - struct user_info *user = get_table_index(user_list, sender); if (!user) { WRITES(2, STRING("User is unknown!\n")); @@ -631,6 +691,7 @@ int initservernetwork(void) { server_network_commands.array = malloc(0); server_list.array = malloc(0); user_list.array = malloc(0); + channel_list.array = malloc(0); set_table_index(&server_network_commands, STRING("PING"), &ping_handler); set_table_index(&server_network_commands, STRING("SERVER"), &server_handler); @@ -669,7 +730,9 @@ int initservernetwork(void) { 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")); + SEND(STRING(" +k :HaxServ\n:1HC000000 OPERTYPE ")); + SEND(opertype); + SEND(STRING("\n")); for (uint64_t i = 0; i < num_prejoin_channels; i++) { SEND(STRING("FJOIN ")); -- cgit v1.2.3