]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/listmode.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / listmode.cpp
index 555f75fa39caa6ded6e871c7215066b9fa294c70..cd034688c8ec2b6be81b8ce47f7c929d17fd7cc3 100644 (file)
 #include "listmode.h"
 
 ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag)
-       : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL),
+       : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_LIST),
        listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy),
-       configtag(ctag), extItem("listbase_mode_" + name + "_list", Creator)
+       configtag(ctag)
+       , extItem("listbase_mode_" + name + "_list", ExtensionItem::EXT_CHANNEL, Creator)
 {
        list = true;
 }
@@ -32,53 +33,31 @@ void ListModeBase::DisplayList(User* user, Channel* channel)
        ChanData* cd = extItem.get(channel);
        if (cd)
        {
-               for (ModeList::reverse_iterator it = cd->list.rbegin(); it != cd->list.rend(); ++it)
+               for (ModeList::const_iterator it = cd->list.begin(); it != cd->list.end(); ++it)
                {
-                       user->WriteNumeric(listnumeric, "%s %s %s %s %lu", user->nick.c_str(), channel->name.c_str(), it->mask.c_str(), (!it->setter.empty() ? it->setter.c_str() : ServerInstance->Config->ServerName.c_str()), (unsigned long) it->time);
+                       user->WriteNumeric(listnumeric, channel->name, it->mask, it->setter, (unsigned long) it->time);
                }
        }
-       user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str());
+       user->WriteNumeric(endoflistnumeric, channel->name, endofliststring);
 }
 
 void ListModeBase::DisplayEmptyList(User* user, Channel* channel)
 {
-       user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str());
+       user->WriteNumeric(endoflistnumeric, channel->name, endofliststring);
 }
 
-void ListModeBase::RemoveMode(Channel* channel, irc::modestacker* stack)
+void ListModeBase::RemoveMode(Channel* channel, Modes::ChangeList& changelist)
 {
        ChanData* cd = extItem.get(channel);
        if (cd)
        {
-               irc::modestacker modestack(false);
-
                for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++)
                {
-                       if (stack)
-                               stack->Push(this->GetModeChar(), it->mask);
-                       else
-                               modestack.Push(this->GetModeChar(), it->mask);
-               }
-
-               if (stack)
-                       return;
-
-               std::vector<std::string> stackresult;
-               stackresult.push_back(channel->name);
-               while (modestack.GetStackedLine(stackresult))
-               {
-                       ServerInstance->SendMode(stackresult, ServerInstance->FakeClient);
-                       stackresult.clear();
-                       stackresult.push_back(channel->name);
+                       changelist.push_remove(this, it->mask);
                }
        }
 }
 
-void ListModeBase::RemoveMode(User*, irc::modestacker* stack)
-{
-       /* Listmodes dont get set on users */
-}
-
 void ListModeBase::DoRehash()
 {
        ConfigTagList tags = ServerInstance->Config->ConfTags(configtag);
@@ -96,14 +75,16 @@ void ListModeBase::DoRehash()
                        chanlimits.push_back(limit);
        }
 
-       if (chanlimits.empty())
-               chanlimits.push_back(ListLimit("*", 64));
+       // Add the default entry. This is inserted last so if the user specifies a
+       // wildcard record in the config it will take precedence over this entry.
+       chanlimits.push_back(ListLimit("*", 64));
 
        // Most of the time our settings are unchanged, so we can avoid iterating the chanlist
        if (oldlimits == chanlimits)
                return;
 
-       for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
+       const chan_hash& chans = ServerInstance->GetChans();
+       for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i)
        {
                ChanData* cd = extItem.get(i->second);
                if (cd)
@@ -111,14 +92,6 @@ void ListModeBase::DoRehash()
        }
 }
 
-void ListModeBase::DoImplements(Module* m)
-{
-       ServerInstance->Modules->AddService(extItem);
-       this->DoRehash();
-       Implementation eventlist[] = { I_OnSyncChannel, I_OnRehash };
-       ServerInstance->Modules->Attach(eventlist, m, sizeof(eventlist)/sizeof(Implementation));
-}
-
 unsigned int ListModeBase::FindLimit(const std::string& channame)
 {
        for (limitlist::iterator it = chanlimits.begin(); it != chanlimits.end(); ++it)
@@ -186,7 +159,6 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std
                {
                        /* List is full, give subclass a chance to send a custom message */
                        TellListTooLong(source, channel, parameter);
-                       parameter.clear();
                        return MODEACTION_DENY;
                }
 
@@ -221,7 +193,7 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std
                        {
                                if (parameter == it->mask)
                                {
-                                       cd->list.erase(it);
+                                       stdalgo::vector::swaperase(cd->list, it);
                                        return MODEACTION_ALLOW;
                                }
                        }
@@ -229,33 +201,10 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std
 
                /* Tried to remove something that wasn't set */
                TellNotSet(source, channel, parameter);
-               parameter.clear();
                return MODEACTION_DENY;
        }
 }
 
-void ListModeBase::DoSyncChannel(Channel* chan, Module* proto, void* opaque)
-{
-       ChanData* cd = extItem.get(chan);
-       if (!cd)
-               return;
-
-       irc::modestacker modestack(true);
-       std::vector<std::string> stackresult;
-       std::vector<TranslateType> types;
-       types.push_back(TR_TEXT);
-
-       for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++)
-               modestack.Push(mode, it->mask);
-
-       while (modestack.GetStackedLine(stackresult))
-       {
-               types.assign(stackresult.size(), this->GetTranslateType());
-               proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, stackresult, types);
-               stackresult.clear();
-       }
-}
-
 bool ListModeBase::ValidateParam(User*, Channel*, std::string&)
 {
        return true;
@@ -263,7 +212,7 @@ bool ListModeBase::ValidateParam(User*, Channel*, std::string&)
 
 void ListModeBase::TellListTooLong(User* source, Channel* channel, std::string& parameter)
 {
-       source->WriteNumeric(478, "%s %s %s :Channel ban list is full", source->nick.c_str(), channel->name.c_str(), parameter.c_str());
+       source->WriteNumeric(ERR_BANLISTFULL, channel->name, parameter, "Channel ban list is full");
 }
 
 void ListModeBase::TellAlreadyOnList(User*, Channel*, std::string&)