]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Add template creation tool for caller classes
[user/henk/code/inspircd.git] / src / channels.cpp
index e4b58a1a4853cd7b1a2d097c25358964537a8c8e..c0055bf1d015a37f0b2b54a2dad78b3cf5d767d3 100644 (file)
@@ -11,9 +11,9 @@
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include <stdarg.h>
 #include "configreader.h"
-#include "inspircd.h"
 #include "users.h"
 #include "modules.h"
 #include "wildcard.h"
@@ -172,6 +172,31 @@ CUList* chanrec::GetVoicedUsers()
        return &internal_voice_userlist;
 }
 
+void chanrec::SetDefaultModes()
+{
+       irc::spacesepstream list(ServerInstance->Config->DefaultModes);
+       std::string modeseq = list.GetToken();
+       std::string parameter;
+       userrec* dummyuser = new userrec(ServerInstance);
+       dummyuser->SetFd(FD_MAGIC_NUMBER);
+
+       for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
+       {
+               ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
+               if (mode)
+               {
+                       if (mode->GetNumParams(true))
+                               parameter = list.GetToken().c_str();
+                       else
+                               parameter.clear();
+
+                       mode->OnModeChange(dummyuser, dummyuser, this, parameter, true);
+               }
+       }
+
+       delete dummyuser;
+}
+
 /* 
  * add a channel to a user, creating the record for it if needed and linking
  * it to the user record 
@@ -192,10 +217,18 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
 
        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)
                {
@@ -213,7 +246,7 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
 
                /* As spotted by jilles, dont bother to set this on remote users */
                if (IS_LOCAL(user))
-                       Ptr->modes[CM_TOPICLOCK] = Ptr->modes[CM_NOEXTERNAL] = 1;
+                       Ptr->SetDefaultModes();
 
                Ptr->created = TS ? TS : Instance->Time();
                Ptr->age = Ptr->created;
@@ -255,18 +288,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;
@@ -303,23 +331,29 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
         * 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)
+
+
+
+       /*
+        * 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);
        }
-       else if (*user->oper)
+
+       /*
+        * 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))
        {
-               /* 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);
 
@@ -765,7 +799,7 @@ char* chanrec::ChanModes(bool showkey)
                if(this->modes[n])
                {
                        *offset++ = n + 65;
-                       extparam = "";
+                       extparam.clear();
                        switch (n)
                        {
                                case CM_KEY:
@@ -786,7 +820,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);
@@ -831,7 +865,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