From 0a31bcd5ae19e94827aec1a475ede69501b8230e Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 15 Dec 2005 14:19:37 +0000 Subject: Moved rehashnick and force_nickchange to users.cpp git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2478 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/users.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index 8e5d996da..57091aea1 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -714,3 +714,67 @@ void ConnectUser(userrec *user) } } +/* re-allocates a nick in the user_hash after they change nicknames, + * returns a pointer to the new user as it may have moved */ + +userrec* ReHashNick(char* Old, char* New) +{ + //user_hash::iterator newnick; + user_hash::iterator oldnick = clientlist.find(Old); + + log(DEBUG,"ReHashNick: %s %s",Old,New); + + if (!strcasecmp(Old,New)) + { + log(DEBUG,"old nick is new nick, skipping"); + return oldnick->second; + } + + if (oldnick == clientlist.end()) return NULL; /* doesnt exist */ + + log(DEBUG,"ReHashNick: Found hashed nick %s",Old); + + userrec* olduser = oldnick->second; + clientlist[New] = olduser; + clientlist.erase(oldnick); + + log(DEBUG,"ReHashNick: Nick rehashed as %s",New); + + return clientlist[New]; +} + +void force_nickchange(userrec* user,const char* newnick) +{ + char nick[MAXBUF]; + int MOD_RESULT = 0; + + strcpy(nick,""); + + FOREACH_RESULT(OnUserPreNick(user,newnick)); + if (MOD_RESULT) { + stats->statsCollisions++; + kill_link(user,"Nickname collision"); + return; + } + if (matches_qline(newnick)) + { + stats->statsCollisions++; + kill_link(user,"Nickname collision"); + return; + } + + if (user) + { + if (newnick) + { + strncpy(nick,newnick,MAXBUF); + } + if (user->registered == 7) + { + char* pars[1]; + pars[0] = nick; + handle_nick(pars,1,user); + } + } +} + -- cgit v1.2.3