From c84d8c493ccdc840a866a9f51f10fe6b1f2bc377 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Mon, 10 Jun 2019 21:17:10 +0100 Subject: Refactoring - split giant processircmessage() switch statement into separate server and client functions in message.h/message.c. --- functions.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'functions.c') 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); +} -- cgit v1.2.3