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(lib/irc): Use protected loops when iterating channels to remove users #187

Merged
merged 1 commit into from
May 29, 2014
Merged
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: 14 additions & 19 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,12 @@ function Client(server, nick, opt) {
var channels = [];

// TODO better way of finding what channels a user is in?
for ( var channame in self.chans ) {
Object.keys(self.chans).forEach(function(channame) {
var channel = self.chans[channame];
if ( 'string' == typeof channel.users[message.nick] ) {
channel.users[message.args[0]] = channel.users[message.nick];
delete channel.users[message.nick];
channels.push(channame);
}
}
channel.users[message.args[0]] = channel.users[message.nick];
delete channel.users[message.nick];
channels.push(channame);
});

// old nick, new nick, channels
self.emit('nick', message.nick, message.args[0], channels, message);
Expand Down Expand Up @@ -452,12 +450,11 @@ function Client(server, nick, opt) {
case "KILL":
var nick = message.args[0];
var channels = [];
for ( var channel in self.chans ) {
if ( self.chans[channel].users[nick])
channels.push(channel);

delete self.chans[channel].users[nick];
}
Object.keys(self.chans).forEach(function(channame) {
var channel = self.chans[channame];
channels.push(channame);
delete channel.users[nick];
});
self.emit('kill', nick, message.args[1], channels, message);
break;
case "PRIVMSG":
Expand Down Expand Up @@ -499,13 +496,11 @@ function Client(server, nick, opt) {
var channels = [];

// TODO better way of finding what channels a user is in?
for ( var channame in self.chans ) {
Object.keys(self.chans).forEach(function(channame) {
var channel = self.chans[channame];
if ( 'string' == typeof channel.users[message.nick] ) {
delete channel.users[message.nick];
channels.push(channame);
}
}
delete channel.users[message.nick];
channels.push(channame);
});

// who, reason, channels
self.emit('quit', message.nick, message.args[0], channels, message);
Expand Down