mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-02-18 23:35:59 -05:00
[next] SDK v6: Implement client and server flags to indicate capabilities and...
This commit is contained in:
@@ -47,6 +47,11 @@ NetworkClient::NetworkClient()
|
||||
{
|
||||
port_ip = "127.0.0.1";
|
||||
port_num = OPENRGB_SDK_PORT;
|
||||
client_flags = NET_CLIENT_FLAG_SUPPORTS_RGBCONTROLLER
|
||||
| NET_CLIENT_FLAG_SUPPORTS_PROFILEMANAGER
|
||||
| NET_CLIENT_FLAG_SUPPORTS_SETTINGSMANAGER;
|
||||
client_flags_sent = false;
|
||||
client_is_local_client = false;
|
||||
client_string_sent = false;
|
||||
client_sock = -1;
|
||||
detection_percent = 100;
|
||||
@@ -56,6 +61,7 @@ NetworkClient::NetworkClient()
|
||||
server_connected = false;
|
||||
server_controller_ids_requested = false;
|
||||
server_controller_ids_received = false;
|
||||
server_flags = 0;
|
||||
server_protocol_version = 0;
|
||||
server_reinitialize = false;
|
||||
change_in_progress = false;
|
||||
@@ -82,6 +88,11 @@ std::string NetworkClient::GetIP()
|
||||
return(port_ip);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetLocal()
|
||||
{
|
||||
return(client_is_local_client);
|
||||
}
|
||||
|
||||
unsigned short NetworkClient::GetPort()
|
||||
{
|
||||
return(port_num);
|
||||
@@ -94,7 +105,7 @@ unsigned int NetworkClient::GetProtocolVersion()
|
||||
|
||||
bool NetworkClient::GetOnline()
|
||||
{
|
||||
return(server_connected && client_string_sent && protocol_initialized && server_initialized);
|
||||
return(server_connected && client_string_sent && protocol_initialized && server_flags_initialized && server_initialized);
|
||||
}
|
||||
|
||||
std::string NetworkClient::GetServerName()
|
||||
@@ -102,9 +113,50 @@ std::string NetworkClient::GetServerName()
|
||||
return(server_name);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetSupportsRGBControllerAPI()
|
||||
{
|
||||
return(server_flags & NET_SERVER_FLAG_SUPPORTS_RGBCONTROLLER);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetSupportsProfileManagerAPI()
|
||||
{
|
||||
return(server_flags & NET_SERVER_FLAG_SUPPORTS_PROFILEMANAGER);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetSupportsPluginManagerAPI()
|
||||
{
|
||||
return(server_flags & NET_SERVER_FLAG_SUPPORTS_PLUGINMANAGER);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetSupportsSettingsManagerAPI()
|
||||
{
|
||||
return(server_flags & NET_SERVER_FLAG_SUPPORTS_SETTINGSMANAGER);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetSupportsDetectionAPI()
|
||||
{
|
||||
return(server_flags & NET_SERVER_FLAG_SUPPORTS_DETECTION);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Client Control functions |
|
||||
\*---------------------------------------------------------*/
|
||||
void NetworkClient::RequestLocalClient(bool request_local)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the request local client flag |
|
||||
\*-----------------------------------------------------*/
|
||||
client_flags |= NET_CLIENT_FLAG_REQUEST_LOCAL_CLIENT;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If we have already sent the flags, send again |
|
||||
\*-----------------------------------------------------*/
|
||||
if(client_flags_sent)
|
||||
{
|
||||
SendData_ClientFlags();
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SetIP(std::string new_ip)
|
||||
{
|
||||
if(server_connected == false)
|
||||
@@ -784,6 +836,25 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
protocol_version = server_protocol_version;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| If the protocol version is less than 6, feature flags were |
|
||||
| not part of this protocol, initialize the server flags to a |
|
||||
| default value that represents what that protocol version |
|
||||
| supported. Protocol 5 introduced rescan so set the supports |
|
||||
| detection flag. |
|
||||
\*-------------------------------------------------------------*/
|
||||
if(protocol_version < 6)
|
||||
{
|
||||
server_flags = NET_SERVER_FLAG_SUPPORTS_RGBCONTROLLER;
|
||||
|
||||
if(protocol_version >= 5)
|
||||
{
|
||||
server_flags |= NET_SERVER_FLAG_SUPPORTS_DETECTION;
|
||||
}
|
||||
|
||||
server_flags_initialized = true;
|
||||
}
|
||||
|
||||
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_PROTOCOL_NEGOTIATED);
|
||||
|
||||
protocol_initialized = true;
|
||||
@@ -802,6 +873,16 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
client_string_sent = true;
|
||||
}
|
||||
|
||||
if((!client_flags_sent) && (protocol_version >= 6))
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Once server is connected, send client string |
|
||||
\*-----------------------------------------------------*/
|
||||
SendData_ClientFlags();
|
||||
|
||||
client_flags_sent = true;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Initialize the server device list if it hasn't already |
|
||||
| been initialized |
|
||||
@@ -983,14 +1064,13 @@ void NetworkClient::ListenThreadFunction()
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_SERVER_NAME:
|
||||
if(data == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ProcessRequest_ServerString(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_SERVER_FLAGS:
|
||||
ProcessRequest_ServerFlags(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_DEVICE_LIST_UPDATED:
|
||||
ProcessRequest_DeviceListChanged();
|
||||
break;
|
||||
@@ -1036,6 +1116,11 @@ void NetworkClient::ListenThreadFunction()
|
||||
|
||||
listen_done:
|
||||
LOG_INFO("[%s] Client socket has been closed", NETWORKCLIENT);
|
||||
client_flags = NET_CLIENT_FLAG_SUPPORTS_RGBCONTROLLER
|
||||
| NET_CLIENT_FLAG_SUPPORTS_PROFILEMANAGER
|
||||
| NET_CLIENT_FLAG_SUPPORTS_SETTINGSMANAGER;
|
||||
client_flags_sent = false;
|
||||
client_is_local_client = false;
|
||||
client_string_sent = false;
|
||||
controller_data_requested = false;
|
||||
controller_data_received = false;
|
||||
@@ -1043,6 +1128,8 @@ listen_done:
|
||||
requested_controller_index = 0;
|
||||
server_controller_ids_requested = false;
|
||||
server_controller_ids_received = false;
|
||||
server_flags = 0;
|
||||
server_flags_initialized = false;
|
||||
server_initialized = false;
|
||||
server_connected = false;
|
||||
|
||||
@@ -1324,8 +1411,38 @@ void NetworkClient::ProcessRequest_RGBController_SignalUpdate(unsigned int data_
|
||||
controller->SignalUpdate(update_reason);
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessRequest_ServerFlags(unsigned int data_size, char * data)
|
||||
{
|
||||
if(data == NULL || data_size < sizeof(unsigned int))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
server_flags = *(unsigned int *)data;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Update the local client status based on the server's |
|
||||
| response |
|
||||
\*-----------------------------------------------------*/
|
||||
if(server_flags & NET_SERVER_FLAG_LOCAL_CLIENT)
|
||||
{
|
||||
client_is_local_client = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
client_is_local_client = false;
|
||||
}
|
||||
|
||||
server_flags_initialized = true;
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessRequest_ServerString(unsigned int data_size, char * data)
|
||||
{
|
||||
if(data == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
server_name.assign(data, data_size);
|
||||
server_name = StringUtils::remove_null_terminating_chars(server_name);
|
||||
|
||||
@@ -1335,6 +1452,18 @@ void NetworkClient::ProcessRequest_ServerString(unsigned int data_size, char * d
|
||||
SignalNetworkClientUpdate(NETWORKCLIENT_UPDATE_REASON_SERVER_STRING_RECEIVED);
|
||||
}
|
||||
|
||||
void NetworkClient::SendData_ClientFlags()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_SET_CLIENT_FLAGS, sizeof(client_flags));
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&client_flags, reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendData_ClientString()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
@@ -54,14 +54,21 @@ public:
|
||||
\*-----------------------------------------------------*/
|
||||
bool GetConnected();
|
||||
std::string GetIP();
|
||||
bool GetLocal();
|
||||
unsigned short GetPort();
|
||||
unsigned int GetProtocolVersion();
|
||||
bool GetOnline();
|
||||
std::string GetServerName();
|
||||
bool GetSupportsRGBControllerAPI();
|
||||
bool GetSupportsProfileManagerAPI();
|
||||
bool GetSupportsPluginManagerAPI();
|
||||
bool GetSupportsSettingsManagerAPI();
|
||||
bool GetSupportsDetectionAPI();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client Control functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void RequestLocalClient(bool request_local);
|
||||
void SetIP(std::string new_ip);
|
||||
void SetName(std::string new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
@@ -128,6 +135,8 @@ private:
|
||||
| Client state variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::atomic<bool> client_active;
|
||||
bool client_flags_sent;
|
||||
bool client_is_local_client;
|
||||
bool client_string_sent;
|
||||
bool controller_data_received;
|
||||
bool controller_data_requested;
|
||||
@@ -145,6 +154,7 @@ private:
|
||||
/*-----------------------------------------------------*\
|
||||
| Client information |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int client_flags;
|
||||
std::string client_name;
|
||||
SOCKET client_sock;
|
||||
net_port port;
|
||||
@@ -154,6 +164,8 @@ private:
|
||||
/*-----------------------------------------------------*\
|
||||
| Server information |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int server_flags;
|
||||
bool server_flags_initialized;
|
||||
std::string server_name;
|
||||
bool server_connected;
|
||||
bool server_initialized;
|
||||
@@ -211,8 +223,10 @@ private:
|
||||
void ProcessRequest_DetectionProgressChanged(unsigned int data_size, char * data);
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
void ProcessRequest_RGBController_SignalUpdate(unsigned int data_size, char * data, unsigned int dev_id);
|
||||
void ProcessRequest_ServerFlags(unsigned int data_size, char * data);
|
||||
void ProcessRequest_ServerString(unsigned int data_size, char * data);
|
||||
|
||||
void SendData_ClientFlags();
|
||||
void SendData_ClientString();
|
||||
void SendRequest_ControllerIDs();
|
||||
void SendRequest_ProtocolVersion();
|
||||
|
||||
@@ -44,12 +44,33 @@ extern const char openrgb_sdk_magic[OPENRGB_SDK_MAGIC_SIZE];
|
||||
|
||||
typedef struct NetPacketHeader
|
||||
{
|
||||
char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
|
||||
unsigned int pkt_dev_id; /* Device ID */
|
||||
unsigned int pkt_id; /* Packet ID */
|
||||
unsigned int pkt_size; /* Packet size */
|
||||
char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
|
||||
unsigned int pkt_dev_id; /* Device ID */
|
||||
unsigned int pkt_id; /* Packet ID */
|
||||
unsigned int pkt_size; /* Packet size */
|
||||
} NetPacketHeader;
|
||||
|
||||
enum
|
||||
{
|
||||
NET_CLIENT_FLAG_SUPPORTS_RGBCONTROLLER = ( 1 << 0 ), /* Client supports RGBController API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_PROFILEMANAGER = ( 1 << 1 ), /* Client supports ProfileManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_PLUGINMANAGER = ( 1 << 2 ), /* Client supports PluginManager API */
|
||||
NET_CLIENT_FLAG_SUPPORTS_SETTINGSMANAGER = ( 1 << 3 ), /* Client supports SettingsManager API */
|
||||
|
||||
NET_CLIENT_FLAG_REQUEST_LOCAL_CLIENT = ( 1 << 16 ), /* Request local client */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NET_SERVER_FLAG_SUPPORTS_RGBCONTROLLER = ( 1 << 0 ), /* Server supports RGBController API */
|
||||
NET_SERVER_FLAG_SUPPORTS_PROFILEMANAGER = ( 1 << 1 ), /* Server supports ProfileManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_PLUGINMANAGER = ( 1 << 2 ), /* Server supports PluginManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_SETTINGSMANAGER = ( 1 << 3 ), /* Server supports SettingsManager API */
|
||||
NET_SERVER_FLAG_SUPPORTS_DETECTION = ( 1 << 4 ), /* Server supports detection functions */
|
||||
|
||||
NET_SERVER_FLAG_LOCAL_CLIENT = ( 1 << 16), /* Confirm that client is local client */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
@@ -62,7 +83,12 @@ enum
|
||||
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
NET_PACKET_ID_SET_SERVER_NAME = 51, /* Send server name string to client */
|
||||
NET_PACKET_ID_SET_CLIENT_FLAGS = 52, /* Send client flags to server */
|
||||
NET_PACKET_ID_SET_SERVER_FLAGS = 53, /* Send server flags to client */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| Detection functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
|
||||
NET_PACKET_ID_DETECTION_STARTED = 101, /* Indicate to clients that detection started */
|
||||
NET_PACKET_ID_DETECTION_PROGRESS_CHANGED = 102, /* Indicate to clients that detection progress changed */
|
||||
|
||||
@@ -55,6 +55,8 @@ NetworkClientInfo::NetworkClientInfo()
|
||||
client_sock = INVALID_SOCKET;
|
||||
client_listen_thread = nullptr;
|
||||
client_protocol_version = 0;
|
||||
client_is_local = false;
|
||||
client_is_local_client = false;
|
||||
}
|
||||
|
||||
NetworkClientInfo::~NetworkClientInfo()
|
||||
@@ -84,6 +86,11 @@ NetworkServer::NetworkServer()
|
||||
legacy_workaround_enabled = false;
|
||||
controller_next_idx = 0;
|
||||
controller_updating = false;
|
||||
server_flags = NET_SERVER_FLAG_SUPPORTS_RGBCONTROLLER
|
||||
| NET_SERVER_FLAG_SUPPORTS_PROFILEMANAGER
|
||||
| NET_SERVER_FLAG_SUPPORTS_PLUGINMANAGER
|
||||
| NET_SERVER_FLAG_SUPPORTS_SETTINGSMANAGER
|
||||
| NET_SERVER_FLAG_SUPPORTS_DETECTION;
|
||||
|
||||
for(int i = 0; i < MAXSOCK; i++)
|
||||
{
|
||||
@@ -773,12 +780,22 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
|
||||
struct sockaddr_in *s_4 = (struct sockaddr_in *)&tmp_addr;
|
||||
inet_ntop(AF_INET, &s_4->sin_addr, ipstr, sizeof(ipstr));
|
||||
client_info->client_ip = ipstr;
|
||||
|
||||
if(s_4->sin_addr.s_addr == htonl(INADDR_LOOPBACK))
|
||||
{
|
||||
client_info->client_is_local = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct sockaddr_in6 *s_6 = (struct sockaddr_in6 *)&tmp_addr;
|
||||
inet_ntop(AF_INET6, &s_6->sin6_addr, ipstr, sizeof(ipstr));
|
||||
client_info->client_ip = ipstr;
|
||||
|
||||
if(IN6_IS_ADDR_LOOPBACK(&s_6->sin6_addr))
|
||||
{
|
||||
client_info->client_is_local = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -995,12 +1012,12 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
SendReply_ServerString(client_sock);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_CLIENT_NAME:
|
||||
if(data == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
case NET_PACKET_ID_SET_CLIENT_FLAGS:
|
||||
ProcessRequest_ClientFlags(client_sock, header.pkt_size, data);
|
||||
SendReply_ServerFlags(client_sock);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_CLIENT_NAME:
|
||||
ProcessRequest_ClientString(client_sock, header.pkt_size, data);
|
||||
break;
|
||||
|
||||
@@ -1383,6 +1400,29 @@ listen_done:
|
||||
/*---------------------------------------------------------*\
|
||||
| Server Protocol functions |
|
||||
\*---------------------------------------------------------*/
|
||||
void NetworkServer::ProcessRequest_ClientFlags(SOCKET client_sock, unsigned int data_size, char * data)
|
||||
{
|
||||
if((data_size == sizeof(unsigned int)) && (data != NULL))
|
||||
{
|
||||
ServerClientsMutex.lock();
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
ServerClients[this_idx]->client_flags = *(unsigned int *)data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ServerClientsMutex.unlock();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
SignalClientInfoChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data)
|
||||
{
|
||||
unsigned int protocol_version = 0;
|
||||
@@ -1416,23 +1456,26 @@ void NetworkServer::ProcessRequest_ClientProtocolVersion(SOCKET client_sock, uns
|
||||
|
||||
void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data)
|
||||
{
|
||||
ServerClientsMutex.lock();
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
if(data != NULL)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
ServerClientsMutex.lock();
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
ServerClients[this_idx]->client_string.assign(data, data_size);
|
||||
ServerClients[this_idx]->client_string = StringUtils::remove_null_terminating_chars(ServerClients[this_idx]->client_string);
|
||||
break;
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
ServerClients[this_idx]->client_string.assign(data, data_size);
|
||||
ServerClients[this_idx]->client_string = StringUtils::remove_null_terminating_chars(ServerClients[this_idx]->client_string);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ServerClientsMutex.unlock();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-----------------------------------------------------*/
|
||||
SignalClientInfoChanged();
|
||||
}
|
||||
|
||||
ServerClientsMutex.unlock();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*---------------------------------------------------------*/
|
||||
SignalClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ProcessRequest_RescanDevices()
|
||||
@@ -2047,10 +2090,49 @@ void NetworkServer::SendReply_ProtocolVersion(SOCKET client_sock)
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ServerFlags(SOCKET client_sock)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Send server flags to client only if protocol is 6 or |
|
||||
| greater |
|
||||
\*-----------------------------------------------------*/
|
||||
ServerClientsMutex.lock();
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_protocol_version >= 6)
|
||||
{
|
||||
unsigned int flags_value = server_flags;
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| If client requested local client, grant |
|
||||
| it if the client is a local connection |
|
||||
\*-----------------------------------------*/
|
||||
if((ServerClients[this_idx]->client_flags & NET_CLIENT_FLAG_REQUEST_LOCAL_CLIENT)
|
||||
&& (ServerClients[this_idx]->client_is_local))
|
||||
{
|
||||
ServerClients[this_idx]->client_is_local_client = true;
|
||||
flags_value |= NET_SERVER_FLAG_LOCAL_CLIENT;
|
||||
}
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_SET_SERVER_FLAGS, sizeof(flags_value));
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&flags_value, reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerClientsMutex.unlock();
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ServerString(SOCKET client_sock)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Send server string to client only if protocol is 5 or |
|
||||
| Send server string to client only if protocol is 6 or |
|
||||
| greater |
|
||||
\*---------------------------------------------------------*/
|
||||
ServerClientsMutex.lock();
|
||||
@@ -2058,7 +2140,7 @@ void NetworkServer::SendReply_ServerString(SOCKET client_sock)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_protocol_version >= 5)
|
||||
if(ServerClients[this_idx]->client_protocol_version >= 6)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
|
||||
@@ -57,10 +57,13 @@ public:
|
||||
~NetworkClientInfo();
|
||||
|
||||
SOCKET client_sock;
|
||||
unsigned int client_flags;
|
||||
std::thread * client_listen_thread;
|
||||
std::string client_string;
|
||||
unsigned int client_protocol_version;
|
||||
std::string client_ip;
|
||||
bool client_is_local;
|
||||
bool client_is_local_client;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
@@ -135,6 +138,7 @@ private:
|
||||
bool legacy_workaround_enabled;
|
||||
unsigned short port_num;
|
||||
std::mutex send_in_progress;
|
||||
unsigned int server_flags;
|
||||
std::string server_name;
|
||||
std::atomic<bool> server_online;
|
||||
std::atomic<bool> server_listening;
|
||||
@@ -208,6 +212,7 @@ private:
|
||||
/*-----------------------------------------------------*\
|
||||
| Server Protocol functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ProcessRequest_ClientFlags(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_RescanDevices();
|
||||
@@ -225,6 +230,7 @@ private:
|
||||
void SendReply_ControllerCount(SOCKET client_sock, unsigned int protocol_version);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_id, unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(SOCKET client_sock);
|
||||
void SendReply_ServerFlags(SOCKET client_sock);
|
||||
void SendReply_ServerString(SOCKET client_sock);
|
||||
|
||||
void SendReply_ProfileList(SOCKET client_sock);
|
||||
|
||||
@@ -97,7 +97,7 @@ ProfileManager::~ProfileManager()
|
||||
|
||||
void ProfileManager::DeleteProfile(std::string profile_name)
|
||||
{
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
|
||||
{
|
||||
ResourceManager::get()->GetLocalClient()->ProfileManager_DeleteProfile(profile_name);
|
||||
}
|
||||
@@ -237,7 +237,7 @@ nlohmann::json ProfileManager::ReadProfileJSON(std::string profile_name)
|
||||
{
|
||||
nlohmann::json profile_json;
|
||||
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
|
||||
{
|
||||
profile_json = nlohmann::json::parse(ResourceManager::get()->GetLocalClient()->ProfileManager_DownloadProfile(profile_name));
|
||||
}
|
||||
@@ -303,7 +303,7 @@ bool ProfileManager::SaveProfile(std::string profile_name)
|
||||
profile_json["plugins"] = plugin_manager->OnProfileSave();
|
||||
}
|
||||
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Upload the profile to the server |
|
||||
@@ -466,7 +466,7 @@ void ProfileManager::UpdateProfileList()
|
||||
{
|
||||
profile_list.clear();
|
||||
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsProfileManagerAPI()))
|
||||
{
|
||||
char * profile_data = ResourceManager::get()->GetLocalClient()->ProfileManager_GetProfileList();
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ unsigned int ResourceManager::GetLocalClientProtocolVersion()
|
||||
|
||||
bool ResourceManager::IsLocalClient()
|
||||
{
|
||||
return(auto_connection_active);
|
||||
return(auto_connection_active && (auto_connection_client != NULL) && auto_connection_client->GetLocal());
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -379,7 +379,7 @@ bool ResourceManager::GetDetectionEnabled()
|
||||
|
||||
unsigned int ResourceManager::GetDetectionPercent()
|
||||
{
|
||||
if(auto_connection_active && auto_connection_client != NULL)
|
||||
if(auto_connection_active && (auto_connection_client != NULL) && auto_connection_client->GetLocal())
|
||||
{
|
||||
return auto_connection_client->DetectionManager_GetDetectionPercent();
|
||||
}
|
||||
@@ -391,7 +391,7 @@ unsigned int ResourceManager::GetDetectionPercent()
|
||||
|
||||
std::string ResourceManager::GetDetectionString()
|
||||
{
|
||||
if(auto_connection_active && auto_connection_client != NULL)
|
||||
if(auto_connection_active && (auto_connection_client != NULL) && auto_connection_client->GetLocal())
|
||||
{
|
||||
return auto_connection_client->DetectionManager_GetDetectionString();
|
||||
}
|
||||
@@ -408,7 +408,7 @@ void ResourceManager::RescanDevices()
|
||||
| instance is the local server, so send rescan requests |
|
||||
| to the automatic local connection client |
|
||||
\*-----------------------------------------------------*/
|
||||
if(auto_connection_active && auto_connection_client != NULL)
|
||||
if(auto_connection_active && (auto_connection_client != NULL) && auto_connection_client->GetLocal())
|
||||
{
|
||||
auto_connection_client->SendRequest_RescanDevices();
|
||||
}
|
||||
@@ -583,6 +583,7 @@ bool ResourceManager::AttemptLocalConnection()
|
||||
std::string titleString = "OpenRGB ";
|
||||
titleString.append(VERSION_STRING);
|
||||
|
||||
auto_connection_client->RequestLocalClient(true);
|
||||
auto_connection_client->SetName(titleString.c_str());
|
||||
auto_connection_client->StartClient();
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ json SettingsManager::GetSettings(std::string settings_key)
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui_settings_key && ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(!ui_settings_key && ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsSettingsManagerAPI()))
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a local client, request the settings |
|
||||
@@ -102,7 +102,7 @@ void SettingsManager::SetSettings(std::string settings_key, json new_settings)
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui_settings_key && ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(!ui_settings_key && ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsSettingsManagerAPI()))
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a local client, request the settings |
|
||||
@@ -195,7 +195,7 @@ void SettingsManager::LoadSettings(const filesystem::path& filename)
|
||||
|
||||
void SettingsManager::SaveSettings()
|
||||
{
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClientProtocolVersion() >= 6))
|
||||
if(ResourceManager::get()->IsLocalClient() && (ResourceManager::get()->GetLocalClient()->GetSupportsSettingsManagerAPI()))
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a local client, save the settings on |
|
||||
|
||||
Reference in New Issue
Block a user