]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Because the user's prefix list must remain sorted at all times (because of assumption...
[user/henk/code/inspircd.git] / src / channels.cpp
index 28052de98ce71de493096948711e88c828e35d3c..5e2ef907c866da549c550019daf48e093f830979 100644 (file)
@@ -301,17 +301,12 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
                                }
                                if (Ptr->bans.size())
                                {
-                                       MOD_RESULT = 0;
-                                       FOREACH_RESULT_I(Instance,I_OnCheckBan,OnCheckBan(user, Ptr));
                                        char mask[MAXBUF];
-                                       sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
-                                       if (!MOD_RESULT)
+                                       snprintf(mask, MAXBUF, "%s!%s@%s",user->nick, user->ident, user->GetIPString());
+                                       if (Ptr->IsBanned(user))
                                        {
-                                               if (Ptr->IsBanned(user))
-                                               {
-                                                       user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
-                                                       return NULL;
-                                               }
+                                               user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
+                                               return NULL;
                                        }
                                }
                        }
@@ -400,13 +395,13 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* u
                switch (status)
                {
                        case '@':
-                               a->uc_modes = UCMODE_OP;
+                               a->uc_modes |= UCMODE_OP;
                        break;
                        case '%':
-                               a->uc_modes = UCMODE_HOP;
+                               a->uc_modes |= UCMODE_HOP;
                        break;
                        case '+':
-                               a->uc_modes = UCMODE_VOICE;
+                               a->uc_modes |= UCMODE_VOICE;
                        break;
                }
                ModeHandler* mh = Instance->Modes->FindPrefix(status);
@@ -443,25 +438,29 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* u
 bool chanrec::IsBanned(userrec* user)
 {
        char mask[MAXBUF];
-       sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
-       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
+       if (!MOD_RESULT)
        {
-               /* This allows CIDR ban matching
-                * 
-                *        Full masked host                      Full unmasked host                   IP with/without CIDR
-                */
-               if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
+               snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
+               for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
                {
-                       return true;
+                       /* This allows CIDR ban matching
+                        * 
+                        *        Full masked host                      Full unmasked host                   IP with/without CIDR
+                        */
+                       if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
+                       {
+                               return true;
+                       }
                }
-
        }
        return false;
 }
 
 /* chanrec::PartUser
- * remove a channel from a users record, and remove the record from the hash
- * if the channel has become empty
+ * remove a channel from a users record, and return the number of users left.
+ * Therefore, if this function returns 0 the caller should delete the chanrec.
  */
 long chanrec::PartUser(userrec *user, const char* reason)
 {
@@ -473,16 +472,8 @@ long chanrec::PartUser(userrec *user, const char* reason)
                /* zap it from the channel list of the user */
                if (user->chans[i]->channel == this)
                {
-                       if (reason)
-                       {
-                               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason));
-                               this->WriteChannel(user, "PART %s :%s", this->name, reason);
-                       }
-                       else
-                       {
-                               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, ""));
-                               this->WriteChannel(user, "PART :%s", this->name);
-                       }
+                       FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason ? reason : ""));
+                       this->WriteChannel(user, "PART %s%s%s", this->name, reason ? " :" : "", reason ? reason : "");
                        user->chans[i]->uc_modes = 0;
                        user->chans[i]->channel = NULL;
                        user->ModChannelCount(-1);
@@ -592,14 +583,7 @@ long chanrec::KickUser(userrec *src, userrec *user, const char* reason)
                                int us = this->GetStatus(user);
                                if ((them < STATUS_HOP) || (them < us))
                                {
-                                       if (them == STATUS_HOP)
-                                       {
-                                               src->WriteServ("482 %s %s :You must be a channel operator",src->nick, this->name);
-                                       }
-                                       else
-                                       {
-                                               src->WriteServ("482 %s %s :You must be at least a half-operator",src->nick, this->name);
-                                       }
+                                       src->WriteServ("482 %s %s :You must be a channel %soperator",src->nick, this->name, them == STATUS_HOP ? "" : "half-");
                                        return this->GetUserCounter();
                                }
                        }
@@ -769,7 +753,7 @@ char* chanrec::ChanModes(bool showkey)
        *scratch = '\0';
        *sparam = '\0';
 
-       /* This was still iterating up to 190, chanrec::custom_modes is only 64 elements -- Om */
+       /* This was still iterating up to 190, chanrec::modes is only 64 elements -- Om */
        for(int n = 0; n < 64; n++)
        {
                if(this->modes[n])
@@ -819,6 +803,9 @@ void chanrec::UserList(userrec *user)
        size_t dlen, curlen;
        int MOD_RESULT = 0;
 
+       if (!IS_LOCAL(user))
+               return;
+
        FOREACH_RESULT(I_OnUserList,OnUserList(user, this));
        ServerInstance->Log(DEBUG,"MOD_RESULT for UserList = %d",MOD_RESULT);
        if (MOD_RESULT == 1)
@@ -881,11 +868,9 @@ void chanrec::UserList(userrec *user)
 
 long chanrec::GetMaxBans()
 {
-       std::string x;
        for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
        {
-               x = n->first;
-               if (match(this->name,x.c_str()))
+               if (match(this->name,n->first.c_str()))
                {
                        return n->second;
                }
@@ -900,26 +885,20 @@ long chanrec::GetMaxBans()
  */
 const char* chanrec::GetPrefixChar(userrec *user)
 {
-       static char px[2];
-       unsigned int mx = 0;
-
-       *px = 0;
-       *(px+1) = 0;
-
+       static char pf[2] = {0, 0};
+       
        prefixlist::iterator n = prefixes.find(user);
        if (n != prefixes.end())
        {
-               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
+               if (n->second.size())
                {
-                       if (x->second > mx)
-                       {
-                               *px = x->first;
-                               mx  = x->second;
-                       }
+                       *pf = n->second.begin()->first;
+                       return pf;
                }
        }
 
-       return px;
+       *pf = 0;
+       return pf;
 }
 
 const char* chanrec::GetAllPrefixChars(userrec* user)
@@ -944,19 +923,13 @@ const char* chanrec::GetAllPrefixChars(userrec* user)
 
 unsigned int chanrec::GetPrefixValue(userrec* user)
 {
-       unsigned int mx = 0;
-
        prefixlist::iterator n = prefixes.find(user);
        if (n != prefixes.end())
        {
-               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
-               {
-                       if (x->second > mx)
-                               mx  = x->second;
-               }
+               if (n->second.size())
+                       return n->second.begin()->second;
        }
-
-       return mx;
+       return 0;
 }