Skip to content

Commit 471f9d3

Browse files
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
1 parent 3117dd0 commit 471f9d3

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

NetworkServer.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ NetworkClientInfo::~NetworkClientInfo()
5858

5959
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
6060
{
61-
host = OPENRGB_SDK_HOST;
62-
port_num = OPENRGB_SDK_PORT;
63-
server_online = false;
64-
server_listening = false;
61+
host = OPENRGB_SDK_HOST;
62+
port_num = OPENRGB_SDK_PORT;
63+
server_online = false;
64+
server_listening = false;
65+
legacy_workaround_enabled = false;
66+
6567
for(int i = 0; i < MAXSOCK; i++)
6668
{
6769
ConnectionThread[i] = nullptr;
6870
}
71+
6972
profile_manager = nullptr;
7073
}
7174

@@ -221,6 +224,11 @@ void NetworkServer::SetHost(std::string new_host)
221224
}
222225
}
223226

227+
void NetworkServer::SetLegacyWorkaroundEnable(bool enable)
228+
{
229+
legacy_workaround_enabled = enable;
230+
}
231+
224232
void NetworkServer::SetPort(unsigned short new_port)
225233
{
226234
if(server_online == false)
@@ -689,14 +697,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
689697
| Verify the color description size (first 4 bytes of data) |
690698
| matches the packet size in the header |
691699
| |
692-
| If protocol version is 4 or below, allow the description |
693-
| size to be zero. This allows backwards compatibility with|
694-
| versions of the OpenRGB.NET SDK implementation which had |
695-
| a bug where this field would always be zero. |
700+
| If protocol version is 4 or below and the legacy SDK |
701+
| compatibility workaround is enabled, ignore this check. |
702+
| This allows backwards compatibility with old versions of |
703+
| SDK applications that didn't properly implement the size |
704+
| field. |
696705
\*---------------------------------------------------------*/
697706
if((header.pkt_size == *((unsigned int*)data))
698707
|| ((client_info->client_protocol_version <= 4)
699-
&& (*((unsigned int*)data) == 0)))
708+
&& (legacy_workaround_enabled)))
700709
{
701710
if(header.pkt_dev_idx < controllers.size())
702711
{
@@ -721,14 +730,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
721730
| Verify the color description size (first 4 bytes of data) |
722731
| matches the packet size in the header |
723732
| |
724-
| If protocol version is 4 or below, allow the description |
725-
| size to be zero. This allows backwards compatibility with|
726-
| versions of the OpenRGB.NET SDK implementation which had |
727-
| a bug where this field would always be zero. |
733+
| If protocol version is 4 or below and the legacy SDK |
734+
| compatibility workaround is enabled, ignore this check. |
735+
| This allows backwards compatibility with old versions of |
736+
| SDK applications that didn't properly implement the size |
737+
| field. |
728738
\*---------------------------------------------------------*/
729739
if((header.pkt_size == *((unsigned int*)data))
730740
|| ((client_info->client_protocol_version <= 4)
731-
&& (*((unsigned int*)data) == 0)))
741+
&& (legacy_workaround_enabled)))
732742
{
733743
if(header.pkt_dev_idx < controllers.size())
734744
{
@@ -793,14 +803,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
793803
| Verify the mode description size (first 4 bytes of data) |
794804
| matches the packet size in the header |
795805
| |
796-
| If protocol version is 4 or below, allow the description |
797-
| size to be zero. This allows backwards compatibility with|
798-
| versions of the OpenRGB.NET SDK implementation which had |
799-
| a bug where this field would always be zero. |
806+
| If protocol version is 4 or below and the legacy SDK |
807+
| compatibility workaround is enabled, ignore this check. |
808+
| This allows backwards compatibility with old versions of |
809+
| SDK applications that didn't properly implement the size |
810+
| field. |
800811
\*---------------------------------------------------------*/
801812
if((header.pkt_size == *((unsigned int*)data))
802813
|| ((client_info->client_protocol_version <= 4)
803-
&& (*((unsigned int*)data) == 0)))
814+
&& (legacy_workaround_enabled)))
804815
{
805816
if(header.pkt_dev_idx < controllers.size())
806817
{
@@ -825,14 +836,15 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
825836
| Verify the mode description size (first 4 bytes of data) |
826837
| matches the packet size in the header |
827838
| |
828-
| If protocol version is 4 or below, allow the description |
829-
| size to be zero. This allows backwards compatibility with|
830-
| versions of the OpenRGB.NET SDK implementation which had |
831-
| a bug where this field would always be zero. |
839+
| If protocol version is 4 or below and the legacy SDK |
840+
| compatibility workaround is enabled, ignore this check. |
841+
| This allows backwards compatibility with old versions of |
842+
| SDK applications that didn't properly implement the size |
843+
| field. |
832844
\*---------------------------------------------------------*/
833845
if((header.pkt_size == *((unsigned int*)data))
834846
|| ((client_info->client_protocol_version <= 4)
835-
&& (*((unsigned int*)data) == 0)))
847+
&& (legacy_workaround_enabled)))
836848
{
837849
if(header.pkt_dev_idx < controllers.size())
838850
{

NetworkServer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class NetworkServer
7171
void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg);
7272

7373
void SetHost(std::string host);
74+
void SetLegacyWorkaroundEnable(bool enable);
7475
void SetPort(unsigned short new_port);
7576

7677
void StartServer();
@@ -92,7 +93,7 @@ class NetworkServer
9293
void SendReply_PluginSpecific(SOCKET client_sock, unsigned int pkt_type, unsigned char* data, unsigned int data_size);
9394

9495
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
95-
96+
9697
void RegisterPlugin(NetworkPlugin plugin);
9798
void UnregisterPlugin(std::string plugin_name);
9899

@@ -125,6 +126,7 @@ class NetworkServer
125126
WSADATA wsa;
126127
#endif
127128

129+
bool legacy_workaround_enabled;
128130
int socket_count;
129131
SOCKET server_sock[MAXSOCK];
130132

ResourceManager.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ResourceManager::ResourceManager()
115115
\*-------------------------------------------------------------------------*/
116116
json server_settings = settings_manager->GetSettings("Server");
117117
bool all_controllers = false;
118+
bool legacy_workaround = false;
118119

119120
if(server_settings.contains("all_controllers"))
120121
{
@@ -130,6 +131,19 @@ ResourceManager::ResourceManager()
130131
server = new NetworkServer(rgb_controllers_hw);
131132
}
132133

134+
/*-------------------------------------------------------------------------*\
135+
| Enable legacy SDK workaround in server if configured |
136+
\*-------------------------------------------------------------------------*/
137+
if(server_settings.contains("legacy_workaround"))
138+
{
139+
legacy_workaround = server_settings["legacy_workaround"];
140+
}
141+
142+
if(legacy_workaround)
143+
{
144+
server->SetLegacyWorkaroundEnable(true);
145+
}
146+
133147
/*-------------------------------------------------------------------------*\
134148
| Initialize Saved Client Connections |
135149
\*-------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)