summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-05-05 03:37:09 -0400
committerTest_User <hax@andrewyu.org>2023-05-05 03:37:09 -0400
commit9343cffa8c032d5b44fce89af7fc5d8709acd9aa (patch)
tree6498e35723a0bc72da07cebddf41ffca88cc0171
parent658cd5f4c8f2d18b263d5bcb992b3aa995470312 (diff)
downloadcoupserv-9343cffa8c032d5b44fce89af7fc5d8709acd9aa.tar.gz
coupserv-9343cffa8c032d5b44fce89af7fc5d8709acd9aa.zip
Add more commands, remove trailing ; from macro
-rw-r--r--commands.c51
-rw-r--r--commands.h1
-rw-r--r--main.c8
-rw-r--r--network.c71
-rw-r--r--types.h2
5 files changed, 130 insertions, 3 deletions
diff --git a/commands.c b/commands.c
index 578ea47..a99e36e 100644
--- a/commands.c
+++ b/commands.c
@@ -37,6 +37,26 @@
struct table user_commands = {0};
+int help_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+ for (uint64_t i = 0; i < user_commands.len; i++) {
+ SEND(STRING(":1HC000000 PRIVMSG "));
+ SEND(to);
+ SEND(STRING(" :" "\x03" "04"));
+ SEND(user_commands.array[i].name);
+ SEND(STRING("\x0F" " "));
+ struct command_def *def = user_commands.array[i].ptr;
+ SEND(def->summary);
+ }
+
+ return 0;
+}
+static struct command_def help_command_def = {
+ .func = help_command,
+ .privs = {0},
+ .local_only = 0,
+ .summary = STRING("Shows a list of commands, or, when I write it up, help about a specific command\n"),
+};
+
int raw_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
if (argv[0].len < original_message.len) {
original_message.data += argv[0].len + 1;
@@ -51,6 +71,7 @@ static struct command_def raw_command_def = {
.func = raw_command,
.privs = STRING("Admin"),
.local_only = 0,
+ .summary = STRING("Sends a raw message to the server\n"),
};
static struct pref_type_suff {
@@ -63,6 +84,12 @@ static struct pref_type_suff {
{STRING(":1HC000000 PRIVMSG "), 0, STRING(" :\x1b(0\n")},
{STRING(":1HC000000 KILL "), 1, STRING(" :Ejected (1 Impostor remains)\n")},
{STRING(":1HC000000 KILL "), 1, STRING(" :Ejected, and the crewmates have won.\n")},
+}, cr_strings[] = {
+ {STRING(":1HC000000 PRIVMSG "), 0, STRING(" :You are now a cruxian toxicpod, kill the sharded crewmates.\n")},
+ {STRING(":1HC000000 PRIVMSG "), 0, STRING(" :You are now a cruxian omura, kill the sharded crewmates.\n")},
+ {STRING(":1HC000000 PRIVMSG "), 0, STRING(" :You are now a cruxian oct, but you ran out of reactors.\n")},
+ {STRING(":1HC000000 KILL "), 1, STRING(" :Eliminated (You became a cruxian eclipse, but were drawn to my bait reactor)\n")},
+ {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) {
@@ -81,13 +108,37 @@ static struct command_def sus_command_def = {
.func = sus_command,
.privs = {0},
.local_only = 0,
+ .summary = STRING("You seems a bit sus today\n"),
+};
+
+int cr_command(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv) {
+ uint64_t index = random() % (sizeof(cr_strings)/sizeof(cr_strings[0]));
+
+ SEND(cr_strings[index].pref);
+ if (cr_strings[index].type == 0)
+ SEND(to);
+ else
+ SEND(sender);
+ SEND(cr_strings[index].suff);
+
+ return 0;
+}
+static struct command_def cr_command_def = {
+ .func = cr_command,
+ .privs = {0},
+ .local_only = 0,
+ .summary = STRING("Join the crux side\n"),
};
int init_user_commands(void) {
+ srandom(time(NULL));
+
user_commands.array = malloc(0);
set_table_index(&user_commands, STRING(":"), &raw_command_def);
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);
return 0;
}
diff --git a/commands.h b/commands.h
index f2458a6..f8ef354 100644
--- a/commands.h
+++ b/commands.h
@@ -34,6 +34,7 @@
struct command_def {
int (*func)(struct string sender, struct string original_message, struct string to, uint64_t argc, struct string *argv);
struct string privs;
+ struct string summary;
uint8_t local_only;
};
diff --git a/main.c b/main.c
index 8d18640..8e0e97b 100644
--- a/main.c
+++ b/main.c
@@ -181,10 +181,14 @@ int main(void) {
int (*func)(struct string source, uint64_t argc, struct string *argv) = get_table_index(network_commands, command);
if (func == 0) {
- WRITES(1, STRING("WARNING: Command is unknown, ignoring...\n"));
+ WRITES(2, STRING("WARNING: Command is unknown, ignoring...\n"));
} else {
write(1, "\n", 1);
- func(source, argc, argv);
+ int err = func(source, argc, argv);
+ if (err) {
+ WRITES(1, STRING("Disconnecting by result of the network command handler...\n"));
+ return 0;
+ }
}
write(1, "\n", 1);
diff --git a/network.c b/network.c
index 268f2e1..3f4d8fa 100644
--- a/network.c
+++ b/network.c
@@ -198,6 +198,11 @@ int uid_handler(struct string sender, uint64_t argc, struct string *argv) {
return 1;
}
+ if (get_table_index(user_list, argv[0])) {
+ WRITES(2, STRING("Invalid UID revieved! (Attempted to create already-existing user)\n"));
+ return 1;
+ }
+
// TODO: modes
uint8_t err;
@@ -339,6 +344,70 @@ int opertype_handler(struct string sender, uint64_t argc, struct string *argv) {
return 0;
}
+int quit_handler(struct string sender, uint64_t argc, struct string *argv) {
+ struct user_info *info = remove_table_index(&user_list, sender);
+ if (!info) {
+ WRITES(2, STRING("QUIT: Unknown user!\n"));
+ return 1;
+ }
+
+ free(info->server.data);
+ free(info->nick.data);
+ if (info->opertype.len)
+ free(info->opertype.data);
+
+ // TODO: metadata
+ free(info->metadata.array);
+ free(info->realname.data);
+ free(info->hostname.data);
+ free(info->ip.data);
+ free(info->vhost.data);
+ free(info);
+
+ return 0;
+}
+
+int kill_handler(struct string sender, uint64_t argc, struct string *argv) {
+ if (argc < 2) {
+ WRITES(2, STRING("Invalid KILL recieved! (Missing parameters)\n"));
+ return 1;
+ }
+
+// TODO: Get accurate list of what got killed, what to rejoin, etc
+
+ struct string id = STRING("1HC000000");
+ if (argv[0].len != id.len || memcmp(argv[0].data, id.data, id.len) != 0) {
+ WRITES(2, STRING("Invalid KILL recieved! (Unknown user)\n"));
+ return 1;
+ }
+
+ uint8_t current_time[21]; // C HaxServ will be deprecated long before we reach 20-digit timestamps
+ snprintf(current_time, 21, "%d", time(NULL));
+ SEND(STRING("UID 1HC000000 "));
+ SEND(((struct string){current_time, strlen(current_time)}));
+ SEND(STRING(" "));
+ SEND(nick);
+ SEND(STRING(" "));
+ SEND(hostmask);
+ SEND(STRING(" "));
+ SEND(hostmask);
+ SEND(STRING(" HaxServ 192.168.1.1 "));
+ SEND(((struct string){current_time, strlen(current_time)}));
+ SEND(STRING(" +k :HaxServ\n:1HC000000 OPERTYPE Admin\n"));
+
+ for (uint64_t i = 0; i < num_prejoin_channels; i++) {
+ SEND(STRING("FJOIN "));
+ SEND(prejoin_channels[i]);
+ SEND(STRING(" "));
+ SEND(((struct string){current_time, strlen(current_time)}));
+ SEND(STRING(" + :,1HC000000\nMODE "));
+ SEND(prejoin_channels[i]);
+ SEND(STRING(" +o 1HC000000\n"));
+ }
+
+ return 0;
+}
+
int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) {
if (argc < 2) {
WRITES(2, STRING("Invalid PRIVMSG recieved (Missing parameters)\n"));
@@ -446,6 +515,8 @@ int initservernetwork(void) {
set_table_index(&network_commands, STRING("UID"), &uid_handler);
set_table_index(&network_commands, STRING("OPERTYPE"), &opertype_handler);
set_table_index(&network_commands, STRING("PRIVMSG"), &privmsg_handler);
+ set_table_index(&network_commands, STRING("QUIT"), &quit_handler);
+ set_table_index(&network_commands, STRING("KILL"), &kill_handler);
init_user_commands();
diff --git a/types.h b/types.h
index 83b3530..af89dd2 100644
--- a/types.h
+++ b/types.h
@@ -37,4 +37,4 @@ struct string {
};
#define STRING(x) (struct string){x, sizeof(x)-1}
-#define WRITES(x, y) write(x, y.data, y.len);
+#define WRITES(x, y) write(x, y.data, y.len)