Core/Battle.net: Use real account name from account table to auth instead of always constructing bnetId#index. Fixes having to reconfigure addons by players.

*NEW* battle.net only accounts should be created with battlenet_account_id#account_index format in username
This commit is contained in:
Shauren
2014-08-22 20:09:18 +02:00
parent f2cb506161
commit b90329d63a
10 changed files with 130 additions and 80 deletions

View File

@@ -28,7 +28,7 @@
#include "AsyncAcceptor.h"
#include "AuthSession.h"
#include "BattlenetManager.h"
#include "BattlenetSession.h"
#include "BattlenetSessionManager.h"
#include "Common.h"
#include "Configuration/Config.h"
#include "Database/DatabaseEnv.h"

View File

@@ -17,7 +17,7 @@
#include "AuthCodes.h"
#include "BattlenetBitStream.h"
#include "BattlenetSession.h"
#include "BattlenetSessionManager.h"
#include "Database/DatabaseEnv.h"
#include "HmacHash.h"
#include "Log.h"
@@ -57,7 +57,7 @@ Battlenet::Session::ModuleHandler const Battlenet::Session::ModuleHandlers[MODUL
};
Battlenet::Session::Session(tcp::socket&& socket) : Socket(std::move(socket), std::size_t(BufferSizes::Read)), _accountId(0), _accountName(), _locale(),
_os(), _build(0), _gameAccountId(0), _gameAccountIndex(0), _accountSecurityLevel(SEC_PLAYER), I(), s(), v(), b(), B(), K(),
_os(), _build(0), _gameAccountId(0), _gameAccountName(), _accountSecurityLevel(SEC_PLAYER), I(), s(), v(), b(), B(), K(),
_reconnectProof(), _crypt(), _authed(false)
{
static uint8 const N_Bytes[] =
@@ -83,6 +83,7 @@ Battlenet::Session::Session(tcp::socket&& socket) : Socket(std::move(socket), st
Battlenet::Session::~Session()
{
sBattlenetSessionMgr.RemoveSession(this);
TC_LOG_TRACE("server.battlenet", "Battlenet::Session::OnClose");
}
@@ -330,12 +331,10 @@ bool Battlenet::Session::HandleAuthReconnect(PacketHeader& header, BitStream& pa
if (baseComponent != reconnect.Components.end())
_build = baseComponent->Build;
uint8 accountIndex = atol(reconnect.GameAccountName.substr(reconnect.GameAccountName.find_last_of('#') + 1).c_str());
Utf8ToUpperOnlyLatin(_accountName);
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_RECONNECT_INFO);
stmt->setString(0, _accountName);
stmt->setUInt8(1, accountIndex);
stmt->setString(1, reconnect.GameAccountName);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
@@ -350,7 +349,7 @@ bool Battlenet::Session::HandleAuthReconnect(PacketHeader& header, BitStream& pa
_accountId = fields[0].GetUInt32();
K.SetHexStr(fields[1].GetString().c_str());
_gameAccountId = fields[2].GetUInt32();
_gameAccountIndex = accountIndex;
_gameAccountName = reconnect.GameAccountName;
ModuleInfo* thumbprint = sBattlenetMgr->CreateModule(_os, "Thumbprint");
ModuleInfo* resume = sBattlenetMgr->CreateModule(_os, "Resume");
@@ -780,7 +779,12 @@ bool Battlenet::Session::HandlePasswordModule(BitStream* dataStream, ServerPacke
{
fields = result->Fetch();
std::ostringstream name;
name << "WoW" << uint32(fields[0].GetUInt8());
std::string originalName = fields[1].GetString();
if (originalName.find('#') != std::string::npos)
name << "WoW" << uint32(fields[0].GetUInt8());
else
name << originalName;
accounts.Write(2, 8);
accounts.WriteString(name.str(), 8);
} while (result->NextRow());
@@ -814,8 +818,8 @@ bool Battlenet::Session::HandlePasswordModule(BitStream* dataStream, ServerPacke
return false;
}
_gameAccountId = fields[1].GetUInt32();
_gameAccountIndex = fields[0].GetUInt8();
_gameAccountId = fields[0].GetUInt32();
_gameAccountName = fields[1].GetString();
request->Modules.push_back(sBattlenetMgr->CreateModule(_os, "RiskFingerprint"));
_modulesWaitingForData.push(MODULE_RISK_FINGERPRINT);
@@ -837,7 +841,7 @@ bool Battlenet::Session::HandleSelectGameAccountModule(BitStream* dataStream, Se
dataStream->Read<uint8>(8);
std::string account = dataStream->ReadString(8);
if (account.length() < 4)
if (account.empty())
{
AuthComplete* complete = new AuthComplete();
complete->SetAuthResult(LOGIN_NO_GAME_ACCOUNT);
@@ -845,10 +849,18 @@ bool Battlenet::Session::HandleSelectGameAccountModule(BitStream* dataStream, Se
return false;
}
uint8 accountIndex = atol(account.substr(3).c_str());
PreparedStatement* stmt;
if (account.substr(0, 3) != "WoW")
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_GAME_ACCOUNT);
stmt->setString(0, account);
}
else
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_GAME_ACCOUNT_UNNAMED);
stmt->setUInt8(0, atol(account.substr(3).c_str()));
}
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_GAME_ACCOUNT);
stmt->setUInt8(0, accountIndex);
stmt->setUInt32(1, _accountId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
@@ -860,10 +872,10 @@ bool Battlenet::Session::HandleSelectGameAccountModule(BitStream* dataStream, Se
}
Field* fields = result->Fetch();
if (fields[3].GetBool())
if (fields[4].GetBool())
{
AuthComplete* complete = new AuthComplete();
if (fields[1].GetUInt32() == fields[2].GetUInt32())
if (fields[2].GetUInt32() == fields[3].GetUInt32())
{
complete->SetAuthResult(LOGIN_BANNED);
TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::SelectGameAccount] Banned account %s tried to login!", GetRemoteIpAddress().to_string().c_str(), GetRemotePort(), _accountName.c_str());
@@ -879,7 +891,7 @@ bool Battlenet::Session::HandleSelectGameAccountModule(BitStream* dataStream, Se
}
_gameAccountId = fields[0].GetUInt32();
_gameAccountIndex = accountIndex;
_gameAccountName = fields[1].GetString();
ProofRequest* request = new ProofRequest();
request->Modules.push_back(sBattlenetMgr->CreateModule(_os, "RiskFingerprint"));
@@ -894,11 +906,8 @@ bool Battlenet::Session::HandleRiskFingerprintModule(BitStream* dataStream, Serv
AuthComplete* complete = new AuthComplete();
if (dataStream->Read<uint8>(8) == 1)
{
std::ostringstream str;
str << _accountId << "#" << uint32(_gameAccountIndex);
complete->AccountId = _accountId;
complete->GameAccountName = str.str();
complete->GameAccountName = _gameAccountName;
complete->GameAccountFlags = GAMEACCOUNT_FLAG_PROPASS_LOCK;
SQLTransaction trans = LoginDatabase.BeginTransaction();
@@ -919,6 +928,7 @@ bool Battlenet::Session::HandleRiskFingerprintModule(BitStream* dataStream, Serv
LoginDatabase.CommitTransaction(trans);
_authed = true;
sBattlenetSessionMgr.AddSession(this);
}
else
complete->SetAuthResult(AUTH_BAD_VERSION_HASH);
@@ -942,8 +952,8 @@ bool Battlenet::Session::HandleResumeModule(BitStream* dataStream, ServerPacket*
std::unique_ptr<uint8[]> clientChallenge = dataStream->ReadBytes(16);
std::unique_ptr<uint8[]> clientProof = dataStream->ReadBytes(32);
std::unique_ptr<uint8[]> serverChallenge = _reconnectProof.AsByteArray();
std::unique_ptr<uint8[]> sessionKey = K.AsByteArray();
std::unique_ptr<uint8[]> serverChallenge = _reconnectProof.AsByteArray(16);
std::unique_ptr<uint8[]> sessionKey = K.AsByteArray(64);
HmacSha256 clientPart(64, sessionKey.get());
clientPart.UpdateData(&ResumeClient, 1);
@@ -1005,6 +1015,7 @@ bool Battlenet::Session::HandleResumeModule(BitStream* dataStream, ServerPacket*
result->Modules.push_back(resume);
ReplaceResponse(response, result);
_authed = true;
sBattlenetSessionMgr.AddSession(this);
return true;
}

View File

@@ -103,7 +103,7 @@ namespace Battlenet
std::string _os;
uint32 _build;
uint32 _gameAccountId;
uint8 _gameAccountIndex;
std::string _gameAccountName;
AccountTypes _accountSecurityLevel;
BigNumber N;

View File

@@ -0,0 +1,18 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BattlenetSessionManager.h"

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BattlenetSessionManager_h__
#define BattlenetSessionManager_h__
#include "BattlenetSession.h"
namespace Battlenet
{
#pragma pack(push, 1)
struct SessionInfo
{
uint32 AccountId;
uint32 GameAccountIndex;
bool operator<(SessionInfo const& right) const
{
return memcmp(this, &right, sizeof(SessionInfo)) < 0;
}
};
#pragma pack(pop)
class SessionManager
{
public:
static SessionManager& Instance()
{
static SessionManager instance;
return instance;
}
// noop for now, will be needed later to broadcast realmlist updates for example
void AddSession(Session* /*session*/) { }
void RemoveSession(Session* /*session*/) { }
private:
std::map<SessionInfo, Session> _sessions;
};
}
#define sBattlenetSessionMgr Battlenet::SessionManager::Instance()
#endif // BattlenetSessionManager_h__

View File

@@ -126,26 +126,3 @@ std::string Battlenet::AccountMgr::CalculateShaPassHash(std::string const& name,
return ByteArrayToHexStr(sha.GetDigest(), sha.GetLength(), true);
}
bool Battlenet::AccountMgr::GetAccountIdAndIndex(std::string const& account, uint32* battlenetAccountId, uint8* battlenetAccountIndex)
{
Tokenizer tokens(account, '#');
if (tokens.size() != 2)
return false;
if (!battlenetAccountId)
return false;
*battlenetAccountId = atol(tokens[0]);
if (!*battlenetAccountId)
return false;
if (battlenetAccountIndex)
{
*battlenetAccountIndex = atol(tokens[1]);
if (!*battlenetAccountIndex)
return false;
}
return true;
}

View File

@@ -38,7 +38,6 @@ namespace Battlenet
uint32 GetIdByGameAccount(uint32 gameAccountId);
std::string CalculateShaPassHash(std::string const& name, std::string const& password);
bool GetAccountIdAndIndex(std::string const& account, uint32* battlenetAccountId, uint8* battlenetAccountIndex);
}
}

View File

@@ -261,31 +261,10 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
account = recvPacket.ReadString(accountNameLength);
// Get the account information from the auth database
// 0 1 2 3 4 5 6 7 8
// SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os FROM account WHERE username = ?
PreparedStatement* stmt;
uint32 battlenetAccountId = 0;
uint8 battlenetAccountIndex = 0;
if (loginServerType == 1)
{
if (!Battlenet::AccountMgr::GetAccountIdAndIndex(account, &battlenetAccountId, &battlenetAccountIndex))
{
// We can not log here, as we do not know the account. Thus, no accountId.
SendAuthResponseError(AUTH_UNKNOWN_ACCOUNT);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
DelayedCloseSocket();
return;
}
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_BNET);
stmt->setUInt32(0, battlenetAccountId);
stmt->setUInt8(1, battlenetAccountIndex);
}
else
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setString(0, account);
}
// 0 1 2 3 4 5 6 7 8 9
// SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os, battlenet_account FROM account WHERE username = ?
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setString(0, account);
PreparedQueryResult result = LoginDatabase.Query(stmt);
@@ -392,7 +371,7 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
mutetime = time(NULL) + llabs(mutetime);
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME_LOGIN);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME_LOGIN);
stmt->setInt64(0, mutetime);
stmt->setUInt32(1, id);
@@ -405,6 +384,11 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
locale = LOCALE_enUS;
uint32 recruiter = fields[7].GetUInt32();
uint32 battlenetAccountId = 0;
if (loginServerType == 1)
battlenetAccountId = fields[9].GetUInt32();
// Checks gmlevel per Realm
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_GMLEVEL_BY_REALMID);

