summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-04-23 05:08:26 -0400
committerAdam <Adam@anope.org>2012-04-23 05:08:26 -0400
commit573e49a7ead331219eb6f0d3ca9cf83e793a5c9c (patch)
treee145e04fa3d041cf92ce46da4ac790b63231059c /src
parent63c639e108a00d7dbb0d7ac9891684fc83a3b207 (diff)
Reworked live SQL support yet again
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp35
-rw-r--r--src/actions.cpp2
-rw-r--r--src/bots.cpp55
-rw-r--r--src/botserv.cpp16
-rw-r--r--src/channels.cpp76
-rw-r--r--src/chanserv.cpp19
-rw-r--r--src/config.cpp31
-rw-r--r--src/init.cpp2
-rw-r--r--src/language.cpp2
-rw-r--r--src/logger.cpp39
-rw-r--r--src/mail.cpp2
-rw-r--r--src/main.cpp4
-rw-r--r--src/memoserv.cpp53
-rw-r--r--src/messages.cpp2
-rw-r--r--src/misc.cpp6
-rw-r--r--src/modes.cpp21
-rw-r--r--src/nickalias.cpp43
-rw-r--r--src/nickcore.cpp36
-rw-r--r--src/nickserv.cpp31
-rw-r--r--src/operserv.cpp108
-rw-r--r--src/protocol.cpp6
-rw-r--r--src/regchannel.cpp495
-rw-r--r--src/serialize.cpp95
-rw-r--r--src/servers.cpp6
-rw-r--r--src/users.cpp37
25 files changed, 726 insertions, 496 deletions
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<AccessProvider> 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<ChanAccess *>(obj);
+ else
+ access = const_cast<ChanAccess *>(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<NickAlias *>::iterator it = nc->aliases.begin(); it != nc->aliases.end(); ++it)
+ for (std::list<serialize_obj<NickAlias> >::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<Privilege> &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<BotInfo *> BotListByNick;
-Anope::map<BotInfo *> BotListByUID;
+serialize_checker<botinfo_map> BotListByNick("BotInfo");
+serialize_checker<botinfouid_map> 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<BotFlag, BI_END>(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<BotInfo *>(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<Anope::string> 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<Command> 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<BotInfo *>::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<BotInfo *>::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<ChannelModeName, ModeLock>::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<ChannelModeStatus *>(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 &param, bool EnforceMLock)
+void Channel::SetMode(const BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -547,7 +547,7 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param,
* @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 &param, bool EnforceMLock)
+void Channel::SetMode(const BotInfo *bi, ChannelModeName Name, const Anope::string &param, 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 &param, bool EnforceMLock)
+void Channel::RemoveMode(const BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -599,7 +599,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &para
* @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 &param, bool EnforceMLock)
+void Channel::RemoveMode(const BotInfo *bi, ChannelModeName Name, const Anope::string &param, 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<ChannelModeName, ModeLock>::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<MemoFlag>(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<Memo *>(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<Memo *>::iterator it = std::find(this->memos.begin(), this->memos.end(), memo);
+ std::vector<Memo *>::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<Anope::string> &para
{
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<UserMode *> ModeManager::UserModes;
/* Number of generic modes we support */
unsigned GenericChannelModes = 0, GenericUserModes = 0;
/* Default mlocked modes */
-std::multimap<ChannelModeName, ModeLock> 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<Anope::string> 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<nickalias_map> NickAliasList("NickAlias");
+class NickServHeld;
typedef std::map<Anope::string, NickServHeld *> 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<NickNameFlag, NS_END>(NickNameFlagStrings)
+NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Flags<NickNameFlag, NS_END>(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<NickAlias *>::iterator it = std::find(this->nc->aliases.begin(), this->nc->aliases.end(), this);
+ std::list<serialize_obj<NickAlias> >::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<NickAlias *>(obj);
+ else
na = new NickAlias(data["nick"].astr(), core);
- else if (na->nc != core)
+
+ if (na->nc != core)
{
- std::list<NickAlias *>::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na);
+ std::list<serialize_obj<NickAlias> >::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<nickcore_map> NickCoreList("NickCore");
+
/** Default constructor
* @param display The display nick
*/
@@ -35,7 +37,7 @@ NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_EN
if (Config->NSDefFlags.HasFlag(static_cast<NickCoreFlag>(t)))
this->SetFlag(static_cast<NickCoreFlag>(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<NickCore *>(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 *> XLineManager::XLineManagers;
-std::multimap<Anope::string, XLine *, ci::less> XLineManager::XLinesByUID;
+serialize_checker<std::multimap<Anope::string, XLine *, ci::less> > 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<XLineManager> xlm("XLineManager", data["manager"].astr());
if (!xlm)
- return;
+ return NULL;
+
+ XLine *xl;
+ if (obj)
+ {
+ xl = debug_cast<XLine *>(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<XLine *> &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<XLine *>::iterator it = std::find(this->XLines.begin(), this->XLines.end(), x);
+ std::vector<XLine *>::iterator it = std::find(this->XLines->begin(), this->XLines->end(), x);
if (!x->UID.empty())
{
- std::multimap<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID.find(x->UID), it3 = XLinesByUID.upper_bound(x->UID);
- for (; it2 != XLinesByUID.end() && it2 != it3; ++it2)
+ std::multimap<Anope::string, XLine *, ci::less>::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<Anope::string, XLine *, ci::less>::iterator it = XLinesByUID.find(mask);
- if (it != XLinesByUID.end())
- for (std::map<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID.upper_bound(mask); it != it2; ++it)
+ std::map<Anope::string, XLine *, ci::less>::iterator it = XLinesByUID->find(mask);
+ if (it != XLinesByUID->end())
+ for (std::map<Anope::string, XLine *, ci::less>::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::vector<Anope
{
Log() << message << ": user record for " << source << " not found";
- BotInfo *bi = findbot(receiver);
+ const BotInfo *bi = findbot(receiver);
if (bi)
ircdproto->SendMessage(bi, source, "%s", "Internal error - unable to process request.");
@@ -443,7 +443,7 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope
}
else if (Config->UseStrictPrivMsg)
{
- 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::vector<Anope::
User *u = finduser(params[0]);
if (u && u->server == 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<registered_channel_map> 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<BadWordType>(n));
+
+ BadWord *bw;
+ if (obj)
+ {
+ bw = debug_cast<BadWord *>(obj);
+ data["word"] >> bw->word;
+ bw->type = static_cast<BadWordType>(n);
+ }
+ else
+ bw = ci->AddBadWord(data["word"].astr(), static_cast<BadWordType>(n));
+
+ return bw;
}
AutoKick::AutoKick() : Flags<AutoKickFlag>(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<AutoKick *>(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<ModeLock *>(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<LogSetting *>(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<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), botflags(BotServFlagStrings)
+ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(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) : Flags<ChannelInfoFlag, C
for (int i = 0; i < TTB_SIZE; ++i)
this->ttb[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<ChannelInfoFlag, C
/** Copy constructor
* @param ci The ChannelInfo to copy settings to
*/
-ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), botflags(BotServFlagStrings)
+ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(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<ChannelInfoFlag, CI_END>(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<ChannelInfoFlag, CI_END>(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 the internal list
*/
ChannelInfo::~ChannelInfo()
{
- unsigned i, end;
-
FOREACH_MOD(I_OnDelChan, OnDelChan(this));
Log(LOG_DEBUG) << "Deleting channel " << this->name;
@@ -297,33 +359,41 @@ ChannelInfo::~ChannelInfo()
this->c->ci = NULL;
}
- RegisteredChannelList.erase(this->name);
+ RegisteredChannelList->erase(this->name);
this->ClearAccess();
this->ClearAkick();
this->ClearBadWords();
- if (!this->memos.memos.empty())
+ for (unsigned i = 0; i < this->log_settings->size(); ++i)
+ this->log_settings->at(i)->destroy();
+ this->log_settings->clear();
+
+ for (ChannelInfo::ModeList::iterator it = this->mode_locks->begin(), it_end = this->mode_locks->end(); it != it_end; ++it)
+ it->second->destroy();
+ this->mode_locks->clear();
+
+ if (!this->memos.memos->empty())
{
- for (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();
}
if (this->founder)
--this->founder->channelcount;
}
-Anope::string ChannelInfo::serialize_name() const
+const Anope::string ChannelInfo::serialize_name() const
{
return "ChannelInfo";
}
-Serializable::serialized_data ChannelInfo::serialize()
+Serialize::Data ChannelInfo::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["name"].setKey().setMax(255) << this->name;
+ data["name"].setMax(255) << this->name;
if (this->founder)
data["founder"] << this->founder->display;
if (this->successor)
@@ -339,7 +409,7 @@ Serializable::serialized_data ChannelInfo::serialize()
data["botflags"] << this->botflags.ToString();
{
Anope::string levels_buffer;
- for (std::map<Anope::string, int16_t>::iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
+ for (std::map<Anope::string, int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
levels_buffer += it->first + " " + stringify(it->second) + " ";
data["levels"] << levels_buffer;
}
@@ -359,24 +429,26 @@ Serializable::serialized_data ChannelInfo::serialize()
return data;
}
-void ChannelInfo::unserialize(serialized_data &data)
+Serializable* ChannelInfo::unserialize(Serializable *obj, Serialize::Data &data)
{
- ChannelInfo *ci = cs_findchan(data["name"].astr());
- if (ci == NULL)
+ ChannelInfo *ci;
+ if (obj)
+ ci = debug_cast<ChannelInfo *>(obj);
+ else
ci = new ChannelInfo(data["name"].astr());
if (data.count("founder") > 0)
{
if (ci->founder)
- ci->founder->channelcount--;
+ --ci->founder->channelcount;
ci->founder = findcore(data["founder"].astr());
if (ci->founder)
- ci->founder->channelcount++;
+ --ci->founder->channelcount;
}
if (data.count("successor") > 0)
{
ci->successor = findcore(data["successor"].astr());
- if (ci->founder && ci->founder == ci->successor)
+ if (ci->founder && *ci->founder == *ci->successor)
ci->successor = NULL;
}
data["description"] >> ci->desc;
@@ -393,8 +465,15 @@ void ChannelInfo::unserialize(serialized_data &data)
for (unsigned i = 0; i + 1 < v.size(); i += 2)
ci->levels[v[i]] = convertTo<int16_t>(v[i + 1]);
}
- if (data.count("bi") > 0)
- ci->bi = findbot(data["bi"].astr());
+ BotInfo *bi = findbot(data["bi"].astr());
+ if (*ci->bi != bi)
+ {
+ if (ci->bi)
+ ci->bi->UnAssign(NULL, ci);
+ ci->bi = bi;
+ if (ci->bi)
+ ci->bi->Assign(NULL, ci);
+ }
data["capsmin"] >> ci->capsmin;
data["capspercent"] >> ci->capspercent;
data["floodlines"] >> ci->floodlines;
@@ -409,6 +488,8 @@ void ChannelInfo::unserialize(serialized_data &data)
while (sep.GetToken(buf))
ci->memos.ignores.push_back(buf);
}
+
+ return ci;
}
@@ -422,7 +503,7 @@ void ChannelInfo::SetFounder(NickCore *nc)
this->founder = nc;
if (this->founder)
++this->founder->channelcount;
- if (this->founder == this->successor)
+ if (*this->founder == *this->successor)
this->successor = NULL;
}
@@ -437,15 +518,15 @@ NickCore *ChannelInfo::GetFounder() const
/** Find which bot should send mode/topic/etc changes for this channel
* @return The bot
*/
-BotInfo *ChannelInfo::WhoSends()
+BotInfo *ChannelInfo::WhoSends() const
{
if (this && this->bi)
return this->bi;
BotInfo *tbi = findbot(Config->ChanServ);
if (tbi)
return tbi;
- else if (!BotListByNick.empty())
- return BotListByNick.begin()->second;
+ else if (!BotListByNick->empty())
+ return BotListByNick->begin()->second;
return NULL;
}
@@ -454,7 +535,7 @@ BotInfo *ChannelInfo::WhoSends()
*/
void ChannelInfo::AddAccess(ChanAccess *taccess)
{
- this->access.push_back(taccess);
+ this->access->push_back(taccess);
}
/** Get an entry from the channel access list by index
@@ -464,25 +545,27 @@ void ChannelInfo::AddAccess(ChanAccess *taccess)
*
* Retrieves an entry from the access list that matches the given index.
*/
-ChanAccess *ChannelInfo::GetAccess(unsigned index)
+ChanAccess *ChannelInfo::GetAccess(unsigned index) const
{
- if (this->access.empty() || index >= this->access.size())
+ if (this->access->empty() || index >= this->access->size())
return NULL;
- return this->access[index];
+ ChanAccess *acc = (*this->access)[index];
+ acc->QueueUpdate();
+ return acc;
}
-AccessGroup ChannelInfo::AccessFor(User *u)
+AccessGroup ChannelInfo::AccessFor(const User *u)
{
AccessGroup group;
if (u == NULL)
return group;
- NickCore *nc = u->Account();
+ const NickCore *nc = u->Account();
if (nc == NULL && u->IsRecognized())
{
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (na != NULL)
nc = na->nc;
}
@@ -492,9 +575,9 @@ AccessGroup ChannelInfo::AccessFor(User *u)
group.ci = this;
group.nc = nc;
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
- if (this->access[i]->Matches(u, nc))
- group.push_back(this->access[i]);
+ for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
+ if (this->GetAccess(i)->Matches(u, nc))
+ group.push_back(this->GetAccess(i));
if (group.Founder || !group.empty())
this->last_used = Anope::CurTime;
@@ -502,7 +585,7 @@ AccessGroup ChannelInfo::AccessFor(User *u)
return group;
}
-AccessGroup ChannelInfo::AccessFor(NickCore *nc)
+AccessGroup ChannelInfo::AccessFor(const NickCore *nc)
{
AccessGroup group;
@@ -510,9 +593,9 @@ AccessGroup ChannelInfo::AccessFor(NickCore *nc)
group.ci = this;
group.nc = nc;
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
- if (this->access[i]->Matches(NULL, nc))
- group.push_back(this->access[i]);
+ for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
+ if (this->GetAccess(i)->Matches(NULL, nc))
+ group.push_back(this->GetAccess(i));
if (group.Founder || !group.empty())
this->last_used = Anope::CurTime;
@@ -525,7 +608,7 @@ AccessGroup ChannelInfo::AccessFor(NickCore *nc)
*/
unsigned ChannelInfo::GetAccessCount() const
{
- return this->access.size();
+ return this->access->size();
}
/** Erase an entry from the channel access list
@@ -536,11 +619,11 @@ unsigned ChannelInfo::GetAccessCount() const
*/
void ChannelInfo::EraseAccess(unsigned index)
{
- if (this->access.empty() || index >= this->access.size())
+ if (this->access->empty() || index >= this->access->size())
return;
- delete this->access[index];
- this->access.erase(this->access.begin() + index);
+ this->access->at(index)->destroy();
+ this->access->erase(this->access->begin() + index);
}
/** Erase an entry from the channel access list
@@ -549,14 +632,14 @@ void ChannelInfo::EraseAccess(unsigned index)
*
* Clears the memory used by the given access entry and removes it from the vector.
*/
-void ChannelInfo::EraseAccess(ChanAccess *taccess)
+void ChannelInfo::EraseAccess(const ChanAccess *taccess)
{
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
+ for (unsigned i = 0, end = this->access->size(); i < end; ++i)
{
- if (this->access[i] == taccess)
+ if (this->GetAccess(i) == taccess)
{
- delete this->access[i];
- this->access.erase(this->access.begin() + i);
+ this->GetAccess(i)->destroy();
+ this->EraseAccess(i);
break;
}
}
@@ -568,9 +651,9 @@ void ChannelInfo::EraseAccess(ChanAccess *taccess)
*/
void ChannelInfo::ClearAccess()
{
- for (unsigned i = this->access.size(); i > 0; --i)
- delete this->access[i - 1];
- this->access.clear();
+ for (unsigned i = this->access->size(); i > 0; --i)
+ this->GetAccess(i - 1)->destroy();
+ this->access->clear();
}
/** Add an akick entry to the channel by NickCore
@@ -583,9 +666,6 @@ void ChannelInfo::ClearAccess()
*/
AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu)
{
- if (!akicknc)
- return NULL;
-
AutoKick *autokick = new AutoKick();
autokick->ci = this;
autokick->SetFlag(AK_ISNICK);
@@ -595,7 +675,7 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, co
autokick->addtime = t;
autokick->last_used = lu;
- this->akick.push_back(autokick);
+ this->akick->push_back(autokick);
return autokick;
}
@@ -619,7 +699,7 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &
autokick->addtime = t;
autokick->last_used = lu;
- this->akick.push_back(autokick);
+ this->akick->push_back(autokick);
return autokick;
}
@@ -628,12 +708,14 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &
* @param index The index in the akick vector
* @return The akick structure, or NULL if not found
*/
-AutoKick *ChannelInfo::GetAkick(unsigned index)
+AutoKick *ChannelInfo::GetAkick(unsigned index) const
{
- if (this->akick.empty() || index >= this->akick.size())
+ if (this->akick->empty() || index >= this->akick->size())
return NULL;
- return this->akick[index];
+ AutoKick *ak = (*this->akick)[index];
+ ak->QueueUpdate();
+ return ak;
}
/** Get the size of the akick vector for this channel
@@ -641,7 +723,7 @@ AutoKick *ChannelInfo::GetAkick(unsigned index)
*/
unsigned ChannelInfo::GetAkickCount() const
{
- return this->akick.empty() ? 0 : this->akick.size();
+ return this->akick->size();
}
/** Erase an entry from the channel akick list
@@ -649,18 +731,18 @@ unsigned ChannelInfo::GetAkickCount() const
*/
void ChannelInfo::EraseAkick(unsigned index)
{
- if (this->akick.empty() || index >= this->akick.size())
+ if (this->akick->empty() || index >= this->akick->size())
return;
- delete this->akick[index];
- this->akick.erase(this->akick.begin() + index);
+ this->GetAkick(index)->destroy();
+ this->akick->erase(this->akick->begin() + index);
}
/** Clear the whole akick list
*/
void ChannelInfo::ClearAkick()
{
- while (!this->akick.empty())
+ while (!this->akick->empty())
EraseAkick(0);
}
@@ -669,14 +751,14 @@ void ChannelInfo::ClearAkick()
* @param type The type (SINGLE START END)
* @return The badword
*/
-BadWord *ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
+BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
{
- BadWord *bw = new BadWord;
+ BadWord *bw = new BadWord();
bw->ci = this;
bw->word = word;
bw->type = type;
- this->badwords.push_back(bw);
+ this->badwords->push_back(bw);
FOREACH_MOD(I_OnBadWordAdd, OnBadWordAdd(this, bw));
@@ -687,12 +769,14 @@ BadWord *ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
* @param index The index
* @return The badword
*/
-BadWord *ChannelInfo::GetBadWord(unsigned index)
+BadWord* ChannelInfo::GetBadWord(unsigned index) const
{
- if (this->badwords.empty() || index >= this->badwords.size())
+ if (this->badwords->empty() || index >= this->badwords->size())
return NULL;
- return this->badwords[index];
+ BadWord *bw = (*this->badwords)[index];
+ bw->QueueUpdate();
+ return bw;
}
/** Get how many badwords are on this channel
@@ -700,7 +784,7 @@ BadWord *ChannelInfo::GetBadWord(unsigned index)
*/
unsigned ChannelInfo::GetBadWordCount() const
{
- return this->badwords.empty() ? 0 : this->badwords.size();
+ return this->badwords->size();
}
/** Remove a badword
@@ -708,20 +792,20 @@ unsigned ChannelInfo::GetBadWordCount() const
*/
void ChannelInfo::EraseBadWord(unsigned index)
{
- if (this->badwords.empty() || index >= this->badwords.size())
+ if (this->badwords->empty() || index >= this->badwords->size())
return;
- FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, this->badwords[index]));
+ FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, (*this->badwords)[index]));
- delete this->badwords[index];
- this->badwords.erase(this->badwords.begin() + index);
+ delete (*this->badwords)[index];
+ this->badwords->erase(this->badwords->begin() + index);
}
/** Clear all badwords from the channel
*/
void ChannelInfo::ClearBadWords()
{
- while (!this->badwords.empty())
+ while (!this->badwords->empty())
EraseBadWord(0);
}
@@ -732,23 +816,23 @@ void ChannelInfo::ClearBadWords()
*/
bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const
{
- std::multimap<ChannelModeName, ModeLock>::const_iterator it = this->mode_locks.find(mode->Name);
+ std::multimap<ChannelModeName, ModeLock *>::const_iterator it = this->mode_locks->find(mode->Name);
- if (it != this->mode_locks.end())
+ if (it != this->mode_locks->end())
{
if (mode->Type != MODE_REGULAR)
{
- std::multimap<ChannelModeName, ModeLock>::const_iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ std::multimap<ChannelModeName, ModeLock *>::const_iterator it_end = this->mode_locks->upper_bound(mode->Name);
for (; it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- if (ml.param == param)
+ const ModeLock *ml = it->second;
+ if (ml->param == param)
return true;
}
}
else
- return it->second.set == status;
+ return it->second->set == status;
}
return false;
}
@@ -763,36 +847,46 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
{
if (setter.empty())
setter = this->founder ? this->founder->display : "Unknown";
- std::pair<ChannelModeName, ModeLock> ml = std::make_pair(mode->Name, ModeLock(this, status, mode->Name, param, setter, created));
+ std::pair<ChannelModeName, ModeLock *> ml = std::make_pair(mode->Name, new ModeLock(this, status, mode->Name, param, setter, created));
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnMLock, OnMLock(this, &ml.second));
+ FOREACH_RESULT(I_OnMLock, OnMLock(this, ml.second));
if (MOD_RESULT == EVENT_STOP)
return false;
/* First, remove this */
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
- this->mode_locks.erase(mode->Name);
+ {
+ ChannelInfo::ModeList::const_iterator it = this->mode_locks->find(mode->Name);
+ if (it != this->mode_locks->end())
+ {
+ ChannelInfo::ModeList::const_iterator it_end = this->mode_locks->upper_bound(mode->Name);
+ for (; it != it_end; ++it)
+ it->second->destroy();
+ }
+ this->mode_locks->erase(mode->Name);
+ }
else
{
// For list or status modes, we must check the parameter
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name);
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name);
+ if (it != this->mode_locks->end())
{
- std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mode->Name);
for (; it != it_end; ++it)
{
- const ModeLock &modelock = it->second;
- if (modelock.param == param)
+ const ModeLock *modelock = it->second;
+ if (modelock->param == param)
{
- this->mode_locks.erase(it);
+ it->second->destroy();
+ this->mode_locks->erase(it);
break;
}
}
}
}
- this->mode_locks.insert(ml);
+ this->mode_locks->insert(ml);
return true;
}
@@ -807,21 +901,22 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
{
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
{
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name), it_end = this->mode_locks.upper_bound(mode->Name), it_next = it;
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name), it_end = this->mode_locks->upper_bound(mode->Name), it_next = it;
+ if (it != this->mode_locks->end())
for (; it != it_end; it = it_next)
{
- const ModeLock &ml = it->second;
+ const ModeLock *ml = it->second;
++it_next;
- if (status != ml.set)
+ if (status != ml->set)
continue;
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, &it->second));
+ FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second));
if (MOD_RESULT != EVENT_STOP)
{
- this->mode_locks.erase(it);
+ it->second->destroy();
+ this->mode_locks->erase(it);
return true;
}
}
@@ -830,20 +925,21 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
else
{
// For list or status modes, we must check the parameter
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name);
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name);
+ if (it != this->mode_locks->end())
{
- std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mode->Name);
for (; it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- if (ml.set == status && ml.param == param)
+ const ModeLock *ml = it->second;
+ if (ml->set == status && ml->param == param)
{
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, &it->second));
+ FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second));
if (MOD_RESULT == EVENT_STOP)
return false;
- this->mode_locks.erase(it);
+ it->second->destroy();
+ this->mode_locks->erase(it);
return true;
}
}
@@ -857,13 +953,13 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
*/
void ChannelInfo::ClearMLock()
{
- this->mode_locks.clear();
+ this->mode_locks->clear();
}
/** Get all of the mlocks for this channel
* @return The mlocks
*/
-const std::multimap<ChannelModeName, ModeLock> &ChannelInfo::GetMLock() const
+const ChannelInfo::ModeList &ChannelInfo::GetMLock() const
{
return this->mode_locks;
}
@@ -874,9 +970,9 @@ const std::multimap<ChannelModeName, ModeLock> &ChannelInfo::GetMLock() const
*/
std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> ChannelInfo::GetModeList(ChannelModeName Name)
{
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(Name), it_end = it;
- if (it != this->mode_locks.end())
- it_end = this->mode_locks.upper_bound(Name);
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(Name), it_end = it;
+ if (it != this->mode_locks->end())
+ it_end = this->mode_locks->upper_bound(Name);
return std::make_pair(it, it_end);
}
@@ -885,20 +981,20 @@ std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> Chan
* @param param An optional param to match with
* @return The MLock, if any
*/
-ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string &param)
+const ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string &param)
{
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mname);
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname);
+ if (it != this->mode_locks->end())
{
if (param.empty())
- return &it->second;
+ return it->second;
else
{
- std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mname);
+ ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mname);
for (; it != it_end; ++it)
{
- if (Anope::Match(param, it->second.param))
- return &it->second;
+ if (Anope::Match(param, it->second->param))
+ return it->second;
}
}
}
@@ -910,20 +1006,20 @@ Anope::string ChannelInfo::GetMLockAsString(bool complete) const
{
Anope::string pos = "+", neg = "-", params;
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = this->GetMLock().begin(), it_end = this->GetMLock().end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::const_iterator it = this->GetMLock().begin(), it_end = this->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_LIST || cm->Type == MODE_STATUS)
continue;
- if (ml.set)
+ if (ml->set)
pos += cm->ModeChar;
else
neg += cm->ModeChar;
- if (complete && !ml.param.empty() && cm->Type == MODE_PARAM)
- params += " " + ml.param;
+ if (complete && !ml->param.empty() && cm->Type == MODE_PARAM)
+ params += " " + ml->param;
}
if (pos.length() == 1)
@@ -1077,7 +1173,7 @@ void ChannelInfo::RestoreTopic()
}
}
-int16_t ChannelInfo::GetLevel(const Anope::string &priv)
+int16_t ChannelInfo::GetLevel(const Anope::string &priv) const
{
if (PrivilegeManager::FindPrivilege(priv) == NULL)
{
@@ -1085,9 +1181,10 @@ int16_t ChannelInfo::GetLevel(const Anope::string &priv)
return ACCESS_INVALID;
}
- if (this->levels.count(priv) == 0)
- this->levels[priv] = 0;
- return this->levels[priv];
+ std::map<Anope::string, int16_t>::const_iterator it = this->levels.find(priv);
+ if (it == this->levels.end())
+ return 0;
+ return it->second;
}
void ChannelInfo::SetLevel(const Anope::string &priv, int16_t level)
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 3f8df0434..9ff3fca1d 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -13,16 +13,17 @@
#include "services.h"
#include "anope.h"
#include "serialize.h"
+#include "modules.h"
std::vector<Anope::string> SerializeType::type_order;
Anope::map<SerializeType *> SerializeType::types;
-std::list<Serializable *> *Serializable::serizliable_items;
+std::list<Serializable *> *Serializable::serializable_items;
-stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), key(false), _max(0)
+stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0)
{
}
-stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), key(false), _max(0)
+stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), _max(0)
{
}
@@ -37,26 +38,25 @@ std::istream &stringstream::operator>>(Anope::string &val)
return *this;
}
-stringstream &stringstream::setType(Serialize::DataType t)
+bool stringstream::operator==(const stringstream &other) const
{
- this->type = t;
- return *this;
+ return this->astr() == other.astr();
}
-Serialize::DataType stringstream::getType() const
+bool stringstream::operator!=(const stringstream &other) const
{
- return this->type;
+ return !(*this == other);
}
-stringstream &stringstream::setKey()
+stringstream &stringstream::setType(Serialize::DataType t)
{
- this->key = true;
+ this->type = t;
return *this;
}
-bool stringstream::getKey() const
+Serialize::DataType stringstream::getType() const
{
- return this->key;
+ return this->type;
}
stringstream &stringstream::setMax(unsigned m)
@@ -70,25 +70,30 @@ unsigned stringstream::getMax() const
return this->_max;
}
-Serializable::Serializable()
+Serializable::Serializable() : id(0)
{
- if (serizliable_items == NULL)
- serizliable_items = new std::list<Serializable *>();
- serizliable_items->push_back(this);
- this->s_iter = serizliable_items->end();
+ if (serializable_items == NULL)
+ serializable_items = new std::list<Serializable *>();
+ serializable_items->push_back(this);
+
+ this->s_iter = serializable_items->end();
--this->s_iter;
+
+ FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
-Serializable::Serializable(const Serializable &)
+Serializable::Serializable(const Serializable &) : id(0)
{
- serizliable_items->push_back(this);
- this->s_iter = serizliable_items->end();
+ serializable_items->push_back(this);
+ this->s_iter = serializable_items->end();
--this->s_iter;
+
+ FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
Serializable::~Serializable()
{
- serizliable_items->erase(this->s_iter);
+ serializable_items->erase(this->s_iter);
}
Serializable &Serializable::operator=(const Serializable &)
@@ -96,12 +101,37 @@ Serializable &Serializable::operator=(const Serializable &)
return *this;
}
+void Serializable::destroy()
+{
+ if (!this)
+ return;
+
+ FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this));
+
+ delete this;
+}
+
+void Serializable::QueueUpdate()
+{
+ FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this));
+}
+
+bool Serializable::IsCached()
+{
+ return this->last_commit == this->serialize();
+}
+
+void Serializable::UpdateCache()
+{
+ this->last_commit = this->serialize();
+}
+
const std::list<Serializable *> &Serializable::GetItems()
{
- return *serizliable_items;
+ return *serializable_items;
}
-SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f)
+SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f), timestamp(0)
{
type_order.push_back(this->name);
types[this->name] = this;
@@ -120,9 +150,24 @@ const Anope::string &SerializeType::GetName()
return this->name;
}
-void SerializeType::Create(Serializable::serialized_data &data)
+Serializable *SerializeType::Unserialize(Serializable *obj, Serialize::Data &data)
+{
+ return this->unserialize(obj, data);
+}
+
+void SerializeType::Check()
+{
+ FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this));
+}
+
+time_t SerializeType::GetTimestamp() const
+{
+ return this->timestamp;
+}
+
+void SerializeType::UpdateTimestamp()
{
- this->unserialize(data);
+ this->timestamp = Anope::CurTime;
}
SerializeType *SerializeType::Find(const Anope::string &name)
diff --git a/src/servers.cpp b/src/servers.cpp
index 6ccd4c403..416b35723 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -49,7 +49,7 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A
if (Me == this->UplinkServer && !this->HasFlag(SERVER_JUPED))
{
/* Now do mode related stuff as we know what modes exist .. */
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : ircd->pseudoclient_mode;
@@ -276,7 +276,7 @@ void Server::Sync(bool SyncLinks)
if (this->GetUplink() && this->GetUplink() == Me)
{
- for (registered_channel_map::iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
if (ci->HasFlag(CI_PERSIST))
@@ -353,7 +353,7 @@ bool Server::IsULined() const
* @param source The source of the message
* @param message The message
*/
-void Server::Notice(BotInfo *source, const Anope::string &message)
+void Server::Notice(const BotInfo *source, const Anope::string &message)
{
if (Config->NSDefFlags.HasFlag(NI_MSG))
ircdproto->SendGlobalPrivmsg(source, this, message);
diff --git a/src/users.cpp b/src/users.cpp
index aa69f27c7..bbe26a11a 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -41,7 +41,6 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
/* we used to do this by calloc, no more. */
server = NULL;
- nc = NULL;
invalid_pw_count = invalid_pw_time = lastmemosend = lastnickreg = lastmail = 0;
OnAccess = false;
timestamp = my_signon = Anope::CurTime;
@@ -81,7 +80,7 @@ void User::SetNewNick(const Anope::string &newnick)
UserListByNick[this->nick] = this;
OnAccess = false;
- NickAlias *na = findnick(this->nick);
+ const NickAlias *na = findnick(this->nick);
if (na)
OnAccess = is_on_access(this, na->nc);
}
@@ -225,7 +224,7 @@ User::~User()
Log(LOG_DEBUG_2) << "User::~User() done";
}
-void User::SendMessage(BotInfo *source, const char *fmt, ...)
+void User::SendMessage(const BotInfo *source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -240,7 +239,7 @@ void User::SendMessage(BotInfo *source, const char *fmt, ...)
va_end(args);
}
-void User::SendMessage(BotInfo *source, Anope::string msg)
+void User::SendMessage(const BotInfo *source, Anope::string msg)
{
const char *translated_message = translate(this, msg.c_str());
@@ -318,7 +317,7 @@ void User::SendMessage(BotInfo *source, Anope::string msg)
*/
void User::Collide(NickAlias *na)
{
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
if (!bi)
return;
if (na)
@@ -372,15 +371,15 @@ void User::Identify(NickAlias *na)
this->Login(na->nc);
ircdproto->SendLogin(this);
- NickAlias *this_na = findnick(this->nick);
- if (!Config->NoNicknameOwnership && this_na && this_na->nc == na->nc && na->nc->HasFlag(NI_UNCONFIRMED) == false)
+ const NickAlias *this_na = findnick(this->nick);
+ if (!Config->NoNicknameOwnership && this_na && this_na->nc == *na->nc && na->nc->HasFlag(NI_UNCONFIRMED) == false)
this->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(this));
if (this->IsServicesOper())
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (!this->nc->o->ot->modes.empty())
{
this->SetModes(bi, "%s", this->nc->o->ot->modes.c_str());
@@ -427,7 +426,7 @@ void User::Logout()
/** Get the account the user is logged in using
* @reurn The account or NULL
*/
-NickCore *User::Account()
+NickCore *User::Account() const
{
return this->nc;
}
@@ -436,13 +435,13 @@ NickCore *User::Account()
* @param CheckNick True to check if the user is identified to the nickname they are on too
* @return true or false
*/
-bool User::IsIdentified(bool CheckNick)
+bool User::IsIdentified(bool CheckNick) const
{
if (CheckNick && this->nc)
{
NickAlias *na = findnick(this->nc->display);
- if (na && na->nc == this->nc)
+ if (na && *na->nc == *this->nc)
return true;
return false;
@@ -455,11 +454,11 @@ bool User::IsIdentified(bool CheckNick)
* @param CheckSecure Only returns true if the user has secure off
* @return true or false
*/
-bool User::IsRecognized(bool CheckSecure)
+bool User::IsRecognized(bool CheckSecure) const
{
if (CheckSecure && OnAccess)
{
- NickAlias *na = findnick(this->nick);
+ const NickAlias *na = findnick(this->nick);
if (!na || na->nc->HasFlag(NI_SECURE))
return false;
@@ -589,7 +588,7 @@ void User::RemoveModeInternal(UserMode *um)
* @param um The user mode
* @param Param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param)
+void User::SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param)
{
if (!um || HasMode(um->Name))
return;
@@ -603,7 +602,7 @@ void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param)
* @param Name The mode name
* @param param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param)
+void User::SetMode(const BotInfo *bi, UserModeName Name, const Anope::string &Param)
{
SetMode(bi, ModeManager::FindUserModeByName(Name), Param);
}
@@ -612,7 +611,7 @@ void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param)
* @param bi The client setting the mode
* @param um The user mode
*/
-void User::RemoveMode(BotInfo *bi, UserMode *um)
+void User::RemoveMode(const BotInfo *bi, UserMode *um)
{
if (!um || !HasMode(um->Name))
return;
@@ -625,7 +624,7 @@ void User::RemoveMode(BotInfo *bi, UserMode *um)
* @param bi The client setting the mode
* @param Name The mode name
*/
-void User::RemoveMode(BotInfo *bi, UserModeName Name)
+void User::RemoveMode(const BotInfo *bi, UserModeName Name)
{
RemoveMode(bi, ModeManager::FindUserModeByName(Name));
}
@@ -634,7 +633,7 @@ void User::RemoveMode(BotInfo *bi, UserModeName Name)
* @param bi The client setting the mode
* @param umodes The modes
*/
-void User::SetModes(BotInfo *bi, const char *umodes, ...)
+void User::SetModes(const BotInfo *bi, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
@@ -761,7 +760,7 @@ Anope::string User::GetModes() const
* @param c The channel
* @return The channel container, or NULL
*/
-ChannelContainer *User::FindChannel(const Channel *c)
+ChannelContainer *User::FindChannel(const Channel *c) const
{
for (UChannelList::const_iterator it = this->chans.begin(), it_end = this->chans.end(); it != it_end; ++it)
if ((*it)->chan == c)