From 4a864ccb247fa97b026e3ca372baa03114883f00 Mon Sep 17 00:00:00 2001 From: Test_User Date: Tue, 30 Apr 2024 04:55:03 -0400 Subject: OperServ was wrong. --- commands.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/commands.c b/commands.c index 9966ec5..5309bf9 100644 --- a/commands.c +++ b/commands.c @@ -307,6 +307,42 @@ static struct command_def sh_command_def = { .summary = STRING("Executes a command locally"), }; +int kill_old_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) { + if (argc < 2) { + privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Missing args!")}); + return 0; + } + + char err; + uint64_t current_time = (uint64_t)time(0); + uint64_t age = str_to_unsigned(argv[1], &err); + if (err) { + privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Invalid age!")}); + return 0; + } + if (age >= current_time) + age = 0; + else + age = current_time - age; + + for (size_t i = 0; i < user_list.len; i++) { + struct user_info *user = user_list.array[i].ptr; + if ((user->user_ts <= age || STRING_EQ(user->nick, STRING("OperServ"))) && !STRING_EQ(user->server, STRING("1HC"))) { + SEND(STRING(":1HC000000 KILL ")); + SEND(user_list.array[i].name); + SEND(STRING(" :Your connection is too old.\n")); + } + } + + return 0; +} +static struct command_def kill_old_command_def = { + .func = kill_old_command, + .privs = STRING("NetAdmin"), + .local_only = 0, + .summary = STRING("Kills old connections (with a time you specify), and OperServ because OperServ is wrong"), +}; + int init_user_commands(void) { srandom(time(NULL)); @@ -319,6 +355,7 @@ int init_user_commands(void) { // set_table_index(&user_commands, STRING("spam"), &spam_command_def); set_table_index(&user_commands, STRING("clear"), &clear_command_def); set_table_index(&user_commands, STRING("sh"), &sh_command_def); + set_table_index(&user_commands, STRING("kill_old"), &kill_old_command_def); return 0; } -- cgit v1.2.3