-
Notifications
You must be signed in to change notification settings - Fork 6
/
gameprotocol.h
executable file
·256 lines (214 loc) · 8.95 KB
/
gameprotocol.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
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 GAMEPROTOCOL_H
#define GAMEPROTOCOL_H
//
// CGameProtocol
//
#define W3GS_HEADER_CONSTANT 247
#define GAME_NONE 0 // this case isn't part of the protocol, it's for internal use only
#define GAME_FULL 2
#define GAME_PUBLIC 16
#define GAME_PRIVATE 17
#define GAMETYPE_CUSTOM 1
#define GAMETYPE_BLIZZARD 9
#define PLAYERLEAVE_DISCONNECT 1
#define PLAYERLEAVE_LOST 7
#define PLAYERLEAVE_LOSTBUILDINGS 8
#define PLAYERLEAVE_WON 9
#define PLAYERLEAVE_DRAW 10
#define PLAYERLEAVE_OBSERVER 11
#define PLAYERLEAVE_LOBBY 13
#define PLAYERLEAVE_GPROXY 100
#define REJECTJOIN_FULL 9
#define REJECTJOIN_STARTED 10
#define REJECTJOIN_WRONGPASSWORD 27
#include "gameslot.h"
class CGamePlayer;
class CIncomingJoinPlayer;
class CIncomingAction;
class CIncomingChatPlayer;
class CIncomingMapSize;
class CGameProtocol
{
public:
CGHost *m_GHost;
enum Protocol {
W3GS_PING_FROM_HOST = 1, // 0x01
W3GS_SLOTINFOJOIN = 4, // 0x04
W3GS_REJECTJOIN = 5, // 0x05
W3GS_PLAYERINFO = 6, // 0x06
W3GS_PLAYERLEAVE_OTHERS = 7, // 0x07
W3GS_GAMELOADED_OTHERS = 8, // 0x08
W3GS_SLOTINFO = 9, // 0x09
W3GS_COUNTDOWN_START = 10, // 0x0A
W3GS_COUNTDOWN_END = 11, // 0x0B
W3GS_INCOMING_ACTION = 12, // 0x0C
W3GS_CHAT_FROM_HOST = 15, // 0x0F
W3GS_START_LAG = 16, // 0x10
W3GS_STOP_LAG = 17, // 0x11
W3GS_HOST_KICK_PLAYER = 28, // 0x1C
W3GS_REQJOIN = 30, // 0x1E
W3GS_LEAVEGAME = 33, // 0x21
W3GS_GAMELOADED_SELF = 35, // 0x23
W3GS_OUTGOING_ACTION = 38, // 0x26
W3GS_OUTGOING_KEEPALIVE = 39, // 0x27
W3GS_CHAT_TO_HOST = 40, // 0x28
W3GS_DROPREQ = 41, // 0x29
W3GS_SEARCHGAME = 47, // 0x2F (UDP/LAN)
W3GS_GAMEINFO = 48, // 0x30 (UDP/LAN)
W3GS_CREATEGAME = 49, // 0x31 (UDP/LAN)
W3GS_REFRESHGAME = 50, // 0x32 (UDP/LAN)
W3GS_DECREATEGAME = 51, // 0x33 (UDP/LAN)
W3GS_CHAT_OTHERS = 52, // 0x34
W3GS_PING_FROM_OTHERS = 53, // 0x35
W3GS_PONG_TO_OTHERS = 54, // 0x36
W3GS_MAPCHECK = 61, // 0x3D
W3GS_STARTDOWNLOAD = 63, // 0x3F
W3GS_MAPSIZE = 66, // 0x42
W3GS_MAPPART = 67, // 0x43
W3GS_MAPPARTOK = 68, // 0x44
W3GS_MAPPARTNOTOK = 69, // 0x45 - just a guess, received this packet after forgetting to send a crc in W3GS_MAPPART (f7 45 0a 00 01 02 01 00 00 00)
W3GS_PONG_TO_HOST = 70, // 0x46
W3GS_INCOMING_ACTION2 = 72 // 0x48 - received this packet when there are too many actions to fit in W3GS_INCOMING_ACTION
};
CGameProtocol( CGHost *nGHost );
~CGameProtocol( );
// receive functions
CIncomingJoinPlayer *RECEIVE_W3GS_REQJOIN( BYTEARRAY data );
uint32_t RECEIVE_W3GS_LEAVEGAME( BYTEARRAY data );
bool RECEIVE_W3GS_GAMELOADED_SELF( BYTEARRAY data );
CIncomingAction *RECEIVE_W3GS_OUTGOING_ACTION( BYTEARRAY data, unsigned char PID );
uint32_t RECEIVE_W3GS_OUTGOING_KEEPALIVE( BYTEARRAY data );
CIncomingChatPlayer *RECEIVE_W3GS_CHAT_TO_HOST( BYTEARRAY data );
bool RECEIVE_W3GS_SEARCHGAME( BYTEARRAY data, unsigned char war3Version );
CIncomingMapSize *RECEIVE_W3GS_MAPSIZE( BYTEARRAY data, BYTEARRAY mapSize );
uint32_t RECEIVE_W3GS_MAPPARTOK( BYTEARRAY data );
uint32_t RECEIVE_W3GS_PONG_TO_HOST( BYTEARRAY data );
// send functions
BYTEARRAY SEND_W3GS_PING_FROM_HOST( );
BYTEARRAY SEND_W3GS_SLOTINFOJOIN( unsigned char PID, BYTEARRAY port, BYTEARRAY externalIP, vector<CGameSlot> &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots );
BYTEARRAY SEND_W3GS_REJECTJOIN( uint32_t reason );
BYTEARRAY SEND_W3GS_PLAYERINFO( unsigned char PID, string name, BYTEARRAY externalIP, BYTEARRAY internalIP );
BYTEARRAY SEND_W3GS_PLAYERLEAVE_OTHERS( unsigned char PID, uint32_t leftCode );
BYTEARRAY SEND_W3GS_GAMELOADED_OTHERS( unsigned char PID );
BYTEARRAY SEND_W3GS_SLOTINFO( vector<CGameSlot> &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots );
BYTEARRAY SEND_W3GS_COUNTDOWN_START( );
BYTEARRAY SEND_W3GS_COUNTDOWN_END( );
BYTEARRAY SEND_W3GS_INCOMING_ACTION( queue<CIncomingAction *> actions, uint16_t sendInterval );
BYTEARRAY SEND_W3GS_CHAT_FROM_HOST( unsigned char fromPID, BYTEARRAY toPIDs, unsigned char flag, BYTEARRAY flagExtra, string message );
BYTEARRAY SEND_W3GS_START_LAG( vector<CGamePlayer *> players, uint32_t gameTicks );
BYTEARRAY SEND_W3GS_STOP_LAG( CGamePlayer *player, bool loadInGame = false );
BYTEARRAY SEND_W3GS_SEARCHGAME( bool TFT, unsigned char war3Version );
BYTEARRAY SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Version, BYTEARRAY mapGameType, BYTEARRAY mapFlags, BYTEARRAY mapWidth, BYTEARRAY mapHeight, string gameName, string hostName, uint32_t upTime, string mapPath, BYTEARRAY mapCRC, uint32_t slotsTotal, uint32_t slotsOpen, uint16_t port, uint32_t hostCounter, uint32_t entryKey );
BYTEARRAY SEND_W3GS_CREATEGAME( bool TFT, unsigned char war3Version );
BYTEARRAY SEND_W3GS_REFRESHGAME( uint32_t players, uint32_t playerSlots );
BYTEARRAY SEND_W3GS_DECREATEGAME( );
BYTEARRAY SEND_W3GS_MAPCHECK( string mapPath, BYTEARRAY mapSize, BYTEARRAY mapInfo, BYTEARRAY mapCRC, BYTEARRAY mapSHA1 );
BYTEARRAY SEND_W3GS_STARTDOWNLOAD( unsigned char fromPID );
BYTEARRAY SEND_W3GS_MAPPART( unsigned char fromPID, unsigned char toPID, uint32_t start, string *mapData );
BYTEARRAY SEND_W3GS_INCOMING_ACTION2( queue<CIncomingAction *> actions );
// other functions
private:
bool AssignLength( BYTEARRAY &content );
bool ValidateLength( BYTEARRAY &content );
BYTEARRAY EncodeSlotInfo( vector<CGameSlot> &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots );
};
//
// CIncomingJoinPlayer
//
class CIncomingJoinPlayer
{
private:
uint32_t m_HostCounter;
uint32_t m_EntryKey;
string m_Name;
BYTEARRAY m_InternalIP;
public:
CIncomingJoinPlayer( uint32_t nHostCounter, uint32_t nEntryKey, string nName, BYTEARRAY &nInternalIP );
~CIncomingJoinPlayer( );
uint32_t GetHostCounter( ) { return m_HostCounter; }
uint32_t GetEntryKey( ) { return m_EntryKey; }
string GetName( ) { return m_Name; }
BYTEARRAY GetInternalIP( ) { return m_InternalIP; }
};
//
// CIncomingAction
//
class CIncomingAction
{
private:
unsigned char m_PID;
BYTEARRAY m_CRC;
BYTEARRAY m_Action;
public:
CIncomingAction( unsigned char nPID, BYTEARRAY &nCRC, BYTEARRAY &nAction );
~CIncomingAction( );
unsigned char GetPID( ) { return m_PID; }
BYTEARRAY GetCRC( ) { return m_CRC; }
BYTEARRAY *GetAction( ) { return &m_Action; }
uint32_t GetLength( ) { return m_Action.size( ) + 3; }
};
//
// CIncomingChatPlayer
//
class CIncomingChatPlayer
{
public:
enum ChatToHostType
{
CTH_MESSAGE = 0, // a chat message
CTH_MESSAGEEXTRA = 1, // a chat message with extra flags
CTH_TEAMCHANGE = 2, // a team change request
CTH_COLOURCHANGE = 3, // a colour change request
CTH_RACECHANGE = 4, // a race change request
CTH_HANDICAPCHANGE = 5 // a handicap change request
};
private:
ChatToHostType m_Type;
unsigned char m_FromPID;
BYTEARRAY m_ToPIDs;
unsigned char m_Flag;
string m_Message;
unsigned char m_Byte;
BYTEARRAY m_ExtraFlags;
public:
CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, string nMessage );
CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, string nMessage, BYTEARRAY &nExtraFlags );
CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, unsigned char nByte );
~CIncomingChatPlayer( );
ChatToHostType GetType( ) { return m_Type; }
unsigned char GetFromPID( ) { return m_FromPID; }
BYTEARRAY GetToPIDs( ) { return m_ToPIDs; }
unsigned char GetFlag( ) { return m_Flag; }
string GetMessage( ) { return m_Message; }
unsigned char GetByte( ) { return m_Byte; }
BYTEARRAY GetExtraFlags( ) { return m_ExtraFlags; }
};
class CIncomingMapSize
{
private:
unsigned char m_SizeFlag;
uint32_t m_MapSize;
public:
CIncomingMapSize( unsigned char nSizeFlag, uint32_t nMapSize );
~CIncomingMapSize( );
unsigned char GetSizeFlag( ) { return m_SizeFlag; }
uint32_t GetMapSize( ) { return m_MapSize; }
};
#endif