From d20eea410dafb444e3bdfa5fab44d166ea588304 Mon Sep 17 00:00:00 2001 From: Test_User Date: Thu, 13 Jun 2024 01:36:55 -0400 Subject: nick and kill support --- protocols/inspircd2.c | 177 +++++++++++++++++++++++++++++++++++++------------- protocols/inspircd2.h | 6 +- 2 files changed, 137 insertions(+), 46 deletions(-) (limited to 'protocols') diff --git a/protocols/inspircd2.c b/protocols/inspircd2.c index 46c9f8b..2d6fe96 100644 --- a/protocols/inspircd2.c +++ b/protocols/inspircd2.c @@ -132,8 +132,9 @@ int init_inspircd2_protocol(void) { set_table_index(&inspircd2_protocol_commands, STRING("RSQUIT"), &inspircd2_protocol_handle_rsquit); set_table_index(&inspircd2_protocol_commands, STRING("UID"), &inspircd2_protocol_handle_uid); + set_table_index(&inspircd2_protocol_commands, STRING("NICK"), &inspircd2_protocol_handle_nick); set_table_index(&inspircd2_protocol_commands, STRING("QUIT"), &inspircd2_protocol_handle_quit); -// set_table_index(&inspircd2_protocol_commands, STRING("KILL"), &inspircd2_protocol_handle_kill); + set_table_index(&inspircd2_protocol_commands, STRING("KILL"), &inspircd2_protocol_handle_kill); return 0; } @@ -505,7 +506,7 @@ void inspircd2_protocol_propagate_new_server(struct string from, struct string a } } -void inspircd2_protocol_propagate_unlink(struct string from, struct server_info *a, struct server_info *b, size_t protocol) { +void inspircd2_protocol_propagate_unlink_server(struct string from, struct server_info *a, struct server_info *b, size_t protocol) { struct server_info *source; struct server_info *target; if (a->distance == 0 && !STRING_EQ(a->sid, SID)) { @@ -567,6 +568,24 @@ void inspircd2_protocol_propagate_new_user(struct string from, struct user_info } } +void inspircd2_protocol_propagate_rename_user(struct string from, struct user_info *user, struct string nick, size_t timestamp, struct string timestamp_str) { + struct server_info *self = get_table_index(server_list, SID); + + for (size_t i = 0; i < self->connected_to.len; i++) { + struct server_info *adjacent = self->connected_to.array[i].ptr; + if (adjacent->protocol != INSPIRCD2_PROTOCOL || STRING_EQ(from, adjacent->sid)) + continue; + + networks[adjacent->net].send(adjacent->handle, STRING(":")); + networks[adjacent->net].send(adjacent->handle, user->uid); + networks[adjacent->net].send(adjacent->handle, STRING(" NICK ")); + networks[adjacent->net].send(adjacent->handle, nick); + networks[adjacent->net].send(adjacent->handle, STRING(" ")); + networks[adjacent->net].send(adjacent->handle, timestamp_str); + networks[adjacent->net].send(adjacent->handle, STRING("\n")); + } +} + void inspircd2_protocol_propagate_remove_user(struct string from, struct user_info *info, struct string reason) { struct server_info *self = get_table_index(server_list, SID); @@ -583,6 +602,24 @@ void inspircd2_protocol_propagate_remove_user(struct string from, struct user_in } } +void inspircd2_protocol_propagate_kill_user(struct string from, struct string source, struct user_info *info, struct string reason) { + struct server_info *self = get_table_index(server_list, SID); + + for (size_t i = 0; i < self->connected_to.len; i++) { + struct server_info *adjacent = self->connected_to.array[i].ptr; + if (adjacent->protocol != INSPIRCD2_PROTOCOL || STRING_EQ(from, adjacent->sid)) + continue; + + networks[adjacent->net].send(adjacent->handle, STRING(":")); + networks[adjacent->net].send(adjacent->handle, source); + networks[adjacent->net].send(adjacent->handle, STRING(" KILL ")); + networks[adjacent->net].send(adjacent->handle, info->uid); + networks[adjacent->net].send(adjacent->handle, STRING(" :")); + networks[adjacent->net].send(adjacent->handle, reason); + networks[adjacent->net].send(adjacent->handle, STRING("\n")); + } +} + void inspircd2_protocol_do_unlink_inner(struct string from, struct server_info *target, struct string reason) { target->distance = 1; // Reusing distance for `have passed`, since its set to 0 bc severed anyways @@ -654,6 +691,30 @@ void inspircd2_protocol_introduce_servers_to(size_t net, void *handle) { } } +void inspircd2_protocol_introduce_user_to(size_t net, void *handle, struct user_info *user) { + networks[net].send(handle, STRING(":")); + networks[net].send(handle, user->server); + networks[net].send(handle, STRING(" UID ")); + networks[net].send(handle, user->uid); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->user_ts_str); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->nick); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->host); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->vhost); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->ident); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->address); + networks[net].send(handle, STRING(" ")); + networks[net].send(handle, user->nick_ts_str); + networks[net].send(handle, STRING(" + :")); + networks[net].send(handle, user->fullname); + networks[net].send(handle, STRING("\n")); +} + // CAPAB [ [, ...]] int inspircd2_protocol_init_handle_capab(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config **config, char is_incoming) { if (argc < 1) { @@ -730,48 +791,8 @@ int inspircd2_protocol_init_handle_server(struct string source, size_t argc, str inspircd2_protocol_introduce_servers_to(net, handle); - for (size_t i = 0; i < user_list.len; i++) { - struct user_info *user = user_list.array[i].ptr; - - networks[net].send(handle, STRING(":")); - networks[net].send(handle, user->server); - networks[net].send(handle, STRING(" UID ")); - networks[net].send(handle, user->uid); - networks[net].send(handle, STRING(" ")); - - struct string timestamp; - char err = unsigned_to_str(user->nick_ts, ×tamp); - - if (err) { - return -1; - } - networks[net].send(handle, timestamp); - free(timestamp.data); - - networks[net].send(handle, STRING(" ")); - networks[net].send(handle, user->nick); - networks[net].send(handle, STRING(" ")); - networks[net].send(handle, user->host); - networks[net].send(handle, STRING(" ")); - networks[net].send(handle, user->vhost); - networks[net].send(handle, STRING(" ")); - networks[net].send(handle, user->ident); - networks[net].send(handle, STRING(" ")); - networks[net].send(handle, user->address); - networks[net].send(handle, STRING(" ")); - - err = unsigned_to_str(user->nick_ts, ×tamp); - - if (err) { - return -1; - } - networks[net].send(handle, timestamp); - free(timestamp.data); - - networks[net].send(handle, STRING(" + :")); - networks[net].send(handle, user->fullname); - networks[net].send(handle, STRING("\n")); - } + for (size_t i = 0; i < user_list.len; i++) + inspircd2_protocol_introduce_user_to(net, handle, user_list.array[i].ptr); networks[net].send(handle, STRING(":")); networks[net].send(handle, SID); @@ -965,7 +986,31 @@ int inspircd2_protocol_handle_uid(struct string source, size_t argc, struct stri return 0; } -// :source QUIT +// :source NICK +int inspircd2_protocol_handle_nick(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) { + if (argc < 2) { + WRITES(2, STRING("[InspIRCd v2] Invalid NICK recieved! (Missing parameters)\r\n")); + return -1; + } + + char err; + size_t nick_ts = str_to_unsigned(argv[1], &err); + if (err) { + WRITES(2, STRING("[InspIRCd v2] Invalid NICK recieved! (Invalid timestamp)\r\n")); + return -1; + } + + struct user_info *user = get_table_index(user_list, source); + if (!user) + return 0; // KILL timings, etc + + if (rename_user(config->sid, user, argv[0], nick_ts) != 0) + return -1; + + return 0; +} + +// :source QUIT [?] int inspircd2_protocol_handle_quit(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) { struct string reason; if (argc < 1) @@ -986,3 +1031,45 @@ int inspircd2_protocol_handle_quit(struct string source, size_t argc, struct str return 0; } + +// [:source] KILL [?] +int inspircd2_protocol_handle_kill(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming) { + if (argc < 1) { + WRITES(2, STRING("[InspIRCd v2] Invalid KILL recieved! (Missing parameters)\r\n")); + return -1; + } + + struct user_info *user = get_table_index(user_list, argv[0]); + if (!user) { + for (size_t i = 0; i < user_list.len; i++) { + struct user_info *tmp = user_list.array[i].ptr; + if (STRING_EQ(tmp->nick, argv[0])) { + user = tmp; + break; + } + } + + if (!user) + return 0; + } + + if (STRING_EQ(user->server, SID)) { + if (config->ignore_local_kills) { + inspircd2_protocol_introduce_user_to(net, handle, user); + } else { + if (argc > 1) + kill_user(config->sid, source, user, argv[1]); + else + kill_user(config->sid, source, user, STRING("")); + } + } else if (config->ignore_remote_kills) { + inspircd2_protocol_introduce_user_to(net, handle, user); + } else { + if (argc > 1) + kill_user(config->sid, source, user, argv[1]); + else + kill_user(config->sid, source, user, STRING("")); + } + + return 0; +} diff --git a/protocols/inspircd2.h b/protocols/inspircd2.h index 03963b6..0a19964 100644 --- a/protocols/inspircd2.h +++ b/protocols/inspircd2.h @@ -42,9 +42,12 @@ void * inspircd2_protocol_autoconnect(void *type); void inspircd2_protocol_update_propagations(void); void inspircd2_protocol_propagate_new_server(struct string from, struct string attached_to, struct server_info *info); -void inspircd2_protocol_propagate_unlink(struct string from, struct server_info *a, struct server_info *b, size_t protocol); +void inspircd2_protocol_propagate_unlink_server(struct string from, struct server_info *a, struct server_info *b, size_t protocol); + void inspircd2_protocol_propagate_new_user(struct string from, struct user_info *info); +void inspircd2_protocol_propagate_rename_user(struct string from, struct user_info *info, struct string nick, size_t timestamp, struct string timestamp_str); void inspircd2_protocol_propagate_remove_user(struct string from, struct user_info *info, struct string reason); +void inspircd2_protocol_propagate_kill_user(struct string from, struct string source, struct user_info *info, struct string reason); void inspircd2_protocol_do_unlink(struct string from, struct server_info *a, struct server_info *b); @@ -61,6 +64,7 @@ int inspircd2_protocol_handle_squit(struct string source, size_t argc, struct st int inspircd2_protocol_handle_rsquit(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming); int inspircd2_protocol_handle_uid(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming); +int inspircd2_protocol_handle_nick(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming); int inspircd2_protocol_handle_quit(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming); int inspircd2_protocol_handle_kill(struct string source, size_t argc, struct string *argv, size_t net, void *handle, struct server_config *config, char is_incoming); -- cgit v1.2.3