diff options
Diffstat (limited to 'server_network.c')
-rw-r--r-- | server_network.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/server_network.c b/server_network.c index 062c9d5..10b2023 100644 --- a/server_network.c +++ b/server_network.c @@ -127,7 +127,7 @@ int server_handler(struct string sender, uint64_t argc, struct string *argv) { } if (get_table_index(server_list, argv[3]) != 0) { - WRITES(2, STRING("Invalid SERVER recieved! (Duplicate SID already connected)")); + WRITES(2, STRING("Invalid SERVER recieved! (Duplicate SID already connected)\n")); return 1; } @@ -339,7 +339,6 @@ 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")); @@ -347,8 +346,7 @@ int opertype_handler(struct string sender, uint64_t argc, struct string *argv) { } memcpy(opertype.data, argv[0].data, argv[0].len); - if (user->opertype.len) - free(user->opertype.data); + free(user->opertype.data); user->opertype = opertype; @@ -375,6 +373,12 @@ int kill_handler(struct string sender, uint64_t argc, struct string *argv) { return 0; // TODO: Currently not all local users are considered; fix that, then make this give an error if (STRING_EQ(user->server, STRING("1HC"))) { + SEND(STRING(":")); + SEND(argv[0]); + SEND(STRING(" QUIT :")); + SEND(argv[1]); + SEND(STRING("\n")); + SEND(STRING("GLOADMODULE m_servprotect\n")); // required for the +k we're about to use char user_time[21]; @@ -399,14 +403,14 @@ int kill_handler(struct string sender, uint64_t argc, struct string *argv) { SEND(NULSTR(nick_time)); SEND(STRING(" +k :")); SEND(user->realname); - SEND(STRING("\n:")); - SEND(argv[0]); - SEND(STRING(" OPERTYPE ")); - SEND(opertype); SEND(STRING("\n")); if (STRING_EQ(argv[0], STRING("1HC000001"))) { SEND(STRING(":1HC METADATA 1HC000001 ssl_cert :vTrse ")); SEND(client_cert); + SEND(STRING("\n:")); + SEND(argv[0]); + SEND(STRING(" OPERTYPE ")); + SEND(opertype); SEND(STRING("\n")); } @@ -544,6 +548,8 @@ int fjoin_handler(struct string sender, uint64_t argc, struct string *argv) { set_table_index(&channel_list, argv[0], channel); } + if (timestamp < channel->ts) + channel->ts = timestamp; struct string userlist = argv[userlist_offset]; @@ -694,6 +700,13 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) { if (argv[1].len < command_prefix.len || memcmp(argv[1].data, command_prefix.data, command_prefix.len) != 0) return 0; + struct channel_info *channel_info = get_table_index(channel_list, argv[0]); + if (!channel_info) + return 0; + + if (!has_table_index(channel_info->user_list, STRING("1HC000000"))) + return 0; + offset = command_prefix.len; } else if (STRING_EQ(argv[0], STRING("1HC000000"))) { offset = 0; @@ -771,12 +784,12 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) { user ? user->nick : (server ? server->address : STRING("")), STRING(" executes `"), argv[1], - STRING("'\n"), + STRING("'"), }; privmsg(STRING("1HC000000"), log_channel, sizeof(message)/sizeof(*message), message); - return cmd->func(sender, argv[1], argv[0], command_argc, command_argv, 0); + return cmd->func(sender, argv[1], argv[0].data[0] == '#' ? argv[0] : sender, command_argc, command_argv, 0); } else { SEND(STRING(":1HC000000 NOTICE ")); if (argv[0].data[0] == '#') @@ -794,7 +807,9 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) { SEND(argv[0]); else SEND(sender); - SEND(STRING(" :Unknown command: " "\x03" "04")); + SEND(STRING(" :Unknown command: ")); + if (argv[0].data[0] == '#') + SEND(command_prefix); SEND(command_argv[0]); SEND(STRING("\n")); return 0; @@ -919,6 +934,7 @@ int initservernetwork(void) { } // probably inefficient to be calling SSL_write this frequently, but also less effort + SEND(STRING("CAPAB START 1202\nCAPAB END\n")); SEND(STRING("SERVER ")); SEND(server_name); SEND(STRING(" ")); @@ -933,7 +949,23 @@ int initservernetwork(void) { if (add_local_client(STRING("1HC000000"), nick, hostmask, nick, nick, current_time, 0) != 0) return 1; + struct user_info *user_info = get_table_index(user_list, STRING("1HC000000")); + for (uint64_t i = 0; i < num_prejoin_channels; i++) { + struct channel_info *channel; + channel = malloc(sizeof(*channel)); + if (!channel) + return 1; + *channel = (struct channel_info){ + .ts = (uint64_t)current_time, + .topic = {.data = malloc(0), .len = 0}, + .topic_ts = 0, + .modes = {.array = malloc(0), .len = 0}, + .user_list = {.array = malloc(0), .len = 0}, + .metadata = {.array = malloc(0), .len = 0}, + }; + set_table_index(&channel_list, prejoin_channels[i], channel); + set_table_index(&(channel->user_list), STRING("1HC000000"), user_info); SEND(STRING("FJOIN ")); SEND(prejoin_channels[i]); SEND(STRING(" ")); |