1
0

Advanced RCON: Command output is sent to the RCON client.

RCON authentication is now required before executing commands.
Console command handlers now return two values, bool (IsHandled) and string (CommandOutput).
API change: removed cRoot:ExecuteConsoleCommand(), added cRoot:QueueExecuteConsoleCommand().
API change: removed cPluginManager:ExecuteConsoleCommand(), use cRoot:QueueExecuteConsoleCommand() instead

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1631 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2013-06-29 15:30:05 +00:00
parent cff6ff2223
commit 7b75aaea7c
22 changed files with 599 additions and 258 deletions

View File

@@ -3,7 +3,7 @@
#define LUA_USE_POSIX
#include "Plugin_NewLua.h"
#include "MCLogger.h"
#include "CommandOutput.h"
extern "C"
{
@@ -1378,13 +1378,15 @@ bool cPlugin_NewLua::HandleCommand(const AStringVector & a_Split, cPlayer * a_Pl
bool cPlugin_NewLua::HandleConsoleCommand(const AStringVector & a_Split)
bool cPlugin_NewLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
{
ASSERT(!a_Split.empty());
CommandMap::iterator cmd = m_ConsoleCommands.find(a_Split[0]);
if (cmd == m_ConsoleCommands.end())
{
LOGWARNING("Console command handler is registered in cPluginManager but not in cPlugin, wtf? Console command \"%s\".", a_Split[0].c_str());
LOGWARNING("Console command handler is registered in cPluginManager but not in cPlugin, wtf? Console command \"%s\", plugin \"%s\".",
a_Split[0].c_str(), GetName().c_str()
);
return false;
}
@@ -1407,16 +1409,21 @@ bool cPlugin_NewLua::HandleConsoleCommand(const AStringVector & a_Split)
}
// Call function:
int s = lua_pcall(m_LuaState, 1, 1, 0);
int s = lua_pcall(m_LuaState, 1, 2, 0);
if (report_errors(m_LuaState, s))
{
LOGERROR("Lua error. Stack size: %i", lua_gettop(m_LuaState));
return false;
}
// Handle return value:
bool RetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1); // Pop return value
// Handle return values:
if (lua_isstring(m_LuaState, -1))
{
AString str = tolua_tocppstring(m_LuaState, -1, "");
a_Output.Out(str);
}
bool RetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0);
lua_pop(m_LuaState, 2); // Pop return values
return RetVal;
}