1
0
cuberite-2a/source/CommandOutput.cpp
madmaxoft@gmail.com 7b75aaea7c 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
2013-06-29 15:30:05 +00:00

72 lines
1.3 KiB
C++

// CommandOutput.cpp
// Implements the various classes that process command output
#include "Globals.h"
#include "CommandOutput.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cCommandOutputCallback:
void cCommandOutputCallback::Out(const char * a_Fmt, ...)
{
AString Output;
va_list args;
va_start(args, a_Fmt);
AppendVPrintf(Output, a_Fmt, args);
va_end(args);
Output.append("\n");
Out(Output);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cLogCommandOutputCallback:
void cLogCommandOutputCallback::Out(const AString & a_Text)
{
m_Buffer.append(a_Text);
}
void cLogCommandOutputCallback::Finished(void)
{
// Log each line separately:
size_t len = m_Buffer.length();
size_t last = 0;
for (size_t i = 0; i < len; i++)
{
switch (m_Buffer[i])
{
case '\n':
{
LOG(m_Buffer.substr(last, i - last).c_str());
last = i + 1;
break;
}
}
} // for i - m_Buffer[]
if (last < len)
{
LOG(m_Buffer.substr(last).c_str());
}
// Clear the buffer for the next command output:
m_Buffer.clear();
}