mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-13 21:01:08 -04:00
needs QA/TEST before even seeing TC - implement login based on returned username from web api
This commit is contained in:
@@ -2864,13 +2864,14 @@ void CentralServer::sendPopulationUpdateToLoginServer()
|
||||
sendToAllLoginServers(upm);
|
||||
}
|
||||
|
||||
// TODO: make this togglable on/off in a config setting
|
||||
void CentralServer::sendMetricsToWebAPI(std::string updateURL)
|
||||
{
|
||||
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;
|
||||
|
||||
std::string response = webAPI::simplePost(updateURL, std::string(postBuf.str()), "");
|
||||
std::string response = webAPI::simplePost(updateURL, std::string(postBuf.str()), "status", "message");
|
||||
WARNING((response != "success"), ("Error sending stats: %s", response.c_str()));
|
||||
}
|
||||
|
||||
|
||||
@@ -172,63 +172,50 @@ void ClientConnection::onReceive(const Archive::ByteStream & message)
|
||||
// originally was used to validate station API credentials, now uses our custom api
|
||||
void ClientConnection::validateClient(const std::string & id, const std::string & key)
|
||||
{
|
||||
// to avoid having to re-type this stupid var all over the place
|
||||
// ideally we wouldn't copy this here, but it would be a huge pain
|
||||
std::string tmp = trim(id);
|
||||
|
||||
if (tmp.length() > MAX_ACCOUNT_NAME_LENGTH) {
|
||||
tmp.resize(MAX_ACCOUNT_NAME_LENGTH); // truncate name after the trim
|
||||
}
|
||||
|
||||
const std::string trimmedId = tmp;
|
||||
const std::string trimmedKey = trim(key);
|
||||
|
||||
// and to avoid funny business with atoi and casing
|
||||
// make it a separate var than the one we send the auth server
|
||||
std::string lcaseId;
|
||||
lcaseId.resize(trimmedId.size());
|
||||
|
||||
std::transform(trimmedId.begin(),trimmedId.end(),lcaseId.begin(),::tolower);
|
||||
|
||||
StationId suid = atoi(lcaseId.c_str());
|
||||
int authOK = 0;
|
||||
|
||||
if (suid == 0)
|
||||
{
|
||||
std::hash<std::string> h;
|
||||
suid = h(lcaseId.c_str()); //lint !e603 // Symbol 'h' not initialized (it's a functor)
|
||||
}
|
||||
|
||||
LOG("LoginClientConnection", ("validateClient() for stationId (%lu) at IP (%s), id (%s)", m_stationId, getRemoteAddress().c_str(), lcaseId.c_str()));
|
||||
StationId suid = atoi(id.c_str());
|
||||
std::string uname;
|
||||
|
||||
std::string authURL(ConfigLoginServer::getExternalAuthUrl());
|
||||
|
||||
if (!authURL.empty())
|
||||
{
|
||||
std::ostringstream postBuf;
|
||||
postBuf << "user_name=" << trimmedId << "&user_password=" << trimmedKey << "&stationID=" << suid << "&ip=" << getRemoteAddress();
|
||||
postBuf << "user_name=" << id << "&user_password=" << key << "&ip=" << getRemoteAddress();
|
||||
|
||||
std::string response = webAPI::simplePost(authURL, std::string(postBuf.str()), "");
|
||||
const std::string response = webAPI::simplePost(authURL, std::string(postBuf.str()), "username", "message");
|
||||
|
||||
if (response == "success")
|
||||
if (!response.empty())
|
||||
{
|
||||
authOK = 1;
|
||||
uname = response;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage err("Login Failed", response);
|
||||
this->send(err, true);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// test mode
|
||||
authOK = 1;
|
||||
uname = id;
|
||||
|
||||
if (uname.length() > MAX_ACCOUNT_NAME_LENGTH) {
|
||||
uname.resize(MAX_ACCOUNT_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
if (authOK)
|
||||
{
|
||||
LoginServer::getInstance().onValidateClient(suid, lcaseId, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF);
|
||||
if (suid == 0)
|
||||
{
|
||||
std::hash<std::string> h;
|
||||
suid = h(uname.c_str());
|
||||
}
|
||||
|
||||
LOG("LoginClientConnection", ("validateClient() for stationId (%lu) at IP (%s), id (%s)", m_stationId, getRemoteAddress().c_str(), uname.c_str()));
|
||||
LoginServer::getInstance().onValidateClient(suid, uname, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF);
|
||||
}
|
||||
// else this case will never be reached, noop
|
||||
}
|
||||
|
||||
+8
-21
@@ -17,40 +17,27 @@ License: what's a license? we're a bunch of dirty pirates!
|
||||
|
||||
using namespace std;
|
||||
|
||||
// if status == success, returns "success", or slotName's contents if specified...
|
||||
// otherwise returns the "message" if no success
|
||||
string webAPI::simplePost(const string &endpoint, const string &data, const string &slotName)
|
||||
// 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)
|
||||
{
|
||||
// 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("status") && response["status"].get<std::string>() == "success")
|
||||
if (response.count(slotName))
|
||||
{
|
||||
// use custom slot if specified (not "")
|
||||
if (!(slotName.empty()) && response.count(slotName))
|
||||
{
|
||||
output = response[slotName].get<std::string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
output = "success";
|
||||
}
|
||||
return response[slotName].get<std::string>();
|
||||
}
|
||||
else //default message is an error, the other end always assumes "success" or the specified slot
|
||||
{
|
||||
if (response.count("message"))
|
||||
if (response.count(messageSlot))
|
||||
{
|
||||
output = response["message"].get<std::string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
output = "Message not provided by remote.";
|
||||
return response[messageSlot].get<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
return "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
|
||||
@@ -122,4 +109,4 @@ size_t webAPI::writeCallback(void *contents, size_t size, size_t nmemb, void *us
|
||||
{
|
||||
((string*)userp)->append((char*)contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -28,7 +28,7 @@ namespace webAPI
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
string simplePost(const string &endpoint, const string &data, const string &slotName);
|
||||
string simplePost(const string &endpoint, const string &data, const string &slotName, const string &messageSlot);
|
||||
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