Merge pull request #5777 from Keatzee/fix-4301

Fix #4301: Remove leading/trailing whitespace from playername
This commit is contained in:
Ted John 2017-07-22 10:17:57 +01:00 committed by GitHub
commit 52372b7429
4 changed files with 14 additions and 9 deletions

View file

@ -10,6 +10,7 @@
- Fix: [#5920] Placing guest spawn doesn't do anything every 3rd click - Fix: [#5920] Placing guest spawn doesn't do anything every 3rd click
- Fix: [#5939] Crash when importing 'Six Flags Santa Fe'. - Fix: [#5939] Crash when importing 'Six Flags Santa Fe'.
- Improved: The land tool buttons can now be held down to increase/decrease size. - 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: [#5859] OpenGL rendering performance
- Improved: [#5863] Switching drawing engines no longer requires the application to restart. - Improved: [#5863] Switching drawing engines no longer requires the application to restart.

View file

@ -347,18 +347,22 @@ namespace Config
{ {
// If the `player_name` setting is missing or equal to the empty string // If the `player_name` setting is missing or equal to the empty string
// use the logged-in user's username instead // use the logged-in user's username instead
utf8* playerName = reader->GetCString("player_name", ""); auto playerName = reader->GetString("player_name", "");
if (String::IsNullOrEmpty(playerName)) if (playerName.empty())
{ {
playerName = String::Duplicate(platform_get_username()); playerName = String::ToStd(platform_get_username());
if (playerName == nullptr) 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; auto model = &gConfigNetwork;
model->player_name = playerName; model->player_name = String::Duplicate(playerName);
model->default_port = reader->GetSint32("default_port", NETWORK_DEFAULT_PORT); model->default_port = reader->GetSint32("default_port", NETWORK_DEFAULT_PORT);
model->listen_address = reader->GetCString("listen_address", ""); model->listen_address = reader->GetCString("listen_address", "");
model->default_password = reader->GetCString("default_password", nullptr); model->default_password = reader->GetCString("default_password", nullptr);

View file

@ -1478,7 +1478,7 @@ NetworkPlayer* Network::AddPlayer(const utf8 *name, const std::string &keyhash)
if (networkUser == nullptr) { if (networkUser == nullptr) {
player->Group = GetDefaultGroup(); player->Group = GetDefaultGroup();
if (!String::IsNullOrEmpty(name)) { if (!String::IsNullOrEmpty(name)) {
player->SetName(MakePlayerNameUnique(std::string(name))); player->SetName(MakePlayerNameUnique(String::Trim(std::string(name))));
} }
} else { } else {
player->Group = networkUser->GroupId.GetValueOrDefault(GetDefaultGroup()); player->Group = networkUser->GroupId.GetValueOrDefault(GetDefaultGroup());
@ -1488,7 +1488,7 @@ NetworkPlayer* Network::AddPlayer(const utf8 *name, const std::string &keyhash)
player = std::unique_ptr<NetworkPlayer>(new NetworkPlayer); // change to make_unique in c++14 player = std::unique_ptr<NetworkPlayer>(new NetworkPlayer); // change to make_unique in c++14
player->Id = newid; player->Id = newid;
player->Group = GetDefaultGroup(); player->Group = GetDefaultGroup();
player->SetName(name); player->SetName(String::Trim(std::string(name)));
} }
addedplayer = player.get(); addedplayer = player.get();

View file

@ -55,7 +55,7 @@ extern "C" {
// This define specifies which version of network stream current build uses. // This define specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within // It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version. // single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "4" #define NETWORK_STREAM_VERSION "5"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
#ifdef __cplusplus #ifdef __cplusplus