move the web api updates into their own function, and make it a configurable via webUpdateIntervalSeconds, also fix the check using mod operator for shutdown as it fired every frame except frame 5, instead of every second

This commit is contained in:
DarthArgus
2016-05-06 02:53:37 +00:00
parent 5a082e5f1d
commit eb8e50c568
4 changed files with 42 additions and 12 deletions
@@ -2780,6 +2780,17 @@ void CentralServer::update()
sendPopulationUpdateToLoginServer();
}
// update the webAPI if specified
// in theory the variables should be set unless this fires at a really early frame
int webUpdateIntervalSeconds = ConfigCentralServer::getWebUpdateIntervalSeconds();
// assuming that every 5th frame is ~1 second, we can multiply and then mod
if ( webUpdateIntervalSeconds > 0 && (loopCount%(webUpdateIntervalSeconds*5) == 0))
{
sendMetricsToWebAPI();
}
if ( ConfigCentralServer::getAuctionEnabled() ) // allow auctions?
{
if ( m_pAuctionTransferClient == nullptr )
@@ -2804,7 +2815,8 @@ void CentralServer::update()
}
// check every 5th frame (one second roughly?)
if( loopCount%5 )
// mod returns 0 if no remainder - meaning the below would return true without == 0, wtf?
if( loopCount % 5 == 0 )
{
checkShutdownProcess();
}
@@ -2841,21 +2853,24 @@ void CentralServer::sendPopulationUpdateToLoginServer()
if (!isPreloadFinished() || (time(0)-m_lastLoadingStateTime < static_cast<time_t>(ConfigCentralServer::getRecentLoadingStateSeconds())))
loadedRecently=true;
// stella: Adding those for sending regular updates through WebAPI to the webserver
std::string updateURL = std::string(ConfigCentralServer::getMetricsDataURL());
if (!(updateURL.empty()))
{
std::ostringstream postBuf;
postBuf << "totalPlayerCount=" << m_totalPlayerCount << "&totalGameServers=" << m_gameServers.size() - 1 << "&totalPlanetServers=" << m_planetServers.size() << "&isPublic=" << getIsClusterPublic() << "&isLocked=" << getIsClusterLocked() << "&isSecret=" << getIsClusterSecret() << "&preloadFinished=" << getClusterStartupTime() << "&databasebacklogged=" << isDatabaseBacklogged() << "&totalTutorialSceneCount=" << m_totalTutorialSceneCount << "&totalFalconSceneCount=" << m_totalFalconSceneCount;
webAPI::simplePost(updateURL, std::string(postBuf.str()), "");
}
UpdatePlayerCountMessage upm(loadedRecently, m_totalPlayerCount, m_totalFreeTrialCount, m_totalEmptySceneCount, m_totalTutorialSceneCount, m_totalFalconSceneCount);
sendToAllLoginServers(upm);
}
void CentralServer::sendMetricsToWebAPI()
{
std::string updateURL = std::string(ConfigCentralServer::getMetricsDataURL());
if (!(updateURL.empty()))
{
std::ostringstream postBuf;
postBuf << "totalPlayerCount=" << m_totalPlayerCount << "&totalGameServers=" << m_gameServers.size() - 1 << "&totalPlanetServers=" << m_planetServers.size() << "&isPublic=" << getIsClusterPublic() << "&isLocked=" << getIsClusterLocked() << "&isSecret=" << getIsClusterSecret() << "&preloadFinished=" << getClusterStartupTime() << "&databasebacklogged=" << isDatabaseBacklogged() << "&totalTutorialSceneCount=" << m_totalTutorialSceneCount << "&totalFalconSceneCount=" << m_totalFalconSceneCount;
webAPI::simplePost(updateURL, std::string(postBuf.str()), "");
}
}
//-----------------------------------------------------------------------
void CentralServer::sendTaskMessage(const GameNetworkMessage & source)
@@ -182,6 +182,7 @@ private:
size_t getGameServerCount (void) const;
void update();
void sendPopulationUpdateToLoginServer();
void sendMetricsToWebAPI();
ConnectionServerConnection * getConnectionServerForAccount(StationId suid);
void addToAccountConnectionMap(StationId suid, ConnectionServerConnection * cconn, uint32 subscriptionBits);
void removeFromAccountConnectionMap(int connectionServerConnectionId);
@@ -128,6 +128,7 @@ void ConfigCentralServer::install(void)
KEY_BOOL (requestDbSaveOnPlanetServerCrash, true);
KEY_INT (maxTimeToWaitForPlanetServerStartSeconds, 5*60); // seconds
KEY_STRING (metricsDataURL, "");
KEY_INT (webUpdateIntervalSeconds, 0);
int index = 0;
char const * result = 0;
@@ -71,7 +71,9 @@ public:
bool requestDbSaveOnPlanetServerCrash;
int maxTimeToWaitForPlanetServerStartSeconds;
const char * metricsDataURL;
int webUpdateIntervalSeconds;
};
static const unsigned short getChatServicePort ();
@@ -141,7 +143,9 @@ public:
static bool getRequestDbSaveOnPlanetServerCrash();
static int getMaxTimeToWaitForPlanetServerStartSeconds();
static const char * getMetricsDataURL();
static int getWebUpdateIntervalSeconds();
private:
static Data * data;
};
@@ -511,11 +515,20 @@ inline int ConfigCentralServer::getMaxTimeToWaitForPlanetServerStartSeconds()
return data->maxTimeToWaitForPlanetServerStartSeconds;
}
// ----------------------------------------------------------------------
inline const char * ConfigCentralServer::getMetricsDataURL()
{
return data->metricsDataURL;
}
// ----------------------------------------------------------------------
inline int ConfigCentralServer::getWebUpdateIntervalSeconds()
{
return data->webUpdateIntervalSeconds;
}
// ======================================================================
#endif // _ConfigCentralServer_H