about summary refs log tree commit diff
path: root/irc.c
diff options
context:
space:
mode:
Diffstat (limited to 'irc.c')
-rw-r--r--irc.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/irc.c b/irc.c
index f214637..a3f69d6 100644
--- a/irc.c
+++ b/irc.c
@@ -19,6 +19,7 @@
 #include <netdb.h>
 #include <netinet/in.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -103,27 +104,16 @@ int ircConnect(void) {
 		);
 	}
 
+	/// FIXME
+	if (self.user[0] == '~') selfUser(&self.user[1]);
+
 	if (irc.pass) ircFmt("PASS :%s\r\n", irc.pass);
-	ircFmt(
-		"NICK %s\r\n"
-		"USER %s 0 * :%s\r\n",
-		self.nick, self.user, self.nick
-	);
+	ircFmt("NICK %s\r\n", self.nick);
+	ircFmt("USER %s 0 * :%s\r\n", self.user, self.nick);
 
 	return irc.sock;
 }
 
-void ircDisconnect(const char *quit) {
-	// TODO: Wait for response, send quit to UI.
-	ircFmt("QUIT :%s\r\n", quit);
-
-	int error = tls_close(irc.client);
-	if (error) errx(EX_IOERR, "tls_close: %s", tls_error(irc.client));
-
-	error = close(irc.sock);
-	if (error) err(EX_IOERR, "close");
-}
-
 void ircWrite(const char *ptr, size_t len) {
 	while (len) {
 		ssize_t ret = tls_write(irc.client, ptr, len);
@@ -151,15 +141,23 @@ void ircFmt(const char *format, ...) {
 	free(buf);
 }
 
-void ircRead(void) {
+static void disconnect(void) {
+	int error = tls_close(irc.client);
+	if (error) errx(EX_IOERR, "tls_close: %s", tls_error(irc.client));
+	error = close(irc.sock);
+	if (error) err(EX_IOERR, "close");
+}
+
+bool ircRead(void) {
 	static char buf[4096];
 	static size_t len;
 
 	ssize_t read = tls_read(irc.client, &buf[len], sizeof(buf) - len);
 	if (read < 0) errx(EX_IOERR, "tls_read: %s", tls_error(irc.client));
 	if (!read) {
-		uiExit();
-		exit(EX_OK);
+		disconnect();
+		len = 0;
+		return false;
 	}
 	len += read;
 
@@ -178,4 +176,5 @@ void ircRead(void) {
 
 	len -= line - buf;
 	memmove(buf, line, len);
+	return true;
 }
title='2021-08-26 16:17:08 -0400'>2021-08-26Add version number generatorJune McEnroe 2021-08-22Add ISC license headerJune McEnroe 2021-08-22Update to Linux man-pages 5.12Štěpán Němec 2021-06-21Add manuals for macOS 11.3June McEnroe 2021-05-08Update to OpenBSD 6.9June McEnroe 2021-04-26Update to Linux man-pages 5.11June McEnroe 2021-04-26Update to FreeBSD 13.0June McEnroe 2021-01-27Completely rewrite how manuals are fetched and installedJune McEnroe Also add section 6 manuals from NetBSD and OpenBSD! 2020-12-14Update to man-pages-posix 2017-aJune McEnroe 2020-12-14Update to OpenBSD 6.8June McEnroe 2020-12-14Update to NetBSD 9.1June McEnroe 2020-12-14Update to man-pages 5.09June McEnroe 2020-12-14Update to FreeBSD 12.2June McEnroe 2020-06-08Update to OpenBSD 6.7June McEnroe 2020-05-04Add hack for macOS to search extra man sectionsJune McEnroe 2020-05-04Don't clear MANSECTJune McEnroe