#include "inspircd.h"
#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, MC_LIST),
- listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy),
- configtag(ctag)
+ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string& eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy)
+ : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_LIST)
+ , listnumeric(lnum)
+ , endoflistnumeric(eolnum)
+ , endofliststring(eolstr)
+ , tidy(autotidy)
, extItem("listbase_mode_" + name + "_list", ExtensionItem::EXT_CHANNEL, Creator)
{
list = true;
void ListModeBase::DoRehash()
{
- ConfigTagList tags = ServerInstance->Config->ConfTags(configtag);
-
- limitlist oldlimits = chanlimits;
- chanlimits.clear();
-
+ ConfigTagList tags = ServerInstance->Config->ConfTags("maxlist");
+ limitlist newlimits;
for (ConfigIter i = tags.first; i != tags.second; i++)
{
- // For each <banlist> tag
ConfigTag* c = i->second;
- ListLimit limit(c->getString("chan"), c->getUInt("limit", 0));
- if (limit.mask.size() && limit.limit > 0)
- chanlimits.push_back(limit);
+ const std::string mname = c->getString("mode");
+ if (!mname.empty() && !stdalgo::string::equalsci(mname, name) && !(mname.length() == 1 && GetModeChar() == mname[0]))
+ continue;
+
+ ListLimit limit(c->getString("chan", "*"), c->getUInt("limit", 0));
+
+ if (limit.mask.empty())
+ throw ModuleException(InspIRCd::Format("<maxlist:chan> is empty, at %s", c->getTagLocation().c_str()));
+
+ if (limit.limit <= 0)
+ throw ModuleException(InspIRCd::Format("<maxlist:limit> must be non-zero, at %s", c->getTagLocation().c_str()));
+
+ newlimits.push_back(limit);
}
// 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("*", DEFAULT_LIST_SIZE));
+ newlimits.push_back(ListLimit("*", DEFAULT_LIST_SIZE));
// Most of the time our settings are unchanged, so we can avoid iterating the chanlist
- if (oldlimits == chanlimits)
+ if (chanlimits == newlimits)
return;
+ chanlimits.swap(newlimits);
+
const chan_hash& chans = ServerInstance->GetChans();
for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i)
{
void ListModeBase::OnParameterMissing(User*, User*, Channel*)
{
+ // Intentionally left blank.
}
void ListModeBase::TellListTooLong(User* source, Channel* channel, std::string& parameter)
source->WriteNumeric(ERR_BANLISTFULL, channel->name, parameter, mode, InspIRCd::Format("Channel %s list is full", name.c_str()));
}
-void ListModeBase::TellAlreadyOnList(User*, Channel*, std::string&)
+void ListModeBase::TellAlreadyOnList(User* source, Channel* channel, std::string& parameter)
{
+ source->WriteNumeric(ERR_LISTMODEALREADYSET, channel->name, parameter, mode, InspIRCd::Format("Channel %s list already contains %s", name.c_str(), parameter.c_str()));
}
-void ListModeBase::TellNotSet(User*, Channel*, std::string&)
+void ListModeBase::TellNotSet(User* source, Channel* channel, std::string& parameter)
{
+ source->WriteNumeric(ERR_LISTMODENOTSET, channel->name, parameter, mode, InspIRCd::Format("Channel %s list does not contain %s", name.c_str(), parameter.c_str()));
}