1
0
mirror of https://github.com/anope/anope.git synced 2026-07-04 05:33:12 +02:00

Pretty large coding style cleanup, in source doc

cleanup, and allow protocol mods to depend on each
other
This commit is contained in:
Adam
2012-11-22 00:50:33 -05:00
parent 368d469631
commit d33a0f75a5
303 changed files with 7880 additions and 9388 deletions
+165 -223
View File
@@ -7,6 +7,7 @@
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
*/
#include "services.h"
@@ -17,26 +18,36 @@
#include "channels.h"
#include "config.h"
#include "bots.h"
#include "extern.h"
#include "language.h"
#include "servers.h"
#include "chanserv.h"
serialize_checker<registered_channel_map> RegisteredChannelList("ChannelInfo");
Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo");
Serialize::Data BadWord::serialize() const
static const Anope::string ChannelInfoFlagStrings[] = {
"BEGIN", "KEEPTOPIC", "SECUREOPS", "PRIVATE", "TOPICLOCK", "RESTRICTED",
"PEACE", "SECURE", "NO_EXPIRE", "MEMO_HARDMAX", "SECUREFOUNDER",
"SIGNKICK", "SIGNKICK_LEVEL", "SUSPENDED", "PERSIST", "STATS", "NOAUTOOP", ""
};
template<> const Anope::string* Flags<ChannelInfoFlag>::flags_strings = ChannelInfoFlagStrings;
static const Anope::string AutoKickFlagString[] = { "AK_ISNICK", "" };
template<> const Anope::string* Flags<AutoKickFlag>::flags_strings = AutoKickFlagString;
Serialize::Data BadWord::Serialize() const
{
Serialize::Data data;
data["ci"].setMax(64)/*XXX*/ << this->ci->name;
data["word"].setMax(512) << this->word;
data["type"].setType(Serialize::DT_INT) << this->type;
data["ci"].SetMax(64)/*XXX*/ << this->ci->name;
data["word"].SetMax(512) << this->word;
data["type"].SetType(Serialize::DT_INT) << this->type;
return data;
}
Serializable* BadWord::unserialize(Serializable *obj, Serialize::Data &data)
Serializable* BadWord::Unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
ChannelInfo *ci = ChannelInfo::Find(data["ci"].astr());
if (!ci)
return NULL;
@@ -56,42 +67,42 @@ Serializable* BadWord::unserialize(Serializable *obj, Serialize::Data &data)
return bw;
}
AutoKick::AutoKick() : Flags<AutoKickFlag>(AutoKickFlagString), Serializable("AutoKick")
AutoKick::AutoKick() : Serializable("AutoKick")
{
}
Serialize::Data AutoKick::serialize() const
Serialize::Data AutoKick::Serialize() const
{
Serialize::Data data;
data["ci"].setMax(64)/*XXX*/ << this->ci->name;
data["ci"].SetMax(64)/*XXX*/ << this->ci->name;
if (this->HasFlag(AK_ISNICK) && this->nc)
data["nc"].setMax(Config->NickLen) << this->nc->display;
data["nc"].SetMax(Config->NickLen) << this->nc->display;
else
data["mask"].setMax(Config->NickLen) << 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;
data["last_used"].setType(Serialize::DT_INT) << this->last_used;
data["addtime"].SetType(Serialize::DT_INT) << this->addtime;
data["last_used"].SetType(Serialize::DT_INT) << this->last_used;
data["flags"] << this->ToString();
return data;
}
Serializable* AutoKick::unserialize(Serializable *obj, Serialize::Data &data)
Serializable* AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
ChannelInfo *ci = ChannelInfo::Find(data["ci"].astr());
if (!ci)
return NULL;
AutoKick *ak;
NickCore *nc = findcore(data["nc"].astr());
NickCore *nc = NickCore::Find(data["nc"].astr());
if (obj)
{
ak = anope_dynamic_static_cast<AutoKick *>(obj);
data["creator"] >> ak->creator;
data["reason"] >> ak->reason;
ak->nc = findcore(data["nc"].astr());
ak->nc = NickCore::Find(data["nc"].astr());
data["mask"] >> ak->mask;
data["addtime"] >> ak->addtime;
data["last_used"] >> ak->last_used;
@@ -115,31 +126,33 @@ ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::stri
{
}
Serialize::Data ModeLock::serialize() const
Serialize::Data ModeLock::Serialize() const
{
Serialize::Data data;
if (!this->ci)
return data;
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;
const Anope::string* ChannelModeNameStrings = Flags<ChannelModeName>::GetFlagStrings();
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;
data["created"].SetType(Serialize::DT_INT) << this->created;
return data;
}
Serializable* ModeLock::unserialize(Serializable *obj, Serialize::Data &data)
Serializable* ModeLock::Unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
ChannelInfo *ci = ChannelInfo::Find(data["ci"].astr());
if (!ci)
return NULL;
ChannelModeName name = CMODE_END;
const Anope::string* ChannelModeNameStrings = Flags<ChannelModeName>::GetFlagStrings();
for (unsigned i = 0; !ChannelModeNameStrings[i].empty(); ++i)
if (ChannelModeNameStrings[i] == data["name"].astr())
{
@@ -177,7 +190,7 @@ Serializable* ModeLock::unserialize(Serializable *obj, Serialize::Data &data)
}
}
Serialize::Data LogSetting::serialize() const
Serialize::Data LogSetting::Serialize() const
{
Serialize::Data data;
@@ -191,14 +204,14 @@ Serialize::Data LogSetting::serialize() const
data["method"] << method;
data["extra"] << extra;
data["creator"] << creator;
data["created"].setType(Serialize::DT_INT) << created;
data["created"].SetType(Serialize::DT_INT) << created;
return data;
}
Serializable* LogSetting::unserialize(Serializable *obj, Serialize::Data &data)
Serializable* LogSetting::Unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
ChannelInfo *ci = ChannelInfo::Find(data["ci"].astr());
if (ci == NULL)
return NULL;
@@ -223,19 +236,16 @@ Serializable* LogSetting::unserialize(Serializable *obj, Serialize::Data &data)
return ls;
}
/** Default constructor
* @param chname The channel name
*/
ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInfo"), Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings),
ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInfo"),
access("ChanAccess"), akick("AutoKick"),
badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings)
badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting")
{
if (chname.empty())
throw CoreException("Empty channel passed to ChannelInfo constructor");
this->founder = NULL;
this->successor = NULL;
this->c = findchan(chname);
this->c = Channel::Find(chname);
if (this->c)
this->c->ci = this;
this->capsmin = this->capspercent = 0;
@@ -274,12 +284,9 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf
FOREACH_MOD(I_OnCreateChan, OnCreateChan(this));
}
/** Copy constructor
* @param ci The ChannelInfo to copy settings to
*/
ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings),
ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"),
access("ChanAccess"), akick("AutoKick"),
badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings)
badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting")
{
*this = ci;
@@ -304,7 +311,7 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), F
newaccess->creator = taccess->creator;
newaccess->last_seen = taccess->last_seen;
newaccess->created = taccess->created;
newaccess->Unserialize(taccess->Serialize());
newaccess->AccessUnserialize(taccess->AccessSerialize());
this->AddAccess(newaccess);
}
@@ -331,8 +338,6 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), F
}
}
/** Default destructor, cleans up the channel complete and removes it from the internal list
*/
ChannelInfo::~ChannelInfo()
{
FOREACH_MOD(I_OnDelChan, OnDelChan(this));
@@ -353,17 +358,17 @@ ChannelInfo::~ChannelInfo()
this->ClearBadWords();
for (unsigned i = 0; i < this->log_settings->size(); ++i)
this->log_settings->at(i)->destroy();
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();
it->second->Destroy();
this->mode_locks->clear();
if (!this->memos.memos->empty())
{
for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i)
this->memos.GetMemo(i)->destroy();
this->memos.GetMemo(i)->Destroy();
this->memos.memos->clear();
}
@@ -371,22 +376,22 @@ ChannelInfo::~ChannelInfo()
--this->founder->channelcount;
}
Serialize::Data ChannelInfo::serialize() const
Serialize::Data ChannelInfo::Serialize() const
{
Serialize::Data data;
data["name"].setMax(255) << this->name;
data["name"].SetMax(255) << this->name;
if (this->founder)
data["founder"] << this->founder->display;
if (this->successor)
data["successor"] << this->successor->display;
data["description"] << this->desc;
data["time_registered"].setType(Serialize::DT_INT) << this->time_registered;
data["last_used"].setType(Serialize::DT_INT) << this->last_used;
data["time_registered"].SetType(Serialize::DT_INT) << this->time_registered;
data["last_used"].SetType(Serialize::DT_INT) << this->last_used;
data["last_topic"] << this->last_topic;
data["last_topic_setter"] << this->last_topic_setter;
data["last_topic_time"].setType(Serialize::DT_INT) << this->last_topic_time;
data["bantype"].setType(Serialize::DT_INT) << this->bantype;
data["last_topic_time"].SetType(Serialize::DT_INT) << this->last_topic_time;
data["bantype"].SetType(Serialize::DT_INT) << this->bantype;
data["flags"] << this->ToString();
data["botflags"] << this->botflags.ToString();
{
@@ -399,11 +404,11 @@ Serialize::Data ChannelInfo::serialize() const
data["bi"] << this->bi->nick;
for (int i = 0; i < TTB_SIZE; ++i)
data["ttb"] << this->ttb[i] << " ";
data["capsmin"].setType(Serialize::DT_INT) << this->capsmin;
data["capspercent"].setType(Serialize::DT_INT) << this->capspercent;
data["floodlines"].setType(Serialize::DT_INT) << this->floodlines;
data["floodsecs"].setType(Serialize::DT_INT) << this->floodsecs;
data["repeattimes"].setType(Serialize::DT_INT) << this->repeattimes;
data["capsmin"].SetType(Serialize::DT_INT) << this->capsmin;
data["capspercent"].SetType(Serialize::DT_INT) << this->capspercent;
data["floodlines"].SetType(Serialize::DT_INT) << this->floodlines;
data["floodsecs"].SetType(Serialize::DT_INT) << this->floodsecs;
data["repeattimes"].SetType(Serialize::DT_INT) << this->repeattimes;
data["memomax"] << this->memos.memomax;
for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
data["memoignores"] << this->memos.ignores[i] << " ";
@@ -411,7 +416,7 @@ Serialize::Data ChannelInfo::serialize() const
return data;
}
Serializable* ChannelInfo::unserialize(Serializable *obj, Serialize::Data &data)
Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci;
if (obj)
@@ -423,13 +428,13 @@ Serializable* ChannelInfo::unserialize(Serializable *obj, Serialize::Data &data)
{
if (ci->founder)
--ci->founder->channelcount;
ci->founder = findcore(data["founder"].astr());
ci->founder = NickCore::Find(data["founder"].astr());
if (ci->founder)
++ci->founder->channelcount;
}
if (data.count("successor") > 0)
{
ci->successor = findcore(data["successor"].astr());
ci->successor = NickCore::Find(data["successor"].astr());
if (ci->founder && *ci->founder == *ci->successor)
ci->successor = NULL;
}
@@ -443,11 +448,12 @@ Serializable* ChannelInfo::unserialize(Serializable *obj, Serialize::Data &data)
ci->FromString(data["flags"].astr());
ci->botflags.FromString(data["botflags"].astr());
{
std::vector<Anope::string> v = BuildStringVector(data["levels"].astr());
std::vector<Anope::string> v;
spacesepstream(data["levels"].astr()).GetTokens(v);
for (unsigned i = 0; i + 1 < v.size(); i += 2)
ci->levels[v[i]] = convertTo<int16_t>(v[i + 1]);
}
BotInfo *bi = findbot(data["bi"].astr());
BotInfo *bi = BotInfo::Find(data["bi"].astr());
if (*ci->bi != bi)
{
if (ci->bi)
@@ -475,9 +481,6 @@ Serializable* ChannelInfo::unserialize(Serializable *obj, Serialize::Data &data)
}
/** Change the founder of the channek
* @params nc The new founder
*/
void ChannelInfo::SetFounder(NickCore *nc)
{
if (this->founder)
@@ -489,44 +492,27 @@ void ChannelInfo::SetFounder(NickCore *nc)
this->successor = NULL;
}
/** Get the founder of the channel
* @return The founder
*/
NickCore *ChannelInfo::GetFounder() const
{
return this->founder;
}
/** Find which bot should send mode/topic/etc changes for this channel
* @return The bot
*/
BotInfo *ChannelInfo::WhoSends() const
{
if (this && this->bi)
return this->bi;
BotInfo *tbi = findbot(Config->ChanServ);
if (tbi)
return tbi;
else if (ChanServ)
return ChanServ;
else if (!BotListByNick->empty())
return BotListByNick->begin()->second;
return NULL;
}
/** Add an entry to the channel access list
* @param taccess The entry
*/
void ChannelInfo::AddAccess(ChanAccess *taccess)
{
this->access->push_back(taccess);
}
/** Get an entry from the channel access list by index
*
* @param index The index in the access list vector
* @return A ChanAccess struct corresponding to the index given, or NULL if outside the bounds
*
* Retrieves an entry from the access list that matches the given index.
*/
ChanAccess *ChannelInfo::GetAccess(unsigned index) const
{
if (this->access->empty() || index >= this->access->size())
@@ -547,13 +533,13 @@ AccessGroup ChannelInfo::AccessFor(const User *u)
const NickCore *nc = u->Account();
if (nc == NULL && u->IsRecognized())
{
const NickAlias *na = findnick(u->nick);
const NickAlias *na = NickAlias::Find(u->nick);
if (na != NULL)
nc = na->nc;
}
group.SuperAdmin = u->SuperAdmin;
group.Founder = IsFounder(u, this);
group.super_admin = u->super_admin;
group.founder = IsFounder(u, this);
group.ci = this;
group.nc = nc;
@@ -561,9 +547,14 @@ AccessGroup ChannelInfo::AccessFor(const User *u)
if (this->GetAccess(i)->Matches(u, nc))
group.push_back(this->GetAccess(i));
if (group.Founder || !group.empty())
if (group.founder || !group.empty())
{
this->last_used = Anope::CurTime;
for (unsigned i = 0; i < group.size(); ++i)
group[i]->last_seen = Anope::CurTime;
}
return group;
}
@@ -571,7 +562,7 @@ AccessGroup ChannelInfo::AccessFor(const NickCore *nc)
{
AccessGroup group;
group.Founder = (this->founder && this->founder == nc);
group.founder = (this->founder && this->founder == nc);
group.ci = this;
group.nc = nc;
@@ -579,41 +570,31 @@ AccessGroup ChannelInfo::AccessFor(const NickCore *nc)
if (this->GetAccess(i)->Matches(NULL, nc))
group.push_back(this->GetAccess(i));
if (group.Founder || !group.empty())
if (group.founder || !group.empty())
{
this->last_used = Anope::CurTime;
for (unsigned i = 0; i < group.size(); ++i)
group[i]->last_seen = Anope::CurTime;
}
return group;
}
/** Get the size of the accss vector for this channel
* @return The access vector size
*/
unsigned ChannelInfo::GetAccessCount() const
{
return this->access->size();
}
/** Erase an entry from the channel access list
*
* @param index The index in the access list vector
*
* Clears the memory used by the given access entry and removes it from the vector.
*/
void ChannelInfo::EraseAccess(unsigned index)
{
if (this->access->empty() || index >= this->access->size())
return;
this->access->at(index)->destroy();
this->access->at(index)->Destroy();
this->access->erase(this->access->begin() + index);
}
/** Erase an entry from the channel access list
*
* @param taccess The access to remove
*
* Clears the memory used by the given access entry and removes it from the vector.
*/
void ChannelInfo::EraseAccess(const ChanAccess *taccess)
{
for (unsigned i = 0, end = this->access->size(); i < end; ++i)
@@ -626,25 +607,13 @@ void ChannelInfo::EraseAccess(const ChanAccess *taccess)
}
}
/** Clear the entire channel access list
*
* Clears the entire access list by deleting every item and then clearing the vector.
*/
void ChannelInfo::ClearAccess()
{
for (unsigned i = this->access->size(); i > 0; --i)
this->GetAccess(i - 1)->destroy();
this->GetAccess(i - 1)->Destroy();
this->access->clear();
}
/** Add an akick entry to the channel by NickCore
* @param user The user who added the akick
* @param akicknc The nickcore being akicked
* @param reason The reason for the akick
* @param t The time the akick was added, defaults to now
* @param lu The time the akick was last used, defaults to never
* @return The AutoKick structure
*/
AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu)
{
AutoKick *autokick = new AutoKick();
@@ -661,14 +630,6 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, co
return autokick;
}
/** Add an akick entry to the channel by reason
* @param user The user who added the akick
* @param mask The mask of the akick
* @param reason The reason for the akick
* @param t The time the akick was added, defaults to now
* @param lu The time the akick was last used, defaults to never
* @return The AutoKick structure
*/
AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu)
{
AutoKick *autokick = new AutoKick();
@@ -685,10 +646,6 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &
return autokick;
}
/** Get an entry from the channel akick list
* @param index The index in the akick vector
* @return The akick structure, or NULL if not found
*/
AutoKick *ChannelInfo::GetAkick(unsigned index) const
{
if (this->akick->empty() || index >= this->akick->size())
@@ -699,39 +656,26 @@ AutoKick *ChannelInfo::GetAkick(unsigned index) const
return ak;
}
/** Get the size of the akick vector for this channel
* @return The akick vector size
*/
unsigned ChannelInfo::GetAkickCount() const
{
return this->akick->size();
}
/** Erase an entry from the channel akick list
* @param index The index of the akick
*/
void ChannelInfo::EraseAkick(unsigned index)
{
if (this->akick->empty() || index >= this->akick->size())
return;
this->GetAkick(index)->destroy();
this->GetAkick(index)->Destroy();
this->akick->erase(this->akick->begin() + index);
}
/** Clear the whole akick list
*/
void ChannelInfo::ClearAkick()
{
while (!this->akick->empty())
EraseAkick(0);
}
/** Add a badword to the badword list
* @param word The badword
* @param type The type (SINGLE START END)
* @return The badword
*/
BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
{
BadWord *bw = new BadWord();
@@ -746,10 +690,6 @@ BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
return bw;
}
/** Get a badword structure by index
* @param index The index
* @return The badword
*/
BadWord* ChannelInfo::GetBadWord(unsigned index) const
{
if (this->badwords->empty() || index >= this->badwords->size())
@@ -760,17 +700,11 @@ BadWord* ChannelInfo::GetBadWord(unsigned index) const
return bw;
}
/** Get how many badwords are on this channel
* @return The number of badwords in the vector
*/
unsigned ChannelInfo::GetBadWordCount() const
{
return this->badwords->size();
}
/** Remove a badword
* @param index The index of the badword
*/
void ChannelInfo::EraseBadWord(unsigned index)
{
if (this->badwords->empty() || index >= this->badwords->size())
@@ -782,28 +716,21 @@ void ChannelInfo::EraseBadWord(unsigned index)
this->badwords->erase(this->badwords->begin() + index);
}
/** Clear all badwords from the channel
*/
void ChannelInfo::ClearBadWords()
{
while (!this->badwords->empty())
EraseBadWord(0);
}
/** Check if a mode is mlocked
* @param mode The mode
* @param status True to check mlock on, false for mlock off
* @return true on success, false on fail
*/
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 (mode->Type != MODE_REGULAR)
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)
{
@@ -818,17 +745,11 @@ bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string &param, bool s
return false;
}
/** Set a mlock
* @param mode The mode
* @param status True for mlock on, false for mlock off
* @param param The param to use for this mode, if required
* @return true on success, false on failure (module blocking)
*/
bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &param, Anope::string setter, time_t created)
{
if (setter.empty())
setter = this->founder ? this->founder->display : "Unknown";
std::pair<ChannelModeName, ModeLock *> ml = std::make_pair(mode->Name, new 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));
@@ -836,30 +757,30 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
return false;
/* First, remove this */
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
if (mode->type == MODE_REGULAR || mode->type == MODE_PARAM)
{
ChannelInfo::ModeList::const_iterator it = this->mode_locks->find(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);
ChannelInfo::ModeList::const_iterator it_end = this->mode_locks->upper_bound(mode->name);
for (; it != it_end; ++it)
it->second->destroy();
it->second->Destroy();
}
this->mode_locks->erase(mode->Name);
this->mode_locks->erase(mode->name);
}
else
{
// For list or status modes, we must check the parameter
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name);
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->name);
if (it != this->mode_locks->end())
{
ChannelInfo::ModeList::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)
{
it->second->destroy();
it->second->Destroy();
this->mode_locks->erase(it);
break;
}
@@ -872,17 +793,11 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
return true;
}
/** Remove a mlock
* @param mode The mode
* @param status True for mlock on, false for mlock off
* @param param The param of the mode, required if it is a list or status mode
* @return true on success, false on failure
*/
bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::string &param)
{
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
if (mode->type == MODE_REGULAR || mode->type == MODE_PARAM)
{
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name), it_end = this->mode_locks->upper_bound(mode->Name), it_next = it;
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)
{
@@ -896,7 +811,7 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second));
if (MOD_RESULT != EVENT_STOP)
{
it->second->destroy();
it->second->Destroy();
this->mode_locks->erase(it);
return true;
}
@@ -906,10 +821,10 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
else
{
// For list or status modes, we must check the parameter
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name);
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->name);
if (it != this->mode_locks->end())
{
ChannelInfo::ModeList::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;
@@ -919,7 +834,7 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second));
if (MOD_RESULT == EVENT_STOP)
return false;
it->second->destroy();
it->second->Destroy();
this->mode_locks->erase(it);
return true;
}
@@ -930,25 +845,16 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
}
}
/** Clear all mlocks on the channel
*/
void ChannelInfo::ClearMLock()
{
this->mode_locks->clear();
}
/** Get all of the mlocks for this channel
* @return The mlocks
*/
const ChannelInfo::ModeList &ChannelInfo::GetMLock() const
{
return this->mode_locks;
}
/** Get a list of modes on a channel
* @param Name The mode name to get a list of
* @return a pair of iterators for the beginning and end of the list
*/
std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> ChannelInfo::GetModeList(ChannelModeName Name)
{
ChannelInfo::ModeList::iterator it = this->mode_locks->find(Name), it_end = it;
@@ -957,11 +863,6 @@ std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> Chan
return std::make_pair(it, it_end);
}
/** Get details for a specific mlock
* @param mname The mode name
* @param param An optional param to match with
* @return The MLock, if any
*/
const ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string &param)
{
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname);
@@ -991,15 +892,15 @@ Anope::string ChannelInfo::GetMLockAsString(bool complete) const
{
const ModeLock *ml = it->second;
ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm || cm->Type == MODE_LIST || cm->Type == MODE_STATUS)
if (!cm || cm->type == MODE_LIST || cm->type == MODE_STATUS)
continue;
if (ml->set)
pos += cm->ModeChar;
pos += cm->mchar;
else
neg += cm->ModeChar;
neg += cm->mchar;
if (complete && !ml->param.empty() && cm->Type == MODE_PARAM)
if (complete && !ml->param.empty() && cm->type == MODE_PARAM)
params += " " + ml->param;
}
@@ -1011,16 +912,12 @@ Anope::string ChannelInfo::GetMLockAsString(bool complete) const
return pos + neg + params;
}
/** Check whether a user is permitted to be on this channel
* @param u The user
* @return true if they were banned, false if they are allowed
*/
bool ChannelInfo::CheckKick(User *user)
{
if (!user || !this->c)
return false;
if (user->SuperAdmin)
if (user->super_admin)
return false;
/* We don't enforce services restrictions on clients on ulined services
@@ -1041,13 +938,13 @@ bool ChannelInfo::CheckKick(User *user)
Anope::string mask, reason;
if (!user->HasMode(UMODE_OPER) && this->HasFlag(CI_SUSPENDED))
{
get_idealban(this, user, mask);
reason = translate(user, _("This channel may not be used."));
mask = this->GetIdealBan(user);
reason = Language::Translate(user, _("This channel may not be used."));
set_modes = true;
do_kick = true;
}
if (!do_kick && matches_list(this->c, user, CMODE_EXCEPT))
if (!do_kick && !this->c->MatchesList(user, CMODE_EXCEPT))
return false;
const NickCore *nc = user->Account() || user->IsRecognized() ? user->Account() : NULL;
@@ -1074,7 +971,7 @@ bool ChannelInfo::CheckKick(User *user)
Log(LOG_DEBUG_2) << user->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask);
autokick->last_used = Anope::CurTime;
if (autokick->HasFlag(AK_ISNICK))
get_idealban(this, user, mask);
mask = this->GetIdealBan(user);
else
mask = autokick->mask;
reason = autokick->reason.empty() ? Config->CSAutokickReason : autokick->reason;
@@ -1086,8 +983,8 @@ bool ChannelInfo::CheckKick(User *user)
if (!do_kick && this->HasFlag(CI_RESTRICTED) && this->AccessFor(user).empty() && (!this->founder || user->Account() != this->founder))
{
do_kick = true;
get_idealban(this, user, mask);
reason = translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN);
mask = this->GetIdealBan(user);
reason = Language::Translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN);
}
if (!do_kick)
@@ -1183,3 +1080,48 @@ void ChannelInfo::ClearLevels()
this->levels.clear();
}
Anope::string ChannelInfo::GetIdealBan(User *u) const
{
switch (this->bantype)
{
case 0:
return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost();
case 1:
if (u->GetVIdent()[0] == '~')
return "*!*" + u->GetVIdent() + "@" + u->GetDisplayedHost();
else
return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost();
case 3:
return "*!" + u->Mask();
case 2:
default:
return "*!*@" + u->GetDisplayedHost();
}
}
ChannelInfo* ChannelInfo::Find(const Anope::string &name)
{
registered_channel_map::const_iterator it = RegisteredChannelList->find(name);
if (it != RegisteredChannelList->end())
{
it->second->QueueUpdate();
return it->second;
}
return NULL;
}
bool IsFounder(const User *user, const ChannelInfo *ci)
{
if (!user || !ci)
return false;
if (user->super_admin)
return true;
if (user->Account() && user->Account() == ci->GetFounder())
return true;
return false;
}