summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Bindings/PluginManager.cpp28
-rw-r--r--src/Bindings/PluginManager.h14
2 files changed, 19 insertions, 23 deletions
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index f9035e869..abbb05ae0 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -257,18 +257,13 @@ bool cPluginManager::CallHookBlockToPickups(
bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message)
{
- bool WasCommandForbidden = false;
- if (HandleCommand(a_Player, a_Message, true, WasCommandForbidden)) // We use HandleCommand as opposed to ExecuteCommand to accomodate the need to the WasCommandForbidden bool
+ if (HandleCommand(a_Player, a_Message, true) != crUnknownCommand) // We use HandleCommand as opposed to ExecuteCommand to accomodate the need to the WasCommandForbidden bool
{
return true; // Chat message was handled as command
}
- else if (WasCommandForbidden) // Couldn't be handled as command, was it because of insufficient permissions?
- {
- return true; // Yes - message was sent in HandleCommand, abort
- }
// Check if it was a standard command (starts with a slash)
- // If it was, we know that it was completely unrecognised (WasCommandForbidden == false)
+ // If it was, we know that it was completely unrecognised
if (!a_Message.empty() && (a_Message[0] == '/'))
{
AStringVector Split(StringSplit(a_Message, " "));
@@ -1318,28 +1313,28 @@ bool cPluginManager::CallHookWorldTick(cWorld & a_World, float a_Dt, int a_LastT
-bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden)
+cPluginManager::CommandResult cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions)
{
ASSERT(a_Player != NULL);
AStringVector Split(StringSplit(a_Command, " "));
if (Split.empty())
{
- return false;
+ return crUnknownCommand;
}
CommandMap::iterator cmd = m_Commands.find(Split[0]);
if (cmd == m_Commands.end())
{
// Command not found
- return false;
+ return crUnknownCommand;
}
// Ask plugins first if a command is okay to execute the command:
if (CallHookExecuteCommand(a_Player, Split))
{
LOGINFO("Player %s tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player->GetName().c_str(), Split[0].c_str());
- return false;
+ return crError;
}
if (
@@ -1350,8 +1345,7 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command
{
a_Player->SendMessageFailure(Printf("Forbidden command; insufficient privileges: \"%s\"", Split[0].c_str()));
LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player->GetName().c_str(), Split[0].c_str());
- a_WasCommandForbidden = true;
- return false;
+ return crError;
}
ASSERT(cmd->second.m_Plugin != NULL);
@@ -1359,10 +1353,10 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command
if (!cmd->second.m_Plugin->HandleCommand(Split, a_Player))
{
a_Player->SendMessageFailure(Printf("Something went wrong while executing command \"%s\"", Split[0].c_str()));
- return true; // The command handler was found and executed, so we return true.
+ return crError;
}
- return true;
+ return crExecuted;
}
@@ -1561,7 +1555,7 @@ AString cPluginManager::GetCommandPermission(const AString & a_Command)
bool cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Command)
{
- return HandleCommand(a_Player, a_Command, true);
+ return (HandleCommand(a_Player, a_Command, true) == crExecuted);
}
@@ -1570,7 +1564,7 @@ bool cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Comman
bool cPluginManager::ForceExecuteCommand(cPlayer * a_Player, const AString & a_Command)
{
- return HandleCommand(a_Player, a_Command, false);
+ return (HandleCommand(a_Player, a_Command, false) == crExecuted);
}
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index 0b0498280..049e70b49 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -58,6 +58,13 @@ public: // tolua_export
// Called each tick
virtual void Tick(float a_Dt);
+ enum CommandResult
+ {
+ crExecuted,
+ crUnknownCommand,
+ crError,
+ } ;
+
// tolua_begin
enum PluginHook
{
@@ -322,12 +329,7 @@ private:
bool AddPlugin(cPlugin * a_Plugin);
/** Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns true if the command is executed. */
- bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden);
- bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions)
- {
- bool DummyBoolean = false;
- return HandleCommand(a_Player, a_Command, a_ShouldCheckPermissions, DummyBoolean);
- }
+ cPluginManager::CommandResult HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions);
} ; // tolua_export