diff --git a/src/cmdline/RootCommands.cpp b/src/cmdline/RootCommands.cpp index c9f947a76d..f9d5fce90e 100644 --- a/src/cmdline/RootCommands.cpp +++ b/src/cmdline/RootCommands.cpp @@ -29,6 +29,7 @@ static bool _headless = false; #ifndef DISABLE_NETWORK static uint32 _port = 0; #endif +static utf8 * _password = nullptr; static utf8 * _userDataPath = nullptr; static utf8 * _openrctDataPath = nullptr; @@ -44,6 +45,7 @@ static const CommandLineOptionDefinition StandardOptions[] #ifndef DISABLE_NETWORK { CMDLINE_TYPE_INTEGER, &_port, NAC, "port", "port to use for hosting or joining a server" }, #endif + { CMDLINE_TYPE_STRING, &_password, NAC, "password", "password needed to join the server" }, { CMDLINE_TYPE_STRING, &_userDataPath, NAC, "user-data-path", "path to the user data directory (containing config.ini)" }, { CMDLINE_TYPE_STRING, &_openrctDataPath, NAC, "openrct-data-path", "path to the OpenRCT2 data directory (containing languages)" }, OptionTableEnd @@ -135,6 +137,11 @@ exitcode_t CommandLine::HandleCommandDefault() Memory::Free(_openrctDataPath); } + if (_password != NULL) { + String::Set(gCustomPassword, sizeof(gCustomPassword), _password); + Memory::Free(_password); + } + return result; } @@ -208,7 +215,7 @@ exitcode_t HandleCommandHost(CommandLineArgEnumerator * enumerator) gOpenRCT2StartupAction = STARTUP_ACTION_OPEN; String::Set(gOpenRCT2StartupActionPath, sizeof(gOpenRCT2StartupActionPath), parkUri); - gNetworkStart = NETWORK_MODE_SERVER; + gNetworkStart = NETWORK_MODE_SERVER; gNetworkStartPort = _port; return EXITCODE_CONTINUE; } @@ -228,9 +235,9 @@ exitcode_t HandleCommandJoin(CommandLineArgEnumerator * enumerator) return EXITCODE_FAIL; } - gNetworkStart = NETWORK_MODE_CLIENT; + gNetworkStart = NETWORK_MODE_CLIENT; gNetworkStartPort = _port; - String::Set(gNetworkStartHost, sizeof(gNetworkStartHost), hostname); + String::Set(gNetworkStartHost, sizeof(gNetworkStartHost), hostname); return EXITCODE_CONTINUE; } diff --git a/src/config.c b/src/config.c index 850a4b978f..76c45357b5 100644 --- a/src/config.c +++ b/src/config.c @@ -253,6 +253,7 @@ config_property_definition _twitchDefinitions[] = { config_property_definition _networkDefinitions[] = { { offsetof(network_configuration, player_name), "player_name", CONFIG_VALUE_TYPE_STRING, {.value_string = "Player" }, NULL }, { offsetof(network_configuration, default_port), "default_port", CONFIG_VALUE_TYPE_UINT32, NETWORK_DEFAULT_PORT, NULL }, + { offsetof(network_configuration, default_password), "default_password", CONFIG_VALUE_TYPE_STRING, {.value_string = NULL }, NULL }, { offsetof(network_configuration, stay_connected), "stay_connected", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, { offsetof(network_configuration, advertise), "advertise", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, { offsetof(network_configuration, maxplayers), "maxplayers", CONFIG_VALUE_TYPE_UINT8, 16, NULL }, diff --git a/src/config.h b/src/config.h index fb00eb8814..ac77571c40 100644 --- a/src/config.h +++ b/src/config.h @@ -226,6 +226,7 @@ typedef struct { typedef struct { utf8string player_name; uint32 default_port; + utf8string default_password; uint8 stay_connected; uint8 advertise; uint8 maxplayers; diff --git a/src/openrct2.c b/src/openrct2.c index f9b55dd7e6..8cc31ed9bb 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -55,6 +55,7 @@ utf8 gOpenRCT2StartupActionPath[512] = { 0 }; utf8 gExePath[MAX_PATH]; utf8 gCustomUserDataPath[MAX_PATH] = { 0 }; utf8 gCustomOpenrctDataPath[MAX_PATH] = { 0 }; +utf8 gCustomPassword[MAX_PATH] = { 0 }; // This should probably be changed later and allow a custom selection of things to initialise like SDL_INIT bool gOpenRCT2Headless = false; @@ -287,6 +288,13 @@ void openrct2_launch() if (gNetworkStartPort == 0) { gNetworkStartPort = gConfigNetwork.default_port; } + + if (str_is_null_or_empty(gCustomPassword)) { + network_set_password(gConfigNetwork.default_password); + } + else { + network_set_password(gCustomPassword); + } network_begin_server(gNetworkStartPort); } #endif // DISABLE_NETWORK @@ -305,6 +313,7 @@ void openrct2_launch() if (gNetworkStartPort == 0) { gNetworkStartPort = gConfigNetwork.default_port; } + network_begin_client(gNetworkStartHost, gNetworkStartPort); } #endif // DISABLE_NETWORK diff --git a/src/openrct2.h b/src/openrct2.h index 82eb77452a..4be5d7fcb3 100644 --- a/src/openrct2.h +++ b/src/openrct2.h @@ -39,6 +39,7 @@ extern utf8 gOpenRCT2StartupActionPath[512]; extern utf8 gExePath[MAX_PATH]; extern utf8 gCustomUserDataPath[MAX_PATH]; extern utf8 gCustomOpenrctDataPath[MAX_PATH]; +extern utf8 gCustomPassword[MAX_PATH]; extern bool gOpenRCT2Headless; extern bool gOpenRCT2ShowChangelog;