summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp4
-rw-r--r--src/nickcore.cpp24
-rw-r--r--src/regchannel.cpp45
3 files changed, 61 insertions, 12 deletions
diff --git a/src/access.cpp b/src/access.cpp
index fdaada75b..dd5881108 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -102,6 +102,10 @@ ChanAccess::~ChanAccess()
std::vector<ChanAccess *>::iterator it = std::find(this->ci->access->begin(), this->ci->access->end(), this);
if (it != this->ci->access->end())
this->ci->access->erase(it);
+
+ const NickAlias *na = NickAlias::Find(this->mask);
+ if (na != NULL)
+ na->nc->RemoveChannelReference(this->ci);
}
}
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 7dda6da5c..f92d4739c 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -17,7 +17,7 @@
Serialize::Checker<nickcore_map> NickCoreList("NickCore");
-NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), aliases("NickAlias")
+NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias")
{
if (coredisplay.empty())
throw CoreException("Empty display passed to NickCore constructor");
@@ -44,6 +44,9 @@ NickCore::~NickCore()
{
FOREACH_MOD(I_OnDelCore, OnDelCore(this));
+ if (!this->chanaccess->empty())
+ Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!";
+
for (std::list<User *>::iterator it = this->users.begin(); it != this->users.end();)
{
User *user = *it++;
@@ -253,6 +256,25 @@ void NickCore::ClearCert()
this->cert.clear();
}
+void NickCore::AddChannelReference(ChannelInfo *ci)
+{
+ ++(*this->chanaccess)[ci];
+}
+
+void NickCore::RemoveChannelReference(ChannelInfo *ci)
+{
+ int& i = (*this->chanaccess)[ci];
+ if (--i <= 0)
+ this->chanaccess->erase(ci);
+}
+
+void NickCore::GetChannelReferences(std::deque<ChannelInfo *> &queue)
+{
+ queue.clear();
+ for (std::map<ChannelInfo *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it)
+ queue.push_back(it->first);
+}
+
NickCore* NickCore::Find(const Anope::string &nick)
{
nickcore_map::const_iterator it = NickCoreList->find(nick);
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 257eca0ee..2a82590e2 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -82,6 +82,10 @@ AutoKick::~AutoKick()
std::vector<AutoKick *>::iterator it = std::find(this->ci->akick->begin(), this->ci->akick->end(), this);
if (it != this->ci->akick->end())
this->ci->akick->erase(it);
+
+ const NickAlias *na = NickAlias::Find(this->mask);
+ if (na != NULL)
+ na->nc->RemoveChannelReference(this->ci);
}
}
@@ -444,16 +448,9 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
ci->ExtensibleUnserialize(data);
- if (ci->founder)
- --ci->founder->channelcount;
- ci->founder = NickCore::Find(sfounder);
- if (ci->founder)
- ++ci->founder->channelcount;
+ ci->SetFounder(NickCore::Find(sfounder));
+ ci->SetSuccessor(NickCore::Find(ssuccessor));
- ci->successor = NickCore::Find(ssuccessor);
- if (ci->founder && *ci->founder == *ci->successor)
- ci->successor = NULL;
-
data["description"] >> ci->desc;
data["time_registered"] >> ci->time_registered;
data["last_used"] >> ci->last_used;
@@ -511,12 +508,18 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
void ChannelInfo::SetFounder(NickCore *nc)
{
if (this->founder)
+ {
--this->founder->channelcount;
+ this->founder->RemoveChannelReference(this);
+ }
+
this->founder = nc;
+
if (this->founder)
+ {
++this->founder->channelcount;
- if (*this->founder == *this->successor)
- this->successor = NULL;
+ this->founder->AddChannelReference(this);
+ }
}
NickCore *ChannelInfo::GetFounder() const
@@ -524,6 +527,20 @@ NickCore *ChannelInfo::GetFounder() const
return this->founder;
}
+void ChannelInfo::SetSuccessor(NickCore *nc)
+{
+ if (this->successor)
+ this->successor->RemoveChannelReference(this);
+ this->successor = nc;
+ if (this->successor)
+ this->successor->AddChannelReference(this);
+}
+
+NickCore *ChannelInfo::GetSuccessor() const
+{
+ return this->successor;
+}
+
BotInfo *ChannelInfo::WhoSends() const
{
if (this && this->bi)
@@ -538,6 +555,10 @@ BotInfo *ChannelInfo::WhoSends() const
void ChannelInfo::AddAccess(ChanAccess *taccess)
{
this->access->push_back(taccess);
+
+ const NickAlias *na = NickAlias::Find(taccess->mask);
+ if (na != NULL)
+ na->nc->AddChannelReference(this);
}
ChanAccess *ChannelInfo::GetAccess(unsigned index) const
@@ -639,6 +660,8 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, co
this->akick->push_back(autokick);
+ akicknc->AddChannelReference(this);
+
return autokick;
}