View File

@@ -43,8 +43,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_FAILEDLOGINS, "SELECT id, failed_logins FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME, "SELECT id FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_LIST_BY_NAME, "SELECT id, username FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME, "SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_BNET, "SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os FROM account WHERE battlenet_account = ? AND battlenet_index = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME, "SELECT id, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, os, battlenet_account FROM account WHERE username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_LIST_BY_EMAIL, "SELECT id, username FROM account WHERE email = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_NUM_CHARS_ON_REALM, "SELECT numchars FROM realmcharacters WHERE realmid = ? AND acctid= ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_ACCOUNT_BY_IP, "SELECT id, username FROM account WHERE last_ip = ?", CONNECTION_SYNCH);
@@ -118,9 +117,10 @@ void LoginDatabaseConnection::DoPrepareStatements()
PrepareStatement(LOGIN_SEL_BNET_ACTIVE_ACCOUNT_BAN, "SELECT bandate, unbandate FROM battlenet_account_bans WHERE id = ? AND active = 1", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_BNET_VS_FIELDS, "UPDATE battlenet_accounts SET v = ?, s = ? WHERE email = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_UPD_BNET_SESSION_KEY, "UPDATE battlenet_accounts SET sessionKey = ?, online = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_RECONNECT_INFO, "SELECT ba.id, ba.sessionKey, a.id FROM battlenet_accounts ba LEFT JOIN account a ON ba.id = a.battlenet_account WHERE ba.email = ? AND a.battlenet_index = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNTS, "SELECT a.battlenet_index, a.id, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNT, "SELECT a.id, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE battlenet_index = ? AND battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_RECONNECT_INFO, "SELECT ba.id, ba.sessionKey, a.id FROM battlenet_accounts ba LEFT JOIN account a ON ba.id = a.battlenet_account WHERE ba.email = ? AND a.username = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNTS, "SELECT a.id, a.username, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNT, "SELECT a.id, a.username, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE username = ? AND battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_SEL_BNET_GAME_ACCOUNT_UNNAMED, "SELECT a.id, a.username, ab.bandate, ab.unbandate, ab.active FROM account a LEFT JOIN account_banned ab ON a.id = ab.id WHERE battlenet_index = ? AND battlenet_account = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_UPD_BNET_LAST_LOGIN_INFO, "UPDATE battlenet_accounts SET last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(LOGIN_SEL_BNET_CHARACTER_COUNTS, "SELECT rc.numchars, r.id, r.Region, r.Battlegroup, r.gamebuild FROM realmcharacters rc INNER JOIN realmlist r ON rc.realmid = r.id WHERE rc.acctid = ?", CONNECTION_SYNCH);
PrepareStatement(LOGIN_INS_BNET_ACCOUNT, "INSERT INTO battlenet_accounts (`email`,`sha_pass_hash`) VALUES (?, ?)", CONNECTION_ASYNC);

View File

@@ -62,7 +62,6 @@ enum LoginDatabaseStatements
LOGIN_SEL_ACCOUNT_ID_BY_NAME,
LOGIN_SEL_ACCOUNT_LIST_BY_NAME,
LOGIN_SEL_ACCOUNT_INFO_BY_NAME,
LOGIN_SEL_ACCOUNT_INFO_BY_BNET,
LOGIN_SEL_ACCOUNT_LIST_BY_EMAIL,
LOGIN_SEL_NUM_CHARS_ON_REALM,
LOGIN_SEL_ACCOUNT_BY_IP,
@@ -137,6 +136,7 @@ enum LoginDatabaseStatements
LOGIN_SEL_BNET_RECONNECT_INFO,
LOGIN_SEL_BNET_GAME_ACCOUNTS,
LOGIN_SEL_BNET_GAME_ACCOUNT,
LOGIN_SEL_BNET_GAME_ACCOUNT_UNNAMED,
LOGIN_UPD_BNET_LAST_LOGIN_INFO,
LOGIN_SEL_BNET_CHARACTER_COUNTS,
LOGIN_INS_BNET_ACCOUNT,