diff options
Diffstat (limited to 'src/command.cpp')
-rw-r--r-- | src/command.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/command.cpp b/src/command.cpp index 92991e38b..36bab658f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1,7 +1,7 @@ /* * * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org> - * Copyright (C) 2008-2012 Anope Team <team@anope.org> + * Copyright (C) 2008-2013 Anope Team <team@anope.org> * * Please read COPYING and README for further details. * @@ -18,9 +18,6 @@ #include "regchannel.h" #include "channels.h" -static const Anope::string CommandFlagString[] = { "CFLAG_ALLOW_UNREGISTERED", "CFLAG_STRIP_CHANNEL", "" }; -template<> const Anope::string* Flags<CommandFlag>::flags_strings = CommandFlagString; - CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) { @@ -90,7 +87,7 @@ bool CommandSource::IsServicesOper() bool CommandSource::IsOper() { if (this->u) - return this->u->HasMode(UMODE_OPER); + return this->u->HasMode("OPER"); else if (this->nc) return this->nc->IsServicesOper(); return false; @@ -123,6 +120,7 @@ void CommandSource::Reply(const Anope::string &message) 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) { + allow_unregistered = require_user = false; } Command::~Command() @@ -160,6 +158,26 @@ void Command::SendSyntax(CommandSource &source, const Anope::string &syn) source.Reply(MORE_INFO, Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str(), source.command.c_str()); } +bool Command::AllowUnregistered() const +{ + return this->allow_unregistered; +} + +void Command::AllowUnregistered(bool b) +{ + this->allow_unregistered = b; +} + +bool Command::RequireUser() const +{ + return this->require_user; +} + +void Command::RequireUser(bool b) +{ + this->require_user = b; +} + const Anope::string &Command::GetDesc() const { return this->desc; @@ -218,8 +236,11 @@ void RunCommand(CommandSource &source, const Anope::string &message) return; } + if (c->RequireUser() && !source.GetUser()) + return; + // Command requires registered users only - if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !source.nc) + if (!c->AllowUnregistered() && !source.nc) { source.Reply(NICK_IDENTIFY_REQUIRED); if (source.GetUser()) @@ -259,13 +280,10 @@ void RunCommand(CommandSource &source, const Anope::string &message) return; } - bool had_u = source.GetUser(), had_nc = source.nc; - Reference<User> user_reference(source.GetUser()); Reference<NickCore> nc_reference(source.nc); c->Execute(source, params); - if (had_u == user_reference && had_nc == nc_reference) - { - FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params)); - } + if (!nc_reference) + source.nc = NULL; + FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params)); } |