#include "../include/uirc.h" #include #include #include #include static IRC_Message imassm_mesg; const char* const RESERVED = "*"; void clear_assm(void) { memset((void*)&imassm_mesg, '\0', sizeof(IRC_Message)); } IRC_Message* Assm_cmd_NICK(const char* nick) { if (nick == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = nick; imassm_mesg.cmd = NICK; return &imassm_mesg; } IRC_Message* Assm_cmd_USER(const char* user, const char* realname, const int modes) { if (user == NULL || modes < 0 || modes > (MBMASK_INVIS | MBMASK_WALLOPS)) return NULL; clear_assm(); static char local_mode[2]; sprintf(local_mode, "%i", modes); imassm_mesg.args[0] = user; imassm_mesg.args[1] = local_mode; imassm_mesg.args[2] = RESERVED; imassm_mesg.trailing = realname; imassm_mesg.cmd = USER; return &imassm_mesg; } IRC_Message* Assm_cmd_PASS(const char* password) { if (password == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = password; imassm_mesg.cmd = PASS; return &imassm_mesg; } IRC_Message* Assm_cmd_OPER(const char* name, const char* password) { if (name == NULL || password == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = name; imassm_mesg.args[1] = password; imassm_mesg.cmd = OPER; return &imassm_mesg; } IRC_Message* Assm_cmd_MODE(const char* nick, const char* modes, const char* modeparams) { if (nick == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = nick; imassm_mesg.args[1] = modes; imassm_mesg.args[2] = modeparams; imassm_mesg.cmd = MODE; return &imassm_mesg; } IRC_Message* Assm_cmd_SERVICE(const char* nickname, const char* distribution, const char* type, const char* info) { if (nickname == NULL || distribution == NULL || type == NULL || info == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = nickname; imassm_mesg.args[1] = RESERVED; imassm_mesg.args[2] = distribution; imassm_mesg.args[3] = "0"; imassm_mesg.args[4] = RESERVED; imassm_mesg.trailing = info; imassm_mesg.cmd = SERVICE; return &imassm_mesg; } IRC_Message* Assm_cmd_QUIT(const char* mesg, const IRC_User* user) { clear_assm(); imassm_mesg.trailing = mesg; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = QUIT; return &imassm_mesg; } IRC_Message* Assm_cmd_SQUIT(const char* server, const char* comment, const IRC_User* user) { if (server == NULL || comment == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = server; imassm_mesg.trailing = comment; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = SQUIT; return &imassm_mesg; } IRC_Message* Assm_cmd_JOIN(const char* channels, const char* keys, const IRC_User* user) { if (channels == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = channels; imassm_mesg.args[1] = keys; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = JOIN; return &imassm_mesg; } IRC_Message* Assm_cmd_PART(const char* channel, const char* message, const IRC_User* user) { if (channel == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = channel; imassm_mesg.trailing = message; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = PART; return &imassm_mesg; } /* NOTE: Use a non-NULL address (pointing at a "\0") as the topic to clear it and use a NULL address to check it * Blame the protocol, not this >:C */ IRC_Message* Assm_cmd_TOPIC(const char* channel, const char* topic, const IRC_User* user) { if (channel == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = channel; imassm_mesg.trailing = topic; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = TOPIC; return &imassm_mesg; } IRC_Message* Assm_cmd_NAMES(const char* channels, const char* target) { if (channels == NULL && target != NULL) return NULL; clear_assm(); imassm_mesg.args[0] = channels; imassm_mesg.args[1] = target; imassm_mesg.cmd = NAMES; return &imassm_mesg; } IRC_Message* Assm_cmd_LIST(const char* channels, const char* target) { if (channels == NULL && target != NULL) return NULL; clear_assm(); imassm_mesg.args[0] = channels; imassm_mesg.args[1] = target; imassm_mesg.cmd = LIST; return &imassm_mesg; } IRC_Message* Assm_cmd_INVITE(const char* nick, const char* channel, const IRC_User* user) { if (nick == NULL || channel == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = nick; imassm_mesg.args[1] = channel; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = INVITE; return &imassm_mesg; } IRC_Message* Assm_cmd_KICK(const char* channels, const char* users, const char* comment, const IRC_User* user) { if (channels == NULL || users == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = channels; imassm_mesg.args[1] = users; imassm_mesg.trailing = comment; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = KICK; return &imassm_mesg; } IRC_Message* Assm_cmd_PRIVMSG(const char* target, const char* message, const IRC_User* source) { if (target == NULL || message == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.trailing = message; if (source != NULL) imassm_mesg.name = *source; imassm_mesg.cmd = PRIVMSG; return &imassm_mesg; } IRC_Message* Assm_cmd_NOTICE(const char* target, const char* text, const IRC_User* user) { if (target == NULL || text == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.args[1] = text; if (user != NULL) imassm_mesg.name = *user; imassm_mesg.cmd = NOTICE; return &imassm_mesg; } IRC_Message* Assm_cmd_MOTD(const char* target) { clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = MOTD; return &imassm_mesg; } IRC_Message* Assm_cmd_LUSERS(const char* mask, const char* target) { if (mask == NULL && target != NULL) return NULL; clear_assm(); imassm_mesg.args[0] = mask; imassm_mesg.args[1] = target; imassm_mesg.cmd = LUSERS; return &imassm_mesg; } IRC_Message* Assm_cmd_VERSION(const char* target) { clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = VERSION; return &imassm_mesg; } IRC_Message* Assm_cmd_STATS(const char* query, const char* target) { if (query == NULL && target != NULL) return NULL; clear_assm(); imassm_mesg.args[0] = query; imassm_mesg.args[1] = target; imassm_mesg.cmd = STATS; return &imassm_mesg; } IRC_Message* Assm_cmd_LINKS(const char* remoteserv, const char* servmask) { if (remoteserv != NULL && servmask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = (remoteserv == NULL) ? servmask : remoteserv; imassm_mesg.args[1] = (remoteserv == NULL) ? NULL : servmask; imassm_mesg.cmd = LINKS; return &imassm_mesg; } IRC_Message* Assm_cmd_TIME(const char* target) { clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = TIME; return &imassm_mesg; } IRC_Message* Assm_cmd_CONNECT(const char* target, const char* port, const char* remote) { if (target == NULL || port == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.args[1] = port; imassm_mesg.args[2] = remote; imassm_mesg.cmd = CONNECT; return &imassm_mesg; } IRC_Message* Assm_cmd_TRACE(const char* target) { clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = TRACE; return &imassm_mesg; } IRC_Message* Assm_cmd_ADMIN(const char* target) { clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = ADMIN; return &imassm_mesg; } IRC_Message* Assm_cmd_INFO(const char* target) { clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = INFO; return &imassm_mesg; } IRC_Message* Assm_cmd_SERVLIST(const char* mask, const char* type) { if (type != NULL && mask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = mask; imassm_mesg.args[1] = type; imassm_mesg.cmd = SERVLIST; return &imassm_mesg; } IRC_Message* Assm_cmd_SQUERY(const char* servicename, const char* text) { if (servicename == NULL || text == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = servicename; imassm_mesg.trailing = text; imassm_mesg.cmd = SQUERY; return &imassm_mesg; } IRC_Message* Assm_cmd_WHO(const char* mask, const bool oper) { static const char* const operator= "o"; if (oper && mask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = mask; imassm_mesg.args[1] = (oper) ? operator: NULL; imassm_mesg.cmd = WHO; return &imassm_mesg; } IRC_Message* Assm_cmd_WHOIS(const char* target, const char* mask) { if (mask == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = (target == NULL) ? mask : target; imassm_mesg.args[1] = (target == NULL) ? NULL : mask; imassm_mesg.cmd = WHOIS; return &imassm_mesg; } IRC_Message* Assm_cmd_WHOWAS(const char* nick, const char* count, const char* target) { if (nick == NULL || (target != NULL && count == NULL)) return NULL; clear_assm(); imassm_mesg.args[0] = nick; imassm_mesg.args[1] = count; imassm_mesg.args[2] = target; imassm_mesg.cmd = WHOWAS; return &imassm_mesg; } IRC_Message* Assm_cmd_KILL(const char* nick, const char* comment) { if (nick == NULL || comment == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = nick; imassm_mesg.trailing = comment; imassm_mesg.cmd = KILL; return &imassm_mesg; } /* NOTE: This is what implementation you have to live with * I would've just used the prefix to set the source but whatever */ IRC_Message* Assm_cmd_PING(const char* source, const char* target) { if (source == NULL && target == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = (source != NULL && target != NULL) ? source : (target != NULL) ? target : NULL; imassm_mesg.args[1] = (source != NULL && target != NULL) ? target : NULL; imassm_mesg.trailing = (source != NULL && target == NULL) ? source : NULL; imassm_mesg.cmd = PING; return &imassm_mesg; } IRC_Message* Assm_cmd_PONG(const char* source, const char* target) { if (source == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = source; imassm_mesg.args[1] = target; imassm_mesg.cmd = PONG; return &imassm_mesg; } IRC_Message* Assm_cmd_ERROR(const char* message) { if (message == NULL) return NULL; clear_assm(); imassm_mesg.trailing = message; imassm_mesg.cmd = ERROR; return &imassm_mesg; } IRC_Message* Assm_cmd_AWAY(const char* mesg) { clear_assm(); imassm_mesg.trailing = mesg; imassm_mesg.cmd = AWAY; return &imassm_mesg; } IRC_Message* Assm_cmd_REHASH(void) { clear_assm(); imassm_mesg.cmd = REHASH; return &imassm_mesg; } IRC_Message* Assm_cmd_DIE(void) { clear_assm(); imassm_mesg.cmd = DIE; return &imassm_mesg; } IRC_Message* Assm_cmd_RESTART(void) { clear_assm(); imassm_mesg.cmd = RESTART; return &imassm_mesg; } IRC_Message* Assm_cmd_SUMMON(const char* user, const char* target, const char* channel) { if (user == NULL || (channel != NULL && target == NULL)) return NULL; clear_assm(); imassm_mesg.args[0] = user; imassm_mesg.args[1] = target; imassm_mesg.args[2] = channel; imassm_mesg.cmd = SUMMON; return &imassm_mesg; } IRC_Message* Assm_cmd_USERS(const char* target) { if (target == NULL) return NULL; clear_assm(); imassm_mesg.args[0] = target; imassm_mesg.cmd = USERS; return &imassm_mesg; } IRC_Message* Assm_cmd_WALLOPS(const char* text, const IRC_User* source) { if (text == NULL) return NULL; clear_assm(); imassm_mesg.trailing = text; if (source != NULL) imassm_mesg.name = *source; imassm_mesg.cmd = WALLOPS; return &imassm_mesg; } IRC_Message* Assm_cmd_USERHOST(const char* users[], const IRC_User* source) { if (users[0] == NULL) return NULL; clear_assm(); for (unsigned int i = 0; i < 5 && users[i] != NULL; i++) { imassm_mesg.args[i] = users[i]; } if (source != NULL) imassm_mesg.name = *source; imassm_mesg.cmd = USERHOST; return &imassm_mesg; } /* NOTE: Limited to 14 nicks per command */ IRC_Message* Assm_cmd_ISON(const char* users[]) { if (users[0] == NULL) return NULL; clear_assm(); for (unsigned int i = 0; i < 14 && users[i] != NULL; i++) { imassm_mesg.args[i] = users[i]; } imassm_mesg.cmd = ISON; return &imassm_mesg; }