summary refs log tree commit diff
path: root/bounce.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-26 02:25:04 -0400
committerJune McEnroe <june@causal.agency>2019-10-26 02:25:04 -0400
commit3beb01f99ac5ea9a22c55edbf0e7b095e1cb5b0d (patch)
tree48235b1b4ea985e0dde72b83bad208f6fc3f6e5a /bounce.c
parentAdd flags to request TOPIC and NAMES on client connect (diff)
downloadpounce-3beb01f99ac5ea9a22c55edbf0e7b095e1cb5b0d.tar.gz
pounce-3beb01f99ac5ea9a22c55edbf0e7b095e1cb5b0d.zip
Set AWAY when no clients are connected
Diffstat (limited to 'bounce.c')
-rw-r--r--bounce.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bounce.c b/bounce.c
index 712b9c3..648a17b 100644
--- a/bounce.c
+++ b/bounce.c
@@ -91,10 +91,12 @@ int main(int argc, char *argv[]) {
 	const char *user = NULL;
 	const char *real = NULL;
 	const char *join = NULL;
+	const char *away = "pounced :3";
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "C:H:K:NTP:W:a:h:j:n:p:r:u:vw:"))) {
+	while (0 < (opt = getopt(argc, argv, "A:C:H:K:NTP:W:a:h:j:n:p:r:u:vw:"))) {
 		switch (opt) {
+			break; case 'A': away = optarg;
 			break; case 'C': strlcpy(certPath, optarg, sizeof(certPath));
 			break; case 'H': localHost = optarg;
 			break; case 'K': strlcpy(privPath, optarg, sizeof(privPath));
@@ -147,6 +149,7 @@ int main(int argc, char *argv[]) {
 	}
 	eventAdd(server, NULL);
 
+	size_t clients = 0;
 	while (0 < poll(event.fds, event.len, -1)) {
 		for (size_t i = 0; i < event.len; ++i) {
 			short revents = event.fds[i].revents;
@@ -156,6 +159,7 @@ int main(int argc, char *argv[]) {
 				int fd;
 				struct tls *tls = listenAccept(&fd, event.fds[i].fd);
 				eventAdd(fd, clientAlloc(tls));
+				if (!clients++) serverFormat("AWAY\r\n");
 				continue;
 			}
 
@@ -172,10 +176,10 @@ int main(int argc, char *argv[]) {
 			if (revents & POLLIN) clientRecv(client);
 			if (revents & POLLOUT) clientConsume(client);
 			if (clientError(client) || revents & (POLLHUP | POLLERR)) {
-				// TODO: Set AWAY if no more clients remain.
 				clientFree(client);
 				close(event.fds[i].fd);
 				eventRemove(i);
+				if (!--clients) serverFormat("AWAY :%s\r\n", away);
 				break;
 			}
 		}
ght'> 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe It's actually in a good state now, I think. 2019-02-21Replace "view" with "window"June McEnroe I think originally I didn't want to use the same word as curses WINDOW but it's really much clearer for the user if they're just called windows. UI code probably needs yet another rewrite though. Still feels messy. 2019-02-21Remove ROT13June McEnroe It's just not convenient when it can only do the whole line... 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe Otherwise the "Traveling" message isn't visible while connecting. 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe