Fix filename collision of string cache between shards on the same host

ryzomclassic-develop
kaetemi 5 years ago committed by Jan Boon
parent 6c6a83bc5d
commit c7b27c8d70

@ -643,7 +643,7 @@ TInterfaceState autoLogin (const string &cookie, const string &fsaddr, bool firs
NetMngr.setDataBase (IngameDbMngr.getNodePtr());
// init the string manager cache.
STRING_MANAGER::CStringManagerClient::instance()->initCache(UsedFSAddr, ClientCfg.LanguageCode);
STRING_MANAGER::CStringManagerClient::instance()->initCache(ClientCfg.LanguageCode);
}
}
else

@ -1149,6 +1149,9 @@ void CFarTP::disconnectFromPreviousShard()
}
else
{
// flush the server string cache
STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
// String manager: remove all waiting callbacks and removers
// (if some interface stuff has not received its string yet, its remover will get useless)
STRING_MANAGER::CStringManagerClient::release( false );
@ -1204,7 +1207,7 @@ void CFarTP::connectToNewShard()
}
// Reinit the string manager cache.
STRING_MANAGER::CStringManagerClient::instance()->initCache(FSAddr, ClientCfg.LanguageCode);
STRING_MANAGER::CStringManagerClient::instance()->initCache(ClientCfg.LanguageCode);
// reset the chat mode
ChatMngr.resetChatMode();

@ -2317,8 +2317,9 @@ void impulseReloadCache(NLMISC::CBitMemStream &impulse)
{
uint32 timestamp;;
impulse.serial(timestamp);
nlwarning("TODO_SHARD_ID %u", (unsigned int)timestamp);
if (PermanentlyBanned) return;
STRING_MANAGER::CStringManagerClient::instance()->loadCache(timestamp);
STRING_MANAGER::CStringManagerClient::instance()->loadCache(timestamp, 1999); // TODO_SHARD_ID
}
//-----------------------------------------------

@ -243,8 +243,8 @@ void releaseMainLoopReselect()
// Pause any user played music
MusicPlayer.pause();
// only really needed at exit
// --STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
// flush the server string cache
STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
// Remove all entities.
if (Driver)

@ -99,22 +99,28 @@ namespace STRING_MANAGER
}
}
void CStringManagerClient::initCache(const std::string &shardId, const std::string &languageCode)
void CStringManagerClient::initCache(const std::string &languageCode)
{
H_AUTO( CStringManagerClient_initCache )
H_AUTO( CStringManagerClient_initLanguage )
_ShardId = shardId;
_LanguageCode = languageCode;
m_LanguageCode = languageCode;
// to be inited, shard id and language code must be filled
if (!_ShardId.empty() && !_LanguageCode.empty())
_CacheInited = true;
else
_CacheInited = false;
// clear all current data.
_ReceivedStrings.clear();
_ReceivedDynStrings.clear();
_CacheStringToSave.clear();
// NB : we keep the waiting strings and dyn strings
// insert the empty string.
_ReceivedStrings.insert(make_pair((uint)EmptyStringId, ucstring()));
// to be inited, language code must be filled
_CacheInited = !m_LanguageCode.empty();
_CacheLoaded = false;
_CacheFilename.clear();
}
void CStringManagerClient::loadCache(uint32 timestamp)
void CStringManagerClient::loadCache(uint32 timestamp, uint32 shardId)
{
H_AUTO( CStringManagerClient_loadCache )
@ -122,7 +128,8 @@ namespace STRING_MANAGER
{
try
{
_CacheFilename = std::string("save/") + _ShardId.substr(0, _ShardId.find(":")) + ".string_cache";
std::string clientApp = ClientCfg.ConfigFile.getVar("Application").asString(0);
_CacheFilename = std::string("save/") + clientApp + "_" + toString(shardId) + "_" + m_LanguageCode + ".string_cache";
nlinfo("SM : Try to open the string cache : %s", _CacheFilename.c_str());
@ -157,6 +164,7 @@ namespace STRING_MANAGER
// clear all current data.
_ReceivedStrings.clear();
_ReceivedDynStrings.clear();
_CacheStringToSave.clear();
// NB : we keep the waiting strings and dyn strings
// insert the empty string.
@ -528,7 +536,7 @@ restartLoop:
void CStringManagerClient::flushStringCache()
{
if(!_CacheStringToSave.empty())
if (!_CacheStringToSave.empty() && !_CacheFilename.empty())
{
NLMISC::COFile file(_CacheFilename, true);
for(uint i=0;i<_CacheStringToSave.size();i++)

@ -48,14 +48,14 @@ public:
/** Prepare the string manager to use a persistent string cache.
* There is one cache file for each language and for each encountered shard.
*/
void initCache(const std::string &shardId, const std::string &languageCode);
void initCache(const std::string &languageCode);
/** Clear the current string table and load the content of the cache file.
* This method is called after receiving the impulse RELOAD_CACHE from
* IOS.
* If the received timestamp and the file timestamp differ, the file cache
* is reseted.
*/
void loadCache(uint32 timestamp);
void loadCache(uint32 timestamp, uint32 shardId);
bool isCacheLoaded() {return _CacheLoaded;};
// Force the cache to be saved
void flushStringCache();
@ -228,10 +228,8 @@ private:
//\name Cache management
/// Flag for cache management initialisation done.
bool _CacheInited;
/// Shard id is used to identify the cache file to use.
std::string _ShardId;
/// Language code is used to identify the cache file to use.
std::string _LanguageCode;
std::string m_LanguageCode;
/// Timestamp (unix date) of the corrently loaded cache file.
uint32 _Timestamp;
/// Fullpath name of the current cache file.

@ -1021,6 +1021,9 @@ void CStringManager::updateUserLanguage( uint32 userId, TServiceId frontEndId, c
GenericXmlMsgHeaderMngr.pushNameToStream( "STRING_MANAGER:RELOAD_CACHE", bmsOut);
bmsOut.serial(timestamp);
uint32 shardId = IService::getInstance()->getShardId();
bmsOut.serial(shardId);
// send the message to Front End
NLNET::CMessage msgout( "IMPULSION_UID" );
msgout.serial(userId);

Loading…
Cancel
Save