Skip to content

Commit a009ddd

Browse files
committed
Possible 'fix' for internal.db access errors
1 parent 31b20b4 commit a009ddd

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

Server/mods/deathmatch/logic/CAccountManager.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@ CAccountManager::CAccountManager ( const SString& strDbPathFilename )
2222
m_bChangedSinceSaved = false;
2323
m_iAccounts = 1;
2424
m_pDatabaseManager = g_pGame->GetDatabaseManager ();
25+
m_strDbPathFilename = strDbPathFilename;
26+
m_hDbConnection = INVALID_DB_HANDLE;
2527

2628
//Load internal.db
27-
SString strOptions;
28-
#ifdef WITH_ACCOUNT_QUERY_LOGGING
29-
g_pGame->GetDatabaseManager ()->SetLogLevel ( EJobLogLevel::ALL, g_pGame->GetConfig ()->GetDbLogFilename () );
30-
SetOption < CDbOptionsMap > ( strOptions, "log", 1 );
31-
SetOption < CDbOptionsMap > ( strOptions, "tag", "accounts" );
32-
#endif
33-
SetOption < CDbOptionsMap > ( strOptions, "queue", DB_SQLITE_QUEUE_NAME_INTERNAL );
34-
m_hDbConnection = m_pDatabaseManager->Connect ( "sqlite", PathConform ( strDbPathFilename ), "", "", strOptions );
29+
ReconnectToDatabase();
3530

3631
// Check if new installation
3732
CRegistryResult result;
@@ -119,6 +114,25 @@ CAccountManager::~CAccountManager ( void )
119114
}
120115

121116

117+
void CAccountManager::ReconnectToDatabase(void)
118+
{
119+
if (m_hDbConnection != INVALID_DB_HANDLE)
120+
{
121+
m_pDatabaseManager->Disconnect(m_hDbConnection);
122+
}
123+
124+
//Load internal.db
125+
SString strOptions;
126+
#ifdef WITH_ACCOUNT_QUERY_LOGGING
127+
g_pGame->GetDatabaseManager ()->SetLogLevel ( EJobLogLevel::ALL, g_pGame->GetConfig ()->GetDbLogFilename () );
128+
SetOption < CDbOptionsMap > ( strOptions, "log", 1 );
129+
SetOption < CDbOptionsMap > ( strOptions, "tag", "accounts" );
130+
#endif
131+
SetOption < CDbOptionsMap > ( strOptions, "queue", DB_SQLITE_QUEUE_NAME_INTERNAL );
132+
m_hDbConnection = m_pDatabaseManager->Connect ( "sqlite", PathConform ( m_strDbPathFilename ), "", "", strOptions );
133+
}
134+
135+
122136
void CAccountManager::DoPulse ( void )
123137
{
124138
// Save it only once in a while whenever something has changed
@@ -926,8 +940,16 @@ void CAccountManager::DbCallback ( CDbJobData* pJobData )
926940
{
927941
if ( m_pDatabaseManager->QueryPoll ( pJobData, 0 ) )
928942
{
929-
if ( pJobData->result.status == EJobResult::FAIL )
943+
if ( pJobData->result.status == EJobResult::FAIL )
944+
{
930945
CLogger::LogPrintf ( "ERROR: While updating account with '%s': %s.\n", *pJobData->command.strData, *pJobData->result.strReason );
946+
if (pJobData->result.strReason.ContainsI("missing database"))
947+
{
948+
// Try reconnection
949+
CLogger::LogPrintf("INFO: Reconnecting to accounts database\n");
950+
ReconnectToDatabase();
951+
}
952+
}
931953
}
932954
else
933955
{

Server/mods/deathmatch/logic/CAccountManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class CAccountManager
164164
void ChangingName ( CAccount* pAccount, const SString& strOldName, const SString& strNewName );
165165
void LoadAccountSerialUsage ( CAccount* pAccount );
166166
void SaveAccountSerialUsage ( CAccount* pAccount );
167+
void ReconnectToDatabase (void);
167168

168169
public:
169170
void RemoveAll ( void );
@@ -185,6 +186,7 @@ class CAccountManager
185186
SDbConnectionId m_hDbConnection;
186187
CDatabaseManager* m_pDatabaseManager;
187188
int m_iAccounts;
189+
SString m_strDbPathFilename;
188190
};
189191

190192

0 commit comments

Comments
 (0)