summary refs log tree commit diff
path: root/command.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-03-23 13:13:43 -0400
committerJune McEnroe <june@causal.agency>2020-03-23 13:25:10 -0400
commitcf1545870af2de418a6bccd4461f92330dc2f605 (patch)
tree48f674ba07d1d7e8fd223bc357abdf645b441803 /command.c
parentImplement message splitting (diff)
downloadcatgirl-cf1545870af2de418a6bccd4461f92330dc2f605.tar.gz
catgirl-cf1545870af2de418a6bccd4461f92330dc2f605.zip
Assume worst case for unknown user and host in splitMessage
The default USERLEN of 9 doesn't have a great source, the RFC only says
that nicks are length 9, so my assumption is that usernames are not
longer.
Diffstat (limited to 'command.c')
-rw-r--r--command.c12
1 files changed, 5 insertions, 7 deletions
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;