Browse Source

Show error if disconnected unintentionally

June 6 days ago
parent
commit
638be4e775
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 15 additions and 6 deletions
  1. 1
    0
      chat.h
  2. 5
    1
      event.c
  3. 8
    5
      handle.c
  4. 1
    0
      input.c

+ 1
- 0
chat.h View File

@@ -44,6 +44,7 @@ struct {
44 44
 	char *join;
45 45
 	bool verbose;
46 46
 	bool notify;
47
+	bool quit;
47 48
 } self;
48 49
 
49 50
 void eventWait(const char *argv[static 2]);

+ 5
- 1
event.c View File

@@ -131,10 +131,14 @@ noreturn void eventLoop(void) {
131 131
 
132 132
 	for (;;) {
133 133
 		if (sig[SIGCHLD]) childWait();
134
-		if (sig[SIGHUP]) ircFmt("QUIT :zzz\r\n");
134
+		if (sig[SIGHUP]) {
135
+			ircFmt("QUIT :zzz\r\n");
136
+			self.quit = true;
137
+		}
135 138
 		if (sig[SIGINT]) {
136 139
 			signal(SIGINT, SIG_DFL);
137 140
 			ircFmt("QUIT :Goodbye\r\n");
141
+			self.quit = true;
138 142
 		}
139 143
 		if (sig[SIGWINCH]) {
140 144
 			curses.sa_handler(SIGWINCH);

+ 8
- 5
handle.c View File

@@ -95,11 +95,14 @@ static void handlePing(char *prefix, char *params) {
95 95
 }
96 96
 
97 97
 static void handleError(char *prefix, char *params) {
98
-	(void)prefix;
99
-	(void)params;
100
-	// TODO: Show error if unintended disconnect.
101
-	uiExit();
102
-	exit(EX_OK);
98
+	char *mesg;
99
+	parse(prefix, NULL, NULL, NULL, params, 1, 0, &mesg);
100
+	if (self.quit) {
101
+		uiExit();
102
+		exit(EX_OK);
103
+	} else {
104
+		errx(EX_PROTOCOL, "%s", mesg);
105
+	}
103 106
 }
104 107
 
105 108
 static void handleErrorErroneousNickname(char *prefix, char *params) {

+ 1
- 0
input.c View File

@@ -106,6 +106,7 @@ static void inputTopic(struct Tag tag, char *params) {
106 106
 static void inputQuit(struct Tag tag, char *params) {
107 107
 	(void)tag;
108 108
 	ircFmt("QUIT :%s\r\n", params ? params : "Goodbye");
109
+	self.quit = true;
109 110
 }
110 111
 
111 112
 static void inputURL(struct Tag tag, char *params) {

Loading…
Cancel
Save