diff options
Diffstat (limited to 'src')
6 files changed, 61 insertions, 33 deletions
diff --git a/src/server/bnetserver/Server/Session.cpp b/src/server/bnetserver/Server/Session.cpp index acfd958b2cd..995f1bbd7b9 100644 --- a/src/server/bnetserver/Server/Session.cpp +++ b/src/server/bnetserver/Server/Session.cpp @@ -249,6 +249,36 @@ uint32 Battlenet::Session::HandleVerifyWebCredentials(authentication::v1::Verify return ERROR_DENIED; } +uint32 Battlenet::Session::HandleGenerateWebCredentials(authentication::v1::GenerateWebCredentialsRequest const* request, std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& continuation) +{ + if (!_authed) + return ERROR_DENIED; + + if (request->program() != 0x576F57) + { + auto asPrintable = [](char c) { return std::isprint(c) ? c : ' '; }; + + TC_LOG_DEBUG("session", "[Battlenet::HandleGenerateWebCredentials] %s attempted to generate web cretentials with game other than WoW (using %c%c%c%c)!", + GetClientInfo().c_str(), asPrintable((request->program() >> 24) & 0xFF), asPrintable((request->program() >> 16) & 0xFF), + asPrintable((request->program() >> 8) & 0xFF), asPrintable(request->program() & 0xFF)); + return ERROR_BAD_PROGRAM; + } + + LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_EXISTING_AUTHENTICATION_BY_ID); + stmt->setUInt32(0, _accountInfo->Id); + + _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback([this, asyncContinuation = std::move(continuation)](PreparedQueryResult result) + { + // just send existing credentials back (not the best but it works for now with them being stored in db) + Battlenet::Services::Authentication asyncContinuationService(this); + authentication::v1::GenerateWebCredentialsResponse response; + response.set_web_credentials((*result)[0].GetCString()); + asyncContinuation(&asyncContinuationService, ERROR_OK, &response); + })); + + return ERROR_OK; +} + uint32 Battlenet::Session::VerifyWebCredentials(std::string const& webCredentials, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation) { if (webCredentials.empty()) diff --git a/src/server/bnetserver/Server/Session.h b/src/server/bnetserver/Server/Session.h index 75fe2f19f02..4809b7d894d 100644 --- a/src/server/bnetserver/Server/Session.h +++ b/src/server/bnetserver/Server/Session.h @@ -34,43 +34,32 @@ namespace pb = google::protobuf; class ServiceBase; -namespace bgs +namespace bgs::protocol { - namespace protocol - { - class Variant; +class Variant; - namespace account - { - namespace v1 - { - class GetAccountStateRequest; - class GetAccountStateResponse; - class GetGameAccountStateRequest; - class GetGameAccountStateResponse; - } - } +namespace account::v1 +{ + class GetAccountStateRequest; + class GetAccountStateResponse; + class GetGameAccountStateRequest; + class GetGameAccountStateResponse; +} - namespace authentication - { - namespace v1 - { - class LogonRequest; - class VerifyWebCredentialsRequest; - } - } +namespace authentication::v1 +{ + class GenerateWebCredentialsRequest; + class LogonRequest; + class VerifyWebCredentialsRequest; +} - namespace game_utilities - { - namespace v1 - { - class ClientRequest; - class ClientResponse; - class GetAllValuesForAttributeRequest; - class GetAllValuesForAttributeResponse; - } - } - } +namespace game_utilities::v1 +{ + class ClientRequest; + class ClientResponse; + class GetAllValuesForAttributeRequest; + class GetAllValuesForAttributeResponse; +} } using namespace bgs::protocol; @@ -144,6 +133,7 @@ namespace Battlenet uint32 HandleLogon(authentication::v1::LogonRequest const* logonRequest, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation); uint32 HandleVerifyWebCredentials(authentication::v1::VerifyWebCredentialsRequest const* verifyWebCredentialsRequest, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation); + uint32 HandleGenerateWebCredentials(authentication::v1::GenerateWebCredentialsRequest const* request, std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& continuation); uint32 HandleGetAccountState(account::v1::GetAccountStateRequest const* request, account::v1::GetAccountStateResponse* response); uint32 HandleGetGameAccountState(account::v1::GetGameAccountStateRequest const* request, account::v1::GetGameAccountStateResponse* response); uint32 HandleProcessClientRequest(game_utilities::v1::ClientRequest const* request, game_utilities::v1::ClientResponse* response); diff --git a/src/server/bnetserver/Services/AuthenticationService.cpp b/src/server/bnetserver/Services/AuthenticationService.cpp index 64231f4b811..d157f42ca32 100644 --- a/src/server/bnetserver/Services/AuthenticationService.cpp +++ b/src/server/bnetserver/Services/AuthenticationService.cpp @@ -31,3 +31,8 @@ uint32 Battlenet::Services::Authentication::HandleVerifyWebCredentials(authentic { return _session->HandleVerifyWebCredentials(request, continuation); } + +uint32 Battlenet::Services::Authentication::HandleGenerateWebCredentials(authentication::v1::GenerateWebCredentialsRequest const* request, authentication::v1::GenerateWebCredentialsResponse* /*response*/, std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& continuation) +{ + return _session->HandleGenerateWebCredentials(request, continuation); +} diff --git a/src/server/bnetserver/Services/AuthenticationService.h b/src/server/bnetserver/Services/AuthenticationService.h index 891ae8957ee..f2e0f19b2cc 100644 --- a/src/server/bnetserver/Services/AuthenticationService.h +++ b/src/server/bnetserver/Services/AuthenticationService.h @@ -36,6 +36,7 @@ namespace Battlenet uint32 HandleLogon(authentication::v1::LogonRequest const* request, NoData* response, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation) override; uint32 HandleVerifyWebCredentials(authentication::v1::VerifyWebCredentialsRequest const* request, NoData* response, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation) override; + uint32 HandleGenerateWebCredentials(authentication::v1::GenerateWebCredentialsRequest const* request, authentication::v1::GenerateWebCredentialsResponse* response, std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& continuation) override; }; } } diff --git a/src/server/database/Database/Implementation/LoginDatabase.cpp b/src/server/database/Database/Implementation/LoginDatabase.cpp index 95997a54d44..21b0b7534f1 100644 --- a/src/server/database/Database/Implementation/LoginDatabase.cpp +++ b/src/server/database/Database/Implementation/LoginDatabase.cpp @@ -123,6 +123,7 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_SEL_BNET_AUTHENTICATION, "SELECT ba.id, ba.sha_pass_hash, ba.failed_logins, ba.LoginTicket, ba.LoginTicketExpiry, bab.unbandate > UNIX_TIMESTAMP() OR bab.unbandate = bab.bandate FROM battlenet_accounts ba LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id WHERE email = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_BNET_AUTHENTICATION, "UPDATE battlenet_accounts SET LoginTicket = ?, LoginTicketExpiry = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_SEL_BNET_EXISTING_AUTHENTICATION, "SELECT LoginTicketExpiry FROM battlenet_accounts WHERE LoginTicket = ?", CONNECTION_ASYNC); + PrepareStatement(LOGIN_SEL_BNET_EXISTING_AUTHENTICATION_BY_ID, "SELECT LoginTicket FROM battlenet_accounts WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_BNET_EXISTING_AUTHENTICATION, "UPDATE battlenet_accounts SET LoginTicketExpiry = ? WHERE LoginTicket = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_SEL_BNET_ACCOUNT_INFO, "SELECT " BnetAccountInfo ", " BnetGameAccountInfo "" " FROM battlenet_accounts ba LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id LEFT JOIN account a ON ba.id = a.battlenet_account" diff --git a/src/server/database/Database/Implementation/LoginDatabase.h b/src/server/database/Database/Implementation/LoginDatabase.h index 7d3c44f1f91..7f46b9e8e3a 100644 --- a/src/server/database/Database/Implementation/LoginDatabase.h +++ b/src/server/database/Database/Implementation/LoginDatabase.h @@ -116,6 +116,7 @@ enum LoginDatabaseStatements : uint32 LOGIN_SEL_BNET_AUTHENTICATION, LOGIN_UPD_BNET_AUTHENTICATION, LOGIN_SEL_BNET_EXISTING_AUTHENTICATION, + LOGIN_SEL_BNET_EXISTING_AUTHENTICATION_BY_ID, LOGIN_UPD_BNET_EXISTING_AUTHENTICATION, LOGIN_SEL_BNET_ACCOUNT_INFO, LOGIN_UPD_BNET_LAST_LOGIN_INFO, |