diff options
| author | Adam <Adam@anope.org> | 2016-07-28 21:29:35 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2016-07-28 21:29:35 -0400 |
| commit | 0e758a2ac23dc4a001e8e126cec14588da9a9769 (patch) | |
| tree | 45df813323e023c5c89db7279426c4ad0943b4a9 /modules/botserv | |
| parent | a3c8afae00c54d5b95c620248b51f90679d7d53f (diff) | |
Allow serializable fields to use storage in the respective objects.
Split service management code nito a proper servicemanager. Make service
references managed instead of lazy lookup. Also made events and
serializable use service manager instead of their respective systems for
management
Diffstat (limited to 'modules/botserv')
| -rw-r--r-- | modules/botserv/assign.cpp | 4 | ||||
| -rw-r--r-- | modules/botserv/autoassign.cpp | 1 | ||||
| -rw-r--r-- | modules/botserv/badwords.cpp | 33 | ||||
| -rw-r--r-- | modules/botserv/bot.cpp | 13 | ||||
| -rw-r--r-- | modules/botserv/botlist.cpp | 2 | ||||
| -rw-r--r-- | modules/botserv/info.cpp | 12 | ||||
| -rw-r--r-- | modules/botserv/kick.cpp | 159 | ||||
| -rw-r--r-- | modules/botserv/main/botserv.cpp | 29 | ||||
| -rw-r--r-- | modules/botserv/set.cpp | 3 |
9 files changed, 158 insertions, 98 deletions
diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp index 1d2755ad5..96e8b0821 100644 --- a/modules/botserv/assign.cpp +++ b/modules/botserv/assign.cpp @@ -227,8 +227,10 @@ class BSAssign : public Module public: BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Invite>(this) + , EventHook<Event::ServiceBotEvent>(this) - , nobot(this, botinfo, "BS_NOBOT") + , nobot(this, "BS_NOBOT") , commandbsassign(this) , commandbsunassign(this) diff --git a/modules/botserv/autoassign.cpp b/modules/botserv/autoassign.cpp index 8978499ed..4b5074abe 100644 --- a/modules/botserv/autoassign.cpp +++ b/modules/botserv/autoassign.cpp @@ -14,6 +14,7 @@ class BSAutoAssign : public Module { public: BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanRegistered>(this) { } diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp index afdc2e09f..94cf8803a 100644 --- a/modules/botserv/badwords.cpp +++ b/modules/botserv/badwords.cpp @@ -12,24 +12,25 @@ #include "module.h" #include "modules/botserv/badwords.h" -static EventHandlers<Event::BadWordEvents> *bwevents; - class BadWordImpl : public BadWord { + friend class BadWordsType; + + ChanServ::Channel *channel = nullptr; + Anope::string word; + BadWordType type; + public: BadWordImpl(Serialize::TypeBase *type) : BadWord(type) { } BadWordImpl(Serialize::TypeBase *type, Serialize::ID id) : BadWord(type, id) { } ChanServ::Channel *GetChannel() override; - void SetChannel(ChanServ::Channel *c) override; Anope::string GetWord() override; - void SetWord(const Anope::string &w) override; BadWordType GetType() override; - void SetType(const BadWordType &t) override; }; @@ -40,10 +41,10 @@ class BadWordsType : public Serialize::Type<BadWordImpl> Serialize::Field<BadWordImpl, Anope::string> word; Serialize::Field<BadWordImpl, BadWordType> type; - BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me, "BadWord") - , channel(this, "ci", true) - , word(this, "word") - , type(this, "type") + BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me) + , channel(this, "ci", &BadWordImpl::channel, true) + , word(this, "word", &BadWordImpl::word) + , type(this, "type", &BadWordImpl::type) { } }; @@ -84,19 +85,19 @@ struct BadWordsImpl : BadWords BadWord* AddBadWord(ChanServ::Channel *ci, const Anope::string &word, BadWordType type) override { - BadWord *bw = badword.Create(); + BadWord *bw = Serialize::New<BadWord *>(); bw->SetChannel(ci); bw->SetWord(word); bw->SetType(type); - (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw); + EventManager::Get()->Dispatch(&Event::BadWordEvents::OnBadWordAdd, ci, bw); return bw; } std::vector<BadWord *> GetBadWords(ChanServ::Channel *ci) override { - return ci->GetRefs<BadWord *>(badword); + return ci->GetRefs<BadWord *>(); } BadWord* GetBadWord(ChanServ::Channel *ci, unsigned index) override @@ -117,7 +118,7 @@ struct BadWordsImpl : BadWords return; BadWord *bw = bws[index]; - (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, bw); + EventManager::Get()->Dispatch(&Event::BadWordEvents::OnBadWordDel, ci, bw); delete bw; } @@ -131,7 +132,8 @@ struct BadWordsImpl : BadWords class CommandBSBadwords : public Command { - private: + ServiceReference<BadWords> badwords; + void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); @@ -448,17 +450,14 @@ class BSBadwords : public Module { CommandBSBadwords commandbsbadwords; BadWordsImpl badwords; - EventHandlers<Event::BadWordEvents> events; BadWordsType bwtype; public: BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , commandbsbadwords(this) , badwords(this) - , events(this) , bwtype(this) { - bwevents = &events; } }; diff --git a/modules/botserv/bot.cpp b/modules/botserv/bot.cpp index b2630bfcb..027df87fa 100644 --- a/modules/botserv/bot.cpp +++ b/modules/botserv/bot.cpp @@ -14,10 +14,6 @@ class CommandBSBot : public Command { - EventHandlers<Event::BotCreate> OnBotCreate; - EventHandlers<Event::BotChange> OnBotChange; - EventHandlers<Event::BotDelete> OnBotDelete; - void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &nick = params[1]; @@ -93,7 +89,7 @@ class CommandBSBot : public Command source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname); - this->OnBotCreate(&Event::BotCreate::OnBotCreate, bi); + EventManager::Get()->Dispatch(&Event::BotCreate::OnBotCreate, bi); } void DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -247,7 +243,7 @@ class CommandBSBot : public Command source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname); Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; - this->OnBotChange(&Event::BotChange::OnBotChange, bi); + EventManager::Get()->Dispatch(&Event::BotChange::OnBotChange, bi); } void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -273,7 +269,7 @@ class CommandBSBot : public Command return; } - this->OnBotDelete(&Event::BotDelete::OnBotDelete, bi); + EventManager::Get()->Dispatch(&Event::BotDelete::OnBotDelete, bi); Log(LOG_ADMIN, source, this) << "DEL " << bi->nick; @@ -283,9 +279,6 @@ class CommandBSBot : public Command public: CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6) - , OnBotCreate(creator) - , OnBotChange(creator) - , OnBotDelete(creator) { this->SetDesc(_("Maintains network bot list")); this->SetSyntax(_("\002ADD \037nicknae\037 \037username\037 \037hostname\037 \037realname\037\002")); diff --git a/modules/botserv/botlist.cpp b/modules/botserv/botlist.cpp index ce899719e..26b23a9fc 100644 --- a/modules/botserv/botlist.cpp +++ b/modules/botserv/botlist.cpp @@ -26,7 +26,7 @@ class CommandBSBotList : public Command list.AddColumn(_("Nick")).AddColumn(_("Mask")); - for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo)) + for (BotInfo *bi : Serialize::GetObjects<BotInfo *>()) { if (source.HasPriv("botserv/administration") || !bi->GetOperOnly()) { diff --git a/modules/botserv/info.cpp b/modules/botserv/info.cpp index 19fe0a775..85100a4ec 100644 --- a/modules/botserv/info.cpp +++ b/modules/botserv/info.cpp @@ -16,10 +16,8 @@ class CommandBSInfo : public Command { - EventHandlers<Event::ServiceBotEvent> &onbotinfo; - public: - CommandBSInfo(Module *creator, EventHandlers<Event::ServiceBotEvent> &event) : Command(creator, "botserv/info", 1, 1), onbotinfo(event) + CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1) { this->SetSyntax(_("{\037channel\037 | \037nickname\037}")); } @@ -41,7 +39,7 @@ class CommandBSInfo : public Command info[_("Options")] = bi->bi->GetOperOnly() ? _("Private") : _("None"); info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)"; - this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); + EventManager::Get()->Dispatch(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); std::vector<Anope::string> replies; info.Process(replies); @@ -72,7 +70,7 @@ class CommandBSInfo : public Command Anope::string enabled = Language::Translate(source.nc, _("Enabled")); Anope::string disabled = Language::Translate(source.nc, _("Disabled")); - this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); + EventManager::Get()->Dispatch(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); std::vector<Anope::string> replies; info.Process(replies); @@ -102,12 +100,10 @@ class CommandBSInfo : public Command class BSInfo : public Module { CommandBSInfo commandbsinfo; - EventHandlers<Event::ServiceBotEvent> onbotinfo; public: BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandbsinfo(this, onbotinfo) - , onbotinfo(this) + , commandbsinfo(this) { } diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp index f61c7eb94..00fd36b88 100644 --- a/modules/botserv/kick.cpp +++ b/modules/botserv/kick.cpp @@ -1,14 +1,9 @@ /* BotServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * */ #include "module.h" @@ -35,6 +30,41 @@ enum TTBType class KickerDataImpl : public KickerData { + friend class KickerDataType; + + ChanServ::Channel *channel = nullptr; + + bool amsgs = false, + badwords = false, + bolds = false, + caps = false, + colors = false, + flood = false, + italics = false, + repeat = false, + reverses = false, + underlines = false; + + int16_t ttb_bolds = 0, + ttb_colors = 0, + ttb_reverses = 0, + ttb_underlines = 0, + ttb_badwords = 0, + ttb_caps = 0, + ttb_flood = 0, + ttb_repeat = 0, + ttb_italics = 0, + ttb_amsgs = 0; + + int16_t capsmin = 0, + capspercent = 0, + floodlines = 0, + floodsecs = 0, + repeattimes = 0; + + bool dontkickops = false, + dontkickvoices = false; + public: KickerDataImpl(Serialize::TypeBase *type) : KickerData(type) { } KickerDataImpl(Serialize::TypeBase *type, Serialize::ID id) : KickerData(type, id) { } @@ -128,42 +158,66 @@ class KickerDataType : public Serialize::Type<KickerDataImpl> { public: Serialize::ObjectField<KickerDataImpl, ChanServ::Channel *> channel; - Serialize::Field<KickerDataImpl, bool> amsgs, badwords, bolds, caps, colors, flood, italics, repeat, reverses, underlines; - Serialize::Field<KickerDataImpl, int16_t> ttb_bolds, ttb_colors, ttb_reverses, ttb_underlines, ttb_badwords, ttb_caps, ttb_flood, ttb_repeat, ttb_italics, ttb_amsgs, - capsmin, capspercent, - floodlines, floodsecs, - repeattimes; - Serialize::Field<KickerDataImpl, bool> dontkickops, dontkickvoices; - - KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner, "KickerData") - , channel(this, "channel", true) - , amsgs(this, "amsgs") - , badwords(this, "badwords") - , bolds(this, "bolds") - , caps(this, "caps") - , colors(this, "colors") - , flood(this, "flood") - , italics(this, "italics") - , repeat(this, "repeat") - , reverses(this, "reverses") - , underlines(this, "underlines") - , ttb_bolds(this, "ttb_bolds") - , ttb_colors(this, "ttb_colors") - , ttb_reverses(this, "ttb_reverses") - , ttb_underlines(this, "ttb_underlines") - , ttb_badwords(this, "ttb_badwords") - , ttb_caps(this, "ttb_caps") - , ttb_flood(this, "ttb_flood") - , ttb_repeat(this, "ttb_repeat") - , ttb_italics(this, "ttb_italics") - , ttb_amsgs(this, "ttb_amsgs") - , capsmin(this, "capsmin") - , capspercent(this, "capspercent") - , floodlines(this, "floodlines") - , floodsecs(this, "floodsecs") - , repeattimes(this, "repeattimes") - , dontkickops(this, "dontkickops") - , dontkickvoices(this, "dontkickvoices") + + Serialize::Field<KickerDataImpl, bool> amsgs, + badwords, + bolds, + caps, + colors, + flood, + italics, + repeat, + reverses, + underlines; + + Serialize::Field<KickerDataImpl, int16_t> ttb_bolds, + ttb_colors, + ttb_reverses, + ttb_underlines, + ttb_badwords, + ttb_caps, + ttb_flood, + ttb_repeat, + ttb_italics, + ttb_amsgs, + capsmin, + capspercent, + floodlines, + floodsecs, + repeattimes; + + Serialize::Field<KickerDataImpl, bool> dontkickops, + dontkickvoices; + + KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner) + , channel(this, "channel", &KickerDataImpl::channel, true) + , amsgs(this, "amsgs", &KickerDataImpl::amsgs) + , badwords(this, "badwords", &KickerDataImpl::badwords) + , bolds(this, "bolds", &KickerDataImpl::bolds) + , caps(this, "caps", &KickerDataImpl::caps) + , colors(this, "colors", &KickerDataImpl::colors) + , flood(this, "flood", &KickerDataImpl::flood) + , italics(this, "italics", &KickerDataImpl::italics) + , repeat(this, "repeat", &KickerDataImpl::repeat) + , reverses(this, "reverses", &KickerDataImpl::reverses) + , underlines(this, "underlines", &KickerDataImpl::underlines) + , ttb_bolds(this, "ttb_bolds", &KickerDataImpl::ttb_bolds) + , ttb_colors(this, "ttb_colors", &KickerDataImpl::ttb_colors) + , ttb_reverses(this, "ttb_reverses", &KickerDataImpl::ttb_reverses) + , ttb_underlines(this, "ttb_underlines", &KickerDataImpl::ttb_underlines) + , ttb_badwords(this, "ttb_badwords", &KickerDataImpl::ttb_badwords) + , ttb_caps(this, "ttb_caps", &KickerDataImpl::ttb_caps) + , ttb_flood(this, "ttb_flood", &KickerDataImpl::ttb_flood) + , ttb_repeat(this, "ttb_repeat", &KickerDataImpl::ttb_repeat) + , ttb_italics(this, "ttb_italics", &KickerDataImpl::ttb_italics) + , ttb_amsgs(this, "ttb_amsgs", &KickerDataImpl::ttb_amsgs) + , capsmin(this, "capsmin", &KickerDataImpl::capsmin) + , capspercent(this, "capspercent", &KickerDataImpl::capspercent) + , floodlines(this, "floodlines", &KickerDataImpl::floodlines) + , floodsecs(this, "floodsecs", &KickerDataImpl::floodsecs) + , repeattimes(this, "repeattimes", &KickerDataImpl::repeattimes) + , dontkickops(this, "dontkickops", &KickerDataImpl::dontkickops) + , dontkickvoices(this, "dontkickvoices", &KickerDataImpl::dontkickvoices) { } }; @@ -477,7 +531,7 @@ class CommandBSKick : public Command if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> command("Command", info.name); + ServiceReference<Command> command(info.name); if (command) { source.command = c_name; @@ -556,7 +610,7 @@ class CommandBSKickBase : public Command void Process(CommandSource &source, ChanServ::Channel *ci, const Anope::string ¶m, const Anope::string &ttb, void (KickerData::*setter)(const bool &), void (KickerData::*ttbsetter)(const int16_t &), const Anope::string &optname) { - KickerData *kd = ci->GetRef<KickerData *>(kickerdata); + KickerData *kd = ci->GetRef<KickerData *>(); if (param.equals_ci("ON")) { @@ -1195,7 +1249,7 @@ class BanDataPurger : public Timer { bd->purge(); if (bd->empty()) - c->ShrinkOK<BanData>("bandata"); + c->Shrink<BanData>("bandata"); } } } @@ -1226,8 +1280,8 @@ class BSKick : public Module CommandBSSetDontKickVoices commandbssetdontkickvoices; BanDataPurger purger; - - EventHandlers<Event::BotBan> onbotban; + + ServiceReference<BadWords> badwords; BanData::Data &GetBanData(User *u, Channel *c) { @@ -1260,7 +1314,7 @@ class BSKick : public Module Anope::string mask = ci->GetIdealBan(u); ci->c->SetMode(NULL, "BAN", mask); - this->onbotban(&Event::BotBan::OnBotBan, u, ci, mask); + EventManager::Get()->Dispatch(&Event::BotBan::OnBotBan, u, ci, mask); } if (!ci->c->FindUser(u)) @@ -1279,6 +1333,9 @@ class BSKick : public Module public: BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ServiceBotEvent>(this) + , EventHook<Event::Privmsg>(this) + , bandata(this, "bandata") , userdata(this, "userdata") @@ -1300,8 +1357,6 @@ class BSKick : public Module , commandbssetdontkickvoices(this) , purger(this) - - , onbotban(this) { me = this; } @@ -1313,7 +1368,7 @@ class BSKick : public Module Anope::string enabled = Language::Translate(source.nc, _("Enabled")); Anope::string disabled = Language::Translate(source.nc, _("Disabled")); - KickerData *kd = ci->GetRef<KickerData *>(&kdtype); + KickerData *kd = ci->GetRef<KickerData *>(); if (kd && kd->GetBadwords()) { @@ -1434,7 +1489,7 @@ class BSKick : public Module ChanServ::Channel *ci = c->ci; if (ci == NULL) return; - KickerData *kd = c->ci->GetRef<KickerData *>(&kdtype); + KickerData *kd = c->ci->GetRef<KickerData *>(); if (kd == NULL) return; diff --git a/modules/botserv/main/botserv.cpp b/modules/botserv/main/botserv.cpp index 0b51691fc..a297db153 100644 --- a/modules/botserv/main/botserv.cpp +++ b/modules/botserv/main/botserv.cpp @@ -20,17 +20,25 @@ class BotServCore : public Module, public BotServ::BotServService , public EventHook<Event::LeaveChannel> , public EventHook<Event::Help> , public EventHook<Event::ChannelModeSet> - , public EventHook<Event::CreateChan> + , public EventHook<Event::ChanRegistered> , public EventHook<Event::UserKicked> , public EventHook<Event::CreateBot> { Reference<ServiceBot> BotServ; - ExtensibleRef<bool> persist, inhabit;//XXX? + ExtensibleRef<bool> inhabit; public: BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , BotServ::BotServService(this) - , persist("PERSIST") + , EventHook<Event::SetCorrectModes>(this) + , EventHook<Event::BotAssign>(this) + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::LeaveChannel>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::ChannelModeSet>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::UserKicked>(this) + , EventHook<Event::CreateBot>(this) , inhabit("inhabit") { } @@ -119,7 +127,7 @@ class BotServCore : public Module, public BotServ::BotServService void OnLeaveChannel(User *u, Channel *c) override { /* Channel is persistent, it shouldn't be deleted and the service bot should stay */ - if (c->ci && persist && persist->HasExt(c->ci)) + if (c->ci && c->ci->HasFieldS("PERSIST")) return; /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediately @@ -132,9 +140,14 @@ class BotServCore : public Module, public BotServ::BotServService if (inhabit && inhabit->HasExt(c)) return; - /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */ - if (c->ci && c->ci->GetBot() && u != c->ci->GetBot() && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(c->ci->GetBot())) - c->ci->GetBot()->Part(c->ci->c); + if (c->ci) + { + ServiceBot *bot = c->ci->GetBot(); + + /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */ + if (bot && u != bot && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(bot)) + bot->Part(c); + } } EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override @@ -201,7 +214,7 @@ class BotServCore : public Module, public BotServ::BotServService return EVENT_CONTINUE; } - void OnCreateChan(ChanServ::Channel *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { /* Set default bot flags */ spacesepstream sep(Config->GetModule(this)->Get<Anope::string>("defaults", "greet fantasy")); diff --git a/modules/botserv/set.cpp b/modules/botserv/set.cpp index b480108af..ee8426e65 100644 --- a/modules/botserv/set.cpp +++ b/modules/botserv/set.cpp @@ -40,7 +40,7 @@ class CommandBSSet : public Command const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> command("Command", info.name); + ServiceReference<Command> command(info.name); if (command) { // XXX dup @@ -203,6 +203,7 @@ class BSSet : public Module public: BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::BotBan>(this) , commandbsset(this) , commandbssetbanexpire(this) , commandbssetprivate(this) |
