Automatically create offline account when logged into steam.
This commit is contained in:
parent
bff3989bfc
commit
ffca9b14d8
@ -162,6 +162,11 @@
|
||||
work anymore - so for now don't enable this. -->
|
||||
<networking enable="false"/>
|
||||
|
||||
<!-- Steam related settings:
|
||||
ask-for-internet - If true the user on first start will be asked
|
||||
for permission to connect to stk servers. -->
|
||||
<steam ask-for-internet="false"/>
|
||||
|
||||
<!-- The field od views for 1-4 player split screen. fov-3 is
|
||||
actually not used (since 3 player split screen uses the
|
||||
same layout as 4 player split screen) -->
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "io/utf_writer.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "online/online_player_profile.hpp"
|
||||
#include "online/steam.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
@ -216,7 +217,17 @@ void PlayerManager::load()
|
||||
stringw name;
|
||||
current->getAndDecode("player", &name);
|
||||
m_current_player = getPlayer(name);
|
||||
// If the account is a steam account, make sure we are logged
|
||||
// into steam with the right user id.
|
||||
if(m_current_player->isSteamUser() &&
|
||||
Steam::get()->getSteamID() != m_current_player->getSteamUserID())
|
||||
{
|
||||
Log::warn("PlayerManager",
|
||||
"Logged in as different steam user, please log in as '%s'.",
|
||||
name.c_str());
|
||||
m_current_player = NULL;
|
||||
}
|
||||
} // if current
|
||||
|
||||
} // load
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "online/online_player_profile.hpp"
|
||||
#include "online/steam.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "io/utf_writer.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@ -38,6 +39,14 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xABCD1234;
|
||||
#endif
|
||||
if(Steam::get()->isSteamAvailable() &&
|
||||
name == StringUtils::utf8ToWide(Steam::get()->getUserName()) )
|
||||
{
|
||||
m_steam_id = Steam::get()->getSteamID();
|
||||
}
|
||||
else
|
||||
m_steam_id = "";
|
||||
|
||||
m_local_name = name;
|
||||
m_is_guest_account = is_guest;
|
||||
m_use_frequency = is_guest ? -1 : 0;
|
||||
@ -68,6 +77,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
|
||||
*/
|
||||
PlayerProfile::PlayerProfile(const XMLNode* node)
|
||||
{
|
||||
m_steam_id = "";
|
||||
m_saved_session = false;
|
||||
m_saved_token = "";
|
||||
m_saved_user_id = 0;
|
||||
@ -79,6 +89,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
|
||||
m_icon_filename = "";
|
||||
|
||||
node->getAndDecode("name", &m_local_name );
|
||||
node->get("steam-id", &m_steam_id );
|
||||
node->get("guest", &m_is_guest_account );
|
||||
node->get("use-frequency", &m_use_frequency );
|
||||
node->get("unique-id", &m_unique_id );
|
||||
@ -154,6 +165,23 @@ void PlayerProfile::addIcon()
|
||||
if (m_icon_filename.size() > 0 || isGuestAccount())
|
||||
return;
|
||||
|
||||
if (isSteamUser())
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << m_unique_id << ".png";
|
||||
std::string full_path = file_manager->getUserConfigFile(out.str());
|
||||
Steam::get()->saveAvatarAs(full_path);
|
||||
if (file_manager->fileExists(full_path))
|
||||
{
|
||||
m_icon_filename = out.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_icon_filename = "";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int n = (m_unique_id + kart_properties_manager->getKartId("tux") - 1)
|
||||
% kart_properties_manager->getNumberOfKarts();
|
||||
|
||||
@ -202,6 +230,7 @@ void PlayerProfile::save(UTFWriter &out)
|
||||
<< L"\" guest=\"" << m_is_guest_account
|
||||
<< L"\" use-frequency=\"" << m_use_frequency << L"\"\n";
|
||||
|
||||
out << L" steam-id=\"" << m_steam_id << L"\"\n";
|
||||
out << L" icon-filename=\"" << m_icon_filename << L"\"\n";
|
||||
|
||||
out << L" unique-id=\"" << m_unique_id
|
||||
|
@ -97,6 +97,11 @@ private:
|
||||
/** The token of the saved session. */
|
||||
std::string m_saved_token;
|
||||
|
||||
/** If the account is a steam account, this stores the steam user id.
|
||||
* Otherwise it is empty. A steam account can only be selected if
|
||||
* the user is logged into steam! */
|
||||
std::string m_steam_id;
|
||||
|
||||
/** The online user name used last (empty if not used online). */
|
||||
core::stringw m_last_online_name;
|
||||
|
||||
@ -300,6 +305,12 @@ public:
|
||||
/** Sets if this player was logged in last time it was used. */
|
||||
void setRememberPassword(bool b) { m_remember_password = b; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if this account is a steam account. */
|
||||
bool isSteamUser() const { return m_steam_id != ""; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the steam user id of this player ("" if not a steam account).*/
|
||||
const std::string &getSteamUserID() const { return m_steam_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
}; // class PlayerProfile
|
||||
|
||||
#endif
|
||||
|
@ -181,6 +181,7 @@ void STKConfig::init_defaults()
|
||||
m_disable_steer_while_unskid = false;
|
||||
m_camera_follow_skid = false;
|
||||
m_cutscene_fov = 0.61f;
|
||||
m_steam_ask_for_internet = false;
|
||||
|
||||
m_score_increase.clear();
|
||||
m_leader_intervals.clear();
|
||||
@ -274,6 +275,11 @@ void STKConfig::getAllData(const XMLNode * root)
|
||||
camera->get("cutscene-fov", &m_cutscene_fov);
|
||||
}
|
||||
|
||||
if (const XMLNode *steam = root->getNode("steam"))
|
||||
{
|
||||
steam->get("ask-for-internet", &m_steam_ask_for_internet);
|
||||
}
|
||||
|
||||
if (const XMLNode *music_node = root->getNode("music"))
|
||||
{
|
||||
std::string title_music;
|
||||
|
@ -152,6 +152,10 @@ public:
|
||||
|
||||
float m_cutscene_fov;
|
||||
|
||||
/** True if the internet question should still be asked when
|
||||
* a steam connection is make. */
|
||||
bool m_steam_ask_for_internet;
|
||||
|
||||
/** Lists of TTF files used in STK. */
|
||||
std::vector<std::string> m_normal_ttf;
|
||||
std::vector<std::string> m_digit_ttf;
|
||||
|
28
src/main.cpp
28
src/main.cpp
@ -1459,6 +1459,16 @@ void askForInternetPermission()
|
||||
Online::RequestManager::IPERM_NOT_ASKED)
|
||||
return;
|
||||
|
||||
// If a steam connection is available, we could skip the
|
||||
// internet permission question (depending on settings).
|
||||
if (Steam::get()->isSteamAvailable() &&
|
||||
!stk_config->m_steam_ask_for_internet)
|
||||
{
|
||||
UserConfigParams::m_internet_status =
|
||||
Online::RequestManager::IPERM_ALLOWED;
|
||||
return;
|
||||
}
|
||||
|
||||
class ConfirmServer :
|
||||
public MessageDialog::IConfirmDialogListener
|
||||
{
|
||||
@ -1517,11 +1527,6 @@ int main(int argc, char *argv[] )
|
||||
CommandLine::init(argc, argv);
|
||||
|
||||
Steam::create();
|
||||
bool steam_avail = Steam::get()->isSteamAvailable();
|
||||
std::string id = Steam::get()->getSteamID();
|
||||
std::string name = Steam::get()->getUserName();
|
||||
int n = Steam::get()->saveAvatarAs("test.png");
|
||||
Steam::destroy();
|
||||
|
||||
CrashReporting::installHandlers();
|
||||
|
||||
@ -1702,6 +1707,15 @@ int main(int argc, char *argv[] )
|
||||
MainMenuScreen::getInstance()->push();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Steam::get()->isSteamAvailable())
|
||||
{
|
||||
PlayerProfile *steam_player = PlayerManager::get()
|
||||
->addNewPlayer(Steam::get()->getUserNameWchar());
|
||||
PlayerManager::get()->setCurrentPlayer(steam_player);
|
||||
MainMenuScreen::getInstance()->push();
|
||||
}
|
||||
else
|
||||
{
|
||||
UserScreen::getInstance()->push();
|
||||
// If there is no player, push the RegisterScreen on top of
|
||||
@ -1712,7 +1726,8 @@ int main(int argc, char *argv[] )
|
||||
RegisterScreen::getInstance()->push();
|
||||
RegisterScreen::getInstance()->setParent(UserScreen::getInstance());
|
||||
}
|
||||
}
|
||||
} // !steam->isAvailable
|
||||
} // no player available
|
||||
#ifdef ENABLE_WIIUSE
|
||||
// Show a dialog to allow connection of wiimotes. */
|
||||
if(WiimoteManager::isEnabled())
|
||||
@ -1800,6 +1815,7 @@ int main(int argc, char *argv[] )
|
||||
if(NetworkConfig::get()->isNetworking() && STKHost::existHost())
|
||||
STKHost::get()->abort();
|
||||
|
||||
Steam::destroy();
|
||||
cleanSuperTuxKart();
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -91,6 +91,8 @@ Steam::Steam()
|
||||
return;
|
||||
}
|
||||
|
||||
m_user_name_wchar = StringUtils::utf8ToWide(m_user_name);
|
||||
|
||||
s = sendCommand("id");
|
||||
m_steam_id = decodeString(s);
|
||||
if (m_steam_id== "")
|
||||
|
@ -18,6 +18,8 @@
|
||||
#ifndef HEADER_STEAM_HPP
|
||||
#define HEADER_STEAM_HPP
|
||||
|
||||
#include "irrString.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# include <windows.h>
|
||||
#endif
|
||||
@ -44,6 +46,9 @@ private:
|
||||
/** Steam user name. Only defined if m_steam_available. */
|
||||
std::string m_user_name;
|
||||
|
||||
/** User name as irr::stringw (wchar), which is used in STK. */
|
||||
irr::core::stringw m_user_name_wchar;
|
||||
|
||||
/** Unique steam id. */
|
||||
std::string m_steam_id;
|
||||
|
||||
@ -97,6 +102,13 @@ public:
|
||||
int saveAvatarAs(const std::string &filename);
|
||||
std::vector<std::string> getFriends();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the user name as wide string. */
|
||||
const irr::core::stringw& getUserNameWchar()
|
||||
{
|
||||
assert(m_steam_available);
|
||||
return m_user_name_wchar;
|
||||
} // getUserNameWchar
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the connection to the Steam API was successful, i.e.
|
||||
* connection to steam worked, and SteamWorks API could be initialised. */
|
||||
bool isSteamAvailable() const { return m_steam_available; }
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "online/steam.hpp"
|
||||
#include "online/xml_request.hpp"
|
||||
#include "states_screens/dialogs/registration_dialog.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
@ -88,7 +89,9 @@ void RegisterScreen::init()
|
||||
}
|
||||
else if (PlayerManager::get()->getNumPlayers() == 0)
|
||||
{
|
||||
if (getenv("USERNAME") != NULL) // for windows
|
||||
if (Steam::get()->isSteamAvailable())
|
||||
username = StringUtils::utf8ToWide( Steam::get()->getUserName());
|
||||
else if (getenv("USERNAME") != NULL) // for windows
|
||||
username = getenv("USERNAME");
|
||||
else if (getenv("USER") != NULL) // Linux, Macs
|
||||
username = getenv("USER");
|
||||
|
Loading…
Reference in New Issue
Block a user