1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
* 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 _BATTLENETSOCKET_H
#define _BATTLENETSOCKET_H
#include "BattlenetPackets.h"
#include "BattlenetPacketCrypt.h"
#include "BigNumber.h"
#include <memory>
#include <boost/asio/ip/tcp.hpp>
using boost::asio::ip::tcp;
namespace Battlenet
{
struct PacketHeader;
class BitStream;
enum ModuleType
{
MODULE_PASSWORD,
MODULE_TOKEN,
MODULE_THUMBPRINT,
MODULE_SELECT_GAME_ACCOUNT,
MODULE_RISK_FINGERPRINT,
MODULE_RESUME,
MODULE_COUNT
};
enum class BufferSizes : uint32
{
SRP_6_V = 0x80,
SRP_6_S = 0x20,
Read = 0x4000
};
class Session : public std::enable_shared_from_this<Session>
{
public:
explicit Session(tcp::socket&& socket);
~Session();
typedef bool(Session::*PacketHandler)(PacketHeader& socket, BitStream& packet);
// Auth
bool HandleAuthChallenge(PacketHeader& header, BitStream& packet);
bool HandleAuthReconnect(PacketHeader& header, BitStream& packet);
bool HandleAuthProofResponse(PacketHeader& header, BitStream& packet);
// Creep
bool HandlePing(PacketHeader& header, BitStream& packet);
bool HandleEnableEncryption(PacketHeader& header, BitStream& packet);
bool HandleDisconnect(PacketHeader& header, BitStream& packet);
// WoW
bool HandleRealmUpdateSubscribe(PacketHeader& header, BitStream& packet);
bool HandleRealmJoinRequest(PacketHeader& header, BitStream& packet);
void Start();
void AsyncRead();
void AsyncWrite(ServerPacket* packet);
private:
void _SetVSFields(std::string const& rI);
typedef bool(Session::*ModuleHandler)(BitStream* dataStream, ServerPacket** response);
static ModuleHandler const ModuleHandlers[MODULE_COUNT];
bool HandlePasswordModule(BitStream* dataStream, ServerPacket** response);
bool HandleSelectGameAccountModule(BitStream* dataStream, ServerPacket** response);
bool HandleRiskFingerprintModule(BitStream* dataStream, ServerPacket** response);
bool HandleResumeModule(BitStream* dataStream, ServerPacket** response);
bool UnhandledModule(BitStream* dataStream, ServerPacket** response);
std::string GetRemoteAddress() const { return _socket.remote_endpoint().address().to_string(); }
uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); }
tcp::socket _socket;
uint8 _readBuffer[BufferSizes::Read];
uint32 _accountId;
std::string _accountName;
std::string _locale;
std::string _os;
uint32 _build;
uint32 _gameAccountId;
uint8 _gameAccountIndex;
AccountTypes _accountSecurityLevel;
BigNumber N;
BigNumber g;
BigNumber k;
BigNumber I;
BigNumber s;
BigNumber v;
BigNumber b;
BigNumber B;
BigNumber K; // session key
BigNumber _reconnectProof;
std::queue<ModuleType> _modulesWaitingForData;
PacketCrypt _crypt;
bool _authed;
};
}
#endif // _BATTLENETSOCKET_H
|