Merge with develop

--HG--
branch : compatibility-develop
This commit is contained in:
Nimetu 2017-04-16 22:45:39 +03:00
commit 8f5588e0ec
9 changed files with 331 additions and 88 deletions

View file

@ -820,7 +820,8 @@ namespace NLGUI
struct CDataDownload struct CDataDownload
{ {
public: public:
CDataDownload(CURL *c, const std::string &u, const std::string &d, FILE *f, TDataType t, CViewBase *i, const std::string &s, const std::string &m, const CStyleParams &style = CStyleParams()) : curl(c), url(u), dest(d), luaScript(s), md5sum(m), type(t), fp(f) CDataDownload(const std::string &u, const std::string &d, TDataType t, CViewBase *i, const std::string &s, const std::string &m, const CStyleParams &style = CStyleParams())
: curl(NULL), fp(NULL), url(u), dest(d), type(t), luaScript(s), md5sum(m)
{ {
if (t == ImgType) imgs.push_back(CDataImageDownload(i, style)); if (t == ImgType) imgs.push_back(CDataImageDownload(i, style));
} }
@ -840,6 +841,8 @@ namespace NLGUI
CURLM *MultiCurl; CURLM *MultiCurl;
int RunningCurls; int RunningCurls;
bool startCurlDownload(CDataDownload &download);
void initImageDownload(); void initImageDownload();
void checkImageDownload(); void checkImageDownload();
void addImageDownload(const std::string &url, CViewBase *img, const CStyleParams &style = CStyleParams()); void addImageDownload(const std::string &url, CViewBase *img, const CStyleParams &style = CStyleParams());

View file

@ -265,6 +265,61 @@ namespace NLGUI
return dest; return dest;
} }
// Add url to MultiCurl queue and return cURL handle
bool CGroupHTML::startCurlDownload(CDataDownload &download)
{
if (!MultiCurl)
{
nlwarning("Invalid MultiCurl handle, unable to download '%s'", download.url.c_str());
return false;
}
string tmpdest = download.dest + ".tmp";
// erase the tmp file if exists
if (CFile::fileExists(tmpdest))
CFile::deleteFile(tmpdest);
FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL)
{
nlwarning("Can't open file '%s' for writing: code=%d '%s'", tmpdest.c_str (), errno, strerror(errno));
return false;
}
CURL *curl = curl_easy_init();
if (!curl)
{
fclose(fp);
CFile::deleteFile(tmpdest);
nlwarning("Creating cURL handle failed, unable to download '%s'", download.url.c_str());
return false;
}
download.curl = curl;
download.fp = fp;
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true);
curl_easy_setopt(curl, CURLOPT_URL, download.url.c_str());
// limit curl to HTTP and HTTPS protocols only
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
std::string userAgent = options.appName + "/" + options.appVersion;
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
sendCookies(curl, _DocumentDomain, _TrustedDomain);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_multi_add_handle(MultiCurl, curl);
return true;
}
// Add a image download request in the multi_curl // Add a image download request in the multi_curl
void CGroupHTML::addImageDownload(const string &url, CViewBase *img, const CStyleParams &style) void CGroupHTML::addImageDownload(const string &url, CViewBase *img, const CStyleParams &style)
{ {
@ -285,55 +340,29 @@ namespace NLGUI
// use requested url for local name // use requested url for local name
string dest = localImageName(url); string dest = localImageName(url);
string tmpdest = localImageName(url)+".tmp";
#ifdef LOG_DL #ifdef LOG_DL
nlwarning("add to download '%s' dest '%s' img %p", finalUrl.c_str(), dest.c_str(), img); nlwarning("add to download '%s' dest '%s' img %p", finalUrl.c_str(), dest.c_str(), img);
#endif #endif
// erase the tmp file if exists
if (NLMISC::CFile::fileExists(tmpdest))
NLMISC::CFile::deleteFile(tmpdest);
if (!NLMISC::CFile::fileExists(dest)) if (!NLMISC::CFile::fileExists(dest))
{ {
if (!MultiCurl) Curls.push_back(CDataDownload(finalUrl, dest, ImgType, img, "", "", style));
if (Curls.size() < options.curlMaxConnections) {
if (!startCurlDownload(Curls.back()))
{ {
nlwarning("Invalid MultiCurl handle, unable to download '%s'", finalUrl.c_str()); Curls.pop_back();
return; return;
} }
CURL *curl = curl_easy_init();
if (!curl)
{
nlwarning("Creating cURL handle failed, unable to download '%s'", finalUrl.c_str());
return;
}
FILE *fp = nlfopen(tmpdest, "wb");
if (fp == NULL)
{
curl_easy_cleanup(curl);
nlwarning("Can't open file '%s' for writing: code=%d '%s'", tmpdest.c_str (), errno, strerror(errno));
return;
}
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true);
curl_easy_setopt(curl, CURLOPT_URL, finalUrl.c_str());
std::string userAgent = options.appName + "/" + options.appVersion;
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
sendCookies(curl, _DocumentDomain, _TrustedDomain);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_multi_add_handle(MultiCurl, curl);
Curls.push_back(CDataDownload(curl, finalUrl, dest, fp, ImgType, img, "", "", style));
#ifdef LOG_DL
nlwarning("adding handle %x, %d curls", curl, Curls.size());
#endif
RunningCurls++; RunningCurls++;
#ifdef LOG_DL
nlwarning("(%s) adding handle %x, %d curls", _Id.c_str(), Curls.back().curl, Curls.size());
}
else
{
nlwarning("(%s) download queued, %d curls", _Id.c_str(), Curls.size());
#endif
}
} }
else else
{ {
@ -378,15 +407,10 @@ namespace NLGUI
} }
string dest = localBnpName(url); string dest = localBnpName(url);
string tmpdest = localBnpName(url)+".tmp";
#ifdef LOG_DL #ifdef LOG_DL
nlwarning("add to download '%s' dest '%s'", url.c_str(), dest.c_str()); nlwarning("add to download '%s' dest '%s'", url.c_str(), dest.c_str());
#endif #endif
// erase the tmp file if exists
if (NLMISC::CFile::fileExists(tmpdest))
NLMISC::CFile::deleteFile(tmpdest);
// create/delete the local file // create/delete the local file
if (NLMISC::CFile::fileExists(dest)) if (NLMISC::CFile::fileExists(dest))
{ {
@ -402,39 +426,23 @@ namespace NLGUI
} }
if (action != "delete") if (action != "delete")
{ {
if (!MultiCurl) Curls.push_back(CDataDownload(url, dest, BnpType, NULL, script, md5sum));
if (Curls.size() < options.curlMaxConnections)
{ {
nlwarning("Invalid MultiCurl handle, unable to download '%s'", url.c_str()); if (!startCurlDownload(Curls.back()))
{
Curls.pop_back();
return false; return false;
} }
CURL *curl = curl_easy_init();
if (!curl)
{
nlwarning("Creating cURL handle failed, unable to download '%s'", url.c_str());
return false;
}
FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL)
{
curl_easy_cleanup(curl);
nlwarning("Can't open file '%s' for writing: code=%d '%s'", tmpdest.c_str (), errno, strerror(errno));
return false;
}
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_multi_add_handle(MultiCurl, curl);
Curls.push_back(CDataDownload(curl, url, dest, fp, BnpType, NULL, script, md5sum));
#ifdef LOG_DL
nlwarning("adding handle %x, %d curls", curl, Curls.size());
#endif
RunningCurls++; RunningCurls++;
#ifdef LOG_DL
nlwarning("(%s) adding handle %x, %d curls", _Id.c_str(), Curls.back().curl, Curls.size());
}
else
{
nlwarning("(%s) download queued, %d curls", _Id.c_str(), Curls.size());
#endif
}
} }
else else
return true; return true;
@ -631,7 +639,30 @@ namespace NLGUI
} }
} }
} }
RunningCurls = NewRunningCurls; RunningCurls = NewRunningCurls;
if (RunningCurls < options.curlMaxConnections)
{
for (vector<CDataDownload>::iterator it=Curls.begin(); it<Curls.end(); it++)
{
if (it->curl == NULL) {
#ifdef LOG_DL
nlwarning("(%s) starting new download '%s'", _Id.c_str(), it->url.c_str());
#endif
if (!startCurlDownload(*it))
{
Curls.erase(it);
break;
}
RunningCurls++;
if (RunningCurls >= options.curlMaxConnections)
break;
}
}
}
#ifdef LOG_DL #ifdef LOG_DL
if (RunningCurls > 0 || !Curls.empty()) if (RunningCurls > 0 || !Curls.empty())
nlwarning("(%s) RunningCurls %d, _Curls %d", _Id.c_str(), RunningCurls, Curls.size()); nlwarning("(%s) RunningCurls %d, _Curls %d", _Id.c_str(), RunningCurls, Curls.size());
@ -4531,6 +4562,18 @@ namespace NLGUI
Curls[i].imgs.clear(); Curls[i].imgs.clear();
} }
// remove download that are still queued
for (vector<CDataDownload>::iterator it=Curls.begin(); it<Curls.end(); )
{
if (it->curl == NULL) {
#ifdef LOG_DL
nlwarning("Remove waiting curl download (%s)", it->url.c_str());
#endif
it = Curls.erase(it);
} else {
++it;
}
}
} }
// *************************************************************************** // ***************************************************************************
@ -4985,7 +5028,7 @@ namespace NLGUI
} }
#if LOG_DL #if LOG_DL
nlwarning("(%s) browse local file '%s'", filename.c_str()); nlwarning("browse local file '%s'", filename.c_str());
#endif #endif
_TrustedDomain = true; _TrustedDomain = true;

