Merge branch 'master' of 45.166.161.136:staff/src

This commit is contained in:
DarthArgus
2016-12-31 00:10:02 -06:00
9 changed files with 113 additions and 107 deletions
@@ -169,8 +169,8 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
bool authOK = false;
StationId suid = atoi(id.c_str());
static const std::string authURL(ConfigLoginServer::getExternalAuthUrl());
std::string uname;
std::string uname;
std::string parentAccount;
std::vector<std::string> childAccounts;
@@ -194,7 +194,7 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
parentAccount = api.getString("mainAccount");
childAccounts = api.getStringVector("subAccounts");
} else {
std::string msg = api.getString("message");
std::string msg(api.getString("message"));
if (msg.empty()) {
msg = "Invalid username or password.";
}
@@ -214,30 +214,48 @@ void ClientConnection::validateClient(const std::string &id, const std::string &
if (authOK) {
if (suid == 0) {
if (uname.length() > MAX_ACCOUNT_NAME_LENGTH) {
uname.resize(MAX_ACCOUNT_NAME_LENGTH);
}
if (uname.length() > MAX_ACCOUNT_NAME_LENGTH)
uname.resize(MAX_ACCOUNT_NAME_LENGTH);
std::hash<std::string> h;
suid = h(uname.c_str());
std::hash<std::string> hasher;
suid = hasher(uname.c_str());
}
std::hash<std::string> h;
StationId parent = h(parentAccount);
REPORT_LOG(true, ("Client connected. Username: %s (%lu) \n", uname.c_str(), suid));
REPORT_LOG(true,
("Client connected. Station Id: %llu, Username: %s, Parent %s\n", suid, uname.c_str(), parentAccount.c_str()));
StationId parent = -1;
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));
}
} else {
parentAccount = "(Empty Parent!) "+uname;
}
for (auto i : childAccounts) {
if (i.length() > MAX_ACCOUNT_NAME_LENGTH) {
i.resize(MAX_ACCOUNT_NAME_LENGTH);
}
std::string child(i);
StationId childID = h(i);
REPORT_LOG(true, ("\tA child account for %s is %s (%llu)\n", parentAccount.c_str(), i.c_str(), childID));
if (!child.empty()) {
if (child.length() > MAX_ACCOUNT_NAME_LENGTH)
child.resize(MAX_ACCOUNT_NAME_LENGTH);
// insert all related accounts, if not already there, into the db
DatabaseConnection::getInstance().upsertAccountRelationship(parent, childID);
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)."));
}
}
LOG("LoginClientConnection",
@@ -46,10 +46,14 @@ bool CreateCharacterCustomPersistStep::beforePersist(DB::Session *session)
bool CreateCharacterCustomPersistStep::afterPersist(DB::Session *session)
{
// std::string characterName = Unicode::wideToNarrow(DatabaseProcess::getInstance().getNameByStationId(m_stationId));
DBQuery::AddCharacter qry(m_stationId,m_characterObject, m_characterName, m_normalizedName);
if (! (session->exec(&qry)))
if (! (session->exec(&qry))) {
std::string characterName(Unicode::wideToNarrow(m_characterName));
WARNING(true, ("CreateCharacterCustomPersistStep: Failed saving character and character object for %s", characterName.c_str()));
return false;
}
qry.done();
return true;
}
@@ -5,8 +5,6 @@
//
// ======================================================================
#include <memory>
#include "serverDatabase/FirstServerDatabase.h"
#include "serverDatabase/Persister.h"
@@ -433,7 +431,6 @@ Snapshot *Persister::getSnapshotForServer(uint32 serverId)
if (!m_arbitraryGameDataSnapshot) {
m_arbitraryGameDataSnapshot = snap;
}
return snap;
}
@@ -602,61 +599,57 @@ void Persister::endBaselines(const NetworkId &objectId, uint32 serverId)
void Persister::saveCompleted(Snapshot *completedSnapshot)
{
auto i=std::remove(m_savingSnapshots.begin(),m_savingSnapshots.end(),completedSnapshot);
if (i!=m_savingSnapshots.end())
{
m_savingSnapshots.erase(i, m_savingSnapshots.end());
if (completedSnapshot != nullptr) {
delete completedSnapshot;
completedSnapshot = nullptr;
bool found = false;
for (auto i = m_savingSnapshots.begin(); i != m_savingSnapshots.end();) {
if (*i == completedSnapshot) {
i = m_savingSnapshots.erase(i);
found = true;
} else {
++i;
}
}
if (m_savingSnapshots.empty() && ConfigServerDatabase::getReportSaveTimes())
{
if (m_savingSnapshots.empty())
{
if (found && ConfigServerDatabase::getReportSaveTimes()) {
int saveTime = Clock::timeMs() - m_saveStartTime;
++m_saveCount;
m_totalSaveTime += saveTime;
if (saveTime > m_maxSaveTime)
m_maxSaveTime = saveTime;
DEBUG_REPORT_LOG(true,("Save completed in %i. (Average %i, max %i)\n", saveTime, m_totalSaveTime/m_saveCount, m_maxSaveTime));
LOG("SaveTimes",("Save completed in %i. (Average %i, max %i)", saveTime, m_totalSaveTime/m_saveCount, m_maxSaveTime));
m_lastSaveTime = saveTime;
DEBUG_REPORT_LOG(true,("Save completed in %i. (Average %i, max %i)\n", saveTime, m_totalSaveTime/m_saveCount, m_maxSaveTime));
LOG("SaveTimes",("Save completed in %i. (Average %i, max %i)", saveTime, m_totalSaveTime/m_saveCount, m_maxSaveTime));
m_lastSaveTime = saveTime;
}
if (m_savingSnapshots.empty())
{
// message Central Server that the current save cycle is complete
GenericValueTypeMessage<int> const saveCompleteMessage("DatabaseSaveComplete", ++m_saveCounter);
DatabaseProcess::getInstance().sendToCentralServer(saveCompleteMessage, true);
LOG("Database",("Sending DatabaseSaveComplete network message to Central."));
}
LOG("Database",("Sending DatabaseSaveComplete network message to Central."));
{
// set the last save completion time (for the monitoring program)
time_t theTime = time(0);
m_lastSaveCompletionTime = ctime(&theTime);
}
// TODO: so do we send this for the other snapshot type or not? hrmph
// message Central Server that the current save cycle is complete
GenericValueTypeMessage<int> const saveCompleteMessage("DatabaseSaveComplete", ++m_saveCounter);
DatabaseProcess::getInstance().sendToCentralServer(saveCompleteMessage, true);
LOG("Database",("Sending DatabaseSaveComplete network message to Central."));
}
else
{
auto j=std::remove(m_savingCharacterSnapshots.begin(),m_savingCharacterSnapshots.end(),completedSnapshot);
DEBUG_FATAL(i==m_savingCharacterSnapshots.end(),("Programmer bug: SaveCompleted() called with a snapshot that wasn't in m_savingSnapshots or m_savingCharacterSnapshots."));
if (j != m_savingCharacterSnapshots.end()) {
m_savingCharacterSnapshots.erase(j, m_savingCharacterSnapshots.end());
if (!found) {
for (auto i = m_savingCharacterSnapshots.begin(); i != m_savingCharacterSnapshots.end();) {
if (*i == completedSnapshot) {
i = m_savingCharacterSnapshots.erase(i);
found = true;
} else {
++i;
}
}
if (completedSnapshot != nullptr) {
delete completedSnapshot;
completedSnapshot = nullptr;
}
DEBUG_REPORT_LOG(ConfigServerDatabase::getReportSaveTimes(),("New character save completed\n"));
}
if (found && completedSnapshot != nullptr) {
delete completedSnapshot;
completedSnapshot = nullptr;
}
}
@@ -993,9 +986,10 @@ void Persister::addCharacter(uint32 stationId, const NetworkId &characterObject,
m_pendingCharacters[characterObject]=temp;
//TODO: remove this hack: match up create and end messages because we can't count on having all the data at a frame bounday
auto i=m_newCharacterLock.find(creationGameServer);
UNREF(i);
DEBUG_FATAL(i!=m_newCharacterLock.end(),("Programmer bug: got an addCharacter from server %i before we received EndBaselines from the previous addCharacter. Indicates we're getting network messages out of order.\n",creationGameServer));
if (m_newCharacterLock.find(creationGameServer) != m_newCharacterLock.end()) {
WARNING(true,("Programmer bug: got an addCharacter from server %i before we received EndBaselines from the previous addCharacter. Indicates we're getting network messages out of order.\n",creationGameServer));
}
m_newCharacterLock.insert(creationGameServer);
}
@@ -69,34 +69,10 @@ bool Snapshot::saveToDB(DB::Session *session)
{
NOT_NULL(session);
m_isBeingSaved = true;
CustomStepListType::iterator step;
for (step=m_customStepList.begin(); step !=m_customStepList.end(); ++step)
{
NOT_NULL(*step);
if (!(*step)->beforePersist(session)) {
m_isBeingSaved = false;
return false;
}
if (m_timestamp != 0 && !saveTimestamp(session)) {
return false;
}
if (m_timestamp!=0)
if (! saveTimestamp(session)) {
m_isBeingSaved = false;
return false;
}
for (step=m_customStepList.begin(); step !=m_customStepList.end(); ++step)
{
NOT_NULL(*step);
if (!(*step)->afterPersist(session)){
m_isBeingSaved = false;
return false;
}
}
m_isBeingSaved = false;
return true;
}
// ----------------------------------------------------------------------
@@ -51,6 +51,17 @@ CommandParser ("script", 0, "...", "Script related commands.", 0)
bool ConsoleCommandParserScript::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
CreatureObject * const playerObject = dynamic_cast<CreatureObject *>(ServerWorld::findObjectByNetworkId(userId));
if (!playerObject)
{
WARNING_STRICT_FATAL(true, ("Console command executed on invalid player object %s", userId.getValueString().c_str()));
return false;
}
if (!playerObject->getClient()->isGod()) {
return false; // <3 you seefo
}
NOT_NULL (node);
UNREF(originalCommand);
@@ -4768,7 +4768,6 @@ void GameServer::handleCharacterCreateNameVerification(const VerifyNameResponse
// ----------------------------------------------------------------------
// Set up the PlayerObject
ServerObject *playerServerObject = ServerWorld::createNewObject(ConfigServerGame::getPlayerObjectTemplate(), *newCharacterObject, false);
PlayerObject *play = dynamic_cast<PlayerObject*>(playerServerObject);
if (play)
@@ -4800,6 +4799,8 @@ void GameServer::handleCharacterCreateNameVerification(const VerifyNameResponse
}
}
}
play->persist();
}
else
{
@@ -10,7 +10,6 @@
#define PLATFORM_LINUX
#include <cstdio>
#include <inttypes.h>
// ======================================================================
// basic types that we assume to be around
@@ -21,8 +20,8 @@ typedef unsigned long uint32;
typedef signed char int8;
typedef signed short int16;
typedef signed long int32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef signed long long int int64;
typedef unsigned long long int uint64;
typedef float real;
typedef FILE* FILE_HANDLE;
-11
View File
@@ -402,8 +402,6 @@ UdpManager::~UdpManager()
TerminateOperatingSystem();
delete mAddressHashTable;
mIpConnectionCount.clear();
blacklist.clear();
delete mConnectCodeHashTable;
delete mPriorityQueue;
@@ -563,14 +561,6 @@ void UdpManager::RemoveConnection(UdpConnection *con)
mAddressHashTable->Remove(con, AddressHashValue(con->mIp, con->mPort));
unsigned int addy = con->mIp.GetAddress();
if (mIpConnectionCount[addy] > 1)
{
mIpConnectionCount[addy]--;
}
else
{
mIpConnectionCount.erase(addy);
}
mConnectCodeHashTable->Remove(con, con->mConnectCode);
}
@@ -587,7 +577,6 @@ void UdpManager::AddConnection(UdpConnection *con)
mConnectionListCount++;
mAddressHashTable->Insert(con, AddressHashValue(con->mIp, con->mPort));
mIpConnectionCount[con->mIp.GetAddress()]++;
mConnectCodeHashTable->Insert(con, con->mConnectCode);
}
@@ -94,6 +94,13 @@ bool SwgSnapshot::saveToDB(DB::Session *session) {
session->setAutoCommitMode(false);
for (auto step = m_customStepList.begin(); step !=m_customStepList.end(); ++step)
{
if (!(*step)->beforePersist(session)) {
return false;
}
}
// save all the buffers
if (!(m_objectTableBuffer.save(session))) { return false; }
if (!(m_battlefieldMarkerObjectBuffer.save(session))) { return false; }
@@ -131,6 +138,13 @@ bool SwgSnapshot::saveToDB(DB::Session *session) {
if (!(m_waypointBuffer.save(session))) { return false; }
if (!(m_weaponObjectBuffer.save(session))) { return false; }
for (auto step = m_customStepList.begin(); step !=m_customStepList.end(); ++step)
{
if (!(*step)->afterPersist(session)){
return false;
}
}
// save the parent class
if (!(Snapshot::saveToDB(session))) { return false; }