diff options
author | Test_User <hax@andrewyu.org> | 2023-08-21 20:36:12 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2023-08-21 20:36:12 -0400 |
commit | 01a37d3dd71843f4edefb68e67c28094a9133ca5 (patch) | |
tree | 79f76fb21983b53458a25d288ce98d6b27d50f0b /commands.c | |
parent | a044933f3eca3572c082c8f99e0c20d32e6d1ac2 (diff) | |
download | c_coupserv-01a37d3dd71843f4edefb68e67c28094a9133ca5.tar.gz c_coupserv-01a37d3dd71843f4edefb68e67c28094a9133ca5.zip |
spam command added
Diffstat (limited to 'commands.c')
-rw-r--r-- | commands.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -36,6 +36,9 @@ #include "network.h" #include "tls.h" #include "config.h" +#include "utils.h" + +#define MAX_SPAM_COUNT 65536 struct table user_commands = {0}; @@ -135,6 +138,51 @@ static struct command_def cr_command_def = { .summary = STRING("Join the crux side"), }; +int spam_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) { + 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); + if (err || count > MAX_SPAM_COUNT) { + privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Unknown number or number exceeds limit.")}); + 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 >= 3 && !wasspace) + break; + } + + if (found < 3) { + WRITES(2, STRING("WARNING: Apparently there was no third argument... shouldn't happen.\n")); + return 0; + } + + struct string message[] = {{.data = original_message.data + offset, .len = original_message.len - offset}}; + + for (uint64_t i = 0; i < count; i++) + privmsg(STRING("1HC000000"), argv[1], 1, message); + + return 0; +} +static struct command_def spam_command_def = { + .func = spam_command, + .privs = STRING("NetAdmin"), + .local_only = 0, + .summary = STRING("Repeats a message to a target <n> times"), +}; + int init_user_commands(void) { srandom(time(NULL)); @@ -144,6 +192,7 @@ 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); return 0; } |