@@ -107,7 +107,7 @@ CAccountManager::CAccountManager ( const SString& strDbPathFilename )
107
107
CAccountManager::~CAccountManager ( void )
108
108
{
109
109
// Save everything
110
- Save ();
110
+ Save (true );
111
111
// Delete our save file
112
112
m_pDatabaseManager->Disconnect ( m_hDbConnection );
113
113
RemoveAll ();
@@ -296,19 +296,21 @@ void CAccountManager::Save ( CAccount* pAccount, bool bCheckForErrors )
296
296
}
297
297
298
298
299
- bool CAccountManager::Save ( void )
299
+ void CAccountManager::Save ( bool bForce )
300
300
{
301
- // Attempted save now
302
- m_bChangedSinceSaved = false ;
303
-
304
- for ( auto pAccount : m_List )
301
+ if (m_bChangedSinceSaved || bForce)
305
302
{
306
- if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
303
+ // Attempted save now
304
+ m_bChangedSinceSaved = false ;
305
+
306
+ for ( auto pAccount : m_List )
307
307
{
308
- Save ( pAccount );
308
+ if ( pAccount->IsRegistered () && pAccount->HasChanged () && !pAccount->IsConsoleAccount () )
309
+ {
310
+ Save ( pAccount );
311
+ }
309
312
}
310
313
}
311
- return true ;
312
314
}
313
315
314
316
@@ -869,6 +871,7 @@ bool CAccountManager::GetAllAccountData( CAccount* pAccount, lua_State* pLua )
869
871
870
872
void CAccountManager::GetAccountsBySerial ( const SString& strSerial, std::vector<CAccount*>& outAccounts )
871
873
{
874
+ Save ();
872
875
CRegistryResult result;
873
876
m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, " SELECT name FROM accounts WHERE serial = ?" , SQLITE_TEXT, strSerial.c_str () );
874
877
@@ -877,12 +880,14 @@ void CAccountManager::GetAccountsBySerial ( const SString& strSerial, std::vecto
877
880
const CRegistryResultRow& row = *iter;
878
881
879
882
CAccount* pAccount = Get ( (const char *)row[0 ].pVal );
880
- outAccounts.push_back ( pAccount );
883
+ if (pAccount)
884
+ outAccounts.push_back ( pAccount );
881
885
}
882
886
}
883
887
884
888
void CAccountManager::GetAccountsByIP ( const SString& strIP, std::vector<CAccount*>& outAccounts )
885
889
{
890
+ Save ();
886
891
CRegistryResult result;
887
892
m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, " SELECT name FROM accounts WHERE added_ip = ?" , SQLITE_TEXT, strIP.c_str () );
888
893
@@ -891,12 +896,14 @@ void CAccountManager::GetAccountsByIP( const SString& strIP, std::vector<CAccoun
891
896
const CRegistryResultRow& row = *iter;
892
897
893
898
CAccount* pAccount = Get ( (const char *) row[0 ].pVal );
894
- outAccounts.push_back ( pAccount );
899
+ if (pAccount)
900
+ outAccounts.push_back ( pAccount );
895
901
}
896
902
}
897
903
898
904
void CAccountManager::GetAccountsByData ( const SString& dataName, const SString& value, std::vector<CAccount*>& outAccounts )
899
905
{
906
+ Save ();
900
907
CRegistryResult result;
901
908
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 () );
902
909
@@ -905,7 +912,8 @@ void CAccountManager::GetAccountsByData ( const SString& dataName, const SString
905
912
const CRegistryResultRow& row = *iter;
906
913
907
914
CAccount* pAccount = Get ( (const char *) row[0 ].pVal );
908
- outAccounts.push_back ( pAccount );
915
+ if (pAccount)
916
+ outAccounts.push_back ( pAccount );
909
917
}
910
918
}
911
919
0 commit comments