1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 05:53:02 +01:00

Merge pull request #2910 from Overv/automatic-player-name

Change default player name to use the OS username if available (resolves #2761)
This commit is contained in:
Ted John
2016-02-12 00:04:22 +00:00
5 changed files with 33 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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);

View File

@@ -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

View File

@@ -23,6 +23,7 @@
#ifdef __WINDOWS__
#include <windows.h>
#include <lmcons.h>
#include <psapi.h>
#include <shlobj.h>
#include <SDL_syswm.h>
@@ -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