summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--chat.c2
-rw-r--r--chat.h2
-rw-r--r--command.c12
-rw-r--r--handle.c6
4 files changed, 14 insertions, 8 deletions
diff --git a/chat.c b/chat.c
index e998812..9e3e374 100644
--- a/chat.c
+++ b/chat.c
@@ -64,7 +64,7 @@ enum Color idColors[IDCap] = {
 };
 uint idNext = Network + 1;
 
-struct Network network;
+struct Network network = { .userLen = 9, .hostLen = 63 };
 struct Self self = { .color = Default };
 
 static const char *save;
diff --git a/chat.h b/chat.h
index 468d864..3f93f3d 100644
--- a/chat.h
+++ b/chat.h
@@ -84,6 +84,8 @@ static inline enum Color hash(const char *str) {
 
 extern struct Network {
 	char *name;
+	uint userLen;
+	uint hostLen;
 	char *chanTypes;
 	char *prefixes;
 	char *prefixModes;
diff --git a/command.c b/command.c
index 9341310..f53cbe7 100644
--- a/command.c
+++ b/command.c
@@ -55,14 +55,12 @@ static void echoMessage(char *cmd, uint id, char *params) {
 
 static void splitMessage(char *cmd, uint id, char *params) {
 	if (!params) return;
-	// FIXME: Get USERLEN, HOSTLEN from ISUPPORT and assume worst case if
-	// self.user and self.host are unset?
-	const char *nick = self.nick;
-	const char *user = (self.user ? self.user : "*");
-	const char *host = (self.host ? self.host : "*");
 	int overhead = snprintf(
-		NULL, 0, ":%s!%s@%s %s %s :\r\n",
-		nick, user, host, cmd, idNames[id]
+		NULL, 0, ":%s!%*s@%*s %s %s :\r\n",
+		self.nick,
+		(self.user ? 0 : network.userLen), (self.user ? self.user : "*"),
+		(self.host ? 0 : network.hostLen), (self.host ? self.host : "*"),
+		cmd, idNames[id]
 	);
 	assert(overhead > 0 && overhead < 512);
 	int chunk = 512 - overhead;
diff --git a/handle.c b/handle.c
index f079c00..376e722 100644
--- a/handle.c
+++ b/handle.c
@@ -238,6 +238,12 @@ static void handleReplyISupport(struct Message *msg) {
 				Network, Cold, tagTime(msg),
 				"You arrive in %s", msg->params[i]
 			);
+		} else if (!strcmp(key, "USERLEN")) {
+			if (!msg->params[i]) continue;
+			network.userLen = strtoul(msg->params[i], NULL, 10);
+		} else if (!strcmp(key, "HOSTLEN")) {
+			if (!msg->params[i]) continue;
+			network.hostLen = strtoul(msg->params[i], NULL, 10);
 		} else if (!strcmp(key, "CHANTYPES")) {
 			if (!msg->params[i]) continue;
 			set(&network.chanTypes, msg->params[i]);