]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Create the core_xline module
[user/henk/code/inspircd.git] / src / channels.cpp
index 51a8f5625c920928c862c3b845718449438a1e83..99c25fbfc8777cd9c386660b849704c1d0a5d35b 100644 (file)
@@ -48,30 +48,7 @@ Channel::Channel(const std::string &cname, time_t ts)
 
 void Channel::SetMode(ModeHandler* mh, bool on)
 {
-       modes[mh->GetModeChar() - 65] = on;
-}
-
-void Channel::SetModeParam(ModeHandler* mh, const std::string& parameter)
-{
-       char mode = mh->GetModeChar();
-       if (parameter.empty())
-       {
-               custom_mode_params.erase(mode);
-               modes[mode-65] = false;
-       }
-       else
-       {
-               custom_mode_params[mode] = parameter;
-               modes[mode-65] = true;
-       }
-}
-
-std::string Channel::GetModeParameter(ModeHandler* mode)
-{
-       CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar());
-       if (n != custom_mode_params.end())
-               return n->second;
-       return "";
+       modes[mh->GetId()] = on;
 }
 
 void Channel::SetTopic(User* u, const std::string& ntopic)
@@ -438,7 +415,6 @@ ModResult Channel::GetExtBanStatus(User *user, char type)
        ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
        const ListModeBase::ModeList* bans = banlm->GetList(this);
        if (bans)
-
        {
                for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it)
                {
@@ -622,11 +598,13 @@ const char* Channel::ChanModes(bool showkey)
        /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
        for(int n = 0; n < 64; n++)
        {
-               if(this->modes[n])
+               ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_CHANNEL);
+               if (mh && IsModeSet(mh))
                {
                        scratch.push_back(n + 65);
-                       ModeHandler* mh = ServerInstance->Modes->FindMode(n+'A', MODETYPE_CHANNEL);
-                       if (!mh)
+
+                       ParamModeBase* pm = mh->IsParameterMode();
+                       if (!pm)
                                continue;
 
                        if (n == 'k' - 65 && !showkey)
@@ -635,12 +613,8 @@ const char* Channel::ChanModes(bool showkey)
                        }
                        else
                        {
-                               const std::string param = this->GetModeParameter(mh);
-                               if (!param.empty())
-                               {
-                                       sparam += ' ';
-                                       sparam += param;
-                               }
+                               sparam += ' ';
+                               pm->GetParameter(this, sparam);
                        }
                }
        }
@@ -678,8 +652,6 @@ void Channel::UserList(User *user)
        std::string nick;
        for (UserMembIter i = userlist.begin(); i != userlist.end(); ++i)
        {
-               if (i->first->quitting)
-                       continue;
                if ((!has_user) && (i->first->IsModeSet(invisiblemode)) && (!has_privs))
                {
                        /*
@@ -689,10 +661,13 @@ void Channel::UserList(User *user)
                        continue;
                }
 
-               prefixlist = this->GetPrefixChar(i->first);
+               Membership* memb = i->second;
+
+               prefixlist.clear();
+               prefixlist.push_back(memb->GetPrefixChar());
                nick = i->first->nick;
 
-               FOREACH_MOD(OnNamesListItem, (user, i->second, prefixlist, nick));
+               FOREACH_MOD(OnNamesListItem, (user, memb, prefixlist, nick));
 
                /* Nick was nuked, a module wants us to skip it */
                if (nick.empty())
@@ -726,23 +701,18 @@ void Channel::UserList(User *user)
  * % for halfop etc. If the user has several modes set, the highest mode
  * the user has must be returned.
  */
-const char* Channel::GetPrefixChar(User *user)
+char Membership::GetPrefixChar() const
 {
-       static char pf[2] = {0, 0};
-       *pf = 0;
+       char pf = 0;
        unsigned int bestrank = 0;
 
-       UserMembIter m = userlist.find(user);
-       if (m != userlist.end())
+       for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
        {
-               for(unsigned int i=0; i < m->second->modes.length(); i++)
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
+               if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
                {
-                       PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(m->second->modes[i]);
-                       if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
-                       {
-                               bestrank = mh->GetPrefixRank();
-                               pf[0] = mh->GetPrefix();
-                       }
+                       bestrank = mh->GetPrefixRank();
+                       pf = mh->GetPrefix();
                }
        }
        return pf;
@@ -761,20 +731,16 @@ unsigned int Membership::getRank()
        return rv;
 }
 
-const char* Channel::GetAllPrefixChars(User* user)
+const char* Membership::GetAllPrefixChars() const
 {
        static char prefix[64];
        int ctr = 0;
 
-       UserMembIter m = userlist.find(user);
-       if (m != userlist.end())
+       for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
        {
-               for(unsigned int i=0; i < m->second->modes.length(); i++)
-               {
-                       PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(m->second->modes[i]);
-                       if (mh && mh->GetPrefix())
-                               prefix[ctr++] = mh->GetPrefix();
-               }
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
+               if (mh && mh->GetPrefix())
+                       prefix[ctr++] = mh->GetPrefix();
        }
        prefix[ctr] = 0;
 
@@ -828,8 +794,8 @@ void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
        else
        {
                inv = new Invitation(c, u, timeout);
-               c->invites.push_back(inv);
-               u->invites.push_back(inv);
+               c->invites.push_front(inv);
+               u->invites.push_front(inv);
                ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
        }
 }
@@ -840,19 +806,17 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
        if (!u || u->invites.empty())
                return NULL;
 
-       InviteList locallist;
-       locallist.swap(u->invites);
-
        Invitation* result = NULL;
-       for (InviteList::iterator i = locallist.begin(); i != locallist.end(); )
+       for (InviteList::iterator i = u->invites.begin(); i != u->invites.end(); )
        {
                Invitation* inv = *i;
+               ++i;
+
                if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time()))
                {
                        /* Expired invite, remove it. */
                        std::string expiration = InspIRCd::TimeString(inv->expiry);
                        ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str());
-                       i = locallist.erase(i);
                        delete inv;
                }
                else
@@ -863,11 +827,9 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
                                result = inv;
                                break;
                        }
-                       ++i;
                }
        }
 
-       locallist.swap(u->invites);
        ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result);
        return result;
 }
@@ -875,21 +837,7 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
 Invitation::~Invitation()
 {
        // Remove this entry from both lists
-       InviteList::iterator it = std::find(chan->invites.begin(), chan->invites.end(), this);
-       if (it != chan->invites.end())
-               chan->invites.erase(it);
-       it = std::find(user->invites.begin(), user->invites.end(), this);
-       if (it != user->invites.end())
-               user->invites.erase(it);
-}
-
-void InviteBase::ClearInvites()
-{
-       ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "InviteBase::ClearInvites %p", (void*) this);
-       InviteList locallist;
-       locallist.swap(invites);
-       for (InviteList::const_iterator i = locallist.begin(); i != locallist.end(); ++i)
-       {
-               delete *i;
-       }
+       chan->invites.erase(this);
+       user->invites.erase(this);
+       ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "Invitation::~ %p", (void*) this);
 }