TrinityCore
Loading...
Searching...
No Matches
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 TRINITYCORE_SESSION_H
19#define TRINITYCORE_SESSION_H
20
22#include "ClientBuildInfo.h"
23#include "DatabaseEnvFwd.h"
24#include "Duration.h"
25#include "Hash.h"
26#include "Realm.h"
27#include "Socket.h"
28#include "SslStream.h"
29#include <memory>
30
32{
33class Message;
34}
35
36namespace pb = google::protobuf;
37
38namespace Battlenet
39{
47
49 {
50 void LoadResult(Field const* fields);
51
53 std::string Name;
54 std::string DisplayName;
55 time_t BanDate;
56 time_t UnbanDate;
60
61 std::unordered_map<uint32 /*realmAddress*/, uint8> CharacterCounts;
62 std::unordered_map<std::string /*subRegion*/, LastPlayedCharacterInfo, Trinity::TransparentHash<std::string_view>, std::equal_to<>> LastPlayedCharacters;
63 };
64
66 {
68
70 std::string Login;
72 std::string LockCountry;
73 std::string LastIP;
77
78 std::unordered_map<uint32, GameAccountInfo> GameAccounts;
79 };
80
81 class Session final : public std::enable_shared_from_this<Session>
82 {
83 public:
86
87 void Start();
88 bool Update();
89 boost::asio::ip::address const& GetRemoteIpAddress() const { return _socket->GetRemoteIpAddress(); }
90 bool IsOpen() const { return _socket->IsOpen(); }
91 void CloseSocket() { return _socket->CloseSocket(); }
92 void DelayedCloseSocket() { return _socket->DelayedCloseSocket(); }
93
94 bool IsAuthed() const { return _authed; }
95
96 uint32 GetSessionId() const { return _sessionId; }
98 void SetClientInstanceId(std::string const& ciid) { _clientInstanceId = ciid; }
99
100 uint32 GetAccountId() const { return _accountInfo->Id; }
101 AccountInfo const* GetAccountInfo() const { return _accountInfo.get(); }
102
105 GameAccountInfo const* GetGameAccountInfo(uint32 gameAccountId) const;
106 LastPlayedCharacterInfo const* GetLastPlayedCharacter(std::string_view subRegion) const;
107
108 std::string const& GetLocale() const { return _locale; }
109 std::string const& GetOS() const { return _os; }
110 uint32 GetBuild() const { return _build; }
113 std::array<uint8, 32> GetClientSecret() const { return _clientSecret; }
114
115 void SendResponse(uint32 token, pb::Message const* response);
116 void SendResponse(uint32 token, uint32 status);
117
118 void SendRequest(uint32 serviceHash, uint32 methodId, pb::Message const* request, std::function<void(MessageBuffer)> callback);
119 void SendRequest(uint32 serviceHash, uint32 methodId, pb::Message const* request);
120
121 void QueueQuery(QueryCallback&& queryCallback);
122
123 void OnLogon(std::string_view platform, std::string_view locale, uint32 applicationVersion, Minutes timezoneOffset);
124 void OnLogonSuccess(std::shared_ptr<AccountInfo> accountInfo, std::string_view ipCountry);
125 void SetClientInfo(uint32 gameAccountId, ClientBuild::VariantId buildVariant, std::array<uint8, 32> const& clientSecret);
126
127 std::string GetClientInfo() const;
128
130
131 protected:
133 bool ReadHeaderHandler();
134 bool ReadDataHandler();
135
136 private:
137 void AsyncWrite(MessageBuffer* packet);
138
140
141 static std::shared_ptr<Socket> CreateSocket(Trinity::Net::IoContextTcpSocket&& socket);
142 std::shared_ptr<Socket> _socket;
143
145 {
147 Header,
148 Data,
149 };
150
153
156 std::string _clientInstanceId;
157
158 std::shared_ptr<AccountInfo> _accountInfo;
159 GameAccountInfo const* _gameAccountInfo; // Points at selected game account (inside _gameAccounts)
160
161 std::string _locale;
162 std::string _os;
166
167 std::string _ipCountry;
168
169 std::array<uint8, 32> _clientSecret;
170
172
174
175 std::unordered_map<uint32, std::function<void(MessageBuffer)>> _responseCallbacks;
177 };
178}
179
180#endif // TRINITYCORE_SESSION_H
AccountTypes
Definition Common.h:42
std::shared_ptr< PreparedResultSet > PreparedQueryResult
uint8_t uint8
Definition Define.h:156
uint64_t uint64
Definition Define.h:153
uint32_t uint32
Definition Define.h:154
std::chrono::system_clock::time_point SystemTimePoint
Definition Duration.h:41
std::chrono::minutes Minutes
Minutes shorthand typedef.
Definition Duration.h:32
uint32 GetGameAccountId() const
Definition Session.h:103
std::string GetClientInfo() const
Definition Session.cpp:345
Minutes GetTimezoneOffset() const
Definition Session.h:112
void DelayedCloseSocket()
Definition Session.h:92
void SendResponse(uint32 token, pb::Message const *response)
Definition Session.cpp:129
SystemTimePoint GetCreationTime() const
Definition Session.h:97
uint32 GetAccountId() const
Definition Session.h:100
void OnLogon(std::string_view platform, std::string_view locale, uint32 applicationVersion, Minutes timezoneOffset)
Definition Session.cpp:214
AccountInfo const * GetAccountInfo() const
Definition Session.h:101
Trinity::Net::SocketReadCallbackResult ReadHandler()
Definition Session.cpp:272
std::array< uint8, 32 > GetClientSecret() const
Definition Session.h:113
std::string _ipCountry
Definition Session.h:167
uint32 GetBuild() const
Definition Session.h:110
ClientBuild::VariantId _buildVariant
Definition Session.h:164
LastPlayedCharacterInfo const * GetLastPlayedCharacter(std::string_view subRegion) const
Definition Session.cpp:237
void SetClientInfo(uint32 gameAccountId, ClientBuild::VariantId buildVariant, std::array< uint8, 32 > const &clientSecret)
Definition Session.cpp:230
static std::shared_ptr< Socket > CreateSocket(Trinity::Net::IoContextTcpSocket &&socket)
Definition Session.cpp:83
bool IsAuthed() const
Definition Session.h:94
uint32 const _sessionId
Definition Session.h:154
SystemTimePoint const _creationTime
Definition Session.h:155
uint32 GetSessionId() const
Definition Session.h:96
bool ReadHeaderLengthHandler()
Definition Session.cpp:297
void AsyncWrite(MessageBuffer *packet)
Definition Session.cpp:121
MessageBuffer _packetBuffer
Definition Session.h:152
void CloseSocket()
Definition Session.h:91
QueryCallbackProcessor _queryProcessor
Definition Session.h:173
ClientBuild::VariantId GetBuildVariant() const
Definition Session.h:111
std::array< uint8, 32 > _clientSecret
Definition Session.h:169
std::string const & GetLocale() const
Definition Session.h:108
bool IsOpen() const
Definition Session.h:90
PacketReadState _packetReadState
Definition Session.h:151
void QueueQuery(QueryCallback &&queryCallback)
Definition Session.cpp:209
void SendRequest(uint32 serviceHash, uint32 methodId, pb::Message const *request, std::function< void(MessageBuffer)> callback)
Definition Session.cpp:176
uint32 _requestToken
Definition Session.h:176
void OnLogonSuccess(std::shared_ptr< AccountInfo > accountInfo, std::string_view ipCountry)
Definition Session.cpp:223
GameAccountInfo const * _gameAccountInfo
Definition Session.h:159
std::string _locale
Definition Session.h:161
std::string const & GetOS() const
Definition Session.h:109
std::shared_ptr< Socket > _socket
Definition Session.h:142
boost::asio::ip::address const & GetRemoteIpAddress() const
Definition Session.h:89
std::string _os
Definition Session.h:162
void SetClientInstanceId(std::string const &ciid)
Definition Session.h:98
GameAccountInfo const * GetGameAccountInfo() const
Definition Session.h:104
Minutes _timezoneOffset
Definition Session.h:165
bool ReadHeaderHandler()
Definition Session.cpp:309
std::unordered_map< uint32, std::function< void(MessageBuffer)> > _responseCallbacks
Definition Session.h:175
std::shared_ptr< AccountInfo > _accountInfo
Definition Session.h:158
std::string _clientInstanceId
Definition Session.h:156
Class used to access individual fields of database query result.
Definition Field.h:94
SocketReadCallbackResult
Definition Socket.h:49
boost::asio::basic_stream_socket< boost::asio::ip::tcp, Asio::IoContextExecutor > IoContextTcpSocket
Definition Socket.h:40
void LoadResult(PreparedQueryResult result)
Definition Session.cpp:31
std::string Login
Definition Session.h:70
std::string LockCountry
Definition Session.h:72
std::string LastIP
Definition Session.h:73
std::unordered_map< uint32, GameAccountInfo > GameAccounts
Definition Session.h:78
std::string DisplayName
Definition Session.h:54
std::unordered_map< std::string, LastPlayedCharacterInfo, Trinity::TransparentHash< std::string_view >, std::equal_to<> > LastPlayedCharacters
Definition Session.h:62
AccountTypes SecurityLevel
Definition Session.h:59
void LoadResult(Field const *fields)
Definition Session.cpp:53
std::unordered_map< uint32, uint8 > CharacterCounts
Definition Session.h:61
Battlenet::RealmHandle RealmId
Definition Session.h:42