alexyoung / ircd.js

A Node ircd (IRC daemon)
GNU General Public License v3.0
528 stars 90 forks source link

PMs break when changing nick without joining channel #16

Closed treeform closed 12 years ago

treeform commented 12 years ago

Repro: start server join with two clients do not join any channels! /msg eash other change /nick on one of the clients now that client cant be msged any more

The irc client gets confused to what the user's nick is because the change nick command is not sent to it.

In this code:

NICK: function(user, nick) { ..... user.channels.forEach(function(channel) { channel.send(user.mask, 'NICK', ':' + nick); });

The new nick command is only sent to channels that nick is in. But if the users is not in any channels he never gets the command that he got the new nick.

I am not sure how to send nick changed command directly to client, i tried this: user.send(user.mask, 'NICK', ':' + nick);

but it does not seem to work.

alexyoung commented 12 years ago

Thanks, I'll check it out

treeform commented 12 years ago

I have changed the nick function to this, it looks like its working:

NICK: function(user, nick) {
    var oldMask = user.mask;

    if (!nick || nick.length === 0) {
      return user.send(this.host, irc.errors.noNickGiven, ':No nickname given');
    } else if (nick === user.nick) {
      return;
    } else if (nick.length > 9 || nick.match(irc.validations.invalidNick)) {
      return user.send(this.host, irc.errors.badNick, (user.nick || ''), nick, ':Erroneus nickname');
    } else if (this.valueExists(nick, this.users.registered, 'nick')) {
      return user.send(this.host, irc.errors.nameInUse, '*', nick, ':is already in use');
    }
    nick = nick.trim();
    // send the the fact that your name changed to yourself first
    user.send(user.mask, 'NICK', ':' + nick);
    user.channels.forEach(function(channel) {
      channel.send(user.mask, 'NICK', ':' + nick);
    });

    user.nick = nick;
    user.register();
  },
alexyoung commented 12 years ago

Yep, that works, I'll release an update with that in