summaryrefslogtreecommitdiff
path: root/modules/commands/cs_flags.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands/cs_flags.cpp')
-rw-r--r--modules/commands/cs_flags.cpp148
1 files changed, 76 insertions, 72 deletions
diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp
index e3f3da978..7e17a1b47 100644
--- a/modules/commands/cs_flags.cpp
+++ b/modules/commands/cs_flags.cpp
@@ -13,16 +13,16 @@
static std::map<Anope::string, char> defaultFlags;
-class FlagsChanAccess : public ChanAccess
+class FlagsChanAccess : public ChanServ::ChanAccess
{
public:
std::set<char> flags;
- FlagsChanAccess(AccessProvider *p) : ChanAccess(p)
+ FlagsChanAccess(ChanServ::AccessProvider *p) : ChanAccess(p)
{
}
- bool HasPriv(const Anope::string &priv) const anope_override
+ bool HasPriv(const Anope::string &priv) const override
{
std::map<Anope::string, char>::iterator it = defaultFlags.find(priv);
if (it != defaultFlags.end() && this->flags.count(it->second) > 0)
@@ -35,17 +35,17 @@ class FlagsChanAccess : public ChanAccess
return Anope::string(this->flags.begin(), this->flags.end());
}
- void AccessUnserialize(const Anope::string &data) anope_override
+ void AccessUnserialize(const Anope::string &data) override
{
for (unsigned i = data.length(); i > 0; --i)
this->flags.insert(data[i - 1]);
}
- static Anope::string DetermineFlags(const ChanAccess *access)
+ static Anope::string DetermineFlags(const ChanServ::ChanAccess *access)
{
if (access->provider->name == "access/flags")
return access->AccessSerialize();
-
+
std::set<char> buffer;
for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it)
@@ -59,17 +59,17 @@ class FlagsChanAccess : public ChanAccess
}
};
-class FlagsAccessProvider : public AccessProvider
+class FlagsAccessProvider : public ChanServ::AccessProvider
{
public:
static FlagsAccessProvider *ap;
- FlagsAccessProvider(Module *o) : AccessProvider(o, "access/flags")
+ FlagsAccessProvider(Module *o) : ChanServ::AccessProvider(o, "access/flags")
{
ap = this;
}
- ChanAccess *Create() anope_override
+ ChanServ::ChanAccess *Create() override
{
return new FlagsChanAccess(this);
}
@@ -78,7 +78,7 @@ FlagsAccessProvider* FlagsAccessProvider::ap;
class CommandCSFlags : public Command
{
- void DoModify(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
+ void DoModify(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> &params)
{
Anope::string mask = params.size() > 2 ? params[2] : "";
Anope::string flags = params.size() > 3 ? params[3] : "";
@@ -89,8 +89,8 @@ class CommandCSFlags : public Command
return;
}
- AccessGroup u_access = source.AccessFor(ci);
- const ChanAccess *highest = u_access.Highest();
+ ChanServ::AccessGroup u_access = source.AccessFor(ci);
+ const ChanServ::ChanAccess *highest = u_access.Highest();
if (IRCD->IsChannelValid(mask))
{
@@ -100,10 +100,10 @@ class CommandCSFlags : public Command
return;
}
- ChannelInfo *targ_ci = ChannelInfo::Find(mask);
+ ChanServ::Channel *targ_ci = ChanServ::Find(mask);
if (targ_ci == NULL)
{
- source.Reply(CHAN_X_NOT_REGISTERED, mask.c_str());
+ source.Reply(_("Channel \002{0}\002 isn't registered."), mask);
return;
}
else if (ci == targ_ci)
@@ -116,7 +116,7 @@ class CommandCSFlags : public Command
}
else
{
- const NickAlias *na = NickAlias::Find(mask);
+ const NickServ::Nick *na = NickServ::FindNick(mask);
if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access"))
{
source.Reply(_("Masks and unregistered users may not be on access lists."));
@@ -129,19 +129,19 @@ class CommandCSFlags : public Command
mask = "*!*@" + targ->GetDisplayedHost();
else
{
- source.Reply(NICK_X_NOT_REGISTERED, mask.c_str());
+ source.Reply(_("\002{0}\002 isn't registered."), mask);
return;
}
}
}
- ChanAccess *current = NULL;
+ ChanServ::ChanAccess *current = NULL;
unsigned current_idx;
std::set<char> current_flags;
bool override = false;
for (current_idx = ci->GetAccessCount(); current_idx > 0; --current_idx)
{
- ChanAccess *access = ci->GetAccess(current_idx - 1);
+ ChanServ::ChanAccess *access = ci->GetAccess(current_idx - 1);
if (mask.equals_ci(access->Mask()))
{
// Flags allows removing others that have the same access as you,
@@ -154,7 +154,7 @@ class CommandCSFlags : public Command
override = true;
else
{
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to modify the access of \002{1}\002."), ci->name, access->Mask());
return;
}
}
@@ -170,11 +170,11 @@ class CommandCSFlags : public Command
unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
if (access_max && ci->GetDeepAccessCount() >= access_max)
{
- source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max);
+ source.Reply(_("Sorry, you can only have \002{0}\002 access entries on a channel, including access entries from other channels."), access_max);
return;
}
- Privilege *p = NULL;
+ ChanServ::Privilege *p = NULL;
bool add = true;
for (size_t i = 0; i < flags.length(); ++i)
{
@@ -210,7 +210,7 @@ class CommandCSFlags : public Command
}
break;
default:
- p = PrivilegeManager::FindPrivilege(flags.substr(i));
+ p = ChanServ::service ? ChanServ::service->FindPrivilege(flags.substr(i)) : nullptr;
if (p != NULL && defaultFlags[p->name])
{
f = defaultFlags[p->name];
@@ -227,7 +227,7 @@ class CommandCSFlags : public Command
override = true;
else
{
- source.Reply(_("You can not set the \002%c\002 flag."), f);
+ source.Reply(_("You can not set the \002{0}\002 flag."), f);
break;
}
}
@@ -244,19 +244,19 @@ class CommandCSFlags : public Command
if (current != NULL)
{
ci->EraseAccess(current_idx - 1);
- FOREACH_MOD(OnAccessDel, (ci, source, current));
+ Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, current);
delete current;
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask;
- source.Reply(_("\002%s\002 removed from the %s access list."), mask.c_str(), ci->name.c_str());
+ source.Reply(_("\002{0}\002 removed from the access list of \002{1}\002."), mask, ci->name);
}
else
{
- source.Reply(_("\002%s\002 not found on %s access list."), mask.c_str(), ci->name.c_str());
+ source.Reply(_("\002{0}\002 not found on the access list of \002{1}\002."), mask, ci->name);
}
return;
}
- ServiceReference<AccessProvider> provider("AccessProvider", "access/flags");
+ ServiceReference<ChanServ::AccessProvider> provider("AccessProvider", "access/flags");
if (!provider)
return;
FlagsChanAccess *access = anope_dynamic_static_cast<FlagsChanAccess *>(provider->Create());
@@ -271,27 +271,27 @@ class CommandCSFlags : public Command
ci->AddAccess(access);
- FOREACH_MOD(OnAccessAdd, (ci, source, access));
+ Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access);
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to modify " << mask << "'s flags to " << access->AccessSerialize();
if (p != NULL)
{
if (add)
- source.Reply(_("Privilege \002%s\002 added to \002%s\002 on \002%s\002, new flags are +\002%s\002"), p->name.c_str(), access->Mask().c_str(), ci->name.c_str(), access->AccessSerialize().c_str());
+ source.Reply(_("Privilege \002{0}\002 added to \002{1}\002 on \002{2}\002, new flags are +\002{3}\002"), p->name, access->Mask(), ci->name, access->AccessSerialize());
else
- source.Reply(_("Privilege \002%s\002 removed from \002%s\002 on \002%s\002, new flags are +\002%s\002"), p->name.c_str(), access->Mask().c_str(), ci->name.c_str(), access->AccessSerialize().c_str());
+ source.Reply(_("Privilege \002{0}\002 removed from \002{1}\002 on \002{2}\002, new flags are +\002{3}\002"), p->name, access->Mask(), ci->name, access->AccessSerialize());
}
else
- source.Reply(_("Flags for \002%s\002 on %s set to +\002%s\002"), access->Mask().c_str(), ci->name.c_str(), access->AccessSerialize().c_str());
+ source.Reply(_("Flags for \002{0}\002 on \002{1}\002 set to +\002{2}\002"), access->Mask(), ci->name, access->AccessSerialize());
}
- void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
+ void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> &params)
{
const Anope::string &arg = params.size() > 2 ? params[2] : "";
if (!ci->GetAccessCount())
{
- source.Reply(_("%s access list is empty."), ci->name.c_str());
+ source.Reply(_("The access list of \002{0}\002 is empty."), ci->name);
return;
}
@@ -302,7 +302,7 @@ class CommandCSFlags : public Command
unsigned count = 0;
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
{
- const ChanAccess *access = ci->GetAccess(i);
+ const ChanServ::ChanAccess *access = ci->GetAccess(i);
const Anope::string &flags = FlagsChanAccess::DetermineFlags(access);
if (!arg.empty())
@@ -331,39 +331,38 @@ class CommandCSFlags : public Command
}
if (list.IsEmpty())
- source.Reply(_("No matching entries on %s access list."), ci->name.c_str());
+ source.Reply(_("No matching entries on the access list of \002{0}\002."), ci->name);
else
{
std::vector<Anope::string> replies;
list.Process(replies);
- source.Reply(_("Flags list for %s"), ci->name.c_str());
+ source.Reply(_("Flags list for \002{0}\002:"), ci->name);
for (unsigned i = 0; i < replies.size(); ++i)
source.Reply(replies[i]);
if (count == ci->GetAccessCount())
source.Reply(_("End of access list."));
else
- source.Reply(_("End of access list - %d/%d entries shown."), count, ci->GetAccessCount());
+ source.Reply(_("End of access list - \002{0}/{1}\002 entries shown."), count, ci->GetAccessCount());
}
}
- void DoClear(CommandSource &source, ChannelInfo *ci)
+ void DoClear(CommandSource &source, ChanServ::Channel *ci)
{
if (!source.IsFounder(ci) && !source.HasPriv("chanserv/access/modify"))
- source.Reply(ACCESS_DENIED);
- else
{
- ci->ClearAccess();
+ source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->name);
+ return;
+ }
- FOREACH_MOD(OnAccessClear, (ci, source));
+ ci->ClearAccess();
- source.Reply(_("Channel %s access list has been cleared."), ci->name.c_str());
+ Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source);
- bool override = !source.IsFounder(ci);
- Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the access list";
- }
+ source.Reply(_("The access list of \002{0}\002 has been cleared."), ci->name);
- return;
+ bool override = !source.IsFounder(ci);
+ Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the access list";
}
public:
@@ -375,15 +374,15 @@ class CommandCSFlags : public Command
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 &chan = params[0];
const Anope::string &cmd = params.size() > 1 ? params[1] : "";
- ChannelInfo *ci = ChannelInfo::Find(chan);
+ ChanServ::Channel *ci = ChanServ::Find(chan);
if (ci == NULL)
{
- source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
+ source.Reply(_("Channel \002{0}\002 isn't registered."), chan);
return;
}
@@ -397,7 +396,7 @@ class CommandCSFlags : public Command
has_access = true;
if (!has_access)
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), is_list ? "ACCESS_LIST" : "ACCESS_CHANGE", ci->name);
else if (Anope::ReadOnly && !is_list)
source.Reply(_("Sorry, channel access list modification is temporarily disabled."));
else if (cmd.equals_ci("MODIFY"))
@@ -410,26 +409,30 @@ class CommandCSFlags : public Command
this->OnSyntaxError(source, cmd);
}
- bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
- this->SendSyntax(source);
- source.Reply(" ");
- source.Reply(_("%s is another way to modify the channel access list, similar to\n"
- "the XOP and ACCESS methods."), source.command.c_str());
+ source.Reply(_("{0} allow granularly granting privileges on channels to users by assigning them flags, which map to one or more privileges.\n"
+ "\n"
+ "The \002MODIFY\002 command allows you to modify the access list."
+ " If \037mask\037 is not already on the access list is it added, then the \037changes\037 are applied."
+ " If the mask has no more flags, then the mask is removed from the access list."
+ " Additionally, you may use +* or -* to add or remove all flags, respectively."
+ " You are only able to modify the access list if you have the \002{1}\002 privilege on the channel, and can only give privileges to up what you have."),
+ source.command, "ACCESS_CHANGE");
source.Reply(" ");
- source.Reply(_("The \002MODIFY\002 command allows you to modify the access list. If mask is\n"
- "not already on the access list is it added, then the changes are applied.\n"
- "If the mask has no more flags, then the mask is removed from the access list.\n"
- "Additionally, you may use +* or -* to add or remove all flags, respectively. You are\n"
- "only able to modify the access list if you have the proper permission on the channel,\n"
- "and even then you can only give other people access to up what you already have."));
+ source.Reply(_("The \002LIST\002 command allows you to list existing entries on the channel access list."
+ " If \037mask\037 is given, the \037mask\037 is wildcard matched against all existing entries on the access list, and only those entries are returned."
+ " If a set of flags is given, only those on the access list with the specified flags are returned."));
source.Reply(" ");
- source.Reply(_("The \002LIST\002 command allows you to list existing entries on the channel access list.\n"
- "If a mask is given, the mask is wildcard matched against all existing entries on the\n"
- "access list, and only those entries are returned. If a set of flags is given, only those\n"
- "on the access list with the specified flags are returned."));
+ source.Reply(_("The \002CLEAR\002 command clears the channel access list, which requires being the founder of \037channel\037."));
source.Reply(" ");
- source.Reply(_("The \002CLEAR\002 command clears the channel access list, which requires channel founder."));
+ source.Reply(_("\n"
+ "Examples:\n"
+ " {command} #anope MODIFY Attila +fHhu-i\n"
+ " Modifies the flags of \"Attila\" on the access list of \"#anope\" to \"+fHhu-i\".\n"
+ "\n"
+ " {command} #anope MODIFY *!*@anope.org +*\n"
+ " Modifies the flags of the host mask \"*!*@anope.org\" on the access list of \"#anope\" to have all flags."));
source.Reply(" ");
source.Reply(_("The available flags are:"));
@@ -440,7 +443,7 @@ class CommandCSFlags : public Command
for (reverse_map::iterator it = reverse.begin(), it_end = reverse.end(); it != it_end; ++it)
{
- Privilege *p = PrivilegeManager::FindPrivilege(it->second);
+ ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(it->second) : nullptr;
if (p == NULL)
continue;
source.Reply(" %c - %s", it->first, Language::Translate(source.nc, p->desc.c_str()));
@@ -456,14 +459,15 @@ class CSFlags : public Module
CommandCSFlags commandcsflags;
public:
- CSFlags(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- accessprovider(this), commandcsflags(this)
+ CSFlags(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , accessprovider(this)
+ , commandcsflags(this)
{
this->SetPermanent(true);
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
defaultFlags.clear();
@@ -473,7 +477,7 @@ class CSFlags : public Module
const Anope::string &pname = priv->Get<const Anope::string>("name");
- Privilege *p = PrivilegeManager::FindPrivilege(pname);
+ ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(pname) : nullptr;
if (p == NULL)
continue;