From c00f2cbfddbb42d2950210aa1966efa339ff28f5 Mon Sep 17 00:00:00 2001 From: Test_User Date: Wed, 7 Aug 2024 20:09:04 -0400 Subject: Add membership id handling for incoming inspircd 3/4 KICKs --- protocols/inspircd4.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'protocols/inspircd4.c') diff --git a/protocols/inspircd4.c b/protocols/inspircd4.c index f336506..c22b20b 100644 --- a/protocols/inspircd4.c +++ b/protocols/inspircd4.c @@ -1927,7 +1927,7 @@ int inspircd4_protocol_handle_part(struct string source, size_t argc, struct str return 0; } -// [:source] KICK [] +// [:source] KICK [] [] int inspircd4_protocol_handle_kick(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 v4] Invalid KICK received! (Missing parameters)\r\n")); @@ -1952,11 +1952,38 @@ int inspircd4_protocol_handle_kick(struct string source, size_t argc, struct str return 0; } - int rejoin; - if (argc > 2) - rejoin = kick_channel(config->sid, source, channel, user, argv[2]); - else - rejoin = kick_channel(config->sid, source, channel, user, STRING("")); + char uses_inspircd4; + if (!STRING_EQ(user->server, SID)) { + struct server_info *server = get_table_index(server_list, user->server); + uses_inspircd4 = (server->protocol == INSPIRCD4_PROTOCOL); + } else { + uses_inspircd4 = 0; + } + + struct string reason; + if (argc >= 4) { + if (uses_inspircd4) { + char err; + size_t member_id = str_to_unsigned(argv[2], &err); + if (err) { + kill_user(SID, SID, user, STRING("Member ID limit exceeded. Please reconnect to reset it.")); + return 0; + } + + struct inspircd4_protocol_specific_user *prot_specific = user->protocol_specific[INSPIRCD4_PROTOCOL]; + struct inspircd4_protocol_member_id *current_member_id = get_table_index(prot_specific->memberships, channel->name); + if (member_id < current_member_id->id) + return 0; // Kick was for an old membership, ignore it + } + + reason = argv[3]; + } else if (argc >= 3) { + reason = argv[2]; + } else { + reason = STRING(""); + } + + int rejoin = kick_channel(config->sid, source, channel, user, reason); if (rejoin) { struct server_info *server = get_table_index(server_list, user->server); -- cgit v1.2.3