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 --- src/access.cpp | 35 ++-- src/actions.cpp | 2 +- src/bots.cpp | 55 +++--- src/botserv.cpp | 16 +- src/channels.cpp | 76 ++++---- src/chanserv.cpp | 19 +- src/config.cpp | 31 ++-- src/init.cpp | 2 +- src/language.cpp | 2 +- src/logger.cpp | 39 +++-- src/mail.cpp | 2 +- src/main.cpp | 4 +- src/memoserv.cpp | 53 ++++-- src/messages.cpp | 2 +- src/misc.cpp | 6 +- src/modes.cpp | 21 ++- src/nickalias.cpp | 43 +++-- src/nickcore.cpp | 36 ++-- src/nickserv.cpp | 31 ++-- src/operserv.cpp | 108 +++++++----- src/protocol.cpp | 6 +- src/regchannel.cpp | 495 ++++++++++++++++++++++++++++++++--------------------- src/serialize.cpp | 95 +++++++--- src/servers.cpp | 6 +- src/users.cpp | 37 ++-- 25 files changed, 726 insertions(+), 496 deletions(-) (limited to 'src') diff --git a/src/access.cpp b/src/access.cpp index 4ed19c7fe..1100d8e7c 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -46,8 +46,11 @@ void PrivilegeManager::RemovePrivilege(Privilege &p) if (it != privs.end()) privs.erase(it); - for (registered_channel_map::const_iterator cit = RegisteredChannelList.begin(), cit_end = RegisteredChannelList.end(); cit != cit_end; ++cit) + for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) + { + cit->second->QueueUpdate(); cit->second->RemoveLevel(p.name); + } } Privilege *PrivilegeManager::FindPrivilege(const Anope::string &name) @@ -84,14 +87,14 @@ ChanAccess::~ChanAccess() { } -Anope::string ChanAccess::serialize_name() const +const Anope::string ChanAccess::serialize_name() const { return "ChanAccess"; } -Serializable::serialized_data ChanAccess::serialize() +Serialize::Data ChanAccess::serialize() const { - serialized_data data; + Serialize::Data data; data["provider"] << this->provider->name; data["ci"] << this->ci->name; @@ -104,14 +107,18 @@ Serializable::serialized_data ChanAccess::serialize() return data; } -void ChanAccess::unserialize(serialized_data &data) +Serializable* ChanAccess::unserialize(Serializable *obj, Serialize::Data &data) { service_reference aprovider("AccessProvider", data["provider"].astr()); ChannelInfo *ci = cs_findchan(data["ci"].astr()); if (!aprovider || !ci) - return; + return NULL; - ChanAccess *access = aprovider->Create(); + ChanAccess *access; + if (obj) + access = debug_cast(obj); + else + access = const_cast(aprovider->Create()); access->provider = aprovider; access->ci = ci; data["mask"] >> access->mask; @@ -120,10 +127,12 @@ void ChanAccess::unserialize(serialized_data &data) data["created"] >> access->created; access->Unserialize(data["data"].astr()); - ci->AddAccess(access); + if (!obj) + ci->AddAccess(access); + return access; } -bool ChanAccess::Matches(User *u, NickCore *nc) +bool ChanAccess::Matches(const User *u, const NickCore *nc) const { bool is_mask = this->mask.find_first_of("!@?*") != Anope::string::npos; if (u && is_mask && Anope::Match(u->nick, this->mask)) @@ -131,10 +140,10 @@ bool ChanAccess::Matches(User *u, NickCore *nc) else if (u && Anope::Match(u->GetDisplayedMask(), this->mask)) return true; else if (nc) - for (std::list::iterator it = nc->aliases.begin(); it != nc->aliases.end(); ++it) + for (std::list >::const_iterator it = nc->aliases.begin(); it != nc->aliases.end();) { - NickAlias *na = *it; - if (Anope::Match(na->nick, this->mask)) + const NickAlias *na = *it++; + if (na && Anope::Match(na->nick, this->mask)) return true; } return false; @@ -245,7 +254,7 @@ bool AccessGroup::HasPriv(const Anope::string &name) const return false; } -ChanAccess *AccessGroup::Highest() const +const ChanAccess *AccessGroup::Highest() const { const std::vector &privs = PrivilegeManager::GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) diff --git a/src/actions.cpp b/src/actions.cpp index 5536596e6..657973e3c 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -51,7 +51,7 @@ bool bad_password(User *u) * @param full True to match against the users real host and IP * @return void */ -void common_unban(ChannelInfo *ci, User *u, bool full) +void common_unban(const ChannelInfo *ci, User *u, bool full) { if (!u || !ci || !ci->c || !ci->c->HasMode(CMODE_BAN)) return; diff --git a/src/bots.cpp b/src/bots.cpp index 242b7d4f2..e9d279c3e 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -16,9 +16,10 @@ #include "config.h" #include "language.h" #include "extern.h" +#include "serialize.h" -Anope::insensitive_map BotListByNick; -Anope::map BotListByUID; +serialize_checker BotListByNick("BotInfo"); +serialize_checker BotListByUID("BotInfo"); BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, ts6_uid_retrieve()), Flags(BotFlagString), botmodes(bmodes) { @@ -28,9 +29,9 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A this->lastmsg = this->created = Anope::CurTime; this->introduced = false; - BotListByNick[this->nick] = this; + (*BotListByNick)[this->nick] = this; if (!this->uid.empty()) - BotListByUID[this->uid] = this; + (*BotListByUID)[this->uid] = this; // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -57,29 +58,32 @@ BotInfo::~BotInfo() ircdproto->SendSQLineDel(&x); } - 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; if (ci->bi == this) + { + ci->QueueUpdate(); ci->bi = NULL; + } } - BotListByNick.erase(this->nick); + BotListByNick->erase(this->nick); if (!this->uid.empty()) - BotListByUID.erase(this->uid); + BotListByUID->erase(this->uid); } -Anope::string BotInfo::serialize_name() const +const Anope::string BotInfo::serialize_name() const { return "BotInfo"; } -Serializable::serialized_data BotInfo::serialize() +Serialize::Data BotInfo::serialize() const { - serialized_data data; + Serialize::Data data; - data["nick"] << this->nick; + data["nick"].setMax(64) << this->nick; data["user"] << this->ident; data["host"] << this->host; data["realname"] << this->realname; @@ -89,13 +93,16 @@ Serializable::serialized_data BotInfo::serialize() return data; } -void BotInfo::unserialize(serialized_data &data) +Serializable* BotInfo::unserialize(Serializable *obj, Serialize::Data &data) { - BotInfo *bi = findbot(data["nick"].astr()); - if (bi == NULL) + BotInfo *bi; + if (obj) + bi = debug_cast(obj); + else if (!(bi = findbot(data["nick"].astr()))) bi = new BotInfo(data["nick"].astr(), data["user"].astr(), data["host"].astr(), data["realname"].astr()); data["created"] >> bi->created; bi->FromString(data["flags"].astr()); + return bi; } void BotInfo::GenerateUID() @@ -103,26 +110,26 @@ void BotInfo::GenerateUID() if (!this->uid.empty()) throw CoreException("Bot already has a uid?"); this->uid = ts6_uid_retrieve(); - BotListByUID[this->uid] = this; + (*BotListByUID)[this->uid] = this; UserListByUID[this->uid] = this; } void BotInfo::SetNewNick(const Anope::string &newnick) { UserListByNick.erase(this->nick); - BotListByNick.erase(this->nick); + BotListByNick->erase(this->nick); this->nick = newnick; UserListByNick[this->nick] = this; - BotListByNick[this->nick] = this; + (*BotListByNick)[this->nick] = this; } void BotInfo::RejoinAll() { - 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 == this && ci->c && ci->c->users.size() >= Config->BSMinUsers) this->Join(ci->c); @@ -162,12 +169,12 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci) ci->bi = NULL; } -unsigned BotInfo::GetChannelCount() +unsigned BotInfo::GetChannelCount() const { unsigned count = 0; - 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 == this) ++count; @@ -234,7 +241,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message) std::vector params = BuildStringVector(message); bool has_help = this->commands.find("HELP") != this->commands.end(); - BotInfo::command_map::iterator it = this->commands.end(); + BotInfo::command_map::const_iterator it = this->commands.end(); unsigned count = 0; for (unsigned max = params.size(); it == this->commands.end() && max > 0; --max) { @@ -256,7 +263,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message) return; } - CommandInfo &info = it->second; + const CommandInfo &info = it->second; service_reference c("Command", info.name); if (!c) { diff --git a/src/botserv.cpp b/src/botserv.cpp index 962f2b80e..4ec6465a1 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -21,24 +21,24 @@ #include "access.h" #include "channels.h" -BotInfo *findbot(const Anope::string &nick) +BotInfo* findbot(const Anope::string &nick) { BotInfo *bi = NULL; if (isdigit(nick[0]) && ircd->ts6) { - Anope::map::iterator it = BotListByUID.find(nick); - if (it != BotListByUID.end()) + botinfouid_map::iterator it = BotListByUID->find(nick); + if (it != BotListByUID->end()) bi = it->second; } else { - Anope::insensitive_map::iterator it = BotListByNick.find(nick); - if (it != BotListByNick.end()) + botinfo_map::iterator it = BotListByNick->find(nick); + if (it != BotListByNick->end()) bi = it->second; } - - FOREACH_MOD(I_OnFindBot, OnFindBot(nick)); - + + if (bi) + bi->QueueUpdate(); return bi; } diff --git a/src/channels.cpp b/src/channels.cpp index 6035d1657..283da3440 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -102,7 +102,7 @@ void Channel::Reset() void Channel::Sync() { - if (!this->HasMode(CMODE_PERM) && (this->users.empty() || (this->users.size() == 1 && this->ci && this->ci->bi == this->users.front()->user))) + if (!this->HasMode(CMODE_PERM) && (this->users.empty() || (this->users.size() == 1 && this->ci && this->ci->bi && *this->ci->bi == this->users.front()->user))) { this->Hold(); } @@ -141,30 +141,30 @@ void Channel::CheckModes() return; if (this->ci) - for (std::multimap::const_iterator it = this->ci->GetMLock().begin(), it_end = this->ci->GetMLock().end(); it != it_end; ++it) + for (ChannelInfo::ModeList::const_iterator it = this->ci->GetMLock().begin(), it_end = this->ci->GetMLock().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; if (cm->Type == MODE_REGULAR) { - if (!this->HasMode(cm->Name) && ml.set) + if (!this->HasMode(cm->Name) && ml->set) this->SetMode(NULL, cm); - else if (this->HasMode(cm->Name) && !ml.set) + else if (this->HasMode(cm->Name) && !ml->set) this->RemoveMode(NULL, cm); } else if (cm->Type == MODE_PARAM) { /* If the channel doesnt have the mode, or it does and it isn't set correctly */ - if (ml.set) + if (ml->set) { Anope::string param; this->GetParam(cm->Name, param); - if (!this->HasMode(cm->Name) || (!param.empty() && !ml.param.empty() && !param.equals_cs(ml.param))) - this->SetMode(NULL, cm, ml.param); + if (!this->HasMode(cm->Name) || (!param.empty() && !ml->param.empty() && !param.equals_cs(ml->param))) + this->SetMode(NULL, cm, ml->param); } else { @@ -175,10 +175,10 @@ void Channel::CheckModes() } else if (cm->Type == MODE_LIST) { - if (ml.set) - this->SetMode(NULL, cm, ml.param); + if (ml->set) + this->SetMode(NULL, cm, ml->param); else - this->RemoveMode(NULL, cm, ml.param); + this->RemoveMode(NULL, cm, ml->param); } } } @@ -260,9 +260,9 @@ void Channel::DeleteUser(User *user) * @param u The user * @return A user container if found, else NULL */ -UserContainer *Channel::FindUser(User *u) +UserContainer *Channel::FindUser(const User *u) const { - for (CUserList::iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) + for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) if ((*it)->user == u) return *it; return NULL; @@ -273,7 +273,7 @@ UserContainer *Channel::FindUser(User *u) * @param cms The status mode, or NULL to represent no status * @return true or false */ -bool Channel::HasUserStatus(User *u, ChannelModeStatus *cms) const +bool Channel::HasUserStatus(const User *u, ChannelModeStatus *cms) const { if (!u || (cms && cms->Type != MODE_STATUS)) throw CoreException("Channel::HasUserStatus got bad mode"); @@ -297,7 +297,7 @@ bool Channel::HasUserStatus(User *u, ChannelModeStatus *cms) const * @param Name The Mode name, eg CMODE_OP, CMODE_VOICE * @return true or false */ -bool Channel::HasUserStatus(User *u, ChannelModeName Name) const +bool Channel::HasUserStatus(const User *u, ChannelModeName Name) const { return HasUserStatus(u, debug_cast(ModeManager::FindChannelModeByName(Name))); } @@ -395,8 +395,8 @@ void Channel::SetModeInternal(User *setter, ChannelMode *cm, const Anope::string if (cm->Name == CMODE_PERM) { this->SetFlag(CH_PERSIST); - if (ci) - ci->SetFlag(CI_PERSIST); + if (this->ci) + this->ci->SetFlag(CI_PERSIST); } /* Check if we should enforce mlock */ @@ -429,8 +429,8 @@ void Channel::RemoveModeInternal(User *setter, ChannelMode *cm, const Anope::str return; } - BotInfo *bi = findbot(param); - User *u = bi ? bi : finduser(param); + const BotInfo *bi = findbot(param); + const User *u = bi ? bi : finduser(param); if (!u) { @@ -482,8 +482,8 @@ void Channel::RemoveModeInternal(User *setter, ChannelMode *cm, const Anope::str { this->UnsetFlag(CH_PERSIST); - if (ci) - ci->UnsetFlag(CI_PERSIST); + if (this->ci) + this->ci->UnsetFlag(CI_PERSIST); if (this->users.empty()) { @@ -506,7 +506,7 @@ void Channel::RemoveModeInternal(User *setter, ChannelMode *cm, const Anope::str * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) +void Channel::SetMode(const BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -547,7 +547,7 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) +void Channel::SetMode(const BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) { SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } @@ -558,7 +558,7 @@ void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &pa * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(const BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -599,7 +599,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶ * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(const BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) { RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } @@ -631,7 +631,7 @@ bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) const * @param EnforceMLock Should mlock be enforced on this mode change * @param cmodes The modes to set */ -void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) +void Channel::SetModes(const BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) { char buf[BUFSIZE] = ""; va_list args; @@ -879,9 +879,7 @@ void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, u, this->topic)); if (this->ci) - { this->ci->CheckTopic(); - } } void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts) @@ -896,9 +894,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, u, this->topic)); if (this->ci) - { this->ci->CheckTopic(); - } } /** A timer used to keep the BotServ bot/ChanServ in the channel @@ -1157,7 +1153,7 @@ void do_cmode(const Anope::string &source, const Anope::string &channel, const A * @param give_modes Set to 1 to give modes, 0 to not give modes * @return void **/ -void chan_set_correct_modes(User *user, Channel *c, int give_modes) +void chan_set_correct_modes(const User *user, Channel *c, int give_modes) { ChannelMode *owner = ModeManager::FindChannelModeByName(CMODE_OWNER), *admin = ModeManager::FindChannelModeByName(CMODE_PROTECT), @@ -1208,20 +1204,20 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes) } // Check mlock - for (std::multimap::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it) + for (ChannelInfo::ModeList::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().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 || cm->Type != MODE_STATUS) continue; - if (Anope::Match(user->nick, ml.param) || Anope::Match(user->GetDisplayedMask(), ml.param)) + if (Anope::Match(user->nick, ml->param) || Anope::Match(user->GetDisplayedMask(), ml->param)) { - if ((ml.set && !c->HasUserStatus(user, ml.name)) || (!ml.set && c->HasUserStatus(user, ml.name))) + if ((ml->set && !c->HasUserStatus(user, ml->name)) || (!ml->set && c->HasUserStatus(user, ml->name))) { - if (ml.set) + if (ml->set) c->SetMode(NULL, cm, user->nick, false); - else if (!ml.set) + else if (!ml->set) c->RemoveMode(NULL, cm, user->nick, false); } } @@ -1326,7 +1322,7 @@ const Anope::string Entry::GetMask() * @param full True to match against a users real host and IP * @return true on match */ -bool Entry::Matches(User *u, bool full) const +bool Entry::Matches(const User *u, bool full) const { bool ret = true; diff --git a/src/chanserv.cpp b/src/chanserv.cpp index fd7fb88f9..67b77a432 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -18,17 +18,14 @@ #include "channels.h" #include "access.h" -registered_channel_map RegisteredChannelList; - -/*************************************************************************/ - -ChannelInfo *cs_findchan(const Anope::string &chan) +ChannelInfo* cs_findchan(const Anope::string &chan) { - FOREACH_MOD(I_OnFindChan, OnFindChan(chan)); - - registered_channel_map::const_iterator it = RegisteredChannelList.find(chan); - if (it != RegisteredChannelList.end()) + registered_channel_map::const_iterator it = RegisteredChannelList->find(chan); + if (it != RegisteredChannelList->end()) + { + it->second->QueueUpdate(); return it->second; + } return NULL; } @@ -40,7 +37,7 @@ ChannelInfo *cs_findchan(const Anope::string &chan) * @param ci The channel * @return true or false */ -bool IsFounder(User *user, ChannelInfo *ci) +bool IsFounder(const User *user, const ChannelInfo *ci) { if (!user || !ci) return false; @@ -71,7 +68,7 @@ void update_cs_lastseen(User *user, ChannelInfo *ci) /* Returns the best ban possible for a user depending of the bantype value. */ -int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret) +int get_idealban(const ChannelInfo *ci, User *u, Anope::string &ret) { Anope::string mask; diff --git a/src/config.cpp b/src/config.cpp index 790f5c82f..66d8f6a8c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -620,9 +620,13 @@ static bool DoneOperTypes(ServerConfig *, const Anope::string &) static bool InitOpers(ServerConfig *config, const Anope::string &) { - for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it) - if (it->second->o && it->second->o->config) - it->second->o = NULL; + for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + { + NickCore *nc = it->second; + nc->QueueUpdate(); + if (nc->o && nc->o->config) + nc->o = NULL; + } for (unsigned i = 0; i < config->Opers.size(); ++i) delete config->Opers[i]; @@ -674,7 +678,7 @@ static bool DoneOpers(ServerConfig *config, const Anope::string &) { Oper *o = config->Opers[i]; - NickAlias *na = findnick(o->name); + const NickAlias *na = findnick(o->name); if (!na) // Nonexistant nick continue; @@ -817,8 +821,15 @@ static bool DoneLogs(ServerConfig *config, const Anope::string &) static bool InitCommands(ServerConfig *config, const Anope::string &) { - for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) - it->second->commands.clear(); + for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + { + BotInfo *bi = it->second; + if (bi) + { + bi->QueueUpdate(); + bi->commands.clear(); + } + } return true; } @@ -929,8 +940,8 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope: throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); services.insert(nick); - BotInfo *bi = findbot(nick); - if (bi == NULL) + BotInfo* bi = findbot(nick); + if (!bi) bi = new BotInfo(nick, user, host, gecos, modes); bi->SetFlag(BI_CONF); @@ -1000,13 +1011,13 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope: static bool DoneServices(ServerConfig *config, const Anope::string &) { - for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end;) + for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end;) { BotInfo *bi = it->second; ++it; if (bi->HasFlag(BI_CONF) && services.count(bi->nick) == 0) - delete bi; + bi->destroy(); } services.clear(); return true; diff --git a/src/init.cpp b/src/init.cpp index 55ad04bae..08d4aed08 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -453,7 +453,7 @@ void Init(int ac, char **av) /* Create me */ Me = new Server(NULL, Config->ServerName, 0, Config->ServerDesc, Config->Numeric); - for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) it->second->server = Me; /* Announce ourselves to the logfile. */ diff --git a/src/language.cpp b/src/language.cpp index 1a374c0bc..8b680077b 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -63,7 +63,7 @@ const char *translate(User *u, const char *string) return translate(u ? u->Account() : NULL, string); } -const char *translate(NickCore *nc, const char *string) +const char *translate(const NickCore *nc, const char *string) { return anope_gettext(nc ? nc->language.c_str() : Config->NSDefLanguage.c_str(), string); } diff --git a/src/logger.cpp b/src/logger.cpp index fb720963c..2b27e1478 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -75,15 +75,15 @@ Anope::string LogFile::GetName() const return this->filename; } -Log::Log(LogType type, const Anope::string &category, BotInfo *b) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(type), Category(category) +Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(type), Category(category) { - if (!bi) - bi = Config ? findbot(Config->Global) : NULL; + if (!bi && Config) + bi = findbot(Config->Global); if (bi) this->Sources.push_back(bi->nick); } -Log::Log(LogType type, User *_u, Command *_c, ChannelInfo *_ci) : u(_u), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) +Log::Log(LogType type, const User *_u, Command *_c, const ChannelInfo *_ci) : u(_u), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) { if (!u || !c) throw CoreException("Invalid pointers passed to Log::Log"); @@ -95,8 +95,8 @@ Log::Log(LogType type, User *_u, Command *_c, ChannelInfo *_ci) : u(_u), c(_c), this->bi = NULL; if (sl != Anope::string::npos) this->bi = findbot(c->name.substr(0, sl)); - if (this->bi == NULL) - this->bi = Config ? findbot(Config->Global) : NULL; + if (this->bi == NULL && Config) + this->bi = findbot(Config->Global); this->Category = c->name; if (this->bi) this->Sources.push_back(this->bi->nick); @@ -106,12 +106,13 @@ Log::Log(LogType type, User *_u, Command *_c, ChannelInfo *_ci) : u(_u), c(_c), this->Sources.push_back(ci->name); } -Log::Log(User *_u, Channel *ch, const Anope::string &category) : u(_u), c(NULL), chan(ch), ci(chan ? chan->ci : NULL), s(NULL), Type(LOG_CHANNEL) +Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), u(_u), c(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), Type(LOG_CHANNEL) { if (!chan) throw CoreException("Invalid pointers passed to Log::Log"); - this->bi = Config ? findbot(Config->ChanServ) : NULL; + if (Config) + this->bi = findbot(Config->ChanServ); this->Category = category; if (this->bi) this->Sources.push_back(this->bi->nick); @@ -120,36 +121,36 @@ Log::Log(User *_u, Channel *ch, const Anope::string &category) : u(_u), c(NULL), this->Sources.push_back(chan->name); } -Log::Log(User *_u, const Anope::string &category, BotInfo *_bi) : bi(_bi), u(_u), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category) +Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(_u), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category) { if (!u) throw CoreException("Invalid pointers passed to Log::Log"); - if (!this->bi) - this->bi = Config ? findbot(Config->Global) : NULL; + if (!this->bi && Config) + this->bi = findbot(Config->Global); if (this->bi) this->Sources.push_back(this->bi->nick); this->Sources.push_back(u->nick); } -Log::Log(Server *serv, const Anope::string &category, BotInfo *_bi) : bi(_bi), u(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category) +Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category) { if (!s) throw CoreException("Invalid pointer passed to Log::Log"); - if (!this->bi) - this->bi = Config ? findbot(Config->OperServ) : NULL; - if (!this->bi) - this->bi = Config ? findbot(Config->Global) : NULL; + if (!this->bi && Config) + this->bi = findbot(Config->OperServ); + if (!this->bi && Config) + this->bi = findbot(Config->Global); if (this->bi) this->Sources.push_back(this->bi->nick); this->Sources.push_back(s->GetName()); } -Log::Log(BotInfo *b, const Anope::string &category) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category) +Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category) { - if (!this->bi) - this->bi = Config ? findbot(Config->Global) : NULL; + if (!this->bi && Config) + this->bi = findbot(Config->Global); if (this->bi) this->Sources.push_back(bi->nick); } diff --git a/src/mail.cpp b/src/mail.cpp index cc1541640..aaf564bc6 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -51,7 +51,7 @@ void MailThread::Run() SetExitState(); } -bool Mail(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message) +bool Mail(User *u, NickCore *nc, const BotInfo *service, const Anope::string &subject, const Anope::string &message) { if (!u || !nc || !service || subject.empty() || message.empty()) return false; diff --git a/src/main.cpp b/src/main.cpp index 303b6b076..cacfec814 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,7 +124,7 @@ UplinkSocket::~UplinkSocket() { /* Don't use quitmsg here, it may contain information you don't want people to see */ ircdproto->SendQuit(u, "Shutting down"); - BotInfo *bi = findbot(u->nick); + BotInfo* bi = findbot(u->nick); if (bi != NULL) bi->introduced = false; } @@ -224,7 +224,7 @@ UplinkSocket::Message::~Message() return; } - BotInfo *bi = findbot(this->user->nick); + const BotInfo *bi = findbot(this->user->nick); if (bi != NULL && bi->introduced == false) { Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced"; diff --git a/src/memoserv.cpp b/src/memoserv.cpp index 1407e8521..92c027702 100644 --- a/src/memoserv.cpp +++ b/src/memoserv.cpp @@ -20,14 +20,14 @@ Memo::Memo() : Flags(MemoFlagStrings) { } -Anope::string Memo::serialize_name() const +const Anope::string Memo::serialize_name() const { return "Memo"; } -Serializable::serialized_data Memo::serialize() +Serialize::Data Memo::serialize() const { - serialized_data data; + Serialize::Data data; data["owner"] << this->owner; data["time"].setType(Serialize::DT_INT) << this->time; @@ -38,50 +38,69 @@ Serializable::serialized_data Memo::serialize() return data; } -void Memo::unserialize(serialized_data &data) +Serializable* Memo::unserialize(Serializable *obj, Serialize::Data &data) { if (!memoserv) - return; + return NULL; bool ischan; MemoInfo *mi = memoserv->GetMemoInfo(data["owner"].astr(), ischan); if (!mi) - return; + return NULL; - Memo *m = new Memo(); + Memo *m; + if (obj) + m = debug_cast(obj); + else + m = new Memo(); data["owner"] >> m->owner; data["time"] >> m->time; data["sender"] >> m->sender; data["text"] >> m->text; m->FromString(data["flags"].astr()); - mi->memos.push_back(m); + if (obj == NULL) + mi->memos->push_back(m); + return m; +} + +MemoInfo::MemoInfo() : memos("Memo") +{ +} + +Memo *MemoInfo::GetMemo(unsigned index) const +{ + if (index >= this->memos->size()) + return NULL; + Memo *m = (*memos)[index]; + m->QueueUpdate(); + return m; } unsigned MemoInfo::GetIndex(Memo *m) const { - for (unsigned i = 0; i < this->memos.size(); ++i) - if (this->memos[i] == m) + for (unsigned i = 0; i < this->memos->size(); ++i) + if (this->GetMemo(i) == m) return i; return -1; } void MemoInfo::Del(unsigned index) { - if (index >= this->memos.size()) + if (index >= this->memos->size()) return; - delete this->memos[index]; - this->memos.erase(this->memos.begin() + index); + this->GetMemo(index)->destroy(); + this->memos->erase(this->memos->begin() + index); } void MemoInfo::Del(Memo *memo) { - std::vector::iterator it = std::find(this->memos.begin(), this->memos.end(), memo); + std::vector::iterator it = std::find(this->memos->begin(), this->memos->end(), memo); - if (it != this->memos.end()) + if (it != this->memos->end()) { - delete memo; - this->memos.erase(it); + memo->destroy(); + this->memos->erase(it); } } diff --git a/src/messages.cpp b/src/messages.cpp index 52e7c57c1..b34841094 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -47,7 +47,7 @@ bool OnStats(const Anope::string &source, const std::vector ¶ { Oper *o = Config->Opers[i]; - NickAlias *na = findnick(o->name); + const NickAlias *na = findnick(o->name); if (na) ircdproto->SendNumeric(243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); } diff --git a/src/misc.cpp b/src/misc.cpp index 855155409..fbc110ef3 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -305,7 +305,7 @@ time_t dotime(const Anope::string &s) * @param seconds time in seconds * @return buffer */ -Anope::string duration(const time_t &t, NickCore *nc) +Anope::string duration(const time_t &t, const NickCore *nc) { /* We first calculate everything */ time_t days = (t / 86400); @@ -339,7 +339,7 @@ Anope::string duration(const time_t &t, NickCore *nc) } } -Anope::string do_strftime(const time_t &t, NickCore *nc, bool short_output) +Anope::string do_strftime(const time_t &t, const NickCore *nc, bool short_output) { tm tm = *localtime(&t); char buf[BUFSIZE]; @@ -514,7 +514,7 @@ bool nickIsServices(const Anope::string &tempnick, bool bot) nick = nick.substr(0, at); } - BotInfo *bi = findbot(nick); + const BotInfo *bi = findbot(nick); if (bi) return bot ? true : bi->HasFlag(BI_CORE); return false; diff --git a/src/modes.cpp b/src/modes.cpp index cbfdc093b..dd5897087 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -24,12 +24,14 @@ std::vector ModeManager::UserModes; /* Number of generic modes we support */ unsigned GenericChannelModes = 0, GenericUserModes = 0; /* Default mlocked modes */ -std::multimap def_mode_locks; +ChannelInfo::ModeList def_mode_locks; /** Parse the mode string from the config file and set the default mlocked modes */ void SetDefaultMLock(ServerConfig *config) { + for (ChannelInfo::ModeList::iterator it = def_mode_locks.begin(), it_end = def_mode_locks.end(); it != it_end; ++it) + delete it->second; def_mode_locks.clear(); Anope::string modes; @@ -57,8 +59,15 @@ void SetDefaultMLock(ServerConfig *config) } if (cm->Type != MODE_LIST) // Only MODE_LIST can have duplicates - def_mode_locks.erase(cm->Name); - def_mode_locks.insert(std::make_pair(cm->Name, ModeLock(NULL, adding == 1, cm->Name, param))); + { + ChannelInfo::ModeList::iterator it = def_mode_locks.find(cm->Name); + if (it != def_mode_locks.end()) + { + delete it->second; + def_mode_locks.erase(it); + } + } + def_mode_locks.insert(std::make_pair(cm->Name, new ModeLock(NULL, adding == 1, cm->Name, param))); } } } @@ -461,7 +470,7 @@ std::list ModeManager::BuildModeStrings(StackerInfo *info) * @param Param A param, if there is one * @param Type The type this is, user or channel */ -void ModeManager::StackerAddInternal(BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type) +void ModeManager::StackerAddInternal(const BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type) { StackerInfo *s = GetInfo(Object); s->Type = Type; @@ -646,7 +655,7 @@ char ModeManager::GetStatusChar(char Value) * @param Set true for setting, false for removing * @param Param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) +void ModeManager::StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) { StackerAddInternal(bi, c, cm, Set, Param, ST_CHANNEL); } @@ -658,7 +667,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, * @param Set true for setting, false for removing * @param param The param, if there is one */ -void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) +void ModeManager::StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) { StackerAddInternal(bi, u, um, Set, Param, ST_USER); } diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 586add90e..18e581714 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -19,16 +19,17 @@ #include "servers.h" #include "config.h" -class NickServHeld; +serialize_checker NickAliasList("NickAlias"); +class NickServHeld; typedef std::map nickservheld_map; static nickservheld_map NickServHelds; /** Default constructor * @param nick The nick - * @param nickcore The nickcofe for this nick + * @param nickcore The nickcore for this nick */ -NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Flags(NickNameFlagStrings) +NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Flags(NickNameFlagStrings) { if (nickname.empty()) throw CoreException("Empty nick passed to NickAlias constructor"); @@ -38,16 +39,16 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Flags< this->time_registered = this->last_seen = Anope::CurTime; this->nick = nickname; this->nc = nickcore; - this->nc->aliases.push_back(this); + nickcore->aliases.push_back(this); - NickAliasList[this->nick] = this; + (*NickAliasList)[this->nick] = this; if (this->nc->o == NULL) { Oper *o = Oper::Find(this->nick); if (o == NULL) o = Oper::Find(this->nc->display); - this->nc->o = o; + nickcore->o = o; if (this->nc->o != NULL) Log() << "Tied oper " << this->nc->display << " to type " << this->nc->o->ot->GetName(); } @@ -63,7 +64,7 @@ NickAlias::~NickAlias() if (this->nc) { /* Next: see if our core is still useful. */ - std::list::iterator it = std::find(this->nc->aliases.begin(), this->nc->aliases.end(), this); + std::list >::iterator it = std::find(this->nc->aliases.begin(), this->nc->aliases.end(), this); if (it != this->nc->aliases.end()) this->nc->aliases.erase(it); if (this->nc->aliases.empty()) @@ -80,7 +81,7 @@ NickAlias::~NickAlias() } /* Remove us from the aliases list */ - NickAliasList.erase(this->nick); + NickAliasList->erase(this->nick); } /** Release a nick from being held. This can be called from the core (ns_release) @@ -242,16 +243,16 @@ time_t NickAlias::GetVhostCreated() const return this->vhost_created; } -Anope::string NickAlias::serialize_name() const +const Anope::string NickAlias::serialize_name() const { return "NickAlias"; } -Serializable::serialized_data NickAlias::serialize() +Serialize::Data NickAlias::serialize() const { - serialized_data data; + Serialize::Data data; - data["nick"].setKey().setMax(Config->NickLen) << this->nick; + data["nick"].setMax(Config->NickLen) << this->nick; data["last_quit"] << this->last_quit; data["last_realname"] << this->last_realname; data["last_usermask"] << this->last_usermask; @@ -272,18 +273,21 @@ Serializable::serialized_data NickAlias::serialize() return data; } -void NickAlias::unserialize(serialized_data &data) +Serializable* NickAlias::unserialize(Serializable *obj, Serialize::Data &data) { NickCore *core = findcore(data["nc"].astr()); if (core == NULL) - return; + return NULL; - NickAlias *na = findnick(data["nick"].astr()); - if (na == NULL) + NickAlias *na; + if (obj) + na = debug_cast(obj); + else na = new NickAlias(data["nick"].astr(), core); - else if (na->nc != core) + + if (na->nc != core) { - std::list::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na); + std::list >::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na); if (it != na->nc->aliases.end()) na->nc->aliases.erase(it); @@ -293,7 +297,7 @@ void NickAlias::unserialize(serialized_data &data) change_core_display(na->nc); na->nc = core; - na->nc->aliases.push_back(na); + core->aliases.push_back(na); } data["last_quit"] >> na->last_quit; @@ -307,5 +311,6 @@ void NickAlias::unserialize(serialized_data &data) time_t vhost_time; data["vhost_time"] >> vhost_time; na->SetVhost(data["vhost_ident"].astr(), data["vhost_host"].astr(), data["vhost_creator"].astr(), vhost_time); + return na; } diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 62a3d7006..e68e7444d 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -14,6 +14,8 @@ #include "account.h" #include "config.h" +serialize_checker NickCoreList("NickCore"); + /** Default constructor * @param display The display nick */ @@ -35,7 +37,7 @@ NickCore::NickCore(const Anope::string &coredisplay) : FlagsNSDefFlags.HasFlag(static_cast(t))) this->SetFlag(static_cast(t)); - NickCoreList[this->display] = this; + (*NickCoreList)[this->display] = this; } /** Default destructor @@ -45,29 +47,29 @@ NickCore::~NickCore() FOREACH_MOD(I_OnDelCore, OnDelCore(this)); /* Remove the core from the list */ - NickCoreList.erase(this->display); + NickCoreList->erase(this->display); /* Clear access before deleting display name, we want to be able to use the display name in the clear access event */ this->ClearAccess(); - if (!this->memos.memos.empty()) + if (!this->memos.memos->empty()) { - for (unsigned i = 0, end = this->memos.memos.size(); i < end; ++i) - delete this->memos.memos[i]; - this->memos.memos.clear(); + for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i) + this->memos.GetMemo(i)->destroy(); + this->memos.memos->clear(); } } -Anope::string NickCore::serialize_name() const +const Anope::string NickCore::serialize_name() const { return "NickCore"; } -Serializable::serialized_data NickCore::serialize() +Serialize::Data NickCore::serialize() const { - serialized_data data; + Serialize::Data data; - data["display"].setKey().setMax(Config->NickLen) << this->display; + data["display"].setMax(Config->NickLen) << this->display; data["pass"] << this->pass; data["email"] << this->email; data["greet"] << this->greet; @@ -84,11 +86,15 @@ Serializable::serialized_data NickCore::serialize() return data; } -void NickCore::unserialize(serialized_data &data) +Serializable* NickCore::unserialize(Serializable *obj, Serialize::Data &data) { - NickCore *nc = findcore(data["display"].astr()); - if (nc == NULL) + NickCore *nc; + + if (obj) + nc = debug_cast(obj); + else nc = new NickCore(data["display"].astr()); + data["pass"] >> nc->pass; data["email"] >> nc->email; data["greet"] >> nc->greet; @@ -119,6 +125,8 @@ void NickCore::unserialize(serialized_data &data) while (sep.GetToken(buf)) nc->memos.ignores.push_back(buf); } + + return nc; } bool NickCore::IsServicesOper() const @@ -178,7 +186,7 @@ Anope::string NickCore::GetCert(unsigned entry) const return this->cert[entry]; } -bool NickCore::FindCert(const Anope::string &entry) +bool NickCore::FindCert(const Anope::string &entry) const { for (unsigned i = 0, end = this->cert.size(); i < end; ++i) if (this->cert[i] == entry) diff --git a/src/nickserv.cpp b/src/nickserv.cpp index 011ee685e..a66738c03 100644 --- a/src/nickserv.cpp +++ b/src/nickserv.cpp @@ -15,29 +15,28 @@ #include "users.h" #include "protocol.h" -nickalias_map NickAliasList; -nickcore_map NickCoreList; - -NickAlias *findnick(const Anope::string &nick) +NickAlias* findnick(const Anope::string &nick) { - FOREACH_MOD(I_OnFindNick, OnFindNick(nick)); - - nickalias_map::const_iterator it = NickAliasList.find(nick); - if (it != NickAliasList.end()) + nickalias_map::const_iterator it = NickAliasList->find(nick); + if (it != NickAliasList->end()) + { + it->second->QueueUpdate(); return it->second; + } return NULL; } /*************************************************************************/ -NickCore *findcore(const Anope::string &nick) +NickCore* findcore(const Anope::string &nick) { - FOREACH_MOD(I_OnFindCore, OnFindCore(nick)); - - nickcore_map::const_iterator it = NickCoreList.find(nick); - if (it != NickCoreList.end()) + nickcore_map::const_iterator it = NickCoreList->find(nick); + if (it != NickCoreList->end()) + { + it->second->QueueUpdate(); return it->second; + } return NULL; } @@ -81,16 +80,16 @@ void change_core_display(NickCore *nc, const Anope::string &newdisplay) FOREACH_MOD(I_OnChangeCoreDisplay, OnChangeCoreDisplay(nc, newdisplay)); /* Remove the core from the list */ - NickCoreList.erase(nc->display); + NickCoreList->erase(nc->display); nc->display = newdisplay; - NickCoreList[nc->display] = nc; + (*NickCoreList)[nc->display] = nc; } void change_core_display(NickCore *nc) { - NickAlias *na; + const NickAlias *na; if (nc->aliases.empty()) return; na = nc->aliases.front(); diff --git a/src/operserv.cpp b/src/operserv.cpp index 018c9b4e0..59a91aa09 100644 --- a/src/operserv.cpp +++ b/src/operserv.cpp @@ -22,7 +22,7 @@ /* List of XLine managers we check users against in XLineManager::CheckAll */ std::list XLineManager::XLineManagers; -std::multimap XLineManager::XLinesByUID; +serialize_checker > XLineManager::XLinesByUID("XLine"); void XLine::InitRegex() { @@ -138,14 +138,14 @@ bool XLine::IsRegex() const return !this->Mask.empty() && this->Mask[0] == '/' && this->Mask[this->Mask.length() - 1] == '/'; } -Anope::string XLine::serialize_name() const +const Anope::string XLine::serialize_name() const { return "XLine"; } -Serializable::serialized_data XLine::serialize() +Serialize::Data XLine::serialize() const { - serialized_data data; + Serialize::Data data; data["mask"] << this->Mask; data["by"] << this->By; @@ -159,19 +159,39 @@ Serializable::serialized_data XLine::serialize() return data; } -void XLine::unserialize(serialized_data &data) +Serializable* XLine::unserialize(Serializable *obj, Serialize::Data &data) { service_reference xlm("XLineManager", data["manager"].astr()); if (!xlm) - return; + return NULL; + + XLine *xl; + if (obj) + { + xl = debug_cast(obj); + data["mask"] >> xl->Mask; + data["by"] >> xl->By; + data["reason"] >> xl->Reason; + data["uid"] >> xl->UID; + + if (xlm != xl->manager) + { + xl->manager->DelXLine(xl); + xlm->AddXLine(xl); + } + } + else + { + time_t expires; + data["expires"] >> expires; + xl = new XLine(data["mask"].astr(), data["by"].astr(), expires, data["reason"].astr(), data["uid"].astr()); + xlm->AddXLine(xl); + } - time_t expires; - data["expires"] >> expires; - XLine *xl = new XLine(data["mask"].astr(), data["by"].astr(), expires, data["reason"].astr(), data["uid"].astr()); data["created"] >> xl->Created; xl->manager = xlm; - xlm->AddXLine(xl); + return xl; } /** Register a XLineManager, places it in XLineManagers for use in XLineManager::CheckAll @@ -220,7 +240,7 @@ Anope::string XLineManager::GenerateUID() { Anope::string id; int count = 0; - while (id.empty() || XLinesByUID.count(id) > 0) + while (id.empty() || XLinesByUID->count(id) > 0) { if (++count > 10) { @@ -244,7 +264,7 @@ Anope::string XLineManager::GenerateUID() /** Constructor */ -XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service(creator, "XLineManager", xname), type(t) +XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service(creator, "XLineManager", xname), type(t), XLines("XLine") { } @@ -269,7 +289,7 @@ const char &XLineManager::Type() */ size_t XLineManager::GetCount() const { - return this->XLines.size(); + return this->XLines->size(); } /** Get the XLine vector @@ -285,10 +305,9 @@ const std::vector &XLineManager::GetList() const */ void XLineManager::AddXLine(XLine *x) { - x->manager = this; if (!x->UID.empty()) - XLinesByUID.insert(std::make_pair(x->UID, x)); - this->XLines.push_back(x); + XLinesByUID->insert(std::make_pair(x->UID, x)); + this->XLines->push_back(x); } /** Delete an entry from this XLineManager @@ -297,25 +316,25 @@ void XLineManager::AddXLine(XLine *x) */ bool XLineManager::DelXLine(XLine *x) { - std::vector::iterator it = std::find(this->XLines.begin(), this->XLines.end(), x); + std::vector::iterator it = std::find(this->XLines->begin(), this->XLines->end(), x); if (!x->UID.empty()) { - std::multimap::iterator it2 = XLinesByUID.find(x->UID), it3 = XLinesByUID.upper_bound(x->UID); - for (; it2 != XLinesByUID.end() && it2 != it3; ++it2) + std::multimap::iterator it2 = XLinesByUID->find(x->UID), it3 = XLinesByUID->upper_bound(x->UID); + for (; it2 != XLinesByUID->end() && it2 != it3; ++it2) if (it2->second == x) { - XLinesByUID.erase(it2); + XLinesByUID->erase(it2); break; } } - if (it != this->XLines.end()) + if (it != this->XLines->end()) { this->SendDel(x); - delete x; - this->XLines.erase(it); + x->destroy(); + this->XLines->erase(it); return true; } @@ -327,25 +346,28 @@ bool XLineManager::DelXLine(XLine *x) * @param index The index * @return The XLine, or NULL if the index is out of bounds */ -XLine *XLineManager::GetEntry(unsigned index) +XLine* XLineManager::GetEntry(unsigned index) { - if (index >= this->XLines.size()) + if (index >= this->XLines->size()) return NULL; - return this->XLines[index]; + XLine *x = this->XLines->at(index); + x->QueueUpdate(); + return x; } /** Clear the XLine vector */ void XLineManager::Clear() { - for (unsigned i = 0; i < this->XLines.size(); ++i) + for (unsigned i = 0; i < this->XLines->size(); ++i) { - if (!this->XLines[i]->UID.empty()) - XLinesByUID.erase(this->XLines[i]->UID); - delete this->XLines[i]; + XLine *x = this->XLines->at(i); + if (!x->UID.empty()) + XLinesByUID->erase(x->UID); + x->destroy(); } - this->XLines.clear(); + this->XLines->clear(); } /** Checks if a mask can/should be added to the XLineManager @@ -406,19 +428,25 @@ bool XLineManager::CanAdd(CommandSource &source, const Anope::string &mask, time * @param mask The mask * @return The XLine the user matches, or NULL */ -XLine *XLineManager::HasEntry(const Anope::string &mask) +XLine* XLineManager::HasEntry(const Anope::string &mask) { - std::map::iterator it = XLinesByUID.find(mask); - if (it != XLinesByUID.end()) - for (std::map::iterator it2 = XLinesByUID.upper_bound(mask); it != it2; ++it) + std::map::iterator it = XLinesByUID->find(mask); + if (it != XLinesByUID->end()) + for (std::map::iterator it2 = XLinesByUID->upper_bound(mask); it != it2; ++it) if (it->second->manager == NULL || it->second->manager == this) + { + it->second->QueueUpdate(); return it->second; - for (unsigned i = 0, end = this->XLines.size(); i < end; ++i) + } + for (unsigned i = 0, end = this->XLines->size(); i < end; ++i) { - XLine *x = this->XLines[i]; + XLine *x = this->XLines->at(i); if (x->Mask.equals_ci(mask)) + { + x->QueueUpdate(); return x; + } } return NULL; @@ -430,9 +458,9 @@ XLine *XLineManager::HasEntry(const Anope::string &mask) */ XLine *XLineManager::CheckAllXLines(User *u) { - for (unsigned i = this->XLines.size(); i > 0; --i) + for (unsigned i = this->XLines->size(); i > 0; --i) { - XLine *x = this->XLines[i - 1]; + XLine *x = this->XLines->at(i - 1); if (x->Expires && x->Expires < Anope::CurTime) { @@ -454,7 +482,7 @@ XLine *XLineManager::CheckAllXLines(User *u) /** Called when an XLine expires * @param x The xline */ -void XLineManager::OnExpire(XLine *x) +void XLineManager::OnExpire(const XLine *x) { } diff --git a/src/protocol.cpp b/src/protocol.cpp index f51880bbe..506b4def6 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -413,7 +413,7 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vectorSendMessage(bi, source, "%s", "Internal error - unable to process request."); @@ -443,7 +443,7 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vectorUseStrictPrivMsg) { - BotInfo *bi = findbot(receiver); + const BotInfo *bi = findbot(receiver); if (!bi) return true; Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source; @@ -543,7 +543,7 @@ bool IRCdMessage::OnWhois(const Anope::string &source, const std::vectorserver == Me) { - BotInfo *bi = findbot(u->nick); + const BotInfo *bi = findbot(u->nick); ircdproto->SendNumeric(311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str()); if (bi) ircdproto->SendNumeric(307, source, "%s :is a registered nick", bi->nick.c_str()); diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 42feddc7b..2ee66805a 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -21,52 +21,64 @@ #include "language.h" #include "servers.h" -Anope::string BadWord::serialize_name() const +serialize_checker RegisteredChannelList("ChannelInfo"); + +const Anope::string BadWord::serialize_name() const { return "BadWord"; } -Serializable::serialized_data BadWord::serialize() +Serialize::Data BadWord::serialize() const { - serialized_data data; + Serialize::Data data; - data["ci"] << this->ci->name; - data["word"] << this->word; + data["ci"].setMax(64)/*XXX*/ << this->ci->name; + data["word"].setMax(512) << this->word; data["type"].setType(Serialize::DT_INT) << this->type; return data; } -void BadWord::unserialize(serialized_data &data) +Serializable* BadWord::unserialize(Serializable *obj, Serialize::Data &data) { ChannelInfo *ci = cs_findchan(data["ci"].astr()); if (!ci) - return; - + return NULL; + unsigned int n; data["type"] >> n; - - ci->AddBadWord(data["word"].astr(), static_cast(n)); + + BadWord *bw; + if (obj) + { + bw = debug_cast(obj); + data["word"] >> bw->word; + bw->type = static_cast(n); + } + else + bw = ci->AddBadWord(data["word"].astr(), static_cast(n)); + + return bw; } AutoKick::AutoKick() : Flags(AutoKickFlagString) { } -Anope::string AutoKick::serialize_name() const +const Anope::string AutoKick::serialize_name() const { return "AutoKick"; } -Serializable::serialized_data AutoKick::serialize() +Serialize::Data AutoKick::serialize() const { - serialized_data data; + Serialize::Data data; - data["ci"] << this->ci->name; + data["ci"].setMax(64)/*XXX*/ << this->ci->name; if (this->HasFlag(AK_ISNICK) && this->nc) - data["nc"] << this->nc->display; + data["nc"].setMax(Config->NickLen) << this->nc->display; else - data["mask"] << this->mask; + data["mask"].setMax(Config->NickLen) << this->mask; data["reason"] << this->reason; data["creator"] << this->creator; data["addtime"].setType(Serialize::DT_INT) << this->addtime; @@ -76,54 +88,70 @@ Serializable::serialized_data AutoKick::serialize() return data; } -void AutoKick::unserialize(serialized_data &data) +Serializable* AutoKick::unserialize(Serializable *obj, Serialize::Data &data) { ChannelInfo *ci = cs_findchan(data["ci"].astr()); - if (ci == NULL) - return; - - time_t addtime, lastused; - data["addtime"] >> addtime; - data["last_used"] >> lastused; + if (!ci) + return NULL; + AutoKick *ak; NickCore *nc = findcore(data["nc"].astr()); - if (nc) - ci->AddAkick(data["creator"].astr(), nc, data["reason"].astr(), addtime, lastused); + if (obj) + { + ak = debug_cast(obj); + data["creator"] >> ak->creator; + data["reason"] >> ak->reason; + ak->nc = findcore(data["nc"].astr()); + data["mask"] >> ak->mask; + data["addtime"] >> ak->addtime; + data["last_used"] >> ak->last_used; + } else - ci->AddAkick(data["creator"].astr(), data["mask"].astr(), data["reason"].astr(), addtime, lastused); + { + time_t addtime, lastused; + data["addtime"] >> addtime; + data["last_used"] >> lastused; + + if (nc) + ak = ci->AddAkick(data["creator"].astr(), nc, data["reason"].astr(), addtime, lastused); + else + ak = ci->AddAkick(data["creator"].astr(), data["mask"].astr(), data["reason"].astr(), addtime, lastused); + } + + return ak; } ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se, time_t c) : ci(ch), set(s), name(n), param(p), setter(se), created(c) { } -Anope::string ModeLock::serialize_name() const +const Anope::string ModeLock::serialize_name() const { return "ModeLock"; } -Serializable::serialized_data ModeLock::serialize() +Serialize::Data ModeLock::serialize() const { - serialized_data data; + Serialize::Data data; - if (this->ci == NULL) + if (!this->ci) return data; - data["ci"] << this->ci->name; - data["set"] << this->set; - data["name"] << ChannelModeNameStrings[this->name]; - data["param"] << this->param; + data["ci"].setMax(64)/*XXX*/ << this->ci->name; + data["set"].setMax(5) << this->set; + data["name"].setMax(64) << ChannelModeNameStrings[this->name]; + data["param"].setMax(512) << this->param; data["setter"] << this->setter; data["created"].setType(Serialize::DT_INT) << this->created; return data; } -void ModeLock::unserialize(serialized_data &data) +Serializable* ModeLock::unserialize(Serializable *obj, Serialize::Data &data) { ChannelInfo *ci = cs_findchan(data["ci"].astr()); - if (ci == NULL) - return; + if (!ci) + return NULL; ChannelModeName name = CMODE_END; @@ -134,28 +162,47 @@ void ModeLock::unserialize(serialized_data &data) break; } if (name == CMODE_END) - return; - - bool set; - data["set"] >> set; + return NULL; + + ModeLock *ml; + if (obj) + { + ml = debug_cast(obj); + + data["set"] >> ml->set; + ml->name = name; + data["param"] >> ml->param; + data["setter"] >> ml->setter; + data["created"] >> ml->created; + return ml; + } + else + { + bool set; + data["set"] >> set; - time_t created; - data["created"] >> created; + time_t created; + data["created"] >> created; - ModeLock ml(ci, set, name, "", data["setter"].astr(), created); - data["param"] >> ml.param; + ml = new ModeLock(ci, set, name, "", data["setter"].astr(), created); + data["param"] >> ml->param; - ci->mode_locks.insert(std::make_pair(ml.name, ml)); + ci->mode_locks->insert(std::make_pair(ml->name, ml)); + return ml; + } } -Anope::string LogSetting::serialize_name() const +const Anope::string LogSetting::serialize_name() const { return "LogSetting"; } -Serializable::serialized_data LogSetting::serialize() +Serialize::Data LogSetting::serialize() const { - serialized_data data; + Serialize::Data data; + + if (!ci) + return data; data["ci"] << ci->name; data["service_name"] << service_name; @@ -169,35 +216,44 @@ Serializable::serialized_data LogSetting::serialize() return data; } -void LogSetting::unserialize(serialized_data &data) +Serializable* LogSetting::unserialize(Serializable *obj, Serialize::Data &data) { - LogSetting ls; - ChannelInfo *ci = cs_findchan(data["ci"].astr()); if (ci == NULL) - return; + return NULL; + + LogSetting *ls; + if (obj) + ls = debug_cast(obj); + else + { + ls = new LogSetting(); + ci->log_settings->push_back(ls); + } - ls.ci = ci; - data["service_name"] >> ls.service_name; - data["command_service"] >> ls.command_service; - data["command_name"] >> ls.command_name; - data["method"] >> ls.method; - data["extra"] >> ls.extra; - data["creator"] >> ls.creator; - data["created"] >> ls.created; + ls->ci = ci; + data["service_name"] >> ls->service_name; + data["command_service"] >> ls->command_service; + data["command_name"] >> ls->command_name; + data["method"] >> ls->method; + data["extra"] >> ls->extra; + data["creator"] >> ls->creator; + data["created"] >> ls->created; - ci->log_settings.push_back(ls); + return ls; } /** Default constructor * @param chname The channel name */ -ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags(ChannelInfoFlagStrings), botflags(BotServFlagStrings) +ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags(ChannelInfoFlagStrings), access("ChanAccess"), akick("AutoKick"), + badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings) { if (chname.empty()) throw CoreException("Empty channel passed to ChannelInfo constructor"); - this->founder = this->successor = NULL; + this->founder = NULL; + this->successor = NULL; this->last_topic_time = 0; this->c = findchan(chname); if (this->c) @@ -227,7 +283,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flagsttb[i] = 0; - RegisteredChannelList[this->name] = this; + (*RegisteredChannelList)[this->name] = this; FOREACH_MOD(I_OnCreateChan, OnCreateChan(this)); } @@ -235,23 +291,24 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags(ChannelInfoFlagStrings), botflags(BotServFlagStrings) +ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Flags(ChannelInfoFlagStrings), access("ChanAccess"), akick("AutoKick"), + badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings) { *this = ci; if (this->founder) - ++this->founder->channelcount; + --this->founder->channelcount; - this->access.clear(); - this->akick.clear(); - this->badwords.clear(); + this->access->clear(); + this->akick->clear(); + this->badwords->clear(); for (int i = 0; i < TTB_SIZE; ++i) this->ttb[i] = ci.ttb[i]; 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(); @@ -267,7 +324,7 @@ ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags(Chann for (unsigned i = 0; i < ci.GetAkickCount(); ++i) { - AutoKick *takick = ci.GetAkick(i); + const AutoKick *takick = ci.GetAkick(i); if (takick->HasFlag(AK_ISNICK)) this->AddAkick(takick->creator, takick->nc, takick->reason, takick->addtime, takick->last_used); else @@ -275,17 +332,22 @@ ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags(Chann } for (unsigned i = 0; i < ci.GetBadWordCount(); ++i) { - BadWord *bw = ci.GetBadWord(i); + const BadWord *bw = ci.GetBadWord(i); this->AddBadWord(bw->word, bw->type); } + + for (unsigned i = 0; i < ci.log_settings->size(); ++i) + { + LogSetting *l = new LogSetting(*ci.log_settings->at(i)); + l->ci = this; + this->log_settings->push_back(l); + } } /** Default destructor, cleans up the channel complete and removes it from