ircd/irc_std.hpp
#ifndef IRC_STD_HPP_
#define IRC_STD_HPP_
#include "client.hpp"
#include "common.hpp"
// :<server>[ code] <nick|*>[ ...]
bool srv_reply_msg(Client* dst, const char* code, const char* msg, size_t len);
bool srv_reply_fmt(Client* dst, const char* code, const char* fmt, ...) PRINTF_FMT(3, 4);
// :<nick!user@host>[ ...]
bool cli_reply_msg(Client* dst, const Client* nick, const char* msg, size_t len);
bool cli_reply_fmt(Client* dst, const Client* nick, const char* fmt, ...) PRINTF_FMT(3, 4);
// ...
bool raw_reply_msg(Client* dst, const char* msg, size_t len);
bool raw_reply_fmt(Client* dst, const char* fmt, ...) PRINTF_FMT(2, 3);
// for splittable suffixes that should not fail in case of too long prefixes, i.e. PRIVMSGs
bool raw_reply_fmt_long(Client* dst, const char* msg, const char* fmt, ...) PRINTF_FMT(3, 4);
// for convenience/typos
#define REPLYMSG(r) r, r##_MSG, sizeof(r##_MSG)-1
#define REPLYFMT(r) r, r##_MSG_FMT
// https://tools.ietf.org/html/rfc2812
#define RPL_WELCOME "001"
#define RPL_WELCOME_MSG ":- Welcome to the Interweb Relay Networks"
#define RPL_AWAY "301"
//#define RPL_AWAY_MSG "<nick> :<away message>"
#define RPL_AWAY_MSG_FMT "%s :%s"
#define RPL_UNAWAY "305"
#define RPL_UNAWAY_MSG ":You are no longer marked as being away"
#define RPL_NOWAWAY "306"
#define RPL_NOWAWAY_MSG ":You have been marked as being away"
#define RPL_LISTSTART "321"
#define RPL_LISTSTART_MSG "Channel :Users Name"
#define RPL_LIST "322"
//#define RPL_LIST_MSG "<channel> <# visible> :<topic>"
#define RPL_LIST_MSG_FMT "%s %zu :%s"
#define RPL_LISTEND "323"
#define RPL_LISTEND_MSG ":End of LIST"
#define RPL_CHANNELMODEIS "324"
//#define RPL_CHANNELMODEIS_MSG "<channel> <mode> <mode params>"
#define RPL_CHANNELMODEIS_MSG_FMT "%s %s"
#define RPL_TOPIC "332"
//#define RPL_TOPIC_MSG "<channel> :<topic>"
#define RPL_TOPIC_MSG_FMT "%s :%s"
#define RPL_WHOREPLY "352"
//#define RPL_WHOREPLY_MSG "<channel> [~]<user> <host> <server> <nick> ( \"H\" / \"G\" > [\"*\"] [ ( \"@\" / \"+\" ) ] :<hopcount> <real name>"
#define RPL_WHOREPLY_MSG_FMT "%s %s%s %s %s %s %c%s :0 %s"
#define RPL_ENDOFWHO "315"
//#define RPL_ENDOFWHO_MSG "<name> :End of WHO list"
#define RPL_ENDOFWHO_MSG_FMT "%s :End of WHO list"
#define RPL_NAMREPLY "353"
//#define RPL_NAMREPLY_MSG "( \"=\" / \"*\" / \"@\" ) <channel> :[ \"@\" / \"+\" ] <nick> *( \" \" [ \"@\" / \"+\" ] <nick> )"
#define RPL_NAMREPLY_MSG_FMT "= %s :%s%s"
#define RPL_ENDOFNAMES "366"
//#define RPL_ENDOFNAMES_MSG "<channel> :End of NAMES list"
#define RPL_ENDOFNAMES_MSG_FMT "%s :End of NAMES list"
#define RPL_MOTDSTART "375"
#define RPL_MOTDSTART_MSG ":- Message of the day:"
#define RPL_MOTD "372"
//#define RPL_MOTD_MSG ":- <text>"
#define RPL_ENDOFMOTD "376"
#define RPL_ENDOFMOTD_MSG ":- End of MOTD."
#define RPL_YOUREOPER "381"
#define RPL_YOUREOPER_MSG ":You are now an IRC operator"
#define ERR_NOSUCHNICK "401"
//#define ERR_NOSUCHNICK_MSG "<nickname> :No such nick/channel"
#define ERR_NOSUCHNICK_MSG_FMT "%s :No such nick/channel"
#define ERR_NOSUCHCHANNEL "403"
//#define ERR_NOSUCHCHANNEL_MSG "<channel_name> :No such channel"
#define ERR_NOSUCHCHANNEL_MSG_FMT "%s :No such channel"
#define ERR_CANNOTSENDTOCHAN "404"
//#define ERR_CANNOTSENDTOCHAN_MSG "<channel_name> :Cannot send to channel"
#define ERR_CANNOTSENDTOCHAN_MSG_FMT "%s :Cannot send to channel"
#define ERR_TOOMANYCHANNELS "405"
//#define ERR_TOOMANYCHANNELS_MSG "<channel name> :You have joined too many channels"
#define ERR_TOOMANYCHANNELS_MSG_FMT "%s :You have joined too many channels"
#define ERR_INVALIDCAPCMD "410"
#define ERR_INVALIDCAPCMD_MSG ":Invalid CAP subcommand"
#define ERR_UNKNOWNCOMMAND "421"
//#define ERR_UNKNOWNCOMMAND_MSG "<command> :Unknown command"
#define ERR_UNKNOWNCOMMAND_MSG_FMT "%s :Unknown command"
#define ERR_NONICKNAMEGIVEN "431"
#define ERR_NONICKNAMEGIVEN_MSG ":No nickname given"
#define ERR_ERRONEUSNICKNAME "432"
//#define ERR_ERRONEUSNICKNAME_MSG "<nick> :Erroneous nickname"
#define ERR_ERRONEUSNICKNAME_MSG_FMT "%s :Erroneous nickname"
#define ERR_NICKNAMEINUSE "433"
//#define ERR_NICKNAMEINUSE_MSG "<nick> :Nickname is already in use"
#define ERR_NICKNAMEINUSE_MSG_FMT "%s :Nickname is already in use"
#define ERR_NOTONCHANNEL "442"
//#define ERR_NOTONCHANNEL_MSG "<channel> :You're not on that channel"
#define ERR_NOTONCHANNEL_MSG_FMT "%s :You're not on that channel"
#define ERR_NOTREGISTERED "451"
//#define ERR_NOTREGISTERED_MSG ":You have not registered"
#define ERR_NOTREGISTERED_MSG_FMT ":You have not registered (%s)"
#define ERR_NEEDMOREPARAMS "461"
//#define ERR_NEEDMOREPARAMS_MSG "<command> :Not enough parameters"
#define ERR_NEEDMOREPARAMS_MSG_FMT "%s :Not enough parameters"
#define ERR_ALREADYREGISTRED "462"
#define ERR_ALREADYREGISTRED_MSG ":Unauthorized command (already registered)"
#define ERR_PASSWDMISMATCH "464"
#define ERR_PASSWDMISMATCH_MSG ":Password incorrect"
#define ERR_INVITEONLYCHAN "473"
//#define ERR_INVITEONLYCHAN_MSG "<channel> :Cannot join channel (+i)"
#define ERR_INVITEONLYCHAN_MSG_FMT "%s :Cannot join channel (%s)"
#define ERR_CHANOPRIVSNEEDED "482"
//#define ERR_CHANOPRIVSNEEDED_MSG "<channel> :You're not channel operator"
#define ERR_CHANOPRIVSNEEDED_MSG_FMT "%s :You're not channel operator"
#define ERR_UMODEUNKNOWNFLAG "501"
#define ERR_UMODEUNKNOWNFLAG_MSG ":Unknown MODE flag"
#endif