From: Egor Date: Sun, 8 Feb 2026 23:20:01 +0000 (+0200) Subject: ircfmt: declutter messages X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=aa2d0a5c5d963935910883b6be795d096bee21bd;p=patchyircd.git ircfmt: declutter messages also fix monitor replies --- diff --git a/src/irc.cpp b/src/irc.cpp index 4b1f393..a9e4009 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -1369,7 +1369,7 @@ void setNick(Client *client, char* nickname) { updateNuh(client); client->key = mystrdup(key); client_map.insert(client); - rpl_mononline(0, client), sendbuf_monitor(client->key, 0, 0, 0); + rpl_mononline(nullptr, client), sendbuf_monitor(client->key, 0, 0, 0); } /* changes username, hostname or both * NULL means no change. additionally username can be client->username+1 diff --git a/src/ircfmt.cpp b/src/ircfmt.cpp index 6971ce1..296b2b2 100644 --- a/src/ircfmt.cpp +++ b/src/ircfmt.cpp @@ -3,10 +3,14 @@ #include "common.hpp" #include "ircfmt.hpp" #define WANT_UNUSED 0 -#define num_reply_to(num, nick, ...) (copy_strf(&databuf, ":%s " #num " %s", hostname, nick), append_strf(&databuf, __VA_ARGS__)) -#define num_reply(num, ...) num_reply_to(num, client->nick, __VA_ARGS__) -#define num_reply_check_nick(num, ...) num_reply_to(num, client->nick ? client->nick : "*", __VA_ARGS__) -#define num_reply_anon(num, ...) num_reply_to(num, "*", __VA_ARGS__) +#define num_reply_to(num, nick, fmt, ...) copy_strf(&databuf, ":%s " #num " %s" fmt, hostname, nick __VA_OPT__(,) __VA_ARGS__) +#define num_reply(num, fmt, ...) num_reply_to(num, client->nick, fmt __VA_OPT__(,) __VA_ARGS__) +#define num_reply_check_nick(num, fmt, ...) num_reply_to(num, client->nick ? client->nick : "*", fmt __VA_OPT__(,) __VA_ARGS__) +#define num_reply_check_client(num, fmt, ...) num_reply_to(num, client ? client->nick : "*", fmt __VA_OPT__(,) __VA_ARGS__) +#define num_reply_anon(num, fmt, ...) num_reply_to(num, "*", fmt __VA_OPT__(,) __VA_ARGS__) +#define msg_from(src, fmt, ...) copy_strf(&databuf, ":%s " fmt, src __VA_OPT__(,) __VA_ARGS__) +#define msg_from_server(fmt, ...) msg_from(hostname, fmt __VA_OPT__(,) __VA_ARGS__) +#define msg_from_client(fmt, ...) copy_strf(&databuf, ":%s!%s@%s " fmt, src->nick, src->username, src->hostname __VA_OPT__(,) __VA_ARGS__) static const char *format_prefixes(Client *client, Client *cl, Channel *chan) { if (!chan) return ""; bool o = chan->is_op(cl); @@ -21,124 +25,80 @@ static const char *format_prefixes(Client *client, Client *cl, Channel *chan) { return ""; } -void msg_away(Client *src) -{ +void msg_away(Client *src) { if (src->away) - copy_strf(&databuf, ":%s!%s@%s AWAY :%s\r\n", - src->nick, src->username, src->hostname, src->away); + msg_from_client("AWAY :%s\r\n", src->away); else - copy_strf(&databuf, ":%s!%s@%s AWAY\r\n", - src->nick, src->username, src->hostname); + msg_from_client("AWAY\r\n"); } -void msg_nick(Client *src, const char *newnick) -{ - copy_strf(&databuf, ":%s!%s@%s NICK %s\r\n", - src->nick, src->username, src->hostname, - newnick); +void msg_nick(Client *src, const char *newnick) { + msg_from_client("NICK %s\r\n", newnick); } #if WANT_UNUSED -void msg_ping(const char *token) -{ - copy_strf(&databuf, ":%s PING :%s\r\n", hostname, token); +void msg_ping(const char *token) { + msg_from_server("PING :%s\r\n", token); } #endif -void msg_pong(const char *token) -{ - copy_strf(&databuf, ":%s PONG %s :%s\r\n", hostname, hostname, token); -} -void msg_quit(Client *src, const char *prefix, const char *reason) -{ - copy_strf(&databuf, ":%s!%s@%s QUIT :%s%s\r\n", - src->nick, src->username, src->hostname, prefix, reason); -} -void msg_error(const char *reason) -{ - copy_strf(&databuf, ":%s ERROR :%s\r\n", hostname, reason); -} -void msg_join(Client *src, Channel *chan) -{ - copy_strf(&databuf, ":%s!%s@%s JOIN %s\r\n", - src->nick, src->username, src->hostname, chan->name); -} -void msg_join_extended(Client *src, Channel *chan) -{ - copy_strf(&databuf, ":%s!%s@%s JOIN %s %s :%s\r\n", - src->nick, src->username, src->hostname, chan->name, +void msg_pong(const char *token) { + msg_from_server("PONG %s :%s\r\n", hostname, token); +} +void msg_quit(Client *src, const char *prefix, const char *reason) { + msg_from_client("QUIT :%s%s\r\n", prefix, reason); +} +void msg_error(const char *reason) { + msg_from_server("ERROR :%s\r\n", reason); +} +void msg_join(Client *src, Channel *chan) { + msg_from_client("JOIN %s\r\n", chan->name); +} +void msg_join_extended(Client *src, Channel *chan) { + msg_from_client("JOIN %s %s :%s\r\n", chan->name, src->umode & UMODE_REGISTERED ? src->username : "*", src->realname); } -void msg_part(Client *src, Channel *chan, const char *reason) -{ +void msg_part(Client *src, Channel *chan, const char *reason) { if (reason) - copy_strf(&databuf, ":%s!%s@%s PART %s :%s\r\n", - src->nick, src->username, src->hostname, chan->name, reason); + msg_from_client("PART %s :%s\r\n", chan->name, reason); else - copy_strf(&databuf, ":%s!%s@%s PART %s\r\n", - src->nick, src->username, src->hostname, chan->name); -} -void msg_topic(Client *src, Channel *chan) -{ - copy_strf(&databuf, ":%s!%s@%s TOPIC %s :%s\r\n", - src->nick, src->username, src->hostname, - chan->name, chan->topic ? chan->topic : ""); -} -void msg_invite(Client *src, Client *dst, Channel *chan) -{ - copy_strf(&databuf, ":%s!%s@%s INVITE %s %s\r\n", - src->nick, src->username, src->hostname, dst->nick, chan->name); -} -void msg_kick(Client *src, Client *who, Channel *chan, const char *reason) -{ + msg_from_client("PART %s\r\n", chan->name); +} +void msg_topic(Client *src, Channel *chan) { + msg_from_client("TOPIC %s\r\n", chan->name, chan->topic ? chan->topic : ""); +} +void msg_invite(Client *src, Client *dst, Channel *chan) { + msg_from_client("INVITE %s %s\r\n", dst->nick, chan->name); +} +void msg_kick(Client *src, Client *who, Channel *chan, const char *reason) { if (reason) - copy_strf(&databuf, ":%s!%s@%s KICK %s %s :%s\r\n", - src->nick, src->username, src->hostname, chan->name, who->nick, reason); + msg_from_client("KICK %s %s :%s\r\n", chan->name, who->nick, reason); else - copy_strf(&databuf, ":%s!%s@%s KICK %s %s\r\n", - src->nick, src->username, src->hostname, chan->name, who->nick); -} -void msg_privmsg(Client *src, const char *dst, const char *msg) -{ - copy_strf(&databuf, ":%s!%s@%s PRIVMSG %s :%s\r\n", - src->nick, src->username, src->hostname, dst, msg); -} -void msg_privmsg_server(const char *src, const char *dst, const char *msg) -{ - copy_strf(&databuf, ":%s PRIVMSG %s :%s\r\n", - src, dst, msg); -} -void msg_notice(Client *src, const char *dst, const char *msg) -{ - copy_strf(&databuf, ":%s!%s@%s NOTICE %s :%s\r\n", - src->nick, src->username, src->hostname, dst, msg); -} -void msg_notice_server(const char *src, const char *dst, const char *msg) -{ - copy_strf(&databuf, ":%s NOTICE %s :%s\r\n", - src, dst, msg); -} -void msg_kill(Client *src, Client *dst, const char *reason) -{ - copy_strf(&databuf, ":%s!%s@%s KILL %s :%s\r\n", - src->nick, src->username, src->hostname, dst->nick, reason); -} -void msg_wallops(Client *src, const char *msg) -{ - copy_strf(&databuf, ":%s!%s@%s WALLOPS :%s\r\n", - src->nick, src->username, src->hostname, msg); -} -void msg_chghost(Client *src, const char *newusername, const char *newhostname) -{ - copy_strf(&databuf, ":%s!%s@%s CHGHOST %s %s\r\n", - src->nick, src->username, src->hostname, newusername, newhostname); -} -void msg_setname(Client *src) -{ - copy_strf(&databuf, ":%s!%s@%s SETNAME :%s\r\n", - src->nick, src->username, src->hostname, src->realname); -} -void msg_account(Client *src) -{ - copy_strf(&databuf, ":%s!%s@%s ACCOUNT %s\r\n", - src->nick, src->username, src->hostname, src->username[0] != '~' ? src->username : "*"); + msg_from_client("KICK %s %s\r\n", chan->name, who->nick); +} +void msg_privmsg(Client *src, const char *dst, const char *msg) { + msg_from_client("PRIVMSG %s :%s\r\n", dst, msg); +} +void msg_privmsg_server(const char *src, const char *dst, const char *msg) { + msg_from(src, "PRIVMSG %s :%s\r\n", dst, msg); +} +void msg_notice(Client *src, const char *dst, const char *msg) { + msg_from_client("NOTICE %s :%s\r\n", dst, msg); +} +void msg_notice_server(const char *src, const char *dst, const char *msg) { + msg_from(src, "NOTICE %s :%s\r\n", dst, msg); +} +void msg_kill(Client *src, Client *dst, const char *reason) { + msg_from_client("KILL %s :%s\r\n", dst->nick, reason); +} +void msg_wallops(Client *src, const char *msg) { + msg_from_client("WALLOPS :%s\r\n", msg); +} +void msg_chghost(Client *src, const char *newusername, const char *newhostname) { + msg_from_client("CHGHOST %s %s\r\n", newusername, newhostname); +} +void msg_setname(Client *src) { + msg_from_client("SETNAME :%s\r\n", src->realname); +} +void msg_account(Client *src) { + msg_from_client("ACCOUNT %s\r\n", src->username[0] != '~' ? src->username : "*"); } void rpl_welcome(Client *client) { // 001 num_reply(001, " :Welcome to the Patchy Network, %s\r\n", client->nick); @@ -596,10 +556,10 @@ void rpl_endofquietlist(Client *client, Channel *chan) { // 729 num_reply(729, " %s q :End of channel quiet list\r\n", chan->name); } void rpl_mononline(Client *client, Client *cl) { // 730 - num_reply_check_nick(730, " :%s!%s@%s\r\n", cl->nick, cl->username, cl->hostname); + num_reply_check_client(730, " :%s!%s@%s\r\n", cl->nick, cl->username, cl->hostname); } void rpl_monoffline(Client *client, std::string_view nick) { // 731 - num_reply_check_nick(731, " :%.*s\r\n", (int)nick.size(), nick.data()); + num_reply_check_client(731, " :%.*s\r\n", (int)nick.size(), nick.data()); } void rpl_monlist(Client *client, std::string_view nick) { // 732 num_reply(732, " :%.*s\r\n", (int)nick.size(), nick.data());