about summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-03-22 14:32:20 -0400
committerJune McEnroe <june@causal.agency>2020-03-22 14:32:20 -0400
commiteb6316c2352f0b50db4167f66528dfaee396f0ff (patch)
treedb714261a1f81c43298020260f565944988df1c2 /handle.c
parentAdd /say (diff)
downloadcatgirl-eb6316c2352f0b50db4167f66528dfaee396f0ff.tar.gz
catgirl-eb6316c2352f0b50db4167f66528dfaee396f0ff.zip
Track own host, handle CHGHOST
Diffstat (limited to 'handle.c')
-rw-r--r--handle.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/handle.c b/handle.c
index fa3f36b..f079c00 100644
--- a/handle.c
+++ b/handle.c
@@ -280,10 +280,13 @@ static void handleJoin(struct Message *msg) {
 	require(msg, true, 1);
 	uint id = idFor(msg->params[0]);
 	if (!strcmp(msg->nick, self.nick)) {
-		if (!self.user) {
+		if (!self.user || strcmp(self.user, msg->user)) {
 			set(&self.user, msg->user);
 			self.color = hash(msg->user);
 		}
+		if (!self.host || strcmp(self.host, msg->host)) {
+			set(&self.host, msg->host);
+		}
 		idColors[id] = hash(msg->params[0]);
 		completeTouch(None, msg->params[0], idColors[id]);
 		if (replies.join) {
@@ -306,6 +309,18 @@ static void handleJoin(struct Message *msg) {
 	);
 }
 
+static void handleChghost(struct Message *msg) {
+	require(msg, true, 2);
+	if (strcmp(msg->nick, self.nick)) return;
+	if (!self.user || strcmp(self.user, msg->params[0])) {
+		set(&self.user, msg->params[0]);
+		self.color = hash(msg->params[0]);
+	}
+	if (!self.host || strcmp(self.host, msg->params[1])) {
+		set(&self.host, msg->params[1]);
+	}
+}
+
 static void handlePart(struct Message *msg) {
 	require(msg, true, 1);
 	uint id = idFor(msg->params[0]);
@@ -1076,6 +1091,7 @@ static const struct Handler {
 	{ "906", handleErrorSASLFail },
 	{ "AUTHENTICATE", handleAuthenticate },
 	{ "CAP", handleCap },
+	{ "CHGHOST", handleChghost },
 	{ "ERROR", handleError },
 	{ "INVITE", handleInvite },
 	{ "JOIN", handleJoin },