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 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'include') 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)...); -- cgit