summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bounce.c3
-rw-r--r--bounce.h1
-rw-r--r--client.c14
-rw-r--r--pounce.122
4 files changed, 35 insertions, 5 deletions
diff --git a/bounce.c b/bounce.c
index cd4898a..4146c0e 100644
--- a/bounce.c
+++ b/bounce.c
@@ -441,7 +441,7 @@ int main(int argc, char *argv[]) {
 			}
 		}
 
-		if (signals[SIGINT] || signals[SIGTERM]) {
+		if (clientQuit || signals[SIGINT] || signals[SIGTERM]) {
 			break;
 		}
 		if (signals[SIGALRM]) {
@@ -458,6 +458,7 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
+	if (clientQuit && clientQuit[0]) quit = clientQuit;
 	serverFormat("QUIT :%s\r\n", quit);
 	serverClose();
 	for (size_t i = clientIndex; i < event.len; ++i) {
diff --git a/bounce.h b/bounce.h
index fa810a2..e196ed0 100644
--- a/bounce.h
+++ b/bounce.h
@@ -228,6 +228,7 @@ extern enum Cap clientCaps;
 extern char *clientOrigin;
 extern char *clientPass;
 extern char *clientAway;
+extern char *clientQuit;
 struct Client *clientAlloc(int sock, struct tls *tls);
 void clientFree(struct Client *client);
 void clientRecv(struct Client *client);
diff --git a/client.c b/client.c
index a20700d..19296ed 100644
--- a/client.c
+++ b/client.c
@@ -46,6 +46,7 @@ enum Cap clientCaps = CapServerTime | CapConsumer | CapPassive | CapSTS;
 char *clientOrigin;
 char *clientPass;
 char *clientAway;
+char *clientQuit;
 
 static size_t active;
 
@@ -279,9 +280,16 @@ static void handleAuthenticate(struct Client *client, struct Message *msg) {
 }
 
 static void handleQuit(struct Client *client, struct Message *msg) {
-	(void)msg;
-	clientFormat(client, "ERROR :Detaching\r\n");
-	client->remove = true;
+	const char *mesg = msg->params[0];
+	if (mesg && !strncmp(mesg, "pounce", 6) && (!mesg[6] || mesg[6] == ' ')) {
+		mesg += 6;
+		mesg += strspn(mesg, " ");
+		clientQuit = strdup(mesg);
+		if (!clientQuit) err(EX_OSERR, "strdup");
+	} else {
+		clientFormat(client, "ERROR :Detaching\r\n");
+		client->remove = true;
+	}
 }
 
 static bool hasTag(const char *tags, const char *tag) {
diff --git a/pounce.1 b/pounce.1
index a4a20c9..3bdfc90 100644
--- a/pounce.1
+++ b/pounce.1
@@ -1,4 +1,4 @@
-.Dd October  5, 2021
+.Dd April  3, 2022
 .Dt POUNCE 1
 .Os
 .
@@ -472,6 +472,26 @@ The nickname and real name
 sent by clients are ignored.
 .
 .Pp
+Normally a client sending
+.Ic QUIT
+will simply be disconnected from
+.Nm .
+If, however,
+the quit message
+starts with the keyword
+.Nm ,
+.Nm
+itself will quit.
+The remainder of the message
+following the keyword
+will be used as
+.Nm Ap s
+quit message,
+or the default set by
+.Cm quit
+if there isn't any.
+.
+.Pp
 Clients which request the
 .Sy causal.agency/passive
 capability