@@ -94,11 +94,18 @@ CAccountManager::CAccountManager ( const SString& strDbPathFilename )
94
94
// Add unique index
95
95
m_pDatabaseManager->Execf ( m_hDbConnection, " CREATE UNIQUE INDEX IF NOT EXISTS IDX_USERDATA_USERID_KEY_U on userdata(userid,key)" );
96
96
}
97
-
97
+
98
98
// Ensure old indexes are removed
99
99
m_pDatabaseManager->Execf ( m_hDbConnection, " DROP INDEX IF EXISTS IDX_ACCOUNTS_NAME" );
100
100
m_pDatabaseManager->Execf ( m_hDbConnection, " DROP INDEX IF EXISTS IDX_USERDATA_USERID" );
101
101
m_pDatabaseManager->Execf ( m_hDbConnection, " DROP INDEX IF EXISTS IDX_USERDATA_USERID_KEY" );
102
+
103
+ // Check if httppass has been added yet
104
+ m_pDatabaseManager->QueryWithResultf (m_hDbConnection, &result, " PRAGMA table_info(accounts)" );
105
+ if (ListContains (result->ColNames , " httppass" ) == false )
106
+ {
107
+ m_pDatabaseManager->Execf (m_hDbConnection, " ALTER TABLE accounts ADD COLUMN httppass TEXT" );
108
+ }
102
109
}
103
110
104
111
@@ -129,7 +136,7 @@ bool CAccountManager::Load( void )
129
136
// Create a registry result
130
137
CRegistryResult result;
131
138
// Select all our required information from the accounts database
132
- m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, " SELECT id,name,password,ip,serial from accounts" );
139
+ m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, " SELECT id,name,password,ip,serial,httppass from accounts" );
133
140
134
141
// Initialize all our variables
135
142
m_iAccounts = 0 ;
@@ -145,6 +152,7 @@ bool CAccountManager::Load( void )
145
152
SString strPassword = (const char *)row[2 ].pVal ;
146
153
SString strIP = (const char *)row[3 ].pVal ;
147
154
SString strSerial = (const char *)row[4 ].pVal ;
155
+ SString strHttpPassAppend = (const char *)row[5 ].pVal ;
148
156
149
157
// Check for overlong names and incorrect escapement
150
158
bool bRemoveAccount = false ;
@@ -181,7 +189,7 @@ bool CAccountManager::Load( void )
181
189
}
182
190
183
191
// Create a new account with the specified information
184
- CAccount* pAccount = g_pGame->GetAccountManager ()->AddPlayerAccount ( strName, strPassword, iUserID, strIP, strSerial );
192
+ CAccount* pAccount = g_pGame->GetAccountManager ()->AddPlayerAccount ( strName, strPassword, iUserID, strIP, strSerial, strHttpPassAppend );
185
193
186
194
if ( bChanged )
187
195
pAccount->SetChanged ( bChanged );
@@ -245,27 +253,26 @@ void CAccountManager::Save ( CAccount* pAccount, bool bCheckForErrors )
245
253
{
246
254
SString strName = pAccount->GetName ();
247
255
SString strPassword = pAccount->GetPasswordHash ();
256
+ SString strHttpPassAppend = pAccount->GetHttpPassAppend ();
248
257
SString strIP = pAccount->GetIP ();
249
258
SString strSerial = pAccount->GetSerial ();
250
259
unsigned int iID = pAccount->GetID ();
251
260
252
261
m_pDatabaseManager->Execf ( m_hDbConnection, " INSERT OR IGNORE INTO accounts (id, name, ip, serial, password) VALUES(?,?,?,?,?)" , SQLITE_INTEGER, iID, SQLITE_TEXT, strName.c_str (), SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str () );
253
262
254
- if ( bCheckForErrors )
263
+ SString strQuery;
264
+ strQuery += m_pDatabaseManager->PrepareStringf (m_hDbConnection, " UPDATE accounts SET ip=?" , SQLITE_TEXT, *strIP);
265
+ if (!strSerial.empty ())
266
+ strQuery += m_pDatabaseManager->PrepareStringf (m_hDbConnection, " ,serial=?" , SQLITE_TEXT, *strSerial);
267
+ strQuery += m_pDatabaseManager->PrepareStringf (m_hDbConnection, " ,password=?, httppass=? WHERE name=?" , SQLITE_TEXT, *strPassword, SQLITE_TEXT, *strHttpPassAppend, SQLITE_TEXT, *strName);
268
+
269
+ if (bCheckForErrors)
255
270
{
256
- if ( strSerial != " " )
257
- m_pDatabaseManager->QueryWithCallbackf ( m_hDbConnection, StaticDbCallback, this , " UPDATE accounts SET ip=?, serial=?, password=? WHERE name=?" , SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () );
258
- else
259
- // If we don't have a serial then IP and password will suffice
260
- m_pDatabaseManager->QueryWithCallbackf ( m_hDbConnection, StaticDbCallback, this , " UPDATE accounts SET ip=?, password=? WHERE name=?" , SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () );
271
+ m_pDatabaseManager->QueryWithCallbackf (m_hDbConnection, StaticDbCallback, this , strQuery);
261
272
}
262
273
else
263
274
{
264
- if ( strSerial != " " )
265
- m_pDatabaseManager->Execf ( m_hDbConnection, " UPDATE accounts SET ip=?, serial=?, password=? WHERE name=?" , SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () );
266
- else
267
- // If we don't have a serial then IP and password will suffice
268
- m_pDatabaseManager->Execf ( m_hDbConnection, " UPDATE accounts SET ip=?, password=? WHERE name=?" , SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () );
275
+ m_pDatabaseManager->Execf (m_hDbConnection, strQuery);
269
276
}
270
277
271
278
SaveAccountSerialUsage ( pAccount );
@@ -872,9 +879,9 @@ CAccount* CAccountManager::AddConsoleAccount( const SString& strName )
872
879
return pAccount;
873
880
}
874
881
875
- CAccount* CAccountManager::AddPlayerAccount ( const SString& strName, const SString& strPassword, int iUserID, const SString& strIP, const SString& strSerial )
882
+ CAccount* CAccountManager::AddPlayerAccount ( const SString& strName, const SString& strPassword, int iUserID, const SString& strIP, const SString& strSerial, const SString& strHttpPassAppend )
876
883
{
877
- CAccount* pAccount = new CAccount ( this , EAccountType::Player, strName, strPassword, iUserID, strIP, strSerial );
884
+ CAccount* pAccount = new CAccount ( this , EAccountType::Player, strName, strPassword, iUserID, strIP, strSerial, strHttpPassAppend );
878
885
return pAccount;
879
886
}
880
887
0 commit comments