From 471f9d3e2ee6422dc37346e819dfd4f41af8aa6b Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 8 Jan 2025 20:44:20 -0600 Subject: [PATCH] Add server option to disable the size check called legacy workaround, which can be enabled to allow some old SDK apps that didn't properly implement the size to still be used --- NetworkServer.cpp | 60 +++++++++++++++++++++++++++------------------ NetworkServer.h | 4 ++- ResourceManager.cpp | 14 +++++++++++ 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/NetworkServer.cpp b/NetworkServer.cpp index c2ab009c..6657519b 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -58,14 +58,17 @@ NetworkClientInfo::~NetworkClientInfo() NetworkServer::NetworkServer(std::vector& control) : controllers(control) { - host = OPENRGB_SDK_HOST; - port_num = OPENRGB_SDK_PORT; - server_online = false; - server_listening = false; + host = OPENRGB_SDK_HOST; + port_num = OPENRGB_SDK_PORT; + server_online = false; + server_listening = false; + legacy_workaround_enabled = false; + for(int i = 0; i < MAXSOCK; i++) { ConnectionThread[i] = nullptr; } + profile_manager = nullptr; } @@ -221,6 +224,11 @@ void NetworkServer::SetHost(std::string new_host) } } +void NetworkServer::SetLegacyWorkaroundEnable(bool enable) +{ + legacy_workaround_enabled = enable; +} + void NetworkServer::SetPort(unsigned short new_port) { if(server_online == false) @@ -689,14 +697,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) | Verify the color description size (first 4 bytes of data) | | matches the packet size in the header | | | - | If protocol version is 4 or below, allow the description | - | size to be zero. This allows backwards compatibility with| - | versions of the OpenRGB.NET SDK implementation which had | - | a bug where this field would always be zero. | + | If protocol version is 4 or below and the legacy SDK | + | compatibility workaround is enabled, ignore this check. | + | This allows backwards compatibility with old versions of | + | SDK applications that didn't properly implement the size | + | field. | \*---------------------------------------------------------*/ if((header.pkt_size == *((unsigned int*)data)) || ((client_info->client_protocol_version <= 4) - && (*((unsigned int*)data) == 0))) + && (legacy_workaround_enabled))) { if(header.pkt_dev_idx < controllers.size()) { @@ -721,14 +730,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) | Verify the color description size (first 4 bytes of data) | | matches the packet size in the header | | | - | If protocol version is 4 or below, allow the description | - | size to be zero. This allows backwards compatibility with| - | versions of the OpenRGB.NET SDK implementation which had | - | a bug where this field would always be zero. | + | If protocol version is 4 or below and the legacy SDK | + | compatibility workaround is enabled, ignore this check. | + | This allows backwards compatibility with old versions of | + | SDK applications that didn't properly implement the size | + | field. | \*---------------------------------------------------------*/ if((header.pkt_size == *((unsigned int*)data)) || ((client_info->client_protocol_version <= 4) - && (*((unsigned int*)data) == 0))) + && (legacy_workaround_enabled))) { if(header.pkt_dev_idx < controllers.size()) { @@ -793,14 +803,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) | Verify the mode description size (first 4 bytes of data) | | matches the packet size in the header | | | - | If protocol version is 4 or below, allow the description | - | size to be zero. This allows backwards compatibility with| - | versions of the OpenRGB.NET SDK implementation which had | - | a bug where this field would always be zero. | + | If protocol version is 4 or below and the legacy SDK | + | compatibility workaround is enabled, ignore this check. | + | This allows backwards compatibility with old versions of | + | SDK applications that didn't properly implement the size | + | field. | \*---------------------------------------------------------*/ if((header.pkt_size == *((unsigned int*)data)) || ((client_info->client_protocol_version <= 4) - && (*((unsigned int*)data) == 0))) + && (legacy_workaround_enabled))) { if(header.pkt_dev_idx < controllers.size()) { @@ -825,14 +836,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) | Verify the mode description size (first 4 bytes of data) | | matches the packet size in the header | | | - | If protocol version is 4 or below, allow the description | - | size to be zero. This allows backwards compatibility with| - | versions of the OpenRGB.NET SDK implementation which had | - | a bug where this field would always be zero. | + | If protocol version is 4 or below and the legacy SDK | + | compatibility workaround is enabled, ignore this check. | + | This allows backwards compatibility with old versions of | + | SDK applications that didn't properly implement the size | + | field. | \*---------------------------------------------------------*/ if((header.pkt_size == *((unsigned int*)data)) || ((client_info->client_protocol_version <= 4) - && (*((unsigned int*)data) == 0))) + && (legacy_workaround_enabled))) { if(header.pkt_dev_idx < controllers.size()) { diff --git a/NetworkServer.h b/NetworkServer.h index 3f21609f..8d9f9106 100644 --- a/NetworkServer.h +++ b/NetworkServer.h @@ -71,6 +71,7 @@ public: void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg); void SetHost(std::string host); + void SetLegacyWorkaroundEnable(bool enable); void SetPort(unsigned short new_port); void StartServer(); @@ -92,7 +93,7 @@ public: void SendReply_PluginSpecific(SOCKET client_sock, unsigned int pkt_type, unsigned char* data, unsigned int data_size); void SetProfileManager(ProfileManagerInterface* profile_manager_pointer); - + void RegisterPlugin(NetworkPlugin plugin); void UnregisterPlugin(std::string plugin_name); @@ -125,6 +126,7 @@ private: WSADATA wsa; #endif + bool legacy_workaround_enabled; int socket_count; SOCKET server_sock[MAXSOCK]; diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 2cc32745..3716f788 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -115,6 +115,7 @@ ResourceManager::ResourceManager() \*-------------------------------------------------------------------------*/ json server_settings = settings_manager->GetSettings("Server"); bool all_controllers = false; + bool legacy_workaround = false; if(server_settings.contains("all_controllers")) { @@ -130,6 +131,19 @@ ResourceManager::ResourceManager() server = new NetworkServer(rgb_controllers_hw); } + /*-------------------------------------------------------------------------*\ + | Enable legacy SDK workaround in server if configured | + \*-------------------------------------------------------------------------*/ + if(server_settings.contains("legacy_workaround")) + { + legacy_workaround = server_settings["legacy_workaround"]; + } + + if(legacy_workaround) + { + server->SetLegacyWorkaroundEnable(true); + } + /*-------------------------------------------------------------------------*\ | Initialize Saved Client Connections | \*-------------------------------------------------------------------------*/