Core/DB: Some DB improvements

This commit is contained in:
hondacrx
2018-05-22 11:05:16 -04:00
parent 0be2dc08e2
commit dbd62e5c6f
23 changed files with 360 additions and 294 deletions
+2 -13
View File
@@ -27,7 +27,7 @@ using System.Text;
namespace Game
{
public sealed class AccountManager : Singleton<AccountManager>
{
{
const int MaxAccountLength = 16;
const int MaxEmailLength = 64;
@@ -59,7 +59,7 @@ namespace Game
stmt.AddValue(4, null);
stmt.AddValue(5, null);
}
DB.Login.Execute(stmt); // Enforce saving, otherwise AddGroup can fail
DB.Login.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail
stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_REALM_CHARACTERS_INIT);
DB.Login.Execute(stmt);
@@ -73,7 +73,6 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (result.IsEmpty())
return AccountOpResult.NameNotExist;
@@ -81,7 +80,6 @@ namespace Game
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARS_BY_ACCOUNT_ID);
stmt.AddValue(0, accountId);
result = DB.Characters.Query(stmt);
if (!result.IsEmpty())
{
do
@@ -147,7 +145,6 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (result.IsEmpty())
return AccountOpResult.NameNotExist;
@@ -231,7 +228,6 @@ namespace Game
PreparedStatement stmt = DB.Login.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;
}
@@ -240,7 +236,6 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_ACCOUNT_ACCESS_GMLEVEL);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
return !result.IsEmpty() ? (AccountTypes)result.Read<byte>(0) : AccountTypes.Player;
}
@@ -250,7 +245,6 @@ namespace Game
stmt.AddValue(0, accountId);
stmt.AddValue(1, realmId);
SQLResult result = DB.Login.Query(stmt);
return !result.IsEmpty() ? (AccountTypes)result.Read<uint>(0) : AccountTypes.Player;
}
@@ -260,7 +254,6 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_USERNAME_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
{
name = result.Read<string>(0);
@@ -276,7 +269,6 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_EMAIL_BY_ID);
stmt.AddValue(0, accountId);
SQLResult result = DB.Login.Query(stmt);
if (!result.IsEmpty())
{
email = result.Read<string>(0);
@@ -297,7 +289,6 @@ namespace Game
stmt.AddValue(0, accountId);
stmt.AddValue(1, CalculateShaPassHash(username, password));
SQLResult result = DB.Login.Query(stmt);
return result.IsEmpty() ? false : true;
}
@@ -321,7 +312,6 @@ namespace Game
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_SUM_CHARS);
stmt.AddValue(0, accountId);
SQLResult result = DB.Characters.Query(stmt);
return result.IsEmpty() ? 0 : (uint)result.Read<ulong>(0);
}
@@ -336,7 +326,6 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_ACCOUNT_BANNED_BY_USERNAME);
stmt.AddValue(0, name);
SQLResult result = DB.Login.Query(stmt);
return !result.IsEmpty();
}
+2 -2
View File
@@ -43,7 +43,7 @@ namespace Game
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_BNET_ACCOUNT);
stmt.AddValue(0, email);
stmt.AddValue(1, CalculateShaPassHash(email, password));
DB.Login.Execute(stmt);
DB.Login.DirectExecute(stmt);
uint newAccountId = GetId(email);
Contract.Assert(newAccountId != 0);
@@ -173,7 +173,7 @@ namespace Game
return 0;
}
string CalculateShaPassHash(string name, string password)
public string CalculateShaPassHash(string name, string password)
{
SHA256 sha256 = SHA256.Create();
var i = sha256.ComputeHash(Encoding.UTF8.GetBytes(name));