]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Whoops, i left a value out of the array, and gcc didnt warn!
[user/henk/code/inspircd.git] / src / users.cpp
index 8b92270831e8d8fee3be98645b88bc1bb41b4515..4854849ad4925eae5b303ad5f6257c11088237be 100644 (file)
@@ -164,8 +164,12 @@ UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_res
        this->bound_fd = user->GetFd();
 }
 
-void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
 {
+       /* We are only interested in the first matching result */
+       if (resultnum)
+               return;
+
        if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
        {
                this->bound_user->stored_host = result;
@@ -923,16 +927,12 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
                return;
        }
 
+       /*
+        * Check connect class settings and initialise settings into userrec.
+        * This will be done again after DNS resolution. -- w00t
+        */
        New->CheckClass();
 
-       New->pingmax = i->GetPingTime();
-       New->nping = Instance->Time() + i->GetPingTime() + Instance->Config->dns_timeout;
-       New->timeout = Instance->Time() + i->GetRegTimeout();
-       New->flood = i->GetFlood();
-       New->threshold = i->GetThreshold();
-       New->sendqmax = i->GetSendqMax();
-       New->recvqmax = i->GetRecvqMax();
-
        Instance->local_users.push_back(New);
 
        if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
@@ -1011,9 +1011,9 @@ unsigned long userrec::LocalCloneCount()
 /*
  * Check class restrictions
  */
-void userrec::CheckClass()
+void userrec::CheckClass(const std::string &explicit_class)
 {
-       ConnectClass* a = this->GetClass();
+       ConnectClass* a = this->GetClass(explicit_class);
 
        if ((!a) || (a->GetType() == CC_DENY))
        {
@@ -1032,6 +1032,15 @@ void userrec::CheckClass()
                ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
                return;
        }
+
+       this->pingmax = a->GetPingTime();
+       this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
+       this->timeout = ServerInstance->Time() + a->GetRegTimeout();
+       this->flood = a->GetFlood();
+       this->threshold = a->GetThreshold();
+       this->sendqmax = a->GetSendqMax();
+       this->recvqmax = a->GetRecvqMax();
+       this->MaxChans = a->GetMaxChans();
 }
 
 void userrec::FullConnect()
@@ -1067,7 +1076,7 @@ void userrec::FullConnect()
                        if (*ServerInstance->Config->MoronBanner)
                                this->WriteServ("NOTICE %s :*** %s", this->nick, ServerInstance->Config->MoronBanner);
                        snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
-                       ServerInstance->GlobalCulls.AddItem(this, reason);
+                       userrec::QuitUser(ServerInstance, this, reason);
                        return;
                }
 
@@ -1080,7 +1089,7 @@ void userrec::FullConnect()
                        if (*ServerInstance->Config->MoronBanner)
                                this->WriteServ("NOTICE %s :*** %s", this, ServerInstance->Config->MoronBanner);
                        snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
-                       ServerInstance->GlobalCulls.AddItem(this, reason);
+                       userrec::QuitUser(ServerInstance, this, reason);
                        return;
                }
        }
@@ -1354,11 +1363,7 @@ const char* userrec::GetIPString(char* buf)
  */
 void userrec::Write(std::string text)
 {
-#ifdef WINDOWS
-       if ((this->fd < 0) || (this->m_internalFd > MAX_DESCRIPTORS))
-#else
-       if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS))
-#endif
+       if (!ServerInstance->SE->BoundsCheckFd(this))
                return;
 
        try
@@ -1631,7 +1636,7 @@ void userrec::WriteWallOps(const std::string &text)
        for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
        {
                userrec* t = *i;
-               if (t->modes[UM_WALLOPS])
+               if (t->IsModeSet('w'))
                        this->WriteTo(t,wallop);
        }
 }
@@ -1790,7 +1795,7 @@ std::string userrec::ChannelList(userrec* source)
                         * If the channel is NOT private/secret OR the user shares a common channel
                         * If the user is an oper, and the <options:operspywhois> option is set.
                         */
-                       if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source))))
+                       if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
                        {
                                list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
                        }
@@ -1849,27 +1854,42 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl)
        }
 }
 
+unsigned int userrec::GetMaxChans()
+{
+       return this->MaxChans;
+}
 
 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
  * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
  * then their ip will be taken as 'priority' anyway, so for example,
  * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
  */
-ConnectClass* userrec::GetClass()
+ConnectClass* userrec::GetClass(const std::string &explicit_name)
 {
-       for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+       if (!explicit_name.empty())
        {
-               if (((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))))
+               for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
                {
-                       if (i->GetPort())
+                       if (explicit_name == i->GetName())
+                               return &(*i);
+               }
+       }
+       else
+       {
+               for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+               {
+                       if (((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))))
                        {
-                               if (this->GetPort() == i->GetPort())
-                                       return &(*i);
+                               if (i->GetPort())
+                               {
+                                       if (this->GetPort() == i->GetPort())
+                                               return &(*i);
+                                       else
+                                               continue;
+                               }
                                else
-                                       continue;
+                                       return &(*i);
                        }
-                       else
-                               return &(*i);
                }
        }
        return NULL;
@@ -1932,15 +1952,16 @@ void userrec::ShowRULES()
 {
        if (!ServerInstance->Config->RULES.size())
        {
-               this->WriteServ("NOTICE %s :Rules file is missing.",this->nick);
+               this->WriteServ("434 %s :RULES File is missing",this->nick);
                return;
        }
-       this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
+
+       this->WriteServ("308 %s :- %s Server Rules -",this->nick,ServerInstance->Config->ServerName);
 
        for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
-               this->WriteServ("NOTICE %s :%s",this->nick,i->c_str());
+               this->WriteServ("232 %s :- %s",this->nick,i->c_str());
 
-       this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
+       this->WriteServ("309 %s :End of RULES command.",this->nick);
 }
 
 void userrec::HandleEvent(EventType et, int errornum)