summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2026-02-13 12:17:02 +0300
committerNakidai <nakidai@disroot.org>2026-02-14 00:20:38 +0300
commit15151c88a7eb381fb5b46daaf521fc609d40539c (patch)
treeaa2991b21156e10477649a436f81f530d750d953
parent3e58f0366205de63b10e9379c9b738dd80664fde (diff)
downloadlibreircd-15151c88a7eb381fb5b46daaf521fc609d40539c.tar.gz
libreircd-15151c88a7eb381fb5b46daaf521fc609d40539c.zip
Fix & Refactor NAMES
When generating a string to respond, there's a condition to either put
a space and continue or the send string and start collecting again. If
after the loop send buffer is non-empty, it should be sent as well.

But there's an issue: that last line after the loop contains a trailing
whitespace. So some clients can put a comma to the end and some bots
probably can even break because of that.

One solution is to simply buf[strlen(buf)-1]=0; but this doesn't feel
right. My solution is to add a check to the condition in loop whether
this iteration is last. If so - print. By the way this eliminates the
need in post-loop condition reducing reply(353) duplication
-rw-r--r--handle.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/handle.c b/handle.c
index 8c36a73..684c2ee 100644
--- a/handle.c
+++ b/handle.c
@@ -298,7 +298,8 @@ names(struct Message *msg, struct Peer *peer)
 			else if (chpp->modes & CHANNEL_VOICE)
 				strlcat(buf, "+", sizeof(buf));
 			strlcat(buf, peer->channels[i]->peers[j].p->nick, sizeof(buf));
-			if (strlen(buf) >= MESSAGE_MAX - 4*PEER_NICK_MAX)
+			if (strlen(buf) >= MESSAGE_MAX - 4*PEER_NICK_MAX
+			 || j + 1 == peer->channels[i]->peers_c)
 			{
 				reply(peer, 353, peer->channels[i]->name, buf);
 				memset(buf, 0, sizeof(buf));
@@ -307,8 +308,6 @@ names(struct Message *msg, struct Peer *peer)
 				strlcat(buf, " ", sizeof(buf));
 			}
 		}
-		if (*buf)
-			reply(peer, 353, peer->channels[i]->name, buf);
 	}
 
 	reply(peer, 366, msg->params[0] ? msg->params[0] : "*");