From 8b694bc392c36551e428b84454efb81cdbc8bcd3 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 6 Feb 2017 14:23:18 -0500 Subject: Track override in CommandSource and use it in the logger --- include/commands.h | 8 +- include/logger.h | 29 ++++++ modules/botserv/assign.cpp | 14 ++- modules/botserv/badwords.cpp | 15 ++- modules/botserv/bot.cpp | 6 +- modules/botserv/control.cpp | 10 +- modules/botserv/kick.cpp | 28 +++--- modules/botserv/set.cpp | 5 +- modules/chanserv/access.cpp | 206 ++++++++++++++++++++--------------------- modules/chanserv/akick.cpp | 21 ++--- modules/chanserv/ban.cpp | 16 ++-- modules/chanserv/clone.cpp | 9 +- modules/chanserv/drop.cpp | 5 +- modules/chanserv/enforce.cpp | 20 ++-- modules/chanserv/entrymsg.cpp | 8 +- modules/chanserv/flags.cpp | 22 ++--- modules/chanserv/getkey.cpp | 5 +- modules/chanserv/invite.cpp | 8 +- modules/chanserv/kick.cpp | 40 ++++---- modules/chanserv/list.cpp | 6 +- modules/chanserv/log.cpp | 8 +- modules/chanserv/mode.cpp | 52 ++++------- modules/chanserv/set.cpp | 78 ++++++++-------- modules/chanserv/set_misc.cpp | 6 +- modules/chanserv/suspend.cpp | 4 +- modules/chanserv/sync.cpp | 5 +- modules/chanserv/topic.cpp | 13 ++- modules/chanserv/unban.cpp | 5 +- modules/chanserv/updown.cpp | 26 +----- modules/chanserv/xop.cpp | 21 ++--- modules/fantasy.cpp | 8 +- modules/global/global.cpp | 2 +- modules/greet.cpp | 8 +- modules/hostserv/add.cpp | 2 +- modules/hostserv/del.cpp | 4 +- modules/hostserv/off.cpp | 2 +- modules/hostserv/on.cpp | 2 +- modules/memoserv/sendall.cpp | 2 +- modules/nickserv/getemail.cpp | 2 +- modules/nickserv/register.cpp | 2 +- modules/nickserv/set.cpp | 6 +- modules/nickserv/suspend.cpp | 4 +- modules/operserv/akill.cpp | 10 +- modules/operserv/chankill.cpp | 2 +- modules/operserv/config.cpp | 4 +- modules/operserv/defcon.cpp | 2 +- modules/operserv/dns.cpp | 22 ++--- modules/operserv/forbid.cpp | 4 +- modules/operserv/ignore.cpp | 8 +- modules/operserv/info.cpp | 6 +- modules/operserv/jupe.cpp | 2 +- modules/operserv/kick.cpp | 2 +- modules/operserv/kill.cpp | 2 +- modules/operserv/list.cpp | 8 +- modules/operserv/login.cpp | 4 +- modules/operserv/logsearch.cpp | 2 +- modules/operserv/mode.cpp | 4 +- modules/operserv/modinfo.cpp | 6 +- modules/operserv/module.cpp | 6 +- modules/operserv/news.cpp | 6 +- modules/operserv/noop.cpp | 4 +- modules/operserv/oper.cpp | 4 +- modules/operserv/reload.cpp | 2 +- modules/operserv/session.cpp | 8 +- modules/operserv/set.cpp | 20 ++-- modules/operserv/shutdown.cpp | 4 +- modules/operserv/stats.cpp | 2 +- modules/operserv/svs.cpp | 8 +- modules/operserv/sxline.cpp | 14 +-- src/command.cpp | 27 +++++- src/logger.cpp | 6 ++ 71 files changed, 457 insertions(+), 485 deletions(-) diff --git a/include/commands.h b/include/commands.h index d3aa180a2..1dddfa4fd 100644 --- a/include/commands.h +++ b/include/commands.h @@ -67,6 +67,8 @@ class CoreExport CommandSource Reference u; /* Command info being executed */ CommandInfo command; + /* whether or not this is an override as determined by the command */ + bool override = false; public: /* The account executing the command */ Reference nc; @@ -108,6 +110,10 @@ class CoreExport CommandSource bool HasPriv(const Anope::string &cmd); bool IsServicesOper(); bool IsOper(); + + bool HasOverridePriv(const Anope::string &priv); + bool HasOverrideCommand(const Anope::string &priv); + bool IsOverride() const; }; /** Every services command is a class, inheriting from Command. @@ -143,8 +149,6 @@ class CoreExport Command : public Service */ Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0); - virtual ~Command(); - void SetDesc(const Anope::string &d); void ClearSyntax(); diff --git a/include/logger.h b/include/logger.h index d368eb142..eabc9d878 100644 --- a/include/logger.h +++ b/include/logger.h @@ -120,6 +120,7 @@ class Logger Anope::string BuildPrefix() const; void LogMessage(const Anope::string &message); void InsertVariables(FormatInfo &fi); + void CheckOverride(); template Anope::string Format(const Anope::string &message, Args&&... args) @@ -184,9 +185,13 @@ class Logger template void Command(LogType type, CommandSource &source, ChanServ::Channel *ci, const Anope::string &message, Args&&... args) { Logger l = *this; + l.type = type; l.SetSource(&source); l.SetCi(ci); + // Override if the source is marked override + l.CheckOverride(); + Anope::string translated = Language::Translate(message); l.LogMessage(l.Format(translated, std::forward(args)...)); } @@ -196,6 +201,30 @@ class Logger Command(type, source, nullptr, message, std::forward(args)...); } + // LOG_COMMAND + + template void Command(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message, Args&&... args) + { + Command(LogType::COMMAND, source, ci, message, std::forward(args)...); + } + + template void Command(CommandSource &source, const Anope::string &message, Args&&... args) + { + Command(LogType::COMMAND, source, nullptr, message, std::forward(args)...); + } + + // LOG_ADMIN + + template void Admin(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message, Args&&... args) + { + Command(LogType::ADMIN, source, ci, message, std::forward(args)...); + } + + template void Admin(CommandSource &source, const Anope::string &message, Args&&... args) + { + Command(LogType::ADMIN, source, nullptr, message, std::forward(args)...); + } + template void Log(const Anope::string &message, Args&&... args) { Log(LogLevel::NORMAL, message, std::forward(args)...); diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp index bb2d35879..b743564b0 100644 --- a/modules/botserv/assign.cpp +++ b/modules/botserv/assign.cpp @@ -55,7 +55,7 @@ class CommandBSAssign : public Command } ChanServ::AccessGroup access = source.AccessFor(ci); - if (!access.HasPriv("ASSIGN") && !source.HasPriv("botserv/administration")) + if (!access.HasPriv("ASSIGN") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->GetName()); return; @@ -79,8 +79,7 @@ class CommandBSAssign : public Command return; } - bool override = !access.HasPriv("ASSIGN"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to assign {0}"), bi->nick); + logger.Command(source, ci, _("{source} used {command} on {channel} to assign {0}"), bi->nick); bi->Assign(source.GetUser(), ci); source.Reply(_("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, ci->GetName()); @@ -128,7 +127,7 @@ class CommandBSUnassign : public Command } ChanServ::AccessGroup access = source.AccessFor(ci); - if (!source.HasPriv("botserv/administration") && !access.HasPriv("ASSIGN")) + if (!access.HasPriv("ASSIGN") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "ASSIGN", ci->GetName()); return; @@ -146,8 +145,7 @@ class CommandBSUnassign : public Command return; } - bool override = !access.HasPriv("ASSIGN"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to unassign {0}"), ci->GetBot()->nick); + logger.Command(source, ci, _("{source} used {command} on {channel} to unassign {0}"), ci->GetBot()->nick); ServiceBot *bi = ci->GetBot(); bi->UnAssign(source.GetUser(), ci); @@ -192,7 +190,7 @@ class CommandBSSetNoBot : public Command if (value.equals_ci("ON")) { - logger.Command(LogType::ADMIN, source, ci, _("{source} used {command} on {channel} to enable nobot")); + logger.Admin(source, ci, _("{source} used {command} on {channel} to enable nobot")); ci->SetS("BS_NOBOT", true); if (ci->GetBot()) @@ -201,7 +199,7 @@ class CommandBSSetNoBot : public Command } else if (value.equals_ci("OFF")) { - logger.Command(LogType::ADMIN, source, ci, _("{source} used {command} on {channel} to disable nobot")); + logger.Admin(source, ci, _("{source} used {command} on {channel} to disable nobot")); ci->UnsetS("BS_NOBOT"); source.Reply(_("No-bot mode is now \002off\002 for \002{0}\002."), ci->GetName()); diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp index 3de381d34..5fb7fa342 100644 --- a/modules/botserv/badwords.cpp +++ b/modules/botserv/badwords.cpp @@ -143,8 +143,7 @@ class CommandBSBadwords : public Command void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { - bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to list badwords")); + logger.Command(source, ci, _("{source} used {command} on {channel} to list badwords")); ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Word")).AddColumn(_("Type")); @@ -243,8 +242,7 @@ class CommandBSBadwords : public Command return; } - bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0}"), realword); + logger.Command(source, ci, _("{source} used {command} on {channel} to add {0}"), realword); badwords->AddBadWord(ci, realword, bwtype); source.Reply(_("\002{0}\002 added to \002{1}\002 bad words list."), realword, ci->GetName()); @@ -271,7 +269,7 @@ class CommandBSBadwords : public Command if (!num || num > badwords->GetBadWordCount(ci)) return; - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to remove {0}"), badwords->GetBadWord(ci, num - 1)->GetWord()); + logger.Command(source, ci, _("{source} used {command} on {channel} to remove {0}"), badwords->GetBadWord(ci, num - 1)->GetWord()); ++deleted; badwords->EraseBadWord(ci, num - 1); @@ -305,7 +303,7 @@ class CommandBSBadwords : public Command return; } - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to remove {3}"), bw->GetWord()); + logger.Command(source, ci, _("{source} used {command} on {channel} to remove {3}"), bw->GetWord()); source.Reply(_("\002{0}\002 deleted from \002{1}\002 bad words list."), bw->GetWord(), ci->GetName()); @@ -315,8 +313,7 @@ class CommandBSBadwords : public Command void DoClear(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the badwords list")); + logger.Command(source, ci, _("{source} used {command} on {channel} to clear the badwords list")); badwords->ClearBadWords(ci); source.Reply(_("Bad words list is now empty.")); @@ -352,7 +349,7 @@ class CommandBSBadwords : public Command return; } - if (!source.AccessFor(ci).HasPriv("BADWORDS") && (!need_args || !source.HasPriv("botserv/administration"))) + if (!source.AccessFor(ci).HasPriv("BADWORDS") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "BADWORDS", ci->GetName()); return; diff --git a/modules/botserv/bot.cpp b/modules/botserv/bot.cpp index ab48dc82e..2e632a805 100644 --- a/modules/botserv/bot.cpp +++ b/modules/botserv/bot.cpp @@ -103,7 +103,7 @@ class CommandBSBot : public Command bi->bi = botinfo; botinfo->bot = bi; - logger.Command(LogType::ADMIN, source, _("{source} used {command} to add bot {0} {1}"), bi->GetMask(), bi->realname); + logger.Admin(source, _("{source} used {command} to add bot {0} {1}"), bi->GetMask(), bi->realname); source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname); @@ -266,7 +266,7 @@ class CommandBSBot : public Command if (!user.empty()) bi->OnKill(); - logger.Command(LogType::ADMIN, source, _("{source} used {command} to change bot {0} to {1} {2}"), + logger.Admin(source, _("{source} used {command} to change bot {0} to {1} {2}"), oldnick, bi->GetMask(), bi->realname); source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname); @@ -299,7 +299,7 @@ class CommandBSBot : public Command EventManager::Get()->Dispatch(&Event::BotDelete::OnBotDelete, bi); - logger.Command(LogType::ADMIN, source, _("{source} used {command} to delete bot {0}"), bi->nick); + logger.Admin(source, _("{source} used {command} to delete bot {0}"), bi->nick); source.Reply(_("Bot \002{0}\002 has been deleted."), bi->nick); delete bi; diff --git a/modules/botserv/control.cpp b/modules/botserv/control.cpp index 6a8edc200..ce2b0d6e6 100644 --- a/modules/botserv/control.cpp +++ b/modules/botserv/control.cpp @@ -40,7 +40,7 @@ class CommandBSSay : public Command return; } - if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration")) + if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SAY", ci->GetName()); return; @@ -74,8 +74,7 @@ class CommandBSSay : public Command IRCD->SendPrivmsg(ci->GetBot(), ci->GetName(), text); ci->GetBot()->lastmsg = Anope::CurTime; - bool override = !source.AccessFor(ci).HasPriv("SAY"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to say: {0}"), text); + logger.Command(source, ci, _("{source} used {command} on {channel} to say: {0}"), text); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -112,7 +111,7 @@ class CommandBSAct : public Command return; } - if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasPriv("botserv/administration")) + if (!source.AccessFor(ci).HasPriv("SAY") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SAY", ci->GetName()); return; @@ -144,8 +143,7 @@ class CommandBSAct : public Command IRCD->SendAction(ci->GetBot(), ci->GetName(), message); ci->GetBot()->lastmsg = Anope::CurTime; - bool override = !source.AccessFor(ci).HasPriv("SAY"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} to say: {0}"), message); + logger.Command(source, ci, _("{source} used {command} to say: {0}"), message); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp index 84939c963..3146483e9 100644 --- a/modules/botserv/kick.cpp +++ b/modules/botserv/kick.cpp @@ -586,7 +586,7 @@ class CommandBSKickBase : public Command this->OnSyntaxError(source, ""); else if (!option.equals_ci("ON") && !option.equals_ci("OFF")) this->OnSyntaxError(source, ""); - else if (!source.AccessFor(ci).HasPriv("SET") && !source.HasPriv("botserv/administration")) + else if (!source.AccessFor(ci).HasPriv("SET") && !source.HasOverridePriv("botserv/administration")) source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); else if (!ci->GetBot()) source.Reply(_("There is no bot assigned to \002{0}\002."), ci->GetName()); @@ -636,13 +636,11 @@ class CommandBSKickBase : public Command else source.Reply(_("Bot will now kick for \002{0}\002."), optname); - bool override = !source.AccessFor(ci).HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enable the {0} kicker"), optname); + logger.Command(source, ci, _("{source} used {command} on {channel} to enable the {0} kicker"), optname); } else if (param.equals_ci("OFF")) { - bool override = !source.AccessFor(ci).HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable the {0} kicker"), optname); + logger.Command(source, ci, _("{source} used {command} on {channel} to disable the {0} kicker"), optname); (kd->*setter)(false); (kd->*ttbsetter)(0); @@ -1082,7 +1080,7 @@ class CommandBSSetDontKickOps : public Command } ChanServ::AccessGroup access = source.AccessFor(ci); - if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) + if (!access.HasPriv("SET") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); return; @@ -1098,16 +1096,14 @@ class CommandBSSetDontKickOps : public Command if (params[1].equals_ci("ON")) { - bool override = !access.HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enable dontkickops")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enable dontkickops")); kd->SetDontKickOps(true); source.Reply(_("Bot \002won't kick ops\002 on channel \002{0}\002."), ci->GetName()); } else if (params[1].equals_ci("OFF")) { - bool override = !access.HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable dontkickops")); + logger.Command(source, ci, _("{source} used {command} on {channel} to disable dontkickops")); kd->SetDontKickOps(false); source.Reply(_("Bot \002will kick ops\002 on channel \002{0}\002."), ci->GetName()); @@ -1148,7 +1144,7 @@ class CommandBSSetDontKickVoices : public Command } ChanServ::AccessGroup access = source.AccessFor(ci); - if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) + if (!access.HasPriv("SET") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); return; @@ -1164,19 +1160,17 @@ class CommandBSSetDontKickVoices : public Command if (params[1].equals_ci("ON")) { - bool override = !access.HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enable dontkickvoices")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enable dontkickvoices")); kd->SetDontKickVoices(true); - source.Reply(_("Bot \002won't kick voices\002 on channel %s."), ci->GetName().c_str()); + source.Reply(_("Bot \002won't kick voices\002 on channel \002{0}\002."), ci->GetName()); } else if (params[1].equals_ci("OFF")) { - bool override = !access.HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable dontkickvoices")); + logger.Command(source, ci, _("{source} used {command} on {channel} to disable dontkickvoices")); kd->SetDontKickVoices(false); - source.Reply(_("Bot \002will kick voices\002 on channel %s."), ci->GetName().c_str()); + source.Reply(_("Bot \002will kick voices\002 on channel \002{0}\002."), ci->GetName()); } else { diff --git a/modules/botserv/set.cpp b/modules/botserv/set.cpp index da3b42f92..559453085 100644 --- a/modules/botserv/set.cpp +++ b/modules/botserv/set.cpp @@ -111,7 +111,7 @@ class CommandBSSetBanExpire : public Command } ChanServ::AccessGroup access = source.AccessFor(ci); - if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) + if (!access.HasPriv("SET") && !source.HasOverridePriv("botserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "SET", ci->GetName()); return; @@ -139,8 +139,7 @@ class CommandBSSetBanExpire : public Command ci->SetBanExpire(t); - bool override = !access.HasPriv("SET"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to change banexpire to {0}"), arg); + logger.Command(source, ci, _("{source} used {command} on {channel} to change banexpire to {0}"), arg); if (!t) source.Reply(_("Bot bans will no longer automatically expire.")); diff --git a/modules/chanserv/access.cpp b/modules/chanserv/access.cpp index 36307c52f..44d21734e 100644 --- a/modules/chanserv/access.cpp +++ b/modules/chanserv/access.cpp @@ -101,19 +101,24 @@ void AccessChanAccessImpl::SetLevel(const int &i) class CommandCSAccess : public Command { - void DoAdd(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoAdd(CommandSource &source, ChanServ::Channel *ci, Anope::string mask, const Anope::string &levelstr) { - Anope::string mask = params[2]; ChanServ::Privilege *p = NULL; int level = ChanServ::ACCESS_INVALID; + if (levelstr.empty()) + { + this->OnSyntaxError(source, "ADD"); + return; + } + try { - level = convertTo(params[3]); + level = convertTo(levelstr); } catch (const ConvertException &) { - p = ChanServ::service ? ChanServ::service->FindPrivilege(params[3]) : nullptr; + p = ChanServ::service ? ChanServ::service->FindPrivilege(levelstr) : nullptr; if (p != NULL && p->level) level = p->level; } @@ -137,15 +142,9 @@ class CommandCSAccess : public Command access->SetChannel(ci); access->SetLevel(level); - bool override = false; - if ((!highest || *highest <= *access) && !u_access.founder) { - if (source.HasPriv("chanserv/access/modify")) - { - override = true; - } - else + if (!source.HasOverridePriv("chanserv/access/modify")) { source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to add someone at level \002{1}\002."), ci->GetName(), level); access->Delete(); @@ -184,12 +183,12 @@ class CommandCSAccess : public Command if (mask.equals_ci(access->Mask())) { /* Don't allow lowering from a level >= u_level */ - if ((!highest || *access >= *highest) && !u_access.founder && !source.HasPriv("chanserv/access/modify")) + if ((!highest || *access >= *highest) && !u_access.founder && !source.HasOverridePriv("chanserv/access/modify")) { source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to lower the access of \002{1}\002."), ci->GetName(), access->Mask()); return; } - delete access; + access->Delete(); break; } } @@ -197,7 +196,7 @@ class CommandCSAccess : public Command unsigned access_max = Config->GetModule("chanserv/main")->Get("accessmax", "1024"); if (access_max && ci->GetAccessCount() >= 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 {0} access entries on a channel, including access entries from other channels."), access_max); return; } @@ -213,7 +212,7 @@ class CommandCSAccess : public Command EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0} with level {1}"), mask, level); + logger.Command(source, ci, _("{source} used {command} on {channel} to add {0} with level {1}"), mask, level); if (p != NULL) source.Reply(_("\002{0}\002 added to the access list of \002{1}\002 with privilege \002{2}\002 (level \002{3}\002)."), access->Mask(), ci->GetName(), p->name, level); @@ -221,9 +220,13 @@ class CommandCSAccess : public Command source.Reply(_("\002{0}\002 added to the access list of \002{1}\002 at level \002{2}\002."), access->Mask(), ci->GetName(), level); } - void DoDel(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoDel(CommandSource &source, ChanServ::Channel *ci, Anope::string mask) { - Anope::string mask = params[2]; + if (mask.empty()) + { + this->OnSyntaxError(source, "DEL"); + return; + } if (!ci->GetAccessCount()) { @@ -245,7 +248,6 @@ class CommandCSAccess : public Command if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - bool override = !source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/access/modify"); Anope::string nicks; bool denied = false; unsigned int deleted = 0; @@ -261,7 +263,7 @@ class CommandCSAccess : public Command ChanServ::AccessGroup ag = source.AccessFor(ci); ChanServ::ChanAccess *u_highest = ag.Highest(); - if ((!u_highest || *u_highest <= *access) && !ag.founder && !override && access->GetObj() != source.nc) + if ((!u_highest || *u_highest <= *access) && !ag.founder && !source.IsOverride() && access->GetObj() != source.nc) { denied = true; return; @@ -274,7 +276,7 @@ class CommandCSAccess : public Command nicks = access->Mask(); EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access); - delete access; + access->Delete(); }, [&]() { @@ -284,7 +286,7 @@ class CommandCSAccess : public Command source.Reply(_("There are no entries matching \002{0}\002 on the access list of \002{1}\002."), mask, ci->GetName()); else { - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), mask); + logger.Command(source, ci, _("{source} used {command} on {channel} to delete {0}"), mask); if (deleted == 1) source.Reply(_("Deleted \0021\002 entry from the access list of \002{0}\002."), ci->GetName()); @@ -303,16 +305,17 @@ class CommandCSAccess : public Command ChanServ::ChanAccess *access = ci->GetAccess(i - 1); if (mask.equals_ci(access->Mask())) { - if (access->GetObj() != source.nc && !u_access.founder && (!highest || *highest <= *access) && !source.HasPriv("chanserv/access/modify")) + if (access->GetObj() != source.nc && !u_access.founder && (!highest || *highest <= *access) && !source.HasOverridePriv("chanserv/access/modify")) + { source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to remove the access of \002{1}\002."), ci->GetName(), access->Mask()); + } else { source.Reply(_("\002{0}\002 deleted from the access list of \002{1}\002."), access->Mask(), ci->GetName()); - bool override = !u_access.founder && !u_access.HasPriv("ACCESS_CHANGE") && !access->Mask().equals_ci(source.nc->GetDisplay()); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {3}"), access->Mask()); + logger.Command(source, ci, _("{source} used {command} on {channel} to delete {3}"), access->Mask()); EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access); - delete access; + access->Delete(); } return; } @@ -322,10 +325,8 @@ class CommandCSAccess : public Command } } - void ProcessList(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms, ListFormatter &list) + void ProcessList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &nick, ListFormatter &list) { - const Anope::string &nick = params.size() > 2 ? params[2] : ""; - if (!ci->GetAccessCount()) { source.Reply(_("The access list for \002{0}\002 is empty."), ci->GetName()); @@ -418,7 +419,7 @@ class CommandCSAccess : public Command source.Reply(_("End of access list.")); } - void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &nick) { if (!ci->GetAccessCount()) { @@ -428,10 +429,10 @@ class CommandCSAccess : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")); - this->ProcessList(source, ci, params, list); + this->ProcessList(source, ci, nick, list); } - void DoView(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoView(CommandSource &source, ChanServ::Channel *ci, const Anope::string &nick) { if (!ci->GetAccessCount()) { @@ -441,12 +442,12 @@ class CommandCSAccess : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Level")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Last seen")); - this->ProcessList(source, ci, params, list); + this->ProcessList(source, ci, nick, list); } void DoClear(CommandSource &source, ChanServ::Channel *ci) { - if (!source.IsFounder(ci) && !source.HasPriv("chanserv/access/modify")) + if (!source.IsFounder(ci) && !source.HasOverridePriv("chanserv/access/modify")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->GetName()); return; @@ -459,7 +460,7 @@ class CommandCSAccess : public Command source.Reply(_("The access list of \002{0}\002 has been cleared."), ci->GetName()); bool override = !source.IsFounder(ci); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the access list")); + logger.Command(source, ci, _("{source} used {command} on {channel} to clear the access list")); } public: @@ -478,10 +479,10 @@ class CommandCSAccess : public Command const Anope::string &chan = params[0]; const Anope::string &cmd = params[1]; const Anope::string &nick = params.size() > 2 ? params[2] : ""; - const Anope::string &s = params.size() > 3 ? params[3] : ""; + const Anope::string &level = params.size() > 3 ? params[3] : ""; ChanServ::Channel *ci = ChanServ::Find(chan); - if (ci == NULL) + if (ci == nullptr) { source.Reply(_("Channel \002{0}\002 isn't registered."), chan); return; @@ -494,14 +495,14 @@ class CommandCSAccess : public Command ChanServ::AccessGroup access = source.AccessFor(ci); bool has_access = false; - if (source.HasPriv("chanserv/access/modify")) - has_access = true; - else if (is_list && source.HasPriv("chanserv/access/list")) + if (access.HasPriv("ACCESS_CHANGE")) + { has_access = true; + } else if (is_list && access.HasPriv("ACCESS_LIST")) + { has_access = true; - else if (access.HasPriv("ACCESS_CHANGE")) - has_access = true; + } else if (is_del) { NickServ::Nick *na = NickServ::FindNick(nick); @@ -509,13 +510,12 @@ class CommandCSAccess : public Command has_access = true; } - /* If LIST, we don't *require* any parameters, but we can take any. - * If DEL, we require a nick and no level. - * Else (ADD), we require a level (which implies a nick). */ - if (is_list || is_clear ? 0 : (cmd.equals_ci("DEL") ? (nick.empty() || !s.empty()) : s.empty())) + if (!has_access) { - this->OnSyntaxError(source, cmd); - return; + if (source.HasOverridePriv("chanserv/access/modify")) + has_access = true; + else if (is_list && source.HasOverridePriv("chanserv/access/list")) + has_access = true; } if (!has_access) @@ -531,13 +531,13 @@ class CommandCSAccess : public Command } if (cmd.equals_ci("ADD")) - this->DoAdd(source, ci, params); + this->DoAdd(source, ci, nick, level); else if (cmd.equals_ci("DEL")) - this->DoDel(source, ci, params); + this->DoDel(source, ci, nick); else if (cmd.equals_ci("LIST")) - this->DoList(source, ci, params); + this->DoList(source, ci, nick); else if (cmd.equals_ci("VIEW")) - this->DoView(source, ci, params); + this->DoView(source, ci, nick); else if (cmd.equals_ci("CLEAR")) this->DoClear(source, ci); else @@ -634,20 +634,25 @@ class CommandCSAccess : public Command class CommandCSLevels : public Command { - void DoSet(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoSet(CommandSource &source, ChanServ::Channel *ci, const Anope::string &privilege, const Anope::string &levelstr) { - const Anope::string &what = params[2]; - const Anope::string &lev = params[3]; - int level; - if (lev.equals_ci("FOUNDER")) + if (levelstr.empty()) + { + this->OnSyntaxError(source, "SET"); + return; + } + + if (levelstr.equals_ci("FOUNDER")) + { level = ChanServ::ACCESS_FOUNDER; + } else { try { - level = convertTo(lev); + level = convertTo(levelstr); } catch (const ConvertException &) { @@ -662,57 +667,58 @@ class CommandCSLevels : public Command return; } - ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(what) : nullptr; + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(privilege) : nullptr; if (p == NULL) { CommandInfo *help = source.service->FindCommand("generic/help"); if (help) source.Reply(_("There is no such privilege \002{0}\002. See \002{0}{1} {2} {3}\002 for a list of valid settings."), - what, Config->StrictPrivmsg, source.service->nick, help->cname, source.GetCommand()); + privilege, Config->StrictPrivmsg, source.service->nick, help->cname, source.GetCommand()); + return; } - else - { - bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to set {0} to level {1}"), p->name, level); - ci->SetLevel(p->name, level); - EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); + logger.Command(source, ci, _("{source} used {command} on {channel} to set {0} to level {1}"), p->name, level); - if (level == ChanServ::ACCESS_FOUNDER) - source.Reply(_("Level for privilege \002{0}\002 on channel \002{1}\002 changed to \002founder only\002."), p->name, ci->GetName()); - else - source.Reply(_("Level for privilege \002{0}\002 on channel \002{1}\002 changed to \002{3}\002."), p->name, ci->GetName(), level); - } + ci->SetLevel(p->name, level); + EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); + + if (level == ChanServ::ACCESS_FOUNDER) + source.Reply(_("Level for privilege \002{0}\002 on channel \002{1}\002 changed to \002founder only\002."), p->name, ci->GetName()); + else + source.Reply(_("Level for privilege \002{0}\002 on channel \002{1}\002 changed to \002{3}\002."), p->name, ci->GetName(), level); } - void DoDisable(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoDisable(CommandSource &source, ChanServ::Channel *ci, const Anope::string &privilege) { - const Anope::string &what = params[2]; + if (privilege.empty()) + { + this->OnSyntaxError(source, "DISABLE"); + return; + } /* Don't allow disabling of the founder level. It would be hard to change it back if you don't have access to use this command */ - if (what.equals_ci("FOUNDER")) + if (privilege.equals_ci("FOUNDER")) { source.Reply(_("You can not disable the founder privilege because it would be impossible to reenable it at a later time.")); return; } - ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(what) : nullptr; - if (p != NULL) + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(privilege) : nullptr; + if (p == nullptr) { - bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable {0}"), p->name); - - ci->SetLevel(p->name, ChanServ::ACCESS_INVALID); - EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID); - - source.Reply(_("Privileged \002{0}\002 disabled on channel \002{1}\002."), p->name, ci->GetName()); + CommandInfo *help = source.service->FindCommand("generic/help"); + if (help) + source.Reply(_("There is no such privilege \002{0}\002. See \002{0}{1} {2} {3}\002 for a list of valid settings."), + privilege, Config->StrictPrivmsg, source.service->nick, help->cname, source.GetCommand()); return; } - CommandInfo *help = source.service->FindCommand("generic/help"); - if (help) - source.Reply(_("There is no such privilege \002{0}\002. See \002{0}{1} {2} {3}\002 for a list of valid settings."), - what, Config->StrictPrivmsg, source.service->nick, help->cname, source.GetCommand()); + logger.Command(source, ci, _("{source} used {command} on {channel} to disable {0}"), p->name); + + ci->SetLevel(p->name, ChanServ::ACCESS_INVALID); + EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID); + + source.Reply(_("Privilege \002{0}\002 disabled on channel \002{1}\002."), p->name, ci->GetName()); } void DoList(CommandSource &source, ChanServ::Channel *ci) @@ -754,8 +760,7 @@ class CommandCSLevels : public Command void DoReset(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to reset all levels")); + logger.Command(source, ci, _("{source} used {command} on {channel} to reset all levels")); ci->ClearLevels(); EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0); @@ -777,33 +782,24 @@ class CommandCSLevels : public Command { const Anope::string &chan = params[0]; const Anope::string &cmd = params[1]; - const Anope::string &what = params.size() > 2 ? params[2] : ""; - const Anope::string &s = params.size() > 3 ? params[3] : ""; + const Anope::string &privilege = params.size() > 2 ? params[2] : ""; + const Anope::string &level = params.size() > 3 ? params[3] : ""; ChanServ::Channel *ci = ChanServ::Find(chan); - if (ci == NULL) + if (ci == nullptr) { source.Reply(_("Channel \002{0}\002 isn't registered."), chan); return; } bool has_access = false; - if (source.HasPriv("chanserv/access/modify")) + if (source.AccessFor(ci).HasPriv("FOUNDER")) has_access = true; - else if (cmd.equals_ci("LIST") && source.HasPriv("chanserv/access/list")) + else if (source.HasOverridePriv("chanserv/access/modify")) has_access = true; - else if (source.AccessFor(ci).HasPriv("FOUNDER")) + else if (cmd.equals_ci("LIST") && source.HasOverridePriv("chanserv/access/list")) has_access = true; - /* If SET, we want two extra parameters; if DIS[ABLE] or FOUNDER, we want only - * one; else, we want none. - */ - if (cmd.equals_ci("SET") ? s.empty() : (cmd.substr(0, 3).equals_ci("DIS") ? (what.empty() || !s.empty()) : !what.empty())) - { - this->OnSyntaxError(source, cmd); - return; - } - if (!has_access) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->GetName()); @@ -817,9 +813,9 @@ class CommandCSLevels : public Command } if (cmd.equals_ci("SET")) - this->DoSet(source, ci, params); + this->DoSet(source, ci, privilege, level); else if (cmd.equals_ci("DIS") || cmd.equals_ci("DISABLE")) - this->DoDisable(source, ci, params); + this->DoDisable(source, ci, privilege); else if (cmd.equals_ci("LIST")) this->DoList(source, ci); else if (cmd.equals_ci("RESET")) diff --git a/modules/chanserv/akick.cpp b/modules/chanserv/akick.cpp index 60d6530e4..d5564e6bf 100644 --- a/modules/chanserv/akick.cpp +++ b/modules/chanserv/akick.cpp @@ -222,9 +222,8 @@ class CommandCSAKick : public Command } } - bool override = !source.AccessFor(ci).HasPriv("AKICK"); /* Opers overriding get to bypass PEACE */ - if (override) + if (source.IsOverride()) ; /* These peace checks are only for masks */ else if (IRCD->IsChannelValid(mask)) @@ -303,9 +302,9 @@ class CommandCSAKick : public Command ak = ci->AddAkick(source.GetNick(), mask, reason); if (reason.empty()) - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0}"), mask); + logger.Command(source, ci, _("{source} used {command} on {channel} to add {0}"), mask); else - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0} ({1})"), mask, reason); + logger.Command(source, ci, _("{source} used {command} on {channel} to add {0} ({1})"), mask, reason); EventManager::Get()->Dispatch(&Event::Akick::OnAkickAdd, source, ci, ak); @@ -317,7 +316,6 @@ class CommandCSAKick : public Command void DoDel(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) { const Anope::string &mask = params[2]; - bool override = !source.AccessFor(ci).HasPriv("AKICK"); if (!ci->GetAkickCount()) { @@ -340,7 +338,7 @@ class CommandCSAKick : public Command EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ak); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), + logger.Command(source, ci, _("{source} used {command} on {channel} to delete {0}"), ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask()); ++deleted; @@ -380,7 +378,7 @@ class CommandCSAKick : public Command return; } - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), + logger.Command(source, ci, _("{source} used {command} on {channel} to delete {0}"), match->GetAccount() ? match->GetAccount()->GetDisplay() : match->GetMask()); EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, match); @@ -530,17 +528,14 @@ class CommandCSAKick : public Command ++count; } - bool override = !source.AccessFor(ci).HasPriv("AKICK"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, - _("{source} used {command} on {channel} to enforce the akick list, affects {0} users"), count); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce the akick list, affects {0} users"), count); source.Reply(_("Autokick enforce for \002{0}\002 complete; \002{1}\002 users were affected."), ci->GetName(), count); } void DoClear(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the akick list")); + logger.Command(source, ci, _("{source} used {command} on {channel} to clear the akick list")); ci->ClearAkick(); source.Reply(_("The autokick list of \002{0}\002 has been cleared."), ci->GetName()); @@ -579,7 +574,7 @@ class CommandCSAKick : public Command return; } - if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasPriv("chanserv/access/modify") && (!is_list || source.HasPriv("chanserv/access/list"))) + if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasOverridePriv("chanserv/access/modify") && (!is_list || source.HasOverridePriv("chanserv/access/list"))) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "AKICK", ci->GetName()); return; diff --git a/modules/chanserv/ban.cpp b/modules/chanserv/ban.cpp index d79afe071..d9105cc49 100644 --- a/modules/chanserv/ban.cpp +++ b/modules/chanserv/ban.cpp @@ -70,7 +70,7 @@ class CommandCSBan : public Command if (IRCD->GetMaxListFor(c) && c->HasMode(mode) >= IRCD->GetMaxListFor(c)) { - source.Reply(_("The %s list for %s is full."), mode.lower().c_str(), c->name.c_str()); + source.Reply(_("The {0} list for {1} is full."), mode.lower(), c->name); return; } @@ -117,7 +117,7 @@ class CommandCSBan : public Command ChanServ::AccessGroup u_access = source.AccessFor(ci); - if (!u_access.HasPriv("BAN") && !source.HasPriv("chanserv/kick")) + if (!u_access.HasPriv("BAN") && !source.HasOverridePriv("chanserv/kick")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "BAN", ci->GetName()); return; @@ -127,7 +127,7 @@ class CommandCSBan : public Command { ChanServ::AccessGroup u2_access = ci->AccessFor(u2); - if (u != u2 && ci->IsPeace() && u2_access >= u_access && !source.HasPriv("chanserv/kick")) + if (u != u2 && ci->IsPeace() && u2_access >= u_access && !source.HasOverridePriv("chanserv/kick")) { source.Reply(_("Access denied. \002{0}\002 has the same or more privileges than you on \002{1}\002."), u2->nick, ci->GetName()); return; @@ -151,8 +151,7 @@ class CommandCSBan : public Command Anope::string mask = ci->GetIdealBan(u2); - bool override = !u_access.HasPriv("BAN") || (u != u2 && ci->IsPeace() && u2_access >= u_access); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} for {0}"), mask); + logger.Command(source, ci, _("{source} used {command} on {channel} for {0}"), mask); if (!c->HasMode(mode, mask)) { @@ -183,12 +182,9 @@ class CommandCSBan : public Command } else { - bool founder = u_access.HasPriv("FOUNDER"); - bool override = !founder && !u_access.HasPriv("BAN"); - Anope::string mask = IRCD->NormalizeMask(target); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} for {0}"), mask); + logger.Command(source, ci, _("{source} used {command} on {channel} for {0}"), mask); if (!c->HasMode(mode, mask)) { @@ -213,7 +209,7 @@ class CommandCSBan : public Command ChanServ::AccessGroup u2_access = ci->AccessFor(uc->user); - if (matched > 1 && !founder) + if (matched > 1 && !u_access.HasPriv("FOUNDER")) continue; if (u != uc->user && ci->IsPeace() && u2_access >= u_access) continue; diff --git a/modules/chanserv/clone.cpp b/modules/chanserv/clone.cpp index 343e6c5b2..a63f33313 100644 --- a/modules/chanserv/clone.cpp +++ b/modules/chanserv/clone.cpp @@ -61,7 +61,6 @@ public: User *u = source.GetUser(); ChanServ::Channel *ci = ChanServ::Find(channel); - bool override = false; if (ci == NULL) { @@ -84,15 +83,11 @@ public: if (!source.IsFounder(ci) || !source.IsFounder(target_ci)) { - if (!source.HasPriv("chanserv/administration")) + if (!source.HasOverridePriv("chanserv/administration")) { source.Reply(_("Access denied. You do not have the privilege \002{0}\002 on \002{1}\002 and \002{2}\002."), "FOUNDER", ci->GetName(), target_ci->GetName()); return; } - else - { - override = true; - } } if (what.equals_ci("ALL")) @@ -209,7 +204,7 @@ public: return; } - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clone {0} to {1}"), + logger.Command(source, ci, _("{source} used {command} on {channel} to clone {0} to {1}"), what.empty() ? "everything from it" : what, target_ci->GetName()); } diff --git a/modules/chanserv/drop.cpp b/modules/chanserv/drop.cpp index 122ac96b8..8ef29eebf 100644 --- a/modules/chanserv/drop.cpp +++ b/modules/chanserv/drop.cpp @@ -52,7 +52,7 @@ class CommandCSDrop : public Command return; } - if ((ci->IsSecureFounder() ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")) && !source.HasCommand("chanserv/drop")) + if ((ci->IsSecureFounder() ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")) && !source.HasOverrideCommand("chanserv/drop")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->GetName()); return; @@ -62,8 +62,7 @@ class CommandCSDrop : public Command if (MOD_RESULT == EVENT_STOP) return; - bool override = (ci->IsSecureFounder() ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} (founder was: {0})"), + logger.Command(source, ci, _("{source} used {command} on {channel} (founder was: {0})"), ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "none"); Reference c = ci->c; diff --git a/modules/chanserv/enforce.cpp b/modules/chanserv/enforce.cpp index 8d41c7af3..a3b99ef67 100644 --- a/modules/chanserv/enforce.cpp +++ b/modules/chanserv/enforce.cpp @@ -24,8 +24,7 @@ class CommandCSEnforce : public Command private: void DoSecureOps(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce secureops")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce secureops")); /* Dirty hack to allow Channel::SetCorrectModes to work ok. * We pretend like SECUREOPS is on so it doesn't ignore that @@ -50,8 +49,7 @@ class CommandCSEnforce : public Command void DoRestricted(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce restricted")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce restricted")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -81,8 +79,7 @@ class CommandCSEnforce : public Command void DoRegOnly(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce registered only")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce registered only")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -113,8 +110,7 @@ class CommandCSEnforce : public Command void DoSSLOnly(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce SSL only")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce SSL only")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -145,8 +141,7 @@ class CommandCSEnforce : public Command void DoBans(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce bans")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce bans")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -174,8 +169,7 @@ class CommandCSEnforce : public Command void DoLimit(CommandSource &source, ChanServ::Channel *ci) { - bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce limit")); + logger.Command(source, ci, _("{source} used {command} on {channel} to enforce limit")); Anope::string l_str; if (!ci->c->GetParam("LIMIT", l_str)) @@ -252,7 +246,7 @@ class CommandCSEnforce : public Command return; } - if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasPriv("chanserv/access/modify")) + if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasOverridePriv("chanserv/access/modify")) { source.Reply("Access denied. You do not have the \002{0}\002 privilege on \002{1}\002.", "AKICK", ci->GetName()); return; diff --git a/modules/chanserv/entrymsg.cpp b/modules/chanserv/entrymsg.cpp index 8867fe6ab..660aacad2 100644 --- a/modules/chanserv/entrymsg.cpp +++ b/modules/chanserv/entrymsg.cpp @@ -152,7 +152,7 @@ class CommandEntryMessage : public Command msg->SetCreator(source.GetNick()); msg->SetMessage(message); - logger.Command(source.AccessFor(ci).HasPriv("SET") ? LogType::COMMAND : LogType::OVERRIDE, source, ci, _("{source} used {command} on {channel} to add a message")); + logger.Command(source, ci, _("{source} used {command} on {channel} to add a message")); source.Reply(_("Entry message added to \002{0}\002"), ci->GetName()); } @@ -180,7 +180,7 @@ class CommandEntryMessage : public Command { messages[i - 1]->Delete(); - logger.Command(source.AccessFor(ci).HasPriv("SET") ? LogType::COMMAND : LogType::OVERRIDE, source, ci, _("{source} used {command} on {channel} to remove a message")); + logger.Command(source, ci, _("{source} used {command} on {channel} to remove a message")); source.Reply(_("Entry message \002{0}\002 for \002{1]\002 deleted."), i, ci->GetName()); } @@ -198,7 +198,7 @@ class CommandEntryMessage : public Command for (EntryMsg *e : ci->GetRefs()) e->Delete(); - logger.Command(source.AccessFor(ci).HasPriv("SET") ? LogType::COMMAND : LogType::OVERRIDE, source, ci, _("{source} used {command} on {channel} to remove all messages")); + logger.Command(source, ci, _("{source} used {command} on {channel} to remove all messages")); source.Reply(_("Entry messages for \002{0}\002 have been cleared."), ci->GetName()); } @@ -230,7 +230,7 @@ class CommandEntryMessage : public Command return; } - if (!source.AccessFor(ci).HasPriv("SET") && !source.HasPriv("chanserv/administration")) + if (!source.AccessFor(ci).HasPriv("SET") && !source.HasOverridePriv("chanserv/administration")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->GetName()); return; diff --git a/modules/chanserv/flags.cpp b/modules/chanserv/flags.cpp index d30d02b4a..6ec65d104 100644 --- a/modules/chanserv/flags.cpp +++ b/modules/chanserv/flags.cpp @@ -160,7 +160,6 @@ class CommandCSFlags : public Command ChanServ::ChanAccess *current = NULL; unsigned current_idx; std::set current_flags; - bool override = false; for (current_idx = ci->GetAccessCount(); current_idx > 0; --current_idx) { ChanServ::ChanAccess *access = ci->GetAccess(current_idx - 1); @@ -172,9 +171,7 @@ class CommandCSFlags : public Command // operator<= on the non-me entry! if (*highest <= *access) { - if (source.HasPriv("chanserv/access/modify")) - override = true; - else + if (!source.HasOverridePriv("chanserv/access/modify")) { source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to modify the access of \002{1}\002."), ci->GetName(), access->Mask()); return; @@ -219,9 +216,7 @@ class CommandCSFlags : public Command if (!u_access.HasPriv(it->first) && !u_access.founder) { - if (source.HasPriv("chanserv/access/modify")) - override = true; - else + if (!source.HasOverridePriv("chanserv/access/modify")) continue; } @@ -245,9 +240,7 @@ class CommandCSFlags : public Command continue; else if (!u_access.HasPriv(it->first) && !u_access.founder) { - if (source.HasPriv("chanserv/access/modify")) - override = true; - else + if (!source.HasOverridePriv("chanserv/access/modify")) { source.Reply(_("You can not set the \002{0}\002 flag."), f); break; @@ -267,7 +260,7 @@ class CommandCSFlags : public Command { EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, current); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), current->Mask()); + logger.Command(source, ci, _("{source} used {command} on {channel} to delete {0}"), current->Mask()); source.Reply(_("\002{0}\002 removed from the access list of \002{1}\002."), current->Mask(), ci->GetName()); @@ -297,7 +290,7 @@ class CommandCSFlags : public Command EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to modify flags of {0} to {1}"), access->Mask(), access->AccessSerialize()); + logger.Command(source, ci, _("{source} used {command} on {channel} to modify flags of {0} to {1}"), access->Mask(), access->AccessSerialize()); if (p != NULL) { @@ -376,7 +369,7 @@ class CommandCSFlags : public Command void DoClear(CommandSource &source, ChanServ::Channel *ci) { - if (!source.IsFounder(ci) && !source.HasPriv("chanserv/access/modify")) + if (!source.IsFounder(ci) && !source.HasOverridePriv("chanserv/access/modify")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->GetName()); return; @@ -388,8 +381,7 @@ class CommandCSFlags : public Command source.Reply(_("The access list of \002{0}\002 has been cleared."), ci->GetName()); - bool override = !source.IsFounder(ci); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the access list")); + logger.Command(source, ci, _("{source} used {command} on {channel} to clear the access list")); } public: diff --git a/modules/chanserv/getkey.cpp b/modules/chanserv/getkey.cpp index 2e6835672..309c6f52d 100644 --- a/modules/chanserv/getkey.cpp +++ b/modules/chanserv/getkey.cpp @@ -39,7 +39,7 @@ class CommandCSGetKey : public Command return; } - if (!source.AccessFor(ci).HasPriv("GETKEY") && !source.HasCommand("chanserv/getkey")) + if (!source.AccessFor(ci).HasPriv("GETKEY") && !source.HasOverrideCommand("chanserv/getkey")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "GETKEY", ci->GetName()); return; @@ -52,8 +52,7 @@ class CommandCSGetKey : public Command return; } - bool override = !source.AccessFor(ci).HasPriv("GETKEY"); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel}")); + logger.Command(source, ci, _("{source} used {command} on {channel}")); source.Reply(_("Key for channel \002{0}\002 is \002{1}\002."), ci->GetName(), key); } diff --git a/modules/chanserv/invite.cpp b/modules/chanserv/invite.cpp index ae6cee04d..6e996dfb7 100644 --- a/modules/chanserv/invite.cpp +++ b/modules/chanserv/invite.cpp @@ -48,7 +48,7 @@ class CommandCSInvite : public Command return; } - if (!source.AccessFor(ci).HasPriv("INVITE") && !source.HasCommand("chanserv/invite")) + if (!source.AccessFor(ci).HasPriv("INVITE") && !source.HasOverrideCommand("chanserv/invite")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "INVITE", ci->GetName()); return; @@ -76,19 +76,17 @@ class CommandCSInvite : public Command return; } - bool override = !source.AccessFor(ci).HasPriv("INVITE"); - IRCD->Send(ci->WhoSends(), c, u2); if (u2 != u) { source.Reply(_("\002{0}\002 has been invited to \002{1}\002."), u2->nick, c->name); u2->SendMessage(ci->WhoSends(), _("You have been invited to \002{0}\002 by \002{1}\002."), c->name, source.GetNick()); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to invite {0}"), u2->nick); + logger.Command(source, ci, _("{source} used {command} on {channel} to invite {0}"), u2->nick); } else { u2->SendMessage(ci->WhoSends(), _("You have been invited to \002{0}\002."), c->name); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel}")); + logger.Command(source, ci, _("{source} used {command} on {channel}")); } } diff --git a/modules/chanserv/kick.cpp b/modules/chanserv/kick.cpp index fad7b9158..0c1333796 100644 --- a/modules/chanserv/kick.cpp +++ b/modules/chanserv/kick.cpp @@ -61,7 +61,7 @@ class CommandCSKick : public Command Anope::string signkickformat = Config->GetModule("chanserv/main")->Get("signkickformat", "%m (%n)"); signkickformat = signkickformat.replace_all_cs("%n", source.GetNick()); - if (!u_access.HasPriv("KICK") && !source.HasPriv("chanserv/kick")) + if (!u_access.HasPriv("KICK") && !source.HasOverridePriv("chanserv/kick")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "KICK", ci->GetName()); return; @@ -70,26 +70,34 @@ class CommandCSKick : public Command if (u2) { ChanServ::AccessGroup u2_access = ci->AccessFor(u2); - if (u != u2 && ci->IsPeace() && u2_access >= u_access && !source.HasPriv("chanserv/kick")) + if (u != u2 && ci->IsPeace() && u2_access >= u_access && !source.HasOverridePriv("chanserv/kick")) + { source.Reply(_("Access denied. \002{0}\002 has the same or more privileges than you on \002{1}\002."), u2->nick, ci->GetName()); - else if (u2->IsProtected()) + return; + } + + if (u2->IsProtected()) + { source.Reply(_("Access denied. \002{0}\002 is protected and can not be kicked."), u2->nick); - else if (!c->FindUser(u2)) + return; + } + + if (!c->FindUser(u2)) + { source.Reply(_("User \002{0}\002 is not on channel \002{1}\002."), u2->nick, c->name); + return; + } + + logger.Command(source, ci, _("{source} used {command} on {channel} for {0}"), u2->nick); + + if (ci->IsSignKick() || (ci->IsSignKickLevel() && !u_access.HasPriv("SIGNKICK"))) + { + signkickformat = signkickformat.replace_all_cs("%m", reason); + c->Kick(ci->WhoSends(), u2, signkickformat); + } else { - bool override = !u_access.HasPriv("KICK") || (u != u2 && ci->IsPeace() && u2_access >= u_access); - logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} for {0}"), u2->nick); - - if (ci->IsSignKick() || (ci->IsSignKickLevel() && !u_access.HasPriv("SIGNKICK"))) - { - signkickformat = signkickformat.replace_all_cs("%m", reason); - c->Kick(ci->WhoSends(), u2, signkickformat); - } - else - { - c->Kick(ci->WhoSends(), u2, reason); - } + c->Kick(ci->WhoSends(), u2, reason); } } else if (u_access.HasPriv("FOUNDER")) diff --git a/modules/chanserv/list.cpp b/modules/chanserv/list.cpp index 4c6712b67..b0675b51e 100644 --- a/modules/chanserv/list.cpp +++ b/modules/chanserv/list.cpp @@