From 39cd7bb66c466ac504db3676ea196ee24540ab2c Mon Sep 17 00:00:00 2001
From: Test_User <hax@andrewyu.org>
Date: Mon, 21 Aug 2023 20:52:11 -0400
Subject: [PATCH] Tell command handlers if it's local

---
 client_network.c |  2 +-
 commands.c       | 12 ++++++------
 commands.h       |  2 +-
 server_network.c |  4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/client_network.c b/client_network.c
index 844be8f..11b7a19 100644
--- a/client_network.c
+++ b/client_network.c
@@ -448,7 +448,7 @@ int client_privmsg_handler(uint64_t argc, struct string *argv) {
 
 			privmsg(STRING("1HC000000"), log_channel, sizeof(message)/sizeof(*message), message);
 
-			return cmd->func(STRING("1HC000001"), argv[1], argv[0], command_argc, command_argv);
+			return cmd->func(STRING("1HC000001"), argv[1], argv[0], command_argc, command_argv, 1);
 		} else {
 			// TODO: complain about remote access
 			WRITES(1, STRING("Not executing local-only command from a remote source!\n"));
diff --git a/commands.c b/commands.c
index b379445..0aee0b1 100644
--- a/commands.c
+++ b/commands.c
@@ -42,7 +42,7 @@
 
 struct table user_commands = {0};
 
-int help_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+int help_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) {
 	for (uint64_t i = 0; i < user_commands.len; i++) {
 		struct command_def *def = user_commands.array[i].ptr;
 
@@ -65,7 +65,7 @@ static struct command_def help_command_def = {
 	.summary = STRING("Shows a list of commands, or, when I write it up, help about a specific command"),
 };
 
-int raw_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+int raw_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) {
 	if (argv[0].len < original_message.len) {
 		original_message.data += argv[0].len + 1;
 		original_message.len -= argv[0].len + 1;
@@ -100,7 +100,7 @@ static struct pref_type_suff {
 	{STRING(":1HC000000 PRIVMSG "), 0, STRING(" :You attempted to change into a cruxian navanax, but were caught in the act.\n")},
 };
 
-int sus_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+int sus_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) {
 	uint64_t index = (uint64_t)random() % (sizeof(sus_strings)/sizeof(sus_strings[0]));
 
 	SEND(sus_strings[index].pref);
@@ -119,7 +119,7 @@ static struct command_def sus_command_def = {
 	.summary = STRING("You seem a bit sus today"),
 };
 
-int cr_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+int cr_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local) {
 	uint64_t index = (uint64_t)random() % (sizeof(cr_strings)/sizeof(cr_strings[0]));
 
 	SEND(cr_strings[index].pref);
@@ -138,7 +138,7 @@ 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) {
+int spam_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;
@@ -146,7 +146,7 @@ int spam_command(struct string sender, struct string original_message, struct st
 
 	char err;
 	uint64_t count = str_to_unsigned(argv[2], &err);
-	if (err || count > MAX_SPAM_COUNT) {
+	if (err || (count > MAX_SPAM_COUNT && !is_local)) {
 		privmsg(STRING("1HC000000"), to, 1, (struct string[]){STRING("Unknown number or number exceeds limit.")});
 		return 0;
 	}
diff --git a/commands.h b/commands.h
index f8ef354..ed6952f 100644
--- a/commands.h
+++ b/commands.h
@@ -32,7 +32,7 @@
 #include "table.h"
 
 struct command_def {
-	int (*func)(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv);
+	int (*func)(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv, char is_local);
 	struct string privs;
 	struct string summary;
 	uint8_t local_only;
diff --git a/server_network.c b/server_network.c
index 72f41a3..1327916 100644
--- a/server_network.c
+++ b/server_network.c
@@ -769,7 +769,7 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) {
 
 			privmsg(STRING("1HC000000"), log_channel, sizeof(message)/sizeof(*message), message);
 
-			return cmd->func(sender, argv[1], argv[0], command_argc, command_argv);
+			return cmd->func(sender, argv[1], argv[0], command_argc, command_argv, 0);
 		} else {
 			// TODO: complain about remote access
 			WRITES(1, STRING("Not executing local-only command from a remote source!\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, 1) != 0)
+	if (add_local_client(STRING("1HC000000"), nick, hostmask, nick, nick, current_time, 0) != 0)
 		return 1;
 
 	for (uint64_t i = 0; i < num_prejoin_channels; i++) {