diff options
author | Robin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-09-30 18:45:09 +0000 |
---|---|---|
committer | Robin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-09-30 18:45:09 +0000 |
commit | 902ef1ce040903dcfc8fe7adb54635a3681c0712 (patch) | |
tree | 674918fe6456eebbe78488c65d1af6f584ae7e80 /src | |
parent | d2d64e17e730848eaa7081c6bd6eddcea8973428 (diff) |
Add User::SetNewNick() method, to be called from ircd protocol.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1188 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r-- | src/users.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/users.c b/src/users.c index 1653d5922..83897fecf 100644 --- a/src/users.c +++ b/src/users.c @@ -64,49 +64,49 @@ User::User(const std::string &nick) this->nickTrack = NULL; /* ensure no default tracking nick */ } +void User::SetNewNick(const std::string &newnick) +{ + User **list; + int is_same; -/*************************************************************************/ -/*************************************************************************/ + /* Sanity check to make sure we don't segfault */ + if (newnick.empty()) + { + throw "User::SetNewNick() got a bad argument"; + } -/* Change the nickname of a user, and move pointers as necessary. */ + is_same = (!stricmp(this->nick, nick) ? 1 : 0); -static void change_user_nick(User * user, const char *nick) -{ - User **list; - int is_same; + if (this->prev) + this->prev->next = this->next; + else + userlist[HASH(this->nick)] = this->next; - /* Sanity check to make sure we don't segfault */ - if (!user || !nick || !*nick) { - return; - } + if (this->next) + this->next->prev = this->prev; - is_same = (!stricmp(user->nick, nick) ? 1 : 0); + strscpy(this->nick, nick, NICKMAX); + list = &userlist[HASH(this->nick)]; + this->next = *list; + this->prev = NULL; - if (user->prev) - user->prev->next = user->next; - else - userlist[HASH(user->nick)] = user->next; - if (user->next) - user->next->prev = user->prev; - user->nick[1] = 0; /* paranoia for zero-length nicks */ - strscpy(user->nick, nick, NICKMAX); - list = &userlist[HASH(user->nick)]; - user->next = *list; - user->prev = NULL; - if (*list) - (*list)->prev = user; - *list = user; - - /* Only if old and new nick aren't the same; no need to waste time */ - if (!is_same) { - if (user->na) - user->na->u = NULL; - user->na = findnick(nick); - if (user->na) - user->na->u = user; - } + if (*list) + (*list)->prev = this; + *list = this; + + /* Only if old and new nick aren't the same; no need to waste time */ + if (!is_same) + { + if (this->na) + this->na->u = NULL; + this->na = findnick(nick); + if (this->na) + this->na->u = this; + } } + +/*************************************************************************/ /*************************************************************************/ void update_host(User * user) @@ -704,7 +704,7 @@ User *do_nick(const char *source, char *nick, char *username, char *host, if (stricmp(nick, user->nick) == 0) { /* No need to redo things */ - change_user_nick(user, nick); + user->SetNewNick(nick); nc_changed = 0; } else { /* Update this only if nicks aren't the same */ @@ -718,7 +718,7 @@ User *do_nick(const char *source, char *nick, char *username, char *host, cancel_user(user); } - change_user_nick(user, nick); + user->SetNewNick(nick); send_event(EVENT_CHANGE_NICK, 1, nick); if ((old_na ? old_na->nc : NULL) == |