handle_anongame.c
上传用户:tany51
上传日期:2013-06-12
资源大小:1397k
文件大小:39k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /*
  2.  * This program is free software; you can redistribute it and/or
  3.  * modify it under the terms of the GNU General Public License
  4.  * as published by the Free Software Foundation; either version 2
  5.  * of the License, or (at your option) any later version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful,
  8.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  * GNU General Public License for more details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License
  13.  * along with this program; if not, write to the Free Software
  14.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  15.  */
  16. #include "common/setup_before.h"
  17. #ifdef HAVE_STRING_H
  18. # include <string.h>
  19. #else
  20. # ifdef HAVE_STRINGS_H
  21. #  include <strings.h>
  22. # endif
  23. #endif
  24. #include <errno.h>
  25. #ifdef STDC_HEADERS
  26. # include <stdlib.h>
  27. #else
  28. # ifdef HAVE_MALLOC_H
  29. #  include <malloc.h>
  30. # endif
  31. #endif
  32. #ifdef WIN32_GUI
  33. # include <win32/winmain.h>
  34. #endif
  35. #include "common/bn_type.h"
  36. #include "common/eventlog.h"
  37. #include "common/packet.h"
  38. #include "common/queue.h"
  39. #include "common/tag.h"
  40. #include "common/list.h"
  41. #include "common/util.h"
  42. #include "connection.h"
  43. #include "account.h"
  44. #include "channel.h"
  45. #include "anongame.h"
  46. #include "anongame_infos.h"
  47. #include "anongame_maplists.h"
  48. #include "handle_anongame.h"
  49. #include "tournament.h"
  50. #include "common/setup_after.h"
  51. /* option - handling function */
  52. /* 0x00 */ /* PG style search - handle_anongame_search() in anongame.c */ 
  53. /* 0x01 */ /* server side packet sent from handle_anongame_search() in anongame.c */
  54. /* 0x02 */ static int _client_anongame_infos(t_connection * c, t_packet const * const packet);
  55. /* 0x03 */ static int _client_anongame_cancel(t_connection * c);
  56. /* 0x04 */ static int _client_anongame_profile(t_connection * c, t_packet const * const packet);
  57. /* 0x05 */ /* AT style search - handle_anongame_search() in anongame.c */
  58. /* 0x06 */ /* AT style search (Inviter) handle_anongame_search() in anongame.c */
  59. /* 0x07 */ static int _client_anongame_tournament(t_connection * c, t_packet const * const packet);
  60. /* 0x08 */ /* unknown if it even exists */
  61. /* 0x09 */ static int _client_anongame_get_icon(t_connection * c, t_packet const * const packet);
  62. /* 0x0A */ static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet);
  63. /* misc functions used by _client_anongame_tournament() */
  64. static unsigned int _tournament_time_convert(unsigned int time);
  65. /* and now the functions */
  66. static int _client_anongame_profile(t_connection * c, t_packet const * const packet)
  67. {
  68.     t_packet * rpacket;
  69.     char const * username;
  70.     int Count;
  71.     int temp;
  72.     t_account * account; 
  73.     t_connection * dest_c;
  74.     char const * ctag;
  75.     
  76.     Count = bn_int_get(packet->u.client_findanongame.count);
  77.     eventlog(eventlog_level_info,__FUNCTION__,"[%d] got a FINDANONGAME PROFILE packet",conn_get_socket(c));
  78.     
  79.     if (!(username = packet_get_str_const(packet,sizeof(t_client_findanongame_profile),USER_NAME_MAX)))
  80.     {
  81. eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad FINDANONGAME_PROFILE (missing or too long username)",conn_get_socket(c));
  82. return -1;
  83.     }
  84.     
  85.     //If no account is found then break
  86.     if (!(account = accountlist_find_account(username)))
  87.     {
  88. eventlog(eventlog_level_error, __FUNCTION__, "Could not get account - PROFILE");
  89. return -1;
  90.     }
  91.     if (!(dest_c = connlist_find_connection_by_accountname(username))) {
  92. eventlog(eventlog_level_debug, __FUNCTION__, "account is offline -  try ll_clienttag");
  93. if (!(ctag = account_get_ll_clienttag(account))) return -1;
  94.     }
  95.     else
  96.     ctag = conn_get_clienttag(dest_c);
  97.     eventlog(eventlog_level_info,__FUNCTION__,"Looking up %s's WAR3 Stats.",username);
  98.     if (account_get_sololevel(account,ctag)<=0 && account_get_teamlevel(account,ctag)<=0 && account_get_atteamcount(account,ctag)<=0)
  99.     {
  100. eventlog(eventlog_level_info,__FUNCTION__,"%s does not have WAR3 Stats.",username);
  101. if (!(rpacket = packet_create(packet_class_bnet)))
  102.     return -1;
  103. packet_set_size(rpacket,sizeof(t_server_findanongame_profile2));
  104. packet_set_type(rpacket,SERVER_FINDANONGAME_PROFILE);
  105. bn_byte_set(&rpacket->u.server_findanongame_profile2.option,CLIENT_FINDANONGAME_PROFILE);
  106. bn_int_set(&rpacket->u.server_findanongame_profile2.count,Count);
  107. bn_int_set(&rpacket->u.server_findanongame_profile2.icon,account_icon_to_profile_icon(account_get_user_icon(account,ctag),account,ctag));
  108. bn_byte_set(&rpacket->u.server_findanongame_profile2.rescount,0);
  109. temp=0;
  110. packet_append_data(rpacket,&temp,2); 
  111. conn_push_outqueue(c,rpacket);
  112. packet_del_ref(rpacket);
  113.     }
  114.     else // If they do have a profile then:
  115.     {
  116. int solowins=account_get_solowin(account,ctag); 
  117. int sololoss=account_get_sololoss(account,ctag);
  118. int soloxp=account_get_soloxp(account,ctag);
  119. int sololevel=account_get_sololevel(account,ctag);
  120. int solorank=account_get_solorank(account,ctag);
  121. int teamwins=account_get_teamwin(account,ctag);
  122. int teamloss=account_get_teamloss(account,ctag);
  123. int teamxp=account_get_teamxp(account,ctag);
  124. int teamlevel=account_get_teamlevel(account,ctag);
  125. int teamrank=account_get_teamrank(account,ctag);
  126. int ffawins=account_get_ffawin(account,ctag);
  127. int ffaloss=account_get_ffaloss(account,ctag);
  128. int ffaxp=account_get_ffaxp(account,ctag);
  129. int ffalevel=account_get_ffalevel(account,ctag);
  130. int ffarank=account_get_ffarank(account,ctag);
  131. int humanwins=account_get_racewin(account,1,ctag);
  132. int humanlosses=account_get_raceloss(account,1,ctag);
  133. int orcwins=account_get_racewin(account,2,ctag);
  134. int orclosses=account_get_raceloss(account,2,ctag);
  135. int undeadwins=account_get_racewin(account,8,ctag);
  136. int undeadlosses=account_get_raceloss(account,8,ctag);
  137. int nightelfwins=account_get_racewin(account,4,ctag);
  138. int nightelflosses=account_get_raceloss(account,4,ctag);
  139. int randomwins=account_get_racewin(account,0,ctag);
  140. int randomlosses=account_get_raceloss(account,0,ctag);
  141. unsigned char rescount;
  142. if (!(rpacket = packet_create(packet_class_bnet)))
  143.     return -1;
  144. packet_set_size(rpacket,sizeof(t_server_findanongame_profile2));
  145. packet_set_type(rpacket,SERVER_FINDANONGAME_PROFILE);
  146. bn_byte_set(&rpacket->u.server_findanongame_profile2.option,CLIENT_FINDANONGAME_PROFILE);
  147. bn_int_set(&rpacket->u.server_findanongame_profile2.count,Count); //job count
  148. bn_int_set(&rpacket->u.server_findanongame_profile2.icon,account_icon_to_profile_icon(account_get_user_icon(account,ctag),account,ctag));
  149. rescount = 0;
  150. if (sololevel > 0) {
  151.     bn_int_set((bn_int*)&temp,0x534F4C4F); // SOLO backwards
  152.     packet_append_data(rpacket,&temp,4);
  153.     temp=0;
  154.     bn_int_set((bn_int*)&temp,solowins);
  155.     packet_append_data(rpacket,&temp,2); //SOLO WINS
  156.     bn_int_set((bn_int*)&temp,sololoss);
  157.     packet_append_data(rpacket,&temp,2); // SOLO LOSSES
  158.     bn_int_set((bn_int*)&temp,sololevel);
  159.     packet_append_data(rpacket,&temp,1); // SOLO LEVEL
  160.     bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,soloxp,sololevel));
  161.     packet_append_data(rpacket,&temp,1); // SOLO PROFILE CALC
  162.     bn_int_set((bn_int *)&temp,soloxp);
  163.     packet_append_data(rpacket,&temp,2); // SOLO XP
  164.     bn_int_set((bn_int *)&temp,solorank);
  165.     packet_append_data(rpacket,&temp,4); // SOLO LADDER RANK
  166.     rescount++;
  167. }
  168. if (teamlevel > 0) {
  169.     //below is for team records. Add this after 2v2,3v3,4v4 are done
  170.     bn_int_set((bn_int*)&temp,0x5445414D); 
  171.     packet_append_data(rpacket,&temp,4);
  172.     bn_int_set((bn_int*)&temp,teamwins);
  173.     packet_append_data(rpacket,&temp,2);
  174.     bn_int_set((bn_int*)&temp,teamloss);
  175.     packet_append_data(rpacket,&temp,2);
  176.     bn_int_set((bn_int*)&temp,teamlevel);
  177.     packet_append_data(rpacket,&temp,1);
  178.     bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,teamxp,teamlevel));
  179.     
  180.     packet_append_data(rpacket,&temp,1);
  181.     bn_int_set((bn_int*)&temp,teamxp);
  182.     packet_append_data(rpacket,&temp,2);
  183.     bn_int_set((bn_int*)&temp,teamrank);
  184.     packet_append_data(rpacket,&temp,4);
  185.     //done of team game stats
  186.     rescount++;
  187. }
  188. if (ffalevel > 0) {
  189.     bn_int_set((bn_int*)&temp,0x46464120);
  190.     packet_append_data(rpacket,&temp,4);
  191.     bn_int_set((bn_int*)&temp,ffawins);
  192.     packet_append_data(rpacket,&temp,2);
  193.     bn_int_set((bn_int*)&temp,ffaloss);
  194.     packet_append_data(rpacket,&temp,2);
  195.     bn_int_set((bn_int*)&temp,ffalevel);
  196.     packet_append_data(rpacket,&temp,1);
  197.     bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,ffaxp,ffalevel));
  198.     packet_append_data(rpacket,&temp,1);
  199.     bn_int_set((bn_int*)&temp,ffaxp);
  200.     packet_append_data(rpacket,&temp,2);
  201.     bn_int_set((bn_int*)&temp,ffarank);
  202.     packet_append_data(rpacket,&temp,4);
  203.     //End of FFA Stats
  204.     rescount++;
  205. }
  206. /* set result count */
  207. bn_byte_set(&rpacket->u.server_findanongame_profile2.rescount,rescount);
  208. bn_int_set((bn_int*)&temp,0x06); //start of race stats
  209. packet_append_data(rpacket,&temp,1);
  210. bn_int_set((bn_int*)&temp,randomwins);
  211. packet_append_data(rpacket,&temp,2); //random wins
  212. bn_int_set((bn_int*)&temp,randomlosses);
  213. packet_append_data(rpacket,&temp,2); //random losses
  214. bn_int_set((bn_int*)&temp,humanwins);
  215. packet_append_data(rpacket,&temp,2); //human wins
  216. bn_int_set((bn_int*)&temp,humanlosses);
  217. packet_append_data(rpacket,&temp,2); //human losses
  218. bn_int_set((bn_int*)&temp,orcwins);
  219. packet_append_data(rpacket,&temp,2); //orc wins
  220. bn_int_set((bn_int*)&temp,orclosses);
  221. packet_append_data(rpacket,&temp,2); //orc losses
  222. bn_int_set((bn_int*)&temp,undeadwins);
  223. packet_append_data(rpacket,&temp,2); //undead wins
  224. bn_int_set((bn_int*)&temp,undeadlosses);
  225. packet_append_data(rpacket,&temp,2); //undead losses
  226. bn_int_set((bn_int*)&temp,nightelfwins);
  227. packet_append_data(rpacket,&temp,2); //elf wins
  228. bn_int_set((bn_int*)&temp,nightelflosses);
  229. packet_append_data(rpacket,&temp,2); //elf losses
  230. temp=0;
  231. packet_append_data(rpacket,&temp,4);
  232. //end of normal stats - Start of AT stats
  233. /* 1 byte team count place holder, set later */
  234. packet_append_data(rpacket, &temp, 1);
  235. temp=account_get_atteamcount(account,ctag);
  236. if(temp>0)
  237. {
  238.     /* [quetzal] 20020827 - partially rewritten AT part */
  239.     int i, j, lvl, highest_lvl[6], cnt;
  240.     int invalid;
  241.     /* allocate array for teamlevels */
  242.     int *teamlevels;
  243.     unsigned char *atcountp;
  244.     cnt = temp;
  245.     teamlevels = malloc(cnt * sizeof(int));
  246.     /* we need to store the AT team count but we dont know yet the no
  247.      * of corectly stored teams so we cache the pointer for later use 
  248.      */
  249.     atcountp = (unsigned char *)packet_get_raw_data(rpacket, packet_get_size(rpacket) - 1);
  250.     /* populate our array */
  251.     for (i = 0; i < cnt; i++)
  252. if ((teamlevels[i] = account_get_atteamlevel(account, i+1,ctag)) < 0)
  253.     teamlevels[i] = 0;
  254.     /* now lets pick indices of 6 highest levels */
  255.     for (j = 0; j < cnt && j < 6; j++) {
  256. lvl = -1;
  257. for (i = 0; i < cnt; i++) {
  258.     if (teamlevels[i] > lvl) {
  259. lvl = teamlevels[i];
  260. highest_lvl[j] = i;
  261.     }
  262. }
  263. teamlevels[highest_lvl[j]] = -1;
  264. eventlog(eventlog_level_debug, __FUNCTION__, 
  265.     "profile/AT - highest level is %d with index %d", lvl, highest_lvl[j]);
  266.     }
  267.     // <-- end of picking indices
  268.     // 
  269.     free((void*)teamlevels);
  270.     cnt = 0;
  271.     invalid = 0;
  272.     for(i = 0; i < j; i++)
  273.     {
  274. int n;
  275. int teamsize;
  276. char * teammembers, *self, *p2, *p3;
  277. int teamtype[] = {0, 0x32565332, 0x33565333, 0x34565334, 0x35565335, 0x36565336};
  278. n = highest_lvl[i] + 1;
  279. teamsize = account_get_atteamsize(account, n, ctag);
  280. teammembers = (char *)account_get_atteammembers(account, n,ctag);
  281. if (!teammembers || teamsize < 1 || teamsize > 5) {
  282.     eventlog(eventlog_level_warn, __FUNCTION__, "skipping invalid AT (members: '%s' teamsize: %d)", teammembers ? teammembers : "NULL", teamsize);
  283.     invalid = 1;
  284.     continue;
  285. }
  286. p2 = p3 = teammembers = strdup(teammembers);
  287. eventlog(eventlog_level_debug, __FUNCTION__,"profile/AT - processing team %d", n);
  288. bn_int_set((bn_int*)&temp,teamtype[teamsize]);
  289. packet_append_data(rpacket,&temp,4);
  290. bn_int_set((bn_int*)&temp,account_get_atteamwin(account,n,ctag)); //at team wins
  291. packet_append_data(rpacket,&temp,2);
  292. bn_int_set((bn_int*)&temp,account_get_atteamloss(account,n,ctag)); //at team losses
  293. packet_append_data(rpacket,&temp,2);
  294. bn_int_set((bn_int*)&temp,account_get_atteamlevel(account,n,ctag)); 
  295. packet_append_data(rpacket,&temp,1);
  296. bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,account_get_atteamxp(account,n,ctag),account_get_atteamlevel(account,n,ctag))); // xp bar calc
  297. packet_append_data(rpacket,&temp,1);
  298. bn_int_set((bn_int*)&temp,account_get_atteamxp(account,n,ctag));
  299. packet_append_data(rpacket,&temp,2);
  300. bn_int_set((bn_int*)&temp,account_get_atteamrank(account,n,ctag)); //rank on AT ladder
  301. packet_append_data(rpacket,&temp,4);
  302. temp=0;
  303. packet_append_data(rpacket,&temp,4); //some unknown packet? random shit
  304. packet_append_data(rpacket,&temp,4); //another unknown packet..random shit
  305. bn_int_set((bn_int*)&temp,teamsize);
  306. packet_append_data(rpacket,&temp,1);
  307. //now attach the names to the packet - not including yourself
  308. // [quetzal] 20020826
  309. self = strstr(teammembers, account_get_name(account));
  310. while (p2)
  311. {
  312.     p3 = strchr(p2, ' ');
  313.     if (p3) *p3++ = 0;
  314.     if (self != p2) packet_append_string(rpacket, p2);
  315.     p2 = p3;
  316. }
  317. free((void *)teammembers);
  318. cnt++;
  319.     }
  320.     if (!cnt) {
  321. eventlog(eventlog_level_warn, __FUNCTION__, "no valid team found, sending bogus team");
  322. bn_int_set((bn_int*)&temp, 0x32565332);
  323. packet_append_data(rpacket,&temp,4);
  324. temp = 0;
  325. packet_append_data(rpacket,&temp,2);
  326. packet_append_data(rpacket,&temp,2);
  327. packet_append_data(rpacket,&temp,1);
  328. packet_append_data(rpacket,&temp,1);
  329. packet_append_data(rpacket,&temp,2);
  330. packet_append_data(rpacket,&temp,4);
  331. packet_append_data(rpacket,&temp,4);
  332. packet_append_data(rpacket,&temp,4);
  333. bn_int_set((bn_int*)&temp, 1);
  334. packet_append_data(rpacket,&temp,1);
  335. packet_append_string(rpacket,"error");
  336. cnt++;
  337.     }
  338.     *atcountp = (unsigned char)cnt;
  339.     if (invalid) account_fix_at(account, ctag);
  340. }
  341. conn_push_outqueue(c,rpacket);
  342. packet_del_ref(rpacket);
  343. eventlog(eventlog_level_info,__FUNCTION__,"Sent %s's WAR3 Stats to requestor.",username);
  344.     }
  345.     return 0;
  346. }    
  347. static int _client_anongame_cancel(t_connection * c)
  348. {
  349.     t_packet * rpacket;
  350.     t_connection * tc[ANONGAME_MAX_GAMECOUNT/2];
  351.     
  352.     // [quetzal] 20020809 - added a_count, so we dont refer to already destroyed anongame
  353.     t_anongame *a = conn_get_anongame(c);
  354.     int a_count, i;
  355.     
  356.     eventlog(eventlog_level_info,__FUNCTION__,"[%d] got FINDANONGAME CANCEL packet", conn_get_socket(c));
  357.     
  358.     if(!a)
  359. return -1;
  360.     
  361.     a_count = anongame_get_count(a);
  362.     
  363.     // anongame_unqueue(c, anongame_get_queue(a)); 
  364.     // -- already doing unqueue in conn_destroy_anongame
  365.     for (i=0; i < ANONGAME_MAX_GAMECOUNT/2; i++)
  366. tc[i] = anongame_get_tc(a, i);
  367.     for (i=0; i < ANONGAME_MAX_GAMECOUNT/2; i++) {
  368. if (tc[i] == NULL)
  369.     continue;
  370.     
  371. conn_set_routeconn(tc[i], NULL);
  372. conn_destroy_anongame(tc[i]);
  373.     }
  374.     
  375.     if (!(rpacket = packet_create(packet_class_bnet)))
  376. return -1;
  377.     
  378.     packet_set_size(rpacket,sizeof(t_server_findanongame_playgame_cancel));
  379.     packet_set_type(rpacket,SERVER_FINDANONGAME_PLAYGAME_CANCEL);
  380.     bn_byte_set(&rpacket->u.server_findanongame_playgame_cancel.cancel,SERVER_FINDANONGAME_CANCEL);
  381.     bn_int_set(&rpacket->u.server_findanongame_playgame_cancel.count, a_count);
  382.     conn_push_outqueue(c,rpacket);
  383.     packet_del_ref(rpacket);
  384.     return 0;
  385. }
  386. static int _client_anongame_get_icon(t_connection * c, t_packet const * const packet)
  387. {
  388.     t_packet * rpacket;
  389.     
  390.     //BlacKDicK 04/20/2003 Need some huge re-work on this.
  391.     {
  392. struct
  393. {
  394.     char  icon_code[4];
  395.     unsigned int portrait_code;
  396.     char  race;
  397.     bn_short  required_wins;
  398.     char  client_enabled;
  399.         } tempicon;
  400.         
  401. //FIXME: Add those to the prefs and also merge them on accoun_wrap;
  402. // FIXED BY DJP 07/16/2003 FOR 110 CHANGE ( TOURNEY & RACE WINS ) + Table_witdh
  403. short icon_req_race_wins;
  404. short icon_req_tourney_wins;
  405.         int race[]={W3_RACE_RANDOM,W3_RACE_HUMANS,W3_RACE_ORCS,W3_RACE_UNDEAD,W3_RACE_NIGHTELVES,W3_ICON_DEMONS};
  406.         char race_char[6] ={'R','H','O','U','N','D'};
  407.         char icon_pos[5] ={'2','3','4','5','6',};
  408.         char table_width = 6;
  409.         char table_height= 5;
  410.         int i,j;
  411.         char rico;
  412.         unsigned int rlvl,rwins;
  413. char const * clienttag;
  414. t_account * acc;
  415.         
  416.         char user_icon[5];
  417.         char const * uicon;
  418. clienttag = conn_get_clienttag(c);
  419. acc = conn_get_account(c);
  420. /* WAR3 uses a different table size, might change if blizzard add tournament support to RoC */
  421. if (strcmp(clienttag,CLIENTTAG_WARCRAFT3)==0) {
  422.          table_width = 5;
  423.     table_height= 4;
  424. }
  425.         eventlog(eventlog_level_info,__FUNCTION__,"[%d] got FINDANONGAME Get Icons packet",conn_get_socket(c));
  426. if ((rpacket = packet_create(packet_class_bnet)) == NULL) {
  427.     eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet");
  428.     return -1;
  429. }
  430. packet_set_size(rpacket, sizeof(t_server_findanongame_iconreply));
  431.         packet_set_type(rpacket, SERVER_FINDANONGAME_ICONREPLY);
  432.         bn_int_set(&rpacket->u.server_findanongame_iconreply.count, bn_int_get(packet->u.client_findanongame_inforeq.count));
  433.         bn_byte_set(&rpacket->u.server_findanongame_iconreply.option, CLIENT_FINDANONGAME_GET_ICON);
  434.         if ((uicon = account_get_user_icon(acc,clienttag)))
  435.         {
  436.     memcpy(&rpacket->u.server_findanongame_iconreply.curricon, uicon,4);
  437.         }
  438.         else 
  439.         {
  440.     account_get_raceicon(acc,&rico,&rlvl,&rwins,clienttag);
  441.     sprintf(user_icon,"%1d%c3W",rlvl,rico);
  442.             memcpy(&rpacket->u.server_findanongame_iconreply.curricon,user_icon,4);
  443.         }
  444. bn_byte_set(&rpacket->u.server_findanongame_iconreply.table_width, table_width);
  445.         bn_byte_set(&rpacket->u.server_findanongame_iconreply.table_size, table_width*table_height);
  446.         for (j=0;j<table_height;j++){
  447.     if (strcmp(clienttag,CLIENTTAG_WARCRAFT3)==0)
  448. icon_req_race_wins = anongame_infos_get_ICON_REQ_WAR3(j+1);
  449.     else
  450. icon_req_race_wins = anongame_infos_get_ICON_REQ_W3XP(j+1);
  451.     for (i=0;i<table_width;i++){
  452. tempicon.race=i;
  453.         tempicon.icon_code[0] = icon_pos[j];
  454.         tempicon.icon_code[1] = race_char[i];
  455.         tempicon.icon_code[2] = '3';
  456.         tempicon.icon_code[3] = 'W';
  457.         tempicon.portrait_code = (account_icon_to_profile_icon(tempicon.icon_code,acc,clienttag));
  458.         if (i<=4){
  459.          //Building the icon for the races
  460.          bn_short_set(&tempicon.required_wins,icon_req_race_wins);
  461.          if (account_get_racewin(acc,race[i],clienttag)>=icon_req_race_wins) {
  462. tempicon.client_enabled=1;
  463.          }else{
  464. tempicon.client_enabled=0;
  465.     }
  466.      }else{
  467.         //Building the icon for the tourney
  468. icon_req_tourney_wins = anongame_infos_get_ICON_REQ_TOURNEY(j+1);
  469.         bn_short_set(&tempicon.required_wins,icon_req_tourney_wins);
  470.         if (account_get_racewin(acc,race[i],clienttag)>=icon_req_tourney_wins) {
  471.     tempicon.client_enabled=1;
  472.         }else{
  473.     tempicon.client_enabled=0;}
  474.         }
  475.         packet_append_data(rpacket, &tempicon, sizeof(tempicon));
  476.     }
  477. }
  478.         //Go,go,go
  479.         conn_push_outqueue(c,rpacket);
  480.         packet_del_ref(rpacket);
  481.     }
  482.     return 0;
  483. }
  484. static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet)
  485. {
  486.     //BlacKDicK 04/20/2003
  487.     unsigned int desired_icon;
  488.     char user_icon[5];
  489.     
  490.     /*FIXME: In this case we do not get a 'count' but insted of it we get the icon
  491.     that the client wants to set.'W3H2' for an example. For now it is ok, since they share
  492.     the same position on the packet*/
  493.     desired_icon=bn_int_get(packet->u.client_findanongame.count);
  494.     user_icon[4]=0;
  495.     if (desired_icon==0){
  496. strcpy(user_icon,"NULL");
  497. eventlog(eventlog_level_info,__FUNCTION__,"[%d] Set icon packet to DEFAULT ICON [%4.4s]",conn_get_socket(c),user_icon);
  498.     }else{
  499. memcpy(user_icon,&desired_icon,4);
  500. eventlog(eventlog_level_info,__FUNCTION__,"[%d] Set icon packet to ICON [%s]",conn_get_socket(c),user_icon);
  501.     }
  502.     
  503.     account_set_user_icon(conn_get_account(c),conn_get_clienttag(c),user_icon);
  504.     //FIXME: Still need a way to 'refresh the user/channel' 
  505.     //_handle_rejoin_command(conn_get_account(c),""); 
  506.     /* ??? channel_update_flags() */
  507. conn_update_w3_playerinfo(c);
  508.     
  509.     channel_rejoin(c);
  510.     return 0;
  511. }
  512. static int _client_anongame_infos(t_connection * c, t_packet const * const packet)
  513. {
  514.     t_packet * rpacket;
  515.     
  516.     if (bn_int_get(packet->u.client_findanongame_inforeq.count) > 1) {
  517. /* reply with 0 entries found */
  518. int temp = 0;
  519. if ((rpacket = packet_create(packet_class_bnet)) == NULL) {
  520.     eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet");
  521.     return -1;
  522. }
  523. packet_set_size(rpacket, sizeof(t_server_findanongame_inforeply));
  524. packet_set_type(rpacket, SERVER_FINDANONGAME_INFOREPLY);
  525. bn_byte_set(&rpacket->u.server_findanongame_inforeply.option, CLIENT_FINDANONGAME_INFOS);
  526. bn_int_set(&rpacket->u.server_findanongame_inforeply.count, bn_int_get(packet->u.client_findanongame_inforeq.count));
  527. bn_byte_set(&rpacket->u.server_findanongame_inforeply.noitems, 0);
  528. packet_append_data(rpacket, &temp, 1);
  529. conn_push_outqueue(c,rpacket);
  530. packet_del_ref(rpacket);
  531.     } else {
  532. int i;
  533. int client_tag;
  534. int server_tag_count = 0;
  535. int client_tag_unk;
  536. int server_tag_unk;
  537. bn_int temp;
  538. char noitems;
  539. char * tmpdata;
  540. int tmplen;
  541. char const * clienttag = conn_get_clienttag(c);
  542. char last_packet = 0x00;
  543. char other_packet = 0x01;
  544.     char langstr[5];
  545.     int gamelang = conn_get_gamelang(c);
  546.     bn_int_tag_get((bn_int const *)&gamelang, langstr, 5);
  547. /* Send seperate packet for each item requested
  548.  * sending all at once overloaded w3xp
  549.  * [Omega] */
  550. for (i=0;i<bn_byte_get(packet->u.client_findanongame_inforeq.noitems);i++){
  551.     noitems = 0;
  552.     
  553.     if ((rpacket = packet_create(packet_class_bnet)) == NULL) {
  554. eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet");
  555. return -1;
  556.     }
  557.     
  558.     /* Starting the packet stuff */
  559.     packet_set_size(rpacket, sizeof(t_server_findanongame_inforeply));
  560.     packet_set_type(rpacket, SERVER_FINDANONGAME_INFOREPLY);
  561.     bn_byte_set(&rpacket->u.server_findanongame_inforeply.option, CLIENT_FINDANONGAME_INFOS);
  562.     bn_int_set(&rpacket->u.server_findanongame_inforeply.count, 1);
  563.     
  564.     memcpy(&temp,(packet_get_data_const(packet,10+(i*8),4)),sizeof(int));
  565.     client_tag=bn_int_get(temp);
  566.     memcpy(&temp,packet_get_data_const(packet,14+(i*8),4),sizeof(int));
  567.     client_tag_unk=bn_int_get(temp);
  568.     switch (client_tag){
  569. case CLIENT_FINDANONGAME_INFOTAG_URL:
  570.     bn_int_set((bn_int*)&server_tag_unk,0xBF1F1047);
  571.     packet_append_data(rpacket, "LRU" , 4);
  572.     packet_append_data(rpacket, &server_tag_unk , 4);
  573.     // FIXME: Maybe need do do some checks to avoid prefs empty strings.
  574. tmpdata = anongame_infos_data_get_url(clienttag, conn_get_versionid(c), &tmplen);
  575.     packet_append_data(rpacket, tmpdata, tmplen);
  576.     noitems++;
  577.     server_tag_count++;
  578.     eventlog(eventlog_level_debug,__FUNCTION__,"client_tag version=(0x%01x) request tagid=(0x%01x) tag=(%s)  tag_unk=(0x%04x)",conn_get_versionid(c),i,"CLIENT_FINDANONGAME_INFOTAG_URL",client_tag_unk);
  579.     break;
  580. case CLIENT_FINDANONGAME_INFOTAG_MAP:
  581.     bn_int_set((bn_int*)&server_tag_unk,0x70E2E0D5);
  582.     packet_append_data(rpacket, "PAM" , 4);
  583.     packet_append_data(rpacket, &server_tag_unk , 4);
  584. tmpdata = anongame_infos_data_get_map(clienttag, conn_get_versionid(c), &tmplen);
  585.     packet_append_data(rpacket, tmpdata, tmplen);
  586.     noitems++;
  587.     server_tag_count++;
  588.     eventlog(eventlog_level_debug,__FUNCTION__,"client_tag request tagid=(0x%01x) tag=(%s)  tag_unk=(0x%04x)",i,"CLIENT_FINDANONGAME_INFOTAG_MAP",client_tag_unk);
  589.     break;
  590. case CLIENT_FINDANONGAME_INFOTAG_TYPE:
  591.     bn_int_set((bn_int*)&server_tag_unk,0x7C87DEEE);
  592.     packet_append_data(rpacket, "EPYT" , 4);
  593.     packet_append_data(rpacket, &server_tag_unk , 4);
  594. tmpdata = anongame_infos_data_get_type(clienttag, conn_get_versionid(c), &tmplen);
  595.     packet_append_data(rpacket, tmpdata, tmplen);
  596.     noitems++;
  597.     server_tag_count++;
  598.     eventlog(eventlog_level_debug,__FUNCTION__,"client_tag request tagid=(0x%01x) tag=(%s) tag_unk=(0x%04x)",i,"CLIENT_FINDANONGAME_INFOTAG_TYPE",client_tag_unk);
  599.     break;
  600. case CLIENT_FINDANONGAME_INFOTAG_DESC:
  601.     bn_int_set((bn_int*)&server_tag_unk,0xA4F0A22F);
  602.     packet_append_data(rpacket, "CSED" , 4);
  603.     packet_append_data(rpacket,&server_tag_unk,4);
  604. tmpdata = anongame_infos_data_get_desc(langstr, clienttag, conn_get_versionid(c), &tmplen);
  605.     packet_append_data(rpacket, tmpdata, tmplen);
  606.     eventlog(eventlog_level_debug,__FUNCTION__,"client_tag request tagid=(0x%01x) tag=(%s) tag_unk=(0x%04x)",i,"CLIENT_FINDANONGAME_INFOTAG_DESC",client_tag_unk);
  607.     noitems++;
  608.     server_tag_count++;
  609.     break;
  610. case CLIENT_FINDANONGAME_INFOTAG_LADR:
  611.     bn_int_set((bn_int*)&server_tag_unk,0x3BADE25A);
  612.     packet_append_data(rpacket, "RDAL" , 4);
  613.     packet_append_data(rpacket, &server_tag_unk , 4);
  614. tmpdata = anongame_infos_data_get_ladr(langstr, clienttag, conn_get_versionid(c), &tmplen);
  615.     packet_append_data(rpacket, tmpdata, tmplen);
  616.     noitems++;
  617.     server_tag_count++;
  618.     eventlog(eventlog_level_debug,__FUNCTION__,"client_tag request tagid=(0x%01x) tag=(%s) tag_unk=(0x%04x)",i,"CLIENT_FINDANONGAME_INFOTAG_LADR",client_tag_unk);
  619.     break;
  620. default:
  621.      eventlog(eventlog_level_debug,__FUNCTION__,"unrec client_tag request tagid=(0x%01x) tag=(0x%04x)",i,client_tag);
  622.     }
  623.     //Adding a last padding null-byte
  624.     if (server_tag_count == bn_byte_get(packet->u.client_findanongame_inforeq.noitems))
  625. packet_append_data(rpacket, &last_packet, 1); /* only last packet in group gets 0x00 */
  626.     else
  627. packet_append_data(rpacket, &other_packet, 1); /* the rest get 0x01 */
  628.     //Go,go,go
  629.     bn_byte_set(&rpacket->u.server_findanongame_inforeply.noitems, noitems);
  630.     conn_push_outqueue(c,rpacket);
  631.     packet_del_ref(rpacket);
  632. }
  633.     }
  634.     return 0;
  635. }
  636. /* tournament notice disabled at this time, but responce is sent to cleint */
  637. static int _client_anongame_tournament(t_connection * c, t_packet const * const packet)
  638. {
  639.     t_packet * rpacket;
  640.     
  641.     t_account * account = conn_get_account(c);
  642.     char const * clienttag = conn_get_clienttag(c);
  643.     
  644.     unsigned int now = time(NULL);
  645.     unsigned int start_prelim = tournament_get_start_preliminary();
  646.     unsigned int end_signup = tournament_get_end_signup();
  647.     unsigned int end_prelim = tournament_get_end_preliminary();
  648.     unsigned int start_r1 = tournament_get_start_round_1();
  649.     
  650.     if ((rpacket = packet_create(packet_class_bnet)) == NULL) {
  651. eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet");
  652. return -1;
  653.     }
  654.     
  655.     packet_set_size(rpacket, sizeof(t_server_anongame_tournament_reply));
  656.     packet_set_type(rpacket, SERVER_FINDANONGAME_TOURNAMENT_REPLY);
  657.     bn_byte_set(&rpacket->u.server_anongame_tournament_reply.option, 7);
  658.     bn_int_set(&rpacket->u.server_anongame_tournament_reply.count,
  659.     bn_int_get(packet->u.client_anongame_tournament_request.count));
  660.     
  661.     if ( !start_prelim || (end_signup <= now && tournament_user_signed_up(account) < 0) ||
  662.     tournament_check_client(clienttag) < 0) { /* No Tournament Notice */
  663. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 0);
  664. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  665. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0);
  666. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, 0);
  667. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0);
  668. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, 0);
  669. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0);
  670. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, 0);
  671. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, 0);
  672. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, 0);
  673. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0);
  674. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 0);
  675. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  676. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  677.     }
  678.     else if (start_prelim>=now) { /* Tournament Notice */
  679. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 1);
  680. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  681. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); /* random */
  682. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_prelim));
  683. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0x01);
  684. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, start_prelim-now);
  685. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0);
  686. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, 0);
  687. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, 0);
  688. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, 0);
  689. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x00);
  690. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  691. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  692. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  693.     }
  694.     else if (end_signup>=now) { /* Tournament Signup Notice - Play Game Active */
  695. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 2);
  696. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  697. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0x0828); /* random */
  698. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(end_signup));
  699. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0x01);
  700. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, end_signup-now);
  701. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0);
  702. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1));
  703. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2));
  704. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3));
  705. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x08);
  706. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  707. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  708. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  709.     }
  710.     else if (end_prelim>=now) { /* Tournament Prelim Period - Play Game Active */
  711. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 3);
  712. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  713. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0x0828); /* random */
  714. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(end_prelim));
  715. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0x01);
  716. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, end_prelim-now);
  717. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0);
  718. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1));
  719. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2));
  720. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3));
  721. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x08);
  722. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  723. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  724. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  725.     }
  726.     else if (start_r1>=now && (tournament_get_game_in_progress()) ) { /* Prelim Period Over - Shows user stats (not all prelim games finished) */
  727. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 4);
  728. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  729. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); /* random */
  730. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_r1));
  731. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0x01);
  732. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, start_r1-now);
  733. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0); /* 00 00 */
  734. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1));
  735. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2));
  736. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3));
  737. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x08);
  738. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  739. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  740. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  741.     }
  742.     else if (!(tournament_get_in_finals_status(account))) { /* Prelim Period Over - user did not make finals - Shows user stats */
  743. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 5);
  744. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  745. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0);
  746. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, 0);
  747. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0);
  748. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, 0);
  749. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0);
  750. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1));
  751. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2));
  752. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3));
  753. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x04);
  754. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  755. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  756. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  757.     }
  758.     /* cycle through [type-6] & [type-7] packets
  759.      *
  760.      * use [type-6] to show client "eliminated" or "continue"
  761.      *     timestamp , countdown & round number (of next round) must be set if clinet continues
  762.      *
  763.      * use [type-7] to make cleint wait for 44FF packet option 1 to start game (A guess, not tested)
  764.      *
  765.      * not sure if there is overall winner packet sent at end of last final round
  766.      */
  767.     
  768.     else if ( (0) ) { /* User in finals - Shows user stats and start of next round*/
  769. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 6);
  770. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  771. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000);
  772. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_r1));
  773. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0x01);
  774. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, start_r1-now);
  775. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0x0000); /* 00 00 */
  776. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, 4); /* round number */
  777. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, 0); /* 0 = continue , 1= eliminated */
  778. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, 0);
  779. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); /* number of rounds in finals */
  780. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  781. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  782. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  783.     }
  784.     else if ( (0) ) { /* user waiting for match to be made */
  785. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.type, 7);
  786. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown, 0);
  787. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown4, 0);
  788. bn_int_set( &rpacket->u.server_anongame_tournament_reply.timestamp, 0);
  789. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown5, 0);
  790. bn_short_set( &rpacket->u.server_anongame_tournament_reply.countdown, 0);
  791. bn_short_set( &rpacket->u.server_anongame_tournament_reply.unknown2, 0);
  792. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.wins, 1); /* round number */
  793. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.losses, 0);
  794. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.ties, 0);
  795. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); /* number of finals */
  796. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.selection, 2);
  797. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.descnum, 0);
  798. bn_byte_set( &rpacket->u.server_anongame_tournament_reply.nulltag, 0);
  799.     }
  800.     
  801.     conn_push_outqueue(c,rpacket);
  802.     packet_del_ref(rpacket);
  803.     return 0;
  804. }
  805. static unsigned int _tournament_time_convert(unsigned int time)
  806. {
  807.     /* it works, don't ask me how */ /* some time drift reportd by testers */
  808.     unsigned int tmp1, tmp2, tmp3;
  809.     
  810.     tmp1 = time-1059179400; /* 0x3F21CB88  */
  811.     tmp2 = tmp1*0.59604645;
  812.     tmp3 = tmp2+3276999960U;
  813.     /*eventlog(eventlog_level_trace,__FUNCTION__,"time: 0x%08x, tmp1: 0x%08x, tmp2 0x%08x, tmp3 0x%08x",time,tmp1,tmp2,tmp3);*/
  814.     return tmp3;
  815. }
  816. extern int handle_anongame_packet(t_connection * c, t_packet const * const packet)
  817. {
  818.     if (bn_byte_get(packet->u.client_anongame.option)==CLIENT_FINDANONGAME_PROFILE)
  819. return _client_anongame_profile(c, packet);
  820.     if (bn_byte_get(packet->u.client_anongame.option) == CLIENT_FINDANONGAME_CANCEL) 
  821. return _client_anongame_cancel(c);
  822.     if (bn_byte_get(packet->u.client_anongame.option)==CLIENT_FINDANONGAME_SEARCH ||
  823.     bn_byte_get(packet->u.client_anongame.option)==CLIENT_FINDANONGAME_AT_INVITER_SEARCH ||
  824.     bn_byte_get(packet->u.client_anongame.option)==CLIENT_FINDANONGAME_AT_SEARCH)
  825. return handle_anongame_search(c, packet); /* located in anongame.c */
  826.     if (bn_byte_get(packet->u.client_anongame.option)==CLIENT_FINDANONGAME_GET_ICON)
  827. return _client_anongame_get_icon(c, packet);
  828.     
  829.     if (bn_byte_get(packet->u.client_anongame.option)==CLIENT_FINDANONGAME_SET_ICON)
  830. return _client_anongame_set_icon(c, packet);
  831.     if (bn_byte_get(packet->u.client_anongame.option) == CLIENT_FINDANONGAME_INFOS)
  832. return _client_anongame_infos(c, packet);
  833.     
  834.     if (bn_byte_get(packet->u.client_anongame.option)==CLIENT_ANONGAME_TOURNAMENT)
  835. return _client_anongame_tournament(c, packet);
  836.     
  837.     eventlog(eventlog_level_error,__FUNCTION__,"got unhandled option %d",bn_byte_get(packet->u.client_findanongame.option));
  838.     return -1;
  839. }