Use steam player name as default playername if nothing was set

This commit is contained in:
titiger 2017-03-13 00:58:06 +01:00
parent 6468f13f28
commit 4425b7d234
2 changed files with 20 additions and 5 deletions

View File

@ -3295,6 +3295,22 @@ void ShowINISettings(int argc, char **argv,Config &config,Config &configKeys) {
}
}
void setupSteamSettings(){
bool needToSaveConfig=false;
Config &config = Config::getInstance();
string steamPlayerName = safeCharPtrCopy(getenv("SteamAppUser"),100);
if( steamPlayerName=="") return;// not a steam launch
string currentPLayerName=config.getString("NetPlayerName","");
if( currentPLayerName=="newbie" || currentPLayerName=="" ){
config.setString("NetPlayerName",steamPlayerName);
needToSaveConfig=true;
}
if( needToSaveConfig == true ){
config.save();
}
}
void CheckForDuplicateData() {
Config &config = Config::getInstance();
@ -4185,9 +4201,6 @@ int glestMain(int argc, char** argv) {
return 2;
}
if( hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
//isMasterServerModeEnabled = true;
//Window::setMasterserverMode(isMasterServerModeEnabled);
@ -4526,6 +4539,8 @@ int glestMain(int argc, char** argv) {
Config &config = Config::getInstance();
setupGameItemPaths(argc, argv, &config);
setupSteamSettings();
if(config.getString("PlayerId","") == "") {
char uuid_str[38];
get_uuid_string(uuid_str,sizeof(uuid_str));
@ -4533,6 +4548,7 @@ int glestMain(int argc, char** argv) {
config.setString("PlayerId",uuid_str);
config.save();
}
//printf("Players UUID: [%s]\n",config.getString("PlayerId","").c_str());
if(config.getBool("DisableLuaSandbox","false") == true) {

View File

@ -174,8 +174,7 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu, Program
labelPlayerNameLabel.setText(lang.getString("Playername"));
labelPlayerName.init(currentColumnStart,currentLine);
string steamPlayerName = safeCharPtrCopy(getenv("SteamAppUser"),100);
labelPlayerName.setText(config.getString("NetPlayerName",(steamPlayerName != "" ? steamPlayerName.c_str() : Socket::getHostName().c_str())));
labelPlayerName.setText(config.getString("NetPlayerName",Socket::getHostName().c_str()));
labelPlayerName.setFont(CoreData::getInstance().getMenuFontBig());
labelPlayerName.setFont3D(CoreData::getInstance().getMenuFontBig3D());
labelPlayerName.setEditable(true);