Skip to content

Add IRCv3 CAP negotiation skeleton with a static capability registry - #269

Open
devin-ai-integration[bot] wants to merge 6 commits into
masterfrom
devin/1791945726-ircv3-cap
Open

devin-ai-integration[bot] wants to merge 6 commits into
masterfrom
devin/1791945726-ircv3-cap

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

Adds IRCv3 client capability negotiation (CAP, version 302) as the base for adding individual caps in later small PRs. Caps are registered statically in core. Bahamut's hook modules can't add commands or change the registration handshake, so caps can't live in modules for now. This PR is independent of #268, which keeps server-side CAPAB and treats the existing server caps as the baseline. Client caps (clientcaps[]/caps) and server caps (servcapabs[]/capabilities) are separate registries.

Adding a cap later looks like this:

/* include/caps.h */
#define CAP_AWAY_NOTIFY (1ULL << 1)
/* src/caps.c clientcaps[] */
{ "away-notify", CAP_AWAY_NOTIFY, NULL, 0 },
/* wherever behavior changes */
if (HasCap(acptr, CAP_AWAY_NOTIFY)) ...

Negotiation (src/caps.c, m_cap):

  • CAP LS [302]: lists the caps. 302 clients get name=value pairs and multi-line replies with a * continuation marker. Lines are split at CAP_LINELEN.
  • CAP LIST: shows the caps enabled for this client, without values even for 302 clients (the spec allows values only in LS/NEW).
  • CAP REQ :a -b: applied all-or-nothing. A copy of sptr->caps is edited and stored only on ACK; a NAK changes nothing. A - prefix disables a cap.
    • A REQ with an empty or all-space list → 461.
    • A REQ longer than CAP_LINELEN can't be echoed in one ACK. It is NAKed without any change, and the echoed list is cut at the last whole token.
  • CAP END: resumes registration.
  • Unknown subcommand → 410 ERR_INVALIDCAPCMD. Missing subcommand → 461.
  • Registration hold: the first CAP LS/CAP REQ from an unregistered client sets FLAGS_CAPNEGO, via SetCapNegotiating(). While it is set, m_nick/m_user don't call register_user(); CAP END clears the flag and calls it once both NICK and USER have arrived. Those are the only local register_user() callers. Clients that never send CAP register as before, and a client that never sends END is still dropped by CONNECTTIMEOUT.
  • cap-notify is the only built-in cap. CAP LS 302 turns it on implicitly, and after that it can't be disabled (CAPF_STICKY_302).

New local-only aClient fields: uint64_t caps (64 caps) and int cap_version. They come after count, so they aren't allocated for remote clients, and HasCap() checks MyConnect first. FLAGS_CAPNEGO takes the free 0x010000 bit in flags. sizeof(aClient) goes from 1816 to 1832 on x86_64, and CLIENT_REMOTE_SIZE is unchanged. The register_user() prototype moved to include/h.h.

CAP NEW/CAP DEL aren't sent yet, because caps can't change at runtime.

Testing

tools/testnet (#270) on this branch: all 17 tests pass (11 CAP, 6 link). Build warning count is unchanged (15).

Link to Devin session: https://app.devin.ai/sessions/9c171b7fd3d341178646e3cce156ddd7
Open in Devin Desktop: https://app.devin.ai/desktop/session/9c171b7fd3d341178646e3cce156ddd7?variant=devin
Requested by: @eaescob

Implements CAP LS [302], LIST, REQ and END. Capabilities are listed in
clientcaps[] in caps.c and checked with HasCap(). Registration is held
from the first CAP LS/REQ until CAP END. REQ is applied atomically
(ACK or NAK for the whole list, -cap disables). cap-notify is the only
built-in capability and is enabled implicitly by CAP LS 302.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

eaescob and others added 5 commits October 28, 2026 18:33
…ter_user in h.h

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant