diff options
| author | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
| commit | 42238034490fb5479d787bd1695750387d508200 (patch) | |
| tree | c93c62e0e1c936e656ae5b9ee1b62380ce2a194c /modules/commands | |
| parent | d492923610d9c9146b2a2b63de38deab2cfd4ca7 (diff) | |
Rewrite serializable to have field level granularity
Represent serializable objects in a digraph, and as a result made most
object relationships implicitly defined, and use the graph to trace
references between objects to determine relationships. Edges may
also be marked as having a dependency of the object they point to,
which allows for automatic cleanup and deletion of most objects when
no longer needed.
Additionally, this allows not having to require in-memory copies of
everything when using external databases. db_sql has been rewritten
for this and now always requires a database to function. db_sql with
MySQL now requires InnoDB to make use of transactions and foreign
key constraints.
Diffstat (limited to 'modules/commands')
87 files changed, 4927 insertions, 4561 deletions
diff --git a/modules/commands/bs_assign.cpp b/modules/commands/bs_assign.cpp index 6fc66f43c..90f6f80cf 100644 --- a/modules/commands/bs_assign.cpp +++ b/modules/commands/bs_assign.cpp @@ -39,7 +39,7 @@ class CommandBSAssign : public Command return; } - BotInfo *bi = BotInfo::Find(nick, true); + ServiceBot *bi = ServiceBot::Find(nick, true); if (!bi) { source.Reply(_("Bot \002{0}\002 does not exist."), nick); @@ -49,25 +49,25 @@ class CommandBSAssign : public Command ChanServ::AccessGroup access = source.AccessFor(ci); if (!access.HasPriv("ASSIGN") && !source.HasPriv("botserv/administration")) { - source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->name); + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->GetName()); return; } - if (ci->HasExt("BS_NOBOT")) + if (ci->HasFieldS("BS_NOBOT")) { - source.Reply(_("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), ci->name); + source.Reply(_("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), ci->GetName()); return; } - if (bi->oper_only && !source.HasPriv("botserv/administration")) + if (bi->bi->GetOperOnly() && !source.HasPriv("botserv/administration")) { source.Reply(_("Access denied. Bot \002{0}\002 is for operators only."), bi->nick); return; } - if (ci->bi == bi) + if (ci->GetBot() == bi) { - source.Reply(_("Bot \002{0}\002 is already assigned to \002{1}\002."), ci->bi->nick, ci->name); + source.Reply(_("Bot \002{0}\002 is already assigned to \002{1}\002."), ci->GetBot()->nick, ci->GetName()); return; } @@ -75,7 +75,7 @@ class CommandBSAssign : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << bi->nick; bi->Assign(source.GetUser(), ci); - source.Reply(_("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, ci->name); + source.Reply(_("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, ci->GetName()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -122,28 +122,28 @@ class CommandBSUnassign : public Command ChanServ::AccessGroup access = source.AccessFor(ci); if (!source.HasPriv("botserv/administration") && !access.HasPriv("ASSIGN")) { - source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->name); + source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->GetName()); return; } - if (!ci->bi) + if (!ci->GetBot()) { - source.Reply(_("There is no bot assigned to \002{0}\002."), ci->name); + source.Reply(_("There is no bot assigned to \002{0}\002."), ci->GetName()); return; } - if (ci->HasExt("PERSIST") && !ModeManager::FindChannelModeByName("PERM")) + if (ci->HasFieldS("PERSIST") && !ModeManager::FindChannelModeByName("PERM")) { source.Reply(_("You can not unassign bots while persist is set on the channel.")); return; } bool override = !access.HasPriv("ASSIGN"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << ci->bi->nick; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << ci->GetBot()->nick; - BotInfo *bi = ci->bi; - ci->bi->UnAssign(source.GetUser(), ci); - source.Reply(_("Bot \002{0}\002 has been unassigned from \002{1}\002."), bi->nick, ci->name); + ServiceBot *bi = ci->GetBot(); + bi->UnAssign(source.GetUser(), ci); + source.Reply(_("Bot \002{0}\002 has been unassigned from \002{1}\002."), bi->nick, ci->GetName()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -186,17 +186,17 @@ class CommandBSSetNoBot : public Command { Log(LOG_ADMIN, source, this, ci) << "to enable nobot"; - ci->Extend<bool>("BS_NOBOT"); - if (ci->bi) - ci->bi->UnAssign(source.GetUser(), ci); - source.Reply(_("No-bot mode is now \002on\002 for \002{0}\002."), ci->name); + ci->SetS<bool>("BS_NOBOT", true); + if (ci->GetBot()) + ci->GetBot()->UnAssign(source.GetUser(), ci); + source.Reply(_("No-bot mode is now \002on\002 for \002{0}\002."), ci->GetName()); } else if (value.equals_ci("OFF")) { Log(LOG_ADMIN, source, this, ci) << "to disable nobot"; - ci->Shrink<bool>("BS_NOBOT"); - source.Reply(_("No-bot mode is now \002off\002 for \002{0}\002."), ci->name); + ci->UnsetS<bool>("BS_NOBOT"); + source.Reply(_("No-bot mode is now \002off\002 for \002{0}\002."), ci->GetName()); } else this->OnSyntaxError(source, source.command); @@ -217,9 +217,9 @@ class CommandBSSetNoBot : public Command class BSAssign : public Module , public EventHook<Event::Invite> - , public EventHook<Event::BotInfoEvent> + , public EventHook<Event::ServiceBotEvent> { - ExtensibleItem<bool> nobot; + Serialize::Field<BotInfo, bool> nobot; CommandBSAssign commandbsassign; CommandBSUnassign commandbsunassign; @@ -228,9 +228,9 @@ class BSAssign : public Module public: BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , EventHook<Event::Invite>("OnInvite") - , EventHook<Event::BotInfoEvent>("OnBotInfoEvent") + , EventHook<Event::ServiceBotEvent>("OnServiceBotEvent") - , nobot(this, "BS_NOBOT") + , nobot(this, botinfo, "BS_NOBOT") , commandbsassign(this) , commandbsunassign(this) @@ -240,40 +240,40 @@ class BSAssign : public Module void OnInvite(User *source, Channel *c, User *targ) override { - BotInfo *bi; - if (Anope::ReadOnly || !c->ci || targ->server != Me || !(bi = BotInfo::Find(targ->nick, true))) + ServiceBot *bi; + if (Anope::ReadOnly || !c->ci || targ->server != Me || !(bi = ServiceBot::Find(targ->nick, true))) return; ChanServ::AccessGroup access = c->ci->AccessFor(source); if (!access.HasPriv("ASSIGN") && !source->HasPriv("botserv/administration")) { - targ->SendMessage(bi, _("Access denied. You do not have privilege \002ASSIGN\002 on \002{0}\002."), c->ci->name); + targ->SendMessage(bi, _("Access denied. You do not have privilege \002ASSIGN\002 on \002{0}\002."), c->ci->GetName()); return; } if (nobot.HasExt(c->ci)) { - targ->SendMessage(bi, _("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), c->ci->name); + targ->SendMessage(bi, _("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), c->ci->GetName()); return; } - if (bi->oper_only && !source->HasPriv("botserv/administration")) + if (bi->bi->GetOperOnly() && !source->HasPriv("botserv/administration")) { targ->SendMessage(bi, _("Access denied. Bot \002{0}\002 is for operators only."), bi->nick); return; } - if (c->ci->bi == bi) + if (c->ci->GetBot() == bi) { - targ->SendMessage(bi, _("Bot \002{0}\002 is already assigned to \002{1}\002."), bi->nick, c->ci->name); + targ->SendMessage(bi, _("Bot \002{0}\002 is already assigned to \002{1}\002."), bi->nick, c->ci->GetName()); return; } bi->Assign(source, c->ci); - targ->SendMessage(bi, _("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, c->ci->name); + targ->SendMessage(bi, _("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, c->ci->GetName()); } - void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) override + void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override { if (nobot.HasExt(ci)) info.AddOption(_("No bot")); diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 38748724e..744f625e1 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -14,136 +14,120 @@ static EventHandlers<Event::BadWordEvents> *bwevents; -struct BadWordImpl : BadWord, Serializable +class BadWordImpl : public BadWord { - BadWordImpl() : Serializable("BadWord") { } - ~BadWordImpl(); + 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; +}; - void Serialize(Serialize::Data &data) const override +class BadWordsType : public Serialize::Type<BadWordImpl> +{ + public: + Serialize::ObjectField<BadWordImpl, ChanServ::Channel *> channel; + 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") { - data["ci"] << this->chan; - data["word"] << this->word; - data.SetType("type", Serialize::Data::DT_INT); data["type"] << this->type; } - - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; -struct BadWordsImpl : BadWords +ChanServ::Channel *BadWordImpl::GetChannel() { - Serialize::Reference<ChanServ::Channel> ci; - typedef std::vector<BadWordImpl *> list; - Serialize::Checker<list> badwords; + return Get(&BadWordsType::channel); +} - BadWordsImpl(Extensible *obj) : ci(anope_dynamic_static_cast<ChanServ::Channel *>(obj)), badwords("BadWord") { } +void BadWordImpl::SetChannel(ChanServ::Channel *c) +{ + Set(&BadWordsType::channel, c); +} - ~BadWordsImpl(); +Anope::string BadWordImpl::GetWord() +{ + return Get(&BadWordsType::word); +} - BadWord* AddBadWord(const Anope::string &word, BadWordType type) override - { - BadWordImpl *bw = new BadWordImpl(); - bw->chan = ci->name; - bw->word = word; - bw->type = type; +void BadWordImpl::SetWord(const Anope::string &w) +{ + Set(&BadWordsType::word, w); +} - this->badwords->push_back(bw); +BadWordType BadWordImpl::GetType() +{ + return Get(&BadWordsType::type); +} - (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw); +void BadWordImpl::SetType(const BadWordType &t) +{ + Set(&BadWordsType::type, t); +} - return bw; - } +struct BadWordsImpl : BadWords +{ + BadWordsImpl(Module *me) : BadWords(me) { } - BadWord* GetBadWord(unsigned index) const override + BadWord* AddBadWord(ChanServ::Channel *ci, const Anope::string &word, BadWordType type) override { - if (this->badwords->empty() || index >= this->badwords->size()) - return NULL; + BadWord *bw = badword.Create(); + bw->SetChannel(ci); + bw->SetWord(word); + bw->SetType(type); + + (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw); - BadWordImpl *bw = (*this->badwords)[index]; - bw->QueueUpdate(); return bw; } - unsigned GetBadWordCount() const override + std::vector<BadWord *> GetBadWords(ChanServ::Channel *ci) { - return this->badwords->size(); + return ci->GetRefs<BadWord *>(badword); } - void EraseBadWord(unsigned index) override + BadWord* GetBadWord(ChanServ::Channel *ci, unsigned index) override { - if (this->badwords->empty() || index >= this->badwords->size()) - return; - - (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, (*this->badwords)[index]); - - delete this->badwords->at(index); + auto bw = GetBadWords(ci); + return index < bw.size() ? bw[index] : nullptr; } - void ClearBadWords() override + unsigned GetBadWordCount(ChanServ::Channel *ci) override { - while (!this->badwords->empty()) - delete this->badwords->back(); + return GetBadWords(ci).size(); } - void Check() override + void EraseBadWord(ChanServ::Channel *ci, unsigned index) override { - if (this->badwords->empty()) - ci->Shrink<BadWords>("badwords"); - } -}; + auto bws = GetBadWords(ci); + if (index >= bws.size()) + return; + + BadWord *bw = bws[index]; + (*bwevents)(&Event::BadWordEvents::OnBadWordDel |
