From eb8e50c568b3983249db9b7dfde3a889ca6a3926 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Fri, 6 May 2016 02:52:55 +0000 Subject: [PATCH] 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 --- .../src/shared/CentralServer.cpp | 39 +++++++++++++------ .../CentralServer/src/shared/CentralServer.h | 1 + .../src/shared/ConfigCentralServer.cpp | 1 + .../src/shared/ConfigCentralServer.h | 13 +++++++ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/engine/server/application/CentralServer/src/shared/CentralServer.cpp b/engine/server/application/CentralServer/src/shared/CentralServer.cpp index e039a517..a6b51427 100755 --- a/engine/server/application/CentralServer/src/shared/CentralServer.cpp +++ b/engine/server/application/CentralServer/src/shared/CentralServer.cpp @@ -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(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) diff --git a/engine/server/application/CentralServer/src/shared/CentralServer.h b/engine/server/application/CentralServer/src/shared/CentralServer.h index 262552b0..22e6a7de 100755 --- a/engine/server/application/CentralServer/src/shared/CentralServer.h +++ b/engine/server/application/CentralServer/src/shared/CentralServer.h @@ -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); diff --git a/engine/server/application/CentralServer/src/shared/ConfigCentralServer.cpp b/engine/server/application/CentralServer/src/shared/ConfigCentralServer.cpp index 28a33e2f..0a981a11 100755 --- a/engine/server/application/CentralServer/src/shared/ConfigCentralServer.cpp +++ b/engine/server/application/CentralServer/src/shared/ConfigCentralServer.cpp @@ -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; diff --git a/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h b/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h index ed971f33..79e08d55 100755 --- a/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h +++ b/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h @@ -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