Add support for sendCOMM method

Credits go to user @angelsware, I just did a copy/paste from #120
This commit is contained in:
Sander Datema
2020-06-27 21:14:42 +02:00
parent 76f7d28ac8
commit 388329b218
10 changed files with 211 additions and 53 deletions

View File

@@ -70,6 +70,7 @@ namespace XPC
handlers.insert(std::make_pair("VIEW", MessageHandlers::HandleView));
handlers.insert(std::make_pair("GETC", MessageHandlers::HandleGetC));
handlers.insert(std::make_pair("GETP", MessageHandlers::HandleGetP));
handlers.insert(std::make_pair("COMM", MessageHandlers::HandleComm));
handlers.insert(std::make_pair("GETT", MessageHandlers::HandleGetT));
// X-Plane data messages
handlers.insert(std::make_pair("DSEL", MessageHandlers::HandleXPlaneData));
@@ -916,6 +917,31 @@ namespace XPC
}
}
void MessageHandlers::HandleComm(const Message& msg)
{
Log::FormatLine(LOG_TRACE, "COMM", "Request to execute COMM command received (Conn %i)", connection.id);
const unsigned char* buffer = msg.GetBuffer();
std::size_t size = msg.GetSize();
std::size_t pos = 5;
while (pos < size)
{
unsigned char len = buffer[pos++];
if (pos + len > size)
{
break;
}
std::string comm = std::string((char*)buffer + pos, len);
pos += len;
DataManager::Execute(comm);
Log::FormatLine(LOG_DEBUG, "COMM", "Execute command %s", comm.c_str());
}
if (pos != size)
{
Log::WriteLine(LOG_ERROR, "COMM", "ERROR: Command did not terminate at the expected position.");
}
}
void MessageHandlers::HandleWypt(const Message& msg)
{
// Update Log