summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-10 21:17:10 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-10 21:17:10 +0100
commitc84d8c493ccdc840a866a9f51f10fe6b1f2bc377 (patch)
treeb064e1f554b19378beb0909c78061001b331eb3a /functions.c
parent853efa64ff8ad6ebde47d1265f8b13e954a0d2f0 (diff)
Refactoring - split giant processircmessage() switch statement into separate server and client functions in message.h/message.c.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c24
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);
+}