]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/listmode.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / listmode.cpp
index d106bfa1d004b8f548e2e51b37d914279fefdf55..f3b2d5fc57937e93c339c3a077b6fb2aec7219cf 100644 (file)
@@ -1,7 +1,10 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
+ *   Copyright (C) 2018 B00mX0r <b00mx0r@aureus.pw>
+ *   Copyright (C) 2017-2019 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
 #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)
-       , extItem("listbase_mode_" + name + "_list", ExtensionItem::EXT_CHANNEL, Creator)
+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(name + "_mode_list", ExtensionItem::EXT_CHANNEL, Creator)
 {
        list = true;
 }
@@ -60,29 +65,42 @@ void ListModeBase::RemoveMode(Channel* channel, Modes::ChangeList& changelist)
 
 void ListModeBase::DoRehash()
 {
-       ConfigTagList tags = ServerInstance->Config->ConfTags(configtag);
-
-       limitlist oldlimits = chanlimits;
-       chanlimits.clear();
-
+       ConfigTagList tags = ServerInstance->Config->ConfTags("maxlist");
+       limitlist newlimits;
+       bool seen_default = false;
        for (ConfigIter i = tags.first; i != tags.second; i++)
        {
-               // For each <banlist> tag
                ConfigTag* c = i->second;
-               ListLimit limit(c->getString("chan"), c->getInt("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", "*", 1), c->getUInt("limit", DEFAULT_LIST_SIZE));
+
+               if (limit.mask.empty())
+                       throw ModuleException(InspIRCd::Format("<maxlist:chan> is empty, at %s", c->getTagLocation().c_str()));
+
+               if (limit.mask == "*" || limit.mask == "#*")
+                       seen_default = true;
+
+               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));
+       // If no default limit has been specified then insert one.
+       if (!seen_default)
+       {
+               ServerInstance->Logs->Log("MODE", LOG_DEBUG, "No default <maxlist> entry was found for the %s mode; defaulting to %u",
+                       name.c_str(), 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)
        {
@@ -102,7 +120,7 @@ unsigned int ListModeBase::FindLimit(const std::string& channame)
                        return it->limit;
                }
        }
-       return DEFAULT_LIST_SIZE;
+       return 0;
 }
 
 unsigned int ListModeBase::GetLimitInternal(const std::string& channame, ChanData* cd)
@@ -123,13 +141,16 @@ unsigned int ListModeBase::GetLimit(Channel* channel)
 
 unsigned int ListModeBase::GetLowerLimit()
 {
+       if (chanlimits.empty())
+               return DEFAULT_LIST_SIZE;
+
        unsigned int limit = UINT_MAX;
        for (limitlist::iterator iter = chanlimits.begin(); iter != chanlimits.end(); ++iter)
        {
                if (iter->limit < limit)
                        limit = iter->limit;
        }
-       return limit == UINT_MAX ? DEFAULT_LIST_SIZE : limit;
+       return limit;
 }
 
 ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
@@ -142,9 +163,6 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std
                if (tidy)
                        ModeParser::CleanMask(parameter);
 
-               if (parameter.length() > 250)
-                       return MODEACTION_DENY;
-
                // If there was no list
                if (!cd)
                {
@@ -223,17 +241,20 @@ bool ListModeBase::ValidateParam(User*, Channel*, std::string&)
 
 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, "Channel ban list is full");
+       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()));
 }