summaryrefslogtreecommitdiff
path: root/modules/commands
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-11-24 14:27:23 -0500
committerAdam <Adam@anope.org>2014-11-24 14:27:23 -0500
commit42238034490fb5479d787bd1695750387d508200 (patch)
treec93c62e0e1c936e656ae5b9ee1b62380ce2a194c /modules/commands
parentd492923610d9c9146b2a2b63de38deab2cfd4ca7 (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')
-rw-r--r--modules/commands/bs_assign.cpp70
-rw-r--r--modules/commands/bs_badwords.cpp268
-rw-r--r--modules/commands/bs_bot.cpp37
-rw-r--r--modules/commands/bs_botlist.cpp10
-rw-r--r--modules/commands/bs_control.cpp32
-rw-r--r--modules/commands/bs_info.cpp28
-rw-r--r--modules/commands/bs_kick.cpp935
-rw-r--r--modules/commands/bs_set.cpp20
-rw-r--r--modules/commands/cs_access.cpp236
-rw-r--r--modules/commands/cs_akick.cpp321
-rw-r--r--modules/commands/cs_ban.cpp18
-rw-r--r--modules/commands/cs_clone.cpp70
-rw-r--r--modules/commands/cs_drop.cpp12
-rw-r--r--modules/commands/cs_enforce.cpp28
-rw-r--r--modules/commands/cs_entrymsg.cpp188
-rw-r--r--modules/commands/cs_flags.cpp122
-rw-r--r--modules/commands/cs_getkey.cpp6
-rw-r--r--modules/commands/cs_info.cpp16
-rw-r--r--modules/commands/cs_invite.cpp2
-rw-r--r--modules/commands/cs_kick.cpp14
-rw-r--r--modules/commands/cs_list.cpp43
-rw-r--r--modules/commands/cs_log.cpp338
-rw-r--r--modules/commands/cs_mode.cpp450
-rw-r--r--modules/commands/cs_register.cpp23
-rw-r--r--modules/commands/cs_seen.cpp32
-rw-r--r--modules/commands/cs_set.cpp356
-rw-r--r--modules/commands/cs_set_misc.cpp160
-rw-r--r--modules/commands/cs_status.cpp22
-rw-r--r--modules/commands/cs_suspend.cpp185
-rw-r--r--modules/commands/cs_sync.cpp4
-rw-r--r--modules/commands/cs_topic.cpp49
-rw-r--r--modules/commands/cs_unban.cpp12
-rw-r--r--modules/commands/cs_updown.cpp12
-rw-r--r--modules/commands/cs_xop.cpp195
-rw-r--r--modules/commands/greet.cpp58
-rw-r--r--modules/commands/help.cpp2
-rw-r--r--modules/commands/hs_del.cpp18
-rw-r--r--modules/commands/hs_group.cpp18
-rw-r--r--modules/commands/hs_list.cpp10
-rw-r--r--modules/commands/hs_off.cpp4
-rw-r--r--modules/commands/hs_on.cpp4
-rw-r--r--modules/commands/hs_request.cpp173
-rw-r--r--modules/commands/hs_set.cpp14
-rw-r--r--modules/commands/ms_cancel.cpp12
-rw-r--r--modules/commands/ms_check.cpp18
-rw-r--r--modules/commands/ms_del.cpp29
-rw-r--r--modules/commands/ms_ignore.cpp81
-rw-r--r--modules/commands/ms_info.cpp84
-rw-r--r--modules/commands/ms_list.cpp43
-rw-r--r--modules/commands/ms_read.cpp51
-rw-r--r--modules/commands/ms_rsend.cpp4
-rw-r--r--modules/commands/ms_sendall.cpp8
-rw-r--r--modules/commands/ms_set.cpp64
-rw-r--r--modules/commands/ms_staff.cpp8
-rw-r--r--modules/commands/ns_access.cpp126
-rw-r--r--modules/commands/ns_ajoin.cpp202
-rw-r--r--modules/commands/ns_alist.cpp31
-rw-r--r--modules/commands/ns_cert.cpp279
-rw-r--r--modules/commands/ns_drop.cpp8
-rw-r--r--modules/commands/ns_getemail.cpp10
-rw-r--r--modules/commands/ns_getpass.cpp10
-rw-r--r--modules/commands/ns_group.cpp114
-rw-r--r--modules/commands/ns_identify.cpp14
-rw-r--r--modules/commands/ns_info.cpp82
-rw-r--r--modules/commands/ns_list.cpp55
-rw-r--r--modules/commands/ns_recover.cpp44
-rw-r--r--modules/commands/ns_register.cpp106
-rw-r--r--modules/commands/ns_resetpass.cpp38
-rw-r--r--modules/commands/ns_set.cpp332
-rw-r--r--modules/commands/ns_set_misc.cpp164
-rw-r--r--modules/commands/ns_status.cpp8
-rw-r--r--modules/commands/ns_suspend.cpp206
-rw-r--r--modules/commands/ns_update.cpp6
-rw-r--r--modules/commands/os_akill.cpp76
-rw-r--r--modules/commands/os_defcon.cpp8
-rw-r--r--modules/commands/os_dns.cpp605
-rw-r--r--modules/commands/os_forbid.cpp381
-rw-r--r--modules/commands/os_ignore.cpp298
-rw-r--r--modules/commands/os_info.cpp214
-rw-r--r--modules/commands/os_login.cpp54
-rw-r--r--modules/commands/os_modinfo.cpp4
-rw-r--r--modules/commands/os_news.cpp339
-rw-r--r--modules/commands/os_noop.cpp6
-rw-r--r--modules/commands/os_oper.cpp220
-rw-r--r--modules/commands/os_session.cpp358
-rw-r--r--modules/commands/os_stats.cpp18
-rw-r--r--modules/commands/os_sxline.cpp55
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