]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
fixed std:: stuff
[user/henk/code/inspircd.git] / src / users.cpp
index 2f1c86a33a62e223f6bd84e0d39e3d56fffc500b..edcc54be56b7f9c5a2f7ae84f68a2c8834cb7100 100644 (file)
@@ -181,7 +181,7 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
        Penalty = 0;
        lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
        ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0;
-       OverPenalty = ExemptFromPenalty = muted = exempt = haspassed = dns_done = false;
+       OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
        fd = -1;
        recvq.clear();
        sendq.clear();
@@ -196,7 +196,7 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
        memset(modes,0,sizeof(modes));
        memset(snomasks,0,sizeof(snomasks));
        /* Invalidate cache */
-       operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
+       cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
 
        if (uid.empty())
                strlcpy(uuid, Instance->GetUID().c_str(), UUID_LENGTH);
@@ -205,25 +205,11 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
 
        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;
+       user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
+       if (finduuid == Instance->Users->uuidlist->end())
+               (*Instance->Users->uuidlist)[uuid] = this;
        else
                throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
-
-       (*(Instance->clientlist))[this->uuid] = this;
-
-       /* The users default nick is their UUID */
-       strlcpy(this->nick, this->uuid, NICKMAX - 1);
-
-       this->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
-       /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
-       strcpy(this->ident, "unknown");
-
-       this->registered = REG_NONE;
-       this->signon = Instance->Time() + Instance->Config->dns_timeout;
-       this->lastping = 1;
-
 }
 
 User::~User()
@@ -242,8 +228,7 @@ User::~User()
 
        this->InvalidateCache();
        this->DecrementModes();
-       if (operquit)
-               free(operquit);
+
        if (ip)
        {
                ServerInstance->Users->RemoveCloneCounts(this);
@@ -260,7 +245,7 @@ User::~User()
 #endif
        }
 
-       ServerInstance->uuidlist->erase(uuid);
+       ServerInstance->Users->uuidlist->erase(uuid);
 }
 
 char* User::MakeHost()
@@ -467,7 +452,7 @@ bool User::AddBuffer(std::string a)
                if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
                {
                        this->SetWriteError("RecvQ exceeded");
-                       ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->MyClass->GetRecvqMax());
+                       ServerInstance->SNO->WriteToSnoMask('A', "User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->MyClass->GetRecvqMax());
                        return false;
                }
 
@@ -539,12 +524,12 @@ void User::AddWriteBuf(const std::string &data)
        if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
        {
                /*
-                * Fix by brain - Set the error text BEFORE calling writeopers, because
+                * Fix by brain - Set the error text BEFORE calling, because
                 * if we dont it'll recursively  call here over and over again trying
                 * to repeatedly add the text to the sendq!
                 */
                this->SetWriteError("SendQ exceeded");
-               ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->MyClass->GetSendqMax());
+               ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->MyClass->GetSendqMax());
                return;
        }
 
@@ -558,7 +543,7 @@ void User::AddWriteBuf(const std::string &data)
        catch (...)
        {
                this->SetWriteError("SendQ exceeded");
-               ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
+               ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ got an exception",this->nick);
        }
 }
 
@@ -651,7 +636,7 @@ void User::Oper(const std::string &opertype, const std::string &opername)
                FOREACH_MOD(I_OnOper, OnOper(this, opertype));
                ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
                strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
-               ServerInstance->all_opers.push_back(this);
+               ServerInstance->Users->all_opers.push_back(this);
 
                opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
                if (iter_opertype != ServerInstance->Config->opertypes.end())
@@ -703,7 +688,7 @@ void User::UnOper()
                        this->modes[UM_OPERATOR] = 0;
                        
                        // remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404
