Change default player name to use the OS username if available (resolves #2761)

This commit is contained in:
Alexander Overvoorde 2016-02-10 21:49:10 +01:00
parent 2077c51e0b
commit 75b072d266
4 changed files with 27 additions and 0 deletions

View File

@ -374,6 +374,9 @@ 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) {
destValue->value_string = _strdup(platform_get_username());
}
else {
// Use static default
if (property->type == CONFIG_VALUE_TYPE_STRING) {

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

@ -43,6 +43,7 @@
#include <time.h>
#include <fts.h>
#include <sys/file.h>
#include <unistd.h>
// The name of the mutex used to prevent multiple instances of the game from running
#define SINGLE_INSTANCE_MUTEX_NAME "openrct2.lock"
@ -876,4 +877,14 @@ datetime64 platform_get_datetime_now_utc()
return utcNow;
}
utf8* platform_get_username() {
char* username = getlogin();
if (username) {
return username;
} else {
return "Player";
}
}
#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)) {
strcpy(username, "Player");
}
return username;
}
#endif