about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-02 17:37:36 -0500
committerJune McEnroe <june@causal.agency>2020-02-02 17:37:36 -0500
commit0d6a60cc6634cafe03671e9d5a1a64295c98bb9d (patch)
treec0040a6be92fba5aae7670d67ff3f1673edb4ba2
parentHandle notices and actions (diff)
downloadcatgirl-0d6a60cc6634cafe03671e9d5a1a64295c98bb9d.tar.gz
catgirl-0d6a60cc6634cafe03671e9d5a1a64295c98bb9d.zip
Save NETWORK, CHANTYPES, PREFIX from ISUPPORT
-rw-r--r--chat.c4
-rw-r--r--chat.h11
-rw-r--r--handle.c14
3 files changed, 21 insertions, 8 deletions
diff --git a/chat.c b/chat.c
index b61dd34..162f68f 100644
--- a/chat.c
+++ b/chat.c
@@ -80,6 +80,10 @@ int main(int argc, char *argv[]) {
 	if (!user) user = nick;
 	if (!real) real = nick;
 
+	set(&self.network, host);
+	set(&self.chanTypes, "#&");
+	set(&self.prefixes, "@+");
+
 	ircConfig(insecure, cert, priv);
 
 	uiInit();
diff --git a/chat.h b/chat.h
index 275fef9..f9de779 100644
--- a/chat.h
+++ b/chat.h
@@ -65,12 +65,21 @@ enum Cap {
 
 extern struct Self {
 	bool debug;
+	char *plain;
 	const char *join;
 	enum Cap caps;
-	char *plain;
+	char *network;
+	char *chanTypes;
+	char *prefixes;
 	char *nick;
 } self;
 
+static inline void set(char **field, const char *value) {
+	free(*field);
+	*field = strdup(value);
+	if (!*field) err(EX_OSERR, "strdup");
+}
+
 #define ENUM_TAG \
 	X("time", TagTime)
 
diff --git a/handle.c b/handle.c
index 2af5837..2766cc8 100644
--- a/handle.c
+++ b/handle.c
@@ -59,12 +59,6 @@ static const char *capList(enum Cap caps) {
 	return buf;
 }
 
-static void set(char **field, const char *value) {
-	free(*field);
-	*field = strdup(value);
-	if (!*field) err(EX_OSERR, "strdup");
-}
-
 static void require(struct Message *msg, bool origin, size_t len) {
 	if (origin) {
 		if (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd);
@@ -158,16 +152,22 @@ static void handleReplyWelcome(struct Message *msg) {
 }
 
 static void handleReplyISupport(struct Message *msg) {
-	// TODO: Extract CHANTYPES and PREFIX for future use.
 	for (size_t i = 1; i < ParamCap; ++i) {
 		if (!msg->params[i]) break;
 		char *key = strsep(&msg->params[i], "=");
 		if (!msg->params[i]) continue;
 		if (!strcmp(key, "NETWORK")) {
+			set(&self.network, msg->params[i]);
 			uiFormat(
 				Network, Cold, tagTime(msg),
 				"You arrive in %s", msg->params[i]
 			);
+		} else if (!strcmp(key, "CHANTYPES")) {
+			set(&self.chanTypes, msg->params[i]);
+		} else if (!strcmp(key, "PREFIX")) {
+			strsep(&msg->params[i], ")");
+			if (!msg->params[i]) continue;
+			set(&self.prefixes, msg->params[i]);
 		}
 	}
 }