meebey / SmartIrc4net

IRC C# Library
http://www.meebey.net/projects/smartirc4net/
Other
126 stars 52 forks source link

IRCv3 capability negotation #39

Closed djkaty closed 8 years ago

djkaty commented 9 years ago

This enables clients to send CAP LS, CAP LIST, CAP REQ and CAP END commands and receive events (OnCapLsReply, OnCapListReply, OnCapAckReply and OnCapNakReply) to query and notify about available, activated, allowed and denied caps and cap requests.

Fully compatible with IRCv3.2, partially compatible with IRCv3.1. Tested on Freenode, Efnet, IRCnet and Twitch.

With no code modifications the client will continue to use IRC 2 as per RFC2812. Use the IrcClient.UseIrcV3 property to enable caps negotiation. This negotiation is started by IrcClient as soon as the connection is made because although servers are lax, it is meant to be completed before attempting to log in.

Vendor-specialized and caps with optional arguments are supported as per the IRCv3 working group's spec at http://ircv3.net/specs/core/capability-negotiation-3.1.html and http://ircv3.net/specs/core/capability-negotiation-3.2.html.

Note that the code automatically calls CAP END after CAP REQ, this is a problem that can cause caps negotiation to be interspersed with login because IrcClient.Listen() is not called until afterwards, so the read thread has no opportunity to respond before login is attempted even though the data will be received by the connection. To use the truly correct flow, the code needs to be re-engineered so that it starts listening as soon as Connect() completes and makes Listen() unnecessary any longer (a moderately easy fix I believe). In practice, this causes no problems on any of the IRC servers I tested with.

IRCv3 message tags next :) (although I need this approved first as one depends on the other)

djkaty commented 9 years ago

I see the build error. Not sure why it is doing that, get-only properties are valid C# and it compiles fine here.

meebey commented 9 years ago

IRCv3 <3

Did you know that someone else made a SASL patch for Smuxi with CAP parsing I think but it couldn't be merged because he rewrote the message parser and left it with zillion regression :(

meebey commented 9 years ago

I noticed you had to send the IRCv3 negotiation in a overridden Connect() method of IrcClient. I wonder if IRCv3 support shouldn't be in IrcConnection instead. IMHO for SmartIrc4net2 (or name it 3 for IRCv3 support :-D) we should discuss if the current class hierarchy makes sense or should be changed.

djkaty commented 9 years ago

Agree on all changes. I didn't know about the sasl patch, do note that my code does nothing with sasl, it's pure caps negotiation, just FYI :)

I believe that putting caps negotiation in IrcClient is correct because it's an application-layer action. IrcConnection deals with the network/transport layer, read/write threads and queues etc. IrcClient does all the application-layer parsing which is how caps are negotiated.

I vote for SmartIrc4net 3 as the name, I'd already thought of it :)

I actually think the class hierarchy is more or less ok as it is. I considered deriving IrcClient to make IrcClient3 or some such instead of using a property to activate it but it just seems like an unnecessary over-complication to start making everything protected virtual and having to call base methods especially when alot of the IRCv3 stuff needs changes interplexed with the main parsing and message dispatching.

djkaty commented 9 years ago

New diff available. See my comments above.