diff --git a/engine/server/application/CentralServer/src/shared/CentralServer.cpp b/engine/server/application/CentralServer/src/shared/CentralServer.cpp index 47798110..01461537 100755 --- a/engine/server/application/CentralServer/src/shared/CentralServer.cpp +++ b/engine/server/application/CentralServer/src/shared/CentralServer.cpp @@ -2871,8 +2871,8 @@ void CentralServer::sendMetricsToWebAPI(std::string updateURL) 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; - std::string response = webAPI::simplePost(updateURL, std::string(postBuf.str()), "status", "message"); - WARNING((response != "success"), ("Error sending stats: %s", response.c_str())); + webAPI::statusMessage response = webAPI::simplePost(updateURL, std::string(postBuf.str()), "status", "message", "status", "success"); + WARNING(response.status, ("Error sending stats: %s", response.message.c_str())); } //----------------------------------------------------------------------- diff --git a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp index f2493d57..007b0bb0 100755 --- a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp @@ -182,16 +182,16 @@ void ClientConnection::validateClient(const std::string & id, const std::string std::ostringstream postBuf; postBuf << "user_name=" << id << "&user_password=" << key << "&ip=" << getRemoteAddress(); - const std::string response = webAPI::simplePost(authURL, std::string(postBuf.str()), "username", "message"); + const webAPI::statusMessage response = webAPI::simplePost(authURL, std::string(postBuf.str()), "username", "message", "status", "success"); - if (!response.empty()) + if (response.status && !response.message.empty()) { authOK = 1; - uname = response; + uname = response.message; } else { - ErrorMessage err("Login Failed", response); + ErrorMessage err("Login Failed", response.message); this->send(err, true); } } diff --git a/external/3rd/library/webAPI/webAPI.cpp b/external/3rd/library/webAPI/webAPI.cpp index 69e4d67e..cb2fe61a 100644 --- a/external/3rd/library/webAPI/webAPI.cpp +++ b/external/3rd/library/webAPI/webAPI.cpp @@ -17,27 +17,33 @@ License: what's a license? we're a bunch of dirty pirates! using namespace std; -// if there is a response contained in slotName, it is returned -string webAPI::simplePost(const string &endpoint, const string &data, const string &slotName, const string &messageSlot) +/* +endpoint: URI +data: get/post +messageSlot: key for fetching a verbose user friendly message +statusSlot: slot containing the success/fail value +statusVal: the expected value in the case of success +*/ +webAPI::statusMessage webAPI::simplePost(const string &endpoint, const string &data, const string &slotName, const string &messageSlot, const string &statusSlot, const string &statusVal) { // declare our output and go ahead and attempt to get data from remote nlohmann::json response = request(endpoint, data, 1); - string output; // if we got data back... - if (response.count(slotName)) + if (response.count(statusSlot) && response[statusSlot].get() == statusVal && response.count(slotName)) { - return response[slotName].get(); + return {true, response[slotName].get()}; + } else //default message is an error, the other end always assumes "success" or the specified slot { if (response.count(messageSlot)) { - return response[messageSlot].get(); + return {false, response[messageSlot].get()}; } } - return "Message not provided by remote."; + return {false, "Message not provided by remote."}; } // this can be broken out to separate the json bits later if we need raw or other http type requests diff --git a/external/3rd/library/webAPI/webAPI.h b/external/3rd/library/webAPI/webAPI.h index 87331f41..4f50cad6 100644 --- a/external/3rd/library/webAPI/webAPI.h +++ b/external/3rd/library/webAPI/webAPI.h @@ -26,9 +26,16 @@ License: what's a license? we're a bunch of dirty pirates! namespace webAPI { + + struct statusMessage + { + bool status; + std::string message; + }; + using namespace std; - string simplePost(const string &endpoint, const string &data, const string &slotName, const string &messageSlot); + statusMessage simplePost(const string &endpoint, const string &data, const string &slotName, const string &messageSlot, const string &statusSlot, const string &statusVal); nlohmann::json request(const string &endpoint, const string &data, const int &reqType); // 1 for post, 0 for get size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp); };