-
Notifications
You must be signed in to change notification settings - Fork 6
/
bnet.h
executable file
·202 lines (178 loc) · 10.7 KB
/
bnet.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
ent-ghost
Copyright [2011-2013] [Jack Lu]
This file is part of the ent-ghost source code.
ent-ghost 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 3 of the License, or
(at your option) any later version.
ent-ghost source code 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 ent-ghost source code. If not, see <http://www.gnu.org/licenses/>.
ent-ghost is modified from GHost++ (http://ghostplusplus.googlecode.com/)
GHost++ is Copyright [2008] [Trevor Hogan]
*/
#ifndef BNET_H
#define BNET_H
#include "bnetprotocol.h"
//
// CBNET
//
class CTCPClient;
class CCommandPacket;
class CBNCSUtilInterface;
class CBNETProtocol;
class CBNLSClient;
class CIncomingFriendList;
class CIncomingClanList;
class CIncomingChatEvent;
class CCallableAdminCount;
class CCallableAdminAdd;
class CCallableAdminRemove;
class CCallableAdminList;
class CCallableGamePlayerSummaryCheck;
class CCallableDotAPlayerSummaryCheck;
class CCallableVampPlayerSummaryCheck;
class CCallableGameUpdate;
class CCallableVerifyUser;
typedef pair<string,CCallableAdminCount *> PairedAdminCount;
typedef pair<string,CCallableAdminAdd *> PairedAdminAdd;
typedef pair<string,CCallableAdminRemove *> PairedAdminRemove;
typedef pair<string,CCallableGamePlayerSummaryCheck *> PairedGPSCheck;
typedef pair<string,CCallableDotAPlayerSummaryCheck *> PairedDPSCheck;
typedef pair<string,CCallableVampPlayerSummaryCheck *> PairedVPSCheck;
typedef pair<string,CCallableGameUpdate *> PairedGameUpdate;
typedef pair<string,CCallableVerifyUser *> PairedVerifyUserCheck;
class CBNET
{
public:
CGHost *m_GHost;
private:
CTCPClient *m_Socket; // the connection to battle.net
CBNETProtocol *m_Protocol; // battle.net protocol
CBNLSClient *m_BNLSClient; // the BNLS client (for external warden handling)
queue<CCommandPacket *> m_Packets; // queue of incoming packets
boost::mutex m_PacketsMutex; // game sometimes calls QueueChatCommand and UnqueueChatCommand; this makes the functions synchronized
CBNCSUtilInterface *m_BNCSUtil; // the interface to the bncsutil library (used for logging into battle.net)
queue<BYTEARRAY> m_OutPackets; // queue of outgoing packets to be sent (to prevent getting kicked for flooding)
vector<CIncomingFriendList *> m_Friends; // vector of friends
vector<CIncomingClanList *> m_Clans; // vector of clan members
vector<PairedAdminCount> m_PairedAdminCounts; // vector of paired threaded database admin counts in progress
vector<PairedAdminAdd> m_PairedAdminAdds; // vector of paired threaded database admin adds in progress
vector<PairedAdminRemove> m_PairedAdminRemoves; // vector of paired threaded database admin removes in progress
vector<PairedGPSCheck> m_PairedGPSChecks; // vector of paired threaded database game player summary checks in progress
vector<PairedDPSCheck> m_PairedDPSChecks; // vector of paired threaded database DotA player summary checks in progress
vector<PairedVPSCheck> m_PairedVPSChecks; // vector of paired threaded database vamp player summary checks in progress
vector<PairedGameUpdate> m_PairedGameUpdates; // vector of paired threaded database gamelist query checks in progress
vector<PairedVerifyUserCheck> m_PairedVerifyUserChecks;
CCallableAdminList *m_CallableAdminList; // threaded database admin list in progress
vector<string> m_Admins; // vector of cached admins
bool m_Exiting; // set to true and this class will be deleted next update
string m_Server; // battle.net server to connect to
string m_ServerIP; // battle.net server to connect to (the IP address so we don't have to resolve it every time we connect)
string m_ServerAlias; // battle.net server alias (short name, e.g. "USEast")
uint32_t m_ServerReconnectCount; // counts how many times we have reconnected to the server and failed; when it's high, we resolve ServerIP again
uint32_t m_CDKeyUseCount; // counts how many times we have disconnected from server due to cd key usage
string m_BNLSServer; // BNLS server to connect to (for warden handling)
uint16_t m_BNLSPort; // BNLS port
uint32_t m_BNLSWardenCookie; // BNLS warden cookie
string m_CDKeyROC; // ROC CD key
string m_CDKeyTFT; // TFT CD key
string m_CountryAbbrev; // country abbreviation
string m_Country; // country
uint32_t m_LocaleID; // see: http://msdn.microsoft.com/en-us/library/0h88fahh%28VS.85%29.aspx
string m_KeyOwnerName; // key owner name
string m_UserName; // battle.net username
string m_UserPassword; // battle.net password
string m_FirstChannel; // the first chat channel to join upon entering chat (note: we hijack this to store the last channel when entering a game)
string m_CurrentChannel; // the current chat channel
string m_RootAdmin; // the root admin
char m_CommandTrigger; // the character prefix to identify commands
unsigned char m_War3Version; // custom warcraft 3 version for PvPGN users
BYTEARRAY m_EXEVersion; // custom exe version for PvPGN users
BYTEARRAY m_EXEVersionHash; // custom exe version hash for PvPGN users
string m_PasswordHashType; // password hash type for PvPGN users
string m_PVPGNRealmName; // realm name for PvPGN users (for mutual friend spoofchecks)
uint32_t m_MaxMessageLength; // maximum message length for PvPGN users
uint32_t m_HostCounterID; // the host counter ID to identify players from this realm
uint32_t m_LastDisconnectedTime; // GetTime when we were last disconnected from battle.net
uint32_t m_LastConnectionAttemptTime; // GetTime when we last attempted to connect to battle.net
uint32_t m_LastNullTime; // GetTime when the last null packet was sent for detecting disconnects
uint32_t m_LastOutPacketTicks; // GetTicks when the last packet was sent for the m_OutPackets queue
uint32_t m_LastOutPacketSize;
uint32_t m_LastPacketReceivedTicks; // GetTicks when we last received a packet from the bnet server
uint32_t m_LastCommandTicks; // GetTicks when we last sent a command that should receive a response
uint32_t m_LastAdminRefreshTime; // GetTime when the admin list was last refreshed from the database
bool m_FirstConnect; // if we haven't tried to connect to battle.net yet
bool m_WaitingToConnect; // if we're waiting to reconnect to battle.net after being disconnected
bool m_LoggedIn; // if we've logged into battle.net or not
bool m_InChat; // if we've entered chat or not (but we're not necessarily in a chat channel yet)
bool m_HoldFriends; // whether to auto hold friends when creating a game or not
bool m_HoldClan; // whether to auto hold clan members when creating a game or not
bool m_PublicCommands; // whether to allow public commands or not
bool m_LastInviteCreation; // whether the last invite received was for a clan creation (else, it was for invitation response)
public:
CBNET( CGHost *nGHost, string nServer, string nServerAlias, string nBNLSServer, uint16_t nBNLSPort, uint32_t nBNLSWardenCookie, string nCDKeyROC, string nCDKeyTFT, string nCountryAbbrev, string nCountry, uint32_t nLocaleID, string nUserName, string nUserPassword, string nKeyOwnerName, string nFirstChannel, string nRootAdmin, char nCommandTrigger, bool nHoldFriends, bool nHoldClan, bool nPublicCommands, unsigned char nWar3Version, BYTEARRAY nEXEVersion, BYTEARRAY nEXEVersionHash, string nPasswordHashType, string nPVPGNRealmName, uint32_t nMaxMessageLength, uint32_t nHostCounterID );
~CBNET( );
bool GetExiting( ) { return m_Exiting; }
string GetServer( ) { return m_Server; }
string GetServerAlias( ) { return m_ServerAlias; }
string GetCDKeyROC( ) { return m_CDKeyROC; }
string GetCDKeyTFT( ) { return m_CDKeyTFT; }
string GetUserName( ) { return m_UserName; }
string GetUserPassword( ) { return m_UserPassword; }
string GetFirstChannel( ) { return m_FirstChannel; }
string GetCurrentChannel( ) { return m_CurrentChannel; }
string GetRootAdmin( ) { return m_RootAdmin; }
char GetCommandTrigger( ) { return m_CommandTrigger; }
BYTEARRAY GetEXEVersion( ) { return m_EXEVersion; }
BYTEARRAY GetEXEVersionHash( ) { return m_EXEVersionHash; }
string GetPasswordHashType( ) { return m_PasswordHashType; }
string GetPVPGNRealmName( ) { return m_PVPGNRealmName; }
uint32_t GetHostCounterID( ) { return m_HostCounterID; }
bool GetLoggedIn( ) { return m_LoggedIn; }
bool GetInChat( ) { return m_InChat; }
bool GetHoldFriends( ) { return m_HoldFriends; }
bool GetHoldClan( ) { return m_HoldClan; }
bool GetPublicCommands( ) { return m_PublicCommands; }
uint32_t GetOutPacketsQueued( ) { return m_OutPackets.size( ); }
BYTEARRAY GetUniqueName( );
uint32_t GetReconnectTime( );
// processing functions
unsigned int SetFD( void *fd, void *send_fd, int *nfds );
bool Update( void *fd, void *send_fd );
void ExtractPackets( );
void ProcessPackets( );
void ProcessChatEvent( CIncomingChatEvent *chatEvent );
void BotCommand( string Message, string User, bool Whisper, bool ForceRoot );
void UxReconnected( );
// functions to send packets to battle.net
void SendJoinChannel( string channel );
void SendGetFriendsList( );
void SendGetClanList( );
void SendClanInvitation( string accountName );
void SendClanRemoveMember( string accountName );
void SendClanChangeRank( string accountName, CBNETProtocol::RankCode rank );
void SendClanSetMotd( string motd );
void SendClanAcceptInvite( bool accept );
void QueueEnterChat( );
void QueueChatCommand( string chatCommand );
void QueueChatCommand( string chatCommand, string user, bool whisper );
void QueueGameCreate( unsigned char state, string gameName, string hostName, CMap *map, CSaveGame *saveGame, uint32_t hostCounter );
void QueueGameRefresh( unsigned char state, string gameName, string hostName, CMap *map, CSaveGame *saveGame, uint32_t upTime, uint32_t hostCounter );
void QueueGameUncreate( );
void UnqueuePackets( unsigned char type );
void UnqueueChatCommand( string chatCommand );
void UnqueueGameRefreshes( );
// other functions
bool IsAdmin( string name );
bool IsRootAdmin( string name );
void AddAdmin( string name );
void RemoveAdmin( string name );
void HoldFriends( CBaseGame *game );
void HoldClan( CBaseGame *game );
};
#endif