aboutsummaryrefslogtreecommitdiff
path: root/src/server/authserver
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-08-22 20:09:18 +0200
committerShauren <shauren.trinity@gmail.com>2014-08-22 20:09:18 +0200
commitb90329d63acaecb1f074dd2b303561baa9f639a2 (patch)
treef2adfc5acec51b4467d56ba1a659330e83fb5aff /src/server/authserver
parentf2cb5061618367d6d4c07dee40eb9c6ecaed5d03 (diff)
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
Diffstat (limited to 'src/server/authserver')
-rw-r--r--src/server/authserver/Main.cpp2
-rw-r--r--src/server/authserver/Server/BattlenetSession.cpp55
-rw-r--r--src/server/authserver/Server/BattlenetSession.h2
-rw-r--r--src/server/authserver/Server/BattlenetSessionManager.cpp18
-rw-r--r--src/server/authserver/Server/BattlenetSessionManager.h61
5 files changed, 114 insertions, 24 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index 50205d1d585..af7ecd15160 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -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"
diff --git a/src/server/authserver/Server/BattlenetSession.cpp b/src/server/authserver/Server/BattlenetSession.cpp
index 9dc43d4bedb..2c2026253dc 100644
--- a/src/server/authserver/Server/BattlenetSession.cpp
+++ b/src/server/authserver/Server/BattlenetSession.cpp
@@ -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;
}
diff --git a/src/server/authserver/Server/BattlenetSession.h b/src/server/authserver/Server/BattlenetSession.h
index 0ffa253e371..f32f97d15e7 100644
--- a/src/server/authserver/Server/BattlenetSession.h
+++ b/src/server/authserver/Server/BattlenetSession.h
@@ -103,7 +103,7 @@ namespace Battlenet
std::string _os;
uint32 _build;
uint32 _gameAccountId;
- uint8 _gameAccountIndex;
+ std::string _gameAccountName;
AccountTypes _accountSecurityLevel;
BigNumber N;
diff --git a/src/server/authserver/Server/BattlenetSessionManager.cpp b/src/server/authserver/Server/BattlenetSessionManager.cpp
new file mode 100644
index 00000000000..e16057ecbf6
--- /dev/null
+++ b/src/server/authserver/Server/BattlenetSessionManager.cpp
@@ -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"
diff --git a/src/server/authserver/Server/BattlenetSessionManager.h b/src/server/authserver/Server/BattlenetSessionManager.h
new file mode 100644
index 00000000000..454bac96ddb
--- /dev/null
+++ b/src/server/authserver/Server/BattlenetSessionManager.h
@@ -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__