]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Fixed an issue that could cause empty parameters in module commands to not be sent...
[user/henk/code/inspircd.git] / src / channels.cpp
index edee36bf7b08ed98c304f296b0290c2f067f8c14..5169fbf6372161a77b83541393fe0a05d14ac519 100644 (file)
@@ -13,9 +13,6 @@
 
 #include "inspircd.h"
 #include <stdarg.h>
-#include "configreader.h"
-#include "users.h"
-#include "modules.h"
 #include "wildcard.h"
 #include "mode.h"
 
@@ -175,10 +172,10 @@ CUList* chanrec::GetVoicedUsers()
 void chanrec::SetDefaultModes()
 {
        irc::spacesepstream list(ServerInstance->Config->DefaultModes);
-       std::string modeseq = list.GetToken();
+       std::string modeseq;
        std::string parameter;
-       userrec* dummyuser = new userrec(ServerInstance);
-       dummyuser->SetFd(FD_MAGIC_NUMBER);
+
+       list.GetToken(modeseq);
 
        for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
        {
@@ -186,15 +183,13 @@ void chanrec::SetDefaultModes()
                if (mode)
                {
                        if (mode->GetNumParams(true))
-                               parameter = list.GetToken().c_str();
+                               list.GetToken(parameter);
                        else
                                parameter.clear();
 
-                       mode->OnModeChange(dummyuser, dummyuser, this, parameter, true);
+                       mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
                }
        }
-
-       delete dummyuser;
 }
 
 /* 
@@ -206,14 +201,50 @@ 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)
        {
@@ -253,7 +284,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
        {
@@ -288,7 +318,7 @@ 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));
@@ -327,58 +357,14 @@ 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.
-        */
-
-
-
-       /*
-        * We place no restrictions on remote users, users that are override-joining, or users that are
-        * currently in under MaxChans channels. For all others, they won't get in here. -- w00t
-        */     
-       if (!IS_LOCAL(user) || override == true || user->chans.size() < Instance->Config->MaxChans)
-       {
-               return chanrec::ForceChan(Instance, Ptr, user, privs);
-       }
-
-       /*
-        * If the above fails, and the user is an oper -- we let them in if they are under OperMaxChans.
-        * Otherwise, they're stuck, and need to override to get in, etc. -- w00t
-        */
-       if (IS_OPER(user))
-       {
-               if (user->chans.size() < Instance->Config->OperMaxChans)
-               {
-                       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)
 {
-       userrec* dummyuser = new userrec(Instance);
        std::string nick = user->nick;
        bool silent = false;
 
-       dummyuser->SetFd(FD_MAGIC_NUMBER);
        Ptr->AddUser(user);
 
        /* Just in case they have no permissions */
@@ -392,7 +378,7 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, con
                {
                        Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
                        /* Make sure that the mode handler knows this mode was now set */
-                       mh->OnModeChange(dummyuser, dummyuser, Ptr, nick, true);
+                       mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
 
                        switch (mh->GetPrefix())
                        {
@@ -417,8 +403,6 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, con
                }
        }
 
-       delete dummyuser;
-
        FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, silent));
 
        if (!silent)
@@ -850,7 +834,7 @@ void chanrec::UserList(userrec *user, CUList *ulist)
        if (MOD_RESULT == 1)
                return;
 
-       dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
+       dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=',  this->name);
 
        int numusers = 0;
        char* ptr = list + dlen;
@@ -865,7 +849,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
@@ -892,7 +876,7 @@ void chanrec::UserList(userrec *user, CUList *ulist)
                        user->WriteServ(std::string(list));
 
                        /* reset our lengths */
-                       dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
+                       dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name);
                        ptr = list + dlen;
 
                        ptrlen = 0;