]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Changed m_messageflood to use PreMessage and PreNotice, because it may kick the user
[user/henk/code/inspircd.git] / src / users.cpp
index bc221b263c76c7ee10d533b555f32c5ce8cf245f..cbf9de0cdcc8a038c0331b7ab08a9317f952e747 100644 (file)
@@ -344,6 +344,29 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
        operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
 }
 
+void userrec::RemoveCloneCounts()
+{
+       clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
+       if (x != ServerInstance->local_clones.end())
+       {
+               x->second--;
+               if (!x->second)
+               {
+                       ServerInstance->local_clones.erase(x);
+               }
+       }
+       
+       clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
+       if (y != ServerInstance->global_clones.end())
+       {
+               y->second--;
+               if (!y->second)
+               {
+                       ServerInstance->global_clones.erase(y);
+               }
+       }
+}
+
 userrec::~userrec()
 {
        this->InvalidateCache();
@@ -352,25 +375,7 @@ userrec::~userrec()
                free(operquit);
        if (ip)
        {
-               clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
-               if (x != ServerInstance->local_clones.end())
-               {
-                       x->second--;
-                       if (!x->second)
-                       {
-                               ServerInstance->local_clones.erase(x);
-                       }
-               }
-
-               clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
-               if (y != ServerInstance->global_clones.end())
-               {
-                       y->second--;
-                       if (!y->second)
-                       {
-                               ServerInstance->global_clones.erase(y);
-                       }
-               }
+               this->RemoveCloneCounts();
 
                if (this->GetProtocolFamily() == AF_INET)
                {
@@ -736,7 +741,7 @@ void userrec::FlushWriteBuf()
                                {
                                        /* Fatal error, set write error and bail
                                         */
-                                       this->SetWriteError(strerror(errno));
+                                       this->SetWriteError(errno ? strerror(errno) : "EOF from client");
                                        return;
                                }
                        }
@@ -918,16 +923,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))
@@ -1027,6 +1028,14 @@ 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();
 }
 
 void userrec::FullConnect()
@@ -1062,7 +1071,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;
                }
 
@@ -1075,7 +1084,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;
                }
        }
@@ -1349,11 +1358,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
@@ -1375,6 +1380,9 @@ void userrec::Write(std::string text)
        {
                try
                {
+                       /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
+                        * implement their own buffering mechanisms
+                        */
                        ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
                }
                catch (CoreException& modexcept)
@@ -1623,7 +1631,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);
        }
 }
@@ -1782,7 +1790,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(" ");
                        }
@@ -1924,15 +1932,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)