about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--chat.h2
-rw-r--r--command.c4
-rw-r--r--handle.c44
3 files changed, 39 insertions, 11 deletions
diff --git a/chat.h b/chat.h
index 43df641..8573ad8 100644
--- a/chat.h
+++ b/chat.h
@@ -246,8 +246,8 @@ extern struct Replies {
 	uint list;
 	uint mode;
 	uint names;
-	uint ops;
 	uint topic;
+	uint who;
 	uint whois;
 } replies;
 
diff --git a/command.c b/command.c
index efc095c..92f1271 100644
--- a/command.c
+++ b/command.c
@@ -176,8 +176,8 @@ static void commandNames(uint id, char *params) {
 
 static void commandOps(uint id, char *params) {
 	(void)params;
-	ircFormat("NAMES %s\r\n", idNames[id]);
-	replies.ops++;
+	ircFormat("WHO %s\r\n", idNames[id]);
+	replies.who++;
 }
 
 static void commandInvite(uint id, char *params) {
diff --git a/handle.c b/handle.c
index e3efe47..7519b87 100644
--- a/handle.c
+++ b/handle.c
@@ -499,26 +499,52 @@ static void handleReplyNames(struct Message *msg) {
 		char *user = strsep(&name, "@");
 		enum Color color = (user ? hash(user) : Default);
 		completeAdd(id, nick, color);
-		if (replies.ops && (prefixes == nick || prefixes[0] == '+')) continue;
-		if (!replies.ops && !replies.names) continue;
+		if (!replies.names) continue;
 		catf(&cat, "%s\3%02d%s\3", (buf[0] ? ", " : ""), color, prefixes);
 	}
 	if (!cat.len) return;
 	uiFormat(
 		id, Cold, tagTime(msg),
-		"%s \3%02d%s\3 are %s",
-		(replies.ops ? "The operators of" : "In"),
+		"In \3%02d%s\3 are %s",
 		hash(msg->params[2]), msg->params[2], buf
 	);
 }
 
 static void handleReplyEndOfNames(struct Message *msg) {
 	(void)msg;
-	if (replies.ops) {
-		replies.ops--;
-	} else if (replies.names) {
-		replies.names--;
+	if (replies.names) replies.names--;
+}
+
+static char whoBuf[1024];
+static struct Cat whoCat = { whoBuf, sizeof(whoBuf), 0 };
+
+static void handleReplyWho(struct Message *msg) {
+	require(msg, false, 7);
+	if (!replies.who) return;
+	if (!whoCat.len) {
+		catf(
+			&whoCat, "The operators of \3%02d%s\3 are ",
+			hash(msg->params[1]), msg->params[1]
+		);
 	}
+	char *prefixes = &msg->params[6][1];
+	if (prefixes[0] == '*') prefixes++;
+	prefixes[strspn(prefixes, network.prefixes)] = '\0';
+	if (!prefixes[0] || prefixes[0] == '+') return;
+	catf(
+		&whoCat, "%s\3%02d%s%s\3%s",
+		(whoCat.buf[whoCat.len - 1] == ' ' ? "" : ", "),
+		hash(msg->params[2]), prefixes, msg->params[5],
+		(msg->params[6][0] == 'H' ? "" : " (away)")
+	);
+}
+
+static void handleReplyEndOfWho(struct Message *msg) {
+	require(msg, false, 2);
+	if (!replies.who) return;
+	replies.who--;
+	uiWrite(idFor(msg->params[1]), Cold, tagTime(msg), whoBuf);
+	whoCat.len = 0;
 }
 
 static void handleReplyNoTopic(struct Message *msg) {
@@ -1196,6 +1222,7 @@ static const struct Handler {
 	{ "311", handleReplyWhoisUser },
 	{ "312", handleReplyWhoisServer },
 	{ "313", handleReplyWhoisGeneric },
+	{ "315", handleReplyEndOfWho },
 	{ "317", handleReplyWhoisIdle },
 	{ "318", handleReplyEndOfWhois },
 	{ "319", handleReplyWhoisChannels },
@@ -1210,6 +1237,7 @@ static const struct Handler {
 	{ "347", handleReplyEndOfInviteList },
 	{ "348", handleReplyExceptList },
 	{ "349", handleReplyEndOfExceptList },
+	{ "352", handleReplyWho },
 	{ "353", handleReplyNames },
 	{ "366", handleReplyEndOfNames },
 	{ "367", handleReplyBanList },