Skip to content

Commit

Permalink
Merge pull request #125 from gsf/sasl
Browse files Browse the repository at this point in the history
Added SASL support
  • Loading branch information
martynsmith committed Sep 6, 2013
2 parents 6108735 + 0dd7ac1 commit bafa696
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 6 additions & 2 deletions docs/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Client
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
sasl: false,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
Expand All @@ -47,14 +48,17 @@ Client
`floodProtectionDelay` sets the amount of time that the client will wait
between sending subsequent messages when `floodProtection` is enabled.

`messageSplit` will split up large messages sent with the `say` method
into multiple messages of length fewer than `messageSplit` characters.
Set `sasl` to true to enable SASL support. You'll also want to set `nick`,
`userName`, and `password` for authentication.

`stripColors` removes mirc colors (0x03 followed by one or two ascii
numbers for foreground,background) and ircII "effect" codes (0x02
bold, 0x1f underline, 0x16 reverse, 0x0f reset) from the entire
message before parsing it and passing it along.

`messageSplit` will split up large messages sent with the `say` method
into multiple messages of length fewer than `messageSplit` characters.

Setting `autoConnect` to false prevents the Client from connecting on
instantiation. You will need to call `connect()` on the client instance::

Expand Down
26 changes: 25 additions & 1 deletion lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Client(server, nick, opt) {
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
sasl: false,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
Expand Down Expand Up @@ -511,6 +512,26 @@ function Client(server, nick, opt) {
// who, reason, channels
self.emit('quit', message.nick, message.args[0], channels, message);
break;

// for sasl
case "CAP":
if ( message.args[0] === '*' &&
message.args[1] === 'ACK' &&
message.args[2] === 'sasl ' ) // there's a space after sasl
self.send("AUTHENTICATE", "PLAIN");
break;
case "AUTHENTICATE":
if ( message.args[0] === '+' ) self.send("AUTHENTICATE",
new Buffer(
self.opt.nick + '\0' +
self.opt.userName + '\0' +
self.opt.password
).toString('base64'));
break;
case "903":
self.send("CAP", "END");
break;

case "err_umodeunknownflag":
if ( self.opt.showErrors )
util.log("\033[01;31mERROR: " + util.inspect(message) + "\033[0m");
Expand Down Expand Up @@ -615,7 +636,10 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
self.conn.setTimeout(0);
self.conn.setEncoding('utf8');
self.conn.addListener("connect", function () {
if ( self.opt.password !== null ) {
if ( self.opt.sasl ) {
// see http://ircv3.atheme.org/extensions/sasl-3.1
self.send("CAP REQ", ":sasl");
} else if ( self.opt.password !== null ) {
self.send( "PASS", self.opt.password );
}
self.send("NICK", self.opt.nick);
Expand Down

0 comments on commit bafa696

Please sign in to comment.