| 1 | /* |
| 2 | * Copyright (C) 2004 CreepLord ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #include "common/setup_before.h" |
| 19 | #include "handle_anongame.h" |
| 20 | |
| 21 | #include <cstring> |
| 22 | #include <cstdio> |
| 23 | |
| 24 | #include "common/eventlog.h" |
| 25 | #include "common/bn_type.h" |
| 26 | #include "common/bnettime.h" |
| 27 | #include "common/tag.h" |
| 28 | #include "common/list.h" |
| 29 | |
| 30 | #include "clan.h" |
| 31 | #include "account.h" |
| 32 | #include "account_wrap.h" |
| 33 | #include "ladder.h" |
| 34 | #include "team.h" |
| 35 | #include "anongame.h" |
| 36 | #include "anongame_infos.h" |
| 37 | #include "server.h" |
| 38 | #include "tournament.h" |
| 39 | #include "channel.h" |
| 40 | #include "common/setup_after.h" |
| 41 | #include "icons.h" |
| 42 | |
| 43 | namespace pvpgn |
| 44 | { |
| 45 | |
| 46 | namespace bnetd |
| 47 | { |
| 48 | |
| 49 | /* option - handling function */ |
| 50 | |
| 51 | /* 0x00 */ /* PG style search - handle_anongame_search() in anongame.c */ |
| 52 | /* 0x01 */ /* server side packet sent from handle_anongame_search() in anongame.c */ |
| 53 | /* 0x02 */ static int _client_anongame_infos(t_connection * c, t_packet const * const packet); |
| 54 | /* 0x03 */ static int _client_anongame_cancel(t_connection * c); |
| 55 | /* 0x04 */ static int _client_anongame_profile(t_connection * c, t_packet const * const packet); |
| 56 | /* 0x05 */ /* AT style search - handle_anongame_search() in anongame.c */ |
| 57 | /* 0x06 */ /* AT style search (Inviter) handle_anongame_search() in anongame.c */ |
| 58 | /* 0x07 */ static int _client_anongame_tournament(t_connection * c, t_packet const * const packet); |
| 59 | /* 0x08 */ static int _client_anongame_profile_clan(t_connection * c, t_packet const * const packet); |
| 60 | /* 0x09 */ static int _client_anongame_get_icon(t_connection * c, t_packet const * const packet); |
| 61 | /* 0x0A */ static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet); |
| 62 | static int check_user_icon(t_account * account, const char * user_icon); |
| 63 | |
| 64 | /* misc functions used by _client_anongame_tournament() */ |
| 65 | static unsigned int _tournament_time_convert(unsigned int time); |
| 66 | |
| 67 | /* and now the functions */ |
| 68 | |
| 69 | static int _client_anongame_profile_clan(t_connection * c, t_packet const * const packet) |
| 70 | { |
| 71 | t_packet * rpacket; |
| 72 | int clantag; |
| 73 | int clienttag; |
| 74 | int count; |
| 75 | int temp; |
| 76 | t_clan * clan; |
| 77 | unsigned char rescount; |
| 78 | |
| 79 | if (packet_get_size(packet) < sizeof(t_client_findanongame_profile_clan)) |
| 80 | { |
| 81 | eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad ANONGAME_PROFILE_CLAN packet (expected {} bytes, got {})", conn_get_socket(c), sizeof(t_client_findanongame_profile_clan), packet_get_size(packet)); |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | clantag = bn_int_get(packet->u.client_findanongame_profile_clan.clantag); |
| 86 | clienttag = bn_int_get(packet->u.client_findanongame_profile_clan.clienttag); |
| 87 | count = bn_int_get(packet->u.server_findanongame_profile_clan.count); |
| 88 | clan = clanlist_find_clan_by_clantag(clantag); |
| 89 | |
| 90 | if ((rpacket = packet_create(packet_class_bnet))) |
| 91 | { |
| 92 | packet_set_size(rpacket, sizeof(t_server_findanongame_profile_clan)); |
| 93 | packet_set_type(rpacket, SERVER_FINDANONGAME_PROFILE_CLAN); |
| 94 | bn_byte_set(&rpacket->u.server_findanongame_profile_clan.option, CLIENT_FINDANONGAME_PROFILE_CLAN); |
| 95 | bn_int_set(&rpacket->u.server_findanongame_profile_clan.count, count); |
| 96 | rescount = 0; |
| 97 | |
| 98 | temp = 0; |
| 99 | packet_append_data(rpacket, &temp, 1); |
| 100 | /* |
| 101 | if (!(clan)) |
| 102 | { |
| 103 | temp = 0; |
| 104 | packet_append_data(rpacket, &temp, 1); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | temp = 0; |
| 109 | packet_append_data(rpacket, &temp, 1); |
| 110 | |
| 111 | /* UNDONE: need to add clan stuff here: |
| 112 | format: |
| 113 | bn_int ladder_tag (SNLC, 2NLC, 3NLC, 4NLC) |
| 114 | bn_int wins |
| 115 | bn_int losses |
| 116 | bn_byte rank |
| 117 | bn_byte progess bar |
| 118 | bn_int xp |
| 119 | bn_int rank |
| 120 | bn_byte 0x06 <-- random + 5 races |
| 121 | 6 times: |
| 122 | bn_int wins |
| 123 | bn_int losses |
| 124 | / |
| 125 | } |
| 126 | */ |
| 127 | |
| 128 | bn_byte_set(&rpacket->u.server_findanongame_profile_clan.rescount, rescount); |
| 129 | |
| 130 | |
| 131 | conn_push_outqueue(c, rpacket); |
| 132 | packet_del_ref(rpacket); |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int _client_anongame_profile(t_connection * c, t_packet const * const packet) |
| 139 | { |
| 140 | t_packet * rpacket; |
| 141 | char const * username; |
| 142 | int Count, i; |
| 143 | int temp; |
| 144 | t_account * account; |
| 145 | t_connection * dest_c; |
| 146 | t_clienttag ctag; |
| 147 | char clienttag_str[5]; |
| 148 | t_list * teamlist; |
| 149 | unsigned char teamcount; |
| 150 | unsigned char *atcountp; |
| 151 | t_elem * curr; |
| 152 | t_team * team; |
| 153 | t_bnettime bn_time; |
| 154 | bn_long ltime; |
| 155 | |
| 156 | |
| 157 | Count = bn_int_get(packet->u.client_findanongame.count); |
| 158 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] got a FINDANONGAME PROFILE packet", conn_get_socket(c)); |
| 159 | |
| 160 | if (!(username = packet_get_str_const(packet, sizeof(t_client_findanongame_profile), MAX_USERNAME_LEN))) |
| 161 | { |
| 162 | eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad FINDANONGAME_PROFILE (missing or too long username)", conn_get_socket(c)); |
| 163 | return -1; |
| 164 | } |
| 165 | |
| 166 | //If no account is found then break |
| 167 | if (!(account = accountlist_find_account(username))) |
| 168 | { |
| 169 | eventlog(eventlog_level_error, __FUNCTION__, "Could not get account - PROFILE"); |
| 170 | return -1; |
| 171 | } |
| 172 | |
| 173 | if (!(dest_c = connlist_find_connection_by_accountname(username))) { |
| 174 | eventlog(eventlog_level_debug, __FUNCTION__, "account is offline - try ll_clienttag"); |
| 175 | if (!(ctag = account_get_ll_clienttag(account))) return -1; |
| 176 | } |
| 177 | else |
| 178 | ctag = conn_get_clienttag(dest_c); |
| 179 | |
| 180 | eventlog(eventlog_level_info, __FUNCTION__, "Looking up {}'s {} Stats.", username, tag_uint_to_str(clienttag_str, ctag)); |
| 181 | |
| 182 | if (account_get_ladder_level(account, ctag, ladder_id_solo) <= 0 && |
| 183 | account_get_ladder_level(account, ctag, ladder_id_team) <= 0 && |
| 184 | account_get_ladder_level(account, ctag, ladder_id_ffa) <= 0 && |
| 185 | account_get_teams(account) == NULL) |
| 186 | { |
| 187 | eventlog(eventlog_level_info, __FUNCTION__, "{} does not have WAR3 Stats.", username); |
| 188 | if (!(rpacket = packet_create(packet_class_bnet))) |
| 189 | return -1; |
| 190 | packet_set_size(rpacket, sizeof(t_server_findanongame_profile2)); |
| 191 | packet_set_type(rpacket, SERVER_FINDANONGAME_PROFILE); |
| 192 | bn_byte_set(&rpacket->u.server_findanongame_profile2.option, CLIENT_FINDANONGAME_PROFILE); |
| 193 | bn_int_set(&rpacket->u.server_findanongame_profile2.count, Count); |
| 194 | bn_int_set(&rpacket->u.server_findanongame_profile2.icon, account_icon_to_profile_icon(account_get_user_icon(account, ctag), account, ctag)); |
| 195 | bn_byte_set(&rpacket->u.server_findanongame_profile2.rescount, 0); |
| 196 | temp = 0; |
| 197 | packet_append_data(rpacket, &temp, 2); |
| 198 | conn_push_outqueue(c, rpacket); |
| 199 | packet_del_ref(rpacket); |
| 200 | } |
| 201 | else // If they do have a profile then: |
| 202 | { |
| 203 | int solowins = account_get_ladder_wins(account, ctag, ladder_id_solo); |
| 204 | int sololoss = account_get_ladder_losses(account, ctag, ladder_id_solo); |
| 205 | int soloxp = account_get_ladder_xp(account, ctag, ladder_id_solo); |
| 206 | int sololevel = account_get_ladder_level(account, ctag, ladder_id_solo); |
| 207 | int solorank = account_get_ladder_rank(account, ctag, ladder_id_solo); |
| 208 | |
| 209 | int teamwins = account_get_ladder_wins(account, ctag, ladder_id_team); |
| 210 | int teamloss = account_get_ladder_losses(account, ctag, ladder_id_team); |
| 211 | int teamxp = account_get_ladder_xp(account, ctag, ladder_id_team); |
| 212 | int teamlevel = account_get_ladder_level(account, ctag, ladder_id_team); |
| 213 | int teamrank = account_get_ladder_rank(account, ctag, ladder_id_team); |
| 214 | |
| 215 | int ffawins = account_get_ladder_wins(account, ctag, ladder_id_ffa); |
| 216 | int ffaloss = account_get_ladder_losses(account, ctag, ladder_id_ffa); |
| 217 | int ffaxp = account_get_ladder_xp(account, ctag, ladder_id_ffa); |
| 218 | int ffalevel = account_get_ladder_level(account, ctag, ladder_id_ffa); |
| 219 | int ffarank = account_get_ladder_rank(account, ctag, ladder_id_ffa); |
| 220 | |
| 221 | int humanwins = account_get_racewins(account, W3_RACE_HUMANS, ctag); |
| 222 | int humanlosses = account_get_racelosses(account, W3_RACE_HUMANS, ctag); |
| 223 | int orcwins = account_get_racewins(account, W3_RACE_ORCS, ctag); |
| 224 | int orclosses = account_get_racelosses(account, W3_RACE_ORCS, ctag); |
| 225 | int undeadwins = account_get_racewins(account, W3_RACE_UNDEAD, ctag); |
| 226 | int undeadlosses = account_get_racelosses(account, W3_RACE_UNDEAD, ctag); |
| 227 | int nightelfwins = account_get_racewins(account, W3_RACE_NIGHTELVES, ctag); |
| 228 | int nightelflosses = account_get_racelosses(account, W3_RACE_NIGHTELVES, ctag); |
| 229 | int randomwins = account_get_racewins(account, W3_RACE_RANDOM, ctag); |
| 230 | int randomlosses = account_get_racelosses(account, W3_RACE_RANDOM, ctag); |
| 231 | int tourneywins = account_get_racewins(account, W3_RACE_DEMONS, ctag); |
| 232 | int tourneylosses = account_get_racelosses(account, W3_RACE_DEMONS, ctag); |
| 233 | |
| 234 | unsigned char rescount; |
| 235 | |
| 236 | if (!(rpacket = packet_create(packet_class_bnet))) |
| 237 | return -1; |
| 238 | packet_set_size(rpacket, sizeof(t_server_findanongame_profile2)); |
| 239 | packet_set_type(rpacket, SERVER_FINDANONGAME_PROFILE); |
| 240 | bn_byte_set(&rpacket->u.server_findanongame_profile2.option, CLIENT_FINDANONGAME_PROFILE); |
| 241 | bn_int_set(&rpacket->u.server_findanongame_profile2.count, Count); //job count |
| 242 | bn_int_set(&rpacket->u.server_findanongame_profile2.icon, account_icon_to_profile_icon(account_get_user_icon(account, ctag), account, ctag)); |
| 243 | |
| 244 | rescount = 0; |
| 245 | if (sololevel > 0) { |
| 246 | bn_int_set((bn_int*)&temp, 0x534F4C4F); // SOLO backwards |
| 247 | packet_append_data(rpacket, &temp, 4); |
| 248 | temp = 0; |
| 249 | bn_int_set((bn_int*)&temp, solowins); |
| 250 | packet_append_data(rpacket, &temp, 2); //SOLO WINS |
| 251 | bn_int_set((bn_int*)&temp, sololoss); |
| 252 | packet_append_data(rpacket, &temp, 2); // SOLO LOSSES |
| 253 | bn_int_set((bn_int*)&temp, sololevel); |
| 254 | packet_append_data(rpacket, &temp, 1); // SOLO LEVEL |
| 255 | bn_int_set((bn_int*)&temp, account_get_profile_calcs(account, soloxp, sololevel)); |
| 256 | packet_append_data(rpacket, &temp, 1); // SOLO PROFILE CALC |
| 257 | bn_int_set((bn_int *)&temp, soloxp); |
| 258 | packet_append_data(rpacket, &temp, 2); // SOLO XP |
| 259 | bn_int_set((bn_int *)&temp, solorank); |
| 260 | packet_append_data(rpacket, &temp, 4); // SOLO LADDER RANK |
| 261 | rescount++; |
| 262 | } |
| 263 | |
| 264 | if (teamlevel > 0) { |
| 265 | //below is for team records. Add this after 2v2,3v3,4v4 are done |
| 266 | bn_int_set((bn_int*)&temp, 0x5445414D); |
| 267 | packet_append_data(rpacket, &temp, 4); |
| 268 | bn_int_set((bn_int*)&temp, teamwins); |
| 269 | packet_append_data(rpacket, &temp, 2); |
| 270 | bn_int_set((bn_int*)&temp, teamloss); |
| 271 | packet_append_data(rpacket, &temp, 2); |
| 272 | bn_int_set((bn_int*)&temp, teamlevel); |
| 273 | packet_append_data(rpacket, &temp, 1); |
| 274 | bn_int_set((bn_int*)&temp, account_get_profile_calcs(account, teamxp, teamlevel)); |
| 275 | |
| 276 | packet_append_data(rpacket, &temp, 1); |
| 277 | bn_int_set((bn_int*)&temp, teamxp); |
| 278 | packet_append_data(rpacket, &temp, 2); |
| 279 | bn_int_set((bn_int*)&temp, teamrank); |
| 280 | packet_append_data(rpacket, &temp, 4); |
| 281 | //done of team game stats |
| 282 | rescount++; |
| 283 | } |
| 284 | |
| 285 | if (ffalevel > 0) { |
| 286 | bn_int_set((bn_int*)&temp, 0x46464120); |
| 287 | packet_append_data(rpacket, &temp, 4); |
| 288 | bn_int_set((bn_int*)&temp, ffawins); |
| 289 | packet_append_data(rpacket, &temp, 2); |
| 290 | bn_int_set((bn_int*)&temp, ffaloss); |
| 291 | packet_append_data(rpacket, &temp, 2); |
| 292 | bn_int_set((bn_int*)&temp, ffalevel); |
| 293 | packet_append_data(rpacket, &temp, 1); |
| 294 | bn_int_set((bn_int*)&temp, account_get_profile_calcs(account, ffaxp, ffalevel)); |
| 295 | packet_append_data(rpacket, &temp, 1); |
| 296 | bn_int_set((bn_int*)&temp, ffaxp); |
| 297 | packet_append_data(rpacket, &temp, 2); |
| 298 | bn_int_set((bn_int*)&temp, ffarank); |
| 299 | packet_append_data(rpacket, &temp, 4); |
| 300 | //End of FFA Stats |
| 301 | rescount++; |
| 302 | } |
| 303 | /* set result count */ |
| 304 | bn_byte_set(&rpacket->u.server_findanongame_profile2.rescount, rescount); |
| 305 | |
| 306 | bn_int_set((bn_int*)&temp, 0x06); //start of race stats |
| 307 | packet_append_data(rpacket, &temp, 1); |
| 308 | bn_int_set((bn_int*)&temp, randomwins); |
| 309 | packet_append_data(rpacket, &temp, 2); //random wins |
| 310 | bn_int_set((bn_int*)&temp, randomlosses); |
| 311 | packet_append_data(rpacket, &temp, 2); //random losses |
| 312 | bn_int_set((bn_int*)&temp, humanwins); |
| 313 | packet_append_data(rpacket, &temp, 2); //human wins |
| 314 | bn_int_set((bn_int*)&temp, humanlosses); |
| 315 | packet_append_data(rpacket, &temp, 2); //human losses |
| 316 | bn_int_set((bn_int*)&temp, orcwins); |
| 317 | packet_append_data(rpacket, &temp, 2); //orc wins |
| 318 | bn_int_set((bn_int*)&temp, orclosses); |
| 319 | packet_append_data(rpacket, &temp, 2); //orc losses |
| 320 | bn_int_set((bn_int*)&temp, undeadwins); |
| 321 | packet_append_data(rpacket, &temp, 2); //undead wins |
| 322 | bn_int_set((bn_int*)&temp, undeadlosses); |
| 323 | packet_append_data(rpacket, &temp, 2); //undead losses |
| 324 | bn_int_set((bn_int*)&temp, nightelfwins); |
| 325 | packet_append_data(rpacket, &temp, 2); //elf wins |
| 326 | bn_int_set((bn_int*)&temp, nightelflosses); |
| 327 | packet_append_data(rpacket, &temp, 2); //elf losses |
| 328 | bn_int_set((bn_int*)&temp, tourneywins); |
| 329 | packet_append_data(rpacket, &temp, 2); //tourney wins |
| 330 | bn_int_set((bn_int*)&temp, tourneylosses); |
| 331 | packet_append_data(rpacket, &temp, 2); //tourney losses |
| 332 | //end of normal stats - Start of AT stats |
| 333 | |
| 334 | /* 1 byte team count place holder, set later */ |
| 335 | packet_append_data(rpacket, &temp, 1); |
| 336 | |
| 337 | /* we need to store the AT team count but we dont know yet the no |
| 338 | * of stored teams so we cache the pointer for later use |
| 339 | */ |
| 340 | atcountp = (unsigned char *)packet_get_raw_data(rpacket, packet_get_size(rpacket) - 1); |
| 341 | |
| 342 | teamlist = account_get_teams(account); |
| 343 | teamcount = 0; |
| 344 | if (teamlist) |
| 345 | { |
| 346 | int teamtype[] = { 0, 0x32565332, 0x33565333, 0x34565334, 0x35565335, 0x36565336 }; |
| 347 | |
| 348 | LIST_TRAVERSE(teamlist, curr) |
| 349 | { |
| 350 | if (!(team = (t_team*)elem_get_data(curr))) |
| 351 | { |
| 352 | eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); |
| 353 | continue; |
| 354 | } |
| 355 | |
| 356 | if (team_get_clienttag(team) != ctag) |
| 357 | continue; |
| 358 | |
| 359 | bn_int_set((bn_int*)&temp, teamtype[team_get_size(team) - 1]); |
| 360 | packet_append_data(rpacket, &temp, 4); |
| 361 | |
| 362 | bn_int_set((bn_int*)&temp, team_get_wins(team)); //at team wins |
| 363 | packet_append_data(rpacket, &temp, 2); |
| 364 | bn_int_set((bn_int*)&temp, team_get_losses(team)); //at team losses |
| 365 | packet_append_data(rpacket, &temp, 2); |
| 366 | bn_int_set((bn_int*)&temp, team_get_level(team)); |
| 367 | packet_append_data(rpacket, &temp, 1); |
| 368 | bn_int_set((bn_int*)&temp, account_get_profile_calcs(account, team_get_xp(team), team_get_level(team))); // xp bar calc |
| 369 | packet_append_data(rpacket, &temp, 1); |
| 370 | bn_int_set((bn_int*)&temp, team_get_xp(team)); |
| 371 | packet_append_data(rpacket, &temp, 2); |
| 372 | bn_int_set((bn_int*)&temp, team_get_rank(team)); //rank on AT ladder |
| 373 | packet_append_data(rpacket, &temp, 4); |
| 374 | |
| 375 | bn_time = time_to_bnettime(temp, team_get_lastgame(team)); |
| 376 | bnettime_to_bn_long(bn_time, <ime); |
| 377 | packet_append_data(rpacket, <ime, 8); |
| 378 | |
| 379 | bn_int_set((bn_int*)&temp, team_get_size(team) - 1); |
| 380 | packet_append_data(rpacket, &temp, 1); |
| 381 | |
| 382 | for (i = 0; i < team_get_size(team); i++) |
| 383 | { |
| 384 | if ((team_get_memberuid(team, i) != account_get_uid(account))) |
| 385 | packet_append_string(rpacket, account_get_name(team_get_member(team, i))); |
| 386 | //now attach the names to the packet - not including yourself |
| 387 | // [quetzal] 20020826 |
| 388 | |
| 389 | } |
| 390 | teamcount++; |
| 391 | |
| 392 | if ((teamcount >= 16)) break; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | *atcountp = (unsigned char)teamcount; |
| 397 | |
| 398 | conn_push_outqueue(c, rpacket); |
| 399 | packet_del_ref(rpacket); |
| 400 | |
| 401 | eventlog(eventlog_level_info, __FUNCTION__, "Sent {}'s WAR3 Stats (including {} teams) to requestor.", username, teamcount); |
| 402 | } |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static int _client_anongame_cancel(t_connection * c) |
| 407 | { |
| 408 | t_packet * rpacket; |
| 409 | t_connection * tc[ANONGAME_MAX_GAMECOUNT / 2]; |
| 410 | |
| 411 | // [quetzal] 20020809 - added a_count, so we dont refer to already destroyed anongame |
| 412 | t_anongame *a = conn_get_anongame(c); |
| 413 | int a_count, i; |
| 414 | |
| 415 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] got FINDANONGAME CANCEL packet", conn_get_socket(c)); |
| 416 | |
| 417 | if (!a) |
| 418 | return -1; |
| 419 | |
| 420 | a_count = anongame_get_count(a); |
| 421 | |
| 422 | // anongame_unqueue(c, anongame_get_queue(a)); |
| 423 | // -- already doing unqueue in conn_destroy_anongame |
| 424 | for (i = 0; i < ANONGAME_MAX_GAMECOUNT / 2; i++) |
| 425 | tc[i] = anongame_get_tc(a, i); |
| 426 | |
| 427 | for (i = 0; i < ANONGAME_MAX_GAMECOUNT / 2; i++) { |
| 428 | if (tc[i] == NULL) |
| 429 | continue; |
| 430 | |
| 431 | conn_set_routeconn(tc[i], NULL); |
| 432 | conn_destroy_anongame(tc[i]); |
| 433 | } |
| 434 | |
| 435 | if (!(rpacket = packet_create(packet_class_bnet))) |
| 436 | return -1; |
| 437 | |
| 438 | packet_set_size(rpacket, sizeof(t_server_findanongame_playgame_cancel)); |
| 439 | packet_set_type(rpacket, SERVER_FINDANONGAME_PLAYGAME_CANCEL); |
| 440 | bn_byte_set(&rpacket->u.server_findanongame_playgame_cancel.cancel, SERVER_FINDANONGAME_CANCEL); |
| 441 | bn_int_set(&rpacket->u.server_findanongame_playgame_cancel.count, a_count); |
| 442 | conn_push_outqueue(c, rpacket); |
| 443 | packet_del_ref(rpacket); |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | /* Open portrait in Warcraft 3 user profile */ |
| 448 | static int _client_anongame_get_icon(t_connection * c, t_packet const * const packet) |
| 449 | { |
| 450 | t_packet * rpacket; |
| 451 | //BlacKDicK 04/20/2003 Need some huge re-work on this. |
| 452 | { |
| 453 | struct |
| 454 | { |
| 455 | char icon_code[4]; |
| 456 | unsigned int portrait_code; |
| 457 | char race; |
| 458 | bn_short required_wins; |
| 459 | char client_enabled; |
| 460 | } tempicon; |
| 461 | |
| 462 | //FIXME: Add those to the prefs and also merge them on accoun_wrap; |
| 463 | // FIXED BY DJP 07/16/2003 FOR 110 CHANGE ( TOURNEY & RACE WINS ) + Table_witdh |
| 464 | short icon_req_race_wins; |
| 465 | short icon_req_tourney_wins; |
| 466 | int race[] = { W3_RACE_RANDOM, W3_RACE_HUMANS, W3_RACE_ORCS, W3_RACE_UNDEAD, W3_RACE_NIGHTELVES, W3_RACE_DEMONS }; |
| 467 | char race_char[6] = { 'R', 'H', 'O', 'U', 'N', 'D' }; |
| 468 | char icon_pos[5] = { '2', '3', '4', '5', '6', }; |
| 469 | char table_width = 6; |
| 470 | char table_height = 5; |
| 471 | int i, j; |
| 472 | char rico; |
| 473 | unsigned int rlvl, rwins; |
| 474 | t_clienttag clienttag; |
| 475 | t_account * acc; |
| 476 | |
| 477 | char user_icon[5]; |
| 478 | char const * uicon; |
| 479 | |
| 480 | clienttag = conn_get_clienttag(c); |
| 481 | acc = conn_get_account(c); |
| 482 | /* WAR3 uses a different table size, might change if blizzard add tournament support to RoC */ |
| 483 | if (clienttag == CLIENTTAG_WARCRAFT3_UINT) { |
| 484 | table_width = 5; |
| 485 | table_height = 4; |
| 486 | } |
| 487 | |
| 488 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] got FINDANONGAME Get Icons packet", conn_get_socket(c)); |
| 489 | |
| 490 | if ((rpacket = packet_create(packet_class_bnet)) == NULL) { |
| 491 | eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet"); |
| 492 | return -1; |
| 493 | } |
| 494 | |
| 495 | packet_set_size(rpacket, sizeof(t_server_findanongame_iconreply)); |
| 496 | packet_set_type(rpacket, SERVER_FINDANONGAME_ICONREPLY); |
| 497 | bn_int_set(&rpacket->u.server_findanongame_iconreply.count, bn_int_get(packet->u.client_findanongame_inforeq.count)); |
| 498 | bn_byte_set(&rpacket->u.server_findanongame_iconreply.option, CLIENT_FINDANONGAME_GET_ICON); |
| 499 | |
| 500 | if (uicon = account_get_user_icon(acc, clienttag)) |
| 501 | { |
| 502 | std::memcpy(&rpacket->u.server_findanongame_iconreply.curricon, uicon, 4); |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | account_get_raceicon(acc, &rico, &rlvl, &rwins, clienttag); |
| 507 | std::sprintf(user_icon, "%1d%c3W", rlvl, rico); |
| 508 | std::memcpy(&rpacket->u.server_findanongame_iconreply.curricon, user_icon, 4); |
| 509 | } |
| 510 | |
| 511 | // if custom stats is enabled then set a custom client icon by player rating |
| 512 | // do not override user selected icon if any |
| 513 | bool assignedCustomIcon = false; |
| 514 | if (!uicon && prefs_get_custom_icons() == 1 && customicons_allowed_by_client(clienttag)) |
| 515 | { |
| 516 | if (t_icon_info * icon = customicons_get_icon_by_account(acc, clienttag)) |
| 517 | { |
| 518 | assignedCustomIcon = true; |
| 519 | std::memcpy(&rpacket->u.server_findanongame_iconreply.curricon, icon->icon_code, 4); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | bn_byte_set(&rpacket->u.server_findanongame_iconreply.table_width, table_width); |
| 524 | bn_byte_set(&rpacket->u.server_findanongame_iconreply.table_size, table_width*table_height); |
| 525 | for (j = 0; j < table_height; j++){ |
| 526 | icon_req_race_wins = anongame_infos_get_ICON_REQ(j + 1, clienttag); |
| 527 | for (i = 0; i < table_width; i++){ |
| 528 | tempicon.race = i; |
| 529 | tempicon.icon_code[0] = icon_pos[j]; |
| 530 | tempicon.icon_code[1] = race_char[i]; |
| 531 | tempicon.icon_code[2] = '3'; |
| 532 | tempicon.icon_code[3] = 'W'; |
| 533 | tempicon.portrait_code = (account_icon_to_profile_icon(tempicon.icon_code, acc, clienttag)); |
| 534 | if (i <= 4) |
| 535 | { |
| 536 | //Building the icon for the races |
| 537 | bn_short_set(&tempicon.required_wins, icon_req_race_wins); |
| 538 | if (assignedCustomIcon || account_get_racewins(acc, race[i], clienttag) < icon_req_race_wins) |
| 539 | tempicon.client_enabled = 0; |
| 540 | else |
| 541 | tempicon.client_enabled = 1; |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | //Building the icon for the tourney |
| 546 | icon_req_tourney_wins = anongame_infos_get_ICON_REQ_TOURNEY(j + 1); |
| 547 | bn_short_set(&tempicon.required_wins, icon_req_tourney_wins); |
| 548 | if (assignedCustomIcon || account_get_racewins(acc, race[i], clienttag) < icon_req_tourney_wins) |
| 549 | tempicon.client_enabled = 0; |
| 550 | else |
| 551 | tempicon.client_enabled = 1; |
| 552 | } |
| 553 | packet_append_data(rpacket, &tempicon, sizeof(tempicon)); |
| 554 | } |
| 555 | } |
| 556 | //Go,go,go |
| 557 | conn_push_outqueue(c, rpacket); |
| 558 | packet_del_ref(rpacket); |
| 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /* Choose icon by user from profile > portrait */ |
| 564 | static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet) |
| 565 | { |
| 566 | //BlacKDicK 04/20/2003 |
| 567 | // Modified by aancw 16/12/2014 |
| 568 | unsigned int desired_icon; |
| 569 | char user_icon[5]; |
| 570 | |
| 571 | t_account * account = conn_get_account(c); |
| 572 | t_clienttag clienttag = conn_get_clienttag(c); |
| 573 | |
| 574 | // do nothing when custom icon enabled and exists |
| 575 | if (prefs_get_custom_icons() == 1 && customicons_allowed_by_client(clienttag) && customicons_get_icon_by_account(account, clienttag)) |
| 576 | return 0; |
| 577 | |
| 578 | /*FIXME: In this case we do not get a 'count' but insted of it we get the icon |
| 579 | that the client wants to set.'W3H2' for an example. For now it is ok, since they share |
| 580 | the same position on the packet*/ |
| 581 | desired_icon = bn_int_get(packet->u.client_findanongame.count); |
| 582 | //user_icon[4]=0; |
| 583 | if (desired_icon == 0){ |
| 584 | std::strcpy(user_icon, "1O3W"); // 103W is equal to Default Icon |
| 585 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] Set icon packet to DEFAULT ICON [{}]", conn_get_socket(c), user_icon); |
| 586 | } |
| 587 | else{ |
| 588 | std::memcpy(user_icon, &desired_icon, 4); |
| 589 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] Set icon packet to ICON [{}]", conn_get_socket(c), user_icon); |
| 590 | } |
| 591 | |
| 592 | // ICON SWITCH HACK PROTECTION |
| 593 | if (check_user_icon(account, user_icon) == 0) |
| 594 | { |
| 595 | std::strcpy(user_icon, "1O3W"); // set icon to default |
| 596 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] \"{}\" ICON SWITCH hack attempt, icon set to default ", conn_get_username(c), user_icon); |
| 597 | //conn_set_state(c,conn_state_destroy); // dont kill user session |
| 598 | } |
| 599 | |
| 600 | account_set_user_icon(account, clienttag, user_icon); |
| 601 | //FIXME: Still need a way to 'refresh the user/channel' |
| 602 | //_handle_rejoin_command(conn_get_account(c),""); |
| 603 | /* ??? channel_update_userflags() */ |
| 604 | conn_update_w3_playerinfo(c); |
| 605 | |
| 606 | channel_rejoin(c); |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | /* Check user choice for illegal icon */ |
| 611 | // check user for illegal icon |
| 612 | // Modified by aancw 16/12/2014 |
| 613 | static int check_user_icon(t_account * account, const char * user_icon) |
| 614 | { |
| 615 | unsigned int i, len; |
| 616 | char temp_str[2]; |
| 617 | char user_race; |
| 618 | int number; |
| 619 | |
| 620 | len = std::strlen(user_icon); |
| 621 | if (len != 4) |
| 622 | eventlog(eventlog_level_error, __FUNCTION__, "got invalid user icon '{}'", user_icon); |
| 623 | |
| 624 | for (i = 0; i < len && i < 2; i++) |
| 625 | temp_str[i] = user_icon[i]; |
| 626 | |
| 627 | number = temp_str[0] - '0'; |
| 628 | user_race = temp_str[1]; |
| 629 | |
| 630 | |
| 631 | int race[] = { W3_RACE_RANDOM, W3_RACE_HUMANS, W3_RACE_ORCS, W3_RACE_UNDEAD, W3_RACE_NIGHTELVES, W3_RACE_DEMONS }; |
| 632 | char race_char[6] = { 'R', 'H', 'O', 'U', 'N', 'D' }; |
| 633 | int icon_pos[5] = { 2, 3, 4, 5, 6 }; |
| 634 | int icon_req_wins[5] = { 25, 150, 350, 750, 1500 }; |
| 635 | int icon_req_wins_tourney[5] = { 10, 75, 150, 250, 500}; |
| 636 | |
| 637 | for (int i = 0; i < sizeof(race_char); i++) |
| 638 | { |
| 639 | if (user_race == race_char[i]) |
| 640 | { |
| 641 | // Client will got DCed because of different req win normal and tournament |
| 642 | // Check if race is tournament or not |
| 643 | // Tournament req wins is different than normal icon |
| 644 | |
| 645 | if(race_char[i] == 'D') |
| 646 | { |
| 647 | for (int j = 0; j < sizeof(icon_pos); j++) |
| 648 | { |
| 649 | if (number == icon_pos[j]) |
| 650 | { |
| 651 | // compare account race wins and require wins for tournament icon |
| 652 | if (account_get_racewins( account, race[i], account_get_ll_clienttag(account) ) >= icon_req_wins_tourney[j]) |
| 653 | return 1; |
| 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | }else |
| 660 | { |
| 661 | // When normal icon |
| 662 | for (int j = 0; j < sizeof(icon_pos); j++) |
| 663 | { |
| 664 | if (number == icon_pos[j]) |
| 665 | { |
| 666 | // compare account race wins and require wins |
| 667 | if (account_get_racewins( account, race[i], account_get_ll_clienttag(account) ) >= icon_req_wins[j]) |
| 668 | return 1; |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | static int _client_anongame_infos(t_connection * c, t_packet const * const packet) |
| 680 | { |
| 681 | t_packet * rpacket; |
| 682 | |
| 683 | if (bn_int_get(packet->u.client_findanongame_inforeq.count) > 1) { |
| 684 | /* reply with 0 entries found */ |
| 685 | int temp = 0; |
| 686 | |
| 687 | if ((rpacket = packet_create(packet_class_bnet)) == NULL) { |
| 688 | eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet"); |
| 689 | return -1; |
| 690 | } |
| 691 | |
| 692 | packet_set_size(rpacket, sizeof(t_server_findanongame_inforeply)); |
| 693 | packet_set_type(rpacket, SERVER_FINDANONGAME_INFOREPLY); |
| 694 | bn_byte_set(&rpacket->u.server_findanongame_inforeply.option, CLIENT_FINDANONGAME_INFOS); |
| 695 | bn_int_set(&rpacket->u.server_findanongame_inforeply.count, bn_int_get(packet->u.client_findanongame_inforeq.count)); |
| 696 | bn_byte_set(&rpacket->u.server_findanongame_inforeply.noitems, 0); |
| 697 | packet_append_data(rpacket, &temp, 1); |
| 698 | |
| 699 | conn_push_outqueue(c, rpacket); |
| 700 | packet_del_ref(rpacket); |
| 701 | } |
| 702 | else { |
| 703 | int i; |
| 704 | int client_tag; |
| 705 | int server_tag_count = 0; |
| 706 | int client_tag_unk; |
| 707 | int server_tag_unk; |
| 708 | bn_int temp; |
| 709 | char noitems; |
| 710 | char * tmpdata; |
| 711 | int tmplen; |
| 712 | t_clienttag clienttag = conn_get_clienttag(c); |
| 713 | char last_packet = 0x00; |
| 714 | char other_packet = 0x01; |
| 715 | char langstr[5]; |
| 716 | t_gamelang gamelang = conn_get_gamelang(c); |
| 717 | bn_int_tag_get((bn_int const *)&gamelang, langstr, 5); |
| 718 | |
| 719 | /* Send seperate packet for each item requested |
| 720 | * sending all at once overloaded w3xp |
| 721 | * [Omega] */ |
| 722 | for (i = 0; i < bn_byte_get(packet->u.client_findanongame_inforeq.noitems); i++){ |
| 723 | noitems = 0; |
| 724 | |
| 725 | if ((rpacket = packet_create(packet_class_bnet)) == NULL) { |
| 726 | eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet"); |
| 727 | return -1; |
| 728 | } |
| 729 | |
| 730 | /* Starting the packet stuff */ |
| 731 | packet_set_size(rpacket, sizeof(t_server_findanongame_inforeply)); |
| 732 | packet_set_type(rpacket, SERVER_FINDANONGAME_INFOREPLY); |
| 733 | bn_byte_set(&rpacket->u.server_findanongame_inforeply.option, CLIENT_FINDANONGAME_INFOS); |
| 734 | bn_int_set(&rpacket->u.server_findanongame_inforeply.count, 1); |
| 735 | |
| 736 | std::memcpy(&temp, (packet_get_data_const(packet, 10 + (i * 8), 4)), sizeof(int)); |
| 737 | client_tag = bn_int_get(temp); |
| 738 | std::memcpy(&temp, packet_get_data_const(packet, 14 + (i * 8), 4), sizeof(int)); |
| 739 | client_tag_unk = bn_int_get(temp); |
| 740 | |
| 741 | switch (client_tag){ |
| 742 | case CLIENT_FINDANONGAME_INFOTAG_URL: |
| 743 | bn_int_set((bn_int*)&server_tag_unk, 0xBF1F1047); |
| 744 | packet_append_data(rpacket, "LRU\0", 4); |
| 745 | packet_append_data(rpacket, &server_tag_unk, 4); |
| 746 | // FIXME: Maybe need do do some checks to avoid prefs empty strings. |
| 747 | tmpdata = anongame_infos_data_get_url(clienttag, conn_get_versionid(c), &tmplen); |
| 748 | packet_append_data(rpacket, tmpdata, tmplen); |
| 749 | noitems++; |
| 750 | server_tag_count++; |
| 751 | eventlog(eventlog_level_debug, __FUNCTION__, "client_tag request tagid=(0x{:01x}) tag=({}) tag_unk=(0x{:04x})", i, "CLIENT_FINDANONGAME_INFOTAG_URL", client_tag_unk); |
| 752 | break; |
| 753 | case CLIENT_FINDANONGAME_INFOTAG_MAP: |
| 754 | bn_int_set((bn_int*)&server_tag_unk, 0x70E2E0D5); |
| 755 | packet_append_data(rpacket, "PAM\0", 4); |
| 756 | packet_append_data(rpacket, &server_tag_unk, 4); |
| 757 | tmpdata = anongame_infos_data_get_map(clienttag, conn_get_versionid(c), &tmplen); |
| 758 | packet_append_data(rpacket, tmpdata, tmplen); |
| 759 | noitems++; |
| 760 | server_tag_count++; |
| 761 | eventlog(eventlog_level_debug, __FUNCTION__, "client_tag request tagid=(0x{:01x}) tag=({}) tag_unk=(0x{:04x})", i, "CLIENT_FINDANONGAME_INFOTAG_MAP", client_tag_unk); |
| 762 | break; |
| 763 | case CLIENT_FINDANONGAME_INFOTAG_TYPE: |
| 764 | bn_int_set((bn_int*)&server_tag_unk, 0x7C87DEEE); |
| 765 | packet_append_data(rpacket, "EPYT", 4); |
| 766 | packet_append_data(rpacket, &server_tag_unk, 4); |
| 767 | tmpdata = anongame_infos_data_get_type(clienttag, conn_get_versionid(c), &tmplen); |
| 768 | packet_append_data(rpacket, tmpdata, tmplen); |
| 769 | noitems++; |
| 770 | server_tag_count++; |
| 771 | eventlog(eventlog_level_debug, __FUNCTION__, "client_tag request tagid=(0x{:01x}) tag=({}) tag_unk=(0x{:04x})", i, "CLIENT_FINDANONGAME_INFOTAG_TYPE", client_tag_unk); |
| 772 | break; |
| 773 | case CLIENT_FINDANONGAME_INFOTAG_DESC: |
| 774 | bn_int_set((bn_int*)&server_tag_unk, 0xA4F0A22F); |
| 775 | packet_append_data(rpacket, "CSED", 4); |
| 776 | packet_append_data(rpacket, &server_tag_unk, 4); |
| 777 | tmpdata = anongame_infos_data_get_desc(langstr, clienttag, conn_get_versionid(c), &tmplen); |
| 778 | packet_append_data(rpacket, tmpdata, tmplen); |
| 779 | eventlog(eventlog_level_debug, __FUNCTION__, "client_tag request tagid=(0x{:01x}) tag=({}) tag_unk=(0x{:04x})", i, "CLIENT_FINDANONGAME_INFOTAG_DESC", client_tag_unk); |
| 780 | noitems++; |
| 781 | server_tag_count++; |
| 782 | break; |
| 783 | case CLIENT_FINDANONGAME_INFOTAG_LADR: |
| 784 | bn_int_set((bn_int*)&server_tag_unk, 0x3BADE25A); |
| 785 | packet_append_data(rpacket, "RDAL", 4); |
| 786 | packet_append_data(rpacket, &server_tag_unk, 4); |
| 787 | tmpdata = anongame_infos_data_get_ladr(langstr, clienttag, conn_get_versionid(c), &tmplen); |
| 788 | packet_append_data(rpacket, tmpdata, tmplen); |
| 789 | noitems++; |
| 790 | server_tag_count++; |
| 791 | eventlog(eventlog_level_debug, __FUNCTION__, "client_tag request tagid=(0x{:01x}) tag=({}) tag_unk=(0x{:04x})", i, "CLIENT_FINDANONGAME_INFOTAG_LADR", client_tag_unk); |
| 792 | break; |
| 793 | default: |
| 794 | eventlog(eventlog_level_debug, __FUNCTION__, "unrec client_tag request tagid=(0x{:01x}) tag=(0x{:04x})", i, client_tag); |
| 795 | |
| 796 | } |
| 797 | //Adding a last padding null-byte |
| 798 | if (server_tag_count == bn_byte_get(packet->u.client_findanongame_inforeq.noitems)) |
| 799 | packet_append_data(rpacket, &last_packet, 1); /* only last packet in group gets 0x00 */ |
| 800 | else |
| 801 | packet_append_data(rpacket, &other_packet, 1); /* the rest get 0x01 */ |
| 802 | |
| 803 | //Go,go,go |
| 804 | bn_byte_set(&rpacket->u.server_findanongame_inforeply.noitems, noitems); |
| 805 | conn_push_outqueue(c, rpacket); |
| 806 | packet_del_ref(rpacket); |
| 807 | } |
| 808 | } |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | /* tournament notice disabled at this time, but responce is sent to cleint */ |
| 813 | static int _client_anongame_tournament(t_connection * c, t_packet const * const packet) |
| 814 | { |
| 815 | t_packet * rpacket; |
| 816 | |
| 817 | t_account * account = conn_get_account(c); |
| 818 | t_clienttag clienttag = conn_get_clienttag(c); |
| 819 | |
| 820 | unsigned int start_prelim = tournament_get_start_preliminary(); |
| 821 | unsigned int end_signup = tournament_get_end_signup(); |
| 822 | unsigned int end_prelim = tournament_get_end_preliminary(); |
| 823 | unsigned int start_r1 = tournament_get_start_round_1(); |
| 824 | |
| 825 | if ((rpacket = packet_create(packet_class_bnet)) == NULL) { |
| 826 | eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet"); |
| 827 | return -1; |
| 828 | } |
| 829 | |
| 830 | packet_set_size(rpacket, sizeof(t_server_anongame_tournament_reply)); |
| 831 | packet_set_type(rpacket, SERVER_FINDANONGAME_TOURNAMENT_REPLY); |
| 832 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.option, 7); |
| 833 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.count, |
| 834 | bn_int_get(packet->u.client_anongame_tournament_request.count)); |
| 835 | |
| 836 | if (!start_prelim || (end_signup <= now && tournament_user_signed_up(account) < 0) || |
| 837 | tournament_check_client(clienttag) < 0) { /* No Tournament Notice */ |
| 838 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 0); |
| 839 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 840 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0); |
| 841 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, 0); |
| 842 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0); |
| 843 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, 0); |
| 844 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); |
| 845 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 0); |
| 846 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); |
| 847 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); |
| 848 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0); |
| 849 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 0); |
| 850 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 851 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 852 | } |
| 853 | else if (start_prelim >= now) { /* Tournament Notice */ |
| 854 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 1); |
| 855 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 856 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); /* random */ |
| 857 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_prelim)); |
| 858 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); |
| 859 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, start_prelim - now); |
| 860 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); |
| 861 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 0); |
| 862 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); |
| 863 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); |
| 864 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x00); |
| 865 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 866 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 867 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 868 | } |
| 869 | else if (end_signup >= now) { /* Tournament Signup Notice - Play Game Active */ |
| 870 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 2); |
| 871 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 872 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0828); /* random */ |
| 873 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(end_signup)); |
| 874 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); |
| 875 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, end_signup - now); |
| 876 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); |
| 877 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); |
| 878 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); |
| 879 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); |
| 880 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x08); |
| 881 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 882 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 883 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 884 | } |
| 885 | else if (end_prelim >= now) { /* Tournament Prelim Period - Play Game Active */ |
| 886 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 3); |
| 887 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 888 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0828); /* random */ |
| 889 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(end_prelim)); |
| 890 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); |
| 891 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, end_prelim - now); |
| 892 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); |
| 893 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); |
| 894 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); |
| 895 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); |
| 896 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x08); |
| 897 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 898 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 899 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 900 | } |
| 901 | else if (start_r1 >= now && (tournament_get_game_in_progress())) { /* Prelim Period Over - Shows user stats (not all prelim games finished) */ |
| 902 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 4); |
| 903 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 904 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); /* random */ |
| 905 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_r1)); |
| 906 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); |
| 907 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, start_r1 - now); |
| 908 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); /* 00 00 */ |
| 909 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); |
| 910 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); |
| 911 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); |
| 912 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x08); |
| 913 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 914 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 915 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 916 | } |
| 917 | else if (!(tournament_get_in_finals_status(account))) { /* Prelim Period Over - user did not make finals - Shows user stats */ |
| 918 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 5); |
| 919 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 920 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0); |
| 921 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, 0); |
| 922 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0); |
| 923 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, 0); |
| 924 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); |
| 925 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); |
| 926 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); |
| 927 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); |
| 928 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); |
| 929 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 930 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 931 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 932 | } |
| 933 | /* cycle through [type-6] & [type-7] packets |
| 934 | * |
| 935 | * use [type-6] to show client "eliminated" or "continue" |
| 936 | * timestamp , countdown & round number (of next round) must be set if clinet continues |
| 937 | * |
| 938 | * use [type-7] to make cleint wait for 44FF packet option 1 to start game (A guess, not tested) |
| 939 | * |
| 940 | * not sure if there is overall winner packet sent at end of last final round |
| 941 | */ |
| 942 | // UNDONE: next two conditions never executed |
| 943 | else if ((0)) { /* User in finals - Shows user stats and start of next round*/ |
| 944 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 6); |
| 945 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 946 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); |
| 947 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_r1)); |
| 948 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); |
| 949 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, start_r1 - now); |
| 950 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0x0000); /* 00 00 */ |
| 951 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 4); /* round number */ |
| 952 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); /* 0 = continue , 1= eliminated */ |
| 953 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); |
| 954 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); /* number of rounds in finals */ |
| 955 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 956 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 957 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 958 | } |
| 959 | else if ((0)) { /* user waiting for match to be made */ |
| 960 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 7); |
| 961 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); |
| 962 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0); |
| 963 | bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, 0); |
| 964 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0); |
| 965 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, 0); |
| 966 | bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); |
| 967 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 1); /* round number */ |
| 968 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); |
| 969 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); |
| 970 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); /* number of finals */ |
| 971 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); |
| 972 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); |
| 973 | bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); |
| 974 | } |
| 975 | |
| 976 | conn_push_outqueue(c, rpacket); |
| 977 | packet_del_ref(rpacket); |
| 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | static unsigned int _tournament_time_convert(unsigned int time) |
| 982 | { |
| 983 | /* it works, don't ask me how */ /* some time drift reportd by testers */ |
| 984 | unsigned int tmp1, tmp2, tmp3; |
| 985 | |
| 986 | tmp1 = time - 1059179400; /* 0x3F21CB88 */ |
| 987 | tmp2 = static_cast<unsigned int>(tmp1*0.59604645); |
| 988 | tmp3 = tmp2 + 3276999960U; |
| 989 | /*eventlog(eventlog_level_trace,__FUNCTION__,"time: 0x%08x, tmp1: 0x%08x, tmp2 0x%08x, tmp3 0x%08x",time,tmp1,tmp2,tmp3);*/ |
| 990 | |
| 991 | return tmp3; |
| 992 | } |
| 993 | |
| 994 | extern int handle_anongame_packet(t_connection * c, t_packet const * const packet) |
| 995 | { |
| 996 | switch (bn_byte_get(packet->u.client_anongame.option)) |
| 997 | { |
| 998 | case CLIENT_FINDANONGAME_PROFILE: |
| 999 | return _client_anongame_profile(c, packet); |
| 1000 | |
| 1001 | case CLIENT_FINDANONGAME_CANCEL: |
| 1002 | return _client_anongame_cancel(c); |
| 1003 | |
| 1004 | case CLIENT_FINDANONGAME_SEARCH: |
| 1005 | case CLIENT_FINDANONGAME_AT_INVITER_SEARCH: |
| 1006 | case CLIENT_FINDANONGAME_AT_SEARCH: |
| 1007 | return handle_anongame_search(c, packet); /* located in anongame.c */ |
| 1008 | |
| 1009 | case CLIENT_FINDANONGAME_GET_ICON: |
| 1010 | return _client_anongame_get_icon(c, packet); |
| 1011 | |
| 1012 | case CLIENT_FINDANONGAME_SET_ICON: |
| 1013 | return _client_anongame_set_icon(c, packet); |
| 1014 | |
| 1015 | case CLIENT_FINDANONGAME_INFOS: |
| 1016 | return _client_anongame_infos(c, packet); |
| 1017 | |
| 1018 | case CLIENT_ANONGAME_TOURNAMENT: |
| 1019 | return _client_anongame_tournament(c, packet); |
| 1020 | |
| 1021 | case CLIENT_FINDANONGAME_PROFILE_CLAN: |
| 1022 | return _client_anongame_profile_clan(c, packet); |
| 1023 | |
| 1024 | default: |
| 1025 | eventlog(eventlog_level_error, __FUNCTION__, "got unhandled option {}", bn_byte_get(packet->u.client_findanongame.option)); |
| 1026 | return -1; |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | } |
| 1031 | |
| 1032 | } |