Rework server initialization

* Only create server instance if server is actually needed
    * Pass initial server host and port through ResourceManager
    * Allow setting default server host and port in Server settings
This commit is contained in:
Adam Honse
2026-04-05 21:25:12 -05:00
parent 9ac84ed408
commit 9b84f28cba
12 changed files with 297 additions and 97 deletions

17
cli.cpp
View File

@@ -1269,8 +1269,6 @@ 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;
@@ -1408,14 +1406,14 @@ unsigned int cli_pre_detection(int argc, char* argv[])
\*---------------------------------------------------------*/
else if(option == "--server-port")
{
if (argument != "")
if(argument != "")
{
try
{
int port = std::stoi(argument);
if (port >= 1024 && port <= 65535)
if(port >= 1024 && port <= 65535)
{
server_port = port;
ResourceManager::get()->SetDefaultServerPort(port);
server_start = true;
}
else
@@ -1446,11 +1444,9 @@ unsigned int cli_pre_detection(int argc, char* argv[])
\*---------------------------------------------------------*/
else if(option == "--server-host")
{
if (argument != "")
if(argument != "")
{
std::string host = argument;
server_host = host;
ResourceManager::get()->SetDefaultServerHost(argument);
server_start = true;
}
else
@@ -1694,9 +1690,6 @@ unsigned int cli_pre_detection(int argc, char* argv[])
if(server_start)
{
NetworkServer * server = ResourceManager::get()->GetServer();
server->SetHost(server_host);
server->SetPort(server_port);
ret_flags |= RET_FLAG_START_SERVER;
}