diff options
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/functions.c b/functions.c index 0aefa05..4ea5a51 100644 --- a/functions.c +++ b/functions.c @@ -912,3 +912,27 @@ void tryautonick(struct ircdstrings *ircdstrings) { debugprint(DEBUG_FULL, "tryautonick(): set irdstrings->ircnick to '%s'.\n", ircdstrings->ircnick); } + +// Exit the program cleanly - tell clients, tell the server, then exit(0) +// Optional quit message string "quitmsg" +// "sourcefd" of 0 means the request didn't come from a client +void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct ircdstrings *ircdstrings, struct settings *settings, char *quitmsg) { + char outgoingmsg[MAXDATASIZE]; + + // Tell clients and debug log + if (sourcefd) { + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request from client with fd '%d', message '%s'.", ircdstrings->ircnick, sourcefd, quitmsg); + debugprint(DEBUG_CRIT, "Exiting on request from client with fd '%d', message '%s'.\n", sourcefd, quitmsg); + } else { + snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :Exiting on request (not from a client), message '%s'.", ircdstrings->ircnick, quitmsg); + debugprint(DEBUG_CRIT, "Exiting on request (not from a client), message '%s'.\n", quitmsg); + } + sendtoallclients(clients, outgoingmsg, EXCEPT_NONE, settings); + + // Tell the server + // Combine "QUIT :" with any (optional) quit message + snprintf(outgoingmsg, MAXDATASIZE, "QUIT :%s", quitmsg); + sendtoserver(server_ssl, outgoingmsg, strlen(outgoingmsg), sourcefd, clients, settings); + + exit(0); +} |