wm: ircd

Download patch

ref: 359e8dd290b1dc8b5662312e0e79214fffdae362
parent: 7edeb57b09c3c14ec9572033fe85285b22e28f83
author: mkf <mkf@cirno>
date: Tue Sep 26 21:49:35 EDT 2023

add AWAY and related numericals

--- a/ircd.c
+++ b/ircd.c
@@ -22,10 +22,14 @@
 	PRIVMSG,
 	NICK,
 	TOPIC,
+	AWAY,
 
 	/* numericals */
 	RPL_WELCOME = 001,
 
+	RPL_AWAY = 301,
+	RPL_UNAWAY = 305,
+	RPL_NOWAWAY = 306,
 	RPL_NOTOPIC = 331,
 	RPL_TOPIC = 332,
 	RPL_TOPICWHOTIME = 333,
@@ -71,6 +75,7 @@
 	int pings; /* unreplied pings */
 	long msgtimer; /* for flood */
 	int passok; 
+	char *away; /* away msg */
 };
 
 /* not to mix with thread(2) Channel:s */
@@ -240,6 +245,7 @@
 	c->fd = fd;
 	c->conninfo = ci;
 	c->pid = getpid();
+	c->away = nil;
 
 	dprint("%d: rsys=%s rserv=%s raddr=%s pid=%d\n", fd, ci->rsys, ci->rserv, ci->raddr, c->pid);
 
@@ -354,7 +360,17 @@
 		/* r->argv is: setter, channel, topic */
 		n = snprint(buf, n, ":%s TOPIC %s :%s\r\n", r->argv[0], r->argv[1], r->argv[2]);
 		break;
-
+	case RPL_AWAY:
+		/* r->argv is: target, awaymsg */
+		n = snprint(buf, n, ":%s 301 %s %s :%s\r\n", servername, c->nick, r->argv[0], r->argv[1]);
+		dprint("here\n");
+		break;
+	case RPL_UNAWAY:
+		n = snprint(buf, n, ":%s 305 %s :You are no longer marked as being away\r\n", servername, c->nick);
+		break;
+	case RPL_NOWAWAY:
+		n = snprint(buf, n, ":%s 306 %s :You are now marked as being away\r\n", servername, c->nick);
+		break;
 	case RPL_WELCOME:
 		n = snprint(buf, n,
 		":%s 001 %s :Welcome %s\r\n"
@@ -839,7 +855,7 @@
 {
 	Client *tc;
 	Chan *ch;
-	Reply r;
+	Reply r, raway;
 
 	r.code = PRIVMSG;
 	r.argv[0] = c->prefix; /* from */
@@ -864,8 +880,15 @@
 		}
 	}else{
 		tc = getclient(&clients, target);
-		if(tc != nil)
+		if(tc != nil){
+			if(tc->away != nil){
+				raway.code = RPL_AWAY;
+				raway.argv[0] = tc->nick;
+				raway.argv[1] = tc->away;
+				reply(c, &raway);
+			}
 			reply(tc, &r);
+		}
 		else{
 			r.code = ERR_NOSUCHNICK;
 			r.argv[0] = target;
@@ -983,6 +1006,23 @@
 }
 
 int
+away(Client *c, char *msg)
+{
+	Reply r;
+	/* don't mark one as away twice */
+	if(msg != nil && c->away == nil){
+		c->away = msg;
+		r.code = RPL_NOWAWAY;
+	}
+	else{
+		c->away = nil;
+		r.code = RPL_UNAWAY;
+	}
+	reply(c, &r);
+	return 1;
+}
+
+int
 process(Client *c, char *msg)
 {
 	char *cmd, *tmp, *tmp2;
@@ -1083,6 +1123,10 @@
 	if(strcmp(cmd, "WHOIS") == 0){
 		tmp = strtok(0, " \r"); /* nicks */
 		return whois(c, tmp);
+	}
+	if(strcmp(cmd, "AWAY") == 0){
+		tmp = strtok(0, " \r"); /* msg */
+		return away(c, tmp);
 	}
 	r.code = ERR_UNKNOWNCOMMAND;
 	r.argv[0] = cmd;