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

This commit is contained in:
Adam Honse 2025-01-08 20:44:20 -06:00
parent 3117dd0885
commit 471f9d3e2e
3 changed files with 53 additions and 25 deletions

View file

@ -58,14 +58,17 @@ NetworkClientInfo::~NetworkClientInfo()
NetworkServer::NetworkServer(std::vector<RGBController *>& 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())
{

View file

@ -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];

View file

@ -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 |
\*-------------------------------------------------------------------------*/