Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix server capabilities handling #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions Classes/IRC/IRCClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -2985,14 +2985,50 @@ - (void)receivePing:(IRCMessage*)m
[self startPongTimer];
}

// This is version 3.1 of the IRC capability negotiation protocol extension
// ( http://ircv3.atheme.org/specification/capability-negotiation-3.1 )
- (void)receiveCap:(IRCMessage*)m
{
if (_isLoggedIn) return;
if (_isLoggedIn) {
[self send:CAP, @"END", nil];
return;
}

NSString* command = [m paramAt:1];
NSString* params = [[m paramAt:2] trim];

if ([command isEqualNoCase:@"ack"]) {
// reply from server indicating supported capabilities
if ([command isEqualNoCase:@"LS"]) {
LOG(@"Server supports capabilities: %@", params);

NSArray* caps = [params componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSMutableString* requestedCaps = [NSMutableString new];

for (NSString* cap in caps) {
if ([cap isEqualToString:@"znc.in/server-time"]) {
[requestedCaps appendString:@"znc.in/server-time "];

} else if ([cap isEqualToString:@"znc.in/server-time-iso"]) {
[requestedCaps appendString:@"znc.in/server-time-iso "];

} else if ([cap isEqualToString:@"sasl"]) {
if (_config.useSASL && _config.nick.length && _config.nickPassword.length) {
[requestedCaps appendString:@"sasl "];
}
}
}

if (requestedCaps.length > 0) {
[self send:CAP, @"REQ", requestedCaps, nil];
}

// Client must send CAP END to continue registration
[self send:CAP, @"END", nil];

// accepted/enabled capabilities
} else if ([command isEqualNoCase:@"ACK"]) {
LOG(@"Using capabilities: %@", params);

if ([params isEqualNoCase:@"sasl"]) {
[self send:AUTHENTICATE, @"PLAIN", nil];
}
Expand Down Expand Up @@ -3667,25 +3703,18 @@ - (void)ircConnectionDidConnect:(IRCConnection*)sender
NSString* realName = _config.realName;
if (!user.length) user = _config.nick;
if (!realName.length) realName = _config.nick;

if (_config.useSASL) {
// If you send REQ to some servers (hyperion or etc) before PASS, the server refuses connection.
// To avoid this, do not send REQ if SASL setting is off.
[self send:CAP, @"REQ", @"znc.in/server-time", nil];
[self send:CAP, @"REQ", @"znc.in/server-time-iso", nil];

if (_config.nick.length && _config.nickPassword.length) {
[self send:CAP, @"REQ", @"sasl", nil];
}
}


[self send:CAP, @"LS", nil];

if (_config.password.length) {
[self send:PASS, _config.password, nil];
}

[self send:NICK, _sentNick, nil];
[self send:USER, user, [NSString stringWithFormat:@"%d", modeParam], @"*", realName, nil];



[self updateClientTitle];
}

Expand Down