mirror of
https://github.com/SWG-Source/src.git
synced 2026-08-01 01:16:03 -04:00
for nullable types we'll need to create a proper function outside the template for them
This commit is contained in:
@@ -2877,11 +2877,11 @@ void CentralServer::sendMetricsToWebAPI()
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (api.submit()) {
|
||||
bool status = api.getRespValue<bool>("status");
|
||||
bool status = api.getNullableValue<bool>("status");
|
||||
|
||||
if (status)
|
||||
{
|
||||
std::string message = api.getRespValue<std::string>("message");
|
||||
std::string message = api.getString("message");
|
||||
|
||||
if (message.empty())
|
||||
{
|
||||
|
||||
@@ -192,8 +192,8 @@ void ClientConnection::validateClient(const std::string & id, const std::string
|
||||
|
||||
if (api.submit())
|
||||
{
|
||||
bool status = api.getRespValue<bool>("status");
|
||||
uname = api.getRespValue<std::string>("username");
|
||||
bool status = api.getNullableValue<bool>("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<std::string>("message");
|
||||
std::string msg = api.getString("message");
|
||||
if (msg.empty())
|
||||
{
|
||||
msg = "Invalid username or password.";
|
||||
|
||||
+10
@@ -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<std::string>();
|
||||
}
|
||||
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
bool webAPI::submit(const int &reqType, const int &getPost, const int &respType)
|
||||
{
|
||||
if (reqType == DTYPE::JSON) // json request
|
||||
|
||||
Vendored
+9
-6
@@ -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<typename T> bool addJsonData(std::string key, T value)
|
||||
template<typename T> 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<typename T> T getRespValue(std::string slot)
|
||||
template<typename T> 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<T>();
|
||||
}
|
||||
|
||||
return static_cast<T>(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user