summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-13 09:33:16 -0400
committerJune McEnroe <june@causal.agency>2020-08-13 09:47:36 -0400
commitdb0edeeb5d2120431792736ff3b30b7c49e14ea7 (patch)
tree064b91f53795d5a8d6ab50129ac21d344ab00b14
parentRefactor intercept to use Handlers and fix QUIT w/o message (diff)
downloadpounce-db0edeeb5d2120431792736ff3b30b7c49e14ea7.tar.gz
pounce-db0edeeb5d2120431792736ff3b30b7c49e14ea7.zip
Fix unintended interception of NICK after registration 1.4p2
Another bug caused by trying to support broken clients. I'm annoyed.

This is a backport of 6f1cb708f0105027f0b2948130e71e0cf0995c89.
-rw-r--r--client.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/client.c b/client.c
index dc33288..1d32172 100644
--- a/client.c
+++ b/client.c
@@ -297,19 +297,20 @@ static void handleTagmsg(struct Client *client, struct Message *msg) {
 }
 
 static const struct {
+	bool intercept;
+	bool need;
 	const char *cmd;
 	Handler *fn;
-	bool need;
 } Handlers[] = {
-	{ "AUTHENTICATE", handleAuthenticate, false },
-	{ "CAP", handleCap, false },
-	{ "NICK", handleNick, false },
-	{ "NOTICE", handlePrivmsg, true },
-	{ "PASS", handlePass, false },
-	{ "PRIVMSG", handlePrivmsg, true },
-	{ "QUIT", handleQuit, true },
-	{ "TAGMSG", handleTagmsg, true },
-	{ "USER", handleUser, false },
+	{ false, false, "AUTHENTICATE", handleAuthenticate },
+	{ false, false, "NICK", handleNick },
+	{ false, false, "PASS", handlePass },
+	{ false, false, "USER", handleUser },
+	{ true, false, "CAP", handleCap },
+	{ true, true, "NOTICE", handlePrivmsg },
+	{ true, true, "PRIVMSG", handlePrivmsg },
+	{ true, true, "QUIT", handleQuit },
+	{ true, true, "TAGMSG", handleTagmsg },
 };
 
 static void clientParse(struct Client *client, char *line) {
@@ -333,6 +334,7 @@ static bool intercept(const char *line, size_t len) {
 		line = sp;
 	}
 	for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) {
+		if (!Handlers[i].intercept) continue;
 		size_t n = strlen(Handlers[i].cmd);
 		if (len < n) continue;
 		if (memcmp(line, Handlers[i].cmd, n)) continue;