summaryrefslogtreecommitdiffstats
path: root/src/Bindings/PluginManager.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-07-04 15:41:48 +0200
committermadmaxoft <github@xoft.cz>2014-07-04 15:41:48 +0200
commit8f65d13d1bff2b7747a88041ad86e6c5838b0e3c (patch)
tree9f397e8d0bc629d32f54ca10c0ebb735723370eb /src/Bindings/PluginManager.cpp
parentFixed c1deda5d8f01811efa5094e9375166acb69d50ed (diff)
parentRemoved useless sentence in cPluginManager:ExecuteCommand description. (diff)
downloadcuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.tar
cuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.tar.gz
cuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.tar.bz2
cuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.tar.lz
cuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.tar.xz
cuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.tar.zst
cuberite-8f65d13d1bff2b7747a88041ad86e6c5838b0e3c.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/PluginManager.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 3cb8c99a1..45bcc61cd 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -257,18 +257,17 @@ 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
+ switch (HandleCommand(a_Player, a_Message, true))
{
- 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
+ case crExecuted: return true;
+ case crError: a_Player->SendMessageFailure(Printf("Something went wrong while executing command \"%s\"", a_Message.c_str())); return true;
+ case crBlocked: return true; // The plugin that blocked the command probably wants to send a message to the player.
+ case crNoPermission: a_Player->SendMessageFailure(Printf("Forbidden command; insufficient privileges: \"%s\"", a_Message.c_str())); return true;
+ case crUnknownCommand: break;
}
// 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, " "));
@@ -1337,28 +1336,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 crBlocked;
}
if (
@@ -1367,15 +1366,18 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command
!a_Player->HasPermission(cmd->second.m_Permission)
)
{
- 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 crNoPermission;
}
ASSERT(cmd->second.m_Plugin != NULL);
- return cmd->second.m_Plugin->HandleCommand(Split, a_Player);
+ if (!cmd->second.m_Plugin->HandleCommand(Split, a_Player))
+ {
+ return crError;
+ }
+
+ return crExecuted;
}
@@ -1573,7 +1575,7 @@ AString cPluginManager::GetCommandPermission(const AString & a_Command)
-bool cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Command)
+cPluginManager::CommandResult cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Command)
{
return HandleCommand(a_Player, a_Command, true);
}
@@ -1582,7 +1584,7 @@ bool cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Comman
-bool cPluginManager::ForceExecuteCommand(cPlayer * a_Player, const AString & a_Command)
+cPluginManager::CommandResult cPluginManager::ForceExecuteCommand(cPlayer * a_Player, const AString & a_Command)
{
return HandleCommand(a_Player, a_Command, false);
}