diff --git a/src/config.c b/src/config.c index 2eb1f44c9a..992a2f29ce 100644 --- a/src/config.c +++ b/src/config.c @@ -374,6 +374,15 @@ void config_set_defaults() else if (strcmp(property->property_name, "temperature_format") == 0){ destValue->value_uint8 = platform_get_locale_temperature_format(); } + else if (strcmp(property->property_name, "player_name") == 0) { + utf8* username = platform_get_username(); + + if (username) { + destValue->value_string = _strdup(username); + } else { + destValue->value_string = _strdup(language_get_string(STR_PLAYER_DEFAULT_NAME)); + } + } else { // Use static default if (property->type == CONFIG_VALUE_TYPE_STRING) { diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 893142ad15..9cce3826d0 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -475,6 +475,7 @@ enum { STR_WATER_RIDES_TIP = 1227, STR_SHOPS_STALLS_TIP = 1228, + STR_PLAYER_DEFAULT_NAME = 1315, STR_X_PLAYER = 1317, STR_X_PLAYERS = 1318, diff --git a/src/platform/platform.h b/src/platform/platform.h index 24717e007b..2f69731ca2 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -157,6 +157,7 @@ void platform_resolve_user_data_path(); void platform_resolve_openrct_data_path(); void platform_get_openrct_data_path(utf8 *outPath); void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory); +utf8* platform_get_username(); void platform_show_messagebox(utf8 *message); int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8 *filterPattern, utf8 *filterName); utf8 *platform_open_directory_browser(utf8 *title); diff --git a/src/platform/posix.c b/src/platform/posix.c index 04cb3e89b4..850ad1df5a 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -876,4 +876,14 @@ datetime64 platform_get_datetime_now_utc() return utcNow; } +utf8* platform_get_username() { + struct passwd* pw = getpwuid(getuid()); + + if (pw) { + return pw->pw_name; + } else { + return NULL; + } +} + #endif diff --git a/src/platform/windows.c b/src/platform/windows.c index 8f0be894b3..31c8fc7fd5 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -23,6 +23,7 @@ #ifdef __WINDOWS__ #include +#include #include #include #include @@ -975,4 +976,15 @@ datetime64 platform_get_datetime_now_utc() return utcNow; } +utf8* platform_get_username() { + static char username[UNLEN + 1]; + + DWORD usernameLength = UNLEN + 1; + if (!GetUserName(username, &usernameLength)) { + return NULL; + } + + return username; +} + #endif