/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/game_conv.c
ViewVC logotype

Contents of /pvpgn-1.7.4/src/bnetd/game_conv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: pvpgn_1-7-4-0_MIL, arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 /*
2 * Copyright (C) 1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu)
3 * Copyright (C) 1999,2000 Rob Crittenden (rcrit@greyoak.com)
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 #define GAME_INTERNAL_ACCESS
20 #include "common/setup_before.h"
21 #ifdef HAVE_STDDEF_H
22 # include <stddef.h>
23 #else
24 # ifndef NULL
25 # define NULL ((void *)0)
26 # endif
27 #endif
28 #ifdef STDC_HEADERS
29 # include <stdlib.h>
30 #else
31 # ifdef HAVE_MALLOC_H
32 # include <malloc.h>
33 # endif
34 #endif
35 #ifdef HAVE_STRING_H
36 # include <string.h>
37 #else
38 # ifdef HAVE_STRINGS_H
39 # include <strings.h>
40 # endif
41 #endif
42 #include "compat/strdup.h"
43 #include "compat/strsep.h"
44 #include "common/tag.h"
45 #include "common/eventlog.h"
46 #include "game.h"
47 #include "common/bnet_protocol.h"
48 #include "common/util.h"
49 #include "common/bn_type.h"
50 #include "common/xalloc.h"
51 #include "game_conv.h"
52 #include "common/setup_after.h"
53
54
55 extern t_game_type bngreqtype_to_gtype(t_clienttag clienttag, unsigned short bngtype)
56 {
57 char clienttag_str[5];
58
59 if (!clienttag)
60 {
61 eventlog(eventlog_level_error,__FUNCTION__,"got NULL clienttag");
62 return game_type_none;
63 }
64
65 if (clienttag==CLIENTTAG_WARCIIBNE_UINT)
66 {
67 switch (bngtype)
68 {
69 case CLIENT_GAMELISTREQ_ALL:
70 return game_type_all;
71 case CLIENT_GAMELISTREQ_TOPVBOT:
72 return game_type_topvbot;
73 case CLIENT_GAMELISTREQ_MELEE:
74 return game_type_melee;
75 case CLIENT_GAMELISTREQ_FFA:
76 return game_type_ffa;
77 case CLIENT_GAMELISTREQ_ONEONONE:
78 return game_type_oneonone;
79 case CLIENT_GAMELISTREQ_LADDER:
80 return game_type_ladder;
81 case CLIENT_GAMELISTREQ_IRONMAN:
82 return game_type_ironman;
83 case CLIENT_GAMELISTREQ_MAPSET:
84 return game_type_mapset;
85 default:
86 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
87 return game_type_none;
88 }
89 }
90 else if (clienttag==CLIENTTAG_DIABLO2DV_UINT ||
91 clienttag==CLIENTTAG_DIABLO2XP_UINT)
92 {
93 switch (bngtype)
94 {
95 case CLIENT_GAMELISTREQ_ALL:
96 return game_type_diablo2open;
97 default:
98 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo II bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
99 return game_type_none;
100 }
101 }
102 else if (clienttag==CLIENTTAG_DIABLORTL_UINT ||
103 clienttag==CLIENTTAG_DIABLOSHR_UINT)
104 {
105 switch (bngtype)
106 {
107 case CLIENT_GAMELISTREQ_ALL:
108 return game_type_all;
109 case CLIENT_GAMETYPE_DIABLO_1:
110 case CLIENT_GAMETYPE_DIABLO_2:
111 case CLIENT_GAMETYPE_DIABLO_3:
112 return game_type_diablo;
113 default:
114 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
115 return game_type_none;
116 }
117 }
118 else if (clienttag==CLIENTTAG_STARCRAFT_UINT ||
119 clienttag==CLIENTTAG_BROODWARS_UINT ||
120 clienttag==CLIENTTAG_SHAREWARE_UINT)
121 {
122 switch (bngtype)
123 {
124 case CLIENT_GAMELISTREQ_ALL:
125 return game_type_all;
126 case CLIENT_GAMELISTREQ_MELEE:
127 return game_type_melee;
128 case CLIENT_GAMELISTREQ_FFA:
129 return game_type_ffa;
130 case CLIENT_GAMELISTREQ_ONEONONE:
131 return game_type_oneonone;
132 case CLIENT_GAMELISTREQ_CTF:
133 return game_type_ctf;
134 case CLIENT_GAMELISTREQ_GREED:
135 return game_type_greed;
136 case CLIENT_GAMELISTREQ_SLAUGHTER:
137 return game_type_slaughter;
138 case CLIENT_GAMELISTREQ_SDEATH:
139 return game_type_sdeath;
140 case CLIENT_GAMELISTREQ_LADDER:
141 return game_type_ladder;
142 case CLIENT_GAMELISTREQ_MAPSET:
143 return game_type_mapset;
144 case CLIENT_GAMELISTREQ_TEAMMELEE:
145 return game_type_teammelee;
146 case CLIENT_GAMELISTREQ_TEAMFFA:
147 return game_type_teamffa;
148 case CLIENT_GAMELISTREQ_TEAMCTF:
149 return game_type_teamctf;
150 case CLIENT_GAMELISTREQ_PGL:
151 return game_type_pgl;
152 case CLIENT_GAMELISTREQ_TOPVBOT:
153 return game_type_topvbot;
154 default:
155 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
156 return game_type_none;
157 }
158 }
159 else if (clienttag==CLIENTTAG_WARCRAFT3_UINT ||
160 clienttag==CLIENTTAG_WAR3XP_UINT)
161 {
162 return game_type_all;
163 }
164 else
165 {
166 eventlog(eventlog_level_error,__FUNCTION__,"unknown game clienttag \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
167 return game_type_none;
168 }
169 }
170
171
172 extern t_game_type bngtype_to_gtype(t_clienttag clienttag, unsigned short bngtype)
173 {
174 char clienttag_str[5];
175 if (!clienttag)
176 {
177 eventlog(eventlog_level_error,__FUNCTION__,"got NULL clienttag");
178 return game_type_none;
179 }
180
181 if (clienttag==CLIENTTAG_WARCIIBNE_UINT)
182 {
183 switch (bngtype)
184 {
185 case CLIENT_GAMELISTREQ_TOPVBOT:
186 return game_type_topvbot;
187 case CLIENT_GAMELISTREQ_MELEE:
188 return game_type_melee;
189 case CLIENT_GAMELISTREQ_FFA:
190 return game_type_ffa;
191 case CLIENT_GAMELISTREQ_ONEONONE:
192 return game_type_oneonone;
193 case CLIENT_GAMELISTREQ_LADDER:
194 return game_type_ladder;
195 case CLIENT_GAMELISTREQ_IRONMAN:
196 return game_type_ironman;
197 case CLIENT_GAMELISTREQ_MAPSET:
198 return game_type_mapset;
199 default:
200 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
201 return game_type_none;
202 }
203 }
204 else if (clienttag==CLIENTTAG_DIABLO2DV_UINT ||
205 clienttag==CLIENTTAG_DIABLO2XP_UINT)
206 {
207 switch (bngtype)
208 {
209 case CLIENT_GAMETYPE_DIABLO2_OPEN_NORMAL:
210 case CLIENT_GAMETYPE_DIABLO2_OPEN_NIGHTMARE:
211 case CLIENT_GAMETYPE_DIABLO2_OPEN_HELL:
212 return game_type_diablo2open;
213 case CLIENT_GAMETYPE_DIABLO2_CLOSE:
214 return game_type_diablo2closed;
215 default:
216 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo II bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
217 return game_type_none;
218 }
219 }
220 else if (clienttag==CLIENTTAG_DIABLORTL_UINT ||
221 clienttag==CLIENTTAG_DIABLOSHR_UINT)
222 {
223 switch (bngtype)
224 {
225 case CLIENT_GAMETYPE_DIABLO_1:
226 case CLIENT_GAMETYPE_DIABLO_2:
227 case CLIENT_GAMETYPE_DIABLO_3:
228 return game_type_diablo;
229 default:
230 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
231 return game_type_none;
232 }
233 }
234 else if (clienttag==CLIENTTAG_STARCRAFT_UINT ||
235 clienttag==CLIENTTAG_BROODWARS_UINT ||
236 clienttag==CLIENTTAG_SHAREWARE_UINT)
237 {
238 switch (bngtype)
239 {
240 case CLIENT_GAMELISTREQ_ALL:
241 return game_type_all;
242 case CLIENT_GAMELISTREQ_MELEE:
243 return game_type_melee;
244 case CLIENT_GAMELISTREQ_FFA:
245 return game_type_ffa;
246 case CLIENT_GAMELISTREQ_ONEONONE:
247 return game_type_oneonone;
248 case CLIENT_GAMELISTREQ_CTF:
249 return game_type_ctf;
250 case CLIENT_GAMELISTREQ_GREED:
251 return game_type_greed;
252 case CLIENT_GAMELISTREQ_SLAUGHTER:
253 return game_type_slaughter;
254 case CLIENT_GAMELISTREQ_SDEATH:
255 return game_type_sdeath;
256 case CLIENT_GAMELISTREQ_LADDER:
257 return game_type_ladder;
258 case CLIENT_GAMELISTREQ_MAPSET:
259 return game_type_mapset;
260 case CLIENT_GAMELISTREQ_TEAMMELEE:
261 return game_type_teammelee;
262 case CLIENT_GAMELISTREQ_TEAMFFA:
263 return game_type_teamffa;
264 case CLIENT_GAMELISTREQ_TEAMCTF:
265 return game_type_teamctf;
266 case CLIENT_GAMELISTREQ_PGL:
267 return game_type_pgl;
268 case CLIENT_GAMELISTREQ_TOPVBOT:
269 return game_type_topvbot;
270 default:
271 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
272 return game_type_none;
273 }
274 }
275 else if (clienttag==CLIENTTAG_WARCRAFT3_UINT ||
276 clienttag==CLIENTTAG_WAR3XP_UINT)
277 {
278 return game_type_all;
279 }
280 else
281 {
282 eventlog(eventlog_level_error,__FUNCTION__,"unknown game clienttag \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),bngtype);
283 return game_type_none;
284 }
285 }
286
287
288 extern unsigned short gtype_to_bngtype(t_game_type gtype)
289 {
290 switch (gtype)
291 {
292 case game_type_all:
293 return CLIENT_GAMELISTREQ_ALL;
294 case game_type_melee:
295 return CLIENT_GAMELISTREQ_MELEE;
296 case game_type_ffa:
297 return CLIENT_GAMELISTREQ_FFA;
298 case game_type_oneonone:
299 return CLIENT_GAMELISTREQ_ONEONONE;
300 case game_type_ctf:
301 return CLIENT_GAMELISTREQ_CTF;
302 case game_type_greed:
303 return CLIENT_GAMELISTREQ_GREED;
304 case game_type_slaughter:
305 return CLIENT_GAMELISTREQ_SLAUGHTER;
306 case game_type_sdeath:
307 return CLIENT_GAMELISTREQ_SDEATH;
308 case game_type_ladder:
309 return CLIENT_GAMELISTREQ_LADDER;
310 case game_type_mapset:
311 return CLIENT_GAMELISTREQ_MAPSET;
312 case game_type_teammelee:
313 return CLIENT_GAMELISTREQ_TEAMMELEE;
314 case game_type_teamffa:
315 return CLIENT_GAMELISTREQ_TEAMFFA;
316 case game_type_teamctf:
317 return CLIENT_GAMELISTREQ_TEAMCTF;
318 case game_type_pgl:
319 return CLIENT_GAMELISTREQ_PGL;
320 case game_type_topvbot:
321 return CLIENT_GAMELISTREQ_TOPVBOT;
322 case game_type_diablo:
323 return CLIENT_GAMELISTREQ_DIABLO;
324 case game_type_diablo2open:
325 return SERVER_GAMELISTREPLY_TYPE_DIABLO2_OPEN;
326 case game_type_diablo2closed:
327 eventlog(eventlog_level_error,__FUNCTION__,"don't know how to list Diablo II");
328 return 0;
329 case game_type_anongame:
330 return 0;
331 case game_type_none:
332 default:
333 eventlog(eventlog_level_error,__FUNCTION__,"unknown game type %u",(unsigned int)gtype);
334 return 0xffff;
335 }
336 }
337
338
339 extern t_game_option bngoption_to_goption(t_clienttag clienttag, t_game_type gtype, unsigned short bngoption)
340 {
341 char clienttag_str[5];
342
343 if (!clienttag)
344 {
345 eventlog(eventlog_level_error,__FUNCTION__,"got NULL clienttag");
346 return game_option_none;
347 }
348
349 if (clienttag==CLIENTTAG_WARCIIBNE_UINT)
350 {
351 switch (gtype)
352 {
353 case game_type_topvbot:
354 switch (bngoption)
355 {
356 case CLIENT_STARTGAME4_OPTION_TOPVBOT_1:
357 return game_option_topvbot_1;
358 case CLIENT_STARTGAME4_OPTION_TOPVBOT_2:
359 return game_option_topvbot_2;
360 case CLIENT_STARTGAME4_OPTION_TOPVBOT_3:
361 return game_option_topvbot_3;
362 case CLIENT_STARTGAME4_OPTION_TOPVBOT_4:
363 return game_option_topvbot_4;
364 case CLIENT_STARTGAME4_OPTION_TOPVBOT_5:
365 return game_option_topvbot_5;
366 case CLIENT_STARTGAME4_OPTION_TOPVBOT_6:
367 return game_option_topvbot_6;
368 case CLIENT_STARTGAME4_OPTION_TOPVBOT_7:
369 return game_option_topvbot_7;
370 default:
371 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
372 return game_option_none;
373 }
374 case game_type_melee:
375 switch (bngoption)
376 {
377 case CLIENT_STARTGAME4_OPTION_MELEE_NORMAL:
378 return game_option_melee_normal;
379 default:
380 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
381 return game_option_none;
382 }
383 case game_type_ffa:
384 switch (bngoption)
385 {
386 case CLIENT_STARTGAME4_OPTION_FFA_NORMAL:
387 return game_option_ffa_normal;
388 default:
389 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
390 return game_option_none;
391 }
392 case game_type_oneonone:
393 switch (bngoption)
394 {
395 case CLIENT_STARTGAME4_OPTION_ONEONONE_NORMAL:
396 return game_option_oneonone_normal;
397 default:
398 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
399 return game_option_none;
400 }
401 case game_type_ladder:
402 switch (bngoption)
403 {
404 case CLIENT_STARTGAME4_OPTION_LADDER_COUNTASLOSS:
405 return game_option_ladder_countasloss;
406 case CLIENT_STARTGAME4_OPTION_LADDER_NOPENALTY:
407 return game_option_ladder_nopenalty;
408 default:
409 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
410 return game_option_none;
411 }
412 case game_type_ironman:
413 switch (bngoption)
414 {
415 default:
416 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
417 return game_option_none;
418 }
419 case game_type_mapset:
420 switch (bngoption)
421 {
422 case CLIENT_STARTGAME4_OPTION_MAPSET_NORMAL:
423 return game_option_mapset_normal;
424 default:
425 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
426 return game_option_none;
427 }
428 default:
429 eventlog(eventlog_level_error,__FUNCTION__,"unknown Warcraft II game type \"%s\" %u",tag_uint_to_str(clienttag_str,clienttag),(unsigned int)gtype);
430 return game_option_none;
431 }
432 }
433 else if (clienttag==CLIENTTAG_DIABLO2DV_UINT ||
434 clienttag==CLIENTTAG_DIABLO2XP_UINT)
435 {
436 switch (gtype)
437 {
438 case game_type_diablo2open:
439 switch (bngoption)
440 {
441 case CLIENT_STARTGAME4_OPTION_NONE: /* FIXME: really? */
442 return game_option_none;
443 default:
444 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
445 return game_option_none;
446 }
447 case game_type_diablo2closed:
448 switch (bngoption)
449 {
450 case CLIENT_STARTGAME4_OPTION_NONE: /* FIXME: really? */
451 return game_option_none;
452 default:
453 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo II bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
454 return game_option_none;
455 }
456 default:
457 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo II game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),(unsigned int)gtype);
458 return game_option_none;
459 }
460 }
461 else if (clienttag==CLIENTTAG_DIABLORTL_UINT ||
462 clienttag==CLIENTTAG_DIABLOSHR_UINT)
463 {
464 switch (gtype)
465 {
466 case game_type_diablo:
467 switch (bngoption)
468 {
469 default:
470 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
471 return game_option_none;
472 }
473 default:
474 eventlog(eventlog_level_error,__FUNCTION__,"unknown Diablo game type \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),(unsigned int)gtype);
475 return game_option_none;
476 }
477 }
478 else if (clienttag==CLIENTTAG_STARCRAFT_UINT ||
479 clienttag==CLIENTTAG_BROODWARS_UINT ||
480 clienttag==CLIENTTAG_SHAREWARE_UINT)
481 {
482 switch (gtype)
483 {
484 case game_type_melee:
485 switch (bngoption)
486 {
487 case CLIENT_STARTGAME4_OPTION_MELEE_NORMAL:
488 return game_option_melee_normal;
489 default:
490 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
491 return game_option_none;
492 }
493 case game_type_ffa:
494 switch (bngoption)
495 {
496 case CLIENT_STARTGAME4_OPTION_FFA_NORMAL:
497 return game_option_ffa_normal;
498 default:
499 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
500 return game_option_none;
501 }
502 case game_type_oneonone:
503 switch (bngoption)
504 {
505 case CLIENT_STARTGAME4_OPTION_ONEONONE_NORMAL:
506 return game_option_oneonone_normal;
507 default:
508 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
509 return game_option_none;
510 }
511 case game_type_ctf:
512 switch (bngoption)
513 {
514 case CLIENT_STARTGAME4_OPTION_CTF_NORMAL:
515 return game_option_ctf_normal;
516 default:
517 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
518 return game_option_none;
519 }
520 case game_type_greed:
521 switch (bngoption)
522 {
523 case CLIENT_STARTGAME4_OPTION_GREED_10000:
524 return game_option_greed_10000;
525 case CLIENT_STARTGAME4_OPTION_GREED_7500:
526 return game_option_greed_7500;
527 case CLIENT_STARTGAME4_OPTION_GREED_5000:
528 return game_option_greed_5000;
529 case CLIENT_STARTGAME4_OPTION_GREED_2500:
530 return game_option_greed_2500;
531 default:
532 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
533 return game_option_none;
534 }
535 case game_type_slaughter:
536 switch (bngoption)
537 {
538 case CLIENT_STARTGAME4_OPTION_SLAUGHTER_60:
539 return game_option_slaughter_60;
540 case CLIENT_STARTGAME4_OPTION_SLAUGHTER_45:
541 return game_option_slaughter_45;
542 case CLIENT_STARTGAME4_OPTION_SLAUGHTER_30:
543 return game_option_slaughter_30;
544 case CLIENT_STARTGAME4_OPTION_SLAUGHTER_15:
545 return game_option_slaughter_15;
546 default:
547 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
548 return game_option_none;
549 }
550 case game_type_sdeath:
551 switch (bngoption)
552 {
553 case CLIENT_STARTGAME4_OPTION_SDEATH_NORMAL:
554 return game_option_sdeath_normal;
555 default:
556 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
557 return game_option_none;
558 }
559 case game_type_ladder:
560 switch (bngoption)
561 {
562 case CLIENT_STARTGAME4_OPTION_LADDER_COUNTASLOSS:
563 return game_option_ladder_countasloss;
564 case CLIENT_STARTGAME4_OPTION_LADDER_NOPENALTY:
565 return game_option_ladder_nopenalty;
566 default:
567 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
568 return game_option_none;
569 }
570 case game_type_mapset:
571 switch (bngoption)
572 {
573 case CLIENT_STARTGAME4_OPTION_MAPSET_NORMAL:
574 return game_option_mapset_normal;
575 default:
576 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
577 return game_option_none;
578 }
579 case game_type_teammelee:
580 switch (bngoption)
581 {
582 case CLIENT_STARTGAME4_OPTION_TEAMMELEE_4:
583 return game_option_teammelee_4;
584 case CLIENT_STARTGAME4_OPTION_TEAMMELEE_3:
585 return game_option_teammelee_3;
586 case CLIENT_STARTGAME4_OPTION_TEAMMELEE_2:
587 return game_option_teammelee_2;
588 default:
589 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
590 return game_option_none;
591 }
592 case game_type_teamffa:
593 switch (bngoption)
594 {
595 case CLIENT_STARTGAME4_OPTION_TEAMFFA_4:
596 return game_option_teamffa_4;
597 case CLIENT_STARTGAME4_OPTION_TEAMFFA_3:
598 return game_option_teamffa_3;
599 case CLIENT_STARTGAME4_OPTION_TEAMFFA_2:
600 return game_option_teamffa_2;
601 default:
602 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
603 return game_option_none;
604 }
605 case game_type_teamctf:
606 switch (bngoption)
607 {
608 case CLIENT_STARTGAME4_OPTION_TEAMCTF_4:
609 return game_option_teamctf_4;
610 case CLIENT_STARTGAME4_OPTION_TEAMCTF_3:
611 return game_option_teamctf_3;
612 case CLIENT_STARTGAME4_OPTION_TEAMCTF_2:
613 return game_option_teamctf_2;
614 default:
615 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
616 return game_option_none;
617 }
618 case game_type_pgl:
619 switch (bngoption)
620 {
621 default:
622 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
623 return game_option_none;
624 }
625 case game_type_topvbot:
626 switch (bngoption)
627 {
628 case CLIENT_STARTGAME4_OPTION_TOPVBOT_1:
629 return game_option_topvbot_1;
630 case CLIENT_STARTGAME4_OPTION_TOPVBOT_2:
631 return game_option_topvbot_2;
632 case CLIENT_STARTGAME4_OPTION_TOPVBOT_3:
633 return game_option_topvbot_3;
634 case CLIENT_STARTGAME4_OPTION_TOPVBOT_4:
635 return game_option_topvbot_4;
636 case CLIENT_STARTGAME4_OPTION_TOPVBOT_5:
637 return game_option_topvbot_5;
638 case CLIENT_STARTGAME4_OPTION_TOPVBOT_6:
639 return game_option_topvbot_6;
640 case CLIENT_STARTGAME4_OPTION_TOPVBOT_7:
641 return game_option_topvbot_7;
642 default:
643 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft bnet game option for \"%s\" game \"%s\" %hu",tag_uint_to_str(clienttag_str,clienttag),game_type_get_str(gtype),bngoption);
644 return game_option_none;
645 }
646 case game_type_none:
647 default:
648 eventlog(eventlog_level_error,__FUNCTION__,"unknown Starcraft game type \"%s\" %u(%s)",tag_uint_to_str(clienttag_str,clienttag),(unsigned int)gtype,game_type_get_str(gtype));
649 return game_option_none;
650 }
651 }
652 else if (clienttag==CLIENTTAG_WARCRAFT3_UINT ||
653 clienttag==CLIENTTAG_WAR3XP_UINT)
654 {
655 return game_option_none;
656 }
657 else
658 {
659 eventlog(eventlog_level_error,__FUNCTION__,"unknown game tag_uint_to_str(clienttag_str,clienttag) \"%s\" %u",clienttag,(unsigned int)gtype);
660 return game_option_none;
661 }
662 }
663
664
665 extern t_game_result bngresult_to_gresult(unsigned int bngresult)
666 {
667 switch (bngresult)
668 {
669 case CLIENT_GAME_REPORT_RESULT_PLAYING:
670 return game_result_playing;
671 case CLIENT_GAME_REPORT_RESULT_WIN:
672 return game_result_win;
673 case CLIENT_GAME_REPORT_RESULT_LOSS:
674 return game_result_loss;
675 case CLIENT_GAME_REPORT_RESULT_DRAW:
676 return game_result_draw;
677 case CLIENT_GAME_REPORT_RESULT_DISCONNECT:
678 return game_result_disconnect;
679 case CLIENT_GAME_REPORT_RESULT_OBSERVER:
680 return game_result_observer;
681 default:
682 eventlog(eventlog_level_error,__FUNCTION__,"unknown bnet game result %u",bngresult);
683 return game_result_disconnect; /* bad packet? */
684 }
685 }
686
687
688 extern t_game_maptype bngmaptype_to_gmaptype(unsigned int bngmaptype)
689 {
690 switch (bngmaptype)
691 {
692 case CLIENT_MAPTYPE_SELFMADE:
693 return game_maptype_selfmade;
694 case CLIENT_MAPTYPE_BLIZZARD:
695 return game_maptype_blizzard;
696 case CLIENT_MAPTYPE_LADDER:
697 return game_maptype_ladder;
698 case CLIENT_MAPTYPE_PGL:
699 return game_maptype_pgl;
700 default:
701 return game_maptype_none;
702 }
703 }
704
705
706 extern t_game_tileset bngtileset_to_gtileset(unsigned int bngtileset)
707 {
708 switch (bngtileset)
709 {
710 case CLIENT_TILESET_BADLANDS:
711 return game_tileset_badlands;
712 case CLIENT_TILESET_SPACE:
713 return game_tileset_space;
714 case CLIENT_TILESET_INSTALLATION:
715 return game_tileset_installation;
716 case CLIENT_TILESET_ASHWORLD:
717 return game_tileset_ashworld;
718 case CLIENT_TILESET_JUNGLE:
719 return game_tileset_jungle;
720 case CLIENT_TILESET_DESERT:
721 return game_tileset_desert;
722 case CLIENT_TILESET_ICE:
723 return game_tileset_ice;
724 case CLIENT_TILESET_TWILIGHT:
725 return game_tileset_twilight;
726 default:
727 return game_tileset_none;
728 }
729 }
730
731
732 extern t_game_speed bngspeed_to_gspeed(unsigned int bngspeed)
733 {
734 switch (bngspeed)
735 {
736 case CLIENT_GAMESPEED_SLOWEST:
737 return game_speed_slowest;
738 case CLIENT_GAMESPEED_SLOWER:
739 return game_speed_slower;
740 case CLIENT_GAMESPEED_SLOW:
741 return game_speed_slow;
742 case CLIENT_GAMESPEED_NORMAL:
743 return game_speed_normal;
744 case CLIENT_GAMESPEED_FAST:
745 return game_speed_fast;
746 case CLIENT_GAMESPEED_FASTER:
747 return game_speed_faster;
748 case CLIENT_GAMESPEED_FASTEST:
749 return game_speed_fastest;
750 default:
751 return game_speed_none;
752 }
753 }
754
755 t_game_speed w3speed_to_gspeed(unsigned int w3speed)
756 {
757 switch (w3speed)
758 {
759 case 0: return game_speed_slow;
760 case 1: return game_speed_normal;
761 case 2: return game_speed_fast;
762 default: return game_speed_none;
763 }
764 }
765
766
767 extern t_game_difficulty bngdifficulty_to_gdifficulty(unsigned int bngdifficulty)
768 {
769 switch (bngdifficulty)
770 {
771 case CLIENT_DIFFICULTY_NORMAL:
772 return game_difficulty_normal;
773 case CLIENT_DIFFICULTY_NIGHTMARE:
774 return game_difficulty_nightmare;
775 case CLIENT_DIFFICULTY_HELL:
776 return game_difficulty_hell;
777 case CLIENT_DIFFICULTY_HARDCORE_NORMAL:
778 return game_difficulty_hardcore_normal;
779 case CLIENT_DIFFICULTY_HARDCORE_NIGHTMARE:
780 return game_difficulty_hardcore_nightmare;
781 case CLIENT_DIFFICULTY_HARDCORE_HELL:
782 return game_difficulty_hardcore_hell;
783 default:
784 return game_difficulty_none;
785 }
786 }
787
788
789 static const char * _w3_decrypt_mapinfo(const char *enc)
790 {
791 char *mapinfo;
792 char *dec;
793 unsigned pos;
794 unsigned char bitmask;
795
796 if (!(mapinfo = xstrdup(enc))) {
797 eventlog(eventlog_level_error, __FUNCTION__, "not enough memory to setup temporary buffer");
798 return NULL;
799 }
800
801 dec = mapinfo;
802 pos = 0;
803 bitmask = 0; /* stupid gcc warning */
804 while(*enc)
805 {
806 if (pos % 8)
807 {
808 *dec = *enc;
809 if (!(bitmask & 0x1)) (*dec)--;
810 dec++;
811 bitmask >>= 1;
812 } else
813 bitmask = *enc >> 1;
814 enc++;
815 pos++;
816 }
817 *dec = '\0';
818
819 return mapinfo;
820 }
821
822
823 extern int game_parse_info(t_game * game, char const * gameinfo)
824 {
825 t_clienttag clienttag;
826 char * save;
827 char * line1;
828 char * line2;
829 char * currtok;
830 char const * unknown;
831 char const * mapsize;
832 char const * maxplayers;
833 char const * speed;
834 char const * maptype;
835 char const * gametype;
836 char const * option;
837 char const * checksum;
838 char const * tileset;
839 char const * player;
840 char const * mapname;
841 unsigned int bngmapsize;
842 unsigned int bngmaxplayers;
843 unsigned int bngspeed;
844 unsigned int bngmaptype;
845 unsigned int bngtileset;
846
847 if (!game)
848 {
849 eventlog(eventlog_level_error,__FUNCTION__,"got NULL game");
850 return -1;
851 }
852 if (!gameinfo)
853 {
854 eventlog(eventlog_level_error,__FUNCTION__,"got NULL gameinfo");
855 return -1;
856 }
857
858 /*
859
860 BW 104:
861 9: recv class=bnet[0x01] type=CLIENT_STARTGAME4[0x1cff] length=74
862 0000: FF 1C 4A 00 00 00 00 00 00 00 00 00 09 00 01 00 ..J.............
863 0010: 00 00 00 00 01 00 00 00 4E 4F 50 45 4E 41 4C 54 ........NOPENALT
864 0020: 59 00 00 2C 34 34 2C 31 34 2C 2C 32 2C 39 2C 31 Y..,44,14,,2,9,1
865 0030: 2C 33 65 33 37 61 38 34 63 2C 33 2C 52 6F 73 73 ,3e37a84c,3,Ross
866 0040: 0D 41 73 68 72 69 67 6F 0D 00 .Ashrigo..
867
868 Diablo:
869 7: cli class=bnet[0x01] type=CLIENT_STARTGAME3[0x1aff] length=105
870 0000: FF 1A 69 00 01 00 00 00 00 00 00 00 00 00 00 00 ..i.............
871 0010: 0F 00 00 00 00 00 00 00 E0 17 00 00 61 73 64 66 ............asdf
872 0020: 61 73 64 66 61 73 64 66 61 73 64 66 32 00 61 73 asdfasdfasdf2.as
873 0030: 64 66 61 73 64 66 73 61 64 66 61 73 64 66 32 00 dfasdfsadfasdf2.
874 0040: 30 0D 7A 62 6E 7A 62 6E 7A 62 6E 0D 4C 54 52 44 0.zbnzbnzbn.LTRD
875 0050: 20 31 20 30 20 30 20 33 30 20 31 30 20 32 30 20 1 0 0 30 10 20
876 0060: 32 35 20 31 30 30 20 30 00 25 100 0.
877
878 10: recv class=bnet[0x01] type=CLIENT_STARTGAME3[0x1aff] length=72
879 0000: FF 1A 48 00 00 00 00 00 00 00 00 00 00 00 00 00 ..H.............
880 0010: 0F 00 00 00 00 00 00 00 E0 17 00 00 61 6E 73 00 ............ans.
881 0020: 00 30 0D 77 61 72 72 69 6F 72 0D 4C 54 52 44 20 .0.warrior.LTRD
882 0030: 31 20 30 20 30 20 33 30 20 31 30 20 32 30 20 32 1 0 0 30 10 20 2
883 0040: 35 20 31 30 30 20 30 00 5 100 0.
884
885
886 Warcraft:
887 4: srv class=bnet[0x01] type=SERVER_GAMELISTREPLY[0x09ff] length=524
888 0000: FF 09 0C 02 05 00 00 00 02 00 01 00 09 04 00 00 ................
889 0010: 02 00 17 E0 D0 C6 66 F0 00 00 00 00 00 00 00 00 ......f.........
890 0020: 04 00 00 00 74 00 00 00 48 65 79 77 6F 6F 64 73 ....t...Heywoods
891 0030: 20 47 4F 57 32 76 32 00 00 2C 2C 2C 36 2C 32 2C GOW2v2..,,,6,2,
892 0040: 32 2C 31 2C 31 39 37 33 64 35 66 32 2C 33 30 30 2,1,1973d5f2,300
893 0050: 30 2C 48 65 79 77 6F 6F 64 0D 47 61 72 64 65 6E 0,Heywood.Garden
894 0060: 20 6F 66 20 77 61 72 20 42 4E 45 2E 70 75 64 0D of war BNE.pud.
895 0070: 00 09 00 02 00 09 04 00 00 02 00 17 E0 CF 45 3E ..............E>
896 0080: 65 00 00 00 00 00 00 00 00 10 00 00 00 11 00 00 e...............
897 0090: 00 67 6F 77 20 6C 61 64 64 65 72 20 31 76 31 00 .gow ladder 1v1.
898 00A0: 00 2C 2C 2C 36 2C 32 2C 39 2C 32 2C 65 66 38 34 .,,,6,2,9,2,ef84
899 00B0: 33 61 35 33 2C 2C 77 63 73 63 6D 61 73 74 65 72 3a53,,wcscmaster
900 00C0: 0D 47 61 72 64 65 6E 20 6F 66 20 77 61 72 20 42 .Garden of war B
901 00D0: 4E 45 2E 70 75 64 0D 00 09 00 01 00 09 04 00 00 NE.pud..........
902 00E0: 02 00 17 E0 98 CE 7C E2 00 00 00 00 00 00 00 00 ......|.........
903 00F0: 04 00 00 00 4D 00 00 00 4C 61 64 64 65 72 20 46 ....M...Ladder F
904 0100: 46 41 20 6F 6E 6C 79 00 00 2C 2C 2C 36 2C 32 2C FA only..,,,6,2,
905 0110: 39 2C 31 2C 61 65 32 66 61 61 62 37 2C 2C 6B 69 9,1,ae2faab7,,ki
906 0120: 6C 6F 67 72 61 6D 0D 50 6C 61 69 6E 73 20 6F 66 logram.Plains of
907 0130: 20 73 6E 6F 77 20 42 4E 45 2E 70 75 64 0D 00 0F snow BNE.pud...
908 0140: 00 04 00 09 04 00 00 02 00 17 E0 C6 0B 13 3C 00 ..............<.
909 0150: 00 00 00 00 00 00 00 04 00 00 00 BE 00 00 00 4C ...............L
910 0160: 61 64 64 65 72 20 31 20 6F 6E 20 31 00 00 2C 2C adder 1 on 1..,,
911 0170: 2C 36 2C 32 2C 66 2C 34 2C 66 63 63 35 38 65 34 ,6,2,f,4,fcc58e4
912 0180: 61 2C 37 32 30 30 2C 49 63 65 36 39 62 75 72 67 a,7200,Ice69burg
913 0190: 0D 46 6F 72 65 73 74 20 54 72 61 69 6C 20 42 4E .Forest Trail BN
914 01A0: 45 2E 70 75 64 0D 00 0F 00 04 00 09 04 00 00 02 E.pud...........
915 01B0: 00 04 15 D1 F4 B6 6A 00 00 00 00 00 00 00 00 04 ......j.........
916 01C0: 00 00 00 C8 03 00 00 52 6F 63 6B 20 49 74 21 21 .......Rock It!!
917 01D0: 20 32 76 32 2B 00 00 2C 2C 2C 38 2C 31 2C 66 2C 2v2+..,,,8,1,f,
918 01E0: 34 2C 62 30 36 38 63 62 34 62 2C 66 30 30 30 2C 4,b068cb4b,f000,
919 01F0: 6E 75 66 74 63 72 6F 77 0D 43 72 6F 73 73 68 61 nuftcrow.Crossha
920 0200: 69 72 20 42 4E 45 2E 70 75 64 0D 00 ir BNE.pud..
921
922 FIXME:
923 Note the map size and max players fields are empty. Does WCII have different
924 map sizes and starting positions? If so, are they reported here?
925 Also note the map tileset is "3000". Maybe this isn't the tileset for WCII
926 but instead the starting gold or something.
927
928 FIXME:
929 Also, what is the upper player limit on WCII... 8 like on Starcraft?
930 */
931
932 if (!(clienttag = game_get_clienttag(game)))
933 {
934 eventlog(eventlog_level_error,__FUNCTION__,"NULL clienttag for game?");
935 return -1;
936 }
937
938 if (clienttag==CLIENTTAG_DIABLORTL_UINT ||
939 clienttag==CLIENTTAG_DIABLOSHR_UINT)
940 {
941 game_set_maxplayers(game,4);
942 eventlog(eventlog_level_debug,__FUNCTION__,"no gameinfo for Diablo");
943 return 0;
944 }
945 else if (clienttag==CLIENTTAG_DIABLO2DV_UINT ||
946 clienttag==CLIENTTAG_DIABLO2XP_UINT)
947 {
948 if ((game->type == game_type_diablo2closed) &&
949 (!strlen(gameinfo)))
950
951 {
952 /* D2 closed games are handled by d2cs so we can have only have a generic startgame4
953 without any info :(, this fix also a memory leak for description allocation */
954 game_set_difficulty(game,game_difficulty_none);
955 game_set_description(game, "");
956 }
957 else
958 {
959 char difficulty[2];
960 unsigned int bngdifficulty;
961
962 difficulty[0] = gameinfo[0];
963 difficulty[1] = '\0';
964 if (str_to_uint(difficulty,&bngdifficulty)<0)
965 {
966 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing difficulty) \"%s\"",gameinfo);
967 return -1;
968 }
969 game_set_difficulty(game,bngdifficulty);
970 game_set_description(game,&gameinfo[1]);
971
972 if ((game->type == game_type_diablo2closed) && (clienttag==CLIENTTAG_DIABLO2DV_UINT))
973 {
974 eventlog(eventlog_level_debug,__FUNCTION__,"D2 classic bug workarround needed (open games tagged as closed)");
975 game->type = game_type_diablo2open;
976 }
977 }
978 return 0;
979 }
980 else if (clienttag==CLIENTTAG_WARCRAFT3_UINT ||
981 clienttag==CLIENTTAG_WAR3XP_UINT)
982 {
983 /* Warcraft 3 game info format -- by Soar
984 0x00 -- 1 byte (char, Empty slots)
985 0x01 -- 8 bytes (char[8], Count of games created)
986
987 From offset 0x11 there is a bitmask byte before every 7 bytes, offset 0x09 to 0x10 also has bitmask 0.
988 Bit 0 corresponds to byte 0, bit 1 to byte 1, and so on.
989 Except offset 0x09, only Byte 1-7 contribute to the info data, bit 0 seems to be always 1;
990 Decoding these bytes works as follows:
991 If the corresponding bit is a '1' then the character is moved over directly.
992 If the corresponding bit is a '0' then subtract 1 from the character.
993 (We decode info data and remove the bitmask bytes from info data in following description)
994 0x09 -- 5 bytes (char[5], map options)
995 0x0e -- 1 bytes (0, seems to be a seperate sign)
996 0x0f -- 2 bytes (short, mapsize x)
997 0x11 -- 2 bytes (short, mapsize y)
998 0x13 -- 4 bytes (long, unknown, map checksum ?)
999 0x17 -- n bytes (string, mapname \0 terminated)
1000 0x17+n -- m bytes (string, game creator \0 terminated, but we already set this to game before, :P)
1001 0x17+n+m -- 2 bytes: \0 \0 (first \0 might be a reserved string for password, but blizzard didn't implement it, second \0 is the info string end sign)
1002 */
1003 const char *pstr;
1004
1005 if (!strlen(gameinfo))
1006 {
1007 eventlog(eventlog_level_info,__FUNCTION__, "got empty gameinfo (W3 client joining PG/AT)");
1008 return -1;
1009 }
1010
1011 if (strlen(gameinfo) < 0xf + 2 + 1 + 2 + 4) {
1012 eventlog(eventlog_level_error, __FUNCTION__, "got too short W3 mapinfo");
1013 return -1;
1014 }
1015 pstr = gameinfo + 9;
1016 pstr = _w3_decrypt_mapinfo(pstr);
1017 if (!pstr) return -1;
1018 /* after decryption we dont have the mask bytes anymore so offsets need
1019 * to be adjusted acordingly */
1020 game_set_speed(game,w3speed_to_gspeed(bn_byte_get(*((bn_byte*)(pstr)))));
1021 game_set_mapsize_x(game, bn_short_get(*((bn_short*)(pstr + 5))));
1022 game_set_mapsize_y(game, bn_short_get(*((bn_short*)(pstr + 7))));
1023 game_set_mapname(game, pstr + 13);
1024 xfree((void*)pstr);
1025
1026 return 0;
1027 }
1028
1029 /* otherwise it's Starcraft, Brood War, or Warcraft II */
1030 if (!(save = xstrdup(gameinfo)))
1031 {
1032 eventlog(eventlog_level_error,__FUNCTION__,"could not allocate memory for save");
1033 return -1;
1034 }
1035
1036 if (!(line1 = strtok(save,"\r"))) /* actual game info fields */
1037 {
1038 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing line1) \"%s\"",gameinfo);
1039 xfree(save);
1040 return -1;
1041 }
1042 if (!(line2 = strtok(NULL,"\r")))
1043 {
1044 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing player) \"%s\"",gameinfo);
1045 xfree(save);
1046 return -1;
1047 }
1048 /* is there room for another field after that? */
1049
1050 /*
1051 * This is the same as the normal strtok() function but it doesn't skip over
1052 * empty entries. The C-library strtok() will skip past entries like 12,,3
1053 * and rather than you being able to get "12", "", "3" you get "12", "3".
1054 * Since some values returned by the client contain these empty entries we
1055 * need this. Unlike strtok() all state is recorded in the first argument.
1056 */
1057 currtok = line1;
1058 if (!(unknown = strsep(&currtok,","))) /* skip past first field (always empty?) */
1059 {
1060 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing unknown)");
1061 xfree(save);
1062 return -1;
1063 }
1064 if (!(mapsize = strsep(&currtok,",")))
1065 {
1066 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing mapsize)");
1067 xfree(save);
1068 return -1;
1069 }
1070 if (!(maxplayers = strsep(&currtok,","))) /* for later use (FIXME: what is upper field, max observers?) */
1071 {
1072 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing maxplayers)");
1073 xfree(save);
1074 return -1;
1075 }
1076 if (!(speed = strsep(&currtok,",")))
1077 {
1078 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing speed)");
1079 xfree(save);
1080 return -1;
1081 }
1082 if (!(maptype = strsep(&currtok,",")))
1083 {
1084 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing maptype)");
1085 xfree(save);
1086 return -1;
1087 }
1088 if (!(gametype = strsep(&currtok,","))) /* this is set from another field */
1089 {
1090 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing gametype)");
1091 xfree(save);
1092 return -1;
1093 }
1094 if (!(option = strsep(&currtok,","))) /* this is set from another field */
1095 {
1096 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing option)");
1097 xfree(save);
1098 return -1;
1099 }
1100 if (!(checksum = strsep(&currtok,","))) /* FIXME */
1101 {
1102 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing checksum)");
1103 xfree(save);
1104 return -1;
1105 }
1106 if (!(tileset = strsep(&currtok,",")))
1107 {
1108 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing tileset)");
1109 xfree(save);
1110 return -1;
1111 }
1112 if (!(player = strsep(&currtok,",")))
1113 {
1114 eventlog(eventlog_level_error,__FUNCTION__,"bad gameinfo format (missing player)");
1115 xfree(save);
1116 return -1;
1117 }
1118
1119 mapname = line2; /* only one item on this line */
1120
1121 eventlog(eventlog_level_debug,__FUNCTION__,"got info \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", mapsize, maxplayers, speed, maptype, gametype, option, checksum, tileset, player, mapname);
1122
1123 /* The map size is determined by breaking the number into two pieces and
1124 * multiplying each piece by 32.
1125 * for example, 34 = (32*3) x (32*4) = 96 x 128
1126 */
1127 /* special handling for mapsize. empty is 256x256 */
1128 if ((mapsize[0]=='\0') || (str_to_uint(mapsize,&bngmapsize)<0))
1129 bngmapsize = 88; /* 256x256 */
1130 game_set_mapsize_x(game,(bngmapsize/10)*32);
1131 game_set_mapsize_y(game,(bngmapsize%10)*32);
1132
1133 /* special handling for maxplayers, empty is 8 */
1134 if ((maxplayers[0]=='\0') || (str_to_uint(maxplayers,&bngmaxplayers)<0))
1135 bngmaxplayers = 8;
1136 game_set_maxplayers(game,(bngmaxplayers%10));
1137
1138 /* special handling for gamespeed. empty is fast */
1139 if ((speed[0]=='\0') || ( str_to_uint(speed,&bngspeed)<0))
1140 bngspeed = CLIENT_GAMESPEED_FAST;
1141 game_set_speed(game,bngspeed_to_gspeed(bngspeed));
1142
1143 /* special handling for maptype. empty is self-made */
1144 if ((maptype[0]=='\0') || (str_to_uint(maptype,&bngmaptype)<0))
1145 bngmaptype = CLIENT_MAPTYPE_SELFMADE;
1146 game_set_maptype(game,bngmaptype_to_gmaptype(bngmaptype));
1147
1148 /* special handling for tileset. empty is badlands */
1149 if ((tileset[0]=='\0') || (str_to_uint(tileset,&bngtileset)<0))
1150 bngtileset = CLIENT_TILESET_BADLANDS;
1151 game_set_tileset(game,bngtileset_to_gtileset(bngtileset));
1152
1153 game_set_mapname(game,mapname);
1154
1155 xfree(save);
1156
1157 return 0;
1158 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1