From 640eb7905c1a075a780c6a6fc08b01965706f379 Mon Sep 17 00:00:00 2001 From: B Horn Date: Sun, 17 Jul 2022 20:30:15 +0000 Subject: [PATCH] SDK Listening Options --- NetworkClient.cpp | 17 ++- NetworkClient.h | 8 +- NetworkProtocol.h | 5 + NetworkServer.cpp | 202 +++++++++++++++++++---------- NetworkServer.h | 15 ++- cli.cpp | 26 +++- net_port/net_port.cpp | 40 +++--- qt/OpenRGBServerInfoPage.cpp | 5 + qt/OpenRGBServerInfoPage.ui | 85 +++++++----- qt/OpenRGBSettingsPage.cpp | 22 ++++ qt/OpenRGBSettingsPage.h | 2 + qt/OpenRGBSettingsPage.ui | 244 ++++++++++++++++++----------------- 12 files changed, 415 insertions(+), 256 deletions(-) diff --git a/NetworkClient.cpp b/NetworkClient.cpp index 57193052..b8709e9e 100644 --- a/NetworkClient.cpp +++ b/NetworkClient.cpp @@ -29,7 +29,7 @@ using namespace std::chrono_literals; NetworkClient::NetworkClient(std::vector& control) : controllers(control) { - strcpy(port_ip, "127.0.0.1"); + port_ip = "127.0.0.1"; port_num = OPENRGB_SDK_PORT; client_sock = -1; server_connected = false; @@ -68,9 +68,9 @@ void NetworkClient::ClientInfoChanged() ClientInfoChangeMutex.unlock(); } -const char * NetworkClient::GetIP() +std::string NetworkClient::GetIP() { - return(port_ip); + return port_ip; } unsigned short NetworkClient::GetPort() @@ -110,15 +110,15 @@ void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callb ClientInfoChangeCallbackArgs.push_back(new_callback_arg); } -void NetworkClient::SetIP(const char *new_ip) +void NetworkClient::SetIP(std::string new_ip) { if(server_connected == false) { - strcpy(port_ip, new_ip); + port_ip = new_ip; } } -void NetworkClient::SetName(const char *new_name) +void NetworkClient::SetName(std::string new_name) { client_name = new_name; @@ -142,7 +142,7 @@ void NetworkClient::StartClient() char port_str[6]; snprintf(port_str, 6, "%d", port_num); - port.tcp_client(port_ip, port_str); + port.tcp_client(port_ip.c_str(), port_str); client_active = true; @@ -157,6 +157,9 @@ void NetworkClient::StartClient() void NetworkClient::StopClient() { + server_connected = false; + client_active = false; + if(server_connected) { shutdown(client_sock, SD_RECEIVE); diff --git a/NetworkClient.h b/NetworkClient.h index 9ad1fce0..8d29287c 100644 --- a/NetworkClient.h +++ b/NetworkClient.h @@ -26,7 +26,7 @@ public: void ClientInfoChanged(); bool GetConnected(); - const char * GetIP(); + std::string GetIP(); unsigned short GetPort(); unsigned int GetProtocolVersion(); bool GetOnline(); @@ -34,8 +34,8 @@ public: void ClearCallbacks(); void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg); - void SetIP(const char *new_ip); - void SetName(const char *new_name); + void SetIP(std::string new_ip); + void SetName(std::string new_name); void SetPort(unsigned short new_port); void StartClient(); @@ -89,7 +89,7 @@ private: SOCKET client_sock; std::string client_name; net_port port; - char port_ip[20]; + std::string port_ip; unsigned short port_num; bool client_active; bool controller_data_received; diff --git a/NetworkProtocol.h b/NetworkProtocol.h index a2cc4385..820be3d8 100644 --- a/NetworkProtocol.h +++ b/NetworkProtocol.h @@ -18,6 +18,11 @@ \*-----------------------------------------------------*/ #define OPENRGB_SDK_PROTOCOL_VERSION 3 +/*-----------------------------------------------------*\ +| Default Interface to bind to. | +\*-----------------------------------------------------*/ +#define OPENRGB_SDK_HOST "0.0.0.0" + /*-----------------------------------------------------*\ | Default OpenRGB SDK port is 6742 | | This is "ORGB" on a phone keypad | diff --git a/NetworkServer.cpp b/NetworkServer.cpp index cec8b1ac..c62b311e 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -35,8 +35,11 @@ using namespace std::chrono_literals; NetworkClientInfo::NetworkClientInfo() { - client_sock = INVALID_SOCKET; - client_listen_thread = nullptr; + client_string = "Client"; + client_ip = OPENRGB_SDK_HOST; + client_sock = INVALID_SOCKET; + client_listen_thread = nullptr; + client_protocol_version = 0; } NetworkClientInfo::~NetworkClientInfo() @@ -52,10 +55,14 @@ NetworkClientInfo::~NetworkClientInfo() NetworkServer::NetworkServer(std::vector& control) : controllers(control) { + host = OPENRGB_SDK_HOST; port_num = OPENRGB_SDK_PORT; server_online = false; server_listening = false; - ConnectionThread = nullptr; + for(int i = 0; i < MAXSOCK; i++) + { + ConnectionThread[i] = nullptr; + } profile_manager = nullptr; } @@ -106,6 +113,11 @@ void NetworkServer::ServerListeningChanged() ServerListeningChangeMutex.unlock(); } +std::string NetworkServer::GetHost() +{ + return host; +} + unsigned short NetworkServer::GetPort() { return port_num; @@ -154,7 +166,7 @@ const char * NetworkServer::GetClientIP(unsigned int client_num) if(client_num < ServerClients.size()) { - result = ServerClients[client_num]->client_ip; + result = ServerClients[client_num]->client_ip.c_str(); } else { @@ -198,6 +210,14 @@ void NetworkServer::RegisterServerListeningChangeCallback(NetServerCallback new_ ServerListeningChangeCallbackArgs.push_back(new_callback_arg); } +void NetworkServer::SetHost(std::string new_host) +{ + if(server_online == false) + { + host = new_host; + } +} + void NetworkServer::SetPort(unsigned short new_port) { if(server_online == false) @@ -208,92 +228,112 @@ void NetworkServer::SetPort(unsigned short new_port) void NetworkServer::StartServer() { + int err; + struct addrinfo hints, *res, *result; //Start a TCP server and launch threads char port_str[6]; snprintf(port_str, 6, "%d", port_num); - sockaddr_in myAddress; + socket_count = 0; /*-------------------------------------------------*\ | Windows requires WSAStartup before using sockets | \*-------------------------------------------------*/ #ifdef WIN32 - if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) + if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) { WSACleanup(); return; } #endif - /*-------------------------------------------------*\ - | Create the server socket | - \*-------------------------------------------------*/ - server_sock = socket(AF_INET, SOCK_STREAM, 0); - if (server_sock == INVALID_SOCKET) + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + err = getaddrinfo(host.c_str(), port_str, &hints, &result); + + if(err) { - printf("Error: network socket could not be created\n"); + printf("Error: Unable to get address.\n"); WSACleanup(); return; } /*-------------------------------------------------*\ - | Fill in server address info with port value | + | Create a server socket for each address returned. | \*-------------------------------------------------*/ - myAddress.sin_family = AF_INET; - myAddress.sin_addr.s_addr = inet_addr("0.0.0.0"); - myAddress.sin_port = htons(atoi(port_str)); - - /*-------------------------------------------------*\ - | Bind the server socket | - \*-------------------------------------------------*/ - if (bind(server_sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) + for(res = result; res && socket_count < MAXSOCK; res = res->ai_next) { - if(errno == EADDRINUSE) + server_sock[socket_count] = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + + if(server_sock[socket_count] == INVALID_SOCKET) { - printf("Error: Could not bind network socket \nIs port %hu already being used?\n", GetPort()); - } - else if(errno == EACCES) - { - printf("Error: Access to socket was denied.\n"); - } - else if(errno == EBADF) - { - printf("Error: sockfd is not a valid file descriptor.\n"); - } - else if(errno == EINVAL) - { - printf("Error: The socket is already bound to an address, or addrlen is wrong, or addr is not a valid address for this socket's domain..\n"); - } - else if(errno == ENOTSOCK) - { - printf("Error: The file descriptor sockfd does not refer to a socket.\n"); - } - else - { - // could be a linux specific error - // https://man7.org/linux/man-pages/man2/bind.2.html - printf("Error: Could not bind network socket, error code:%d\n", errno); + printf("Error: network socket could not be created\n"); + WSACleanup(); + return; } - WSACleanup(); - return; + /*-------------------------------------------------*\ + | Bind the server socket | + \*-------------------------------------------------*/ + if(bind(server_sock[socket_count], res->ai_addr, res->ai_addrlen) == SOCKET_ERROR) + { + if(errno == EADDRINUSE) + { + printf("Error: Could not bind network socket \nIs port %hu already being used?\n", GetPort()); + } + else if(errno == EACCES) + { + printf("Error: Access to socket was denied.\n"); + } + else if(errno == EBADF) + { + printf("Error: sockfd is not a valid file descriptor.\n"); + } + else if(errno == EINVAL) + { + printf("Error: The socket is already bound to an address, or addrlen is wrong, or addr is not a valid address for this socket's domain..\n"); + } + else if(errno == ENOTSOCK) + { + printf("Error: The file descriptor sockfd does not refer to a socket.\n"); + } + else + { + // could be a linux specific error + // https://man7.org/linux/man-pages/man2/bind.2.html + printf("Error: Could not bind network socket, error code:%d\n", errno); + } + + WSACleanup(); + return; + } + + /*-------------------------------------------------*\ + | Set socket options - no delay | + \*-------------------------------------------------*/ + setsockopt(server_sock[socket_count], IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); + + socket_count += 1; } - /*-------------------------------------------------*\ - | Set socket options - no delay | - \*-------------------------------------------------*/ - setsockopt(server_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); - + freeaddrinfo(result); server_online = true; + /*-------------------------------------------------*\ | Start the connection thread | \*-------------------------------------------------*/ - ConnectionThread = new std::thread(&NetworkServer::ConnectionThreadFunction, this); - ConnectionThread->detach(); + for(int curr_socket = 0; curr_socket < socket_count; curr_socket++) + { + ConnectionThread[curr_socket] = new std::thread(&NetworkServer::ConnectionThreadFunction, this, curr_socket); + ConnectionThread[curr_socket]->detach(); + } } void NetworkServer::StopServer() { + int curr_socket; server_online = false; ServerClientsMutex.lock(); @@ -305,24 +345,32 @@ void NetworkServer::StopServer() ServerClients.clear(); - shutdown(server_sock, SD_RECEIVE); - closesocket(server_sock); + for(curr_socket = 0; curr_socket < socket_count; curr_socket++) + { + shutdown(server_sock[curr_socket], SD_RECEIVE); + closesocket(server_sock[curr_socket]); + } ServerClientsMutex.unlock(); - if(ConnectionThread) + for(curr_socket = 0; curr_socket < socket_count; curr_socket++) { - delete ConnectionThread; - ConnectionThread = nullptr; + if(ConnectionThread[curr_socket]) + { + delete ConnectionThread[curr_socket]; + ConnectionThread[curr_socket] = nullptr; + } } + socket_count = 0; + /*-------------------------------------------------*\ | Client info has changed, call the callbacks | \*-------------------------------------------------*/ ClientInfoChanged(); } -void NetworkServer::ConnectionThreadFunction() +void NetworkServer::ConnectionThreadFunction(int socket_idx) { //This thread handles client connections @@ -339,7 +387,7 @@ void NetworkServer::ConnectionThreadFunction() | server socket. This call blocks until a | | connection is established | \*-------------------------------------------------*/ - if(listen(server_sock, 10) < 0) + if(listen(server_sock[socket_idx], 10) < 0) { printf("Connection thread closed\r\n"); server_online = false; @@ -353,9 +401,7 @@ void NetworkServer::ConnectionThreadFunction() /*-------------------------------------------------*\ | Accept the client connection | \*-------------------------------------------------*/ - struct sockaddr_in client_addr; - socklen_t client_addr_len = sizeof(client_addr); - client_info->client_sock = accept_select(server_sock, (struct sockaddr *)&client_addr, &client_addr_len); + client_info->client_sock = accept_select(server_sock[socket_idx]); if(client_info->client_sock < 0) { @@ -376,9 +422,27 @@ void NetworkServer::ConnectionThreadFunction() ioctlsocket(client_info->client_sock, FIONBIO, &arg); setsockopt(client_info->client_sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); - inet_ntop(AF_INET, &client_addr.sin_addr, client_info->client_ip, INET_ADDRSTRLEN); - - client_info->client_string = "Client"; + /*-------------------------------------------------*\ + | Discover the remote hosts IP | + \*-------------------------------------------------*/ + struct sockaddr_storage tmp_addr; + char ipstr[INET6_ADDRSTRLEN]; + socklen_t len; + len = sizeof(tmp_addr); + getpeername(client_info->client_sock, (struct sockaddr*)&tmp_addr, &len); + + if(tmp_addr.ss_family == AF_INET) + { + 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; + } + 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; + } /* We need to lock before the thread could possibly finish */ ServerClientsMutex.lock(); @@ -402,7 +466,7 @@ void NetworkServer::ConnectionThreadFunction() ServerListeningChanged(); } -int NetworkServer::accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen) +int NetworkServer::accept_select(int sockfd) { fd_set set; struct timeval timeout; @@ -428,7 +492,7 @@ int NetworkServer::accept_select(int sockfd, struct sockaddr *addr, socklen_t *a else { // socket has something to read - return(accept(sockfd, addr, addrlen)); + return(accept(sockfd, NULL, NULL)); } } } diff --git a/NetworkServer.h b/NetworkServer.h index 2000219a..96f33939 100644 --- a/NetworkServer.h +++ b/NetworkServer.h @@ -17,6 +17,7 @@ #pragma once +#define MAXSOCK 32 #define TCP_TIMEOUT_SECONDS 5 typedef void (*NetServerCallback)(void *); @@ -31,7 +32,7 @@ public: std::thread * client_listen_thread; std::string client_string; unsigned int client_protocol_version; - char client_ip[INET_ADDRSTRLEN]; + std::string client_ip; }; class NetworkServer @@ -40,6 +41,7 @@ public: NetworkServer(std::vector& control); ~NetworkServer(); + std::string GetHost(); unsigned short GetPort(); bool GetOnline(); bool GetListening(); @@ -55,12 +57,13 @@ public: void ServerListeningChanged(); void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg); + void SetHost(std::string host); void SetPort(unsigned short new_port); void StartServer(); void StopServer(); - void ConnectionThreadFunction(); + void ConnectionThreadFunction(int socket_idx); void ListenThreadFunction(NetworkClientInfo * client_sock); void ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data); @@ -76,6 +79,7 @@ public: void SetProfileManager(ProfileManagerInterface* profile_manager_pointer); protected: + std::string host; unsigned short port_num; bool server_online; bool server_listening; @@ -84,7 +88,7 @@ protected: std::mutex ServerClientsMutex; std::vector ServerClients; - std::thread * ConnectionThread; + std::thread * ConnectionThread[MAXSOCK]; std::mutex ClientInfoChangeMutex; std::vector ClientInfoChangeCallbacks; @@ -101,8 +105,9 @@ private: WSADATA wsa; #endif - SOCKET server_sock; + int socket_count; + SOCKET server_sock[MAXSOCK]; - int accept_select(int sockfd, struct sockaddr *addr, socklen_t *addrlen); + int accept_select(int sockfd); int recv_select(SOCKET s, char *buf, int len, int flags); }; diff --git a/cli.cpp b/cli.cpp index 093d74ef..e712a337 100644 --- a/cli.cpp +++ b/cli.cpp @@ -993,6 +993,7 @@ unsigned int cli_pre_detection(int argc, char *argv[]) int arg_index = 1; unsigned int cfg_args = 0; unsigned int ret_flags = 0; + std::string server_host = OPENRGB_SDK_HOST; unsigned short server_port = OPENRGB_SDK_PORT; bool server_start = false; bool print_help = false; @@ -1150,6 +1151,27 @@ unsigned int cli_pre_detection(int argc, char *argv[]) cfg_args++; arg_index++; } + /*---------------------------------------------------------*\ + | --server-host | + \*---------------------------------------------------------*/ + else if(option == "--server-host") + { + if (argument != "") + { + std::string host = argument; + + server_host = host; + server_start = true; + } + else + { + std::cout << "Error: Missing argument for --server-host" << std::endl; + print_help = true; + break; + } + cfg_args++; + arg_index++; + } /*---------------------------------------------------------*\ | --loglevel | @@ -1382,7 +1404,9 @@ unsigned int cli_pre_detection(int argc, char *argv[]) if(server_start) { - ResourceManager::get()->GetServer()->SetPort(server_port); + NetworkServer * server = ResourceManager::get()->GetServer(); + server->SetHost(server_host); + server->SetPort(server_port); ret_flags |= RET_FLAG_START_SERVER; } diff --git a/net_port/net_port.cpp b/net_port/net_port.cpp index 69236301..6a2912a5 100644 --- a/net_port/net_port.cpp +++ b/net_port/net_port.cpp @@ -47,7 +47,7 @@ bool net_port::udp_client(const char * client_name, const char * port) sockaddr_in myAddress; #ifdef WIN32 - if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) + if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) { WSACleanup(); return(false); @@ -55,7 +55,7 @@ bool net_port::udp_client(const char * client_name, const char * port) #endif sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock == INVALID_SOCKET) + if(sock == INVALID_SOCKET) { WSACleanup(); return(false); @@ -65,7 +65,7 @@ bool net_port::udp_client(const char * client_name, const char * port) myAddress.sin_addr.s_addr = inet_addr("0.0.0.0"); myAddress.sin_port = htons(0); - if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) + if(bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) { WSACleanup(); return false; @@ -107,7 +107,7 @@ bool net_port::tcp_client(const char * client_name, const char * port) result_list = NULL; #ifdef WIN32 - if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) + if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) { WSACleanup(); return(false); @@ -116,7 +116,7 @@ bool net_port::tcp_client(const char * client_name, const char * port) port = strtok((char *)port, "\r"); - hints.ai_family = AF_INET; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; getaddrinfo(client_name, port, &hints, &result_list); @@ -131,11 +131,13 @@ bool net_port::tcp_client(const char * client_name, const char * port) bool net_port::tcp_client_connect() { + struct addrinfo *res; connected = false; + for(res = result_list; res; res = res->ai_next) { - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == INVALID_SOCKET) + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if(sock == INVALID_SOCKET) { WSACleanup(); return(false); @@ -152,7 +154,7 @@ bool net_port::tcp_client_connect() connected = false; return(false); } - connect(sock, result_list->ai_addr, result_list->ai_addrlen); + connect(sock, res->ai_addr, res->ai_addrlen); FD_ZERO(&fdset); FD_SET(sock, &fdset); @@ -165,14 +167,14 @@ bool net_port::tcp_client_connect() \*-------------------------------------------------*/ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); - if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1) + if(select(sock + 1, NULL, &fdset, NULL, &tv) == 1) { char so_error; socklen_t len = sizeof(so_error); getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len); - if (so_error == 0) + if(so_error == 0) { connected = true; arg = 0; @@ -201,7 +203,7 @@ bool net_port::tcp_server(const char * port) | Windows requires WSAStartup before using sockets | \*-------------------------------------------------*/ #ifdef WIN32 - if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) + if(WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) { WSACleanup(); return false; @@ -212,7 +214,7 @@ bool net_port::tcp_server(const char * port) | Create the server socket | \*-------------------------------------------------*/ sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == INVALID_SOCKET) + if(sock == INVALID_SOCKET) { WSACleanup(); return false; @@ -230,7 +232,7 @@ bool net_port::tcp_server(const char * port) /*-------------------------------------------------*\ | Bind the server socket | \*-------------------------------------------------*/ - if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) + if(bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) { WSACleanup(); return false; @@ -299,7 +301,7 @@ int net_port::tcp_write(char * buffer, int length) timeval waitd; fd_set writefd; - for (unsigned int i = 0; i < clients.size(); i++) + for(unsigned int i = 0; i < clients.size(); i++) { val = length; @@ -309,11 +311,11 @@ int net_port::tcp_write(char * buffer, int length) waitd.tv_sec = 5; waitd.tv_usec = 0; - if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd)) + if(select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd)) { val = send(*(clients[i]), (const char *)&length, sizeof(length), 0); - if (val == -1) + if(val == -1) { clients.erase(clients.begin() + i); return 0; @@ -328,17 +330,17 @@ int net_port::tcp_write(char * buffer, int length) waitd.tv_sec = 5; waitd.tv_usec = 0; - if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd)) + if(select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd)) { val = send(*(clients[i]), buffer, length, 0); - if (val == -1) + if(val == -1) { clients.erase(clients.begin() + i); return 0; } - if (val != length) + if(val != length) { ret = val; } diff --git a/qt/OpenRGBServerInfoPage.cpp b/qt/OpenRGBServerInfoPage.cpp index 070d4ed9..9f44ec4a 100644 --- a/qt/OpenRGBServerInfoPage.cpp +++ b/qt/OpenRGBServerInfoPage.cpp @@ -30,6 +30,7 @@ OpenRGBServerInfoPage::~OpenRGBServerInfoPage() void OpenRGBServerInfoPage::UpdateInfo() { + ui->ServerHostValue->setText(network_server->GetHost().c_str()); ui->ServerPortValue->setText(std::to_string(network_server->GetPort()).c_str()); if(network_server->GetListening() && !network_server->GetOnline()) @@ -37,6 +38,7 @@ void OpenRGBServerInfoPage::UpdateInfo() ui->ServerStatusValue->setText(tr("Stopping...")); ui->ServerStartButton->setEnabled(false); ui->ServerStopButton->setEnabled(false); + ui->ServerHostValue->setEnabled(false); ui->ServerPortValue->setEnabled(false); } else if(network_server->GetListening()) @@ -44,6 +46,7 @@ void OpenRGBServerInfoPage::UpdateInfo() ui->ServerStatusValue->setText(tr("Online")); ui->ServerStartButton->setEnabled(false); ui->ServerStopButton->setEnabled(true); + ui->ServerHostValue->setEnabled(false); ui->ServerPortValue->setEnabled(false); } else @@ -51,6 +54,7 @@ void OpenRGBServerInfoPage::UpdateInfo() ui->ServerStatusValue->setText(tr("Offline")); ui->ServerStartButton->setEnabled(true); ui->ServerStopButton->setEnabled(false); + ui->ServerHostValue->setEnabled(true); ui->ServerPortValue->setEnabled(true); } @@ -73,6 +77,7 @@ void Ui::OpenRGBServerInfoPage::on_ServerStartButton_clicked() { if(network_server->GetOnline() == false) { + network_server->SetHost(ui->ServerHostValue->text().toStdString()); network_server->SetPort(ui->ServerPortValue->text().toInt()); network_server->StartServer(); diff --git a/qt/OpenRGBServerInfoPage.ui b/qt/OpenRGBServerInfoPage.ui index 93c98357..cee5dace 100644 --- a/qt/OpenRGBServerInfoPage.ui +++ b/qt/OpenRGBServerInfoPage.ui @@ -14,20 +14,65 @@ Server info page - + Stop Server - + Server Port: + + + + Connected Clients: + + + + + + + 0 + + + + + + + + 0 + 0 + + + + + + + + Server Status: + + + + + + + Start Server + + + + + + + Offline + + + @@ -41,36 +86,15 @@ - - + + - Start Server - - - - - - - 0 - - - - - - - Server Status: - - - - - - - Offline + Server Host: - + 0 @@ -79,13 +103,6 @@ - - - - Connected Clients: - - - diff --git a/qt/OpenRGBSettingsPage.cpp b/qt/OpenRGBSettingsPage.cpp index 8b9e7d5b..41bda7a7 100644 --- a/qt/OpenRGBSettingsPage.cpp +++ b/qt/OpenRGBSettingsPage.cpp @@ -114,6 +114,9 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) : /*---------------------------------------------------------*\ | Text boxes | \*---------------------------------------------------------*/ + ui->TextServerHost->setText(QString::fromStdString(autostart_settings["host"])); + ui->TextServerHost->setEnabled(autostart_settings["setserverhost"]); + ui->TextServerPort->setText(QString::fromStdString(autostart_settings["port"])); ui->TextServerPort->setEnabled(autostart_settings["setserverport"]); @@ -132,6 +135,7 @@ OpenRGBSettingsPage::OpenRGBSettingsPage(QWidget *parent) : ui->CheckboxAutoStartMinimized->setChecked(autostart_settings["setminimized"]); ui->CheckboxAutoStartClient->setChecked(autostart_settings["setclient"]); ui->CheckboxAutoStartServer->setChecked(autostart_settings["setserver"]); + ui->CheckboxAutoStartSetServerHost->setChecked(autostart_settings["setserverhost"]); ui->CheckboxAutoStartSetServerPort->setChecked(autostart_settings["setserverport"]); ui->CheckboxAutoStartCustom->setChecked(autostart_settings["setcustom"]); @@ -331,6 +335,12 @@ void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartServer_clicked() SaveAutoStartSetting("setserver", ui->CheckboxAutoStartServer->isChecked()); } +void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartSetServerHost_clicked() +{ + SaveAutoStartSetting("setserverhost", ui->CheckboxAutoStartSetServerHost->isChecked()); + ui->TextServerHost->setEnabled(ui->CheckboxAutoStartSetServerHost->isChecked()); +} + void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartSetServerPort_clicked() { SaveAutoStartSetting("setserverport", ui->CheckboxAutoStartSetServerPort->isChecked()); @@ -355,6 +365,11 @@ void Ui::OpenRGBSettingsPage::on_CheckboxAutoStartCustom_clicked() ui->TextCustomArgs->setEnabled(ui->CheckboxAutoStartCustom->isChecked()); } +void Ui::OpenRGBSettingsPage::on_TextServerHost_textChanged(QString host) +{ + SaveAutoStartSetting("host", host); +} + void Ui::OpenRGBSettingsPage::on_TextServerPort_textChanged(QString port) { SaveAutoStartSetting("port", port); @@ -411,9 +426,11 @@ void OpenRGBSettingsPage::SetAutoStartVisibility(bool visible) ui->CheckboxAutoStartMinimized->hide(); ui->CheckboxAutoStartProfile->hide(); ui->CheckboxAutoStartServer->hide(); + ui->CheckboxAutoStartSetServerHost->hide(); ui->CheckboxAutoStartSetServerPort->hide(); ui->TextCustomArgs->hide(); ui->TextClientHost->hide(); + ui->TextServerHost->hide(); ui->TextServerPort->hide(); ui->AutoStartStatusLabel->hide(); } @@ -425,9 +442,11 @@ void OpenRGBSettingsPage::SetAutoStartVisibility(bool visible) ui->CheckboxAutoStartMinimized->show(); ui->CheckboxAutoStartProfile->show(); ui->CheckboxAutoStartServer->show(); + ui->CheckboxAutoStartSetServerHost->show(); ui->CheckboxAutoStartSetServerPort->show(); ui->TextCustomArgs->show(); ui->TextClientHost->show(); + ui->TextServerHost->show(); ui->TextServerPort->show(); ui->AutoStartStatusLabel->show(); } @@ -438,6 +457,7 @@ void OpenRGBSettingsPage::ConfigureAutoStart() std::map> autostart_map = { {"setminimized", {"--startminimized","",false}}, {"setserver", {"--server","",false}}, + {"setserverhost", {"--server-host","host",false}}, {"setserverport", {"--server-port","port",false}}, {"setclient", {"--client","client",false}}, {"setprofile", {"--profile","profile",true}}, @@ -533,6 +553,7 @@ void OpenRGBSettingsPage::CreateAutoStartSettings() { std::map autostart_default_map_string = { {"custom", ""}, + {"host", "0.0.0.0"}, {"port", "6742"}, {"client","localhost:6742"}, {"profile",ui->ComboBoxAutoStartProfile->count() > 0 ? ui->ComboBoxAutoStartProfile->itemText(0).toStdString(): ""} @@ -543,6 +564,7 @@ void OpenRGBSettingsPage::CreateAutoStartSettings() {"setminimized", false}, {"setclient", false}, {"setserver", false}, + {"setserverhost", false}, {"setserverport", false}, {"setcustom", false}, {"setprofile", false}, diff --git a/qt/OpenRGBSettingsPage.h b/qt/OpenRGBSettingsPage.h index a8fe6751..02060f07 100644 --- a/qt/OpenRGBSettingsPage.h +++ b/qt/OpenRGBSettingsPage.h @@ -48,10 +48,12 @@ private slots: void on_CheckboxAutoStartServer_clicked(); void on_CheckboxAutoStartClient_clicked(); void on_CheckboxAutoStartProfile_clicked(); + void on_TextServerHost_textChanged(const QString); void on_TextServerPort_textChanged(const QString); void on_TextClientHost_textChanged(const QString); void on_TextCustomArgs_textChanged(const QString); void on_ComboBoxAutoStartProfile_currentTextChanged(const QString); + void on_CheckboxAutoStartSetServerHost_clicked(); void on_CheckboxAutoStartSetServerPort_clicked(); void on_CheckboxAutoStartCustom_clicked(); void on_CheckboxRunZoneChecks_clicked(); diff --git a/qt/OpenRGBSettingsPage.ui b/qt/OpenRGBSettingsPage.ui index 0192d84c..a35dbcd5 100644 --- a/qt/OpenRGBSettingsPage.ui +++ b/qt/OpenRGBSettingsPage.ui @@ -29,13 +29,30 @@ - 0 - -204 - 427 - 670 + -67 + -258 + 465 + 724 + + + + Start At Login + + + + + + + Save Geometry On Close + + + + + + @@ -43,6 +60,51 @@ + + + + Start at Login Status + + + + + + + AMD SMBus: Reduce CPU Usage (restart required) + + + + + + + Custom Arguments + + + + + + + Start Server + + + + + + + Theme (restart required) + + + + + + + Log Manager Settings: + + + + + + @@ -50,24 +112,30 @@ - - + + - Load Window Geometry - - - - - - - Drivers Settings + User Interface Settings: - + - + + + + 90000 + + + + + + + + + + Set Server Port @@ -81,52 +149,17 @@ - - + + - Start Server + Start At Login Settings: - - - - User Interface Settings: - - + + - - - - Greyscale Tray Icon - - - - - - - - - - Log Manager Settings: - - - - - - - Custom Arguments - - - - - - - Load Profile - - - - + Qt::Vertical @@ -142,74 +175,20 @@ - - - - - + + - Start At Login + Load Window Geometry - - - - 90000 - - - - - - - - - - - - - AMD SMBus: Reduce CPU Usage (restart required) - - - - + Start Client - - - - - - - Start At Login Settings: - - - - - - - Start at Login Status - - - - - - - Save Geometry On Close - - - - - - - Theme (restart required) - - - @@ -217,15 +196,46 @@ + + + + Drivers Settings + + + + + + Load Profile + + + + + + + + + + Greyscale Tray Icon + + + + Set Profile on Exit - - + + + + Set Server Host + + + + +