about summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'handle.c')
-rw-r--r--handle.c350
1 files changed, 195 insertions, 155 deletions
diff --git a/handle.c b/handle.c
index 7721745..5a2cf7c 100644
--- a/handle.c
+++ b/handle.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2020  C. McEnroe <june@causal.agency>
+/* Copyright (C) 2020  June McEnroe <june@causal.agency>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -127,10 +127,33 @@ static void handleErrorGeneric(struct Message *msg) {
 	}
 }
 
+static void handleReplyGeneric(struct Message *msg) {
+	uint first = 1;
+	uint id = Network;
+	if (msg->params[1] && strchr(network.chanTypes, msg->params[1][0])) {
+		id = idFor(msg->params[1]);
+		first++;
+	}
+	char buf[1024];
+	char *ptr = buf, *end = &buf[sizeof(buf)];
+	ptr = seprintf(ptr, end, "\3%d(%s)\3\t", Gray, msg->cmd);
+	for (uint i = first; i < ParamCap && msg->params[i]; ++i) {
+		ptr = seprintf(
+			ptr, end, "%s%s", (i > first ? " " : ""), msg->params[i]
+		);
+	}
+	uiWrite(id, Ice, tagTime(msg), buf);
+}
+
 static void handleErrorNicknameInUse(struct Message *msg) {
 	require(msg, false, 2);
 	if (!strcmp(self.nick, "*")) {
-		ircFormat("NICK :%s_\r\n", msg->params[1]);
+		static uint i = 1;
+		if (i < ARRAY_LEN(self.nicks) && self.nicks[i]) {
+			ircFormat("NICK %s\r\n", self.nicks[i++]);
+		} else {
+			ircFormat("NICK %s_\r\n", msg->params[1]);
+		}
 	} else {
 		handleErrorGeneric(msg);
 	}
@@ -164,7 +187,9 @@ static void handleCap(struct Message *msg) {
 	} else if (!strcmp(msg->params[1], "ACK")) {
 		self.caps |= caps;
 		if (caps & CapSASL) {
-			ircFormat("AUTHENTICATE %s\r\n", (self.plain ? "PLAIN" : "EXTERNAL"));
+			ircFormat(
+				"AUTHENTICATE %s\r\n", (self.plainUser ? "PLAIN" : "EXTERNAL")
+			);
 		}
 		if (!(self.caps & CapSASL)) ircFormat("CAP END\r\n");
 	} else if (!strcmp(msg->params[1], "NAK")) {
@@ -203,33 +228,34 @@ static void base64(char *dst, const byte *src, size_t len) {
 
 static void handleAuthenticate(struct Message *msg) {
 	(void)msg;
-	if (!self.plain) {
+	if (!self.plainUser) {
 		ircFormat("AUTHENTICATE +\r\n");
 		return;
 	}
 
 	byte buf[299] = {0};
-	size_t len = 1 + strlen(self.plain);
+	size_t userLen = strlen(self.plainUser);
+	size_t passLen = strlen(self.plainPass);
+	size_t len = 1 + userLen + 1 + passLen;
 	if (sizeof(buf) < len) errx(EX_USAGE, "SASL PLAIN is too long");
-	memcpy(&buf[1], self.plain, len - 1);
-	byte *sep = memchr(buf, ':', len);
-	if (!sep) errx(EX_USAGE, "SASL PLAIN missing colon");
-	*sep = 0;
+	memcpy(&buf[1], self.plainUser, userLen);
+	memcpy(&buf[1 + userLen + 1], self.plainPass, passLen);
 
 	char b64[BASE64_SIZE(sizeof(buf))];
 	base64(b64, buf, len);
 	ircFormat("AUTHENTICATE ");
-	ircSend(b64, BASE64_SIZE(len));
+	ircSend(b64, BASE64_SIZE(len) - 1);
 	ircFormat("\r\n");
 
 	explicit_bzero(b64, sizeof(b64));
 	explicit_bzero(buf, sizeof(buf));
-	explicit_bzero(self.plain, strlen(self.plain));
+	explicit_bzero(self.plainPass, strlen(self.plainPass));
 }
 
 static void handleReplyLoggedIn(struct Message *msg) {
 	(void)msg;
 	ircFormat("CAP END\r\n");
+	handleReplyGeneric(msg);
 }
 
 static void handleErrorSASLFail(struct Message *msg) {
@@ -240,7 +266,7 @@ static void handleErrorSASLFail(struct Message *msg) {
 static void handleReplyWelcome(struct Message *msg) {
 	require(msg, false, 1);
 	set(&self.nick, msg->params[0]);
-	completeTouch(Network, self.nick, Default);
+	completePull(Network, self.nick, Default);
 	if (self.mode) ircFormat("MODE %s %s\r\n", self.nick, self.mode);
 	if (self.join) {
 		uint count = 1;
@@ -252,19 +278,26 @@ static void handleReplyWelcome(struct Message *msg) {
 		replies[ReplyTopicAuto] += count;
 		replies[ReplyNamesAuto] += count;
 	}
+	commandCompletion();
+	handleReplyGeneric(msg);
 }
 
 static void handleReplyISupport(struct Message *msg) {
+	handleReplyGeneric(msg);
 	for (uint i = 1; i < ParamCap; ++i) {
 		if (!msg->params[i]) break;
 		char *key = strsep(&msg->params[i], "=");
 		if (!strcmp(key, "NETWORK")) {
 			if (!msg->params[i]) continue;
 			set(&network.name, msg->params[i]);
-			uiFormat(
-				Network, Cold, tagTime(msg),
-				"You arrive in %s", msg->params[i]
-			);
+			static bool arrived;
+			if (!arrived) {
+				uiFormat(
+					Network, Cold, tagTime(msg),
+					"You arrive in %s", msg->params[i]
+				);
+				arrived = true;
+			}
 		} else if (!strcmp(key, "USERLEN")) {
 			if (!msg->params[i]) continue;
 			network.userLen = strtoul(msg->params[i], NULL, 10);
@@ -339,13 +372,13 @@ static void handleJoin(struct Message *msg) {
 			set(&self.host, msg->host);
 		}
 		idColors[id] = hash(msg->params[0]);
-		completeTouch(None, msg->params[0], idColors[id]);
+		completePull(None, msg->params[0], idColors[id]);
 		if (replies[ReplyJoin]) {
-			uiShowID(id);
+			windowShow(windowFor(id));
 			replies[ReplyJoin]--;
 		}
 	}
-	completeTouch(id, msg->nick, hash(msg->user));
+	completePull(id, msg->nick, hash(msg->user));
 	if (msg->params[2] && !strcasecmp(msg->params[2], msg->nick)) {
 		msg->params[2] = NULL;
 	}
@@ -377,7 +410,7 @@ static void handlePart(struct Message *msg) {
 	require(msg, true, 1);
 	uint id = idFor(msg->params[0]);
 	if (!strcmp(msg->nick, self.nick)) {
-		completeClear(id);
+		completeRemove(id, NULL);
 	}
 	completeRemove(id, msg->nick);
 	enum Heat heat = filterCheck(Cold, id, msg);
@@ -399,7 +432,7 @@ static void handleKick(struct Message *msg) {
 	require(msg, true, 2);
 	uint id = idFor(msg->params[0]);
 	bool kicked = !strcmp(msg->params[1], self.nick);
-	completeTouch(id, msg->nick, hash(msg->user));
+	completePull(id, msg->nick, hash(msg->user));
 	urlScan(id, msg->nick, msg->params[2]);
 	uiFormat(
 		id, (kicked ? Hot : Cold), tagTime(msg),
@@ -416,16 +449,17 @@ static void handleKick(struct Message *msg) {
 		(msg->params[2] ? ": " : ""), (msg->params[2] ?: "")
 	);
 	completeRemove(id, msg->params[1]);
-	if (kicked) completeClear(id);
+	if (kicked) completeRemove(id, NULL);
 }
 
 static void handleNick(struct Message *msg) {
 	require(msg, true, 1);
 	if (!strcmp(msg->nick, self.nick)) {
 		set(&self.nick, msg->params[0]);
-		uiRead(); // Update prompt.
+		inputUpdate();
 	}
-	for (uint id; (id = completeID(msg->nick));) {
+	struct Cursor curs = {0};
+	for (uint id; (id = completeEachID(&curs, msg->nick));) {
 		if (!strcmp(idNames[id], msg->nick)) {
 			set(&idNames[id], msg->params[0]);
 		}
@@ -440,12 +474,13 @@ static void handleNick(struct Message *msg) {
 			msg->nick, msg->params[0]
 		);
 	}
-	completeReplace(None, msg->nick, msg->params[0]);
+	completeReplace(msg->nick, msg->params[0]);
 }
 
 static void handleSetname(struct Message *msg) {
 	require(msg, true, 1);
-	for (uint id; (id = completeID(msg->nick));) {
+	struct Cursor curs = {0};
+	for (uint id; (id = completeEachID(&curs, msg->nick));) {
 		uiFormat(
 			id, filterCheck(Cold, id, msg), tagTime(msg),
 			"\3%02d%s\3\tis now known as \3%02d%s\3 (%s\17)",
@@ -457,7 +492,8 @@ static void handleSetname(struct Message *msg) {
 
 static void handleQuit(struct Message *msg) {
 	require(msg, true, 0);
-	for (uint id; (id = completeID(msg->nick));) {
+	struct Cursor curs = {0};
+	for (uint id; (id = completeEachID(&curs, msg->nick));) {
 		enum Heat heat = filterCheck(Cold, id, msg);
 		if (heat > Ice) urlScan(id, msg->nick, msg->params[0]);
 		uiFormat(
@@ -535,7 +571,12 @@ static void handleReplyNames(struct Message *msg) {
 		char *nick = &prefixes[strspn(prefixes, network.prefixes)];
 		char *user = strsep(&name, "@");
 		enum Color color = (user ? hash(user) : Default);
-		completeAdd(id, nick, color);
+		uint bits = 0;
+		for (char *p = prefixes; p < nick; ++p) {
+			bits |= prefixBit(*p);
+		}
+		completePush(id, nick, color);
+		*completeBits(id, nick) = bits;
 		if (!replies[ReplyNames] && !replies[ReplyNamesAuto]) continue;
 		ptr = seprintf(
 			ptr, end, "%s\3%02d%s\3", (ptr > buf ? ", " : ""), color, prefixes
@@ -558,41 +599,6 @@ static void handleReplyEndOfNames(struct Message *msg) {
 	}
 }
 
-static struct {
-	char buf[1024];
-	char *ptr;
-	char *end;
-} who = {
-	.ptr = who.buf,
-	.end = &who.buf[sizeof(who.buf)],
-};
-
-static void handleReplyWho(struct Message *msg) {
-	require(msg, false, 7);
-	if (who.ptr == who.buf) {
-		who.ptr = seprintf(
-			who.ptr, who.end, "The council of \3%02d%s\3 are ",
-			hash(msg->params[1]), msg->params[1]
-		);
-	}
-	char *prefixes = &msg->params[6][1];
-	if (prefixes[0] == '*') prefixes++;
-	prefixes[strspn(prefixes, network.prefixes)] = '\0';
-	if (!prefixes[0] || prefixes[0] == '+') return;
-	who.ptr = seprintf(
-		who.ptr, who.end, "%s\3%02d%s%s\3%s",
-		(who.ptr[-1] == ' ' ? "" : ", "),
-		hash(msg->params[2]), prefixes, msg->params[5],
-		(msg->params[6][0] == 'H' ? "" : " (away)")
-	);
-}
-
-static void handleReplyEndOfWho(struct Message *msg) {
-	require(msg, false, 2);
-	uiWrite(idFor(msg->params[1]), Warm, tagTime(msg), who.buf);
-	who.ptr = who.buf;
-}
-
 static void handleReplyNoTopic(struct Message *msg) {
 	require(msg, false, 2);
 	uiFormat(
@@ -604,14 +610,15 @@ static void handleReplyNoTopic(struct Message *msg) {
 
 static void topicComplete(uint id, const char *topic) {
 	char buf[512];
-	const char *prev = complete(id, "/topic ");
+	struct Cursor curs = {0};
+	const char *prev = completePrefix(&curs, id, "/topic ");
 	if (prev) {
 		snprintf(buf, sizeof(buf), "%s", prev);
 		completeRemove(id, buf);
 	}
 	if (topic) {
 		snprintf(buf, sizeof(buf), "/topic %s", topic);
-		completeAdd(id, buf, Default);
+		completePush(id, buf, Default);
 	}
 }
 
@@ -643,6 +650,28 @@ static void swap(wchar_t *a, wchar_t *b) {
 	*b = x;
 }
 
+static char *highlightMiddle(
+	char *ptr, char *end, enum Color color,
+	wchar_t *str, size_t pre, size_t suf
+) {
+	wchar_t nul = L'\0';
+	swap(&str[pre], &nul);
+	ptr = seprintf(ptr, end, "%ls", str);
+	swap(&str[pre], &nul);
+	swap(&str[suf], &nul);
+	if (hashBound) {
+		ptr = seprintf(
+			ptr, end, "\3%02d,%02d%ls\3%02d,%02d",
+			Default, color, &str[pre], Default, Default
+		);
+	} else {
+		ptr = seprintf(ptr, end, "\26%ls\26", &str[pre]);
+	}
+	swap(&str[suf], &nul);
+	ptr = seprintf(ptr, end, "%ls", &str[suf]);
+	return ptr;
+}
+
 static void handleTopic(struct Message *msg) {
 	require(msg, true, 2);
 	uint id = idFor(msg->params[0]);
@@ -660,10 +689,8 @@ static void handleTopic(struct Message *msg) {
 		return;
 	}
 
-	char buf[1024];
-	char *ptr = buf, *end = &buf[sizeof(buf)];
-	const char *prev = complete(id, "/topic ");
-	completeReject();
+	struct Cursor curs = {0};
+	const char *prev = completePrefix(&curs, id, "/topic ");
 	if (prev) {
 		prev += 7;
 	} else {
@@ -675,45 +702,46 @@ static void handleTopic(struct Message *msg) {
 	if (swprintf(old, ARRAY_LEN(old), L"%s", prev) < 0) goto plain;
 	if (swprintf(new, ARRAY_LEN(new), L"%s", msg->params[1]) < 0) goto plain;
 
-	if (!hashBound) {
-		ptr = seprintf(ptr, end, "%c%ls%c -> %c%ls%c", R, old, O, R, new, O);
-		goto plain;
-	}
-
 	size_t pre;
 	for (pre = 0; old[pre] && new[pre] && old[pre] == new[pre]; ++pre);
-	wchar_t *osuf = &old[wcslen(old)];
-	wchar_t *nsuf = &new[wcslen(new)];
-	while (osuf > &old[pre] && nsuf > &new[pre] && osuf[-1] == nsuf[-1]) {
+	size_t osuf = wcslen(old);
+	size_t nsuf = wcslen(new);
+	while (osuf > pre && nsuf > pre && old[osuf-1] == new[nsuf-1]) {
 		osuf--;
 		nsuf--;
 	}
 
-	wchar_t nul = L'\0';
-	swap(&new[pre], &nul);
-	ptr = seprintf(ptr, end, "%ls", new);
-	swap(&new[pre], &nul);
-	swap(osuf, &nul);
-	ptr = seprintf(ptr, end, "\3%02d,%02d%ls", Default, Brown, &old[pre]);
-	swap(osuf, &nul);
-	swap(nsuf, &nul);
-	ptr = seprintf(ptr, end, "\3%02d,%02d%ls", Default, Green, &new[pre]);
-	swap(nsuf, &nul);
-	ptr = seprintf(ptr, end, "\3%02d,%02d%ls", Default, Default, nsuf);
+	char buf[1024];
+	char *ptr = buf, *end = &buf[sizeof(buf)];
+	ptr = seprintf(
+		ptr, end, "\3%02d%s\3\ttakes down the sign in \3%02d%s\3: ",
+		hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0]
+	);
+	ptr = highlightMiddle(ptr, end, Brown, old, pre, osuf);
+	if (osuf != pre) uiWrite(id, Cold, tagTime(msg), buf);
+	ptr = buf;
+	ptr = seprintf(
+		ptr, end, "\3%02d%s\3\tplaces a new sign in \3%02d%s\3: ",
+		hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0]
+	);
+	ptr = highlightMiddle(ptr, end, Green, new, pre, nsuf);
+	uiWrite(id, Warm, tagTime(msg), buf);
+	goto log;
 
 plain:
-	topicComplete(id, msg->params[1]);
-	urlScan(id, msg->nick, msg->params[1]);
 	uiFormat(
 		id, Warm, tagTime(msg),
 		"\3%02d%s\3\tplaces a new sign in \3%02d%s\3: %s",
 		hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0],
-		(ptr > buf ? buf : msg->params[1])
+		msg->params[1]
 	);
+log:
 	logFormat(
 		id, tagTime(msg), "%s places a new sign in %s: %s",
 		msg->nick, msg->params[0], msg->params[1]
 	);
+	topicComplete(id, msg->params[1]);
+	urlScan(id, msg->nick, msg->params[1]);
 }
 
 static const char *UserModes[256] = {
@@ -835,6 +863,12 @@ static void handleMode(struct Message *msg) {
 			char prefix = network.prefixes[
 				strchr(network.prefixModes, *ch) - network.prefixModes
 			];
+			completePush(id, nick, Default);
+			if (set) {
+				*completeBits(id, nick) |= prefixBit(prefix);
+			} else {
+				*completeBits(id, nick) &= ~prefixBit(prefix);
+			}
 			uiFormat(
 				id, Cold, tagTime(msg),
 				"\3%02d%s\3\t%s \3%02d%c%s\3 %s%s in \3%02d%s\3",
@@ -1021,19 +1055,19 @@ static void handleReplyInviteList(struct Message *msg) {
 }
 
 static void handleReplyList(struct Message *msg) {
-	require(msg, false, 4);
+	require(msg, false, 3);
 	uiFormat(
 		Network, Warm, tagTime(msg),
 		"In \3%02d%s\3 are %ld under the banner: %s",
 		hash(msg->params[1]), msg->params[1],
 		strtol(msg->params[2], NULL, 10),
-		msg->params[3]
+		(msg->params[3] ?: "")
 	);
 }
 
 static void handleReplyWhoisUser(struct Message *msg) {
 	require(msg, false, 6);
-	completeTouch(Network, msg->params[1], hash(msg->params[2]));
+	completePull(Network, msg->params[1], hash(msg->params[2]));
 	uiFormat(
 		Network, Warm, tagTime(msg),
 		"\3%02d%s\3\tis %s!%s@%s (%s\17)",
@@ -1122,7 +1156,7 @@ static void handleReplyEndOfWhois(struct Message *msg) {
 
 static void handleReplyWhowasUser(struct Message *msg) {
 	require(msg, false, 6);
-	completeTouch(Network, msg->params[1], hash(msg->params[2]));
+	completePull(Network, msg->params[1], hash(msg->params[2]));
 	uiFormat(
 		Network, Warm, tagTime(msg),
 		"\3%02d%s\3\twas %s!%s@%s (%s)",
@@ -1141,14 +1175,9 @@ static void handleReplyEndOfWhowas(struct Message *msg) {
 static void handleReplyAway(struct Message *msg) {
 	require(msg, false, 3);
 	// Might be part of a WHOIS response.
-	uint id;
-	if (completeColor(Network, msg->params[1]) != Default) {
-		id = Network;
-	} else {
-		id = idFor(msg->params[1]);
-	}
+	uint id = (replies[ReplyWhois] ? Network : idFor(msg->params[1]));
 	uiFormat(
-		id, Warm, tagTime(msg),
+		id, (id == Network ? Warm : Cold), tagTime(msg),
 		"\3%02d%s\3\tis away: %s",
 		completeColor(id, msg->params[1]), msg->params[1], msg->params[2]
 	);
@@ -1179,11 +1208,11 @@ static bool isAction(struct Message *msg) {
 	return true;
 }
 
-static bool isMention(const struct Message *msg) {
-	size_t len = strlen(self.nick);
-	const char *match = msg->params[1];
-	while (NULL != (match = strstr(match, self.nick))) {
-		char a = (match > msg->params[1] ? match[-1] : ' ');
+static bool matchWord(const char *str, const char *word) {
+	size_t len = strlen(word);
+	const char *match = str;
+	while (NULL != (match = strstr(match, word))) {
+		char a = (match > str ? match[-1] : ' ');
 		char b = (match[len] ?: ' ');
 		if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) {
 			return true;
@@ -1193,48 +1222,53 @@ static bool isMention(const struct Message *msg) {
 	return false;
 }
 
-static void colorMentions(char *buf, size_t cap, uint id, struct Message *msg) {
-	*buf = '\0';
+static bool isMention(const struct Message *msg) {
+	if (matchWord(msg->params[1], self.nick)) return true;
+	for (uint i = 0; i < ARRAY_LEN(self.nicks) && self.nicks[i]; ++i) {
+		if (matchWord(msg->params[1], self.nicks[i])) return true;
+	}
+	return false;
+}
 
-	char *split = strstr(msg->params[1], ": ");
+static char *colorMentions(char *ptr, char *end, uint id, const char *msg) {
+	// Consider words before a colon, or only the first two.
+	const char *split = strstr(msg, ": ");
 	if (!split) {
-		split = strchr(msg->params[1], ' ');
+		split = strchr(msg, ' ');
 		if (split) split = strchr(&split[1], ' ');
 	}
-	if (!split) split = &msg->params[1][strlen(msg->params[1])];
-	for (char *ch = msg->params[1]; ch < split; ++ch) {
-		if (iscntrl(*ch)) return;
+	if (!split) split = &msg[strlen(msg)];
+	// Bail if there is existing formatting.
+	for (const char *ch = msg; ch < split; ++ch) {
+		if (iscntrl(*ch)) goto rest;
 	}
-	char delimit = *split;
-	char *mention = msg->params[1];
-	msg->params[1] = (delimit ? &split[1] : split);
-	*split = '\0';
 
-	char *ptr = buf, *end = &buf[cap];
-	while (*mention) {
-		size_t skip = strspn(mention, ",<> ");
-		ptr = seprintf(ptr, end, "%.*s", (int)skip, mention);
-		mention += skip;
-
-		size_t len = strcspn(mention, ",<> ");
-		char punct = mention[len];
-		mention[len] = '\0';
-		enum Color color = completeColor(id, mention);
+	while (msg < split) {
+		size_t skip = strspn(msg, ",:<> ");
+		ptr = seprintf(ptr, end, "%.*s", (int)skip, msg);
+		msg += skip;
+
+		size_t len = strcspn(msg, ",:<> ");
+		char *p = seprintf(ptr, end, "%.*s", (int)len, msg);
+		enum Color color = completeColor(id, ptr);
 		if (color != Default) {
-			ptr = seprintf(ptr, end, "\3%02d%s\3", color, mention);
+			ptr = seprintf(ptr, end, "\3%02d%.*s\3", color, (int)len, msg);
 		} else {
-			ptr = seprintf(ptr, end, "%s", mention);
+			ptr = p;
 		}
-		mention[len] = punct;
-		mention += len;
+		msg += len;
 	}
-	seprintf(ptr, end, "%c", delimit);
+
+rest:
+	return seprintf(ptr, end, "%s", msg);
 }
 
 static void handlePrivmsg(struct Message *msg) {
 	require(msg, true, 2);
-	if (network.statusmsg) {
-		msg->params[0] += strspn(msg->params[0], network.statusmsg);
+	char statusmsg = '\0';
+	if (network.statusmsg && strchr(network.statusmsg, msg->params[0][0])) {
+		statusmsg = msg->params[0][0];
+		msg->params[0]++;
 	}
 	bool query = !strchr(network.chanTypes, msg->params[0][0]);
 	bool server = strchr(msg->nick, '.');
@@ -1252,42 +1286,48 @@ static void handlePrivmsg(struct Message *msg) {
 	bool notice = (msg->cmd[0] == 'N');
 	bool action = !notice && isAction(msg);
 	bool highlight = !mine && isMention(msg);
-	enum Heat heat = filterCheck((highlight || query ? Hot : Warm), id, msg);
+	enum Heat heat = (!notice && (highlight || query) ? Hot : Warm);
+	heat = filterCheck(heat, id, msg);
 	if (heat > Warm && !mine && !query) highlight = true;
 	if (!notice && !mine && heat > Ice) {
-		completeTouch(id, msg->nick, hash(msg->user));
+		completePull(id, msg->nick, hash(msg->user));
 	}
 	if (heat > Ice) urlScan(id, msg->nick, msg->params[1]);
 
 	char buf[1024];
+	char *ptr = buf, *end = &buf[sizeof(buf)];
+	if (statusmsg) {
+		ptr = seprintf(
+			ptr, end, "\3%d[%c]\3 ", hash(msg->params[0]), statusmsg
+		);
+	}
 	if (notice) {
 		if (id != Network) {
 			logFormat(id, tagTime(msg), "-%s- %s", msg->nick, msg->params[1]);
 		}
-		uiFormat(
-			id, filterCheck(Warm, id, msg), tagTime(msg),
-			"\3%d-%s-\3%d\t%s",
-			hash(msg->user), msg->nick, LightGray, msg->params[1]
+		ptr = seprintf(
+			ptr, end, "\3%d-%s-\3%d\t",
+			hash(msg->user), msg->nick, LightGray
 		);
 	} else if (action) {
 		logFormat(id, tagTime(msg), "* %s %s", msg->nick, msg->params[1]);
-		colorMentions(buf, sizeof(buf), id, msg);
-		uiFormat(
-			id, heat, tagTime(msg),
-			"%s\35\3%d* %s\17\35\t%s%s",
-			(highlight ? "\26" : ""), hash(msg->user), msg->nick,
-			buf, msg->params[1]
+		ptr = seprintf(
+			ptr, end, "%s\35\3%d* %s\17\35\t",
+			(highlight ? "\26" : ""), hash(msg->user), msg->nick
 		);
 	} else {
 		logFormat(id, tagTime(msg), "<%s> %s", msg->nick, msg->params[1]);
-		colorMentions(buf, sizeof(buf), id, msg);
-		uiFormat(
-			id, heat, tagTime(msg),
-			"%s\3%d<%s>\17\t%s%s",
-			(highlight ? "\26" : ""), hash(msg->user), msg->nick,
-			buf, msg->params[1]
+		ptr = seprintf(
+			ptr, end, "%s\3%d<%s>\17\t",
+			(highlight ? "\26" : ""), hash(msg->user), msg->nick
 		);
 	}
+	if (notice) {
+		ptr = seprintf(ptr, end, "%s", msg->params[1]);
+	} else {
+		ptr = colorMentions(ptr, end, id, msg->params[1]);
+	}
+	uiWrite(id, heat, tagTime(msg), buf);
 }
 
 static void handlePing(struct Message *msg) {
@@ -1317,7 +1357,6 @@ static const struct Handler {
 	{ "312", 0, handleReplyWhoisServer },
 	{ "313", +ReplyWhois, handleReplyWhoisGeneric },
 	{ "314", +ReplyWhowas, handleReplyWhowasUser },
-	{ "315", -ReplyWho, handleReplyEndOfWho },
 	{ "317", +ReplyWhois, handleReplyWhoisIdle },
 	{ "318", -ReplyWhois, handleReplyEndOfWhois },
 	{ "319", +ReplyWhois, handleReplyWhoisChannels },
@@ -1335,7 +1374,6 @@ static const struct Handler {
 	{ "347", -ReplyInvex, NULL },
 	{ "348", +ReplyExcepts, handleReplyExceptList },
 	{ "349", -ReplyExcepts, NULL },
-	{ "352", +ReplyWho, handleReplyWho },
 	{ "353", 0, handleReplyNames },
 	{ "366", 0, handleReplyEndOfNames },
 	{ "367", +ReplyBan, handleReplyBanList },
@@ -1400,5 +1438,7 @@ void handle(struct Message *msg) {
 		if (handler->reply < 0) replies[abs(handler->reply)]--;
 	} else if (strcmp(msg->cmd, "400") >= 0 && strcmp(msg->cmd, "599") <= 0) {
 		handleErrorGeneric(msg);
+	} else if (isdigit(msg->cmd[0])) {
+		handleReplyGeneric(msg);
 	}
 }