summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-23 19:58:42 -0400
committerJune McEnroe <june@causal.agency>2019-10-23 19:58:42 -0400
commitd30bd701e902137c58879ffdc8a8a48de68913dc (patch)
tree106384caf6996340089d86a340de4993b0cfe431
parentRename Command to Message (diff)
downloadpounce-d30bd701e902137c58879ffdc8a8a48de68913dc.tar.gz
pounce-d30bd701e902137c58879ffdc8a8a48de68913dc.zip
Track nick changes
-rw-r--r--state.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/state.c b/state.c
index 48f7185..e86cf01 100644
--- a/state.c
+++ b/state.c
@@ -104,6 +104,20 @@ static void handleReplyISupport(struct Message msg) {
 	}
 }
 
+static bool self(struct Message msg) {
+	assert(nick);
+	size_t len = strlen(nick);
+	if (strncmp(msg.origin, nick, len)) return false;
+	if (strlen(msg.origin) < len || msg.origin[len] != '!') return false;
+	return true;
+}
+
+static void handleNick(struct Message msg) {
+	if (!msg.origin) errx(EX_PROTOCOL, "NICK without origin");
+	if (!msg.params[0]) errx(EX_PROTOCOL, "NICK without new nick");
+	if (self(msg)) set(&nick, msg.params[0]);
+}
+
 static void handleError(struct Message msg) {
 	errx(EX_UNAVAILABLE, "%s", msg.params[0]);
 }
@@ -119,6 +133,7 @@ static const struct {
 	{ "005", handleReplyISupport },
 	{ "CAP", handleCap },
 	{ "ERROR", handleError },
+	{ "NICK", handleNick },
 };
 
 void stateParse(char *line) {