diff --git a/NetworkClient.cpp b/NetworkClient.cpp index a46c6ea8..3916ef86 100644 --- a/NetworkClient.cpp +++ b/NetworkClient.cpp @@ -835,6 +835,28 @@ void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, u send(client_sock, (char *)data, size, MSG_NOSIGNAL); } +void NetworkClient::SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size) +{ + if(change_in_progress) + { + return; + } + + NetPacketHeader request_hdr; + + request_hdr.pkt_magic[0] = 'O'; + request_hdr.pkt_magic[1] = 'R'; + request_hdr.pkt_magic[2] = 'G'; + request_hdr.pkt_magic[3] = 'B'; + + request_hdr.pkt_dev_idx = dev_idx; + request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_SAVEMODE; + request_hdr.pkt_size = size; + + send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL); + send(client_sock, (char *)data, size, MSG_NOSIGNAL); +} + void NetworkClient::SendRequest_LoadProfile(std::string profile_name) { NetPacketHeader reply_hdr; diff --git a/NetworkClient.h b/NetworkClient.h index 3499b00d..9ad1fce0 100644 --- a/NetworkClient.h +++ b/NetworkClient.h @@ -67,6 +67,7 @@ public: void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx); void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size); + void SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size); std::vector * ProcessReply_ProfileList(unsigned int data_size, char * data); diff --git a/NetworkProtocol.h b/NetworkProtocol.h index 98da2317..a2cc4385 100644 --- a/NetworkProtocol.h +++ b/NetworkProtocol.h @@ -62,4 +62,5 @@ enum NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */ NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */ + NET_PACKET_ID_RGBCONTROLLER_SAVEMODE = 1102, /* RGBController::SaveMode() */ }; diff --git a/NetworkServer.cpp b/NetworkServer.cpp index 81c0a058..d65e5812 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -690,6 +690,19 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) } break; + case NET_PACKET_ID_RGBCONTROLLER_SAVEMODE: + if(data == NULL) + { + break; + } + + if(header.pkt_dev_idx < controllers.size()) + { + controllers[header.pkt_dev_idx]->SetModeDescription((unsigned char *)data, client_info->client_protocol_version); + controllers[header.pkt_dev_idx]->SaveMode(); + } + break; + case NET_PACKET_ID_REQUEST_PROFILE_LIST: SendReply_ProfileList(client_sock); break; diff --git a/RGBController/RGBController_Network.cpp b/RGBController/RGBController_Network.cpp index 338e3cf9..6363f192 100644 --- a/RGBController/RGBController_Network.cpp +++ b/RGBController/RGBController_Network.cpp @@ -79,6 +79,18 @@ void RGBController_Network::DeviceUpdateMode() delete[] data; } +void RGBController_Network::DeviceSaveMode() +{ + unsigned char * data = GetModeDescription(active_mode, client->GetProtocolVersion()); + unsigned int size; + + memcpy(&size, &data[0], sizeof(unsigned int)); + + client->SendRequest_RGBController_SaveMode(dev_idx, data, size); + + delete[] data; +} + /*-----------------------------------------------------*\ | This function overrides RGBController::UpdateLEDs()! | | Normally, UpdateLEDs() sets a flag for the updater | diff --git a/RGBController/RGBController_Network.h b/RGBController/RGBController_Network.h index 156ba801..47edff2d 100644 --- a/RGBController/RGBController_Network.h +++ b/RGBController/RGBController_Network.h @@ -26,6 +26,7 @@ public: void SetCustomMode(); void DeviceUpdateMode(); + void DeviceSaveMode(); void UpdateLEDs();