Merge branch 'testing'

This commit is contained in:
DarthArgus
2016-12-29 15:09:23 +00:00
5 changed files with 64 additions and 75 deletions
@@ -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;
}
// ----------------------------------------------------------------------
@@ -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
{
@@ -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; }