From 4e9a2df8274f010ff50d4a937e04cc3eff2fca72 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 30 Nov 2023 14:25:35 +0000 Subject: [PATCH] Add the UNBANME privilege to allow users to unban themselves. This is separate from the existing UNBAN privilege which applies to all users. Closes #331. --- data/chanserv.example.conf | 16 ++++++++++++++++ modules/commands/cs_unban.cpp | 16 +++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/data/chanserv.example.conf b/data/chanserv.example.conf index e5d623223..71965cc94 100644 --- a/data/chanserv.example.conf +++ b/data/chanserv.example.conf @@ -755,6 +755,22 @@ privilege xop = "HOP" } +/* + * UNBANME privilege. + * + * Used by chanserv/unban. + * + * Users with this permission can unban themself through ChanServ. + */ +privilege +{ + name = "UNBANME" + rank = 200 + level = 4 + flag = "U" + xop = "HOP" +} + /* * VOICE privilege. * diff --git a/modules/commands/cs_unban.cpp b/modules/commands/cs_unban.cpp index fec777cc0..832c1cfcb 100644 --- a/modules/commands/cs_unban.cpp +++ b/modules/commands/cs_unban.cpp @@ -40,7 +40,7 @@ class CommandCSUnban : public Command unsigned count = 0; for (auto *ci : queue) { - if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) + if (!ci->c || !(source.AccessFor(ci).HasPriv("UNBAN") || source.AccessFor(ci).HasPriv("UNBANME"))) continue; FOREACH_MOD(OnChannelUnban, (source.GetUser(), ci)); @@ -69,12 +69,6 @@ class CommandCSUnban : public Command return; } - if (!source.AccessFor(ci).HasPriv("UNBAN") && !source.HasPriv("chanserv/kick")) - { - source.Reply(ACCESS_DENIED); - return; - } - User *u2 = source.GetUser(); if (params.size() > 1) u2 = User::Find(params[1], true); @@ -85,6 +79,14 @@ class CommandCSUnban : public Command return; } + if (!source.AccessFor(ci).HasPriv("UNBAN") && + !(u2 == source.GetUser() && source.AccessFor(ci).HasPriv("UNBANME")) && + !source.HasPriv("chanserv/kick")) + { + source.Reply(ACCESS_DENIED); + return; + } + bool override = !source.AccessFor(ci).HasPriv("UNBAN") && source.HasPriv("chanserv/kick"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to unban " << u2->nick;