View file

@ -85,13 +85,16 @@ namespace WEEKDAY
void CRyzomTime::updateRyzomClock(uint32 gameCyle) void CRyzomTime::updateRyzomClock(uint32 gameCyle)
{ {
static const uint32 ticksPerDay = (RYZOM_DAY_IN_HOUR * RYZOM_HOURS_IN_TICKS);
static const float ticksPerHour = (float)RYZOM_HOURS_IN_TICKS; static const float ticksPerHour = (float)RYZOM_HOURS_IN_TICKS;
uint32 totalTicks = gameCyle + _TickOffset; uint32 totalTicks = gameCyle + _TickOffset;
uint32 days = totalTicks / ticksPerDay; uint32 days = totalTicks / RYZOM_DAY_IN_TICKS;
uint32 dayCycle = totalTicks - (days * ticksPerDay); uint32 dayCycle = totalTicks - (days * RYZOM_DAY_IN_TICKS);
// Avoid rollover for low amount of days
if(days >= RYZOM_START_SPRING)
days -= RYZOM_START_SPRING; days -= RYZOM_START_SPRING;
else
days = 0;
float hours = (float)dayCycle / ticksPerHour; float hours = (float)dayCycle / ticksPerHour;
_RyzomDay = days; _RyzomDay = days;

View file

@ -36,6 +36,7 @@
#include "game_share/multi_target.h" #include "game_share/multi_target.h"
#include "phrase_manager/s_effect.h" #include "phrase_manager/s_effect.h"
#include "projectile_stats.h" #include "projectile_stats.h"
#include "primitives_parser.h"
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
@ -297,7 +298,6 @@ bool CDeposit::build( const NLLIGO::CPrimZone* zone )
{ {
if ( IsRingShard ) if ( IsRingShard )
return false; return false;
//_Id =id; //_Id =id;
*( (NLLIGO::CPrimZone*)this ) = *zone; *( (NLLIGO::CPrimZone*)this ) = *zone;
@ -305,7 +305,11 @@ bool CDeposit::build( const NLLIGO::CPrimZone* zone )
string name; string name;
if ( ! zone->getPropertyByName( "name", name ) ) return malformed( "name", name ); if ( ! zone->getPropertyByName( "name", name ) ) return malformed( "name", name );
_Name = name; _Name = name;
// Read alias
if(!CPrimitivesParser::getAlias(zone, _Alias))
{
nlwarning("<CDeposit::build> Could not find an alias for deposit %s", _Name.c_str());
}
// Read exact raw material codes to add // Read exact raw material codes to add
vector<string> *exactRMCodesS = NULL; vector<string> *exactRMCodesS = NULL;
if ( ! (zone->getPropertyByName( "exact_mp_item", exactRMCodesS ) && exactRMCodesS) ) return malformed( "exact_mp_item", name ); if ( ! (zone->getPropertyByName( "exact_mp_item", exactRMCodesS ) && exactRMCodesS) ) return malformed( "exact_mp_item", name );
@ -469,6 +473,21 @@ bool CDeposit::build( const NLLIGO::CPrimZone* zone )
return true; return true;
} }
CDepositState CDeposit::currentState()
{
CDepositState out;
//If we don't have an alias, don't send any information (it's better to be missing information than having wrong information)
if(_Alias == 0)
return out;
// We should never save the state of a spot without quantity constraint, this is just an additional safeguard against it
if(!_QuantityConstraintsPt)
return out;
out.alias = _Alias;
out.currentQuantity = _QuantityConstraintsPt->getCurrentQuantity();
out.nextRespawnDay = _QuantityConstraintsPt->NextRespawnDay;
return out;
}
/* /*
* Select the raw materials, using the specified filters and _Ecotype * Select the raw materials, using the specified filters and _Ecotype

View file

@ -195,6 +195,29 @@ namespace NLMISC
class CWordsDictionary; class CWordsDictionary;
} }
struct CDepositState {
uint32 alias;
float currentQuantity;
uint32 nextRespawnDay;
CDepositState() : alias(0), currentQuantity(0.f), nextRespawnDay(0) {}
void serial(NLMISC::IStream &f) throw(NLMISC::EStream)
{
if(f.isXML())
{
f.xmlSerial(alias, "ALIAS");
f.xmlSerial(currentQuantity, "CURRENT_QUANTITY");
f.xmlSerial(nextRespawnDay, "NEXT_RESPAWN_DAY");
}
else
{
f.serial(alias);
f.serial(currentQuantity);
f.serial(nextRespawnDay);
}
}
};
/** /**
* \author Nicolas Brigand, Alain Saffray, Olivier Cado * \author Nicolas Brigand, Alain Saffray, Olivier Cado
* \author Nevrax France * \author Nevrax France
@ -205,7 +228,7 @@ class CDeposit : public NLLIGO::CPrimZone, public NLMISC::CRefCount
public: public:
/// Constructor /// Constructor
CDeposit() : _AutoSpawnSourcePt(NULL), _QuantityConstraintsPt(NULL), _Ecotype(ECOSYSTEM::common_ecosystem), _FilterPhase(0), _KamiAnger(0.0f), _MinQuality(-1), _MaxQuality(-1), _SourceFXIndex(0), _CanProspect(false), _Enabled(false), _CurrentNbAutoSpawnedSources(0), _AllowDepletionRisk(true) {} CDeposit() : _AutoSpawnSourcePt(NULL), _QuantityConstraintsPt(NULL), _Ecotype(ECOSYSTEM::common_ecosystem), _FilterPhase(0), _KamiAnger(0.0f), _MinQuality(-1), _MaxQuality(-1), _SourceFXIndex(0), _CanProspect(false), _Enabled(false), _CurrentNbAutoSpawnedSources(0), _AllowDepletionRisk(true), _Alias(0) {}
/// Destructor /// Destructor
~CDeposit(); ~CDeposit();
@ -346,6 +369,13 @@ public:
// For auto-spawn source minimum number. Internaly used by CHarvestSource only // For auto-spawn source minimum number. Internaly used by CHarvestSource only
void decreaseAutoSpawnedSources(); void decreaseAutoSpawnedSources();
void increaseAutoSpawnedSources(); void increaseAutoSpawnedSources();
/// Used to save the deposit
bool needSave() const { return _QuantityConstraintsPt && (_QuantityConstraintsPt->CurrentQuantity != _QuantityConstraintsPt->InitialQuantity || _QuantityConstraintsPt->NextRespawnDay != 0); }
CDepositState currentState();
uint32 getAlias() const { return _Alias;}
void setCurrentQuantity(uint32 currentQuantity) { _QuantityConstraintsPt->CurrentQuantity = currentQuantity; }
void setNextRespawnDay(uint32 nextRespawnDay) { _QuantityConstraintsPt->NextRespawnDay = nextRespawnDay; }
protected: protected:
@ -429,6 +459,9 @@ private:
/// Current Number of AutoSpawned Sources in this deposit /// Current Number of AutoSpawned Sources in this deposit
uint32 _CurrentNbAutoSpawnedSources; uint32 _CurrentNbAutoSpawnedSources;
/// CPrimAlias, needed to identify a deposit to restore its state between shutdown of the EGS
uint32 _Alias;
}; };

View file

@ -329,6 +329,10 @@ CVariable<float> DodgeFactorForForageSkills("egs","DodgeFactorForForageSkills"
CVariable<float> ForageExtractionTimeMinGC( "egs", "ForageExtractionTimeMinGC", "Minimum time of extraction in ticks", 230.0f, 0, true ); CVariable<float> ForageExtractionTimeMinGC( "egs", "ForageExtractionTimeMinGC", "Minimum time of extraction in ticks", 230.0f, 0, true );
CVariable<float> ForageExtractionTimeSlopeGC( "egs", "ForageExtractionTimeSlopeGC", "Slope of base extraction time curve", 2.0f, 0, true ); CVariable<float> ForageExtractionTimeSlopeGC( "egs", "ForageExtractionTimeSlopeGC", "Slope of base extraction time curve", 2.0f, 0, true );
CVariable<bool> RefillDepositOnStartup("egs", "RefillDepositOnStartup", "Ignore saved CurrentQuantity / NextRespawnDay in deposits", false, 0, true);
CVariable<uint32> DepositSaveInterval("egs", "DepositSaveInterval", "time *in tick* between two saves of a deposit", 10 * 60 * 10, 0, true);
CVariable<bool> DepositStateUseXml("egs", "DepositStateUseXml", "Use xml instead of binary file to save deposit state", true, 0, true);
CVariable<float> ForageQuantityBaseRate( "egs", "ForageQuantityBaseRate", "Base of extraction rate", 0.23f, 0, true ); // 0.23 doubles the previous minimum setting CVariable<float> ForageQuantityBaseRate( "egs", "ForageQuantityBaseRate", "Base of extraction rate", 0.23f, 0, true ); // 0.23 doubles the previous minimum setting

View file

@ -280,6 +280,9 @@ extern NLMISC::CVariable<float> ForageQuantityXPDeltaLevelBonusRate;
extern NLMISC::CVariable<float> ForageExtractionTimeMinGC; extern NLMISC::CVariable<float> ForageExtractionTimeMinGC;
extern NLMISC::CVariable<float> ForageExtractionTimeSlopeGC; extern NLMISC::CVariable<float> ForageExtractionTimeSlopeGC;
extern NLMISC::CVariable<bool> RefillDepositOnStartup;
extern NLMISC::CVariable<uint32> DepositSaveInterval;
extern NLMISC::CVariable<bool> DepositStateUseXml;
// QUARTERING // QUARTERING
extern NLMISC::CVariable<float> QuarteringQuantityAverageForCraftHerbivore; extern NLMISC::CVariable<float> QuarteringQuantityAverageForCraftHerbivore;

View file

@ -530,6 +530,7 @@ void CZoneManager::release()
void CZoneManager::initInstance() void CZoneManager::initInstance()
{ {
_NextDepositIndexUpdated = 0; _NextDepositIndexUpdated = 0;
_NextDepositSave = CTickEventHandler::getGameCycle() + DepositSaveInterval;
_SpreadUpdateLoopBeginTick = CTickEventHandler::getGameCycle(); _SpreadUpdateLoopBeginTick = CTickEventHandler::getGameCycle();
// get the loaded primitives // get the loaded primitives
@ -589,6 +590,8 @@ void CZoneManager::initInstance()
nlwarning("<CZoneManager constructor> Error while building the zones"); nlwarning("<CZoneManager constructor> Error while building the zones");
} }
} }
// Ask Bsi for saved deposit states
Bsi.requestFile(DepositStateFileName, new CDepositCallback());
// Don't keep ecotypes in memory, the information is already in the deposits // Don't keep ecotypes in memory, the information is already in the deposits
CDeposit::clearEcotypes(); CDeposit::clearEcotypes();
@ -1417,6 +1420,59 @@ bool CZoneManager::parsePVPSafeZones( const NLLIGO::IPrimitive * prim )
return result; return result;
} // CZoneManager parsePVPSafeZones } // CZoneManager parsePVPSafeZones
//-----------------------------------------------
// CZoneManager receivedDepositState
//-----------------------------------------------
void CZoneManager::receivedDepositState(const CFileDescription& fileDescription, NLMISC::IStream& dataStream)
{
if(fileDescription.FileName.empty())
{
nlwarning("Got no deposit state file from backup service, probably because no deposit need to be saved");
return;
}
NLMISC::CMemStream& memStream = dynamic_cast<NLMISC::CMemStream&>(dataStream);
if (&memStream != NULL)
{
try
{
std::vector<CDepositState> states;
if(DepositStateUseXml)
{
CIXml xml;
xml.init(memStream);
xml.serialCont(states);
}
else
{
memStream.serialCont(states);
}
nldebug("Got %d CDepositState from backup service", states.size());
//If we don't want to use state, stop here
if(RefillDepositOnStartup) return;
for(int i=0; i < states.size(); i++)
{
//Find the matching deposit
for(int j = 0 ; j < _Deposits.size(); j++)
{
CDeposit* dep = _Deposits[j];
if(dep->getAlias() == states[i].alias)
{
dep->setCurrentQuantity(states[i].currentQuantity);
dep->setNextRespawnDay(states[i].nextRespawnDay);
}
}
nldebug("CDepositState for alias %d : currentQuantity=%f, nextRespawn=%d", states[i].alias, states[i].currentQuantity, states[i].nextRespawnDay);
}
}
catch (const Exception& e)
{
nlwarning("Could not parse deposit state file, reason : %s", e.what());
}
}
}// CZoneManager receivedDepositState
//----------------------------------------------- //-----------------------------------------------
// CZoneManager getContinent // CZoneManager getContinent
//----------------------------------------------- //-----------------------------------------------
@ -2021,9 +2077,63 @@ void CZoneManager::tickUpdate()
_DepositNeedingAutoSpawnUpdate.erase(itDeposit); _DepositNeedingAutoSpawnUpdate.erase(itDeposit);
itDeposit= itNext; itDeposit= itNext;
} }
// Save the deposits
if(_NextDepositSave < CTickEventHandler::getGameCycle())
{
_NextDepositSave = CTickEventHandler::getGameCycle() + DepositSaveInterval;
saveDeposits();
}
}// CZoneManager tickUpdate }// CZoneManager tickUpdate
//-----------------------------------------------
// CZoneManager saveDeposits
//-----------------------------------------------
void CZoneManager::saveDeposits()
{
std::vector<CDepositState> toSave;
for(int i=0; i < _Deposits.size(); i++)
{
if (!_Deposits[i]->needSave()) continue;
CDepositState tmp = _Deposits[i]->currentState();
//Don't save if for some reason we couldn't get an alias for the deposit
if(tmp.alias == 0) continue;
toSave.push_back(tmp);
}
// No need to save if we have 0 states
if(toSave.size() == 0) return;
CMemStream stream;
try
{
if(DepositStateUseXml)
{
COXml output;
if (!output.init(&stream))
{
nlwarning("<CZoneManager::saveDeposits> cannot init XML output for file %s", DepositStateFileName.c_str());
return;
}
output.serialCont(toSave);
output.flush();
}
else
{
stream.serialCont(toSave);
}
}
catch (const Exception & e)
{
nlwarning("<CZoneManager::saveDeposits> cannot save file %s : %s", DepositStateFileName.c_str(), e.what());
}
nldebug("<CZoneManager::saveDeposits>: sending %d states to BIS (total of %d deposits available).", toSave.size(), _Deposits.size());
CBackupMsgSaveFile msg( DepositStateFileName, CBackupMsgSaveFile::SaveFile, Bsi );
msg.DataMsg.serialBuffer((uint8*)stream.buffer(), stream.length());
Bsi.sendFile( msg );
}// CZoneManager saveDeposits
//----------------------------------------------- //-----------------------------------------------
// CZoneManager dumpWorld // CZoneManager dumpWorld
//----------------------------------------------- //-----------------------------------------------

View file

@ -31,6 +31,7 @@
#include "game_share/string_manager_sender.h" #include "game_share/string_manager_sender.h"
#include "mission_manager/ai_alias_translator.h" #include "mission_manager/ai_alias_translator.h"
#include "deposit.h" #include "deposit.h"
#include "game_share/backup_service_interface.h"
class CCharacter; class CCharacter;
extern NLMISC::CRandom RandomGenerator; extern NLMISC::CRandom RandomGenerator;
@ -39,6 +40,7 @@ static const uint16 InvalidSpawnZoneId = 0xFFFF;
static const uint16 InvalidPlaceId = 0xFFFF; static const uint16 InvalidPlaceId = 0xFFFF;
static const std::string DepositStateFileName = "deposits_state";
/** /**
* A teleport destination zone * A teleport destination zone
* \author Nicolas Brigand * \author Nicolas Brigand
@ -539,6 +541,11 @@ public:
*/ */
void clearEcotypes(); void clearEcotypes();
// Save deposit to primitive file, if needed
void saveDeposits();
/// Callback for deposit state
void receivedDepositState(CFileDescription const &fileDescription, NLMISC::IStream &dataStream);
private: private:
/** /**
@ -640,6 +647,24 @@ private:
/// The ecotype zones /// The ecotype zones
static CEcotypeZones _EcotypeZones; static CEcotypeZones _EcotypeZones;
/// Next cycle where we'll save deposits
NLMISC::TGameCycle _NextDepositSave;
};
class CDepositCallback : public IBackupFileReceiveCallback
{
public:
CDepositCallback() : processed(false) {}
bool processed;
void callback(const CFileDescription& fileDescription, NLMISC::IStream& dataStream)
{
if (!processed)
{
CZoneManager::getInstance().receivedDepositState(fileDescription, dataStream);
processed = true;
}
}
}; };