diff options
author | Adam <Adam@anope.org> | 2012-06-18 05:04:30 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-06-18 05:04:30 -0400 |
commit | 2dec8e767a70def4b9b04a96ae4f75e4d1013038 (patch) | |
tree | 36f5b551ff359a578e17d5e7d2f486970d759a7b /src/logger.cpp | |
parent | 873d4287de57f7f9caa23cb2c9265d1ad2804aba (diff) |
Allow userless command sources
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/logger.cpp b/src/logger.cpp index 1b7c48f78..d18b0731e 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -75,7 +75,7 @@ Anope::string LogFile::GetName() const return this->filename; } -Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(type), Category(category) +Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(type), Category(category) { if (!bi && Config) bi = findbot(Config->Global); @@ -83,9 +83,9 @@ Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), this->Sources.push_back(bi->nick); } -Log::Log(LogType type, const User *_u, Command *_c, const ChannelInfo *_ci) : u(_u), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) +Log::Log(LogType type, const CommandSource &source, Command *_c, const ChannelInfo *_ci) : u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) { - if (!u || !c) + if (!c) throw CoreException("Invalid pointers passed to Log::Log"); if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN) @@ -100,13 +100,14 @@ Log::Log(LogType type, const User *_u, Command *_c, const ChannelInfo *_ci) : u( this->Category = c->name; if (this->bi) this->Sources.push_back(this->bi->nick); - this->Sources.push_back(u->nick); + if (u) + this->Sources.push_back(u->nick); this->Sources.push_back(c->name); if (ci) this->Sources.push_back(ci->name); } -Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), u(_u), c(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), Type(LOG_CHANNEL) +Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), u(_u), nc(NULL), c(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), Type(LOG_CHANNEL) { if (!chan) throw CoreException("Invalid pointers passed to Log::Log"); @@ -121,7 +122,7 @@ Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), this->Sources.push_back(chan->name); } -Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(_u), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category) +Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category) { if (!u) throw CoreException("Invalid pointers passed to Log::Log"); @@ -133,7 +134,7 @@ Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi this->Sources.push_back(u->nick); } -Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category) +Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category) { if (!s) throw CoreException("Invalid pointer passed to Log::Log"); @@ -147,7 +148,7 @@ Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_ this->Sources.push_back(s->GetName()); } -Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category) +Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category) { if (!this->bi && Config) this->bi = findbot(Config->Global); @@ -179,36 +180,45 @@ Anope::string Log::BuildPrefix() const { case LOG_ADMIN: { - if (!this->c || !this->u) + if (!this->c && !(this->u || this->nc)) break; buffer += "ADMIN: "; size_t sl = this->c->name.find('/'); Anope::string cname = sl != Anope::string::npos ? this->c->name.substr(sl + 1) : this->c->name; - buffer += this->u->GetMask() + " used " + cname + " "; + if (this->u) + buffer += this->u->GetMask() + " used " + cname + " "; + else if (this->nc) + buffer += this->nc->display + " used " + cname + " "; if (this->ci) buffer += "on " + this->ci->name + " "; break; } case LOG_OVERRIDE: { - if (!this->c || !this->u) + if (!this->c && !(this->u || this->nc)) break; buffer += "OVERRIDE: "; size_t sl = this->c->name.find('/'); Anope::string cname = sl != Anope::string::npos ? this->c->name.substr(sl + 1) : this->c->name; - buffer += this->u->GetMask() + " used " + cname + " "; + if (this->u) + buffer += this->u->GetMask() + " used " + cname + " "; + else if (this->nc) + buffer += this->nc->display + " used " + cname + " "; if (this->ci) buffer += "on " + this->ci->name + " "; break; } case LOG_COMMAND: { - if (!this->c || !this->u) + if (!this->c || !(this->u || this->nc)) break; buffer += "COMMAND: "; size_t sl = this->c->name.find('/'); Anope::string cname = sl != Anope::string::npos ? this->c->name.substr(sl + 1) : this->c->name; - buffer += this->u->GetMask() + " used " + cname + " "; + if (this->u) + buffer += this->u->GetMask() + " used " + cname + " "; + else if (this->nc) + buffer += this->nc->display + " used " + cname + " "; if (this->ci) buffer += "on " + this->ci->name + " "; break; |