mirror of
https://bitbucket.org/seefoe/src.git
synced 2026-07-30 00:15:46 -04:00
the response should never be empty but we need to check the json lib for exceptions and return appropriately... + cleanup a bit - closes #33
This commit is contained in:
@@ -2786,14 +2786,15 @@ void CentralServer::update()
|
||||
|
||||
// update the webAPI if specified
|
||||
int webUpdateIntervalSeconds = ConfigCentralServer::getWebUpdateIntervalSeconds();
|
||||
std::string updateURL = std::string(ConfigCentralServer::getMetricsDataURL());
|
||||
|
||||
// assuming that every 5th frame is ~1 second, we can multiply and then check
|
||||
if ( webUpdateIntervalSeconds && (++apiLoopCount > (webUpdateIntervalSeconds*1000)) )
|
||||
if ( !(updateURL.empty()) && webUpdateIntervalSeconds && (++apiLoopCount > (webUpdateIntervalSeconds*1000)) )
|
||||
{
|
||||
apiLoopCount = 0;
|
||||
|
||||
// update the web api
|
||||
sendMetricsToWebAPI();
|
||||
sendMetricsToWebAPI(updateURL);
|
||||
}
|
||||
|
||||
if ( ConfigCentralServer::getAuctionEnabled() ) // allow auctions?
|
||||
@@ -2863,18 +2864,14 @@ void CentralServer::sendPopulationUpdateToLoginServer()
|
||||
sendToAllLoginServers(upm);
|
||||
}
|
||||
|
||||
void CentralServer::sendMetricsToWebAPI()
|
||||
void CentralServer::sendMetricsToWebAPI(std::string updateURL)
|
||||
{
|
||||
std::string updateURL = std::string(ConfigCentralServer::getMetricsDataURL());
|
||||
std::ostringstream postBuf;
|
||||
|
||||
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;
|
||||
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()), "");
|
||||
}
|
||||
std::string response = webAPI::simplePost(updateURL, std::string(postBuf.str()), "");
|
||||
WARNING((response != "success"), ("Error sending stats: %s", response.c_str()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -182,7 +182,7 @@ private:
|
||||
size_t getGameServerCount (void) const;
|
||||
void update();
|
||||
void sendPopulationUpdateToLoginServer();
|
||||
void sendMetricsToWebAPI();
|
||||
void sendMetricsToWebAPI(std::string updateURL);
|
||||
ConnectionServerConnection * getConnectionServerForAccount(StationId suid);
|
||||
void addToAccountConnectionMap(StationId suid, ConnectionServerConnection * cconn, uint32 subscriptionBits);
|
||||
void removeFromAccountConnectionMap(int connectionServerConnectionId);
|
||||
|
||||
@@ -192,23 +192,16 @@ void ClientConnection::validateClient(const std::string & id, const std::string
|
||||
|
||||
std::string response = webAPI::simplePost(authURL, std::string(postBuf.str()), "");
|
||||
|
||||
if (!response.empty())
|
||||
if (response == "success")
|
||||
{
|
||||
if (response == "success")
|
||||
{
|
||||
authOK = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage err("Login Failed", response);
|
||||
this->send(err, true);
|
||||
}
|
||||
authOK = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage err("Login Failed", "Error connecting to authentication provider.");
|
||||
ErrorMessage err("Login Failed", response);
|
||||
this->send(err, true);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+9
-1
@@ -81,7 +81,15 @@ nlohmann::json webAPI::request(std::string endpoint, std::string data, int reqTy
|
||||
|
||||
if (res == CURLE_OK && http_code == 200 && !(readBuffer.empty())) // check it all out and parse
|
||||
{
|
||||
response = nlohmann::json::parse(readBuffer);
|
||||
try {
|
||||
response = nlohmann::json::parse(readBuffer);
|
||||
} catch (std::string e) {
|
||||
response["message"] = e;
|
||||
response["status"] = "failure";
|
||||
} catch (...) {
|
||||
response["message"] = "JSON parse error for endpoint.";
|
||||
response["status"] = "failure";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user