Merge branch 'testing'

This commit is contained in:
DarthArgus
2017-01-01 01:51:34 +00:00
10 changed files with 2692 additions and 854 deletions

View File

@@ -33,9 +33,10 @@
#include "serverNetworkMessages/UploadCharacterMessage.h"
#include "sharedLog/Log.h"
#include "sharedNetworkMessages/ConsoleChannelMessages.h"
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
#include "unicodeArchive/UnicodeArchive.h"
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
#include "sharedFoundation/CrcConstexpr.hpp"
// ======================================================================
@@ -126,11 +127,16 @@ void GameServerConnection::onReceive(Archive::ByteStream const &message)
}
case constcrc("TransferReplyNameValidation") :
{
GenericValueTypeMessage<std::pair<std::string, TransferCharacterData> > const replyNameValidation(ri);
GenericValueTypeMessage<std::map<std::string, TransferCharacterData> > const replyNameValidation(ri);
auto i = replyNameValidation.getValue().begin();
if (replyNameValidation.getValue().second.getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (i == replyNameValidation.getValue().end()) {
break;
}
if (i->second.getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
LOG("CustomerService", ("CharacterTransfer: Received TransferReplyNameValidation from GameServer, forwarding to TransferServer : %s", replyNameValidation.getValue().second.toString().c_str()));
LOG("CustomerService", ("CharacterTransfer: Received TransferReplyNameValidation from GameServer, forwarding to TransferServer : %s", i->second.toString().c_str()));
CentralServer::getInstance().sendToTransferServer(replyNameValidation);
}
else
@@ -138,14 +144,14 @@ void GameServerConnection::onReceive(Archive::ByteStream const &message)
// pass reply back to the source galaxy for handling, which is to
// either display an error message to the user if the request failed,
// or to start the transfer process if the request succeeds
LOG("CustomerService", ("CharacterTransfer: Received TransferReplyNameValidation from GameServer, forwarding to source galaxy CentralServer : %s", replyNameValidation.getValue().second.toString().c_str()));
LOG("CustomerService", ("CharacterTransfer: Received TransferReplyNameValidation from GameServer, forwarding to source galaxy CentralServer : %s", i->second.toString().c_str()));
CentralServer::getInstance().sendToArbitraryLoginServer(replyNameValidation);
// if the request succeeded, also disconnect any clients with a connection to SWG services on this (the target) galaxy
if (replyNameValidation.getValue().second.getIsValidName() && (replyNameValidation.getValue().second.getTransferRequestSource() != TransferRequestMoveValidation::TRS_ingame_freects_command_validate) && (replyNameValidation.getValue().second.getTransferRequestSource() != TransferRequestMoveValidation::TRS_ingame_cts_command_validate))
if (i->second.getIsValidName() && (i->second.getTransferRequestSource() != TransferRequestMoveValidation::TRS_ingame_freects_command_validate) && (i->second.getTransferRequestSource() != TransferRequestMoveValidation::TRS_ingame_cts_command_validate))
{
GenericValueTypeMessage<unsigned int> kickSource("TransferKickConnectedClients", replyNameValidation.getValue().second.getSourceStationId());
GenericValueTypeMessage<unsigned int> kickDestination("TransferKickConnectedClients", replyNameValidation.getValue().second.getDestinationStationId());
GenericValueTypeMessage<unsigned int> kickSource("TransferKickConnectedClients", i->second.getSourceStationId());
GenericValueTypeMessage<unsigned int> kickDestination("TransferKickConnectedClients", i->second.getDestinationStationId());
CentralServer::getInstance().sendToAllLoginServers(kickSource);
CentralServer::getInstance().sendToAllLoginServers(kickDestination);
CentralServer::getInstance().sendToAllConnectionServers(kickSource, true);

View File

@@ -396,11 +396,14 @@ void ClientConnection::handleClientIdMessage(const ClientIdMsg& msg)
}
else
{
m_suid = atoi(m_accountName.c_str());
if (m_suid == 0)
{
std::hash<std::string> h;
m_suid = h(m_accountName.c_str());
if (!m_suid) {
m_suid = atoi(m_accountName.c_str());
if (m_suid == 0)
{
std::hash<std::string> h;
m_suid = h(m_accountName.c_str());
}
}
onValidateClient(m_suid, m_accountName, m_isSecure, nullptr, ConfigConnectionServer::getDefaultGameFeatures(), ConfigConnectionServer::getDefaultSubscriptionFeatures(), 0, 0, 0, 0, ConfigConnectionServer::getFakeBuddyPoints());
}
@@ -1462,7 +1465,7 @@ void ClientConnection::onCharacterValidated(bool isValid, const NetworkId &chara
//------------------------------------------------------------------------------------------
void ClientConnection::onValidateClient (uint32 suid, const std::string & username, bool secure, const char* id, const uint32 gameFeatures, const uint32 subscriptionFeatures, unsigned int entitlementTotalTime, unsigned int entitlementEntitledTime, unsigned int entitlementTotalTimeSinceLastLogin, unsigned int entitlementEntitledTimeSinceLastLogin, int buddyPoints)
void ClientConnection::onValidateClient (StationId suid, const std::string & username, bool secure, const char* id, const uint32 gameFeatures, const uint32 subscriptionFeatures, unsigned int entitlementTotalTime, unsigned int entitlementEntitledTime, unsigned int entitlementTotalTimeSinceLastLogin, unsigned int entitlementEntitledTimeSinceLastLogin, int buddyPoints)
{
UNREF(id);
m_sessionValidated = true;

View File

@@ -91,7 +91,7 @@ public:
void handleGameServerForLoginMessage(uint32 serverId);
void onIdValidated(bool canLogin, bool canCreateRegularCharacter, bool canCreateJediCharacter, bool canSkipTutorial, std::vector<std::pair<NetworkId, std::string> > const & consumedRewardEvents, std::vector<std::pair<NetworkId, std::string> > const & claimedRewardItems);
void onValidateClient (uint32 id, const std::string & username, bool, const char*, uint32 gameFeatures, uint32 subscriptionFeatures, unsigned int entitlementTotalTime, unsigned int entitlementEntitledTime, unsigned int entitlementTotalTimeSinceLastLogin, unsigned int entitlementEntitledTimeSinceLastLogin, int buddyPoints);
void onValidateClient (StationId id, const std::string & username, bool, const char*, uint32 gameFeatures, uint32 subscriptionFeatures, unsigned int entitlementTotalTime, unsigned int entitlementEntitledTime, unsigned int entitlementTotalTimeSinceLastLogin, unsigned int entitlementEntitledTimeSinceLastLogin, int buddyPoints);
void onCharacterValidated(bool isValid, const NetworkId &character, const std::string &characterName, const NetworkId &container, const std::string &scene, const Vector &coordinates);
static std::string describeAccount(const ClientConnection *);

View File

@@ -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 = static_cast<StationId>(api.getNullableValue<int>("user_id"));
parent_id = static_cast<StationId>(api.getNullableValue<int>("parent_id"));
} else {
std::string msg(api.getString("message"));
if (msg.empty()) {
@@ -211,58 +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 (%lu) \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 (%lu) \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(true, ("\tchild of %s (%lu) is %s (%lu) \n", parentAccount.c_str(), parent, child.c_str(), childID));
// insert all related accounts, if not already there, into the db
DatabaseConnection::getInstance().upsertAccountRelationship(parent, childID);
} else {
WARNING(true, ("Login API returned empty child account(s)."));
}
}
}
for (auto i : childAccounts) {
StationId child_id = static_cast<StationId>(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 (%lu) 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);
}
}

View File

@@ -228,27 +228,32 @@ void CentralServerConnection::onReceive(const Archive::ByteStream & message)
}
case constcrc("TransferReplyNameValidation") :
{
const GenericValueTypeMessage<std::pair<std::string, TransferCharacterData> > replyNameValidation(ri);
if(!replyNameValidation.getValue().second.getIsMoveRequest())
const GenericValueTypeMessage<std::map<std::string, TransferCharacterData> > replyNameValidation(ri);
auto i = replyNameValidation.getValue().begin();
if (i == replyNameValidation.getValue().end()) {
break;
}
if(!i->second.getIsMoveRequest())
{
LOG("CustomerService", ("CharacterTransfer: Received replyNameValidation for move validation request. (%s) %s", replyNameValidation.getValue().first.c_str(), replyNameValidation.getValue().second.toString().c_str()));
TransferServer::replyValidateMove(replyNameValidation.getValue().second);
LOG("CustomerService", ("CharacterTransfer: Received replyNameValidation for move validation request. (%s) %s", i->first.c_str(), i->second.toString().c_str()));
TransferServer::replyValidateMove(i->second);
}
else
{
if(TransferServer::isRename(replyNameValidation.getValue().second))
if(TransferServer::isRename(i->second))
{
LOG("CustomerService", ("CharacterTransfer: Received replyNameValidation for rename request, starting character rename protocol. (%s) %s", replyNameValidation.getValue().first.c_str(), replyNameValidation.getValue().second.toString().c_str()));
const GenericValueTypeMessage<TransferCharacterData> renameCharacter("TransferRenameCharacter", replyNameValidation.getValue().second);
CentralServerConnection * centralServerConnection = CentralServerConnection::getCentralServerConnectionForGalaxy(replyNameValidation.getValue().second.getSourceGalaxy());
LOG("CustomerService", ("CharacterTransfer: Received replyNameValidation for rename request, starting character rename protocol. (%s) %s", i->first.c_str(), i->second.toString().c_str()));
const GenericValueTypeMessage<TransferCharacterData> renameCharacter("TransferRenameCharacter", i->second);
CentralServerConnection * centralServerConnection = CentralServerConnection::getCentralServerConnectionForGalaxy(i->second.getSourceGalaxy());
if(centralServerConnection)
{
centralServerConnection->send(renameCharacter, true);
}
else
{
TransferServer::transferCreateCharacterFailed(replyNameValidation.getValue().second);
}
TransferServer::transferCreateCharacterFailed(i->second); }
}
else
{

View File

@@ -103,10 +103,8 @@ public:
void setWorkingSkill (const std::string & workingSkill);
void setCSToolId (const unsigned int toolId);
private:
TransferCharacterData();
private:
friend class Archive::AutoVariable<TransferCharacterData>;
friend struct std::pair<std::string, TransferCharacterData>;
friend void Archive::get(Archive::ReadIterator & source, TransferCharacterData & target);

View File

@@ -12,10 +12,6 @@
// ======================================================================
typedef unsigned long uint32;
// ======================================================================
class DebugHelp
{
public:

File diff suppressed because it is too large Load Diff

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;
}
}

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>