wm: ircd

Download patch

ref: 0d0cbaf19e8911c6555a81c2dc9c1d4cbe31f55b
parent: a69e8b7ae62a125b93d0aca61ccd676689c3cc9f
author: mkf <mkf@cirno>
date: Tue Sep 26 22:24:54 EDT 2023

add ERR_NORECIPIENT and ERR_NOTEXTTOSEND instead and don't close the connection

--- a/ircd.c
+++ b/ircd.c
@@ -39,6 +39,8 @@
 	ERR_NOSUCHNICK = 401,
 	ERR_NOSUCHCHANNEL = 403,
 	ERR_CANNOTSENDTOCHAN = 404,
+	ERR_NORECIPIENT = 411,
+	ERR_NOTEXTTOSEND = 412,
 	ERR_UNKNOWNCOMMAND = 421,
 	ERR_NOMOTD = 422,
 	ERR_NONICKNAMEGIVEN = 431,
@@ -411,9 +413,15 @@
 		n = snprint(buf, n, ":%s 403 %s %s :No such channel\r\n", servername, c->nick, r->argv[0]);
 		break;
 	case ERR_CANNOTSENDTOCHAN:
-		/* r->argv is: channel */
+		/* r->argv is: command */
 		n = snprint(buf, n, ":%s 404 %s %s :Cannot send to channel\r\n", servername, c->nick, r->argv[0]);
 		break;
+	case ERR_NORECIPIENT:
+		n = snprint(buf, n, ":%s 411 %s :No recipient given (%s)\r\n", servername, c->nick, r->argv[0]);
+		break;
+	case ERR_NOTEXTTOSEND:
+		n = snprint(buf, n, ":%s 412 %s :No text to send\r\n", servername, c->nick);
+		break;
 	case ERR_UNKNOWNCOMMAND:
 		/* r->argv is: command */
 		n = snprint(buf, n, ":%s 421 %s %s :Unknown command\r\n", servername, c->nick, r->argv[0]);
@@ -1074,11 +1082,18 @@
 
 	if(strcmp(cmd, "PRIVMSG") == 0){
 		tmp = strtok(0, " :"); /* target */
-		if(tmp == nil)
-			return 0;
+		if(tmp == nil){
+			r.code = ERR_NORECIPIENT;
+			r.argv[0] = cmd;
+			reply(c, &r);
+			return 1;
+		}
 		tmp2 = strtok(0, "\r"); /* msg */
-		if(tmp2 == nil)
-			return 0;
+		if(tmp2 == nil){
+			r.code = ERR_NOTEXTTOSEND;
+			reply(c, &r);
+			return 1;
+		}
 		tmp2++;
 		return privmsg(c, tmp, tmp2);
 	}