-                       ServerInstance->all_opers.remove(this);
+                       ServerInstance->Users->all_opers.remove(this);
 
                        if (AllowedOperCommands)
                        {
@@ -723,8 +708,10 @@ void User::QuitUser(InspIRCd* Instance, User *user, const std::string &quitreaso
 {
        Instance->Log(DEBUG,"QuitUser: %s '%s'", user->nick, quitreason.c_str());
        user->Write("ERROR :Closing link (%s@%s) [%s]", user->ident, user->host, *operreason ? operreason : quitreason.c_str());
-       user->muted = true;
-       Instance->GlobalCulls.AddItem(user, quitreason.c_str(), operreason);
+       user->quietquit = false;
+       user->quitmsg = quitreason;
+       user->operquitmsg = operreason;
+       Instance->GlobalCulls.AddItem(user);
 }
 
 /* adds or updates an entry in the whowas list */
@@ -754,13 +741,13 @@ void User::CheckClass()
        else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
        {
                User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)");
-               ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
+               ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
                return;
        }
        else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
        {
                User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (global)");
-               ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
+               ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
                return;
        }
 
@@ -797,7 +784,6 @@ void User::FullConnect()
 
                if (r)
                {
-                       this->muted = true;
                        r->Apply(this);
                        return;
                }
@@ -806,7 +792,6 @@ void User::FullConnect()
 
                if (n)
                {
-                       this->muted = true;
                        n->Apply(this);
                        return;
                }
@@ -826,8 +811,8 @@ void User::FullConnect()
        this->ShowMOTD();
 
        /* Now registered */
-       if (ServerInstance->unregistered_count)
-               ServerInstance->unregistered_count--;
+       if (ServerInstance->Users->unregistered_count)
+               ServerInstance->Users->unregistered_count--;
 
        /* Trigger LUSERS output, give modules a chance too */
        int MOD_RESULT = 0;
@@ -860,17 +845,17 @@ User* User::UpdateNickHash(const char* New)
        try
        {
                //user_hash::iterator newnick;
-               user_hash::iterator oldnick = ServerInstance->clientlist->find(this->nick);
+               user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
 
                if (!strcasecmp(this->nick,New))
                        return oldnick->second;
 
-               if (oldnick == ServerInstance->clientlist->end())
+               if (oldnick == ServerInstance->Users->clientlist->end())
                        return NULL; /* doesnt exist */
 
                User* olduser = oldnick->second;
-               (*(ServerInstance->clientlist))[New] = olduser;
-               ServerInstance->clientlist->erase(oldnick);
+               (*(ServerInstance->Users->clientlist))[New] = olduser;
+               ServerInstance->Users->clientlist->erase(oldnick);
                return olduser;
        }
 
@@ -899,25 +884,33 @@ bool User::ForceNickChange(const char* newnick)
 {
        try
        {
-               int MOD_RESULT = 0;
+               /*
+                * XXX this makes no sense..
+                * why do we do nothing for change on users not REG_ALL?
+                * why do we trigger events twice for everyone previously (and just them now)
+                * i think the first if () needs removing totally, or? -- w00t
+                */
+               if (this->registered != REG_ALL)
+               {
+                       int MOD_RESULT = 0;
 
-               this->InvalidateCache();
+                       this->InvalidateCache();
 
-               FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
+                       FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
 
-               if (MOD_RESULT)
-               {
-                       ServerInstance->stats->statsCollisions++;
-                       return false;
-               }
+                       if (MOD_RESULT)
+                       {
+                               ServerInstance->stats->statsCollisions++;
+                               return false;
+                       }
 
-               if (ServerInstance->XLines->MatchesLine("Q",newnick))
-               {
-                       ServerInstance->stats->statsCollisions++;
-                       return false;
+                       if (ServerInstance->XLines->MatchesLine("Q",newnick))
+                       {
+                               ServerInstance->stats->statsCollisions++;
+                               return false;
+                       }
                }
-
-               if (this->registered == REG_ALL)
+               else
                {
                        std::deque<classbase*> dummy;
                        Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
@@ -941,6 +934,8 @@ bool User::ForceNickChange(const char* newnick)
 
 void User::SetSockAddr(int protocol_family, const char* ip, int port)
 {
+       this->cachedip = "";
+
        switch (protocol_family)
        {
 #ifdef SUPPORT_IP6LINKS
@@ -1016,6 +1011,9 @@ const char* User::GetIPString()
        if (this->ip == NULL)
                return "";
 
+       if (!this->cachedip.empty())
+               return this->cachedip.c_str();
+
        switch (this->GetProtocolFamily())
        {
 #ifdef SUPPORT_IP6LINKS
@@ -1030,8 +1028,11 @@ const char* User::GetIPString()
                        {
                                strlcpy(&temp[1], buf, sizeof(temp) - 1);
                                *temp = '0';
+                               this->cachedip = temp;
                                return temp;
                        }
+                       
+                       this->cachedip = buf;
                        return buf;
                }
                break;
@@ -1040,12 +1041,15 @@ const char* User::GetIPString()
                {
                        sockaddr_in* sin = (sockaddr_in*)this->ip;
                        inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
+                       this->cachedip = buf;
                        return buf;
                }
                break;
                default:
                break;
        }
+       
+       // Unreachable, probably
        return "";
 }
 
@@ -1327,7 +1331,7 @@ void User::WriteWallOps(const std::string &text)
        std::string wallop("WALLOPS :");
        wallop.append(text);
 
-       for (std::vector<User*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
+       for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
                User* t = *i;
                if (t->IsModeSet('w'))
@@ -1471,7 +1475,7 @@ void User::SendAll(const char* command, char* text, ...)
        snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost(), command, textbuffer);
        std::string fmt = formatbuffer;
 
-       for (std::vector<User*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
+       for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
                (*i)->Write(fmt);
        }
@@ -1714,6 +1718,9 @@ void User::ShowRULES()
 
 void User::HandleEvent(EventType et, int errornum)
 {
+       if (this->quitting) // drop everything, user is due to be quit
+               return;
+
        /* WARNING: May delete this user! */
        int thisfd = this->GetFd();
 
@@ -1750,15 +1757,12 @@ void User::HandleEvent(EventType et, int errornum)
 
 void User::SetOperQuit(const std::string &oquit)
 {
-       if (operquit)
-               return;
-
-       operquit = strdup(oquit.c_str());
+       operquitmsg = oquit;
 }
 
 const char* User::GetOperQuit()
 {
-       return operquit ? operquit : "";
+       return operquitmsg.c_str();
 }
 
 void User::IncreasePenalty(int increase)