X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=35a0e716fe50ecb88639e4078a25a61a65dc9227;hb=2b3394855d5adddb16285b905503d9ffe5a1d963;hp=ccf506697142040fd0d4199e0796e12abe57bd5c;hpb=d0d36795e807cf72295c6e73813e0c2daa0a71e7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index ccf506697..35a0e716f 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -12,9 +12,6 @@ */ #include "inspircd.h" -#include "configreader.h" -#include "channels.h" -#include "users.h" #include #include "socketengine.h" #include "wildcard.h" @@ -323,10 +320,9 @@ void userrec::DecrementModes() } } -userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance) +userrec::userrec(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance) { - // the PROPER way to do it, AVOID bzero at *ALL* costs - *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0; + *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = *uuid = 0; server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName); reset_due = ServerInstance->Time(); age = ServerInstance->Time(true); @@ -346,6 +342,19 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance) memset(snomasks,0,sizeof(snomasks)); /* Invalidate cache */ operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL; + + if (uid.empty()) + strlcpy(uuid, Instance->GetUID().c_str(), UUID_LENGTH); + else + strlcpy(uuid, uid.c_str(), UUID_LENGTH); + + ServerInstance->Log(DEBUG,"New UUID for user: %s (%s)", uuid, uid.empty() ? "allocated new" : "used remote"); + + user_hash::iterator finduuid = Instance->uuidlist->find(uuid); + if (finduuid == Instance->uuidlist->end()) + (*Instance->uuidlist)[uuid] = this; + else + throw CoreException("Duplicate UUID "+std::string(uuid)+" in userrec constructor"); } void userrec::RemoveCloneCounts() @@ -392,6 +401,8 @@ userrec::~userrec() } #endif } + + ServerInstance->uuidlist->erase(uuid); } char* userrec::MakeHost() @@ -859,8 +870,14 @@ void userrec::AddToWhoWas() /* add a client connection to the sockets list */ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip) { - std::string tempnick = ConvToStr(socket) + "-unknown"; - user_hash::iterator iter = Instance->clientlist->find(tempnick); + /* NOTE: Calling this one parameter constructor for userrec automatically + * allocates a new UUID and places it in the hash_map. + */ + userrec* New = new userrec(Instance); + int j = 0; + + Instance->unregistered_count++; + char ipaddr[MAXBUF]; #ifdef IPV6 if (socketfamily == AF_INET6) @@ -868,31 +885,12 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, else #endif inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr)); - userrec* New; - int j = 0; - Instance->unregistered_count++; + (*(Instance->clientlist))[New->uuid] = New; + New->SetFd(socket); - /* - * fix by brain. - * as these nicknames are 'RFC impossible', we can be sure nobody is going to be - * using one as a registered connection. As they are per fd, we can also safely assume - * that we wont have collisions. Therefore, if the nick exists in the list, its only - * used by a dead socket, erase the iterator so that the new client may reclaim it. - * this was probably the cause of 'server ignores me when i hammer it with reconnects' - * issue in earlier alphas/betas - */ - if (iter != Instance->clientlist->end()) - { - userrec* goner = iter->second; - DELETE(goner); - Instance->clientlist->erase(iter); - } - - New = new userrec(Instance); - (*(Instance->clientlist))[tempnick] = New; - New->fd = socket; - strlcpy(New->nick,tempnick.c_str(),NICKMAX-1); + /* The users default nick is their UUID */ + strlcpy(New->nick, New->uuid, NICKMAX - 1); New->server = Instance->FindServerNamePtr(Instance->Config->ServerName); /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */ @@ -1099,6 +1097,9 @@ void userrec::FullConnect() ServerInstance->Config->Send005(this); + this->WriteServ("042 %s %s :your unique ID", this->nick, this->uuid); + + this->ShowMOTD(); /* Now registered */ @@ -1192,7 +1193,15 @@ bool userrec::ForceNickChange(const char* newnick) if (this->registered == REG_ALL) { - return (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS); + std::deque dummy; + command_t* nickhandler = ServerInstance->Parser->GetHandler("NICK"); + if (nickhandler) + { + nickhandler->HandleInternal(1, dummy); + bool result = (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS); + nickhandler->HandleInternal(0, dummy); + return result; + } } return false; }