From a339efad2a4ba8826d2234ffb7714084142b024f Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 8 Aug 2021 10:14:48 +0200 Subject: [PATCH] Add exit_client_fmt() which accepts formatting characters. --- include/h.h | 1 + src/misc.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/h.h b/include/h.h index e5c574150..c071d8295 100644 --- a/include/h.h +++ b/include/h.h @@ -285,6 +285,7 @@ extern char *myctime(time_t); extern char *short_date(time_t, char *buf); extern char *long_date(time_t); extern void exit_client(Client *client, MessageTag *recv_mtags, char *comment); +extern void exit_client_fmt(Client *client, MessageTag *recv_mtags, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 3, 4))); extern void exit_client_ex(Client *client, Client *origin, MessageTag *recv_mtags, char *comment); extern void initstats(), tstats(Client *, char *); extern char *check_string(char *); diff --git a/src/misc.c b/src/misc.c index 0a386ee42..fd70a2715 100644 --- a/src/misc.c +++ b/src/misc.c @@ -558,6 +558,23 @@ void exit_client(Client *client, MessageTag *recv_mtags, char *comment) exit_client_ex(client, client->direction, recv_mtags, comment); } +/** Exit this IRC client, and all the dependents (users, servers) if this is a server. + * @param client The client to exit. + * @param recv_mtags Message tags to use as a base (if any). + * @param comment The (s)quit message + */ +void exit_client_fmt(Client *client, MessageTag *recv_mtags, FORMAT_STRING(const char *pattern), ...) +{ + char comment[512]; + + va_list vl; + va_start(vl, pattern); + vsnprintf(comment, sizeof(comment), pattern, vl); + va_end(vl); + + exit_client_ex(client, client->direction, recv_mtags, comment); +} + /** Exit this IRC client, and all the dependents (users, servers) if this is a server. * @param client The client to exit. * @param recv_mtags Message tags to use as a base (if any).