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
+29 -29
View File
@@ -36,7 +36,7 @@ namespace Game
(byte[] salt, byte[] verifier) = SRP6.MakeRegistrationData(username, password);
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_ACCOUNT);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.INS_ACCOUNT);
stmt.AddValue(0, username);
stmt.AddValue(1, salt);
stmt.AddValue(2, verifier);
@@ -54,7 +54,7 @@ namespace Game
}
DB.Login.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail
stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_REALM_CHARACTERS_INIT);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.INS_REALM_CHARACTERS_INIT);
DB.Login.Execute(stmt);
return AccountOpResult.Ok;
@@ -63,14 +63,14 @@ namespace Game
public AccountOpResult DeleteAccount(uint accountId)
{
// Check if accounts exists
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_ID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (result.IsEmpty())
return AccountOpResult.NameNotExist;
// Obtain accounts characters
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARS_BY_ACCOUNT_ID);
stmt = CharacterDatabase.GetPreparedStatement(CharStatements.SEL_CHARS_BY_ACCOUNT_ID);
stmt.AddValue(0, accountId);
result = DB.Characters.Query(stmt);
if (!result.IsEmpty())
@@ -93,37 +93,37 @@ namespace Game
}
// table realm specific but common for all characters of account for realm
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_TUTORIALS);
stmt = CharacterDatabase.GetPreparedStatement(CharStatements.DEL_TUTORIALS);
stmt.AddValue(0, accountId);
DB.Characters.Execute(stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_ACCOUNT_DATA);
stmt = CharacterDatabase.GetPreparedStatement(CharStatements.DEL_ACCOUNT_DATA);
stmt.AddValue(0, accountId);
DB.Characters.Execute(stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHARACTER_BAN);
stmt = CharacterDatabase.GetPreparedStatement(CharStatements.DEL_CHARACTER_BAN);
stmt.AddValue(0, accountId);
DB.Characters.Execute(stmt);
SQLTransaction trans = new();
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_ACCOUNT);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_ACCOUNT);
stmt.AddValue(0, accountId);
trans.Append(stmt);
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_ACCESS);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_ACCESS);
stmt.AddValue(0, accountId);
trans.Append(stmt);
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_REALM_CHARACTERS);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_REALM_CHARACTERS);
stmt.AddValue(0, accountId);
trans.Append(stmt);
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_BANNED);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_BANNED);
stmt.AddValue(0, accountId);
trans.Append(stmt);
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_MUTED);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_MUTED);
stmt.AddValue(0, accountId);
trans.Append(stmt);
@@ -135,7 +135,7 @@ namespace Game
public AccountOpResult ChangeUsername(uint accountId, string newUsername, string newPassword)
{
// Check if accounts exists
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_ID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (result.IsEmpty())
@@ -147,13 +147,13 @@ namespace Game
if (newPassword.Length > MaxAccountLength)
return AccountOpResult.PassTooLong;
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_USERNAME);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_USERNAME);
stmt.AddValue(0, newUsername);
stmt.AddValue(1, accountId);
DB.Login.Execute(stmt);
(byte[] salt, byte[] verifier) = SRP6.MakeRegistrationData(newUsername, newPassword);
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_LOGON);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_LOGON);
stmt.AddValue(0, salt);
stmt.AddValue(1, verifier);
stmt.AddValue(2, accountId);
@@ -174,7 +174,7 @@ namespace Game
(byte[] salt, byte[] verifier) = SRP6.MakeRegistrationData(username, newPassword);
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_LOGON);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_LOGON);
stmt.AddValue(0, salt);
stmt.AddValue(1, verifier);
stmt.AddValue(2, accountId);
@@ -191,7 +191,7 @@ namespace Game
if (newEmail.Length > MaxEmailLength)
return AccountOpResult.EmailTooLong;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_EMAIL);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_EMAIL);
stmt.AddValue(0, newEmail);
stmt.AddValue(1, accountId);
DB.Login.Execute(stmt);
@@ -207,7 +207,7 @@ namespace Game
if (newEmail.Length > MaxEmailLength)
return AccountOpResult.EmailTooLong;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_REG_EMAIL);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_REG_EMAIL);
stmt.AddValue(0, newEmail);
stmt.AddValue(1, accountId);
DB.Login.Execute(stmt);
@@ -217,7 +217,7 @@ namespace Game
public uint GetId(string username)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_ACCOUNT_ID_BY_USERNAME);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.GET_ACCOUNT_ID_BY_USERNAME);
stmt.AddValue(0, username);
SQLResult result = DB.Login.Query(stmt);
return !result.IsEmpty() ? result.Read<uint>(0) : 0;
@@ -225,7 +225,7 @@ namespace Game
public AccountTypes GetSecurity(uint accountId, int realmId)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
stmt.AddValue(0, accountId);
stmt.AddValue(1, realmId);
SQLResult result = DB.Login.Query(stmt);
@@ -234,7 +234,7 @@ namespace Game
public QueryCallback GetSecurityAsync(uint accountId, int realmId, Action<uint> callback)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
stmt.AddValue(0, accountId);
stmt.AddValue(1, realmId);
return DB.Login.AsyncQuery(stmt).WithCallback(result =>
@@ -246,7 +246,7 @@ namespace Game
public bool GetName(uint accountId, out string name)
{
name = "";
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_USERNAME_BY_ID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.GET_USERNAME_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
@@ -261,7 +261,7 @@ namespace Game
public bool GetEmail(uint accountId, out string email)
{
email = "";
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);
if (!result.IsEmpty())
@@ -280,7 +280,7 @@ namespace Game
if (!GetName(accountId, out username))
return false;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_CHECK_PASSWORD);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_CHECK_PASSWORD);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
@@ -311,7 +311,7 @@ namespace Game
public uint GetCharactersCount(uint accountId)
{
// check character count
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_SUM_CHARS);
PreparedStatement stmt = CharacterDatabase.GetPreparedStatement(CharStatements.SEL_SUM_CHARS);
stmt.AddValue(0, accountId);
SQLResult result = DB.Characters.Query(stmt);
return result.IsEmpty() ? 0 : (uint)result.Read<ulong>(0);
@@ -319,7 +319,7 @@ namespace Game
public bool IsBannedAccount(string name)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BANNED_BY_USERNAME);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BANNED_BY_USERNAME);
stmt.AddValue(0, name);
SQLResult result = DB.Login.Query(stmt);
return !result.IsEmpty();
@@ -431,13 +431,13 @@ namespace Game
// Delete old security level from DB
if (realmId == -1)
{
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_ACCESS);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_ACCESS);
stmt.AddValue(0, accountId);
trans.Append(stmt);
}
else
{
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_ACCESS_BY_REALM);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_ACCOUNT_ACCESS_BY_REALM);
stmt.AddValue(0, accountId);
stmt.AddValue(1, realmId);
trans.Append(stmt);
@@ -446,7 +446,7 @@ namespace Game
// Add new security level
if (securityLevel != 0)
{
stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_ACCOUNT_ACCESS);
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.INS_ACCOUNT_ACCESS);
stmt.AddValue(0, accountId);
stmt.AddValue(1, securityLevel);
stmt.AddValue(2, realmId);
+10 -10
View File
@@ -25,7 +25,7 @@ namespace Game
if (GetId(email) != 0)
return AccountOpResult.NameAlreadyExist;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_BNET_ACCOUNT);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.INS_BNET_ACCOUNT);
stmt.AddValue(0, email);
stmt.AddValue(1, CalculateShaPassHash(email.ToUpper(), password.ToUpper()));
DB.Login.DirectExecute(stmt);
@@ -51,7 +51,7 @@ namespace Game
if (newPassword.Length > 16)
return AccountOpResult.PassTooLong;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_PASSWORD);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_BNET_PASSWORD);
stmt.AddValue(0, CalculateShaPassHash(username, newPassword));
stmt.AddValue(1, accountId);
DB.Login.Execute(stmt);
@@ -65,7 +65,7 @@ namespace Game
if (!GetName(accountId, out username))
return false;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_CHECK_PASSWORD);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_CHECK_PASSWORD);
stmt.AddValue(0, accountId);
stmt.AddValue(1, CalculateShaPassHash(username, password));
@@ -85,7 +85,7 @@ namespace Game
if (GetIdByGameAccount(gameAccountId) != 0)
return AccountOpResult.BadLink;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LINK);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LINK);
stmt.AddValue(0, bnetAccountId);
stmt.AddValue(1, GetMaxIndex(bnetAccountId) + 1);
stmt.AddValue(2, gameAccountId);
@@ -102,7 +102,7 @@ namespace Game
if (GetIdByGameAccount(gameAccountId) == 0)
return AccountOpResult.BadLink;
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LINK);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_BNET_GAME_ACCOUNT_LINK);
stmt.AddNull(0);
stmt.AddNull(1);
stmt.AddValue(2, gameAccountId);
@@ -112,7 +112,7 @@ namespace Game
public uint GetId(string username)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_ID_BY_EMAIL);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_ID_BY_EMAIL);
stmt.AddValue(0, username);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
@@ -124,7 +124,7 @@ namespace Game
public bool GetName(uint accountId, out string name)
{
name = "";
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_EMAIL_BY_ID);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_EMAIL_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
@@ -138,7 +138,7 @@ namespace Game
public uint GetIdByGameAccount(uint gameAccountId)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_ID_BY_GAME_ACCOUNT);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_ID_BY_GAME_ACCOUNT);
stmt.AddValue(0, gameAccountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
@@ -149,14 +149,14 @@ namespace Game
public QueryCallback GetIdByGameAccountAsync(uint gameAccountId)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_ID_BY_GAME_ACCOUNT);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_ACCOUNT_ID_BY_GAME_ACCOUNT);
stmt.AddValue(0, gameAccountId);
return DB.Login.AsyncQuery(stmt);
}
public byte GetMaxIndex(uint accountId)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_BNET_MAX_ACCOUNT_INDEX);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_BNET_MAX_ACCOUNT_INDEX);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
+4 -4
View File
@@ -116,7 +116,7 @@ namespace Game.Accounts
void SavePermission(uint permission, bool granted, int realmId)
{
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_RBAC_ACCOUNT_PERMISSION);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.INS_RBAC_ACCOUNT_PERMISSION);
stmt.AddValue(0, GetId());
stmt.AddValue(1, permission);
stmt.AddValue(2, granted);
@@ -142,7 +142,7 @@ namespace Game.Accounts
{
Log.outDebug(LogFilter.Rbac, "RBACData.RevokePermission [Id: {0} Name: {1}] (Permission {2}, RealmId {3}). Ok and DB updated",
GetId(), GetName(), permissionId, realmId);
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_RBAC_ACCOUNT_PERMISSION);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.DEL_RBAC_ACCOUNT_PERMISSION);
stmt.AddValue(0, GetId());
stmt.AddValue(1, permissionId);
stmt.AddValue(2, realmId);
@@ -163,7 +163,7 @@ namespace Game.Accounts
Log.outDebug(LogFilter.Rbac, "RBACData.LoadFromDB [Id: {0} Name: {1}]: Loading permissions", GetId(), GetName());
// Load account permissions (granted and denied) that affect current realm
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_RBAC_ACCOUNT_PERMISSIONS);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_RBAC_ACCOUNT_PERMISSIONS);
stmt.AddValue(0, GetId());
stmt.AddValue(1, GetRealmId());
@@ -176,7 +176,7 @@ namespace Game.Accounts
Log.outDebug(LogFilter.Rbac, "RBACData.LoadFromDB [Id: {0} Name: {1}]: Loading permissions", GetId(), GetName());
// Load account permissions (granted and denied) that affect current realm
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_RBAC_ACCOUNT_PERMISSIONS);
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_RBAC_ACCOUNT_PERMISSIONS);
stmt.AddValue(0, GetId());
stmt.AddValue(1, GetRealmId());