1
0
forked from 0ad/0ad

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:
leper 2012-12-25 22:49:18 +00:00
parent b1a606eb08
commit adc4012944
6 changed files with 46 additions and 40 deletions

View File

@ -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");
}

View File

@ -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();
if (name.empty())
name = L"anonymous";
CStr playername;
CFG_GET_USER_VAL("playername", String, playername);
std::wstring name = playername.FromUTF8();
if (!name.empty())
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");

View File

@ -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]);
}
@ -300,10 +300,11 @@ CConfigValue *CConfigDB::CreateValue(EConfigNamespace ns, const CStr& name)
return NULL;
}
CConfigValue *ret=GetValue(ns, name);
if (ret) return ret;
TConfigMap::iterator it = m_Map[ns].find(name);
if (it != m_Map[ns].end())
return &(it->second[0]);
TConfigMap::iterator it=m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet( 1 )));
it=m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet(1)));
return &(it->second[0]);
}

View File

@ -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.

View File

@ -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);

View File

@ -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;