diff options
author | Adam <Adam@anope.org> | 2012-12-19 16:03:53 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-12-19 16:03:53 -0500 |
commit | 276247b463ab0731c1476c94adc247a2934960b3 (patch) | |
tree | 8d9b99f32e58e0e580dbcbd0ab4e36867df4dfa8 | |
parent | 67bd2c6b2da0d66dc7874dabbc8c9d2136efeb94 (diff) |
Add a command flag to require that a user is executing the command
-rw-r--r-- | include/commands.h | 8 | ||||
-rw-r--r-- | modules/commands/cs_updown.cpp | 6 | ||||
-rw-r--r-- | modules/commands/hs_off.cpp | 4 | ||||
-rw-r--r-- | modules/commands/hs_on.cpp | 7 | ||||
-rw-r--r-- | modules/commands/ns_group.cpp | 9 | ||||
-rw-r--r-- | modules/commands/ns_identify.cpp | 6 | ||||
-rw-r--r-- | modules/commands/ns_update.cpp | 4 | ||||
-rw-r--r-- | modules/commands/os_login.cpp | 10 | ||||
-rw-r--r-- | src/command.cpp | 5 |
9 files changed, 25 insertions, 34 deletions
diff --git a/include/commands.h b/include/commands.h index e390fb3d3..6935db576 100644 --- a/include/commands.h +++ b/include/commands.h @@ -18,8 +18,14 @@ enum CommandFlag { + /* Command allow unidentified users to use it */ CFLAG_ALLOW_UNREGISTERED, - CFLAG_STRIP_CHANNEL + + /* Command's first parameter is a channel name */ + CFLAG_STRIP_CHANNEL, + + /* Command requires a user to execute */ + CFLAG_REQUIRE_USER }; /* Used in BotInfo::commands */ diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 6d46c873e..7504c3601 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -18,6 +18,7 @@ class CommandCSUp : public Command public: CommandCSUp(Module *creator) : Command(creator, "chanserv/up", 0, 1) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Updates your status on a channel")); this->SetSyntax(_("[\037channel\037]")); } @@ -25,8 +26,6 @@ class CommandCSUp : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - if (!u) - return; if (params.empty()) for (UChannelList::iterator it = u->chans.begin(); it != u->chans.end(); ++it) @@ -75,6 +74,7 @@ class CommandCSDown : public Command public: CommandCSDown(Module *creator) : Command(creator, "chanserv/down", 0, 1) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Removes your status from a channel")); this->SetSyntax(_("[\037channel\037]")); } @@ -82,8 +82,6 @@ class CommandCSDown : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - if (!u) - return; if (params.empty()) for (UChannelList::iterator it = u->chans.begin(); it != u->chans.end(); ++it) diff --git a/modules/commands/hs_off.cpp b/modules/commands/hs_off.cpp index 27c6c0756..3ca6cc148 100644 --- a/modules/commands/hs_off.cpp +++ b/modules/commands/hs_off.cpp @@ -18,6 +18,7 @@ class CommandHSOff : public Command public: CommandHSOff(Module *creator) : Command(creator, "hostserv/off", 0, 0) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Deactivates your assigned vhost")); this->SetSyntax(""); } @@ -25,9 +26,6 @@ class CommandHSOff : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - if (!u) - return; - const NickAlias *na = NickAlias::Find(u->nick); if (!na || !na->HasVhost()) diff --git a/modules/commands/hs_on.cpp b/modules/commands/hs_on.cpp index c4cf2fee8..9417ac2be 100644 --- a/modules/commands/hs_on.cpp +++ b/modules/commands/hs_on.cpp @@ -18,18 +18,17 @@ class CommandHSOn : public Command public: CommandHSOn(Module *creator) : Command(creator, "hostserv/on", 0, 0) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Activates your assigned vhost")); this->SetSyntax(""); } void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = source.GetUser(); - if (!u) - return; - else if (!IRCD->CanSetVHost) + if (!IRCD->CanSetVHost) return; // HostServ wouldn't even be loaded at this point + User *u = source.GetUser(); const NickAlias *na = NickAlias::Find(u->nick); if (na && u->Account() == na->nc && na->HasVhost()) { diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp index ff4d5029e..59a0b603c 100644 --- a/modules/commands/ns_group.cpp +++ b/modules/commands/ns_group.cpp @@ -78,6 +78,7 @@ class CommandNSGroup : public Command public: CommandNSGroup(Module *creator) : Command(creator, "nickserv/group", 1, 2) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetFlag(CFLAG_ALLOW_UNREGISTERED); this->SetDesc(_("Join a group")); this->SetSyntax(_("\037target\037 \037password\037")); @@ -86,10 +87,6 @@ class CommandNSGroup : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - - if (!u) - return; - const Anope::string &nick = params[0]; const Anope::string &pass = params.size() > 1 ? params[1] : ""; @@ -206,6 +203,7 @@ class CommandNSUngroup : public Command public: CommandNSUngroup(Module *creator) : Command(creator, "nickserv/ungroup", 0, 1) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Remove a nick from a group")); this->SetSyntax(_("[\037nick\037]")); } @@ -213,9 +211,6 @@ class CommandNSUngroup : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - if (!u) - return; - Anope::string nick = !params.empty() ? params[0] : ""; NickAlias *na = NickAlias::Find(!nick.empty() ? nick : u->nick); diff --git a/modules/commands/ns_identify.cpp b/modules/commands/ns_identify.cpp index f1e0a7d3d..315e474f5 100644 --- a/modules/commands/ns_identify.cpp +++ b/modules/commands/ns_identify.cpp @@ -65,6 +65,7 @@ class CommandNSIdentify : public Command CommandNSIdentify(Module *creator) : Command(creator, "nickserv/identify", 1, 2) { this->SetFlag(CFLAG_ALLOW_UNREGISTERED); + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Identify yourself with your password")); this->SetSyntax(_("[\037account\037] \037password\037")); } @@ -73,9 +74,6 @@ class CommandNSIdentify : public Command { User *u = source.GetUser(); - if (!u) - return; - const Anope::string &nick = params.size() == 2 ? params[0] : u->nick; Anope::string pass = params[params.size() - 1]; @@ -87,7 +85,7 @@ class CommandNSIdentify : public Command else { NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass); - FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(source.GetUser(), req)); + FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(u, req)); req->Dispatch(); } return; diff --git a/modules/commands/ns_update.cpp b/modules/commands/ns_update.cpp index 8f4812b9e..3786413d3 100644 --- a/modules/commands/ns_update.cpp +++ b/modules/commands/ns_update.cpp @@ -18,6 +18,7 @@ class CommandNSUpdate : public Command public: CommandNSUpdate(Module *creator) : Command(creator, "nickserv/update", 0, 0) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(_("Updates your current status, i.e. it checks for new memos")); this->SetSyntax(""); } @@ -25,9 +26,6 @@ class CommandNSUpdate : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - if (!u) - return; - NickAlias *na = NickAlias::Find(u->nick); if (na && na->nc == source.GetAccount()) diff --git a/modules/commands/os_login.cpp b/modules/commands/os_login.cpp index 735562819..ad0430f74 100644 --- a/modules/commands/os_login.cpp +++ b/modules/commands/os_login.cpp @@ -19,6 +19,7 @@ class CommandOSLogin : public Command public: CommandOSLogin(Module *creator) : Command(creator, "operserv/login", 1, 1) { + this->SetFlag(CFLAG_REQUIRE_USER); this->SetDesc(Anope::printf(_("Login to %s"), Config->OperServ.c_str())); this->SetSyntax(_("\037password\037")); } @@ -28,9 +29,6 @@ class CommandOSLogin : public Command const Anope::string &password = params[0]; User *u = source.GetUser(); - if (!u) - return; - Oper *o = source.nc->o; if (o == NULL) source.Reply(_("No oper block for your nick.")); @@ -69,16 +67,14 @@ class CommandOSLogout : public Command public: CommandOSLogout(Module *creator) : Command(creator, "operserv/logout", 0, 0) { - this->SetDesc(Anope::printf(_("Logout from to %s"), Config->OperServ.c_str())); + this->SetFlag(CFLAG_REQUIRE_USER); + this->SetDesc(Anope::printf(_("Logout from %s"), Config->OperServ.c_str())); this->SetSyntax(""); } void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override { User *u = source.GetUser(); - if (!u) - return; - Oper *o = source.nc->o; if (o == NULL) source.Reply(_("No oper block for your nick.")); diff --git a/src/command.cpp b/src/command.cpp index 92991e38b..887967626 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -18,7 +18,7 @@ #include "regchannel.h" #include "channels.h" -static const Anope::string CommandFlagString[] = { "CFLAG_ALLOW_UNREGISTERED", "CFLAG_STRIP_CHANNEL", "" }; +static const Anope::string CommandFlagString[] = { "CFLAG_ALLOW_UNREGISTERED", "CFLAG_STRIP_CHANNEL", "CFLAG_REQUIRE_USER", "" }; 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), @@ -218,6 +218,9 @@ void RunCommand(CommandSource &source, const Anope::string &message) return; } + if (c->HasFlag(CFLAG_REQUIRE_USER) && !source.GetUser()) + return; + // Command requires registered users only if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !source.nc) { |