From 573e49a7ead331219eb6f0d3ca9cf83e793a5c9c Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 23 Apr 2012 05:08:26 -0400 Subject: Reworked live SQL support yet again --- modules/commands/bs_badwords.cpp | 8 ++-- modules/commands/bs_bot.cpp | 13 +++--- modules/commands/bs_botlist.cpp | 2 +- modules/commands/bs_info.cpp | 10 ++--- modules/commands/bs_kick.cpp | 4 +- modules/commands/cs_access.cpp | 24 +++++----- modules/commands/cs_akick.cpp | 17 ++++---- modules/commands/cs_clone.cpp | 11 ++--- modules/commands/cs_drop.cpp | 2 +- modules/commands/cs_enforce.cpp | 14 +++--- modules/commands/cs_entrymsg.cpp | 25 ++++++++--- modules/commands/cs_fantasy_stats.cpp | 5 ++- modules/commands/cs_flags.cpp | 8 ++-- modules/commands/cs_info.cpp | 6 ++- modules/commands/cs_list.cpp | 4 +- modules/commands/cs_log.cpp | 67 ++++++++++++++-------------- modules/commands/cs_mode.cpp | 16 +++---- modules/commands/cs_modes.cpp | 30 +++++++++---- modules/commands/cs_register.cpp | 11 ++--- modules/commands/cs_saset.cpp | 4 +- modules/commands/cs_seen.cpp | 22 ++++++---- modules/commands/cs_set.cpp | 4 +- modules/commands/cs_set_founder.cpp | 5 +-- modules/commands/cs_set_misc.cpp | 30 +++++++++---- modules/commands/cs_set_successor.cpp | 2 +- modules/commands/cs_suspend.cpp | 34 ++++++++++----- modules/commands/cs_updown.cpp | 4 +- modules/commands/cs_xop.cpp | 20 ++++----- modules/commands/help.cpp | 10 ++--- modules/commands/hs_del.cpp | 4 +- modules/commands/hs_group.cpp | 9 ++-- modules/commands/hs_list.cpp | 4 +- modules/commands/hs_off.cpp | 2 +- modules/commands/hs_on.cpp | 2 +- modules/commands/hs_request.cpp | 33 +++++++++----- modules/commands/hs_set.cpp | 9 ++-- modules/commands/ms_cancel.cpp | 17 ++++++-- modules/commands/ms_check.cpp | 14 +++--- modules/commands/ms_del.cpp | 33 +++++++------- modules/commands/ms_info.cpp | 43 +++++++++--------- modules/commands/ms_list.cpp | 21 ++++----- modules/commands/ms_read.cpp | 31 ++++++------- modules/commands/ms_rsend.cpp | 4 +- modules/commands/ms_sendall.cpp | 6 +-- modules/commands/ms_set.cpp | 35 ++++++++------- modules/commands/ms_staff.cpp | 4 +- modules/commands/ns_access.cpp | 3 +- modules/commands/ns_ajoin.cpp | 35 ++++++++++----- modules/commands/ns_alist.cpp | 4 +- modules/commands/ns_cert.cpp | 16 ++++--- modules/commands/ns_drop.cpp | 2 +- modules/commands/ns_getemail.cpp | 4 +- modules/commands/ns_getpass.cpp | 2 +- modules/commands/ns_ghost.cpp | 2 +- modules/commands/ns_group.cpp | 82 ++++++++++++++++++++--------------- modules/commands/ns_info.cpp | 2 +- modules/commands/ns_list.cpp | 4 +- modules/commands/ns_register.cpp | 39 ++++++++++------- modules/commands/ns_resetpass.cpp | 18 ++++---- modules/commands/ns_saset.cpp | 6 +-- modules/commands/ns_sendpass.cpp | 6 +-- modules/commands/ns_set.cpp | 4 +- modules/commands/ns_set_autoop.cpp | 2 +- modules/commands/ns_set_display.cpp | 4 +- modules/commands/ns_set_email.cpp | 17 +++++--- modules/commands/ns_set_greet.cpp | 2 +- modules/commands/ns_set_hide.cpp | 2 +- modules/commands/ns_set_kill.cpp | 2 +- modules/commands/ns_set_language.cpp | 2 +- modules/commands/ns_set_message.cpp | 2 +- modules/commands/ns_set_misc.cpp | 32 ++++++++++---- modules/commands/ns_set_private.cpp | 2 +- modules/commands/ns_set_secure.cpp | 2 +- modules/commands/ns_status.cpp | 2 +- modules/commands/ns_suspend.cpp | 45 +++++++++++-------- modules/commands/os_akill.cpp | 8 ++-- modules/commands/os_forbid.cpp | 8 ++-- modules/commands/os_forbid.h | 24 ++++++---- modules/commands/os_ignore.cpp | 6 ++- modules/commands/os_ignore.h | 28 ++++++++---- modules/commands/os_modinfo.cpp | 4 +- modules/commands/os_news.cpp | 12 ++--- modules/commands/os_news.h | 24 ++++++---- modules/commands/os_oper.cpp | 34 +++++++++------ modules/commands/os_session.cpp | 8 ++-- modules/commands/os_session.h | 24 ++++++---- modules/commands/os_stats.cpp | 9 ++-- modules/commands/os_sxline.cpp | 12 ++--- 88 files changed, 709 insertions(+), 520 deletions(-) (limited to 'modules/commands') diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index bb7a073f1..eaf00d347 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -81,7 +81,7 @@ class CommandBSBadwords : public Command if (!Number || Number > ci->GetBadWordCount()) return; - BadWord *bw = ci->GetBadWord(Number - 1); + const BadWord *bw = ci->GetBadWord(Number - 1); ListFormatter::ListEntry entry; entry["Number"] = stringify(Number); entry["Word"] = bw->word; @@ -96,7 +96,7 @@ class CommandBSBadwords : public Command { for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { - BadWord *bw = ci->GetBadWord(i); + const BadWord *bw = ci->GetBadWord(i); if (!word.empty() && !Anope::Match(bw->word, word)) continue; @@ -154,7 +154,7 @@ class CommandBSBadwords : public Command for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { - BadWord *bw = ci->GetBadWord(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)))) { @@ -183,7 +183,7 @@ class CommandBSBadwords : public Command else { unsigned i, end; - BadWord *badword; + const BadWord *badword; for (i = 0, end = ci->GetBadWordCount(); i < end; ++i) { diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index 526cd922c..b1f22909f 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -22,7 +22,6 @@ class CommandBSBot : public Command const Anope::string &user = params[2]; const Anope::string &host = params[3]; const Anope::string &real = params[4]; - BotInfo *bi; if (findbot(nick)) { @@ -93,7 +92,7 @@ class CommandBSBot : public Command return; } - bi = new BotInfo(nick, user, host, real); + BotInfo *bi = new BotInfo(nick, user, host, real); Log(LOG_ADMIN, source.u, this) << "ADD " << bi->GetMask() << " " << bi->realname; @@ -110,7 +109,6 @@ class CommandBSBot : public Command const Anope::string &user = params.size() > 3 ? params[3] : ""; const Anope::string &host = params.size() > 4 ? params[4] : ""; const Anope::string &real = params.size() > 5 ? params[5] : ""; - BotInfo *bi; if (oldnick.empty() || nick.empty()) { @@ -118,7 +116,8 @@ class CommandBSBot : public Command return; } - if (!(bi = findbot(oldnick))) + BotInfo *bi = findbot(oldnick); + if (!bi) { source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return; @@ -263,7 +262,6 @@ class CommandBSBot : public Command void DoDel(CommandSource &source, const std::vector ¶ms) { const Anope::string &nick = params[1]; - BotInfo *bi; if (nick.empty()) { @@ -271,7 +269,8 @@ class CommandBSBot : public Command return; } - if (!(bi = findbot(nick))) + BotInfo *bi = findbot(nick); + if (!bi) { source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); return; @@ -288,7 +287,7 @@ class CommandBSBot : public Command Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick; source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str()); - delete bi; + bi->destroy(); return; } public: diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index ed50371fc..68fb7bdfa 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -30,7 +30,7 @@ class CommandBSBotList : public Command list.addColumn("Nick").addColumn("Mask"); - for (Anope::insensitive_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + for (Anope::insensitive_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) { BotInfo *bi = it->second; diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index ed36818b3..251bd84df 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -17,12 +17,12 @@ class CommandBSInfo : public Command { private: - void send_bot_channels(std::vector &buffers, BotInfo *bi) + void send_bot_channels(std::vector &buffers, const BotInfo *bi) { Anope::string buf; - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) + for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) { - ChannelInfo *ci = it->second; + const ChannelInfo *ci = it->second; if (ci->bi == bi) { @@ -38,7 +38,7 @@ class CommandBSInfo : public Command buffers.push_back(buf); } - void CheckOptStr(Anope::string &buf, BotServFlag flag, const char *option, Flags &flags, NickCore *nc) + void CheckOptStr(Anope::string &buf, BotServFlag flag, const char *option, Flags &flags, const NickCore *nc) { if (flags.HasFlag(flag)) { @@ -60,7 +60,7 @@ class CommandBSInfo : public Command const Anope::string &query = params[0]; User *u = source.u; - BotInfo *bi = findbot(query); + const BotInfo *bi = findbot(query); ChannelInfo *ci; InfoFormatter info(u); diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 42b43e7a1..819c5af74 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -900,7 +900,7 @@ class BSKick : public Module for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { - BadWord *bw = ci->GetBadWord(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))) mustkick = true; @@ -1012,7 +1012,7 @@ class BSKick : public Module Channel *chan = (*it)->chan; ++it; - if (chan->ci != NULL && chan->ci->botflags.HasFlag(BS_KICK_AMSGS) && !chan->ci->AccessFor(u).HasPriv("NOKICK")) + if (chan->ci && chan->ci->botflags.HasFlag(BS_KICK_AMSGS) && !chan->ci->AccessFor(u).HasPriv("NOKICK")) { check_ban(chan->ci, u, TTB_AMSGS); bot_kick(chan->ci, u, _("Don't use AMSGs!")); diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index aa32d29ef..a37446df2 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -15,7 +15,7 @@ static std::map defaultLevels; -static void reset_levels(ChannelInfo *ci) +static inline void reset_levels(ChannelInfo *ci) { ci->ClearLevels(); for (std::map::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it) @@ -36,7 +36,7 @@ class AccessChanAccess : public ChanAccess return this->ci->GetLevel(name) != ACCESS_INVALID && this->level >= this->ci->GetLevel(name); } - Anope::string Serialize() + Anope::string Serialize() const { return stringify(this->level); } @@ -46,11 +46,11 @@ class AccessChanAccess : public ChanAccess this->level = convertTo(data); } - static int DetermineLevel(ChanAccess *access) + static int DetermineLevel(const ChanAccess *access) { if (access->provider->name == "access/access") { - AccessChanAccess *aaccess = debug_cast(access); + const AccessChanAccess *aaccess = debug_cast(access); return aaccess->level; } else @@ -108,7 +108,7 @@ class CommandCSAccess : public Command } AccessGroup u_access = ci->AccessFor(u); - ChanAccess *highest = u_access.Highest(); + const ChanAccess *highest = u_access.Highest(); int u_level = (highest ? AccessChanAccess::DetermineLevel(highest) : 0); if (level >= u_level && !u_access.Founder && !u->HasPriv("chanserv/access/modify")) { @@ -123,7 +123,7 @@ class CommandCSAccess : public Command bool override = !ci->AccessFor(u).HasPriv("ACCESS_CHANGE") || (level >= u_level && !u_access.Founder); - if (mask.find_first_of("!*@") == Anope::string::npos && findnick(mask) == NULL) + if (mask.find_first_of("!*@") == Anope::string::npos && !findnick(mask)) { User *targ = finduser(mask); if (targ != NULL) @@ -137,7 +137,7 @@ class CommandCSAccess : public Command for (unsigned i = ci->GetAccessCount(); i > 0; --i) { - ChanAccess *access = ci->GetAccess(i - 1); + const ChanAccess *access = ci->GetAccess(i - 1); if (mask.equals_ci(access->mask)) { /* Don't allow lowering from a level >= u_level */ @@ -230,7 +230,7 @@ class CommandCSAccess : public Command ChanAccess *access = ci->GetAccess(Number - 1); AccessGroup u_access = ci->AccessFor(user); - ChanAccess *u_highest = u_access.Highest(); + const ChanAccess *u_highest = u_access.Highest(); if ((u_highest ? AccessChanAccess::DetermineLevel(u_highest) : 0) <= AccessChanAccess::DetermineLevel(access) && !u_access.Founder && !this->override && !access->mask.equals_ci(user->Account()->display)) { @@ -255,7 +255,7 @@ class CommandCSAccess : public Command else { AccessGroup u_access = ci->AccessFor(u); - ChanAccess *highest = u_access.Highest(); + const ChanAccess *highest = u_access.Highest(); int u_level = (highest ? AccessChanAccess::DetermineLevel(highest) : 0); for (unsigned i = ci->GetAccessCount(); i > 0; --i) @@ -308,7 +308,7 @@ class CommandCSAccess : public Command if (!number || number > ci->GetAccessCount()) return; - ChanAccess *access = ci->GetAccess(number - 1); + const ChanAccess *access = ci->GetAccess(number - 1); Anope::string timebuf; if (ci->c) @@ -339,7 +339,7 @@ class CommandCSAccess : public Command { for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - ChanAccess *access = ci->GetAccess(i); + const ChanAccess *access = ci->GetAccess(i); if (!nick.empty() && !Anope::Match(access->mask, nick)) continue; @@ -470,7 +470,7 @@ class CommandCSAccess : public Command has_access = true; else if (is_del) { - NickAlias *na = findnick(nick); + const NickAlias *na = findnick(nick); if (na && na->nc == u->Account()) has_access = true; } diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index beaa8ffd3..107f97584 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -54,9 +54,9 @@ class CommandCSAKick : public Command Anope::string mask = params[2]; Anope::string reason = params.size() > 3 ? params[3] : ""; - NickAlias *na = findnick(mask); + const NickAlias *na = findnick(mask); NickCore *nc = NULL; - AutoKick *akick; + const AutoKick *akick; if (!na) { @@ -113,7 +113,7 @@ class CommandCSAKick : public Command /* Match against the lastusermask of all nickalias's with equal * or higher access. - Viper */ - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) + for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) { na = it->second; @@ -166,7 +166,6 @@ class CommandCSAKick : public Command User *u = source.u; const Anope::string &mask = params[2]; - AutoKick *akick; unsigned i, end; if (!ci->GetAkickCount()) @@ -218,12 +217,12 @@ class CommandCSAKick : public Command } else { - NickAlias *na = findnick(mask); - NickCore *nc = na ? na->nc : NULL; + const NickAlias *na = findnick(mask); + const NickCore *nc = na ? *na->nc : NULL; for (i = 0, end = ci->GetAkickCount(); i < end; ++i) { - akick = ci->GetAkick(i); + const AutoKick *akick = ci->GetAkick(i); if ((akick->HasFlag(AK_ISNICK) && akick->nc == nc) || (!akick->HasFlag(AK_ISNICK) && mask.equals_ci(akick->mask))) break; @@ -267,7 +266,7 @@ class CommandCSAKick : public Command if (!number || number > ci->GetAkickCount()) return; - AutoKick *akick = ci->GetAkick(number - 1); + const AutoKick *akick = ci->GetAkick(number - 1); Anope::string timebuf, lastused; if (akick->addtime) @@ -296,7 +295,7 @@ class CommandCSAKick : public Command { for (unsigned i = 0, end = ci->GetAkickCount(); i < end; ++i) { - AutoKick *akick = ci->GetAkick(i); + const AutoKick *akick = ci->GetAkick(i); if (!mask.empty()) { diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp index 1676c70f6..be6907b81 100644 --- a/modules/commands/cs_clone.cpp +++ b/modules/commands/cs_clone.cpp @@ -41,6 +41,7 @@ public: source.Reply(ACCESS_DENIED); return; } + ChannelInfo *target_ci = cs_findchan(target); if (!target_ci) { @@ -58,10 +59,10 @@ public: if (what.empty()) { - delete target_ci; + target_ci->destroy(); target_ci = new ChannelInfo(*ci); target_ci->name = target; - RegisteredChannelList[target_ci->name] = target_ci; + (*RegisteredChannelList)[target_ci->name] = target_ci; target_ci->c = findchan(target_ci->name); if (target_ci->c) { @@ -107,7 +108,7 @@ public: { for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { - ChanAccess *taccess = ci->GetAccess(i); + const ChanAccess *taccess = ci->GetAccess(i); AccessProvider *provider = taccess->provider; ChanAccess *newaccess = provider->Create(); @@ -128,7 +129,7 @@ public: target_ci->ClearAkick(); for (unsigned i = 0; i < ci->GetAkickCount(); ++i) { - AutoKick *akick = ci->GetAkick(i); + const AutoKick *akick = ci->GetAkick(i); if (akick->HasFlag(AK_ISNICK)) target_ci->AddAkick(akick->creator, akick->nc, akick->reason, akick->addtime, akick->last_used); else @@ -142,7 +143,7 @@ public: target_ci->ClearBadWords(); for (unsigned i = 0; i < ci->GetBadWordCount(); ++i) { - BadWord *bw = ci->GetBadWord(i); + const BadWord *bw = ci->GetBadWord(i); target_ci->AddBadWord(bw->word, bw->type); } diff --git a/modules/commands/cs_drop.cpp b/modules/commands/cs_drop.cpp index d2d05c457..fb9da23b8 100644 --- a/modules/commands/cs_drop.cpp +++ b/modules/commands/cs_drop.cpp @@ -59,7 +59,7 @@ class CommandCSDrop : public Command FOREACH_MOD(I_OnChanDrop, OnChanDrop(ci)); Channel *c = ci->c; - delete ci; + ci->destroy(); source.Reply(_("Channel \002%s\002 has been dropped."), chan.c_str()); diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index 1c5cabddd..62c8e0c6d 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -20,9 +20,9 @@ class CommandCSEnforce : public Command private: void DoSet(Channel *c) { - ChannelInfo *ci; + const ChannelInfo *ci = c->ci; - if (!(ci = c->ci)) + if (!ci) return; if (ci->HasFlag(CI_SECUREOPS)) @@ -39,10 +39,9 @@ class CommandCSEnforce : public Command void DoSecureOps(Channel *c) { - ChannelInfo *ci; - bool hadsecureops = false; + ChannelInfo *ci = c->ci; - if (!(ci = c->ci)) + if (!ci) return; /* Dirty hack to allow chan_set_correct_modes to work ok. @@ -50,6 +49,7 @@ class CommandCSEnforce : public Command * part of the code. This way we can enforce SECUREOPS even * if it's off. */ + bool hadsecureops = false; if (!ci->HasFlag(CI_SECUREOPS)) { ci->SetFlag(CI_SECUREOPS); @@ -91,10 +91,10 @@ class CommandCSEnforce : public Command void DoCModeR(Channel *c) { - ChannelInfo *ci; + ChannelInfo *ci = c->ci; Anope::string mask; - if (!(ci = c->ci)) + if (!ci) return; for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index 477f68cb2..9b5a6753c 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -15,7 +15,7 @@ struct EntryMsg : Serializable { - ChannelInfo *ci; + serialize_obj ci; Anope::string creator; Anope::string message; time_t when; @@ -29,14 +29,14 @@ struct EntryMsg : Serializable this->when = ct; } - Anope::string serialize_name() const anope_override + const Anope::string serialize_name() const anope_override { return "EntryMsg"; } - serialized_data serialize() anope_override + Serialize::Data serialize() const anope_override { - serialized_data data; + Serialize::Data data; data["ci"] << this->ci->name; data["creator"] << this->creator; @@ -46,7 +46,7 @@ struct EntryMsg : Serializable return data; } - static void unserialize(serialized_data &data); + static Serializable* unserialize(Serializable *obj, Serialize::Data &data); }; static unsigned MaxEntries = 0; @@ -55,11 +55,21 @@ struct EntryMessageList : std::vector, ExtensibleItem { }; -void EntryMsg::unserialize(serialized_data &data) +Serializable* EntryMsg::unserialize(Serializable *obj, Serialize::Data &data) { ChannelInfo *ci = cs_findchan(data["ci"].astr()); if (!ci) - return; + return NULL; + + if (obj) + { + EntryMsg *msg = debug_cast(obj); + msg->ci = ci; + data["creator"] >> msg->creator; + data["message"] >> msg->message; + data["when"] >> msg->when; + return msg; + } EntryMessageList *messages = ci->GetExt("cs_entrymsg"); if (messages == NULL) @@ -69,6 +79,7 @@ void EntryMsg::unserialize(serialized_data &data) } messages->push_back(EntryMsg(ci, data["creator"].astr(), data["message"].astr())); + return &messages->back(); } class CommandEntryMessage : public Command diff --git a/modules/commands/cs_fantasy_stats.cpp b/modules/commands/cs_fantasy_stats.cpp index 7a4419e30..3e9d482b8 100644 --- a/modules/commands/cs_fantasy_stats.cpp +++ b/modules/commands/cs_fantasy_stats.cpp @@ -106,7 +106,7 @@ class CSStats : public Module Anope::string display; if (params.empty()) display = source.u->Account()->display; - else if (NickAlias *na = findnick(params[0])) + else if (const NickAlias *na = findnick(params[0])) display = na->nc->display; else { @@ -165,4 +165,5 @@ void CommandCSGStats::Execute(CommandSource &source, const std::vectorDoStats(source, true, params); } -MODULE_INIT(CSStats) \ No newline at end of file +MODULE_INIT(CSStats) + diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index aceb28192..222409eca 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -32,7 +32,7 @@ class FlagsChanAccess : public ChanAccess return false; } - Anope::string Serialize() + Anope::string Serialize() const { return Anope::string(this->flags.begin(), this->flags.end()); } @@ -43,7 +43,7 @@ class FlagsChanAccess : public ChanAccess this->flags.insert(data[i - 1]); } - static Anope::string DetermineFlags(ChanAccess *access) + static Anope::string DetermineFlags(const ChanAccess *access) { if (access->provider->name == "access/flags") return access->Serialize(); @@ -88,7 +88,7 @@ class CommandCSFlags : public Command AccessGroup u_access = ci->AccessFor(u); - if (mask.find_first_of("!*@") == Anope::string::npos && findnick(mask) == NULL) + if (mask.find_first_of("!*@") == Anope::string::npos && !findnick(mask)) { User *targ = finduser(mask); if (targ != NULL) @@ -234,7 +234,7 @@ class CommandCSFlags : public Command unsigned count = 0; for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - ChanAccess *access = ci->GetAccess(i); + const ChanAccess *access = ci->GetAccess(i); const Anope::string &flags = FlagsChanAccess::DetermineFlags(access); if (!arg.empty()) diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp index 290ead3ba..47ba4d3b0 100644 --- a/modules/commands/cs_info.cpp +++ b/modules/commands/cs_info.cpp @@ -13,9 +13,11 @@ #include "module.h" +struct ExtensibleString : Anope::string, ExtensibleItem { }; + class CommandCSInfo : public Command { - void CheckOptStr(Anope::string &buf, ChannelInfoFlag opt, const char *str, ChannelInfo *ci, NickCore *nc) + void CheckOptStr(Anope::string &buf, ChannelInfoFlag opt, const char *str, const ChannelInfo *ci, const NickCore *nc) { if (ci->HasFlag(opt)) { @@ -68,7 +70,7 @@ class CommandCSInfo : public Command info["Registered"] = do_strftime(ci->time_registered); info["Last used"] = do_strftime(ci->last_used); - ModeLock *secret = ci->GetMLock(CMODE_SECRET); + const ModeLock *secret = ci->GetMLock(CMODE_SECRET); if (!ci->last_topic.empty() && (show_all || ((!secret || secret->set == false) && (!ci->c || !ci->c->HasMode(CMODE_SECRET))))) { info["Last topic"] = ci->last_topic; diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp index 77d7613fe..8385fc38b 100644 --- a/modules/commands/cs_list.cpp +++ b/modules/commands/cs_list.cpp @@ -76,9 +76,9 @@ class CommandCSList : public Command ListFormatter list; list.addColumn("Name").addColumn("Description"); - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) + for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) { - ChannelInfo *ci = it->second; + const ChannelInfo *ci = it->second; if (!is_servadmin && (ci->HasFlag(CI_PRIVATE) || ci->HasFlag(CI_SUSPENDED))) continue; diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp index 28c7e6f91..163789b53 100644 --- a/modules/commands/cs_log.cpp +++ b/modules/commands/cs_log.cpp @@ -36,23 +36,23 @@ public: source.Reply(ACCESS_DENIED); else if (params.size() == 1) { - if (ci->log_settings.empty()) + if (ci->log_settings->empty()) source.Reply(_("There currently are no logging configurations for %s."), ci->name.c_str()); else { ListFormatter list; list.addColumn("Number").addColumn("Service").addColumn("Command").addColumn("Method").addColumn(""); - for (unsigned i = 0; i < ci->log_settings.size(); ++i) + for (unsigned i = 0; i < ci->log_settings->size(); ++i) { - LogSetting &log = ci->log_settings[i]; + const LogSetting *log = ci->log_settings->at(i); ListFormatter::ListEntry entry; entry["Number"] = stringify(i + 1); - entry["Service"] = log.command_service; - entry["Command"] = log.command_name; - entry["Method"] = log.method; - entry[""] = log.extra; + entry["Service"] = log->command_service; + entry["Command"] = log->command_name; + entry["Method"] = log->method; + entry[""] = log->extra; list.addEntry(entry); } @@ -110,21 +110,22 @@ public: bool override = !ci->AccessFor(u).HasPriv("SET"); - for (unsigned i = ci->log_settings.size(); i > 0; --i) + for (unsigned i = ci->log_settings->size(); i > 0; --i) { - LogSetting &log = ci->log_settings[i - 1]; + LogSetting *log = ci->log_settings->at(i - 1); - if (log.service_name == bi->commands[command_name].name && log.method.equals_ci(method)) + if (log->service_name == bi->commands[command_name].name && log->method.equals_ci(method)) { - if (log.extra == extra) + if (log->extra == extra) { - ci->log_settings.erase(ci->log_settings.begin() + i - 1); + log->destroy(); + ci->log_settings->erase(ci->log_settings->begin() + i - 1); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to remove logging for " << command << " with method " << method << (extra == "" ? "" : " ") << extra; source.Reply(_("Logging for command %s on %s with log method %s%s%s has been removed."), command_name.c_str(), bi->nick.c_str(), method.c_str(), extra.empty() ? "" : " ", extra.empty() ? "" : extra.c_str()); } else { - log.extra = extra; + log->extra = extra; Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to change logging for " << command << " to method " << method << (extra == "" ? "" : " ") << extra; source.Reply(_("Logging changed for command %s on %s, now using log method %s%s%s."), command_name.c_str(), bi->nick.c_str(), method.c_str(), extra.empty() ? "" : " ", extra.empty() ? "" : extra.c_str()); } @@ -132,17 +133,17 @@ public: } } - LogSetting log; - log.ci = ci; - log.service_name = bi->commands[command_name].name; - log.command_service = bi->nick; - log.command_name = command_name; - log.method = method; - log.extra = extra; - log.created = Anope::CurTime; - log.creator = u->nick; - - ci->log_settings.push_back(log); + LogSetting *log = new LogSetting(); + log->ci = ci; + log->service_name = bi->commands[command_name].name; + log->command_service = bi->nick; + log->command_name = command_name; + log->method = method; + log->extra = extra; + log->created = Anope::CurTime; + log->creator = u->nick; + + ci->log_settings->push_back(log); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to log " << command << " with method " << method << (extra == "" ? "" : " ") << extra; source.Reply(_("Logging is now active for command %s on %s, using log method %s%s%s."), command_name.c_str(), bi->nick.c_str(), method.c_str(), extra.empty() ? "" : " ", extra.empty() ? "" : extra.c_str()); @@ -197,19 +198,19 @@ class CSLog : public Module if (l->Type != LOG_COMMAND || l->u == NULL || l->c == NULL || l->ci == NULL || !Me || !Me->IsSynced()) return; - for (unsigned i = l->ci->log_settings.size(); i > 0; --i) + for (unsigned i = l->ci->log_settings->size(); i > 0; --i) { - LogSetting &log = l->ci->log_settings[i - 1]; + const LogSetting *log = l->ci->log_settings->at(i - 1); - if (log.service_name == l->c->name) + if (log->service_name == l->c->name) { - Anope::string buffer = l->u->nick + " used " + log.command_name + " " + l->buf.str(); + Anope::string buffer = l->u->nick + " used " + log->command_name + " " + l->buf.str(); - if (log.method.equals_ci("MESSAGE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL) - ircdproto->SendPrivmsg(l->ci->bi, log.extra + l->ci->c->name, "%s", buffer.c_str()); - else if (log.method.equals_ci("NOTICE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL) - ircdproto->SendNotice(l->ci->bi, log.extra + l->ci->c->name, "%s", buffer.c_str()); - else if (log.method.equals_ci("MEMO") && memoserv && l->ci->WhoSends() != NULL) + if (log->method.equals_ci("MESSAGE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL) + ircdproto->SendPrivmsg(l->ci->bi, log->extra + l->ci->c->name, "%s", buffer.c_str()); + else if (log->method.equals_ci("NOTICE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL) + ircdproto->SendNotice(l->ci->bi, log->extra + l->ci->c->name, "%s", buffer.c_str()); + else if (log->method.equals_ci("MEMO") && memoserv && l->ci->WhoSends() != NULL) memoserv->Send(l->ci->WhoSends()->nick, l->ci->name, buffer, true); } } diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp index c9d7c112a..425a54a01 100644 --- a/modules/commands/cs_mode.cpp +++ b/modules/commands/cs_mode.cpp @@ -151,7 +151,7 @@ class CommandCSMode : public Command } else if (subcommand.equals_ci("LIST")) { - const std::multimap &mlocks = ci->GetMLock(); + const ChannelInfo::ModeList &mlocks = ci->GetMLock(); if (mlocks.empty()) { source.Reply(_("Channel %s has no mode locks."), ci->name.c_str()); @@ -161,18 +161,18 @@ class CommandCSMode : public Command ListFormatter list; list.addColumn("Mode").addColumn("Param").addColumn("Creator").addColumn("Created"); - for (std::multimap::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it) + for (ChannelInfo::ModeList::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it) { - const ModeLock &ml = it->second; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name); + const ModeLock *ml = it->second; + ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm) continue; ListFormatter::ListEntry entry; - entry["Mode"] = Anope::printf("%c%c", ml.set ? '+' : '-', cm->ModeChar); - entry["Param"] = ml.param; - entry["Creator"] = ml.setter; - entry["Created"] = do_strftime(ml.created, source.u->Account(), false); + entry["Mode"] = Anope::printf("%c%c", ml->set ? '+' : '-', cm->ModeChar); + entry["Param"] = ml->param; + entry["Creator"] = ml->setter; + entry["Created"] = do_strftime(ml->created, source.u->Account(), false); list.addEntry(entry); } diff --git a/modules/commands/cs_modes.cpp b/modules/commands/cs_modes.cpp index a460c6c87..37d710505 100644 --- a/modules/commands/cs_modes.cpp +++ b/modules/commands/cs_modes.cpp @@ -20,19 +20,31 @@ class CommandModeBase : public Command User *u = source.u; User *u2 = finduser(nick); Channel *c = findchan(chan); - ChannelInfo *ci = c ? c->ci : NULL; - - bool is_same = u == u2; - - AccessGroup u_access = ci ? ci->AccessFor(u) : AccessGroup(), u2_access = ci && u2 ? ci->AccessFor(u2) : AccessGroup(); if (!c) + { source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); - else if (!ci) - source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); - else if (!u2) + return; + + } + + if (!u2) + { source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); - else if (is_same ? !ci->AccessFor(u).HasPriv(levelself) : !ci->AccessFor(u).HasPriv(level)) + return; + } + + ChannelInfo *ci = c->ci; + if (!ci) + { + source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str()); + return; + } + + bool is_same = u == u2; + AccessGroup u_access = ci->AccessFor(u), u2_access = ci->AccessFor(u2); + + if (is_same ? !ci->AccessFor(u).HasPriv(levelself) : !ci->AccessFor(u).HasPriv(level)) source.Reply(ACCESS_DENIED); else if (!set && !is_same && ci->HasFlag(CI_PEACE) && u2_access >= u_access) source.Reply(ACCESS_DENIED); diff --git a/modules/commands/cs_register.cpp b/modules/commands/cs_register.cpp index 570fd8125..fd62ff754 100644 --- a/modules/commands/cs_register.cpp +++ b/modules/commands/cs_register.cpp @@ -46,7 +46,7 @@ class CommandCSRegister : public Command else if (c && !c->HasUserStatus(u, CMODE_OP)) source.Reply(_("You must be a channel operator to register the channel.")); else if (Config->CSMaxReg && u->Account()->channelcount >= Config->CSMaxReg && !u->HasPriv("chanserv/no-register-limit")) - source.Reply(u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : _(CHAN_REACHED_CHANNEL_LIMIT), Config->CSMaxReg); + source.Reply(u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, Config->CSMaxReg); else { ci = new ChannelInfo(chan); @@ -54,11 +54,12 @@ class CommandCSRegister : public Command if (!chdesc.empty()) ci->desc = chdesc; - ci->mode_locks = def_mode_locks; - for (ChannelInfo::ModeList::iterator it = ci->mode_locks.begin(), it_end = ci->mode_locks.end(); it != it_end; ++it) + for (ChannelInfo::ModeList::iterator it = def_mode_locks.begin(), it_end = def_mode_locks.end(); it != it_end; ++it) { - it->second.setter = u->nick; - it->second.ci = ci; + ModeLock *ml = new ModeLock(*it->second); + ml->setter = u->nick; + ml->ci = ci; + ci->mode_locks->insert(std::make_pair(it->first, ml)); } if (c && !c->topic.empty()) diff --git a/modules/commands/cs_saset.cpp b/modules/commands/cs_saset.cpp index c564a9c90..c2e7b13d5 100644 --- a/modules/commands/cs_saset.cpp +++ b/modules/commands/cs_saset.cpp @@ -37,10 +37,10 @@ class CommandCSSASet : public Command " \n" "Available options:")); Anope::string this_name = source.command; - for (BotInfo::command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it) + for (BotInfo::command_map::const_iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it) { const Anope::string &c_name = it->first; - CommandInfo &info = it->second; + const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { service_reference command("Command", info.name); diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index 0143f50d6..3f7b276f7 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -37,14 +37,14 @@ struct SeenInfo : Serializable { } - Anope::string serialize_name() const anope_override + const Anope::string serialize_name() const anope_override { return "SeenInfo"; } - serialized_data serialize() anope_override + Serialize::Data serialize() const anope_override { - serialized_data data; + Serialize::Data data; data["nick"] << nick; data["vhost"] << vhost; @@ -57,9 +57,13 @@ struct SeenInfo : Serializable return data; } - static void unserialize(serialized_data &data) + static Serializable* unserialize(Serializable *obj, Serialize::Data &data) { - SeenInfo *s = new SeenInfo(); + SeenInfo *s; + if (obj) + s = debug_cast(obj); + else + s = new SeenInfo(); data["nick"] >> s->nick; data["vhost"] >> s->vhost; @@ -71,7 +75,9 @@ struct SeenInfo : Serializable data["message"] >> s->message; data["last"] >> s->last; - database[s->nick] = s; + if (!s) + database[s->nick] = s; + return s; } }; @@ -89,7 +95,7 @@ static SeenInfo *FindInfo(const Anope::string &nick) static bool ShouldHide(const Anope::string &channel, User *u) { Channel *targetchan = findchan(channel); - ChannelInfo *targetchan_ci = targetchan ? targetchan->ci : cs_findchan(channel); + const ChannelInfo *targetchan_ci = targetchan ? *targetchan->ci : cs_findchan(channel); if (targetchan && targetchan->HasMode(CMODE_SECRET)) return true; @@ -303,7 +309,7 @@ class DataBasePurger : public CallBack if ((Anope::CurTime - cur->second->last) > purgetime) { Log(LOG_DEBUG) << cur->first << " was last seen " << do_strftime(cur->second->last) << ", purging entry"; - delete cur->second; + cur->second->destroy(); database.erase(cur); } } diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index ac91d213f..0d23b5550 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -37,10 +37,10 @@ class CommandCSSet : public Command " \n" "Available options:")); Anope::string this_name = source.command; - for (BotInfo::command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it) + for (BotInfo::command_map::const_iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it) { const Anope::string &c_name = it->first; - CommandInfo &info = it->second; + const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { service_reference command("Command", info.name); diff --git a/modules/commands/cs_set_founder.cpp b/modules/commands/cs_set_founder.cpp index 0d375f760..5f2990196 100644 --- a/modules/commands/cs_set_founder.cpp +++ b/modules/commands/cs_set_founder.cpp @@ -22,7 +22,7 @@ class CommandCSSetFounder : public Command this->SetSyntax(_("\037channel\037 \037nick\037")); } - void Execute(CommandSource &source, const std::vector ¶ms)anope_override + void Execute(CommandSource &source, const std::vector ¶ms) anope_override { User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); @@ -44,8 +44,7 @@ class CommandCSSetFounder : public Command return; } - NickAlias *na = findnick(params[1]); - + const NickAlias *na = findnick(params[1]); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, params[1].c_str()); diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 75794697d..ab40f9fdc 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -12,9 +12,9 @@ #include "module.h" -struct CSMiscData : Anope::string, ExtensibleItem, Serializable +struct CSMiscData : ExtensibleItem, Serializable { - ChannelInfo *ci; + serialize_obj ci; Anope::string name; Anope::string data; @@ -22,14 +22,14 @@ struct CSMiscData : Anope::string, ExtensibleItem, Serializable { } - Anope::string serialize_name() const anope_override + const Anope::string serialize_name() const anope_override { return "CSMiscData"; } - serialized_data serialize() anope_override + Serialize::Data serialize() const anope_override { - serialized_data sdata; + Serialize::Data sdata; sdata["ci"] << this->ci->name; sdata["name"] << this->name; @@ -38,13 +38,27 @@ struct CSMiscData : Anope::string, ExtensibleItem, Serializable return sdata; } - static void unserialize(serialized_data &data) + static Serializable* unserialize(Serializable *obj, Serialize::Data &data) { ChannelInfo *ci = cs_findchan(data["ci"].astr()); if (ci == NULL) - return; + return NULL; + + CSMiscData *d; + if (obj) + { + d = debug_cast(obj); + d->ci = ci; + data["name"] >> d->name; + data["data"] >> d->data; + } + else + { + d = new CSMiscData(ci, data["name"].astr(), data["data"].astr()); + ci->Extend(data["name"].astr(), d); + } - ci->Extend(data["name"].astr(), new CSMiscData(ci, data["name"].astr(), data["data"].astr())); + return d; } }; diff --git a/modules/commands/cs_set_successor.cpp b/modules/commands/cs_set_successor.cpp index fe2860920..e0f05e67b 100644 --- a/modules/commands/cs_set_successor.cpp +++ b/modules/commands/cs_set_successor.cpp @@ -48,7 +48,7 @@ class CommandCSSetSuccessor : public Command if (params.size() > 1) { - NickAlias *na = findnick(params[1]); + const NickAlias *na = findnick(params[1]); if (!na) { diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index 676ffebfa..d5898083e 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -13,6 +13,11 @@ #include "module.h" +struct ExtensibleString : Anope::string, ExtensibleItem +{ + ExtensibleString(const Anope::string &s) : Anope::string(s) { } +}; + struct ChanSuspend : ExtensibleItem, Serializable { Anope::string chan; @@ -22,14 +27,14 @@ struct ChanSuspend : ExtensibleItem, Serializable { } - Anope::string serialize_name() const + const Anope::string serialize_name() const { return "ChanSuspend"; } - serialized_data serialize() anope_override + Serialize::Data serialize() const anope_override { - serialized_data sd; + Serialize::Data sd; sd["chan"] << this->chan; sd["when"] << this->when; @@ -37,18 +42,24 @@ struct ChanSuspend : ExtensibleItem, Serializable return sd; } - static void unserialize(serialized_data &sd) + static Serializable* unserialize(Serializable *obj, Serialize::Data &sd) { ChannelInfo *ci = cs_findchan(sd["chan"].astr()); if (ci == NULL) - return; + return NULL; - ChanSuspend *cs = new ChanSuspend(); + ChanSuspend *cs; + if (obj) + cs = debug_cast(obj); + else + cs = new ChanSuspend(); sd["chan"] >> cs->chan; sd["when"] >> cs->when; - ci->Extend("ci_suspend_expire", cs); + if (!obj) + ci->Extend("ci_suspend_expire", cs); + return cs; } }; @@ -220,11 +231,12 @@ class CSSuspend : public Module ~CSSuspend() { - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) + for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) { - it->second->Shrink("cs_suspend_expire"); - it->second->Shrink("suspend_by"); - it->second->Shrink("suspend_reason"); + ChannelInfo *ci = it->second; + ci->Shrink("cs_suspend_expire"); + ci->Shrink("suspend_by"); + ci->Shrink("suspend_reason"); } } diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index da272835f..11b2f4749 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -39,7 +39,7 @@ class CommandCSUp : public Command if (c == NULL) source.Reply(CHAN_X_NOT_IN_USE, channel.c_str()); - else if (c->ci == NULL) + else if (!c->ci) source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str()); else chan_set_correct_modes(u, c, 1); @@ -94,7 +94,7 @@ class CommandCSDown : public Command if (c == NULL) source.Reply(CHAN_X_NOT_IN_USE, channel.c_str()); - else if (c->ci == NULL) + else if (!c->ci) source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str()); else RemoveAll(u, c); diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 7935467c2..807cbe1f6 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -116,7 +116,7 @@ class XOPChanAccess : public ChanAccess return false; } - Anope::string Serialize() + Anope::string Serialize() const { for (int i = 0; xopAccess[i].type != XOP_UNKNOWN; ++i) { @@ -145,11 +145,11 @@ class XOPChanAccess : public ChanAccess this->type = XOP_UNKNOWN; } - static XOPType DetermineLevel(ChanAccess *access) + static XOPType DetermineLevel(const ChanAccess *access) { if (access->provider->name == "access/xop") { - XOPChanAccess *xaccess = debug_cast(access); + const XOPChanAccess *xaccess = debug_cast(access); return xaccess->type; } else @@ -216,7 +216,7 @@ class XOPBase : public Command } AccessGroup access = ci->AccessFor(u); - ChanAccess *highest = access.Highest(); + const ChanAccess *highest = access.Highest(); int u_level = (highest ? XOPChanAccess::DetermineLevel(highest) : 0); if ((!access.Founder && !access.HasPriv("ACCESS_CHANGE") && !u->HasPriv("chanserv/access/modify")) || (level <= u_level && !access.Founder)) @@ -225,7 +225,7 @@ class XOPBase : public Command return; } - if (mask.find_first_of("!*@") == Anope::string::npos && findnick(mask) == NULL) + if (mask.find_first_of("!*@") == Anope::string::npos && !findnick(mask)) { User *targ = finduser(mask); if (targ != NULL) @@ -239,7 +239,7 @@ class XOPBase : public Command for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { - ChanAccess *a = ci->GetAccess(i); + const ChanAccess *a = ci->GetAccess(i); if (a->mask.equals_ci(mask)) { @@ -304,7 +304,7 @@ class XOPBase : public Command } AccessGroup access = ci->AccessFor(u); - ChanAccess *highest = access.Highest(); + const ChanAccess *highest = access.Highest(); bool override = false; if ((!mask.equals_ci(u->Account()->display) && !access.HasPriv("ACCESS_CHANGE") && !access.Founder) || ((!highest || level <= XOPChanAccess::DetermineLevel(highest)) && !access.Founder)) { @@ -436,7 +436,7 @@ class XOPBase : public Command if (!Number || Number > ci->GetAccessCount()) return; - ChanAccess *a = ci->GetAccess(Number - 1); + const ChanAccess *a = ci->GetAccess(Number - 1); if (this->type != XOPChanAccess::DetermineLevel(a)) return; @@ -453,7 +453,7 @@ class XOPBase : public Command { for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - ChanAccess *a = ci->GetAccess(i); + const ChanAccess *a = ci->GetAccess(i); if (XOPChanAccess::DetermineLevel(a) != level) continue; @@ -507,7 +507,7 @@ class XOPBase : public Command for (unsigned i = ci->GetAccessCount(); i > 0; --i) { - ChanAccess *access = ci->GetAccess(i - 1); + const ChanAccess *access = ci->GetAccess(i - 1); if (XOPChanAccess::DetermineLevel(access) == level) ci->EraseAccess(i - 1); } diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index a329eb63c..7b7c52110 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -31,14 +31,14 @@ class CommandHelp : public Command return; User *u = source.u; - BotInfo *bi = source.owner; + const BotInfo *bi = source.owner; if (params.empty()) { - for (BotInfo::command_map::iterator it = bi->commands.begin(), it_end = bi->commands.end(); it != it_end; ++it) + for (BotInfo::command_map::const_iterator it = bi->commands.begin(), it_end = bi->commands.end(); it != it_end; ++it) { const Anope::string &c_name = it->first; - CommandInfo &info = it->second; + const CommandInfo &info = it->second; // Smaller command exists Anope::string cmd = myStrGetToken(c_name, ' ', 0); @@ -65,11 +65,11 @@ class CommandHelp : public Command full_command += " " + params[i]; full_command.erase(full_command.begin()); - BotInfo::command_map::iterator it = bi->commands.find(full_command); + BotInfo::command_map::const_iterator it = bi->commands.find(full_command); if (it == bi->commands.end()) continue; - CommandInfo &info = it->second; + const CommandInfo &info = it->second; service_reference c("Command", info.name); if (!c) diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp index 80b8333d9..48e11c08c 100644 --- a/modules/commands/hs_del.cpp +++ b/modules/commands/hs_del.cpp @@ -65,8 +65,8 @@ class CommandHSDelAll : public Command if (na) { FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); - NickCore *nc = na->nc; - for (std::list::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) + const NickCore *nc = na->nc; + for (std::list >::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) { na = *it; na->RemoveVhost(); diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp index 79db12536..a9c3dc232 100644 --- a/modules/commands/hs_group.cpp +++ b/modules/commands/hs_group.cpp @@ -15,15 +15,16 @@ class CommandHSGroup : public Command { - void Sync(NickAlias *na) + void Sync(const NickAlias *na) { if (!na || !na->HasVhost()) return; - for (std::list::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it) + for (std::list >::const_iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end;) { - NickAlias *nick = *it; - nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); + NickAlias *nick = *it++; + if (nick) + nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); } } diff --git a/modules/commands/hs_list.cpp b/modules/commands/hs_list.cpp index 3bc8be862..9e708f0b4 100644 --- a/modules/commands/hs_list.cpp +++ b/modules/commands/hs_list.cpp @@ -59,9 +59,9 @@ class CommandHSList : public Command ListFormatter list; list.addColumn("Number").addColumn("Nick").addColumn("Vhost").addColumn("Creator").addColumn("Created"); - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) + for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) { - NickAlias *na = it->second; + const NickAlias *na = it->second; if (!na->HasVhost()) continue; diff --git a/modules/commands/hs_off.cpp b/modules/commands/hs_off.cpp index c9c2fecd1..bf7d92dba 100644 --- a/modules/commands/hs_off.cpp +++ b/modules/commands/hs_off.cpp @@ -25,7 +25,7 @@ class CommandHSOff : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { User *u = source.u; - NickAlias *na = findnick(u->nick); + const NickAlias *na = findnick(u->nick); if (!na || !na->HasVhost()) source.Reply(HOST_NOT_ASSIGNED); diff --git a/modules/commands/hs_on.cpp b/modules/commands/hs_on.cpp index 2dfa18c12..223f169fc 100644 --- a/modules/commands/hs_on.cpp +++ b/modules/commands/hs_on.cpp @@ -25,7 +25,7 @@ class CommandHSOn : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { User *u = source.u; - NickAlias *na = findnick(u->nick); + const NickAlias *na = findnick(u->nick); if (na && u->Account() == na->nc && na->HasVhost()) { if (!na->GetVhostIdent().empty()) diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index 06308c8cb..e44fa06e2 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -30,14 +30,14 @@ struct HostRequest : ExtensibleItem, Serializable Anope::string host; time_t time; - Anope::string serialize_name() const anope_override + const Anope::string serialize_name() const anope_override { return "HostRequest"; } - serialized_data serialize() anope_override + Serialize::Data serialize() const anope_override { - serialized_data data; + Serialize::Data data; data["nick"] << this->nick; data["ident"] << this->ident; @@ -47,19 +47,25 @@ struct HostRequest : ExtensibleItem, Serializable return data; } - static void unserialize(serialized_data &data) + static Serializable* unserialize(Serializable *obj, Serialize::Data &data) { NickAlias *na = findnick(data["nick"].astr()); if (na == NULL) - return; + return NULL; - HostRequest *req = new HostRequest; + HostRequest *req; + if (obj) + req = debug_cast(obj); + else + req = new HostRequest; req->nick = na->nick; data["ident"] >> req->ident; data["host"] >> req->host; data["time"] >> req->time; - na->Extend("hs_request", req); + if (!obj) + na->Extend("hs_request", req); + return req; } }; @@ -282,9 +288,9 @@ class CommandHSWaiting : public Command list.addColumn("Number").addColumn("Nick").addColumn("Vhost").addColumn("Created"); - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) + for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) { - NickAlias *na = it->second; + const NickAlias *na = it->second; HostRequest *hr = na->GetExt("hs_request"); if (!hr) continue; @@ -358,8 +364,11 @@ class HSRequest : public Module ~HSRequest() { - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) - it->second->Shrink("hs_request"); + for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + { + NickAlias *na = it->second; + na->Shrink("hs_request"); + } } void OnReload() anope_override @@ -387,7 +396,7 @@ void req_send_memos(CommandSource &source, const Anope::string &vIdent, const An { Oper *o = Config->Opers[i]; - NickAlias *na = findnick(o->name); + const NickAlias *na = findnick(o->name); if (!na) continue; diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp index 5e73fd800..d4fbe9d5c 100644 --- a/modules/commands/hs_set.cpp +++ b/modules/commands/hs_set.cpp @@ -104,15 +104,16 @@ class CommandHSSet : public Command class CommandHSSetAll : public Command { - void Sync(NickAlias *na) + void Sync(const NickAlias *na) { if (!na || !na->HasVhost()) return; - for (std::list::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it) + for (std::list >::const_iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end;) { - NickAlias *nick = *it; - nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); + NickAlias *nick = *it++; + if (nick) + nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); } } diff --git a/modules/commands/ms_cancel.cpp b/modules/commands/ms_cancel.cpp index 46f410aec..059ca2f06 100644 --- a/modules/commands/ms_cancel.cpp +++ b/modules/commands/ms_cancel.cpp @@ -39,11 +39,20 @@ class CommandMSCancel : public Command source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), nname.c_str()); else { - for (int i = mi->memos.size() - 1; i >= 0; --i) - if (mi->memos[i]->HasFlag(MF_UNREAD) && u->Account()->display.equals_ci(mi->memos[i]->sender)) + ChannelInfo *ci; + NickAlias *na; + if (ischan) + ci = cs_findchan(nname); + else + na = findnick(nname); + for (int i = mi->memos->size() - 1; i >= 0; --i) + if (mi->GetMemo(i)->HasFlag(MF_UNREAD) && u->Account()->display.equals_ci(mi->GetMemo(i)->sender)) { - FOREACH_MOD(I_OnMemoDel, OnMemoDel(findnick(nname)->nc, mi, mi->memos[i])); - mi->Del(mi->memos[i]); + if (ischan) + FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(i))); + else + FOREACH_MOD(I_OnMemoDel, OnMemoDel(na->nc, mi, mi->GetMemo(i))); + mi->Del(i); source.Reply(_("Last memo to \002%s\002 has been cancelled."), nname.c_str()); return; } diff --git a/modules/commands/ms_check.cpp b/modules/commands/ms_check.cpp index a77b7192f..5b031e8ec 100644 --- a/modules/commands/ms_check.cpp +++ b/modules/commands/ms_check.cpp @@ -30,28 +30,28 @@ class CommandMSCheck : public Command bool found = false; - NickAlias *na = findnick(recipient); + const NickAlias *na = findnick(recipient); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, recipient.c_str()); return; } - MemoInfo *mi = &na->nc->memos; + MemoInfo *mi = const_cast(&na->nc->memos); /* Okay, I know this looks strange but we wanna get the LAST memo, so we have to loop backwards */ - for (int i = mi->memos.size() - 1; i >= 0; --i) + for (int i = mi->memos->size() - 1; i >= 0; --i) { - if (u->Account()->display.equals_ci(mi->memos[i]->sender)) + if (u->Account()->display.equals_ci(mi->GetMemo(i)->sender)) { found = true; /* Yes, we've found the memo */ - if (mi->memos[i]->HasFlag(MF_UNREAD)) - source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str()); + if (mi->GetMemo(i)->HasFlag(MF_UNREAD)) + source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), do_strftime(mi->GetMemo(i)->time).c_str()); else - source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str()); + source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), do_strftime(mi->GetMemo(i)->time).c_str()); break; } } diff --git a/modules/commands/ms_del.cpp b/modules/commands/ms_del.cpp index 65969b025..0ad906c49 100644 --- a/modules/commands/ms_del.cpp +++ b/modules/commands/ms_del.cpp @@ -25,13 +25,13 @@ class MemoDelCallback : public NumberList void HandleNumber(unsigned Number) anope_override { - if (!Number || Number > mi->memos.size()) + if (!Number || Number > mi->memos->size()) return; if (ci) - FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[Number - 1])); + FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(Number - 1))); else - FOREACH_MOD(I_OnMemoDel, OnMemoDel(source.u->Account(), mi, mi->memos[Number - 1])); + FOREACH_MOD(I_OnMemoDel, OnMemoDel(source.u->Account(), mi, mi->GetMemo(Number - 1))); mi->Del(Number - 1); source.Reply(_("Memo %d has been deleted."), Number); @@ -52,7 +52,7 @@ class CommandMSDel : public Command User *u = source.u; MemoInfo *mi; - ChannelInfo *ci = NULL; + ChannelInfo *ci; Anope::string numstr = !params.empty() ? params[0] : "", chan; if (!numstr.empty() && numstr[0] == '#') @@ -60,7 +60,8 @@ class CommandMSDel : public Command chan = numstr; numstr = params.size() > 1 ? params[1] : ""; - if (!(ci = cs_findchan(chan))) + ci = cs_findchan(chan); + if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return; @@ -78,10 +79,10 @@ class CommandMSDel : public Command mi = &ci->memos; } else - mi = &u->Account()->memos; + mi = const_cast(&u->Account()->memos); if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST"))) this->OnSyntaxError(source, numstr); - else if (mi->memos.empty()) + else if (mi->memos->empty()) { if (!chan.empty()) source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str()); @@ -99,24 +100,24 @@ class CommandMSDel : public Command { /* Delete last memo. */ if (ci) - FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[mi->memos.size() - 1])); + FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(mi->memos->size() - 1))); else - FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[mi->memos.size() - 1])); - mi->Del(mi->memos[mi->memos.size() - 1]); - source.Reply(_("Memo %d has been deleted."), mi->memos.size() + 1); + FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->GetMemo(mi->memos->size() - 1))); + mi->Del(mi->memos->size() - 1); + source.Reply(_("Memo %d has been deleted."), mi->memos->size() + 1); } else { /* Delete all memos. */ - for (unsigned i = 0, end = mi->memos.size(); i < end; ++i) + for (unsigned i = 0, end = mi->memos->size(); i < end; ++i) { if (ci) - FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[i])); + FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(i))); else - FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[i])); - delete mi->memos[i]; + FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->GetMemo(i))); + mi->GetMemo(i)->destroy(); } - mi->memos.clear(); + mi->memos->clear(); if (!chan.empty()) source.Reply(_("All memos for channel %s have been deleted."), chan.c_str()); else diff --git a/modules/commands/ms_info.cpp b/modules/commands/ms_info.cpp index 1cb6199a8..3f132f1d2 100644 --- a/modules/commands/ms_info.cpp +++ b/modules/commands/ms_info.cpp @@ -27,8 +27,8 @@ class CommandMSInfo : public Command User *u = source.u; const MemoInfo *mi; - NickAlias *na = NULL; - ChannelInfo *ci = NULL; + const NickAlias *na = NULL; + ChannelInfo *ci; const Anope::string &nname = !params.empty() ? params[0] : ""; int hardmax = 0; @@ -45,7 +45,8 @@ class CommandMSInfo : public Command } else if (!nname.empty() && nname[0] == '#') { - if (!(ci = cs_findchan(nname))) + ci = cs_findchan(nname); + if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, nname.c_str()); return; @@ -71,11 +72,11 @@ class CommandMSInfo : public Command if (!nname.empty() && (ci || na->nc != u->Account())) { - if (mi->memos.empty()) + if (mi->memos->empty()) source.Reply(_("%s currently has no memos."), nname.c_str()); - else if (mi->memos.size() == 1) + else if (mi->memos->size() == 1) { - if (mi->memos[0]->HasFlag(MF_UNREAD)) + if (mi->GetMemo(0)->HasFlag(MF_UNREAD)) source.Reply(_("%s currently has \0021\002 memo, and it has not yet been read."), nname.c_str()); else source.Reply(_("%s currently has \0021\002 memo."), nname.c_str()); @@ -83,17 +84,17 @@ class CommandMSInfo : public Command else { unsigned count = 0, i, end; - for (i = 0, end = mi->memos.size(); i < end; ++i) - if (mi->memos[i]->HasFlag(MF_UNREAD)) + for (i = 0, end = mi->memos->size(); i < end; ++i) + if (mi->GetMemo(i)->HasFlag(MF_UNREAD)) ++count; - if (count == mi->memos.size()) + if (count == mi->memos->size()) source.Reply(_("%s currently has \002%d\002 memos; all of them are unread."), nname.c_str(), count)