summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-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) {