]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Set defaults for an enum
[user/henk/code/inspircd.git] / src / users.cpp
index 196be89e98d8d6bf334c306fba0f207eea243699..12742bbc9e6ad94a6854079c4593338202fab2c4 100644 (file)
@@ -198,7 +198,7 @@ void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl,
        else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
        {
                /* Both lookups completed */
-               std::string result2 = "0::ffff:";
+               std::string result2("0::ffff:");
                result2.append(result);
                if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
                {
@@ -210,7 +210,7 @@ void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl,
                                {
                                        /* Hostnames starting with : are not a good thing (tm) */
                                        if (*(hostname.c_str()) == ':')
-                                               hostname = "0" + hostname;
+                                               hostname.insert(0, "0");
 
                                        this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
                                        this->bound_user->dns_done = true;
@@ -330,9 +330,9 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
        ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
        muted = exempt = haspassed = dns_done = false;
        fd = -1;
-       recvq = "";
-       sendq = "";
-       WriteError = "";
+       recvq.clear();
+       sendq.clear();
+       WriteError.clear();
        res_forward = res_reverse = NULL;
        Visibility = NULL;
        ip = NULL;
@@ -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)
                {
@@ -632,7 +637,7 @@ bool userrec::BufferIsReady()
 
 void userrec::ClearBuffer()
 {
-       recvq = "";
+       recvq.clear();
 }
 
 std::string userrec::GetBuffer()
@@ -713,7 +718,7 @@ void userrec::FlushWriteBuf()
        {
                if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
                {
-                       sendq = "";
+                       sendq.clear();
                }
                if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
                {
@@ -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;
                                }
                        }
@@ -962,6 +967,8 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
                if (r)
                {
                        char reason[MAXBUF];
+                       if (*Instance->Config->MoronBanner)
+                               New->WriteServ("NOTICE %s :*** %s", New->nick, Instance->Config->MoronBanner);
                        snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
                        userrec::QuitUser(Instance, New, reason);
                        return;
@@ -1013,11 +1020,6 @@ void userrec::CheckClass()
                userrec::QuitUser(ServerInstance, this, "Unauthorised connection");
                return;
        }
-       else if ((!a->GetPass().empty()) && (!this->haspassed))
-       {
-               userrec::QuitUser(ServerInstance, this, "Invalid password");
-               return;
-       }
        else if ((a->GetMaxLocal()) && (this->LocalCloneCount() > a->GetMaxLocal()))
        {
                userrec::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)");
@@ -1044,7 +1046,16 @@ void userrec::FullConnect()
         * Don't remove this! -- w00t
         */
        this->CheckClass();
-
+       
+       /* Check the password, if one is required by the user's connect class.
+        * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
+        */
+       if ((!this->GetClass()->GetPass().empty()) && (!this->haspassed))
+       {
+               userrec::QuitUser(ServerInstance, this, "Invalid password");
+               return;
+       }
+       
        if (!this->exempt)
        {
                GLine* r = ServerInstance->XLines->matches_gline(this);
@@ -1053,8 +1064,10 @@ void userrec::FullConnect()
                {
                        this->muted = true;
                        char reason[MAXBUF];
+                       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;
                }
 
@@ -1064,11 +1077,12 @@ void userrec::FullConnect()
                {
                        this->muted = true;
                        char reason[MAXBUF];
+                       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;
                }
-
        }
 
        this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
@@ -1172,10 +1186,7 @@ bool userrec::ForceNickChange(const char* newnick)
 
                if (this->registered == REG_ALL)
                {
-                       const char* pars[1];
-                       pars[0] = newnick;
-                       std::string cmd = "NICK";
-                       return (ServerInstance->Parser->CallHandler(cmd, pars, 1, this) == CMD_SUCCESS);
+                       return (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS);
                }
                return false;
        }
@@ -1369,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)
@@ -1611,12 +1625,13 @@ void userrec::WriteWallOps(const std::string &text)
        if (!IS_OPER(this) && IS_LOCAL(this))
                return;
 
-       std::string wallop = "WALLOPS :" + text;
+       std::string wallop("WALLOPS :");
+       wallop.append(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);
        }
 }
@@ -1775,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(" ");
                        }
@@ -1917,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)