Core/BnetServer: Bnetserver cleanup
Port From (https://github.com/TrinityCore/TrinityCore/commit/e9392ad28767626e519c463e2110184d71ba8426)
This commit is contained in:
@@ -23,6 +23,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Framework.Cryptography;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
@@ -44,20 +45,23 @@ namespace Game
|
||||
if (GetId(username) != 0)
|
||||
return AccountOpResult.NameAlreadyExist; // username does already exist
|
||||
|
||||
(byte[] salt, byte[] verifier) registrationData = SRP6.MakeRegistrationData(username, password);
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_ACCOUNT);
|
||||
stmt.AddValue(0, username);
|
||||
stmt.AddValue(1, CalculateShaPassHash(username, password));
|
||||
stmt.AddValue(1, registrationData.Item1);
|
||||
stmt.AddValue(2, registrationData.Item2);
|
||||
stmt.AddValue(2, email);
|
||||
stmt.AddValue(3, email);
|
||||
stmt.AddValue(4, email);
|
||||
if (bnetAccountId != 0 && bnetIndex != 0)
|
||||
{
|
||||
stmt.AddValue(4, bnetAccountId);
|
||||
stmt.AddValue(5, bnetIndex);
|
||||
stmt.AddValue(5, bnetAccountId);
|
||||
stmt.AddValue(6, bnetIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt.AddValue(4, null);
|
||||
stmt.AddValue(5, null);
|
||||
stmt.AddValue(6, null);
|
||||
}
|
||||
DB.Login.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail
|
||||
|
||||
@@ -156,10 +160,23 @@ namespace Game
|
||||
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_USERNAME);
|
||||
stmt.AddValue(0, newUsername);
|
||||
stmt.AddValue(1, CalculateShaPassHash(newUsername, newPassword));
|
||||
stmt.AddValue(1, accountId);
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
(byte[] salt, byte[] verifier) registrationData = SRP6.MakeRegistrationData(newUsername, newPassword);
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_LOGON);
|
||||
stmt.AddValue(0, registrationData.salt);
|
||||
stmt.AddValue(1, registrationData.verifier);
|
||||
stmt.AddValue(2, accountId);
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_LOGON_LEGACY);
|
||||
stmt.AddValue(0, CalculateShaPassHash(newUsername, newPassword));
|
||||
stmt.AddValue(1, accountId);
|
||||
DB.Login.Execute(stmt);
|
||||
}
|
||||
|
||||
return AccountOpResult.Ok;
|
||||
}
|
||||
|
||||
@@ -173,16 +190,20 @@ namespace Game
|
||||
if (newPassword.Length > MaxAccountLength)
|
||||
return AccountOpResult.PassTooLong;
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_PASSWORD);
|
||||
stmt.AddValue(0, CalculateShaPassHash(username, newPassword));
|
||||
stmt.AddValue(1, accountId);
|
||||
(byte[] salt, byte[] verifier) registrationData = SRP6.MakeRegistrationData(username, newPassword);
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_LOGON);
|
||||
stmt.AddValue(0, registrationData.salt);
|
||||
stmt.AddValue(1, registrationData.verifier);
|
||||
stmt.AddValue(2, accountId);
|
||||
DB.Login.Execute(stmt);
|
||||
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_VS);
|
||||
stmt.AddValue(0, "");
|
||||
stmt.AddValue(1, "");
|
||||
stmt.AddValue(2, username);
|
||||
DB.Login.Execute(stmt);
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.UPD_LOGON_LEGACY);
|
||||
stmt.AddValue(0, CalculateShaPassHash(username, newPassword));
|
||||
stmt.AddValue(1, accountId);
|
||||
DB.Login.Execute(stmt);
|
||||
}
|
||||
|
||||
return AccountOpResult.Ok;
|
||||
}
|
||||
@@ -283,9 +304,16 @@ namespace Game
|
||||
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_CHECK_PASSWORD);
|
||||
stmt.AddValue(0, accountId);
|
||||
stmt.AddValue(1, CalculateShaPassHash(username, password));
|
||||
SQLResult result = DB.Login.Query(stmt);
|
||||
return !result.IsEmpty();
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
byte[] salt = result.Read<byte[]>(0);
|
||||
byte[] verifier = result.Read<byte[]>(1);
|
||||
if (SRP6.CheckLogin(username, password, salt, verifier))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CheckEmail(uint accountId, string newEmail)
|
||||
@@ -311,6 +339,7 @@ namespace Game
|
||||
return result.IsEmpty() ? 0 : (uint)result.Read<ulong>(0);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
string CalculateShaPassHash(string name, string password)
|
||||
{
|
||||
SHA1 sha = SHA1.Create();
|
||||
|
||||
@@ -99,7 +99,9 @@ namespace Game.Chat.Commands
|
||||
byte index = (byte)(Global.BNetAccountMgr.GetMaxIndex(accountId) + 1);
|
||||
string accountName = accountId.ToString() + '#' + index;
|
||||
|
||||
switch (Global.AccountMgr.CreateAccount(accountName, "DUMMY", bnetAccountName, accountId, index))
|
||||
// Generate random hex string for password, these accounts must not be logged on with GRUNT
|
||||
byte[] randPassword = new byte[0].GenerateRandomKey(16);
|
||||
switch (Global.AccountMgr.CreateAccount(accountName, randPassword.ToHexString(), bnetAccountName, accountId, index))
|
||||
{
|
||||
case AccountOpResult.Ok:
|
||||
handler.SendSysMessage(CypherStrings.AccountCreated, accountName);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Game
|
||||
_battlePetMgr = new BattlePetMgr(this);
|
||||
_collectionMgr = new CollectionMgr(this);
|
||||
|
||||
m_Address = sock.GetRemoteIpAddress().ToString();
|
||||
m_Address = sock.GetRemoteIpAddress().Address.ToString();
|
||||
ResetTimeOutTime(false);
|
||||
DB.Login.Execute("UPDATE account SET online = 1 WHERE id = {0};", GetAccountId()); // One-time query
|
||||
}
|
||||
|
||||
@@ -64,17 +64,7 @@ namespace Game
|
||||
wardenCheck.Action = (WardenActions)WorldConfig.GetIntValue(WorldCfg.WardenClientFailAction);
|
||||
|
||||
if (checkType == WardenCheckType.PageA || checkType == WardenCheckType.PageB || checkType == WardenCheckType.Driver)
|
||||
{
|
||||
wardenCheck.Data = new BigInteger(data.ToByteArray());
|
||||
int len = data.Length / 2;
|
||||
|
||||
if (wardenCheck.Data.ToByteArray().Length < len)
|
||||
{
|
||||
byte[] temp = wardenCheck.Data.ToByteArray();
|
||||
Array.Reverse(temp);
|
||||
wardenCheck.Data = new BigInteger(temp);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkType == WardenCheckType.Memory || checkType == WardenCheckType.Module)
|
||||
MemChecksIdPool.Add(id);
|
||||
@@ -96,13 +86,6 @@ namespace Game
|
||||
if (checkType == WardenCheckType.MPQ || checkType == WardenCheckType.Memory)
|
||||
{
|
||||
BigInteger Result = new BigInteger(checkResult.ToByteArray());
|
||||
int len = checkResult.Length / 2;
|
||||
if (Result.ToByteArray().Length < len)
|
||||
{
|
||||
byte[] temp = Result.ToByteArray();
|
||||
Array.Reverse(temp);
|
||||
Result = new BigInteger(temp);
|
||||
}
|
||||
CheckResultStore[id] = Result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user