wm: ircd

Download patch

ref: 20e767d202964f6121b2a2f2061c7506987dd593
parent: 4251d493d8eb4371fb6f59a0f511cb80e4a24588
author: mkf <mkf@cloud9p.org>
date: Tue Sep 3 14:20:09 EDT 2024

add NAMES

--- a/ircd.c
+++ b/ircd.c
@@ -419,7 +419,6 @@
 		/* r->argv is: channel, topicwhotime */
 		n = snprint(buf, n, ":%s 376 %s :End of message of the day\r\n", servername, c->nick);
 		break;
-
 	case ERR_NOSUCHNICK:
 		/* r->argv[0] is nick/channel */
 		n = snprint(buf, n, ":%s 401 %s %s :No such nick/channel\r\n", servername, c->nick, r->argv[0]);
@@ -745,6 +744,7 @@
 	return 1;	
 }
 
+
 void
 replytopic(Client *c, Chan *ch)
 {
@@ -888,6 +888,34 @@
 	return 1;
 }
 
+int
+names(Client *c, char *chan)
+{
+	Chan *ch;
+	Reply r;
+
+
+	qlock(&clock);
+	ch = getchan(&channels, chan);
+	if(ch == nil){
+		if(!validchan(chan)){
+			dprint("%d: no channel found for NAMES %s\n", c->fd, chan);
+			r.code = ERR_NOSUCHCHANNEL;
+			r.argv[0] = chan;
+			reply(c, &r);
+			goto end;
+		}
+		ch = addchan(chan);
+	}
+	dprint("%d: NAMES chan=%s\n", c->fd, chan);
+	replynames(c, ch);
+end:
+	qunlock(&clock);
+	return 1;
+
+	
+}
+
 void
 quit(Client *c, char *reason)
 {
@@ -1100,6 +1128,7 @@
 		}
 		return nick(c, tmp);
 	}
+	
 	if(strcmp(cmd, "USER") == 0){
 		tmp = strtok(0, " \r"); /* username */
 		if(tmp == nil)
@@ -1142,6 +1171,17 @@
 		do{ /* if there are multiple channels */
 			if(tmp2 != nil)
 				join(c, tmp2);
+		}while(tmp2 = strtok(0, ","));
+		return 1;
+	}
+	if(strcmp(cmd, "NAMES") == 0){
+		tmp = strtok(0, " :\r"); /* channels */
+		if(tmp == nil)
+			return 0;
+		tmp2 = strtok(tmp, ",");
+		do{ /* if there are multiple channels */
+			if(tmp2 != nil)
+				names(c, tmp2);
 		}while(tmp2 = strtok(0, ","));
 		return 1;
 	}