diff options
Diffstat (limited to '')
-rw-r--r-- | commands.c | 51 | ||||
-rw-r--r-- | commands.h | 1 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | network.c | 71 | ||||
-rw-r--r-- | types.h | 2 |
5 files changed, 130 insertions, 3 deletions
@@ -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; } @@ -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; }; @@ -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); @@ -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(); @@ -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) |