1 /*
2  * Copyright (C) 1998  Mark Baysinger (mbaysng@ucsd.edu)
3  * Copyright (C) 1998,1999,2000  Ross Combs (rocombs@cs.nmsu.edu)
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 #ifndef INCLUDED_PACKET_TYPES
20 #define INCLUDED_PACKET_TYPES
21 
22 #ifdef JUST_NEED_TYPES
23 # include "common/field_sizes.h"
24 # include "common/init_protocol.h"
25 # include "common/bnet_protocol.h"
26 # include "common/anongame_protocol.h"
27 # include "common/file_protocol.h"
28 # include "common/bot_protocol.h"
29 # include "common/udp_protocol.h"
30 # include "common/d2game_protocol.h"
31 # include "d2cs/d2cs_protocol.h"
32 # include "d2cs/d2cs_d2gs_protocol.h"
33 # include "d2cs/d2cs_bnetd_protocol.h"
34 #else
35 # define JUST_NEED_TYPES
36 # include "common/field_sizes.h"
37 # include "common/init_protocol.h"
38 # include "common/bnet_protocol.h"
39 # include "common/anongame_protocol.h"
40 # include "common/file_protocol.h"
41 # include "common/bot_protocol.h"
42 # include "common/udp_protocol.h"
43 # include "common/d2game_protocol.h"
44 # include "d2cs/d2cs_protocol.h"
45 # include "d2cs/d2cs_d2gs_protocol.h"
46 # include "d2cs/d2cs_bnetd_protocol.h"
47 # undef JUST_NEED_TYPES
48 #endif
49 
50 typedef enum
51 {
52     packet_class_none,
53     packet_class_init,
54     packet_class_bnet,
55     packet_class_file,
56     packet_class_raw,
57     packet_class_udp,
58     packet_class_d2game,
59     packet_class_d2gs,
60     packet_class_d2cs,
61     packet_class_d2cs_bnetd,
62     packet_class_w3route
63 } t_packet_class;
64 
65 
66 typedef enum
67 {
68     packet_dir_from_client,
69     packet_dir_from_server
70 } t_packet_dir;
71 
72 
73 /* These aren't really packets so much as records in a TCP stream. They are variable-
74  * length structures which make up the Battle.net protocol. It is just easier to call
75  * them "packets".
76  */
77 typedef struct
78 {
79     unsigned int   ref;   /* reference count */
80     t_packet_class class;
81     unsigned int   flags; /* user-defined flags (used to mark UDP in bnproxy) */
82     unsigned int   len;   /* raw packets have no header, so we use this */
83 
84     /* next part looks just like it would on the network (no padding, byte for byte) */
85     union
86     {
87         char data[MAX_PACKET_SIZE];
88 
89         t_bnet_generic   bnet;
90         t_file_generic   file;
91         t_udp_generic    udp;
92         t_d2game_generic d2game;
93 	t_w3route_generic w3route;
94 
95 	t_client_initconn client_initconn;
96 
97         t_server_authreply1         server_authreply1;
98         t_server_authreq1           server_authreq1;
99         t_client_authreq1           client_authreq1;
100         t_server_authreply_109      server_authreply_109;
101         t_server_authreq_109        server_authreq_109;
102         t_client_authreq_109        client_authreq_109;
103         t_client_cdkey              client_cdkey;
104         t_server_cdkeyreply         server_cdkeyreply;
105         t_client_statsreq           client_statsreq;
106         t_server_statsreply         server_statsreply;
107         t_client_loginreq1          client_loginreq1;
108         t_server_loginreply1        server_loginreply1;
109         t_client_progident          client_progident;
110         t_client_progident2         client_progident2;
111         t_client_joinchannel        client_joinchannel;
112         t_server_channellist        server_channellist;
113         t_server_serverlist         server_serverlist;
114         t_server_message            server_message;
115         t_client_message            client_message;
116         t_client_gamelistreq        client_gamelistreq;
117         t_server_gamelistreply      server_gamelistreply;
118         t_client_udpok              client_udpok;
119         t_client_unknown_1b         client_unknown_1b;
120         t_client_startgame1         client_startgame1;
121         t_server_startgame1_ack     server_startgame1_ack;
122         t_client_startgame3         client_startgame3;
123         t_server_startgame3_ack     server_startgame3_ack;
124         t_client_startgame4         client_startgame4;
125         t_server_startgame4_ack     server_startgame4_ack;
126         t_client_leavechannel       client_leavechannel;
127         t_client_closegame          client_closegame;
128         t_client_mapauthreq1        client_mapauthreq1;
129         t_server_mapauthreply1      server_mapauthreply1;
130         t_client_mapauthreq2        client_mapauthreq2;
131         t_server_mapauthreply2      server_mapauthreply2;
132         t_client_ladderreq          client_ladderreq;
133         t_server_ladderreply        server_ladderreply;
134 	t_client_laddersearchreq    client_laddersearchreq;
135 	t_server_laddersearchreply  server_laddersearchreply;
136         t_client_adreq              client_adreq;
137         t_server_adreply            server_adreply;
138         t_client_adack              client_adack;
139 	t_client_adclick            client_adclick;
140 	t_client_adclick2           client_adclick2;
141 	t_server_adclickreply2      server_adclickreply2;
142         t_client_game_report        client_gamerep;
143         t_server_sessionkey1        server_sessionkey1;
144         t_server_sessionkey2        server_sessionkey2;
145         t_client_createacctreq1     client_createacctreq1;
146         t_server_createacctreply1   server_createacctreply1;
147         t_client_changepassreq      client_changepassreq;
148         t_server_changepassack      server_changepassack;
149         t_client_iconreq            client_iconreq;
150         t_server_iconreply          server_iconreply;
151         t_client_fileinforeq        client_fileinforeq;
152         t_server_fileinforeply      server_fileinforeply;
153         t_client_statsupdate        client_statsupdate;
154         t_client_countryinfo1       client_countryinfo1;
155         t_client_countryinfo_109    client_countryinfo_109;
156         t_client_unknown_2b         client_unknown_2b;
157         t_client_compinfo1          client_compinfo1;
158         t_client_compinfo2          client_compinfo2;
159         t_server_compreply          server_compreply;
160         t_server_echoreq            server_echoreq;
161         t_client_echoreply          client_echoreply;
162         t_client_playerinforeq      client_playerinforeq;
163         t_server_playerinforeply    server_playerinforeply;
164 	t_client_pingreq            client_pingreq;
165 	t_server_pingreply          server_pingreply;
166         t_client_cdkey2             client_cdkey2;
167         t_server_cdkeyreply2        server_cdkeyreply2;
168         t_client_cdkey3             client_cdkey3;
169         t_server_cdkeyreply3        server_cdkeyreply3;
170         t_server_regsnoopreq        server_regsnoopreq;
171         t_client_regsnoopreply      client_regsnoopreply;
172         t_client_realmlistreq       client_realmlistreq;
173         t_client_realmlistreq_110   client_realmlistreq_110;
174         t_server_realmlistreply     server_realmlistreply;
175         t_server_realmlistreply_110 server_realmlistreply_110;
176         t_client_profilereq         client_profilereq;
177         t_server_profilereply       server_profilereply;
178         t_client_realmjoinreq_109   client_realmjoinreq_109;
179         t_server_realmjoinreply_109 server_realmjoinreply_109;
180         t_client_unknown_37         client_unknown_37;
181         t_server_unknown_37         server_unknown_37;
182         t_client_unknown_39         client_unknown_39;
183         t_client_loginreq2          client_loginreq2;
184         t_server_loginreply2        server_loginreply2;
185         t_client_loginreq_w3          client_loginreq_w3;
186         t_server_loginreply_w3        server_loginreply_w3;
187 	t_client_createacctreq2     client_createacctreq2;
188 	t_server_createacctreply2   server_createacctreply2;
189 	t_client_changegameport	   client_changegameport;
190 	t_client_file_req          client_file_req;
191 	t_server_file_reply        server_file_reply;
192 
193 	t_server_file_unknown1	   server_file_unknown1;
194 	t_client_file_req2         client_file_req2;
195 	t_client_file_req3         client_file_req3;
196 
197 	t_server_udptest           server_udptest;
198 	t_client_udpping           client_udpping;
199 	t_client_sessionaddr1      client_sessionaddr1;
200 	t_client_sessionaddr2      client_sessionaddr2;
201 
202 	t_client_motd_w3           client_motd_w3;
203 	t_server_motd_w3           server_motd_w3;
204 	t_client_logonproofreq     client_logonproofreq;
205 	t_server_logonproofreply   server_logonproofreply;
206 	t_client_createaccount_w3  client_createaccount_w3;
207 	t_server_createaccount_w3  server_createaccount_w3;
208 	t_client_findanongame      client_findanongame;
209 	t_client_findanongame_at   client_findanongame_at;
210 	t_client_findanongame_at_inv   client_findanongame_at_inv;
211 
212 
213 	t_server_findanongame_playgame_cancel		server_findanongame_playgame_cancel;
214 	t_server_anongame_found		server_anongame_found;
215         t_d2cs_bnetd_generic            d2cs_bnetd;
216         t_bnetd_d2cs_authreq            bnetd_d2cs_authreq;
217         t_d2cs_bnetd_authreply          d2cs_bnetd_authreply;
218         t_bnetd_d2cs_authreply          bnetd_d2cs_authreply;
219         t_d2cs_bnetd_accountloginreq    d2cs_bnetd_accountloginreq;
220         t_bnetd_d2cs_accountloginreply  bnetd_d2cs_accountloginreply;
221         t_d2cs_bnetd_charloginreq       d2cs_bnetd_charloginreq;
222         t_bnetd_d2cs_charloginreply     bnetd_d2cs_charloginreply;
223 	t_bnetd_d2cs_gameinforeq	bnetd_d2cs_gameinforeq;
224 	t_d2cs_bnetd_gameinforeply	d2cs_bnetd_gameinforeply;
225 
226         t_d2cs_d2gs_generic             d2cs_d2gs;
227         t_d2cs_d2gs_authreq             d2cs_d2gs_authreq;
228         t_d2gs_d2cs_authreply           d2gs_d2cs_authreply;
229         t_d2cs_d2gs_authreply           d2cs_d2gs_authreply;
230 	t_d2cs_d2gs_setinitinfo         d2cs_d2gs_setinitinfo;
231 	t_d2cs_d2gs_setgsinfo           d2cs_d2gs_setgsinfo;
232         t_d2gs_d2cs_setgsinfo           d2gs_d2cs_setgsinfo;
233         t_d2cs_d2gs_creategamereq       d2cs_d2gs_creategamereq;
234         t_d2gs_d2cs_creategamereply     d2gs_d2cs_creategamereply;
235         t_d2cs_d2gs_joingamereq         d2cs_d2gs_joingamereq;
236         t_d2gs_d2cs_joingamereply       d2gs_d2cs_joingamereply;
237         t_d2gs_d2cs_updategameinfo      d2gs_d2cs_updategameinfo;
238         t_d2gs_d2cs_closegame           d2gs_d2cs_closegame;
239         t_d2cs_d2gs_echoreq             d2cs_d2gs_echoreq;
240         t_d2gs_d2cs_echoreply           d2gs_d2cs_echoreply;
241 	t_d2cs_d2gs_control             d2cs_d2gs_control;
242 	t_d2cs_d2gs_setconffile			d2cs_d2gs_setconffile;
243 
244         t_d2cs_client_generic           d2cs_client;
245         t_client_d2cs_loginreq          client_d2cs_loginreq;
246         t_d2cs_client_loginreply        d2cs_client_loginreply;
247         t_client_d2cs_createcharreq     client_d2cs_createcharreq;
248         t_d2cs_client_createcharreply   d2cs_client_createcharreply;
249         t_client_d2cs_creategamereq     client_d2cs_creategamereq;
250         t_d2cs_client_creategamereply   d2cs_client_creategamereply;
251         t_client_d2cs_joingamereq       client_d2cs_joingamereq;
252         t_d2cs_client_joingamereply     d2cs_client_joingamereply;
253         t_client_d2cs_gamelistreq       client_d2cs_gamelistreq;
254         t_d2cs_client_gamelistreply     d2cs_client_gamelistreply;
255         t_client_d2cs_gameinforeq       client_d2cs_gameinforeq;
256         t_d2cs_client_gameinforeply     d2cs_client_gameinforeply;
257         t_client_d2cs_charloginreq      client_d2cs_charloginreq;
258         t_d2cs_client_charloginreply    d2cs_client_charloginreply;
259         t_client_d2cs_deletecharreq     client_d2cs_deletecharreq;
260         t_d2cs_client_deletecharreply   d2cs_client_deletecharreply;
261         t_client_d2cs_ladderreq         client_d2cs_ladderreq;
262         t_d2cs_client_ladderreply       d2cs_client_ladderreply;
263         t_client_d2cs_motdreq           client_d2cs_motdreq;
264         t_d2cs_client_motdreply         d2cs_client_motdreply;
265         t_client_d2cs_cancelcreategame  client_d2cs_cancelcreategame;
266         t_d2cs_client_creategamewait    d2cs_client_creategamewait;
267         t_client_d2cs_charladderreq     client_d2cs_charladderreq;
268         t_client_d2cs_charlistreq       client_d2cs_charlistreq;
269         t_d2cs_client_charlistreply     d2cs_client_charlistreply;
270         t_client_d2cs_charlistreq_110   client_d2cs_charlistreq_110;
271         t_d2cs_client_charlistreply_110 d2cs_client_charlistreply_110;
272         t_client_d2cs_convertcharreq    client_d2cs_convertcharreq;
273         t_d2cs_client_convertcharreply  d2cs_client_convertcharreply;
274 
275 	t_client_friendslistreq		client_friendslistreq;
276 	t_server_friendslistreply	server_friendslistreply;
277 	t_client_friendinforeq		client_friendinforeq;
278 	t_server_friendinforeply	server_friendinforeply;
279 	t_server_friendadd_ack		server_friendadd_ack;
280 	t_server_frienddel_ack		server_frienddel_ack;
281 	t_server_friendmove_ack		server_friendmove_ack;
282 
283 	t_client_arrangedteam_friendscreen	client_arrangedteam_friendscreen;
284 	t_server_arrangedteam_friendscreen	server_arrangedteam_friendscreen;
285 	t_client_arrangedteam_invite_friend	client_arrangedteam_invite_friend;
286 	t_server_arrangedteam_invite_friend_ack	server_arrangedteam_invite_friend_ack;
287 	t_server_arrangedteam_send_invite	server_arrangedteam_send_invite;
288 	t_client_arrangedteam_accept_invite    client_arrangedteam_accept_invite;
289 	t_client_arrangedteam_accept_decline_invite    client_arrangedteam_accept_decline_invite;
290 	t_server_arrangedteam_member_decline    server_arrangedteam_member_decline;
291 	t_client_findanongame_profile		client_findanongame_profile;
292 
293 	t_server_findanongame_profile2		server_findanongame_profile2;
294 
295 	t_client_w3route_req			client_w3route_req;
296 	t_server_w3route_ack			server_w3route_ack;
297 	t_server_w3route_playerinfo		server_w3route_playerinfo;
298 	t_server_w3route_levelinfo		server_w3route_levelinfo;
299 	t_server_w3route_startgame1		server_w3route_startgame1;
300 	t_server_w3route_startgame2		server_w3route_startgame2;
301 	t_client_w3route_loadingdone		client_w3route_loadingdone;
302 	t_server_w3route_loadingack		server_w3route_loadingack;
303 	t_client_w3route_connected		client_w3route_connected;
304 	t_server_w3route_echoreq		server_w3route_echoreq;
305 	t_client_w3route_abort			client_w3route_abort;
306 	t_server_w3route_ready			server_w3route_host;
307 	t_client_w3route_gameresult		client_w3route_gameresult;
308 
309 	t_client_findanongame_inforeq		client_findanongame_inforeq;
310 	t_server_findanongame_inforeply		server_findanongame_inforeply;
311 
312 	t_client_w3xp_clan_invitereq		client_w3xp_clan_invitereq;
313     	t_server_w3xp_clan_invitereply		server_w3xp_clan_invitereply;
314 	t_server_w3xp_clan_invitereq		server_w3xp_clan_invitereq;
315 	t_client_w3xp_clan_invitereply		client_w3xp_clan_invitereply;
316 	t_client_w3xp_clan_disbandreq		client_w3xp_clan_disbandreq;
317 	t_server_w3xp_clan_disbandreply		server_w3xp_clan_disbandreply;
318 	t_client_w3xp_clan_motdchg		client_w3xp_clan_motdchg;
319 	t_client_w3xp_clan_motdreq		client_w3xp_clan_motdreq;
320 	t_server_w3xp_clan_motdreply		server_w3xp_clan_motdreply;
321 	t_client_w3xp_clanmemberlist_req	client_w3xp_clanmemberlist_req;
322 	t_server_w3xp_clanmemberlist_reply	server_w3xp_clanmemberlist_reply;
323 	t_client_w3xp_clan_createreq		client_w3xp_clan_createreq;
324 	t_server_w3xp_clan_createreply		server_w3xp_clan_createreply;
325 	t_client_w3xp_clan_createinvitereq	client_w3xp_clan_createinvitereq;
326 	t_server_w3xp_clan_createinvitereply	server_w3xp_clan_createinvitereply;
327 	t_server_w3xp_clan_createinvitereq	server_w3xp_clan_createinvitereq;
328 	t_client_w3xp_clan_createinvitereply	client_w3xp_clan_createinvitereply;
329 	t_server_w3xp_clan_clanack		server_w3xp_clan_clanack;
330 	t_server_w3xp_clanmemberupdate          server_w3xp_clanmemberupdate;
331 	t_client_w3xp_clanmember_rankupdate_req   client_w3xp_clanmember_rankupdate_req;
332 	t_server_w3xp_clanmember_rankupdate_reply server_w3xp_clanmember_rankupdate_reply;
333 	t_client_w3xp_clanmember_remove_req     client_w3xp_clanmember_remove_req;
334 	t_server_w3xp_clanmember_remove_reply   server_w3xp_clanmember_remove_reply;
335 	t_client_w3xp_clan_membernewchiefreq    client_w3xp_clan_membernewchiefreq;
336 	t_server_w3xp_clan_membernewchiefreply  server_w3xp_clan_membernewchiefreply;
337 	t_server_w3xp_clanquitnotify            server_w3xp_clanquitnotify;
338 	t_server_w3xp_clanmember_removed_notify server_w3xp_clanmember_removed_notify;
339 
340 	t_server_findanongame_iconreply		server_findanongame_iconreply;
341 	t_client_changeclient			client_changeclient;
342 	t_client_anongame			client_anongame;
343 	t_server_anongame_search_reply		server_anongame_search_reply;
344 	t_client_anongame_tournament_request	client_anongame_tournament_request;
345 	t_server_anongame_tournament_reply	server_anongame_tournament_reply;
346 
347 	t_client_setemailreply			client_setemailreq;
348 	t_server_setemailreq			server_setemailreply;
349 	t_client_getpasswordreq			client_getpasswordreq;
350 	t_client_changeemailreq			client_changeemailreq;
351 	t_client_crashdump			client_crashdump;
352 	t_client_claninforeq			client_claninforeq;
353 	t_server_claninforeply			server_claninforeply;
354 	t_client_findanongame_profile_clan	client_findanongame_profile_clan;
355 	t_server_findanongame_profile_clan	server_findanongame_profile_clan;
356 	} u;
357 } t_packet;
358 
359 #endif
360 
361 /*****/
362 #ifndef JUST_NEED_TYPES
363 #ifndef INCLUDED_PACKET_PROTOS
364 #define INCLUDED_PACKET_PROTOS
365 
366 #include "common/lstr.h"
367 
368 extern t_packet * packet_create(t_packet_class class) ;
369 extern void packet_destroy(t_packet const * packet);
370 extern t_packet * packet_add_ref(t_packet * packet);
371 extern void packet_del_ref(t_packet * packet);
372 extern t_packet_class packet_get_class(t_packet const * packet);
373 extern char const * packet_get_class_str(t_packet const * packet);
374 extern int packet_set_class(t_packet * packet, t_packet_class class);
375 extern unsigned int packet_get_type(t_packet const * packet);
376 extern char const * packet_get_type_str(t_packet const * packet, t_packet_dir dir);
377 extern int packet_set_type(t_packet * packet, unsigned int type);
378 extern unsigned int packet_get_size(t_packet const * packet);
379 extern int packet_set_size(t_packet * packet, unsigned int size);
380 extern unsigned int packet_get_header_size(t_packet const * packet);
381 extern unsigned int packet_get_flags(t_packet const * packet);
382 extern int packet_set_flags(t_packet * packet, unsigned int flags);
383 extern int packet_append_string(t_packet * packet, char const * str);
384 extern int packet_append_ntstring(t_packet * packet, char const * str);
385 extern int packet_append_lstr(t_packet * packet, t_lstr *lstr);
386 extern int packet_append_data(t_packet * packet, void const * data, unsigned int len);
387 extern void const * packet_get_raw_data_const(t_packet const * packet, unsigned int offset);
388 extern void * packet_get_raw_data(t_packet * packet, unsigned int offset);
389 extern void * packet_get_raw_data_build(t_packet * packet, unsigned int offset);
390 extern char const * packet_get_str_const(t_packet const * packet, unsigned int offset, unsigned int maxlen);
391 extern void const * packet_get_data_const(t_packet const * packet, unsigned int offset, unsigned int len);
392 extern t_packet * packet_duplicate(t_packet const * src);
393 
394 #endif
395 #endif
396