summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-02 03:13:50 -0500
committerJune McEnroe <june@causal.agency>2020-02-02 03:13:50 -0500
commitec83332e15d31c1ffbb7112ff6743f2a5c815c71 (patch)
tree13c8812f90e5c3a830063144f47a8b3cb33e2719 /handle.c
parentPreserve copyright year in term.c (diff)
downloadcatgirl-ec83332e15d31c1ffbb7112ff6743f2a5c815c71.tar.gz
catgirl-ec83332e15d31c1ffbb7112ff6743f2a5c815c71.zip
Implement window switching and status line
Diffstat (limited to '')
-rw-r--r--handle.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/handle.c b/handle.c
index 350a636..609867e 100644
--- a/handle.c
+++ b/handle.c
@@ -65,9 +65,11 @@ static void set(char **field, const char *value) {
 	if (!*field) err(EX_OSERR, "strdup");
 }
 
-static void require(const struct Message *msg, bool origin, size_t len) {
-	if (origin && !msg->nick) {
-		errx(EX_PROTOCOL, "%s missing origin", msg->cmd);
+static void require(struct Message *msg, bool origin, size_t len) {
+	if (origin) {
+		if (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd);
+		if (!msg->user) msg->user = msg->nick;
+		if (!msg->host) msg->host = msg->user;
 	}
 	for (size_t i = 0; i < len; ++i) {
 		if (msg->params[i]) continue;
@@ -177,6 +179,19 @@ static void handleReplyMOTD(struct Message *msg) {
 	uiFormat(Network, Cold, tagTime(msg), "%s", line);
 }
 
+static void handleJoin(struct Message *msg) {
+	require(msg, true, 1);
+	size_t id = idFor(msg->params[0]);
+	if (self.nick && !strcmp(msg->nick, self.nick)) {
+		uiShowID(id);
+	}
+	uiFormat(
+		id, Cold, tagTime(msg),
+		C"%02d%s"C" arrives in "C"%02d%s"C,
+		hash(msg->user), msg->nick, hash(idNames[id]), idNames[id]
+	);
+}
+
 static void handlePing(struct Message *msg) {
 	require(msg, false, 1);
 	ircFormat("PONG :%s\r\n", msg->params[0]);
@@ -197,6 +212,7 @@ static const struct Handler {
 	{ "906", handleErrorSASLFail },
 	{ "AUTHENTICATE", handleAuthenticate },
 	{ "CAP", handleCap },
+	{ "JOIN", handleJoin },
 	{ "PING", handlePing },
 };