From 0884cfd3955054fc8cb8c94913c122e7a69deeed Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Wed, 6 May 2015 15:13:21 -0700 Subject: [PATCH] Added support for setting multiple datarefs to the plugin. - The DREF command now uses the packet length to detect and set multiple datarefs in a single packet. --- xpcPlugin/MessageHandlers.cpp | 43 +++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index 17e5cb0..1a94bf3 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -402,18 +402,41 @@ namespace XPC void MessageHandlers::HandleDref(Message& msg) { - const unsigned char* buffer = msg.GetBuffer(); - unsigned char len = buffer[5]; - std::string dref = std::string((char*)buffer + 6, len); - - unsigned char valueCount = buffer[6 + len]; - float* values = (float*)(buffer + 7 + len); - -#if LOG_VERBOSITY > 1 - Log::FormatLine("[DREF] Request to set DREF value received (Conn %i): %s", connection.id, dref.c_str()); +#if LOG_VERBOSITY >= 3 + Log::FormatLine("[DREF] Request to set DREF value received (Conn %i)", connection.id); #endif + 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 dref = std::string((char*)buffer + pos, len); + pos += len; - DataManager::Set(dref, values, valueCount); + unsigned char valueCount = buffer[pos++]; + if (pos + 4 * valueCount > size) + { + break; + } + float* values = (float*)(buffer + pos); + pos += 4 * valueCount; + + DataManager::Set(dref, values, valueCount); +#if LOG_VERBOSITY >= 4 + Log::FormatLine("[DREF] Set %d values for %s", valueCount, dref.c_str()); +#endif + } +#if LOG_VERBOSITY >= 2 + if (pos != size) + { + Log::WriteLine("[DREF] Error: Command did not terminate at the expected position."); + } +#endif } void MessageHandlers::HandleGetD(Message& msg)