Skip to content

Commit

Permalink
Account Manager crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Nov 20, 2017
1 parent 12a0c11 commit eb8e077
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions Server/mods/deathmatch/logic/CAccountManager.cpp
Expand Up @@ -107,7 +107,7 @@ CAccountManager::CAccountManager ( const SString& strDbPathFilename )
CAccountManager::~CAccountManager ( void )
{
//Save everything
Save ();
Save (true);
//Delete our save file
m_pDatabaseManager->Disconnect ( m_hDbConnection );
RemoveAll ();
Expand Down Expand Up @@ -296,19 +296,21 @@ void CAccountManager::Save ( CAccount* pAccount, bool bCheckForErrors )
}


bool CAccountManager::Save ( void )
void CAccountManager::Save ( bool bForce )
{
// Attempted save now
m_bChangedSinceSaved = false;

for ( auto pAccount : m_List )
if (m_bChangedSinceSaved || bForce)
{
if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
// Attempted save now
m_bChangedSinceSaved = false;

for ( auto pAccount : m_List )
{
Save ( pAccount );
if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
{
Save ( pAccount );
}
}
}
return true;
}


Expand Down Expand Up @@ -869,6 +871,7 @@ bool CAccountManager::GetAllAccountData( CAccount* pAccount, lua_State* pLua )

void CAccountManager::GetAccountsBySerial ( const SString& strSerial, std::vector<CAccount*>& outAccounts )
{
Save();
CRegistryResult result;
m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "SELECT name FROM accounts WHERE serial = ?", SQLITE_TEXT, strSerial.c_str () );

Expand All @@ -877,12 +880,14 @@ void CAccountManager::GetAccountsBySerial ( const SString& strSerial, std::vecto
const CRegistryResultRow& row = *iter;

CAccount* pAccount = Get ( (const char*)row[0].pVal );
outAccounts.push_back ( pAccount );
if (pAccount)
outAccounts.push_back ( pAccount );
}
}

void CAccountManager::GetAccountsByIP( const SString& strIP, std::vector<CAccount*>& outAccounts )
{
Save();
CRegistryResult result;
m_pDatabaseManager->QueryWithResultf( m_hDbConnection, &result, "SELECT name FROM accounts WHERE added_ip = ?", SQLITE_TEXT, strIP.c_str() );

Expand All @@ -891,12 +896,14 @@ void CAccountManager::GetAccountsByIP( const SString& strIP, std::vector<CAccoun
const CRegistryResultRow& row = *iter;

CAccount* pAccount = Get( (const char*) row[0].pVal );
outAccounts.push_back( pAccount );
if (pAccount)
outAccounts.push_back( pAccount );
}
}

void CAccountManager::GetAccountsByData ( const SString& dataName, const SString& value, std::vector<CAccount*>& outAccounts )
{
Save();
CRegistryResult result;
m_pDatabaseManager->QueryWithResultf( m_hDbConnection, &result, "SELECT acc.name FROM accounts acc, userdata dat WHERE dat.key = ? AND dat.value = ? AND dat.userid = acc.id", SQLITE_TEXT, dataName.c_str(), SQLITE_TEXT, value.c_str() );

Expand All @@ -905,7 +912,8 @@ void CAccountManager::GetAccountsByData ( const SString& dataName, const SString
const CRegistryResultRow& row = *iter;

CAccount* pAccount = Get( (const char*) row[0].pVal );
outAccounts.push_back( pAccount );
if (pAccount)
outAccounts.push_back( pAccount );
}
}

Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CAccountManager.h
Expand Up @@ -128,7 +128,7 @@ class CAccountManager
void DoPulse ( void );

bool Load ( void );
bool Save ( void );
void Save ( bool bForce = false );
void Save ( CAccount* pParent, bool bCheckForErrors = true );

bool SaveSettings ( void );
Expand Down

0 comments on commit eb8e077

Please sign in to comment.