diff options
| author | 2026-03-05 04:20:52 +0000 | |
|---|---|---|
| committer | 2026-03-06 14:54:25 +0000 | |
| commit | ae03e3c32bc77fc6903209083c88698fe291e279 (patch) | |
| tree | a967e6d3c6a37b37a1e673ff4db2cd9e3a6b181e /src/commands.cpp | |
| parent | Add oper-only options to the class and server extbans. (diff) | |
| download | inspircd++-ae03e3c32bc77fc6903209083c88698fe291e279.tar.gz inspircd++-ae03e3c32bc77fc6903209083c88698fe291e279.tar.bz2 inspircd++-ae03e3c32bc77fc6903209083c88698fe291e279.zip | |
Deduplicate command usability checks into Command::IsUsableBy.
Diffstat (limited to 'src/commands.cpp')
| -rw-r--r-- | src/commands.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index bb0648539..ac1219a24 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -114,29 +114,9 @@ CmdResult CommandParser::CallHandler(const std::string& commandname, const Comma if (parameters.size() >= handler->min_params) { - bool bOkay = false; + bool bOkay = true; if (IS_LOCAL(user)) - { - switch (handler->access_needed) - { - case CmdAccess::NORMAL: // Anyone can execute. - bOkay = true; - break; - - case CmdAccess::OPERATOR: // Only opers can execute. - bOkay = user->HasCommandPermission(commandname); - break; - - case CmdAccess::SERVER: // Only servers can execute. - bOkay = IS_SERVER(user); - break; - } - } - else - { - /* remote or no flags required anyway */ - bOkay = true; - } + bOkay = handler->IsUsableBy(user); if (bOkay) { @@ -440,6 +420,22 @@ void Command::RegisterService() throw ModuleException(creator, "Command already exists: " + name); } +bool Command::IsUsableBy(User *user) const +{ + switch (this->access_needed) + { + case CmdAccess::NORMAL: // Everyone can use user commands. + return true; + + case CmdAccess::OPERATOR: // Only opers can use oper commands. + return user->HasCommandPermission(this->name); + + case CmdAccess::SERVER: // Nobody can use server commands. + return false; + } + return true; // Should never happen. +} + void Command::TellNotEnoughParameters(LocalUser* user, const Params& parameters) { user->WriteNumeric(ERR_NEEDMOREPARAMS, name, "Not enough parameters."); |
