communi / libcommuni

A cross-platform IRC framework for Qt
https://communi.github.io
BSD 3-Clause "New" or "Revised" License
84 stars 37 forks source link

Add a way to send messages to the server before authenticating #98

Closed zneix closed 3 years ago

zneix commented 3 years ago

This Pull Request adds a new property to connection class - authMessages, which will contain messages that can be specified and sent to the server before sending PASS and NICK. This is very necessary in my case - after successfully authenticating to Twitch IRC servers it can send us a GLOBALUSERSTATE message, but only if a special message before authenticating has been sent. Without this feature I was not able to receive the mentioned message in any way.

I hope my documentation, tests and comments are clear. I'll be happy to clarify everything and I hope I can get this merged into master, If possible, please use Squash & Merge as this PR is quite big.

jpnurmi commented 3 years ago

According to https://dev.twitch.tv/docs/irc/tags#globaluserstate-twitch-tags, requesting GLOBALUSERSTATE is a matter of requesting the twitch.tv/tags capability.

In order to request capabilities with libcommuni, you can call IrcNetwork::setRequestedCapabilities() before calling IrcConnection::open():

connection->network()->setRequestedCapabilities({"twitch.tv/tags"});

P.S. You can also combine the list of requested capabilities with Irc::supportedCapabilities() that lists all capabilities that are "explicitly" supported by the framework.

zneix commented 3 years ago

I tried the solution you've proposed, but it doesn't seem to cut it, here's some relevant logs:

c2logs

I'm assuming that libcommuni requests those capabilities only after authenticating, which is a problem because I need to send CAP REQ before I send PASS and NICK to the server. Otherwise, I won't receive the message at all. I realize that my addition is perhaps very hacky and not the ideal fix for this, but maybe something related to how libcommuni requests capabilities could be done?

jpnurmi commented 3 years ago

Right. I don't remember the details and I'm stuck on phone right now, but I recall there's some validation against the actual available capabilities so it would wait until the CAP LS response before sending CAP REQ. Anyway, it would be fine to add this functionality to IrcNetwork together with the other capability functionality. Maybe just a flag if the caps should be validated or not and if not, send the request right away. How does that sound?

zneix commented 3 years ago

the other capability functionality

You mean this?: "Maybe just a flag if the caps should be validated or not and if not, send the request right away." If so, sounds good to me :+1: Twitch shouldn't change their capabilities so we could just skip capability checking in general

Anyway, it would be fine to add this functionality to IrcNetwork

Just to be sure, you're talking about subject of my PR, right? If so, yes I'm down for this but if not I'd be also fine with skipping capability validation as that'd cover my usecase.