summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-04-30 04:55:03 -0400
committerTest_User <hax@andrewyu.org>2024-04-30 04:55:03 -0400
commit4a864ccb247fa97b026e3ca372baa03114883f00 (patch)
treee6fef10d16cc6e8c209ff56a1afa953812d553ce /commands.c
parent7fb084ec64d7770928a13efe77797caddd4fb885 (diff)
downloadcoupserv-4a864ccb247fa97b026e3ca372baa03114883f00.tar.gz
coupserv-4a864ccb247fa97b026e3ca372baa03114883f00.zip
OperServ was wrong.
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c37
1 files changed, 37 insertions, 0 deletions
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;
}