ref: a30a8ec1ecc99617582604be95fc7c7eb90ba893
parent: b091853cd6fb11ad5ebca22d1b31710ebbc22efe
author: mkf <mkf@cloud9p.org>
date: Wed Sep 27 03:47:10 EDT 2023
improve JOIN, add proper MOTD support
--- a/ircd.c
+++ b/ircd.c
@@ -2,7 +2,7 @@
#include <libc.h>
char *password = nil; /* nil to disable server password */
-char *motdtxt = nil; /* nil for no motd */
+char *motdtxt = "hello!\nworld!"; /* nil for no motd */
enum {
Maxclients = 48,
Maxchannels = 16,
@@ -35,6 +35,9 @@
RPL_NOTOPIC = 331,
RPL_TOPIC = 332,
RPL_TOPICWHOTIME = 333,
+ RPL_MOTD = 372,
+ RPL_MOTDSTART = 375,
+ RPL_ENDOFMOTD = 376,
ERR_NOSUCHNICK = 401,
ERR_NOSUCHCHANNEL = 403,
@@ -404,6 +407,18 @@
/* r->argv is: channel, topicwhotime */
n = snprint(buf, n, ":%s 333 %s %s :%s\r\n", servername, c->nick, r->argv[0], r->argv[1]);
break;
+ case RPL_MOTD:
+ /* r->argv is: channel, topicwhotime */
+ n = snprint(buf, n, ":%s 372 %s :%s\r\n", servername, c->nick, r->argv[0]);
+ break;
+ case RPL_MOTDSTART:
+ /* r->argv is: channel, topicwhotime */
+ n = snprint(buf, n, ":%s 375 %s :Message of the day:\r\n", servername, c->nick);
+ break;
+ case RPL_ENDOFMOTD:
+ /* 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 */
@@ -499,9 +514,25 @@
motd(Client *c)
{
Reply r;
+ char *s;
+
if(motdtxt == nil){
r.code = ERR_NOMOTD;
reply(c, &r);
+ }else{
+ r.code = RPL_MOTDSTART;
+ reply(c, &r);
+
+ s = strtok(motdtxt, "\n");
+ do{
+ r.code = RPL_MOTD;
+ r.argv[0] = s;
+ reply(c, &r);
+ }while(s = strtok(0, "\n"));
+
+
+ r.code = RPL_ENDOFMOTD;
+ reply(c, &r);
}
return 1;
}
@@ -1108,10 +1139,10 @@
tmp = strtok(0, " \r"); /* channels */
if(tmp == nil)
return 0;
- tmp2 = strtok(tmp, ","); /* channel */
- do {
+ while(tmp2 = strtok(0, ",")){/* if there are multiple channels */
join(c, tmp2);
- } while(tmp2 = strtok(0, ","));
+ }
+ join(c, tmp2); /* if there is only one channel (left) */
return 1;
}
if(strcmp(cmd, "PART") == 0){