From b83aba4ac6b3d428e4988f56f82999bea81e6c57 Mon Sep 17 00:00:00 2001 From: Test_User Date: Mon, 6 May 2024 20:27:55 -0400 Subject: Replace spam with a spam , add tell to replace old spam function (when used with the new spam) --- commands.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/commands.c b/commands.c index c3f236b..6ee3182 100644 --- a/commands.c +++ b/commands.c @@ -140,13 +140,13 @@ static struct command_def cr_command_def = { }; int spam_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) { - if (argc < 4) { + if (argc < 3) { privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Missing args!")}); return 0; } char err; - uint64_t count = str_to_unsigned(argv[2], &err); + uint64_t count = str_to_unsigned(argv[1], &err); if (err || (count > MAX_SPAM_COUNT && !is_local)) { privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Unknown number or number exceeds limit.")}); return 0; @@ -161,19 +161,48 @@ int spam_command(struct string sender, struct string original_message, struct st wasspace = (original_message.data[offset] == ' '); - if (found >= 3 && !wasspace) + if (found >= 2 && !wasspace) break; } - if (found < 3) { - WRITES(2, STRING("WARNING: Apparently there was no third argument... shouldn't happen.\n")); + if (found < 2) { + WRITES(2, STRING("WARNING: Apparently there was no second argument... shouldn't happen.\n")); return 0; } - struct string message[] = {{.data = original_message.data + offset, .len = original_message.len - offset}}; + struct command_def *cmd = get_table_index(user_commands, argv[2]); + if (cmd) { + if (!cmd->local_only) { + if (cmd->privs.len != 0 && sender.len != 3) { + struct user_info *user = get_table_index(user_list, sender); + if (!user) + return 1; // really shouldn't happen + if (!STRING_EQ(user->opertype, cmd->privs)) { + SEND(STRING(":1HC000000 NOTICE ")); + SEND(to); + SEND(STRING(" :You are not authorized to execute that command.\n")); + + return 0; + } + } + } else { + SEND(STRING(":1HC000000 NOTICE ")); + SEND(to); + SEND(STRING(" :Spamming of local-only commands is disabled.\n")); + + return 0; + } + } - for (uint64_t i = 0; i < count; i++) - privmsg(STRING("1HC000000"), argv[1], 1, message); + struct string fake_original_message = {.data = original_message.data + offset, .len = original_message.len - offset}; + WRITES(2, fake_original_message); + WRITES(2, STRING("\n")); + + for (uint64_t i = 0; i < count; i++) { + int ret = cmd->func(sender, fake_original_message, to, argc - 2, &(argv[2]), 0); + if (ret) + return ret; + } return 0; } @@ -181,7 +210,7 @@ static struct command_def spam_command_def = { .func = spam_command, .privs = STRING("NetAdmin"), .local_only = 0, - .summary = STRING("Repeats a message to a target times"), + .summary = STRING("Repeats a command times"), }; int clear_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) { @@ -379,6 +408,42 @@ static struct command_def echo_command_def = { .summary = STRING("Repeats a message back"), }; +int tell_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) { + if (argc < 3) { + privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Missing args!")}); + return 0; + } + + char wasspace = 1; + uint64_t offset = 0; + char found = 0; + for (; offset < original_message.len; offset++) { + if (original_message.data[offset] == ' ' && !wasspace) + found++; + + wasspace = (original_message.data[offset] == ' '); + + if (found >= 2 && !wasspace) + break; + } + + if (found < 2) { + WRITES(2, STRING("WARNING: Apparently there was no second argument... shouldn't happen.\n")); + return 0; + } + + struct string message[] = {{.data = original_message.data + offset, .len = original_message.len - offset}}; + privmsg(STRING("1HC000000"), argv[1], 1, message); + + return 0; +} +static struct command_def tell_command_def = { + .func = tell_command, + .privs = STRING("NetAdmin"), + .local_only = 0, + .summary = STRING("Sends a message to a target"), +}; + int init_user_commands(void) { srandom(time(NULL)); @@ -388,11 +453,12 @@ int init_user_commands(void) { set_table_index(&user_commands, STRING("sus"), &sus_command_def); set_table_index(&user_commands, STRING("cr"), &cr_command_def); set_table_index(&user_commands, STRING("help"), &help_command_def); -// set_table_index(&user_commands, STRING("spam"), &spam_command_def); + 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); set_table_index(&user_commands, STRING("echo"), &echo_command_def); + set_table_index(&user_commands, STRING("tell"), &tell_command_def); return 0; } -- cgit v1.2.3