diff options
author | June McEnroe <june@causal.agency> | 2020-02-05 21:57:23 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-02-05 21:57:23 -0500 |
commit | 7c0e9cf3d2e83814fab3bb4bb09f7b955c2afaca (patch) | |
tree | 70adbed2adff0b4639f2a6647c6aa19121aa2f1a | |
parent | Add /me, /notice, /quote commands (diff) | |
download | catgirl-7c0e9cf3d2e83814fab3bb4bb09f7b955c2afaca.tar.gz catgirl-7c0e9cf3d2e83814fab3bb4bb09f7b955c2afaca.zip |
Add /quit
-rw-r--r-- | chat.c | 13 | ||||
-rw-r--r-- | chat.h | 1 | ||||
-rw-r--r-- | command.c | 5 |
3 files changed, 14 insertions, 5 deletions
diff --git a/chat.c b/chat.c index 2d58b1e..1ad2833 100644 --- a/chat.c +++ b/chat.c @@ -115,13 +115,12 @@ int main(int argc, char *argv[]) { { .events = POLLIN, .fd = STDIN_FILENO }, { .events = POLLIN, .fd = irc }, }; - for (;;) { + while (!self.quit) { int nfds = poll(fds, 2, -1); if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll"); - if (signals[SIGHUP] || signals[SIGINT] || signals[SIGTERM]) { - break; - } + if (signals[SIGHUP]) self.quit = "zzz"; + if (signals[SIGINT] || signals[SIGTERM]) break; if (signals[SIGWINCH]) { signals[SIGWINCH] = 0; cursesWinch(SIGWINCH); @@ -136,6 +135,10 @@ int main(int argc, char *argv[]) { uiDraw(); } - ircFormat("QUIT\r\n"); + if (self.quit) { + ircFormat("QUIT :%s\r\n", self.quit); + } else { + ircFormat("QUIT\r\n"); + } uiHide(); } diff --git a/chat.h b/chat.h index b73cf40..5b3c01c 100644 --- a/chat.h +++ b/chat.h @@ -75,6 +75,7 @@ extern struct Self { char *nick; char *user; enum Color color; + char *quit; } self; static inline void set(char **field, const char *value) { diff --git a/command.c b/command.c index 0843bd3..7fb98af 100644 --- a/command.c +++ b/command.c @@ -56,12 +56,17 @@ static void commandMe(size_t id, char *params) { commandPrivmsg(id, buf); } +static void commandQuit(size_t id, char *params) { + set(&self.quit, (params ? params : "Goodbye")); +} + static const struct Handler { const char *cmd; Command *fn; } Commands[] = { { "/me", commandMe }, { "/notice", commandNotice }, + { "/quit", commandQuit }, { "/quote", commandQuote }, }; |