Make PreparedStatements static for each database.

This commit is contained in:
hondacrx
2023-02-04 20:55:14 -05:00
parent e0e20b6b1c
commit 149fadccab
90 changed files with 922 additions and 923 deletions
+14 -14
View File
@@ -40,7 +40,7 @@ namespace Game.Chat
string emailoutput;
uint accountId = session.GetAccountId();
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_EMAIL_BY_ID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.GET_EMAIL_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
@@ -67,7 +67,7 @@ namespace Game.Chat
uint accountId = handler.GetSession().GetAccountId();
byte[] secret;
{ // get current TOTP secret
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_TOTP_SECRET);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_TOTP_SECRET);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
@@ -102,7 +102,7 @@ namespace Game.Chat
if (TOTP.ValidateToken(secret, token.Value))
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
stmt.AddNull(0);
stmt.AddValue(1, accountId);
DB.Login.Execute(stmt);
@@ -130,7 +130,7 @@ namespace Game.Chat
uint accountId = handler.GetSession().GetAccountId();
{ // check if 2FA already enabled
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_TOTP_SECRET);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_TOTP_SECRET);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
@@ -161,7 +161,7 @@ namespace Game.Chat
if (masterKey.IsValid())
AES.Encrypt(suggestions[accountId], masterKey.GetValue());
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
stmt.AddValue(0, suggestions[accountId]);
stmt.AddValue(1, accountId);
DB.Login.Execute(stmt);
@@ -187,7 +187,7 @@ namespace Game.Chat
return false;
}
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
stmt.AddValue(0, expansion);
stmt.AddValue(1, handler.GetSession().GetAccountId());
DB.Login.Execute(stmt);
@@ -398,14 +398,14 @@ namespace Game.Chat
/*var ipBytes = System.Net.IPAddress.Parse(handler.GetSession().GetRemoteAddress()).GetAddressBytes();
Array.Reverse(ipBytes);
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_LOGON_COUNTRY);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_LOGON_COUNTRY);
stmt.AddValue(0, BitConverter.ToUInt32(ipBytes, 0));
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
{
string country = result.Read<string>(0);
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK_COUNTRY);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK_COUNTRY);
stmt.AddValue(0, country);
stmt.AddValue(1, handler.GetSession().GetAccountId());
DB.Login.Execute(stmt);
@@ -419,7 +419,7 @@ namespace Game.Chat
}
else
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK_COUNTRY);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK_COUNTRY);
stmt.AddValue(0, "00");
stmt.AddValue(1, handler.GetSession().GetAccountId());
DB.Login.Execute(stmt);
@@ -431,7 +431,7 @@ namespace Game.Chat
[Command("ip", CypherStrings.CommandAccLockIpHelp, RBACPermissions.CommandAccountLockIp)]
static bool HandleAccountLockIpCommand(CommandHandler handler, bool state)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_LOCK);
if (state)
{
@@ -566,7 +566,7 @@ namespace Game.Chat
PreparedStatement stmt;
if (secret == "off")
{
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
stmt.AddNull(0);
stmt.AddValue(1, targetAccountId);
DB.Login.Execute(stmt);
@@ -596,7 +596,7 @@ namespace Game.Chat
if (masterKey.IsValid())
AES.Encrypt(decoded, masterKey.GetValue());
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_ACCOUNT_TOTP_SECRET);
stmt.AddValue(0, decoded);
stmt.AddValue(1, targetAccountId);
DB.Login.Execute(stmt);
@@ -639,7 +639,7 @@ namespace Game.Chat
if (expansion > WorldConfig.GetIntValue(WorldCfg.Expansion))
return false;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_EXPANSION);
stmt.AddValue(0, expansion);
stmt.AddValue(1, accountId);
@@ -743,7 +743,7 @@ namespace Game.Chat
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
if (realmID == -1 && !Global.AccountMgr.IsConsoleAccount(playerSecurity))
{
stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_ACCESS_SECLEVEL_TEST);
stmt.AddValue(0, accountId);
stmt.AddValue(1, securityLevel);