diff --git a/engine/server/application/CentralServer/src/shared/CentralServer.cpp b/engine/server/application/CentralServer/src/shared/CentralServer.cpp index f9feb1d9..427f9fac 100755 --- a/engine/server/application/CentralServer/src/shared/CentralServer.cpp +++ b/engine/server/application/CentralServer/src/shared/CentralServer.cpp @@ -2877,11 +2877,11 @@ void CentralServer::sendMetricsToWebAPI() #ifdef _DEBUG if (api.submit()) { - bool status = api.getRespValue("status"); + bool status = api.getNullableValue("status"); if (status) { - std::string message = api.getRespValue("message"); + std::string message = api.getString("message"); if (message.empty()) { diff --git a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp index 52425044..65c94369 100755 --- a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp @@ -192,8 +192,8 @@ void ClientConnection::validateClient(const std::string & id, const std::string if (api.submit()) { - bool status = api.getRespValue("status"); - uname = api.getRespValue("username"); + bool status = api.getNullableValue("status"); + uname = api.getString("username"); if (status && !uname.empty()) { @@ -201,7 +201,7 @@ void ClientConnection::validateClient(const std::string & id, const std::string } else { - std::string msg = api.getRespValue("message"); + std::string msg = api.getString("message"); if (msg.empty()) { msg = "Invalid username or password."; diff --git a/external/3rd/library/webAPI/webAPI.cpp b/external/3rd/library/webAPI/webAPI.cpp index ecf84038..13ad61ae 100644 --- a/external/3rd/library/webAPI/webAPI.cpp +++ b/external/3rd/library/webAPI/webAPI.cpp @@ -50,6 +50,16 @@ bool webAPI::setData(std::string &data) return false; } +std::string webAPI::getString(const std::string &slot) +{ + if (!this->responseData.empty() && !slot.empty() && responseData.count(slot)) + { + return this->responseData[slot].get(); + } + + return std::string(""); +} + bool webAPI::submit(const int &reqType, const int &getPost, const int &respType) { if (reqType == DTYPE::JSON) // json request diff --git a/external/3rd/library/webAPI/webAPI.h b/external/3rd/library/webAPI/webAPI.h index e371129f..001a8cc1 100644 --- a/external/3rd/library/webAPI/webAPI.h +++ b/external/3rd/library/webAPI/webAPI.h @@ -52,11 +52,14 @@ namespace StellaBellum // set a standard request string bool setData(std::string &data); // all or nothing + + // get a string from a given slot + std::string getString(const std::string &slot); // set json key and value for request - template bool addJsonData(std::string key, T value) + template bool addJsonData(const std::string &key, const T &value) { - if (!key.empty()) + if (!key.empty() && responseData.count(key) == 0) // only alow one of a given key for now, unless we support nesting later { this->requestData[key] = value; return true; @@ -66,14 +69,14 @@ namespace StellaBellum } // get json response slot - template T getRespValue(std::string slot) + template T getNullableValue(const std::string &slot) { - if (!this->responseData.is_null() && !slot.empty() && !this->responseData[slot].is_null()) + if (!this->responseData.empty() && !slot.empty() && responseData.count(slot)) { return this->responseData[slot].get(); } - - return static_cast(NULL); + + return 0; } private: