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