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

Hacky fix for missing quit messages when spam control was ON #100

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 21 additions & 12 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ Client.prototype.prefixForMode = {};
Client.prototype.modeForPrefix = {};
Client.prototype.chans = {};
Client.prototype._whoisData = {};
Client.prototype.queueEmpty = true;
Client.prototype.chanData = function( name, create ) { // {{{
var key = name.toLowerCase();
if ( create ) {
Expand Down Expand Up @@ -587,26 +588,31 @@ Client.prototype.disconnect = function ( message, callback ) { // {{{
}
message = message || "node-irc says goodbye";
var self = this;
if ( self.conn.readyState == 'open' ) {
if ( self.conn.writable ) {
self.conn.removeAllListeners('close');
self.send( "QUIT", message );
}
self.conn.requestedDisconnect = true;
if (typeof(callback) === 'function') {
self.conn.once('end', callback);
}
self.conn.end();
var intv = setInterval(function () {
if (self.queueEmpty) {
self.conn.requestedDisconnect = true;
self.conn.end();
clearInterval(intv);
}
}, 100);
}; // }}}
Client.prototype.send = function(command) { // {{{
var args = Array.prototype.slice.call(arguments);
var args = [];
for ( var k in arguments )
args.push(arguments[k]);
args[args.length-1] = ":" + args[args.length-1];

// Remove the command
args.shift();

if ( args[args.length-1].match(/\s/) ) {
args[args.length-1] = ":" + args[args.length-1];
}

if ( this.opt.debug )
if ( this.opt.debug && ! this.conn.requestedDisconnect )
util.log('SEND: ' + command + " " + args.join(" "));

if ( ! this.conn.requestedDisconnect ) {
Expand All @@ -624,13 +630,16 @@ Client.prototype.activateFloodProtection = function(interval) { // {{{
// Wrapper for the original function. Just put everything to on central
// queue.
this.send = function() {
self.queueEmpty = false;
cmdQueue.push(arguments);
};

dequeue = function() {
var args = cmdQueue.shift();
if (args) {
origSend.apply(self, args);
} else {
self.queueEmpty = true;
}
};

Expand Down Expand Up @@ -781,9 +790,9 @@ function parseMessage(line, stripColors) { // {{{

// Parse parameters
if ( line.indexOf(':') != -1 ) {
match = line.match(/(.*)(?:^:|\s+:)(.*)/);
middle = match[1].trimRight();
trailing = match[2];
var index = line.indexOf(':');
middle = line.substr(0, index).replace(/ +$/, "");
trailing = line.substr(index+1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the lines above, @tuhoojabotti might have something to say. This part of the pull request is not made by me.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recollect doing that code, maybe it's probably a change on master that is not yet in the NPM package or something.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it was made by pull rq #91. Perhaps I should merge the master branch of node-irc to my fork...

}
else {
middle = line;
Expand Down