ref: a3d7d3bbd391651dd9b6570480406c05e751eb45
parent: 4b27eadd45e9d157374782d164e8a79faf08575c
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Jul 22 17:35:44 EDT 2025
implements quit command
--- a/cmd.c
+++ b/cmd.c
@@ -144,6 +144,21 @@
reply(c, Runaway);
}
+static void
+cquit(Client *c, Request *r)
+{
+ /* (/lib/rfc/rfc2812:/^3.1.7) */
+ ircerror(c, "Bye");
+ if (c->user)
+ deluser(c->user);
+ if (c->nick)
+ free(c->nick);
+ if (c->away)
+ free(c->away);
+ c->nick = c->away = nil;
+ c->user = nil;
+}
+
static Command commands[] = {
{ "whois", cwhois },
{ "version", cversion },
@@ -151,6 +166,7 @@
{ "nick", cnick },
{ "privmsg", cprivmsg },
{ "away", caway },
+ { "quit", cquit },
};
int ncommands = sizeof(commands) / sizeof(Command);
--- a/dat.h
+++ b/dat.h
@@ -55,9 +55,6 @@
User *user;
char *nick;
char *away;
-
- Client *next;
- Client *prev;
};
extern int debug;
--- a/fns.h
+++ b/fns.h
@@ -7,6 +7,7 @@
void reply(Client*, Reply, ...);
void ircsend(Client*, Client*, Reply, ...);
+void ircerror(Client*, char*, ...);
char *getreplies(Client*);
void flushreplies(Client*);
--- a/reply.c
+++ b/reply.c
@@ -70,3 +70,28 @@
s_append(s, buf);
qunlock(&c->replies);
}
+
+void
+ircerror(Client *c, char *msg, ...)
+{
+ char buf[1024];
+ int i;
+ va_list arg;
+ String *s;
+
+ i = snprint(buf, sizeof buf, ":%s ERROR :", sysnameb);
+
+ va_start(arg, msg);
+ i += vsnprint(&buf[i], sizeof(buf) - i, msg, arg);
+ va_end(arg);
+
+ snprint(&buf[i], sizeof(buf) - i, "\r\n");
+
+ if (debug > 1)
+ fprint(2, "error: '%s'\n", buf);
+
+ qlock(&c->replies);
+ s = c->replies.reply;
+ s_append(s, buf);
+ qunlock(&c->replies);
+}
--
⑨