From b2089e21606aed1a6aaa9644dbe0d2fe998ae1e0 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Fri, 8 Aug 2025 23:11:31 +0100 Subject: Improve output of LISTCLIENTS blabouncer command, add identical listclients command to STDIN commands, declare STDIN commands ("debug commands") in README. --- blabouncer.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'blabouncer.c') diff --git a/blabouncer.c b/blabouncer.c index 1c61336..b57fb4a 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -805,6 +805,42 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) { continue; } + if (strncmp(outgoingmsg, "listclients", strlen("listclients")) == 0) { + debugprint(DEBUG_SOME, "dochat(): stdin: There are %d blabouncer client(s) connected:\n", numclients(clients)); + printf("There are %d blabouncer client(s) connected:\n", numclients(clients)); + + // Loop through each client in clients struct for connected and authenticated clients... + int clientcount = 0; + debugprint(DEBUG_SOME, "dochat(): stdin: Authenticated clients:\n"); + printf("Authenticated clients:\n"); + for (int i = 0; i < MAXCLIENTS; i++) { + if (clients[i].fd && clients[i].authed) { + // ...then tell the requesting client about them + clientcount++; + debugprint(DEBUG_SOME, "dochat(): stdin: #%d: File descriptor: %d, IP: %s.\n", clientcount, clients[i].fd, clients[i].remoteip); + printf("#%d: File descriptor: %d, IP: %s.\n", clientcount, clients[i].fd, clients[i].remoteip); + } + } + + // And now loop through each client in clients struct for connected but unauthenticated clients... + clientcount = 0; + debugprint(DEBUG_SOME, "dochat(): stdin: Unauthenticated clients:\n"); + printf("Unauthenticated clients:\n"); + for (int i = 0; i < MAXCLIENTS; i++) { + if (clients[i].fd && !clients[i].authed) { + // ...then tell the requesting client about them + clientcount++; + debugprint(DEBUG_SOME, "dochat(): stdin: #%d: File descriptor: %d, IP: %s.\n", clientcount, clients[i].fd, clients[i].remoteip); + printf("#%d: File descriptor: %d, IP: %s.\n", clientcount, clients[i].fd, clients[i].remoteip); + } + } + + debugprint(DEBUG_SOME, "dochat(): stdin: STDIN command complete: listclients\n"); + printf("STDIN command complete: listclients\n"); + + continue; + } + debugprint(DEBUG_FULL, "dochat(): stdin: '%s' not processed as a command, sending to server.\n", outgoingmsg); printf("'%s' not processed as a command, sending to server.\n", outgoingmsg); // sourcefd = 0 as this is a trusted message -- cgit v1.2.3