mirror of
https://github.com/anope/anope.git
synced 2026-07-04 23:33:12 +02:00
Remove channels from accesss lists when they expire/drop
This commit is contained in:
@@ -47,6 +47,8 @@ class CoreExport AutoKick : public Serializable
|
||||
*/
|
||||
class CoreExport ChannelInfo : public Serializable, public Extensible
|
||||
{
|
||||
/* channels who reference this one */
|
||||
Anope::map<int> references;
|
||||
private:
|
||||
Serialize::Reference<NickCore> founder; /* Channel founder */
|
||||
Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */
|
||||
@@ -230,6 +232,10 @@ class CoreExport ChannelInfo : public Serializable, public Extensible
|
||||
* @return the ChannelInfo associated with the channel
|
||||
*/
|
||||
static ChannelInfo* Find(const Anope::string &name);
|
||||
|
||||
void AddChannelReference(const Anope::string &what);
|
||||
void RemoveChannelReference(const Anope::string &what);
|
||||
void GetChannelReferences(std::deque<Anope::string> &chans);
|
||||
};
|
||||
|
||||
/** Is the user the real founder?
|
||||
|
||||
@@ -199,6 +199,32 @@ class ChanServCore : public Module, public ChanServService
|
||||
}
|
||||
}
|
||||
|
||||
void OnDelChan(ChannelInfo *ci) anope_override
|
||||
{
|
||||
/* remove access entries that are this channel */
|
||||
|
||||
std::deque<Anope::string> chans;
|
||||
ci->GetChannelReferences(chans);
|
||||
|
||||
for (unsigned i = 0; i < chans.size(); ++i)
|
||||
{
|
||||
ChannelInfo *c = ChannelInfo::Find(chans[i]);
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
for (unsigned j = 0; j < c->GetAccessCount(); ++j)
|
||||
{
|
||||
ChanAccess *a = c->GetAccess(j);
|
||||
|
||||
if (a->mask.equals_ci(ci->name))
|
||||
{
|
||||
delete a;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
|
||||
{
|
||||
if (!params.empty() || source.c || source.service != *ChanServ)
|
||||
|
||||
@@ -154,6 +154,12 @@ ChanAccess::~ChanAccess()
|
||||
const NickAlias *na = NickAlias::Find(this->mask);
|
||||
if (na != NULL)
|
||||
na->nc->RemoveChannelReference(this->ci);
|
||||
else
|
||||
{
|
||||
ChannelInfo *c = ChannelInfo::Find(this->mask);
|
||||
if (c)
|
||||
c->RemoveChannelReference(this->ci->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -401,6 +401,12 @@ void ChannelInfo::AddAccess(ChanAccess *taccess)
|
||||
na->nc->AddChannelReference(this);
|
||||
taccess->nc = na->nc;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChannelInfo *ci = ChannelInfo::Find(taccess->mask);
|
||||
if (ci != NULL)
|
||||
ci->AddChannelReference(this->name);
|
||||
}
|
||||
}
|
||||
|
||||
ChanAccess *ChannelInfo::GetAccess(unsigned index) const
|
||||
@@ -656,3 +662,22 @@ bool IsFounder(const User *user, const ChannelInfo *ci)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ChannelInfo::AddChannelReference(const Anope::string &what)
|
||||
{
|
||||
++references[what];
|
||||
}
|
||||
|
||||
void ChannelInfo::RemoveChannelReference(const Anope::string &what)
|
||||
{
|
||||
int &i = references[what];
|
||||
if (--i <= 0)
|
||||
references.erase(what);
|
||||
}
|
||||
|
||||
void ChannelInfo::GetChannelReferences(std::deque<Anope::string> &chans)
|
||||
{
|
||||
chans.clear();
|
||||
for (Anope::map<int>::iterator it = references.begin(); it != references.end(); ++it)
|
||||
chans.push_back(it->first);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user