Save last multiplayer server. Based on patch by Aurium. Fixes #1778.
Fix bug in ConfigDB: Creating a value could result in changing a value in a different namespace. This was SVN commit r13021.
This commit is contained in:
parent
b1a606eb08
commit
adc4012944
@ -19,7 +19,7 @@
|
||||
Multiplayer
|
||||
</object>
|
||||
|
||||
<object name="pageJoin" size="0 32 100% 100%" hidden="true">
|
||||
<object name="pageJoin" size="0 32 100% 100%" hidden="true">
|
||||
|
||||
<object type="text" style="CenteredLabelText" size="0 0 400 30">
|
||||
Joining an existing game.
|
||||
@ -39,7 +39,7 @@
|
||||
Server Hostname or IP:
|
||||
</object>
|
||||
|
||||
<object name="joinIP" type="input" size="210 80 100%-32 104" style="StoneInput">
|
||||
<object name="joinServer" type="input" size="210 80 100%-32 104" style="StoneInput">
|
||||
<action on="Load"><![CDATA[
|
||||
this.caption = Engine.GetDefaultMPServer();
|
||||
]]></action>
|
||||
@ -48,9 +48,10 @@
|
||||
<object type="button" size="50%-144 100%-60 50%-16 100%-32" style="StoneButton">
|
||||
Continue
|
||||
<action on="Press"><![CDATA[
|
||||
if (startJoin(
|
||||
getGUIObjectByName("joinPlayerName").caption,
|
||||
getGUIObjectByName("joinIP").caption))
|
||||
var joinPlayerName = getGUIObjectByName("joinPlayerName").caption;
|
||||
var joinServer = getGUIObjectByName("joinServer").caption;
|
||||
Engine.SaveMPConfig(joinPlayerName, joinServer);
|
||||
if (startJoin(joinPlayerName, joinServer))
|
||||
{
|
||||
switchSetupPage("pageJoin", "pageConnecting");
|
||||
}
|
||||
|
@ -170,19 +170,31 @@ int GetPlayerID(void* UNUSED(cbdata))
|
||||
|
||||
std::wstring GetDefaultPlayerName(void* UNUSED(cbdata))
|
||||
{
|
||||
std::wstring name = g_PlayerName.FromUTF8();
|
||||
if (name.empty())
|
||||
name = sys_get_user_name();
|
||||
CStr playername;
|
||||
CFG_GET_USER_VAL("playername", String, playername);
|
||||
std::wstring name = playername.FromUTF8();
|
||||
if (!name.empty())
|
||||
return name;
|
||||
|
||||
if (name.empty())
|
||||
name = L"anonymous";
|
||||
return name;
|
||||
name = sys_get_user_name();
|
||||
if (!name.empty())
|
||||
return name;
|
||||
|
||||
return L"anonymous";
|
||||
}
|
||||
|
||||
std::wstring GetDefaultMPServer(void* UNUSED(cbdata))
|
||||
{
|
||||
std::wstring server = g_MPServer.FromUTF8();
|
||||
return server;
|
||||
CStr server;
|
||||
CFG_GET_USER_VAL("multiplayerserver", String, server);
|
||||
return server.FromUTF8();
|
||||
}
|
||||
|
||||
void SaveMPConfig(void* UNUSED(cbdata), std::wstring playerName, std::wstring server)
|
||||
{
|
||||
g_ConfigDB.CreateValue(CFG_USER, "playername")->m_String = CStrW(playerName).ToUTF8();
|
||||
g_ConfigDB.CreateValue(CFG_USER, "multiplayerserver")->m_String = CStrW(server).ToUTF8();
|
||||
g_ConfigDB.WriteFile(CFG_USER);
|
||||
}
|
||||
|
||||
void StartNetworkGame(void* UNUSED(cbdata))
|
||||
@ -641,6 +653,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
|
||||
scriptInterface.RegisterFunction<int, &GetPlayerID>("GetPlayerID");
|
||||
scriptInterface.RegisterFunction<std::wstring, &GetDefaultPlayerName>("GetDefaultPlayerName");
|
||||
scriptInterface.RegisterFunction<std::wstring, &GetDefaultMPServer>("GetDefaultMPServer");
|
||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &SaveMPConfig>("SaveMPConfig");
|
||||
scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
|
||||
scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
|
||||
scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -220,7 +220,7 @@ CConfigValue *CConfigDB::GetValue(EConfigNamespace ns, const CStr& name)
|
||||
{
|
||||
CConfigValueSet* values = GetValues(ns, name);
|
||||
if (!values)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
return &((*values)[0]);
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ CConfigValueSet *CConfigDB::GetValues(EConfigNamespace ns, const CStr& name)
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
EConfigNamespace CConfigDB::GetValueNamespace(EConfigNamespace ns, const CStr& name)
|
||||
{
|
||||
@ -299,11 +299,12 @@ CConfigValue *CConfigDB::CreateValue(EConfigNamespace ns, const CStr& name)
|
||||
debug_warn(L"CConfigDB: Invalid ns value");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CConfigValue *ret=GetValue(ns, name);
|
||||
if (ret) return ret;
|
||||
|
||||
TConfigMap::iterator it=m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet( 1 )));
|
||||
|
||||
TConfigMap::iterator it = m_Map[ns].find(name);
|
||||
if (it != m_Map[ns].end())
|
||||
return &(it->second[0]);
|
||||
|
||||
it=m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet(1)));
|
||||
return &(it->second[0]);
|
||||
}
|
||||
|
||||
@ -314,7 +315,7 @@ void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path)
|
||||
debug_warn(L"CConfigDB: Invalid ns value");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_ConfigFile[ns]=path;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -85,17 +85,19 @@ public:
|
||||
CConfigDB();
|
||||
|
||||
/**
|
||||
* Attempt to find a config variable with the given name; will search all
|
||||
* namespaces from system up to the specified namespace.
|
||||
* Attempt to find a config variable with the given name; will search
|
||||
* CFG_COMMAND first, and then all namespaces from the specified namespace
|
||||
* down to system.
|
||||
*
|
||||
* Returns a pointer to the config value structure for the variable, or
|
||||
* NULL if such a variable could not be found
|
||||
* NULL if such a variable could not be found.
|
||||
*/
|
||||
CConfigValue *GetValue(EConfigNamespace ns, const CStr& name);
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to retrieve a vector of values corresponding to the given setting;
|
||||
* will search all namespaces from system up to the specified namespace.
|
||||
* will search CFG_COMMAND first, and then all namespaces from the specified
|
||||
* namespace down to system.
|
||||
*
|
||||
* Returns a pointer to the vector, or NULL if the setting could not be found.
|
||||
*/
|
||||
@ -116,8 +118,7 @@ public:
|
||||
|
||||
/**
|
||||
* Create a new config value in the specified namespace. If such a
|
||||
* variable already exists, the old value is returned and the effect is
|
||||
* exactly the same as that of GetValue()
|
||||
* variable already exists in this namespace, the old value is returned.
|
||||
*
|
||||
* Returns a pointer to the value of the newly created config variable, or
|
||||
* that of the already existing config variable.
|
||||
|
@ -34,8 +34,6 @@ bool g_NoGLAutoMipmap = false;
|
||||
bool g_NoGLVBO = false;
|
||||
|
||||
bool g_PauseOnFocusLoss = false;
|
||||
CStr g_PlayerName = "";
|
||||
CStr g_MPServer = "";
|
||||
|
||||
bool g_Shadows = false;
|
||||
bool g_ShadowPCF = false;
|
||||
@ -86,8 +84,6 @@ static void LoadGlobals()
|
||||
CFG_GET_USER_VAL("noautomipmap", Bool, g_NoGLAutoMipmap);
|
||||
CFG_GET_USER_VAL("novbo", Bool, g_NoGLVBO);
|
||||
CFG_GET_USER_VAL("pauseonfocusloss", Bool, g_PauseOnFocusLoss);
|
||||
CFG_GET_USER_VAL("playername", String, g_PlayerName);
|
||||
CFG_GET_USER_VAL("multiplayerserver", String, g_MPServer);
|
||||
CFG_GET_USER_VAL("shadows", Bool, g_Shadows);
|
||||
CFG_GET_USER_VAL("shadowpcf", Bool, g_ShadowPCF);
|
||||
|
||||
|
@ -44,12 +44,6 @@ extern bool g_NoGLVBO;
|
||||
// flag to pause the game on window focus loss
|
||||
extern bool g_PauseOnFocusLoss;
|
||||
|
||||
// default player name to use in multiplayer
|
||||
extern CStr g_PlayerName;
|
||||
|
||||
// default server name or IP to use in multiplayer
|
||||
extern CStr g_MPServer;
|
||||
|
||||
// flag to switch on shadows
|
||||
extern bool g_Shadows;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user