From 21ccf587c3efd980444a6167ff819dcd52888c57 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 7 Jul 2018 12:32:06 +0800 Subject: [PATCH] Add --init-user for server owner to save player profile without gui --- src/config/player_manager.cpp | 8 +++++--- src/main.cpp | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index f52e470e4..e2a159d87 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -326,8 +326,9 @@ void PlayerManager::enforceCurrentPlayer() { if (!player->isGuestAccount()) { - Log::info("PlayerManager", "Enforcing current player '%ls'.", - player->getName(true/*ignoreRTL*/).c_str()); + Log::info("PlayerManager", "Enforcing current player '%s'.", + StringUtils::wideToUtf8(player->getName(true/*ignoreRTL*/)) + .c_str()); m_current_player = player; return; } @@ -341,7 +342,8 @@ void PlayerManager::enforceCurrentPlayer() if (!player->isGuestAccount()) { Log::info("PlayerManager", "Enforcing current player '%s'.", - player->getName(true/*ignoreRTL*/).c_str()); + StringUtils::wideToUtf8(player->getName(true/*ignoreRTL*/)) + .c_str()); m_current_player = player; return; } diff --git a/src/main.cpp b/src/main.cpp index 1226e355d..6119b601e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -597,6 +597,7 @@ void cmdLineHelp() " public port.\n" " --login=s Automatically log in (set the login).\n" " --password=s Automatically log in (set the password).\n" + " --init-user Save the above login and password (if set) in config.\n" " --port=n Port number to use.\n" " --disable-lan Disable LAN detection (connect using WAN).\n" " --auto-connect Automatically connect to fist server and start race\n" @@ -1031,6 +1032,13 @@ int handleCmdLine() } } // --type + bool init_user = CommandLine::has("--init-user"); + if (init_user) + { + PlayerManager::get()->enforceCurrentPlayer(); + PlayerManager::getCurrentPlayer()->setRememberPassword(true); + UserConfigParams::m_internet_status = Online::RequestManager::IPERM_ALLOWED; + } if (CommandLine::has("--login", &s)) login = s.c_str(); if (CommandLine::has("--password", &s)) @@ -1047,8 +1055,16 @@ int handleCmdLine() StkTime::sleep(1); } Log::info("Main", "Logged in from command-line."); + if (init_user) + PlayerManager::getCurrentPlayer()->setWasOnlineLastTime(true); can_wan = true; } + if (init_user) + { + Log::info("Main", "Done saving user, leaving"); + cleanSuperTuxKart(); + return false; + } if (!can_wan && CommandLine::has("--login-id", &n) && CommandLine::has("--token", &s)) @@ -1664,12 +1680,12 @@ void askForInternetPermission() // than sorry). If internet should be allowed, the news // manager needs to be started (which in turn activates // the add-ons manager). +#ifndef SERVER_ONLY bool need_to_start_news_manager = UserConfigParams::m_internet_status != Online::RequestManager::IPERM_ALLOWED; UserConfigParams::m_internet_status = Online::RequestManager::IPERM_ALLOWED; -#ifndef SERVER_ONLY if (need_to_start_news_manager) NewsManager::get()->init(false); #endif