]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Opers are not exempt from other modes, don't exempt them from +N (we may add this...
[user/henk/code/inspircd.git] / src / users.cpp
index ca2a27f0d2293dc074a0aab48c2f249aeb2202fb..1955c90295bea651cdce870dcda06ec8e93a5c8e 100644 (file)
@@ -338,6 +338,7 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
        sendq = "";
        WriteError = "";
        res_forward = res_reverse = NULL;
+       Visibility = NULL;
        ip = NULL;
        chans.clear();
        invites.clear();
@@ -552,7 +553,7 @@ bool userrec::HasPermission(const std::string &command)
                return true;
 
        // are they even an oper at all?
-       if (*this->oper)
+       if (IS_OPER(this))
        {
                opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
                if (iter_opertype != ServerInstance->Config->opertypes.end())
@@ -689,8 +690,8 @@ void userrec::AddWriteBuf(const std::string &data)
 
        try
        {
-               if (data.length() > 512)
-                       sendq.append(data.substr(0,510)).append("\r\n");
+               if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
+                       sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
                else
                        sendq.append(data);
        }
@@ -799,10 +800,13 @@ void userrec::UnOper()
 {
        try
        {
-               if (*this->oper)
+               if (IS_OPER(this))
                {
+                       // unset their oper type (what IS_OPER checks), and remove +o
                        *this->oper = 0;
                        this->modes[UM_OPERATOR] = 0;
+
+                       // remove them from the opers list.
                        for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
                        {
                                if (*a == this)
@@ -896,13 +900,12 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
        Instance->AddLocalClone(New);
        Instance->AddGlobalClone(New);
 
+       /*
+        * First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
+        * See my note down there for why this is required. DO NOT REMOVE. :) -- w00t
+        */
        ConnectClass* i = New->GetClass();
-
-       if ((!i) || (i->GetType() == CC_DENY))
-       {
-               userrec::QuitUser(Instance, New,"Unauthorised connection");
-               return;
-       }
+       New->CheckClass();
 
        New->pingmax = i->GetPingTime();
        New->nping = Instance->Time() + i->GetPingTime() + Instance->Config->dns_timeout;
@@ -983,41 +986,57 @@ unsigned long userrec::LocalCloneCount()
                return 0;
 }
 
-void userrec::FullConnect()
+/*
+ * Check class restrictions
+ */
+void userrec::CheckClass()
 {
-       ServerInstance->stats->statsConnects++;
-       this->idle_lastmsg = ServerInstance->Time();
-
        ConnectClass* a = this->GetClass();
 
        if ((!a) || (a->GetType() == CC_DENY))
        {
-               this->muted = true;
-               ServerInstance->GlobalCulls.AddItem(this,"Unauthorised connection");
+               userrec::QuitUser(ServerInstance, this, "Unauthorised connection");
                return;
        }
 
        if ((!a->GetPass().empty()) && (!this->haspassed))
        {
-               this->muted = true;
-               ServerInstance->GlobalCulls.AddItem(this,"Invalid password");
+               userrec::QuitUser(ServerInstance, this, "Invalid password");
                return;
        }
 
-       if (this->LocalCloneCount() > a->GetMaxLocal())
+       if ((!a) || (a->GetType() == CC_DENY))
+       {
+               userrec::QuitUser(ServerInstance, this,"Unauthorised connection");
+               return;
+       }
+
+       if ((a->GetMaxLocal()) && (this->LocalCloneCount() > a->GetMaxLocal()))
        {
-               this->muted = true;
-               ServerInstance->GlobalCulls.AddItem(this, "No more connections allowed from your host via this connect class (local)");
+               userrec::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());
                return;
        }
-       else if (this->GlobalCloneCount() > a->GetMaxGlobal())
+       else if ((a->GetMaxGlobal()) && (this->GlobalCloneCount() > a->GetMaxGlobal()))
        {
-               this->muted = true;
-               ServerInstance->GlobalCulls.AddItem(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());
+               userrec::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());
                return;
        }
+}
+
+void userrec::FullConnect()
+{
+       ServerInstance->stats->statsConnects++;
+       this->idle_lastmsg = ServerInstance->Time();
+
+       /*
+        * You may be thinking "wtf, we checked this in userrec::AddClient!" - and yes, we did, BUT.
+        * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
+        * may put the user into a totally seperate class with different restrictions! so we *must* check again.
+        * Don't remove this! -- w00t
+        */
+       this->CheckClass();
 
        if (!this->exempt)
        {
@@ -1059,6 +1078,12 @@ void userrec::FullConnect()
        if (ServerInstance->unregistered_count)
                ServerInstance->unregistered_count--;
 
+       /* Trigger LUSERS output, give modules a chance too */
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnPreCommand, OnPreCommand("LUSERS", NULL, 0, this, true, "LUSERS"));
+       if (!MOD_RESULT)
+               ServerInstance->CallCommandHandler("LUSERS", NULL, 0, this);
+
        /*
         * fix 3 by brain, move registered = 7 below these so that spurious modes and host
         * changes dont go out onto the network and produce 'fake direction'.
@@ -1069,7 +1094,7 @@ void userrec::FullConnect()
 
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
 
-       ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
+       ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString(), this->fullname);
 }
 
 /** userrec::UpdateNick()
@@ -1467,10 +1492,10 @@ void userrec::WriteCommon(const std::string &text)
                        CUList* ulist = v->first->GetUsers();
                        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
                        {
-                               if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
+                               if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
                                {
-                                       already_sent[i->second->fd] = uniq_id;
-                                       i->second->Write(out);
+                                       already_sent[i->first->fd] = uniq_id;
+                                       i->first->Write(out);
                                        sent_to_at_least_one = true;
                                }
                        }
@@ -1528,12 +1553,12 @@ void userrec::WriteCommonQuit(const std::string &normal_text, const std::string
                CUList *ulist = v->first->GetUsers();
                for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
                {
-                       if (this != i->second)
+                       if (this != i->first)
                        {
-                               if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
+                               if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
                                {
-                                       already_sent[i->second->fd] = uniq_id;
-                                       i->second->Write(*i->second->oper ? out2 : out1);
+                                       already_sent[i->first->fd] = uniq_id;
+                                       i->first->Write(IS_OPER(i->first) ? out2 : out1);
                                }
                        }
                }
@@ -1557,12 +1582,12 @@ void userrec::WriteCommonExcept(const std::string &text)
                CUList *ulist = v->first->GetUsers();
                for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
                {
-                       if (this != i->second)
+                       if (this != i->first)
                        {
-                               if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
+                               if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
                                {
-                                       already_sent[i->second->fd] = uniq_id;
-                                       i->second->Write(out1);
+                                       already_sent[i->first->fd] = uniq_id;
+                                       i->first->Write(out1);
                                }
                        }
                }
@@ -1572,21 +1597,10 @@ void userrec::WriteCommonExcept(const std::string &text)
 
 void userrec::WriteWallOps(const std::string &text)
 {
-       /* Does nothing if theyre not opered */
-       if ((!*this->oper) && (IS_LOCAL(this)))
+       if (!IS_OPER(this) && IS_LOCAL(this))
                return;
 
-       std::string wallop = "WALLOPS :";
-
-       try
-       {
-               wallop.append(text);
-       }
-       catch (...)
-       {
-               ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
-               return;
-       }
+       std::string wallop = "WALLOPS :" + text;
 
        for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
        {
@@ -1750,7 +1764,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) || (*source->oper && 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->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source))))
                        {
                                list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
                        }
@@ -1952,4 +1966,16 @@ const char* userrec::GetOperQuit()
        return operquit ? operquit : "";
 }
 
+VisData::VisData()
+{
+}
+
+VisData::~VisData()
+{
+}
+
+bool VisData::VisibleTo(userrec* user)
+{
+       return true;
+}