From 638be4e7757a7e7fcb52332461b5b1b5330a6771 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 4 Dec 2018 15:56:10 -0500 Subject: Show error if disconnected unintentionally --- chat.h | 1 + event.c | 6 +++++- handle.c | 13 ++++++++----- input.c | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/chat.h b/chat.h index 01dcd72..9a544f5 100644 --- a/chat.h +++ b/chat.h @@ -44,6 +44,7 @@ struct { char *join; bool verbose; bool notify; + bool quit; } self; void eventWait(const char *argv[static 2]); diff --git a/event.c b/event.c index 4ea9f81..a5a49cc 100644 --- a/event.c +++ b/event.c @@ -131,10 +131,14 @@ noreturn void eventLoop(void) { for (;;) { if (sig[SIGCHLD]) childWait(); - if (sig[SIGHUP]) ircFmt("QUIT :zzz\r\n"); + if (sig[SIGHUP]) { + ircFmt("QUIT :zzz\r\n"); + self.quit = true; + } if (sig[SIGINT]) { signal(SIGINT, SIG_DFL); ircFmt("QUIT :Goodbye\r\n"); + self.quit = true; } if (sig[SIGWINCH]) { curses.sa_handler(SIGWINCH); diff --git a/handle.c b/handle.c index 137f859..3b52f0c 100644 --- a/handle.c +++ b/handle.c @@ -95,11 +95,14 @@ static void handlePing(char *prefix, char *params) { } static void handleError(char *prefix, char *params) { - (void)prefix; - (void)params; - // TODO: Show error if unintended disconnect. - uiExit(); - exit(EX_OK); + char *mesg; + parse(prefix, NULL, NULL, NULL, params, 1, 0, &mesg); + if (self.quit) { + uiExit(); + exit(EX_OK); + } else { + errx(EX_PROTOCOL, "%s", mesg); + } } static void handleErrorErroneousNickname(char *prefix, char *params) { diff --git a/input.c b/input.c index cc52928..7093363 100644 --- a/input.c +++ b/input.c @@ -106,6 +106,7 @@ static void inputTopic(struct Tag tag, char *params) { static void inputQuit(struct Tag tag, char *params) { (void)tag; ircFmt("QUIT :%s\r\n", params ? params : "Goodbye"); + self.quit = true; } static void inputURL(struct Tag tag, char *params) { -- cgit 1.4.1-2-gfad0