TrinityCore
Session.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef Session_h__
19#define Session_h__
20
22#include "Duration.h"
23#include "QueryResult.h"
24#include "Realm.h"
25#include "Socket.h"
26#include "SslSocket.h"
27#include <boost/asio/ip/tcp.hpp>
28#include <google/protobuf/message.h>
29#include <memory>
30
31namespace pb = google::protobuf;
32
33class ServiceBase;
34
36{
37class Variant;
38
39namespace account::v1
40{
41 class GetAccountStateRequest;
42 class GetAccountStateResponse;
43 class GetGameAccountStateRequest;
44 class GetGameAccountStateResponse;
45}
46
47namespace authentication::v1
48{
49 class GenerateWebCredentialsRequest;
50 class LogonRequest;
51 class VerifyWebCredentialsRequest;
52}
53
54namespace game_utilities::v1
55{
56 class ClientRequest;
57 class ClientResponse;
58 class GetAllValuesForAttributeRequest;
59 class GetAllValuesForAttributeResponse;
60}
61}
62
63using namespace bgs::protocol;
64
65namespace Battlenet
66{
67 class Session : public Socket<Session, SslSocket<>>
68 {
70
71 public:
73 {
75 std::string CharacterName;
78 };
79
81 {
82 void LoadResult(Field const* fields);
83
85 std::string Name;
86 std::string DisplayName;
91
92 std::unordered_map<uint32 /*realmAddress*/, uint8> CharacterCounts;
93 std::unordered_map<std::string /*subRegion*/, LastPlayedCharacterInfo> LastPlayedCharacters;
94 };
95
97 {
99
101 std::string Login;
103 std::string LockCountry;
104 std::string LastIP;
108
109 std::unordered_map<uint32, GameAccountInfo> GameAccounts;
110 };
111
112 explicit Session(boost::asio::ip::tcp::socket&& socket);
114
115 void Start() override;
116 bool Update() override;
117
118 uint32 GetAccountId() const { return _accountInfo->Id; }
120
121 void SendResponse(uint32 token, pb::Message const* response);
122 void SendResponse(uint32 token, uint32 status);
123
124 void SendRequest(uint32 serviceHash, uint32 methodId, pb::Message const* request, std::function<void(MessageBuffer)> callback)
125 {
126 _responseCallbacks[_requestToken] = std::move(callback);
127 SendRequest(serviceHash, methodId, request);
128 }
129
130 void SendRequest(uint32 serviceHash, uint32 methodId, pb::Message const* request);
131
132 uint32 HandleLogon(authentication::v1::LogonRequest const* logonRequest, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation);
133 uint32 HandleVerifyWebCredentials(authentication::v1::VerifyWebCredentialsRequest const* verifyWebCredentialsRequest, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation);
134 uint32 HandleGenerateWebCredentials(authentication::v1::GenerateWebCredentialsRequest const* request, std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& continuation);
139
140 std::string GetClientInfo() const;
141
142 protected:
143 void HandshakeHandler(boost::system::error_code const& error);
144 void ReadHandler() override;
146 bool ReadHeaderHandler();
147 bool ReadDataHandler();
148
149 private:
150 void AsyncWrite(MessageBuffer* packet);
151
152 void AsyncHandshake();
153
155
156 uint32 VerifyWebCredentials(std::string const& webCredentials, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation);
157
158 typedef uint32(Session::*ClientRequestHandler)(std::unordered_map<std::string, Variant const*> const&, game_utilities::v1::ClientResponse*);
159 static std::unordered_map<std::string, ClientRequestHandler> const ClientRequestHandlers;
160
161 uint32 GetRealmListTicket(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response);
162 uint32 GetLastCharPlayed(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response);
163 uint32 GetRealmList(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response);
164 uint32 JoinRealm(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response);
165
169
170 std::shared_ptr<AccountInfo> _accountInfo;
171 GameAccountInfo* _gameAccountInfo; // Points at selected game account (inside _gameAccounts)
172
173 std::string _locale;
174 std::string _os;
177
178 std::string _ipCountry;
179
180 std::array<uint8, 32> _clientSecret;
181
183
185
186 std::unordered_map<uint32, std::function<void(MessageBuffer)>> _responseCallbacks;
188 };
189}
190
191#endif // Session_h__
AccountTypes
Definition: Common.h:39
std::shared_ptr< PreparedResultSet > PreparedQueryResult
uint8_t uint8
Definition: Define.h:144
uint64_t uint64
Definition: Define.h:141
uint32_t uint32
Definition: Define.h:142
std::unordered_set< uint32 > params[2]
Definition: DisableMgr.cpp:50
std::chrono::minutes Minutes
Minutes shorthand typedef.
Definition: Duration.h:35
uint32 GetGameAccountId() const
Definition: Session.h:119
uint32 VerifyWebCredentials(std::string const &webCredentials, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation)
Definition: Session.cpp:306
Session(boost::asio::ip::tcp::socket &&socket)
Definition: Session.cpp:77
uint32 JoinRealm(std::unordered_map< std::string, Variant const * > const &params, game_utilities::v1::ClientResponse *response)
Definition: Session.cpp:696
std::string GetClientInfo() const
Definition: Session.cpp:829
void AsyncHandshake()
Definition: Session.cpp:86
uint32 HandleGenerateWebCredentials(authentication::v1::GenerateWebCredentialsRequest const *request, std::function< void(ServiceBase *, uint32, google::protobuf::Message const *)> &continuation)
Definition: Session.cpp:276
static std::unordered_map< std::string, ClientRequestHandler > const ClientRequestHandlers
Definition: Session.h:159
void SendResponse(uint32 token, pb::Message const *response)
Definition: Session.cpp:149
uint32 GetAccountId() const
Definition: Session.h:118
uint32 GetRealmList(std::unordered_map< std::string, Variant const * > const &params, game_utilities::v1::ClientResponse *response)
Definition: Session.cpp:655
MessageBuffer _headerBuffer
Definition: Session.h:167
uint32 HandleProcessClientRequest(game_utilities::v1::ClientRequest const *request, game_utilities::v1::ClientResponse *response)
Definition: Session.cpp:515
uint32 HandleVerifyWebCredentials(authentication::v1::VerifyWebCredentialsRequest const *verifyWebCredentialsRequest, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation)
Definition: Session.cpp:268
uint32(Session::* ClientRequestHandler)(std::unordered_map< std::string, Variant const * > const &, game_utilities::v1::ClientResponse *)
Definition: Session.h:158
void CheckIpCallback(PreparedQueryResult result)
Definition: Session.cpp:107
std::string _ipCountry
Definition: Session.h:178
bool ReadDataHandler()
Definition: Session.cpp:804
void Start() override
Definition: Session.cpp:92
void HandshakeHandler(boost::system::error_code const &error)
Definition: Session.cpp:719
bool Update() override
Definition: Session.cpp:131
uint32 GetLastCharPlayed(std::unordered_map< std::string, Variant const * > const &params, game_utilities::v1::ClientResponse *response)
Definition: Session.cpp:620
Socket< Session, SslSocket<> > BattlenetSocket
Definition: Session.h:69
uint32 HandleGetGameAccountState(account::v1::GetGameAccountStateRequest const *request, account::v1::GetGameAccountStateResponse *response)
Definition: Session.cpp:473
void ReadHandler() override
Definition: Session.cpp:762
bool ReadHeaderLengthHandler()
Definition: Session.cpp:786
void AsyncWrite(MessageBuffer *packet)
Definition: Session.cpp:141
MessageBuffer _packetBuffer
Definition: Session.h:168
uint32 HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const *request, game_utilities::v1::GetAllValuesForAttributeResponse *response)
Definition: Session.cpp:705
QueryCallbackProcessor _queryProcessor
Definition: Session.h:184
std::array< uint8, 32 > _clientSecret
Definition: Session.h:180
GameAccountInfo * _gameAccountInfo
Definition: Session.h:171
uint32 HandleLogon(authentication::v1::LogonRequest const *logonRequest, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation)
Definition: Session.cpp:214
void SendRequest(uint32 serviceHash, uint32 methodId, pb::Message const *request, std::function< void(MessageBuffer)> callback)
Definition: Session.h:124
uint32 _requestToken
Definition: Session.h:187
std::string _locale
Definition: Session.h:173
std::string _os
Definition: Session.h:174
Minutes _timezoneOffset
Definition: Session.h:176
MessageBuffer _headerLengthBuffer
Definition: Session.h:166
uint32 HandleGetAccountState(account::v1::GetAccountStateRequest const *request, account::v1::GetAccountStateResponse *response)
Definition: Session.cpp:456
bool ReadHeaderHandler()
Definition: Session.cpp:794
std::unordered_map< uint32, std::function< void(MessageBuffer)> > _responseCallbacks
Definition: Session.h:186
uint32 GetRealmListTicket(std::unordered_map< std::string, Variant const * > const &params, game_utilities::v1::ClientResponse *response)
Definition: Session.cpp:565
std::shared_ptr< AccountInfo > _accountInfo
Definition: Session.h:170
Class used to access individual fields of database query result.
Definition: Field.h:90
Definition: Socket.h:63
std::unordered_map< uint32, GameAccountInfo > GameAccounts
Definition: Session.h:109
void LoadResult(PreparedQueryResult result)
Definition: Session.cpp:38
void LoadResult(Field const *fields)
Definition: Session.cpp:60
std::unordered_map< uint32, uint8 > CharacterCounts
Definition: Session.h:92
std::unordered_map< std::string, LastPlayedCharacterInfo > LastPlayedCharacters
Definition: Session.h:93