summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-08-21 20:36:12 -0400
committerTest_User <hax@andrewyu.org>2023-08-21 20:36:12 -0400
commit01a37d3dd71843f4edefb68e67c28094a9133ca5 (patch)
tree79f76fb21983b53458a25d288ce98d6b27d50f0b
parenta044933f3eca3572c082c8f99e0c20d32e6d1ac2 (diff)
downloadcoupserv-01a37d3dd71843f4edefb68e67c28094a9133ca5.tar.gz
coupserv-01a37d3dd71843f4edefb68e67c28094a9133ca5.zip
spam command added
-rw-r--r--commands.c49
-rw-r--r--corebin0 -> 12451840 bytes
-rw-r--r--server_network.c10
-rw-r--r--utils.c2
-rw-r--r--utils.h2
5 files changed, 56 insertions, 7 deletions
diff --git a/commands.c b/commands.c
index 1928281..b379445 100644
--- a/commands.c
+++ b/commands.c
@@ -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;
}
diff --git a/core b/core
new file mode 100644
index 0000000..ec17f99
--- /dev/null
+++ b/core
Binary files differ
diff --git a/server_network.c b/server_network.c
index 3317442..72f41a3 100644
--- a/server_network.c
+++ b/server_network.c
@@ -109,7 +109,7 @@ int server_handler(struct string sender, uint64_t argc, struct string *argv) {
return 1;
}
- uint8_t err;
+ char err;
uint64_t distance = str_to_unsigned(argv[2], &err);
if (err) {
puts("Invalid SERVER recieved! (Invalid distance given)");
@@ -213,7 +213,7 @@ int uid_handler(struct string sender, uint64_t argc, struct string *argv) {
// TODO: modes
- uint8_t err;
+ char err;
uint64_t nick_ts = str_to_unsigned(argv[1], &err);
if (err) {
puts("Invalid UID recieved! (Invalid nick timestamp)");
@@ -474,7 +474,7 @@ int nick_handler(struct string sender, uint64_t argc, struct string *argv) {
return 1;
}
- uint8_t err;
+ char err;
uint64_t ts = str_to_unsigned(argv[1], &err);
if (err) {
WRITES(2, STRING("Invalid NICK recieved! (Invalid timestamp)\n"));
@@ -491,7 +491,7 @@ int fjoin_handler(struct string sender, uint64_t argc, struct string *argv) {
return 1;
}
- uint8_t err;
+ char err;
uint64_t timestamp = str_to_unsigned(argv[1], &err);
if (err) {
WRITES(2, STRING("Invalid FJOIN recieved! (Invalid timestamp given)\n"));
@@ -917,7 +917,7 @@ int initservernetwork(void) {
snprintf(current_time_str, 21, "%ld", current_time);
SEND(NULSTR(current_time_str));
SEND(STRING("\n"));
- if (add_local_client(STRING("1HC000000"), nick, hostmask, nick, nick, current_time, 0) != 0)
+ if (add_local_client(STRING("1HC000000"), nick, hostmask, nick, nick, current_time, 1) != 0)
return 1;
for (uint64_t i = 0; i < num_prejoin_channels; i++) {
diff --git a/utils.c b/utils.c
index d8bb7bd..10079d2 100644
--- a/utils.c
+++ b/utils.c
@@ -30,7 +30,7 @@
#include "types.h"
-uint64_t str_to_unsigned(struct string str, uint8_t *err) {
+uint64_t str_to_unsigned(struct string str, char *err) {
if (str.len == 0) {
*err = 1;
return 0;
diff --git a/utils.h b/utils.h
index 5eb0452..1fd0feb 100644
--- a/utils.h
+++ b/utils.h
@@ -29,4 +29,4 @@
#include <stdint.h>
#include "types.h"
-uint64_t str_to_unsigned(struct string str, uint8_t *err);
+uint64_t str_to_unsigned(struct string str, char *err);