diff options
author | Test_User <hax@andrewyu.org> | 2024-04-30 04:55:03 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-04-30 04:55:03 -0400 |
commit | 4a864ccb247fa97b026e3ca372baa03114883f00 (patch) | |
tree | e6fef10d16cc6e8c209ff56a1afa953812d553ce /commands.c | |
parent | 7fb084ec64d7770928a13efe77797caddd4fb885 (diff) | |
download | coupserv-4a864ccb247fa97b026e3ca372baa03114883f00.tar.gz coupserv-4a864ccb247fa97b026e3ca372baa03114883f00.zip |
OperServ was wrong.
Diffstat (limited to '')
-rw-r--r-- | commands.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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; } |