]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Add <connect:maxchans> as per feature bug #338 - combined with the last feature,...
[user/henk/code/inspircd.git] / src / channels.cpp
index 7629c8bb685a0cc6ffcb3764dce779b311210c12..bd8a9719c5f8e17dbb2291342232191530dff718 100644 (file)
@@ -188,7 +188,7 @@ void chanrec::SetDefaultModes()
                        if (mode->GetNumParams(true))
                                parameter = list.GetToken().c_str();
                        else
-                               parameter = "";
+                               parameter.clear();
 
                        mode->OnModeChange(dummyuser, dummyuser, this, parameter, true);
                }
@@ -206,21 +206,65 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
        if (!user || !cn)
                return NULL;
 
-       bool new_channel = false;
        char cname[MAXBUF];
        int MOD_RESULT = 0;
-       strlcpy(cname,cn,CHANMAX);
-
        std::string privs;
+       chanrec *Ptr;
 
-       chanrec* Ptr = Instance->FindChan(cname);
+       /*
+        * We don't restrict the number of channels that remote users or users that are override-joining may be in.
+        * We restrict local users to MaxChans channels.
+        * We restrict local operators to OperMaxChans channels.
+        * This is a lot more logical than how it was formerly. -- w00t
+        */
+       if (IS_LOCAL(user) && !override)
+       {
+               if (user->GetMaxChans())
+               {
+                       if (user->chans.size() >= user->GetMaxChans())
+                       {
+                               user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn);
+                               return NULL;
+                       }
+               }
+               else
+               {
+                       if (IS_OPER(user))
+                       {
+                               if (user->chans.size() >= Instance->Config->OperMaxChans)
+                               {
+                                       user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn);
+                                       return NULL;
+                               }
+                       }
+                       else
+                       {
+                               if (user->chans.size() >= Instance->Config->MaxChans)
+                               {
+                                       user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn);
+                                       return NULL;
+                               }
+                       }
+               }
+       }
+
+       strlcpy(cname, cn, CHANMAX);
+       Ptr = Instance->FindChan(cname);
 
        if (!Ptr)
        {
-               if ((!IS_LOCAL(user)) && (!TS))
-                       Instance->Log(DEBUG,"*** BUG *** chanrec::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn);
-
-               privs = "@";
+               /*
+                * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
+                */
+               if (!IS_LOCAL(user))
+               {
+                       if (!TS)
+                               Instance->Log(DEBUG,"*** BUG *** chanrec::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn);
+               }
+               else
+               {
+                       privs = "@";
+               }
 
                if (IS_LOCAL(user) && override == false)
                {
@@ -245,7 +289,6 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
                *Ptr->topic = 0;
                *Ptr->setby = 0;
                Ptr->topicset = 0;
-               new_channel = true;
        }
        else
        {
@@ -280,18 +323,13 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
                                                }
                                        }
                                }
-                               if (Ptr->modes[CM_INVITEONLY])
+                               if (Ptr->IsModeSet('i'))
                                {
                                        MOD_RESULT = 0;
                                        FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
                                        if (!MOD_RESULT)
                                        {
-                                               if (user->IsInvited(Ptr->name))
-                                               {
-                                                       /* user was invited to channel */
-                                                       /* there may be an optional channel NOTICE here */
-                                               }
-                                               else
+                                               if (!user->IsInvited(Ptr->name))
                                                {
                                                        user->WriteServ("473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
                                                        return NULL;
@@ -324,43 +362,7 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
                }
        }
 
-       /* NOTE: If the user is an oper here, we can extend their user->chans by up to
-        * OperMaxchans. For remote users which are not bound by the channel limits,
-        * we can extend infinitely. Otherwise, nope, youre restricted to MaxChans.
-        */
-       if (!IS_LOCAL(user) || override == true)
-       {
-               return chanrec::ForceChan(Instance, Ptr, user, privs);
-       }
-       else if (IS_OPER(user))
-       {
-               /* Oper allows extension up to the OperMaxchans value */
-               if (user->chans.size() < Instance->Config->OperMaxChans)
-               {
-                       return chanrec::ForceChan(Instance, Ptr, user, privs);
-               }
-       }
-       else if (user->chans.size() < Instance->Config->MaxChans)
-       {
-               return chanrec::ForceChan(Instance, Ptr, user, privs);
-       }
-
-
-       user->WriteServ("405 %s %s :You are on too many channels",user->nick, cname);
-
-       if (new_channel)
-       {
-               /* Things went seriously pear shaped, so take this away. bwahaha. */
-               chan_hash::iterator n = Instance->chanlist->find(cname);
-               if (n != Instance->chanlist->end())
-               {
-                       Ptr->DelUser(user);
-                       DELETE(Ptr);
-                       Instance->chanlist->erase(n);
-               }
-       }
-
-       return NULL;
+       return chanrec::ForceChan(Instance, Ptr, user, privs);
 }
 
 chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, const std::string &privs)
@@ -790,7 +792,7 @@ char* chanrec::ChanModes(bool showkey)
                if(this->modes[n])
                {
                        *offset++ = n + 65;
-                       extparam = "";
+                       extparam.clear();
                        switch (n)
                        {
                                case CM_KEY:
@@ -811,7 +813,7 @@ char* chanrec::ChanModes(bool showkey)
                                        extparam = this->GetModeParameter(n + 65);
                                break;
                        }
-                       if (extparam != "")
+                       if (!extparam.empty())
                        {
                                charlcat(sparam,' ',MAXBUF);
                                strlcat(sparam,extparam.c_str(),MAXBUF);
@@ -856,7 +858,7 @@ void chanrec::UserList(userrec *user, CUList *ulist)
 
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if ((!has_user) && (i->first->modes[UM_INVISIBLE]))
+               if ((!has_user) && (i->first->IsModeSet('i')))
                {
                        /*
                         * user is +i, and source not on the channel, does not show