summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2023-07-11 12:19:47 +0100
committerSadie Powell <sadie@witchery.services>2023-07-11 12:19:47 +0100
commitb7458c5da1dc952a29c39fc7c72cbde44ace004f (patch)
tree154f25bc6474b5e08f41ccd8dd74e7388ec370e2
parent4a6f4bc92fbf447c2aea52df78814514e7e3d60b (diff)
Allow access list entries to have a description.
This is useful when adding glob matches to the access list as a reminder of who they actually match. Resolves https://bugs.anope.org/view.php?id=1613
-rw-r--r--include/access.h1
-rw-r--r--modules/commands/cs_access.cpp11
-rw-r--r--modules/commands/cs_clone.cpp1
-rw-r--r--modules/commands/cs_flags.cpp18
-rw-r--r--modules/commands/cs_xop.cpp8
-rw-r--r--src/access.cpp2
6 files changed, 28 insertions, 13 deletions
diff --git a/include/access.h b/include/access.h
index 842dcb78a..f22e098bf 100644
--- a/include/access.h
+++ b/include/access.h
@@ -84,6 +84,7 @@ class CoreExport ChanAccess : public Serializable
/* Channel this access entry is on */
Serialize::Reference<ChannelInfo> ci;
Anope::string creator;
+ Anope::string description;
time_t last_seen;
time_t created;
diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp
index e75a840d3..52dbdef20 100644
--- a/modules/commands/cs_access.cpp
+++ b/modules/commands/cs_access.cpp
@@ -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));
@@ -388,6 +389,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);
}
}
@@ -425,6 +427,7 @@ class CommandCSAccess : public Command
entry["Mask"] = access->Mask();
entry["By"] = access->creator;
entry["Last seen"] = timebuf;
+ entry["Description"] = access->description;
list.AddEntry(entry);
}
}
@@ -456,7 +459,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);
}
@@ -469,7 +472,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);
}
@@ -493,10 +496,10 @@ 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]"));
diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp
index c7869e7ce..84c7d91cb 100644
--- a/modules/commands/cs_clone.cpp
+++ b/modules/commands/cs_clone.cpp
@@ -44,6 +44,7 @@ class CommandCSClone : public Command
ChanAccess *newaccess = provider->Create();
newaccess->SetMask(taccess->Mask(), target_ci);
newaccess->creator = taccess->creator;
+ newaccess->description = taccess->description;
newaccess->last_seen = taccess->last_seen;
newaccess->created = taccess->created;
newaccess->AccessUnserialize(taccess->AccessSerialize());
diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp
index 38370024c..6edb736fc 100644
--- a/modules/commands/cs_flags.cpp
+++ b/modules/commands/cs_flags.cpp
@@ -78,7 +78,7 @@ FlagsAccessProvider* FlagsAccessProvider::ap;
class CommandCSFlags : public Command
{
- void DoModify(CommandSource &source, ChannelInfo *ci, Anope::string mask, const Anope::string &flags)
+ void DoModify(CommandSource &source, ChannelInfo *ci, Anope::string mask, const Anope::string &flags, const Anope::string &description)
{
if (flags.empty())
{
@@ -262,7 +262,8 @@ class CommandCSFlags : public Command
return;
FlagsChanAccess *access = anope_dynamic_static_cast<FlagsChanAccess *>(provider->Create());
access->SetMask(mask, ci);
- access->creator = source.GetNick();
+ access->creator = source.GetNick();
+ access->description = current ? current->description : description;
access->last_seen = current ? current->last_seen : 0;
access->created = Anope::CurTime;
access->flags = current_flags;
@@ -298,7 +299,7 @@ class CommandCSFlags : public Command
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Flags")).AddColumn(_("Creator")).AddColumn(_("Created"));
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Flags")).AddColumn(_("Creator")).AddColumn(_("Created")).AddColumn(_("Description"));
unsigned count = 0;
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
@@ -328,6 +329,7 @@ class CommandCSFlags : public Command
entry["Flags"] = flags;
entry["Creator"] = access->creator;
entry["Created"] = Anope::strftime(access->created, source.nc, true);
+ entry["Description"] = access->description;
list.AddEntry(entry);
}
@@ -368,10 +370,10 @@ class CommandCSFlags : public Command
}
public:
- CommandCSFlags(Module *creator) : Command(creator, "chanserv/flags", 1, 4)
+ CommandCSFlags(Module *creator) : Command(creator, "chanserv/flags", 1, 5)
{
this->SetDesc(_("Modify the list of privileged users"));
- this->SetSyntax(_("\037channel\037 [MODIFY] \037mask\037 \037changes\037"));
+ this->SetSyntax(_("\037channel\037 [MODIFY] \037mask\037 \037changes\037 [\037description\037]"));
this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | +\037flags\037]"));
this->SetSyntax(_("\037channel\037 CLEAR"));
}
@@ -409,19 +411,21 @@ class CommandCSFlags : public Command
this->DoClear(source, ci);
else
{
- Anope::string mask, flags;
+ Anope::string mask, flags, description;
if (cmd.equals_ci("MODIFY"))
{
mask = params.size() > 2 ? params[2] : "";
flags = params.size() > 3 ? params[3] : "";
+ description = params.size() > 4 ? params[4] : "";
}
else
{
mask = cmd;
flags = params.size() > 2 ? params[2] : "";
+ description = params.size() > 3 ? params[3] : "";
}
- this->DoModify(source, ci, mask, flags);
+ this->DoModify(source, ci, mask, flags, description);
}
}
diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp
index e2cd82064..1d5cfb7d9 100644
--- a/modules/commands/cs_xop.cpp
+++ b/modules/commands/cs_xop.cpp
@@ -100,6 +100,7 @@ class CommandCSXOP : public Command
void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> &params)
{
Anope::string mask = params.size() > 2 ? params[2] : "";
+ Anope::string description = params.size() > 3 ? params[3] : "";
if (mask.empty())
{
@@ -208,6 +209,7 @@ class CommandCSXOP : public Command
XOPChanAccess *acc = anope_dynamic_static_cast<XOPChanAccess *>(provider->Create());
acc->SetMask(mask, ci);
acc->creator = source.GetNick();
+ acc->description = description;
acc->type = source.command.upper();
acc->last_seen = 0;
acc->created = Anope::CurTime;
@@ -374,7 +376,7 @@ class CommandCSXOP : public Command
}
ListFormatter list(source.GetAccount());
- list.AddColumn(_("Number")).AddColumn(_("Mask"));
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Description"));
if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos)
{
@@ -401,6 +403,7 @@ class CommandCSXOP : public Command
ListFormatter::ListEntry entry;
entry["Number"] = stringify(Number);
entry["Mask"] = a->Mask();
+ entry["Description"] = a->description;
this->list.AddEntry(entry);
}
} nl_list(list, ci, nick, source);
@@ -420,6 +423,7 @@ class CommandCSXOP : public Command
ListFormatter::ListEntry entry;
entry["Number"] = stringify(i + 1);
entry["Mask"] = a->Mask();
+ entry["Description"] = a->description;
list.AddEntry(entry);
}
}
@@ -478,7 +482,7 @@ class CommandCSXOP : public Command
public:
CommandCSXOP(Module *modname) : Command(modname, "chanserv/xop", 2, 4)
{
- this->SetSyntax(_("\037channel\037 ADD \037mask\037"));
+ this->SetSyntax(_("\037channel\037 ADD \037mask\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 CLEAR"));
diff --git a/src/access.cpp b/src/access.cpp
index 68fd0777d..baa377a02 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -211,6 +211,7 @@ void ChanAccess::Serialize(Serialize::Data &data) const
data["ci"] << this->ci->name;
data["mask"] << this->Mask();
data["creator"] << this->creator;
+ data["description"] << this->description;
data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created;
data["data"] << this->AccessSerialize();
@@ -238,6 +239,7 @@ Serializable* ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data)
data["mask"] >> m;
access->SetMask(m, ci);
data["creator"] >> access->creator;
+ data["description"] >> access->description;
data["last_seen"] >> access->last_seen;
data["created"] >> access->created;