use ints for the subaccounts and account ids

This commit is contained in:
DarthArgus
2016-12-31 23:59:15 +00:00
parent ddc83f77a0
commit bb842aa187
4 changed files with 2652 additions and 824 deletions
@@ -167,12 +167,13 @@ 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) {
bool authOK = false;
StationId suid = atoi(id.c_str());
static const std::string authURL(ConfigLoginServer::getExternalAuthUrl());
std::string uname;
std::string parentAccount;
std::vector<std::string> childAccounts;
StationId user_id;
StationId parent_id;
std::unordered_map<int, std::string> childAccounts;
if (!authURL.empty()) {
// create the object
@@ -191,7 +192,10 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
authOK = true;
parentAccount = api.getString("mainAccount");
childAccounts = api.getStringVector("subAccounts");
childAccounts = api.getStringMap("subAccounts");
user_id = api.getNullableValue<int>("user_id");
parent_id = api.getNullableValue<int>("parent_id");
} else {
std::string msg(api.getString("message"));
if (msg.empty()) {
@@ -211,60 +215,39 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
uname = id;
}
if (authOK) {
if (suid == 0) {
if (uname.length() > MAX_ACCOUNT_NAME_LENGTH)
uname.resize(MAX_ACCOUNT_NAME_LENGTH);
std::hash<std::string> hasher;
suid = hasher(uname.c_str());
}
REPORT_LOG(true, ("Client connected. Username: %s (%zu) \n", uname.c_str(), suid));
StationId parent = -1;
if (authOK && user_id && parent_id) {
REPORT_LOG(true, ("Client connected. Username: %s (%i) \n", uname.c_str(), user_id));
if (!parentAccount.empty()) {
if (parentAccount.length() > MAX_ACCOUNT_NAME_LENGTH)
parentAccount.resize(MAX_ACCOUNT_NAME_LENGTH);
std::hash<std::string> hasher;
parent = hasher(parentAccount.c_str());
if (parentAccount != uname) {
REPORT_LOG(true, ("\t%s's parent is %s (%zu) \n", uname.c_str(), parentAccount.c_str(), parent));
REPORT_LOG(true, ("\t%s's parent is %s (%i) \n", uname.c_str(), parentAccount.c_str(), parent_id));
}
} else {
parentAccount = "(Empty Parent!) "+uname;
}
if (parent != -1) {
for (auto i : childAccounts) {
std::string child(i);
if (!child.empty()) {
if (child.length() > MAX_ACCOUNT_NAME_LENGTH)
child.resize(MAX_ACCOUNT_NAME_LENGTH);
std::hash<std::string> hasher;
StationId childID = hasher(child.c_str());
REPORT_LOG(parent!=childID, ("\tchild of %s (%zu) is %s (%zu) \n", parentAccount.c_str(), parent, child.c_str(), childID));
// insert all related accounts, if not already there, into the db
if (parent != childID) {
DatabaseConnection::getInstance().upsertAccountRelationship(parent, childID);
}
} else {
WARNING(true, ("Login API returned empty child account(s)."));
}
}
}
for (auto i : childAccounts) {
StationId child_id = i.first;
std::string child(i.second);
if (!child.empty()) {
REPORT_LOG((parent_id != child_id), ("\tchild of %s (%i) is %s (%i) \n", parentAccount.c_str(), parent_id, child.c_str(), child_id));
// insert all related accounts, if not already there, into the db
if (parent_id != child_id) {
DatabaseConnection::getInstance().upsertAccountRelationship(parent_id, child_id);
}
} else {
WARNING(true, ("Login API returned empty child account(s)."));
}
}
LOG("LoginClientConnection",
("validateClient() for stationId (%zu) at IP (%s), id (%s)", m_stationId, getRemoteAddress().c_str(), uname.c_str()));
("validateClient() for stationId (%i) at IP (%s), id (%s)", user_id, getRemoteAddress().c_str(), uname.c_str()));
LoginServer::getInstance().onValidateClient(suid, uname, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF);
m_stationId = user_id;
LoginServer::getInstance().onValidateClient(m_stationId, uname, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF);
}
}
+2604 -770
View File
File diff suppressed because it is too large Load Diff
+16 -6
View File
@@ -1,5 +1,5 @@
/*
* Version: 1.5
* Version: 1.6
*
* This code is just a simple wrapper around nlohmann's wonderful json lib
* (https://github.com/nlohmann/json) and libcurl. While originally included directly,
@@ -55,13 +55,23 @@ std::string webAPI::getString(const std::string &slot) {
return std::string("");
}
std::vector<std::string> webAPI::getStringVector(const std::string &slot) {
std::unordered_map<int, std::string> webAPI::getStringMap(const std::string &slot) {
std::unordered_map<int, std::string> ret = std::unordered_map<int, std::string>();
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot) &&
!this->responseData[slot].is_null()) {
return this->responseData[slot].get<std::vector<std::string>>();
}
nlohmann::json j = this->responseData[slot];
return std::vector<std::string>();
for (nlohmann::json::iterator it = j.begin(); it != j.end(); ++it) {
int k = std::stoi(it.key());
std::string val = it.value();
ret.insert({k, val});
}
}
return ret;
}
bool webAPI::submit(const int &reqType, const int &getPost, const int &respType) {
@@ -184,4 +194,4 @@ bool webAPI::processJSON() {
}
return false;
}
}
+3 -2
View File
@@ -1,5 +1,5 @@
/*
* Version: 1.5
* Version: 1.6
*
* This code is just a simple wrapper around nlohmann's wonderful json lib
* (https://github.com/nlohmann/json) and libcurl. While originally included directly,
@@ -24,6 +24,7 @@
#include <curl.h>
#else
#include <unordered_map>
#include <curl/curl.h>
#endif
@@ -63,7 +64,7 @@ namespace StellaBellum {
std::string getString(const std::string &slot);
// get a vector of strings from a given slot
std::vector<std::string> getStringVector(const std::string &slot);
std::unordered_map<int, std::string> getStringMap(const std::string &slot);
// set json key and value for request
template<typename T>