summaryrefslogtreecommitdiff
path: root/modules/commands/cs_access.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands/cs_access.cpp')
-rw-r--r--modules/commands/cs_access.cpp90
1 files changed, 47 insertions, 43 deletions
diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp
index cab343057..7a37c5434 100644
--- a/modules/commands/cs_access.cpp
+++ b/modules/commands/cs_access.cpp
@@ -16,30 +16,30 @@ static std::map<Anope::string, int16_t, ci::less> defaultLevels;
static inline void reset_levels(ChannelInfo *ci)
{
ci->ClearLevels();
- for (std::map<Anope::string, int16_t, ci::less>::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it)
- ci->SetLevel(it->first, it->second);
+ for (auto &[priv, level] : defaultLevels)
+ ci->SetLevel(priv, level);
}
class AccessChanAccess : public ChanAccess
{
public:
- int level;
+ int level = 0;
- AccessChanAccess(AccessProvider *p) : ChanAccess(p), level(0)
+ AccessChanAccess(AccessProvider *p) : ChanAccess(p)
{
}
- bool HasPriv(const Anope::string &name) const anope_override
+ bool HasPriv(const Anope::string &name) const override
{
return this->ci->GetLevel(name) != ACCESS_INVALID && this->level >= this->ci->GetLevel(name);
}
- Anope::string AccessSerialize() const anope_override
+ Anope::string AccessSerialize() const override
{
return stringify(this->level);
}
- void AccessUnserialize(const Anope::string &data) anope_override
+ void AccessUnserialize(const Anope::string &data) override
{
try
{
@@ -50,7 +50,7 @@ class AccessChanAccess : public ChanAccess
}
}
- bool operator>(const ChanAccess &other) const anope_override
+ bool operator>(const ChanAccess &other) const override
{
if (this->provider != other.provider)
return ChanAccess::operator>(other);
@@ -58,7 +58,7 @@ class AccessChanAccess : public ChanAccess
return this->level > anope_dynamic_static_cast<const AccessChanAccess *>(&other)->level;
}
- bool operator<(const ChanAccess &other) const anope_override
+ bool operator<(const ChanAccess &other) const override
{
if (this->provider != other.provider)
return ChanAccess::operator<(other);
@@ -77,7 +77,7 @@ class AccessAccessProvider : public AccessProvider
me = this;
}
- ChanAccess *Create() anope_override
+ ChanAccess *Create() override
{
return new AccessChanAccess(this);
}
@@ -214,6 +214,7 @@ class CommandCSAccess : public Command
access->level = level;
access->last_seen = 0;
access->created = Anope::CurTime;
+ access->description = params.size() > 4 ? params[4] : "";
ci->AddAccess(access);
FOREACH_MOD(OnAccessAdd, (ci, source, access));
@@ -255,18 +256,18 @@ class CommandCSAccess : public Command
CommandSource &source;
ChannelInfo *ci;
Command *c;
- unsigned deleted;
+ unsigned deleted = 0;
Anope::string Nicks;
- bool denied;
- bool override;
+ bool denied = false;
+ bool override = false;
public:
- AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), denied(false), override(false)
+ AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c)
{
if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/access/modify"))
this->override = true;
}
- ~AccessDelCallback()
+ ~AccessDelCallback() override
{
if (denied && !deleted)
source.Reply(ACCESS_DENIED);
@@ -283,7 +284,7 @@ class CommandCSAccess : public Command
}
}
- void HandleNumber(unsigned Number) anope_override
+ void HandleNumber(unsigned Number) override
{
if (!Number || Number > ci->GetAccessCount())
return;
@@ -364,7 +365,7 @@ class CommandCSAccess : public Command
{
}
- void HandleNumber(unsigned number) anope_override
+ void HandleNumber(unsigned number) override
{
if (!number || number > ci->GetAccessCount())
return;
@@ -373,12 +374,14 @@ class CommandCSAccess : public Command
Anope::string timebuf;
if (ci->c)
- for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
+ {
+ for (const auto &[_, cuc] : ci->c->users)
{
ChannelInfo *p;
- if (access->Matches(cit->second->user, cit->second->user->Account(), p))
+ if (access->Matches(cuc->user, cuc->user->Account(), p))
timebuf = "Now";
}
+ }
if (timebuf.empty())
{
if (access->last_seen == 0)
@@ -393,6 +396,7 @@ class CommandCSAccess : public Command
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
entry["Last seen"] = timebuf;
+ entry["Description"] = access->description;
this->list.AddEntry(entry);
}
}
@@ -410,12 +414,14 @@ class CommandCSAccess : public Command
Anope::string timebuf;
if (ci->c)
- for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
+ {
+ for (auto &[_, cuc] : ci->c->users)
{
ChannelInfo *p;
- if (access->Matches(cit->second->user, cit->second->user->Account(), p))
+ if (access->Matches(cuc->user, cuc->user->Account(), p))
timebuf = "Now";
}
+ }
if (timebuf.empty())
{
if (access->last_seen == 0)
@@ -430,6 +436,7 @@ class CommandCSAccess : public Command
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
entry["Last seen"] = timebuf;
+ entry["Description"] = access->description;
list.AddEntry(entry);
}
}
@@ -443,8 +450,8 @@ class CommandCSAccess : public Command
source.Reply(_("Access list for %s:"), ci->name.c_str());
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
source.Reply(_("End of access list"));
}
@@ -461,7 +468,7 @@ class CommandCSAccess : public Command
}
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask"));
+ list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("Description"));
this->ProcessList(source, ci, params, list);
}
@@ -474,7 +481,7 @@ class CommandCSAccess : public Command
}
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Last seen"));
+ list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Last seen")).AddColumn(_("Description"));
this->ProcessList(source, ci, params, list);
}
@@ -498,17 +505,17 @@ class CommandCSAccess : public Command
}
public:
- CommandCSAccess(Module *creator) : Command(creator, "chanserv/access", 2, 4)
+ CommandCSAccess(Module *creator) : Command(creator, "chanserv/access", 2, 5)
{
this->SetDesc(_("Modify the list of privileged users"));
- this->SetSyntax(_("\037channel\037 ADD \037mask\037 \037level\037"));
+ this->SetSyntax(_("\037channel\037 ADD \037mask\037 \037level\037 [\037description\037]"));
this->SetSyntax(_("\037channel\037 DEL {\037mask\037 | \037entry-num\037 | \037list\037}"));
this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 VIEW [\037mask\037 | \037list\037]"));
this->SetSyntax(_("\037channel\037 CLEAR"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[1];
const Anope::string &nick = params.size() > 2 ? params[2] : "";
@@ -566,7 +573,7 @@ class CommandCSAccess : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
this->SendSyntax(source);
source.Reply(" ");
@@ -703,9 +710,8 @@ class CommandCSLevels : public Command
const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
- for (unsigned i = 0; i < privs.size(); ++i)
+ for (const auto &p : privs)
{
- const Privilege &p = privs[i];
int16_t j = ci->GetLevel(p.name);
ListFormatter::ListEntry entry;
@@ -724,8 +730,8 @@ class CommandCSLevels : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
void DoReset(CommandSource &source, ChannelInfo *ci)
@@ -750,7 +756,7 @@ class CommandCSLevels : public Command
this->SetSyntax(_("\037channel\037 RESET"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
const Anope::string &cmd = params[1];
const Anope::string &what = params.size() > 2 ? params[2] : "";
@@ -794,7 +800,7 @@ class CommandCSLevels : public Command
return;
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
if (subcommand.equals_ci("DESC"))
{
@@ -803,10 +809,8 @@ class CommandCSLevels : public Command
ListFormatter list(source.GetAccount());
list.AddColumn(_("Name")).AddColumn(_("Description"));
- const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
- for (unsigned i = 0; i < privs.size(); ++i)
+ for (const auto &p : PrivilegeManager::GetPrivileges())
{
- const Privilege &p = privs[i];
ListFormatter::ListEntry entry;
entry["Name"] = p.name;
entry["Description"] = Language::Translate(source.nc, p.desc.c_str());
@@ -816,8 +820,8 @@ class CommandCSLevels : public Command
std::vector<Anope::string> replies;
list.Process(replies);
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ for (const auto &reply : replies)
+ source.Reply(reply);
}
else
{
@@ -861,7 +865,7 @@ class CSAccess : public Module
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
defaultLevels.clear();
@@ -887,12 +891,12 @@ class CSAccess : public Module
}
}
- void OnCreateChan(ChannelInfo *ci) anope_override
+ void OnCreateChan(ChannelInfo *ci) override
{
reset_levels(ci);
}
- EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) anope_override
+ EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) override
{
if (group->ci == NULL)
return EVENT_CONTINUE;