diff options
Diffstat (limited to 'src/command.cpp')
| -rw-r--r-- | src/command.cpp | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/src/command.cpp b/src/command.cpp index 6aa2f744b..59db22a4b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -12,13 +12,15 @@ #include "users.h" #include "language.h" #include "config.h" -#include "bots.h" #include "opertype.h" -#include "access.h" -#include "regchannel.h" #include "channels.h" +#include "event.h" +#include "bots.h" +#include "protocol.h" +#include "modules/botserv.h" +#include "modules/chanserv.h" -CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), +CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) { } @@ -33,25 +35,25 @@ User *CommandSource::GetUser() return this->u; } -NickCore *CommandSource::GetAccount() +NickServ::Account *CommandSource::GetAccount() { return this->nc; } -AccessGroup CommandSource::AccessFor(ChannelInfo *ci) +ChanServ::AccessGroup CommandSource::AccessFor(ChanServ::Channel *ci) { if (this->u) return ci->AccessFor(this->u); else if (this->nc) return ci->AccessFor(this->nc); else - return AccessGroup(); + return ChanServ::AccessGroup(); } -bool CommandSource::IsFounder(ChannelInfo *ci) +bool CommandSource::IsFounder(ChanServ::Channel *ci) { if (this->u) - return ::IsFounder(this->u, ci); + return ci->IsFounder(this->u); else if (this->nc) return *this->nc == ci->GetFounder(); return false; @@ -93,21 +95,6 @@ bool CommandSource::IsOper() return false; } -void CommandSource::Reply(const char *message, ...) -{ - va_list args; - char buf[4096]; // Messages can be really big. - - const char *translated_message = Language::Translate(this->nc, message); - - va_start(args, message); - vsnprintf(buf, sizeof(buf), translated_message, args); - - this->Reply(Anope::string(buf)); - - va_end(args); -} - void CommandSource::Reply(const Anope::string &message) { const char *translated_message = Language::Translate(this->nc, message.c_str()); @@ -115,7 +102,7 @@ void CommandSource::Reply(const Anope::string &message) sepstream sep(translated_message, '\n', true); Anope::string tok; while (sep.GetToken(tok)) - this->reply->SendMessage(this->service, tok); + this->reply->SendMessage(*this->service, tok); } Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(owner) @@ -147,13 +134,13 @@ void Command::SendSyntax(CommandSource &source) Anope::string s = Language::Translate(source.GetAccount(), _("Syntax")); if (!this->syntax.empty()) { - source.Reply("%s: \002%s %s\002", s.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[0].c_str())); + source.Reply("{0}: \002{1} {2}\002", s, source.command, Language::Translate(source.GetAccount(), this->syntax[0].c_str())); Anope::string spaces(s.length(), ' '); for (unsigned i = 1, j = this->syntax.size(); i < j; ++i) - source.Reply("%s \002%s %s\002", spaces.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[i].c_str())); + source.Reply("{0} \002{1} {2}\002", spaces, source.command, Language::Translate(source.GetAccount(), this->syntax[i].c_str())); } else - source.Reply("%s: \002%s\002", s.c_str(), source.command.c_str()); + source.Reply("{0}: \002{1}\002", s, source.command); } bool Command::AllowUnregistered() const @@ -183,7 +170,7 @@ const Anope::string Command::GetDesc(CommandSource &) const void Command::OnServHelp(CommandSource &source) { - source.Reply(" %-14s %s", source.command.c_str(), Language::Translate(source.nc, this->GetDesc(source).c_str())); + source.Reply(Anope::printf(" %-14s %s", source.command.c_str(), Language::Translate(source.nc, this->GetDesc(source).c_str()))); } bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; } @@ -193,7 +180,7 @@ void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcomma this->SendSyntax(source); bool has_help = source.service->commands.find("HELP") != source.service->commands.end(); if (has_help) - source.Reply(MORE_INFO, Config->StrictPrivmsg.c_str(), source.service->nick.c_str(), source.command.c_str()); + source.Reply(_("\002{0}{1} HELP {2}\002 for more information."), Config->StrictPrivmsg, source.service->nick, source.command); } void Command::Run(CommandSource &source, const Anope::string &message) @@ -242,7 +229,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) // Command requires registered users only if (!c->AllowUnregistered() && !source.nc) { - source.Reply(NICK_IDENTIFY_REQUIRED); + source.Reply(_("Password authentication required for that command.")); if (source.GetUser()) Log(LOG_NORMAL, "access_denied_unreg", source.service) << "Access denied for unregistered user " << source.GetUser()->GetMask() << " with command " << it->first; return; @@ -261,7 +248,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) source.permission = info.permission; EventReturn MOD_RESULT; - FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, c, params)); + MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, c, params); if (MOD_RESULT == EVENT_STOP) return; @@ -274,14 +261,17 @@ void Command::Run(CommandSource &source, const Anope::string &message) // If the command requires a permission, and they aren't registered or don't have the required perm, DENIED if (!info.permission.empty() && !source.HasCommand(info.permission)) { - source.Reply(ACCESS_DENIED); + if (!source.IsOper()) + source.Reply(_("Access denied. You are not a Services Operator.")); + else + source.Reply(_("Access denied. You do not have access to command \002{0}\002."), info.permission); if (source.GetUser()) Log(LOG_NORMAL, "access_denied", source.service) << "Access denied for user " << source.GetUser()->GetMask() << " with command " << it->first; return; } c->Execute(source, params); - FOREACH_MOD(OnPostCommand, (source, c, params)); + Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, c, params); } bool Command::FindCommandFromService(const Anope::string &command_service, BotInfo* &bot, Anope::string &name) @@ -305,7 +295,7 @@ bool Command::FindCommandFromService(const Anope::string &command_service, BotIn return true; } } - + return false; } |
