diff options
| author | Adam <Adam@anope.org> | 2013-05-05 01:55:04 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2013-05-05 01:55:04 -0400 |
| commit | 1d0bb9b26b7ad58ab0bf979ac046f4511b3bf12b (patch) | |
| tree | 4486f0784bdf050fd7eb225c0cb9df352ce1f45a /modules/commands | |
| parent | 781defb7076ddfddf723ca08cd0a518b6657b64f (diff) | |
Rework the config file reader to be much more flexible and move many configuration directives to the actual modules they are used in.
Diffstat (limited to 'modules/commands')
64 files changed, 680 insertions, 719 deletions
diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 90fbb875d..31dee8f8e 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -9,11 +9,8 @@ * Based on the original code of Services by Andy Church. */ -/*************************************************************************/ - #include "module.h" - class BadwordsDelCallback : public NumberList { CommandSource &source; @@ -146,17 +143,20 @@ class CommandBSBadwords : public Command realword = word.substr(0, pos); } - if (ci->GetBadWordCount() >= Config->BSBadWordsMax) + unsigned badwordsmax = Config->GetModule(this->module)->Get<unsigned>("badwordsmax"); + if (ci->GetBadWordCount() >= badwordsmax) { - source.Reply(_("Sorry, you can only have %d bad words entries on a channel."), Config->BSBadWordsMax); + source.Reply(_("Sorry, you can only have %d bad words entries on a channel."), badwordsmax); return; } + bool casesensitive = Config->GetModule("botserv")->Get<bool>("casesensitive"); + for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { const BadWord *bw = ci->GetBadWord(i); - if (!bw->word.empty() && ((Config->BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config->BSCaseSensitive && realword.equals_ci(bw->word)))) + if ((casesensitive && realword.equals_cs(bw->word)) || (!casesensitive && realword.equals_ci(bw->word))) { source.Reply(_("\002%s\002 already exists in %s bad words list."), bw->word.c_str(), ci->name.c_str()); return; @@ -168,8 +168,6 @@ class CommandBSBadwords : public Command ci->AddBadWord(realword, bwtype); source.Reply(_("\002%s\002 added to %s bad words list."), realword.c_str(), ci->name.c_str()); - - return; } void DoDelete(CommandSource &source, ChannelInfo *ci, const Anope::string &word) @@ -219,6 +217,7 @@ class CommandBSBadwords : public Command source.Reply(_("Bad words list is now empty.")); return; } + public: CommandBSBadwords(Module *creator) : Command(creator, "botserv/badwords", 2, 3) { @@ -289,7 +288,7 @@ class CommandBSBadwords : public Command "will be done if a user says a word that ends with\n" "\037word\037. If you don't specify anything, a kick will\n" "be issued every time \037word\037 is said by a user.\n" - " \n"), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str(), source.command.c_str()); + " \n"), Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), source.command.c_str()); source.Reply(_("The \002DEL\002 command removes the given word from the\n" "bad words list. If a list of entry numbers is given, those\n" "entries are deleted. (See the example for LIST below.)\n" @@ -316,7 +315,6 @@ class BSBadwords : public Module BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandbsbadwords(this) { - } }; diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index f8ecb1a1d..16fd9f2f2 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -29,21 +29,23 @@ class CommandBSBot : public Command return; } - if (nick.length() > Config->NickLen) + Configuration::Block *networkinfo = Config->GetBlock("networkinfo"); + + if (nick.length() > networkinfo->Get<unsigned>("nicklen")) { - source.Reply(_("Bot nicks may only be %d characters long."), Config->NickLen); + source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen")); return; } - if (user.length() > Config->UserLen) + if (user.length() > networkinfo->Get<unsigned>("userlen")) { - source.Reply(_("Bot idents may only be %d characters long."), Config->UserLen); + source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen")); return; } - if (host.length() > Config->HostLen) + if (host.length() > networkinfo->Get<unsigned>("hostlen")) { - source.Reply(_("Bot hosts may only be %d characters long."), Config->HostLen); + source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen")); return; } @@ -112,21 +114,23 @@ class CommandBSBot : public Command return; } - if (nick.length() > Config->NickLen) + Configuration::Block *networkinfo = Config->GetBlock("networkinfo"); + + if (nick.length() > networkinfo->Get<unsigned>("nicklen")) { - source.Reply(_("Bot nicks may only be %d characters long."), Config->NickLen); + source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen")); return; } - if (!user.empty() && user.length() > Config->UserLen) + if (user.length() > networkinfo->Get<unsigned>("userlen")) { - source.Reply(_("Bot idents may only be %d characters long."), Config->UserLen); + source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen")); return; } - if (!host.empty() && host.length() > Config->HostLen) + if (host.length() > networkinfo->Get<unsigned>("hostlen")) { - source.Reply(_("Bot hosts may only be %d characters long."), Config->HostLen); + source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen")); return; } @@ -204,7 +208,15 @@ class CommandBSBot : public Command if (!user.empty()) { IRCD->SendClientIntroduction(bi); - bi->RejoinAll(); + unsigned minusers = Config->GetBlock("botserv")->Get<unsigned>("minusers"); + const std::set<ChannelInfo *> &channels = bi->GetChannels(); + for (std::set<ChannelInfo *>::const_iterator it = channels.begin(), it_end = channels.end(); it != it_end; ++it) + { + const ChannelInfo *ci = *it; + + if (ci->c && ci->c->users.size() >= minusers) + bi->Join(ci->c); + } } source.Reply(_("Bot \002%s\002 has been changed to %s!%s@%s (%s)."), oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 86248ae80..5c1bdc6a8 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -13,6 +13,8 @@ #include "module.h" +static Module *me; + class CommandBSKick : public Command { public: @@ -54,7 +56,7 @@ class CommandBSKick : public Command "on a specific option.\n" " \n" "Note: access to this command is controlled by the\n" - "level SET."), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str(), this_name.c_str()); + "level SET."), Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), this_name.c_str()); return true; } @@ -199,7 +201,7 @@ class CommandBSKickBadwords : public CommandBSKickBase "more information.\n" "ttb is the number of times a user can be kicked\n" "before it get banned. Don't give ttb to disable\n" - "the ban system once activated."), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str()); + "the ban system once activated."), Config->StrictPrivmsg.c_str(), source.service->nick.c_str()); return true; } }; @@ -406,8 +408,8 @@ class CommandBSKickFlood : public CommandBSKickBase catch (const ConvertException &) { } if (ci->floodsecs < 1) ci->floodsecs = 10; - if (ci->floodsecs > Config->BSKeepData) - ci->floodsecs = Config->BSKeepData; + if (ci->floodsecs > Config->GetModule(me)->Get<time_t>("keepdata")) + ci->floodsecs = Config->GetModule(me)->Get<time_t>("keepdata"); ci->ExtendMetadata("BS_KICK_FLOOD"); if (ci->ttb[TTB_FLOOD]) @@ -639,13 +641,14 @@ struct BanData : ExtensibleItem void purge() { + time_t keepdata = Config->GetModule(me)->Get<time_t>("keepdata"); for (data_type::iterator it = data_map.begin(), it_end = data_map.end(); it != it_end;) { const Anope::string &user = it->first; Data &bd = it->second; ++it; - if (Anope::CurTime - bd.last_use > Config->BSKeepData) + if (Anope::CurTime - bd.last_use > keepdata) data_map.erase(user); } } @@ -797,8 +800,10 @@ class BSKick : public Module purger(this) { + me = this; - ModuleManager::Attach(I_OnPrivmsg, this); + Implementation i[] = { I_OnPrivmsg }; + ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); } ~BSKick() @@ -920,30 +925,31 @@ class BSKick : public Module /* Normalize the buffer */ Anope::string nbuf = Anope::NormalizeBuffer(realbuf); + bool casesensitive = Config->GetModule("botserv")->Get<bool>("casesensitive"); for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { const BadWord *bw = ci->GetBadWord(i); - if (bw->type == BW_ANY && ((Config->BSCaseSensitive && nbuf.find(bw->word) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) + if (bw->type == BW_ANY && ((casesensitive && nbuf.find(bw->word) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) mustkick = true; else if (bw->type == BW_SINGLE) { size_t len = bw->word.length(); - if ((Config->BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config->BSCaseSensitive && bw->word.equals_ci(nbuf))) + if ((casesensitive && bw->word.equals_cs(nbuf)) || (!casesensitive && bw->word.equals_ci(nbuf))) mustkick = true; - else if (nbuf.find(' ') == len && ((Config->BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config->BSCaseSensitive && bw->word.equals_ci(nbuf)))) + else if (nbuf.find(' ') == len && ((casesensitive && bw->word.equals_cs(nbuf)) || (!casesensitive && bw->word.equals_ci(nbuf)))) mustkick = true; else { - if (nbuf.rfind(' ') == nbuf.length() - len - 1 && ((Config->BSCaseSensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!Config->BSCaseSensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) + if (nbuf.rfind(' ') == nbuf.length() - len - 1 && ((casesensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!casesensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) mustkick = true; else { Anope::string wordbuf = " " + bw->word + " "; - if ((Config->BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; } } @@ -952,13 +958,13 @@ class BSKick : public Module { size_t len = bw->word.length(); - if ((Config->BSCaseSensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!Config->BSCaseSensitive && nbuf.substr(0, len).equals_ci(bw->word))) + if ((casesensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!casesensitive && nbuf.substr(0, len).equals_ci(bw->word))) mustkick = true; else { Anope::string wordbuf = " " + bw->word; - if ((Config->BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; } } @@ -966,13 +972,13 @@ class BSKick : public Module { size_t len = bw->word.length(); - if ((Config->BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!Config->BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) + if ((casesensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!casesensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) mustkick = true; else { Anope::string wordbuf = bw->word + " "; - if ((Config->BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; } } @@ -980,7 +986,7 @@ class BSKick : public Module if (mustkick) { check_ban(ci, u, TTB_BADWORDS); - if (Config->BSGentleBWReason) + if (Config->GetModule(me)->Get<bool>("gentlebadwordreason")) bot_kick(ci, u, _("Watch your language!")); else bot_kick(ci, u, _("Don't use the word \"%s\" on this channel!"), bw->word.c_str()); diff --git a/modules/commands/bs_set.cpp b/modules/commands/bs_set.cpp index 6d764c665..20a53faf3 100644 --- a/modules/commands/bs_set.cpp +++ b/modules/commands/bs_set.cpp @@ -48,7 +48,7 @@ class CommandBSSet : public Command } } source.Reply(_("Type \002%s%s HELP %s \037option\037\002 for more information on a\n" - "particular option."), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str(), this_name.c_str()); + "particular option."), Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), this_name.c_str()); return true; } @@ -309,13 +309,13 @@ class CommandBSSetFantasy : public Command source.Reply(_(" \n" "Enables or disables \002fantasy\002 mode on a channel.\n" "When it is enabled, users will be able to use\n" - "%s commands on a channel when prefixed\n" + "fantasy commands on a channel when prefixed\n" "with one of the following fantasy characters: \002%s\002\n" " \n" "Note that users wanting to use fantaisist\n" "commands MUST have enough access for both\n" "the FANTASIA and the command they are executing."), - Config->ChanServ.c_str(), Config->BSFantasyCharacter.c_str()); + Config->GetModule("botserv")->Get<const char *>("fantasycharacter", "!")); return true; } }; @@ -495,7 +495,6 @@ class BSSet : public Module commandbsset(this), commandbssetbanexpire(this), commandbssetdontkickops(this), commandbssetdontkickvoices(this), commandbssetfantasy(this), commandbssetgreet(this), commandbssetnobot(this), commandbssetprivate(this) { - ModuleManager::Attach(I_OnBotBan, this); } diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 90e17eeed..de434337b 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -158,9 +158,10 @@ class CommandCSAccess : public Command } } - if (ci->GetAccessCount() >= Config->CSAccessMax) + unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024"); + if (access_max && ci->GetAccessCount() >= access_max) { - source.Reply(_("Sorry, you can only have %d access entries on a channel."), Config->CSAccessMax); + source.Reply(_("Sorry, you can only have %d access entries on a channel."), access_max); return; } @@ -555,7 +556,7 @@ class CommandCSAccess : public Command source.Reply(" "); source.Reply(_("\002User access levels\002 can be seen by using the\n" "\002LEVELS\002 command; type \002%s%s HELP LEVELS\002 for\n" - "information."), source.service->nick.c_str(), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str()); + "information."), source.service->nick.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str()); return true; } }; @@ -590,7 +591,7 @@ class CommandCSLevels : public Command { Privilege *p = PrivilegeManager::FindPrivilege(what); if (p == NULL) - source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str()); + source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str()); else { ci->SetLevel(p->name, level); @@ -628,7 +629,7 @@ class CommandCSLevels : public Command } } - source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str()); + source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str()); return; } @@ -792,19 +793,21 @@ class CSAccess : public Module ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); } - void OnReload(ServerConfig *conf, ConfigReader &reader) anope_override + void OnReload(Configuration::Conf *conf) anope_override { defaultLevels.clear(); - for (int i = 0; i < reader.Enumerate("privilege"); ++i) + for (int i = 0; i < conf->CountBlock("privilege"); ++i) { - const Anope::string &pname = reader.ReadValue("privilege", "name", "", i); + Configuration::Block *priv = conf->GetBlock("privilege", i); + + const Anope::string &pname = priv->Get<const Anope::string &>("name"); Privilege *p = PrivilegeManager::FindPrivilege(pname); if (p == NULL) continue; - const Anope::string &value = reader.ReadValue("privilege", "level", "", i); + const Anope::string &value = priv->Get<const Anope::string &>("level"); if (value.empty()) continue; else if (value.equals_ci("founder")) @@ -812,7 +815,7 @@ class CSAccess : public Module else if (value.equals_ci("disabled")) defaultLevels[p->name] = ACCESS_INVALID; else - defaultLevels[p->name] = reader.ReadInteger("privilege", "level", i, false); + defaultLevels[p->name] = priv->Get<int16_t>("level"); } } diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index b2b1c7579..bb1e6ecd6 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -23,8 +23,9 @@ class CommandCSAKick : public Command NickCore *nc = NULL; const AutoKick *akick; - if (reason.length() > Config->CSReasonMax) - reason = reason.substr(0, Config->CSReasonMax); + unsigned reasonmax = Config->GetModule("chanserv")->Get<unsigned>("reasonmax", "200"); + if (reason.length() > reasonmax) + reason = reason.substr(0, reasonmax); if (IRCD->IsExtbanValid(mask)) ; /* If this is an extban don't try to complete the mask */ @@ -148,9 +149,9 @@ class CommandCSAKick : public Command } } - if (ci->GetAkickCount() >= Config->CSAutokickMax) + if (ci->GetAkickCount() >= Config->GetModule(this->owner)->Get<unsigned>("autokickmax")) { - source.Reply(_("Sorry, you can only have %d autokick masks on a channel."), Config->CSAutokickMax); + source.Reply(_("Sorry, you can only have %d autokick masks on a channel."), Config->GetModule(this->owner)->Get<unsigned>("autokickmax")); return; } @@ -513,7 +514,6 @@ class CSAKick : public Module CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsakick(this) { - Implementation i[] = { I_OnCheckKick }; Modu |
