mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-13 21:01:08 -04:00
did i say simpler? i'm not sure if this is more or less simple...but it is secure and operates how we need... @apathy audit please?
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-7
@@ -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<std::string>() == statusVal && response.count(slotName))
|
||||
{
|
||||
return response[slotName].get<std::string>();
|
||||
return {true, response[slotName].get<std::string>()};
|
||||
|
||||
}
|
||||
else //default message is an error, the other end always assumes "success" or the specified slot
|
||||
{
|
||||
if (response.count(messageSlot))
|
||||
{
|
||||
return response[messageSlot].get<std::string>();
|
||||
return {false, response[messageSlot].get<std::string>()};
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Vendored
+8
-1
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user