diff --git a/source/code/main.cpp b/source/code/main.cpp index 3b5c601..dd2d20d 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -998,7 +998,7 @@ int main(int argc, char* argv[]) { keySettings[player2keys].change = SDLK_LCTRL; keySettings[player2keys].push = SDLK_LSHIFT; - globalData.player1name = _("Player 1"); + globalData.player1name = defaultPlayerName(); globalData.player2name = _("Player 2"); Config* configSettings = Config::getInstance(); diff --git a/source/code/os.cpp b/source/code/os.cpp index e04bb4a..848608e 100644 --- a/source/code/os.cpp +++ b/source/code/os.cpp @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/ Source information and contacts persons can be found at -http://blockattack.net +https://blockattack.net =========================================================================== */ @@ -27,6 +27,11 @@ http://blockattack.net #include "sago/platform_folders.h" #include "version.h" +#if defined(__unix__) +#include +#include +#endif + static sago::PlatformFolders pf; static std::string overrideSavePath = ""; @@ -48,6 +53,22 @@ void setPathToSaveFiles(const std::string& path) { overrideSavePath = path; } +std::string defaultPlayerName() { + std::string ret; + #if defined(__unix__) + int uid = getuid(); + struct passwd* pw = getpwuid(uid); + if (pw && pw->pw_gecos) { + ret = pw->pw_gecos; + ret = ret.substr(0, ret.find_first_of(',',0)); + } + if (pw && pw->pw_name && ret.empty()) { + ret = pw->pw_name; + } + #endif + return ret; +} + void OsCreateSaveFolder() { #if defined(__unix__) std::string cmd = "mkdir -p '"+getPathToSaveFiles()+"/'"; diff --git a/source/code/os.hpp b/source/code/os.hpp index ab99a33..3277fa3 100644 --- a/source/code/os.hpp +++ b/source/code/os.hpp @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/ Source information and contacts persons can be found at -http://blockattack.net +https://blockattack.net =========================================================================== */ @@ -32,6 +32,8 @@ std::string getPathToSaveFiles(); std::string getMyDocumentsPath(); #endif +std::string defaultPlayerName(); + void setPathToSaveFiles(const std::string& path); void OsCreateSaveFolder();