diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 75d355f543..16202a9e87 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -10,6 +10,7 @@ - Fix: [#5920] Placing guest spawn doesn't do anything every 3rd click - Fix: [#5939] Crash when importing 'Six Flags Santa Fe'. - Improved: The land tool buttons can now be held down to increase/decrease size. +- Improved: [#4301] Leading and trailing whitespace in player name is now removed. - Improved: [#5859] OpenGL rendering performance - Improved: [#5863] Switching drawing engines no longer requires the application to restart. diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 0da1d13e5f..8fc6c41e90 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -347,18 +347,22 @@ namespace Config { // If the `player_name` setting is missing or equal to the empty string // use the logged-in user's username instead - utf8* playerName = reader->GetCString("player_name", ""); - if (String::IsNullOrEmpty(playerName)) + auto playerName = reader->GetString("player_name", ""); + if (playerName.empty()) { - playerName = String::Duplicate(platform_get_username()); - if (playerName == nullptr) + playerName = String::ToStd(platform_get_username()); + if (playerName.empty()) { - playerName = String::Duplicate("Player"); + playerName = "Player"; } } + // Trim any whitespace before or after the player's name, + // to avoid people pretending to be someone else + playerName = String::Trim(playerName); + auto model = &gConfigNetwork; - model->player_name = playerName; + model->player_name = String::Duplicate(playerName); model->default_port = reader->GetSint32("default_port", NETWORK_DEFAULT_PORT); model->listen_address = reader->GetCString("listen_address", ""); model->default_password = reader->GetCString("default_password", nullptr); diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index d1e351d0b1..97647b2f07 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -1478,7 +1478,7 @@ NetworkPlayer* Network::AddPlayer(const utf8 *name, const std::string &keyhash) if (networkUser == nullptr) { player->Group = GetDefaultGroup(); if (!String::IsNullOrEmpty(name)) { - player->SetName(MakePlayerNameUnique(std::string(name))); + player->SetName(MakePlayerNameUnique(String::Trim(std::string(name)))); } } else { player->Group = networkUser->GroupId.GetValueOrDefault(GetDefaultGroup()); @@ -1488,7 +1488,7 @@ NetworkPlayer* Network::AddPlayer(const utf8 *name, const std::string &keyhash) player = std::unique_ptr(new NetworkPlayer); // change to make_unique in c++14 player->Id = newid; player->Group = GetDefaultGroup(); - player->SetName(name); + player->SetName(String::Trim(std::string(name))); } addedplayer = player.get(); diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 6565db4acf..c66a5581d6 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -55,7 +55,7 @@ extern "C" { // This define specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "4" +#define NETWORK_STREAM_VERSION "5" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION #ifdef __cplusplus