- /* if we're doing an LS, then we only send this if
- * they havent ack'd
- */
- if(clicap_list[i].cap_cli &&
- (!flags || !IsCapable(source_p, clicap_list[i].cap_cli)))
- {
- *p++ = '~';
- buflen++;
+ if (!clicap_visible(source_p, entry))
+ continue;
+
+ if (!flags && (source_p->flags & FLAGS_CLICAP_DATA) && clicap != NULL && clicap->data != NULL)
+ data = clicap->data(source_p);
+
+ for (int attempts = 0; attempts < 2; attempts++) {
+ if (rb_snprintf_try_append(buf_list, max_list, "%s%s%s%s",
+ buf_list[0] == '\0' ? "" : " ", /* space between caps */
+ entry->cap,
+ data != NULL ? "=" : "", /* '=' between cap and data */
+ data != NULL ? data : "") < 0
+ && buf_list[0] != '\0') {
+
+ if (!(source_p->flags & FLAGS_CLICAP_DATA)) {
+ /* the client doesn't support multiple lines */
+ continue;
+ }
+
+ /* doesn't fit in the buffer, output what we have */
+ sendto_one(source_p, "%s%s%s", buf_prefix, str_cont, buf_list);
+
+ /* reset the buffer and go around the loop one more time */
+ buf_list[0] = '\0';
+ } else {
+ break;