Core/bnetserver: Implemented reconnecting with launcherlogin

This commit is contained in:
Shauren
2022-09-13 14:27:54 +02:00
parent 30ad7e3337
commit 8a183a6e5e
6 changed files with 61 additions and 33 deletions

View File

@@ -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())

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;
};
}
}

View File

@@ -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"

View File

@@ -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,