@@ -107,7 +107,7 @@ CAccountManager::CAccountManager ( const SString& strDbPathFilename )
107107CAccountManager::~CAccountManager ( void )
108108{
109109 // Save everything
110- Save ();
110+ Save (true );
111111 // Delete our save file
112112 m_pDatabaseManager->Disconnect ( m_hDbConnection );
113113 RemoveAll ();
@@ -296,19 +296,21 @@ void CAccountManager::Save ( CAccount* pAccount, bool bCheckForErrors )
296296}
297297
298298
299- bool CAccountManager::Save ( void )
299+ void CAccountManager::Save ( bool bForce )
300300{
301- // Attempted save now
302- m_bChangedSinceSaved = false ;
303-
304- for ( auto pAccount : m_List )
301+ if (m_bChangedSinceSaved || bForce)
305302 {
306- if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
303+ // Attempted save now
304+ m_bChangedSinceSaved = false ;
305+
306+ for ( auto pAccount : m_List )
307307 {
308- Save ( pAccount );
308+ if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
309+ {
310+ Save ( pAccount );
311+ }
309312 }
310313 }
311- return true ;
312314}
313315
314316
@@ -869,6 +871,7 @@ bool CAccountManager::GetAllAccountData( CAccount* pAccount, lua_State* pLua )
869871
870872void CAccountManager::GetAccountsBySerial ( const SString& strSerial, std::vector<CAccount*>& outAccounts )
871873{
874+ Save ();
872875 CRegistryResult result;
873876 m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, " SELECT name FROM accounts WHERE serial = ?" , SQLITE_TEXT, strSerial.c_str () );
874877
@@ -877,12 +880,14 @@ void CAccountManager::GetAccountsBySerial ( const SString& strSerial, std::vecto
877880 const CRegistryResultRow& row = *iter;
878881
879882 CAccount* pAccount = Get ( (const char *)row[0 ].pVal );
880- outAccounts.push_back ( pAccount );
883+ if (pAccount)
884+ outAccounts.push_back ( pAccount );
881885 }
882886}
883887
884888void CAccountManager::GetAccountsByIP ( const SString& strIP, std::vector<CAccount*>& outAccounts )
885889{
890+ Save ();
886891 CRegistryResult result;
887892 m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, " SELECT name FROM accounts WHERE added_ip = ?" , SQLITE_TEXT, strIP.c_str () );
888893
@@ -891,12 +896,14 @@ void CAccountManager::GetAccountsByIP( const SString& strIP, std::vector<CAccoun
891896 const CRegistryResultRow& row = *iter;
892897
893898 CAccount* pAccount = Get ( (const char *) row[0 ].pVal );
894- outAccounts.push_back ( pAccount );
899+ if (pAccount)
900+ outAccounts.push_back ( pAccount );
895901 }
896902}
897903
898904void CAccountManager::GetAccountsByData ( const SString& dataName, const SString& value, std::vector<CAccount*>& outAccounts )
899905{
906+ Save ();
900907 CRegistryResult result;
901908 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 () );
902909
@@ -905,7 +912,8 @@ void CAccountManager::GetAccountsByData ( const SString& dataName, const SString
905912 const CRegistryResultRow& row = *iter;
906913
907914 CAccount* pAccount = Get ( (const char *) row[0 ].pVal );
908- outAccounts.push_back ( pAccount );
915+ if (pAccount)
916+ outAccounts.push_back ( pAccount );
909917 }
910918}
911919
0 commit comments