wm: ircd

Download patch

ref: efdfdd344d47687bfceaeafec89e0e81d6208098
parent: cbf3068e0f404a6370d3b7d4da3161d056a071cc
author: saeed <saeed@cloud9p.org>
date: Fri Jul 4 13:51:09 IDT 2025

readd WHO support

also fix numericals and messages a bit, it's still suboptimal. :-(

--- a/ircd.c
+++ b/ircd.c
@@ -3,6 +3,7 @@
 
 char *password = nil; /* nil to disable server password */
 char *motdtxt = nil; /* nil for no motd */
+
 enum {
 	Maxclients = 48,
 	Maxchannels = 16,
@@ -1021,6 +1022,46 @@
 }
 
 int
+who(Client *c, char *nicks)
+{
+	static char buf[Msglen+1];
+	Item *i;
+	Client *w;
+	int nargs, n, j;
+	char *args[5];
+
+	if(nicks == nil || strcmp(nicks, "*") == 0)
+		nargs = 0;
+	else
+		nargs = getfields(nicks, args, 5, 0, ",");
+
+	qlock(&clock);
+
+	for(i = clients.head; i != nil; i = i->next){
+		w = i->data;
+		if(w->prefix == nil)
+			continue;
+		if(nargs == 0)
+			goto match;
+		for(j = 0; j < nargs; j++)
+			if(strcmp(w->nick, args[j]) == 0)
+				goto match;
+		continue;
+match:
+		/* skip realname at the end */
+		n = snprint(buf, sizeof(buf), ":%s 352 %s %s %s %s * :\r\n", servername, c->nick, w->nick, w->user, w->conninfo->rsys);
+		dprint("%d: reply: %s", c->fd, buf);
+		ewrite(c->fd, buf, n);
+	}
+	qunlock(&clock);
+
+	n = snprint(buf, sizeof(buf), ":%s 315 %s %s :End of /WHO\r\n", servername, c->nick, nicks == nil ? "*" : nicks);
+	dprint("%d: reply: %s", c->fd, buf);
+	ewrite(c->fd, buf, n);
+	return 1;
+}
+
+int
 whois(Client *c, char *nicks)
 {
 	static char buf[Msglen+1];
@@ -1217,6 +1258,10 @@
 	if(strcmp(cmd, "LIST") == 0){
 		tmp = strtok(0, " :\r"); /* channels */
 		return list(c, tmp);
+	}
+	if(strcmp(cmd, "WHO") == 0){
+		tmp = strtok(0, " :\r"); /* nicks */
+		return who(c, tmp);
 	}
 	if(strcmp(cmd, "WHOIS") == 0){
 		tmp = strtok(0, " :\r"); /* nicks */
--