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

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. #ifdef TIME_WITH_SYS_TIME
  25. # include <sys/time.h>
  26. # include <time.h>
  27. #else
  28. # if HAVE_SYS_TIME_H
  29. #  include <sys/time.h>
  30. # else
  31. #  include <time.h>
  32. # endif
  33. #endif
  34. #include <errno.h>
  35. #ifdef STDC_HEADERS
  36. # include <stdlib.h>
  37. #else
  38. # ifdef HAVE_MALLOC_H
  39. #  include <malloc.h>
  40. # endif
  41. #endif
  42. #ifdef WIN32_GUI
  43. # include <win32/winmain.h>
  44. #endif
  45. #include "common/eventlog.h"
  46. #include "common/packet.h"
  47. #include "common/tag.h"
  48. #include "common/list.h"
  49. #include "common/util.h"
  50. #include "account.h"
  51. #include "anongame_maplists.h"
  52. #include "tournament.h"
  53. #include "common/setup_after.h"
  54. static t_tournament_info * tournament_info = NULL;
  55. static t_list * tournament_head=NULL;
  56. static int tournamentlist_create(void);
  57. static int gamelist_destroy(void);
  58. static t_tournament_user * tournament_get_user(t_account * account);
  59. //static int tournament_get_in_game_status(t_account * account);
  60. /*****/
  61. static int tournamentlist_create(void)
  62. {
  63.     if (!(tournament_head = list_create()))
  64. return -1;
  65.     return 0;
  66. }
  67. static int gamelist_destroy(void)
  68. {
  69.     t_elem * curr;
  70.     t_tournament_user * user;
  71.     
  72.     if (tournament_head) {
  73. LIST_TRAVERSE(tournament_head,curr)
  74. {
  75.     if (!(user = elem_get_data(curr))) {
  76. eventlog(eventlog_level_error,__FUNCTION__,"tournament list contains NULL item");
  77. continue;
  78.     }
  79.     
  80.     if (list_remove_elem(tournament_head,curr)<0)
  81. eventlog(eventlog_level_error,__FUNCTION__,"could not remove item from list");
  82.     
  83.     if (user->name)
  84. free((void *)user->name); /* avoid warning */
  85.     
  86.     free(user);
  87.     
  88. }
  89. if (list_destroy(tournament_head)<0)
  90.     return -1;
  91. tournament_head = NULL;
  92.     }
  93.     return 0;
  94. }
  95. /*****/
  96. extern int tournament_check_client(char const * clienttag)
  97. {
  98.     if ((strcmp(clienttag,CLIENTTAG_WAR3XP) == 0) && (tournament_info->game_client == 2))
  99. return 1;
  100.     if ((strcmp(clienttag,CLIENTTAG_WARCRAFT3) == 0) && (tournament_info->game_client == 1))
  101. return 1;
  102.     return -1;
  103. }
  104. extern int tournament_signup_user(t_account * account)
  105. {
  106.     t_tournament_user * user;
  107.     if (!(account))
  108. return -1;
  109.     
  110.     if ((user = tournament_get_user(account))) {
  111. eventlog(eventlog_level_info,__FUNCTION__,"user "%s" already signed up in tournament",account_get_name(account));
  112. return 0;
  113.     }
  114.     
  115.     if (!(user = malloc(sizeof(t_tournament_user)))) {
  116. eventlog(eventlog_level_error,__FUNCTION__,"could not allocate memory for tournament user");
  117. return -1;
  118.     }
  119.     
  120.     user->name = strdup(account_get_name(account));
  121.     user->wins = 0;
  122.     user->losses = 0;
  123.     user->ties = 0;
  124.     user->in_game = 0;
  125.     user->in_finals = 0;
  126.         
  127.     if (list_prepend_data(tournament_head,user)<0) {
  128. eventlog(eventlog_level_error,__FUNCTION__,"could not insert user");
  129. free((void *)user->name); /* avoid warning */
  130. free(user);
  131. return -1;
  132.     }
  133.     
  134.     eventlog(eventlog_level_info,__FUNCTION__,"added user "%s" to tournament",account_get_name(account));
  135.     return 0;
  136. }
  137. static t_tournament_user * tournament_get_user(t_account * account)
  138. {
  139.     t_elem const * curr;
  140.     t_tournament_user * user;
  141.     
  142.     if (tournament_head)
  143. LIST_TRAVERSE(tournament_head,curr)
  144. {
  145.     user = elem_get_data(curr);
  146.     if (strcmp(user->name, account_get_name(account)) == 0)
  147. return user;
  148. }
  149.     
  150.     return NULL;
  151. }
  152. extern int tournament_user_signed_up(t_account * account)
  153. {
  154.     if (!(tournament_get_user(account)))
  155. return -1;
  156.         
  157.     return 0;
  158. }
  159. extern int tournament_add_stat(t_account * account, int stat)
  160. {
  161.     t_tournament_user * user;
  162.     
  163.     if (!(user = tournament_get_user(account)))
  164. return -1;
  165.     
  166.     if (stat == 1)
  167. user->wins++;
  168.     if (stat == 2)
  169. user->losses++;
  170.     if (stat == 3)
  171. user->ties++;
  172.     
  173.     return 0;
  174. }
  175. extern int tournament_get_stat(t_account * account, int stat)
  176. {
  177.     t_tournament_user * user;
  178.     
  179.     if (!(user = tournament_get_user(account)))
  180. return 0;
  181.     
  182.     if (stat == 1)
  183. return user->wins;
  184.     if (stat == 2)
  185. return user->losses;
  186.     if (stat == 3)
  187. return user->ties;
  188.     return 0;
  189. }
  190. extern int tournament_get_player_score(t_account * account)
  191. {
  192.     t_tournament_user * user;
  193.     int score;
  194.     
  195.     if (!(user = tournament_get_user(account)))
  196. return 0;
  197.     
  198.     score = user->wins * 3 + user->ties - user->losses;
  199.     
  200.     if (score < 0)
  201. return 0;
  202.     return score;
  203. }
  204.     
  205. extern int tournament_set_in_game_status(t_account * account, int status)
  206. {
  207.     t_tournament_user * user;
  208.     
  209.     if (!(user = tournament_get_user(account)))
  210. return -1;
  211.     
  212.     user->in_game = status;
  213.     
  214.     return 0;
  215. }
  216. /*
  217. static int tournament_get_in_game_status(t_account * account)
  218. {
  219.     t_tournament_user * user;
  220.     
  221.     if (!(user = tournament_get_user(account)))
  222. return 0;
  223.     
  224.     return user->in_game;
  225. }
  226. */
  227. extern int tournament_get_in_finals_status(t_account * account)
  228. {
  229.     t_tournament_user * user;
  230.     
  231.     if (!(user = tournament_get_user(account)))
  232. return 0;
  233.     
  234.     return user->in_finals;
  235. }
  236. extern int tournament_get_game_in_progress(void)
  237. {
  238.     t_elem const * curr;
  239.     t_tournament_user * user;
  240.     
  241.     if (tournament_head)
  242. LIST_TRAVERSE_CONST(tournament_head,curr)
  243. {
  244.     user = elem_get_data(curr);
  245.     if (user->in_game == 1)
  246. return 1;
  247. }
  248.     
  249.     return 0;
  250. }
  251. extern int tournament_is_arranged(void)
  252. {
  253.     if (tournament_info->game_selection == 2)
  254. return 1;
  255.     else
  256. return 0;
  257. }
  258. extern int tournament_get_totalplayers(void)
  259. {
  260.     return tournament_info->game_type * 2;
  261. }
  262. void tournament_check_date(unsigned int *mon, unsigned int *mday, unsigned int *year, unsigned int *hour, unsigned int *min, unsigned int *sec, char const * caller)
  263. {
  264.   if (*mon>12)
  265.   {
  266.     eventlog(eventlog_level_error,__FUNCTION__,"got invalid month (%u) in %s",*mon,caller);
  267.     *mon = 12;
  268.   }
  269.   if (*mday>31)
  270.   {
  271.     eventlog(eventlog_level_error,__FUNCTION__,"got invalid mday (%u) in %s",*mday,caller);
  272.     *mday = 31;
  273.   }
  274.   if (*hour>23)
  275.   {
  276.     eventlog(eventlog_level_error,__FUNCTION__,"got invalid hour (%u) from %s",*hour,caller);
  277.     *hour = 23;
  278.   }
  279.   if (*min >59)
  280.   {
  281.     eventlog(eventlog_level_error,__FUNCTION__,"got invalid min (%u) from %s",*min,caller);
  282.     *min = 59;
  283.   }
  284.   if (*sec >59)
  285.   {
  286.     eventlog(eventlog_level_error,__FUNCTION__,"got invalid sec (%u) from %s",*sec,caller);
  287.     *sec = 59;
  288.   }
  289.   return;
  290. }
  291. /*****/
  292. extern int tournament_init(char const * filename)
  293. {
  294.     FILE * fp;
  295.     unsigned int line,pos,mon,day,year,hour,min,sec;
  296.     char *buff,*temp,*pointer,*value;
  297.     char format[30];
  298.     char *variable;
  299.     char *sponsor = NULL;
  300.     char *have_sponsor = NULL;
  301.     char *have_icon = NULL;
  302.     struct tm * timestamp = malloc(sizeof(struct tm));
  303.     
  304.     sprintf(format,"%%02u/%%02u/%%04u %%02u:%%02u:%%02u");
  305.     tournament_info = malloc(sizeof(t_tournament_info));
  306.     tournament_info->start_preliminary = 0;
  307.     tournament_info->end_signup = 0;
  308.     tournament_info->end_preliminary = 0;
  309.     tournament_info->start_round_1 = 0;
  310.     tournament_info->start_round_2 = 0;
  311.     tournament_info->start_round_3 = 0;
  312.     tournament_info->start_round_4 = 0;
  313.     tournament_info->tournament_end = 0;
  314.     tournament_info->game_selection = 1; /* Default to PG */
  315.     tournament_info->game_type = 1; /* Default to 1v1 */
  316.     tournament_info->game_client = 2; /* Default to FT */
  317.     tournament_info->races = 0x3F; /* Default to all races */
  318.     tournament_info->format = strdup("");
  319.     tournament_info->sponsor = strdup("");
  320.     tournament_info->thumbs_down = 0;
  321.     
  322.     anongame_tournament_maplists_destroy();
  323.     
  324.     if (!filename) {
  325. eventlog(eventlog_level_error,__FUNCTION__,"got NULL filename");
  326.         free((void *)timestamp);
  327. return -1;
  328.     }
  329.     
  330.     if (!(fp = fopen(filename,"r"))) {
  331. eventlog(eventlog_level_error,__FUNCTION__,"could not open file "%s" for reading (fopen: %s)",filename,strerror(errno));
  332. free((void *)timestamp);
  333. return -1;
  334.     }
  335.     
  336.     for (line=1; (buff = file_get_line(fp)); line++) {
  337. for (pos=0; buff[pos]=='t' || buff[pos]==' '; pos++);
  338. if (buff[pos]=='' || buff[pos]=='#') {
  339.     free(buff);
  340.     continue;
  341. }
  342. if ((temp = strrchr(buff,'#'))) {
  343.     unsigned int len;
  344.     unsigned int endpos;
  345.     
  346.     *temp = '';
  347.     len = strlen(buff)+1;
  348.     for (endpos=len-1; buff[endpos]=='t' || buff[endpos]==' '; endpos--);
  349.     buff[endpos+1] = '';
  350. }
  351. if (strcmp(buff,"[MAPS]") == 0) {
  352.     char *clienttag, *ctag, *mapname, *mname;
  353.     
  354.     free(buff);
  355.     for (; (buff = file_get_line(fp));) {
  356. for (pos=0; buff[pos]=='t' || buff[pos]==' '; pos++);
  357. if (buff[pos]=='' || buff[pos]=='#') {
  358.     free(buff);
  359.     continue;
  360. }
  361. if ((temp = strrchr(buff,'#'))) {
  362.     unsigned int len;
  363.     unsigned int endpos;
  364.     
  365.     *temp = '';
  366.     len = strlen(buff)+1;
  367.     for (endpos=len-1; buff[endpos]=='t' || buff[endpos]==' '; endpos--);
  368.     buff[endpos+1] = '';
  369. }
  370. if (!(clienttag = strtok(buff, " t"))) { /* strtok modifies the string it is passed */
  371.     free(buff);
  372.     continue;
  373. }
  374. if (strcmp(buff,"[ENDMAPS]") == 0) {
  375.     free(buff);
  376.     break;
  377. }
  378. if (!(mapname = strtok(NULL," t"))) {
  379.     free(buff);
  380.     continue;
  381. }
  382. ctag = strdup(clienttag);
  383. mname = strdup(mapname);
  384. anongame_add_tournament_map(ctag, mname);
  385. eventlog(eventlog_level_trace,__FUNCTION__,"added tournament map "%s" for %s",mname,ctag);
  386. free(ctag);
  387. free(mname);
  388. free(buff);
  389.     }
  390. } else {
  391.     variable = buff;
  392.     pointer = strchr(variable,'=');
  393.     for(pointer--;pointer[0]==' ' || pointer[0]=='t';pointer--);
  394.     pointer[1]='';
  395.     pointer++;
  396.     pointer++;
  397.     pointer = strchr(pointer,'=');
  398.     pointer++;
  399.     
  400.     if (strcmp(variable,"start_preliminary") == 0) {
  401.         pointer = strchr(pointer,'"');
  402.         pointer++;
  403.         value = pointer;
  404.         pointer = strchr(pointer,'"');
  405.         pointer[0]='';
  406.         
  407.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  408. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  409.         
  410.         timestamp->tm_mon = mon-1;
  411.         timestamp->tm_mday = day;
  412.         timestamp->tm_year = year-1900;
  413.         timestamp->tm_hour = hour;
  414.         timestamp->tm_min = min;
  415.         timestamp->tm_sec = sec;
  416.         timestamp->tm_isdst = -1;
  417.         
  418.         tournament_info->start_preliminary = mktime(timestamp);
  419.     }
  420.     else if (strcmp(variable,"end_signup") == 0) {
  421.         pointer = strchr(pointer,'"');
  422.         pointer++;
  423.         value = pointer;
  424.         pointer = strchr(pointer,'"');
  425.         pointer[0]='';
  426.         
  427.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  428.         
  429. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  430.         timestamp->tm_mon = mon-1;
  431.         timestamp->tm_mday = day;
  432.         timestamp->tm_year = year-1900;
  433.         timestamp->tm_hour = hour;
  434.         timestamp->tm_min = min;
  435.         timestamp->tm_sec = sec;
  436.         timestamp->tm_isdst = -1;
  437. tournament_info->end_signup = mktime(timestamp);
  438.     }
  439.     else if (strcmp(variable,"end_preliminary") == 0) {
  440.         pointer = strchr(pointer,'"');
  441.         pointer++;
  442.         value = pointer;
  443.         pointer = strchr(pointer,'"');
  444.         pointer[0]='';
  445.         
  446.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  447.         
  448. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  449.         timestamp->tm_mon = mon-1;
  450.         timestamp->tm_mday = day;
  451.         timestamp->tm_year = year-1900;
  452.         timestamp->tm_hour = hour;
  453.         timestamp->tm_min = min;
  454.         timestamp->tm_sec = sec;
  455.         timestamp->tm_isdst = -1;
  456.     
  457.         tournament_info->end_preliminary = mktime(timestamp);
  458.     }
  459.     else if (strcmp(variable,"start_round_1") == 0) {
  460. pointer = strchr(pointer,'"');
  461.         pointer++;
  462.         value = pointer;
  463.         pointer = strchr(pointer,'"');
  464.         pointer[0]='';
  465.         
  466.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  467.         
  468. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  469.         timestamp->tm_mon = mon-1;
  470.         timestamp->tm_mday = day;
  471.         timestamp->tm_year = year-1900;
  472.         timestamp->tm_hour = hour;
  473.         timestamp->tm_min = min;
  474.         timestamp->tm_sec = sec;
  475.         timestamp->tm_isdst = -1;
  476.     
  477.         tournament_info->start_round_1 = mktime(timestamp);
  478.     }
  479.     else if (strcmp(variable,"start_round_2") == 0) {
  480.         pointer = strchr(pointer,'"');
  481.         pointer++;
  482.         value = pointer;
  483.         pointer = strchr(pointer,'"');
  484.         pointer[0]='';
  485.         
  486.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  487.         
  488. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  489.         timestamp->tm_mon = mon-1;
  490.         timestamp->tm_mday = day;
  491.         timestamp->tm_year = year-1900;
  492.         timestamp->tm_hour = hour;
  493.         timestamp->tm_min = min;
  494.         timestamp->tm_sec = sec;
  495.         timestamp->tm_isdst = -1;
  496.         tournament_info->start_round_2 = mktime(timestamp);
  497.     }
  498.     else if (strcmp(variable,"start_round_3") == 0) {
  499. pointer = strchr(pointer,'"');
  500.         pointer++;
  501.         value = pointer;
  502.         pointer = strchr(pointer,'"');
  503.         pointer[0]='';
  504.         
  505.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  506.         
  507. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  508.         timestamp->tm_mon = mon-1;
  509.         timestamp->tm_mday = day;
  510.         timestamp->tm_year = year-1900;
  511.         timestamp->tm_hour = hour;
  512.         timestamp->tm_min = min;
  513.         timestamp->tm_sec = sec;
  514.         timestamp->tm_isdst = -1;
  515.         tournament_info->start_round_3 = mktime(timestamp);
  516.     }
  517.     else if (strcmp(variable,"start_round_4") == 0) {
  518.         pointer = strchr(pointer,'"');
  519.         pointer++;
  520.         value = pointer;
  521.         pointer = strchr(pointer,'"');
  522.         pointer[0]='';
  523.         
  524.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  525.         
  526. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  527.         timestamp->tm_mon = mon-1;
  528.         timestamp->tm_mday = day;
  529.         timestamp->tm_year = year-1900;
  530.         timestamp->tm_hour = hour;
  531.         timestamp->tm_min = min;
  532.         timestamp->tm_sec = sec;
  533.         timestamp->tm_isdst = -1;
  534.         tournament_info->start_round_4 = mktime(timestamp);
  535.     }
  536.     else if (strcmp(variable,"tournament_end") == 0) {
  537. pointer = strchr(pointer,'"');
  538.         pointer++;
  539.         value = pointer;
  540.         pointer = strchr(pointer,'"');
  541.         pointer[0]='';
  542.         
  543.         sscanf(value,format,&mon,&day,&year,&hour,&min,&sec);
  544.         
  545. tournament_check_date(&mon,&day,&year,&hour,&min,&sec,variable);
  546.         timestamp->tm_mon = mon-1;
  547.         timestamp->tm_mday = day;
  548.         timestamp->tm_year = year-1900;
  549.         timestamp->tm_hour = hour;
  550.         timestamp->tm_min = min;
  551.         timestamp->tm_sec = sec;
  552.         timestamp->tm_isdst = -1;
  553.         tournament_info->tournament_end = mktime(timestamp);
  554.     }
  555.     else if (strcmp(variable,"game_selection") == 0) {
  556. if (atoi(pointer) >= 1 && atoi(pointer) <= 2)
  557.     tournament_info->game_selection = atoi(pointer);
  558.     }
  559.     else if (strcmp(variable,"game_type") == 0) {
  560. if (atoi(pointer) >= 1 && atoi(pointer) <= 4)
  561.     tournament_info->game_type = atoi(pointer);
  562.     }
  563.     else if (strcmp(variable,"game_client") == 0) {
  564. if (atoi(pointer) >= 1 && atoi(pointer) <= 2)
  565.     tournament_info->game_client = atoi(pointer);
  566.     }
  567.     else if (strcmp(variable,"format") == 0) {
  568.         pointer = strchr(pointer,'"');
  569.         pointer++;
  570.         value = pointer;
  571.         pointer = strchr(pointer,'"');
  572.         pointer[0]='';
  573.         
  574.         if (tournament_info->format) free((void *)tournament_info->format);
  575.         tournament_info->format = strdup(value);
  576.     }
  577.     else if (strcmp(variable,"races") == 0) {
  578.         unsigned int intvalue = 0;
  579.         unsigned int i;
  580.         
  581.         pointer = strchr(pointer,'"');
  582.         pointer++;
  583.         value = pointer;
  584.         pointer = strchr(pointer,'"');
  585.         pointer[0]='';
  586.         
  587.         for(i=0;i<strlen(value);i++) {
  588.     if (value[i] == 'H') intvalue = intvalue | 0x01;
  589.     if (value[i] == 'O') intvalue = intvalue | 0x02;
  590.     if (value[i] == 'N') intvalue = intvalue | 0x04;
  591.     if (value[i] == 'U') intvalue = intvalue | 0x08;
  592.     if (value[i] == 'R') intvalue = intvalue | 0x20;
  593. }
  594. if (intvalue == 0 || intvalue == 0x2F)
  595.     intvalue = 0x3F; /* hack to make all races availiable */
  596.         tournament_info->races = intvalue;
  597.     }
  598.     else if (strcmp(variable,"sponsor") == 0) {
  599. pointer = strchr(pointer,'"');
  600. pointer++;
  601.         value = pointer;
  602.         pointer = strchr(pointer,'"');
  603.         pointer[0]='';
  604.         have_sponsor = strdup(value);
  605.     }
  606.     else if (strcmp(variable,"icon") == 0) {
  607.         pointer = strchr(pointer,'"');
  608.         pointer++;
  609.         value = pointer;
  610.         pointer = strchr(pointer,'"');
  611.         pointer[0]='';
  612.         have_icon = strdup(value);
  613.     }
  614.     else if (strcmp(variable,"thumbs_down") == 0) {
  615.         tournament_info->thumbs_down = atoi(pointer);
  616.     }
  617.     else
  618.         eventlog(eventlog_level_error,__FUNCTION__,"bad option "%s" in "%s"",variable,filename);
  619.     
  620.     if (have_sponsor && have_icon) {
  621.         sponsor = malloc(strlen(have_sponsor)+6);
  622. if (strlen(have_icon) == 4)
  623.     sprintf(sponsor, "%c%c%c%c,%s",have_icon[3],have_icon[2],have_icon[1],have_icon[0],have_sponsor);
  624. else if (strlen(have_icon) == 2)
  625.     sprintf(sponsor, "%c%c3W,%s",have_icon[1],have_icon[0],have_sponsor);
  626. else {
  627.     sprintf(sponsor, "PX3W,%s",have_sponsor); /* default to standard FT icon */
  628.     eventlog(eventlog_level_warn,__FUNCTION__,"bad icon length, using W3XP");
  629. }
  630. if (tournament_info->sponsor)
  631.     free((void *)tournament_info->sponsor);
  632.         
  633. tournament_info->sponsor = strdup(sponsor);
  634.         free((void *)have_sponsor);
  635. free((void *)have_icon);
  636.         free((void *)sponsor);
  637. have_sponsor = NULL;
  638.         have_icon = NULL;
  639.     }
  640.     free(buff);
  641. }
  642.     }
  643.     if (have_sponsor) free((void *)have_sponsor);
  644.     if (have_icon) free((void *)have_icon);
  645.     free((void *)timestamp);
  646.     fclose(fp);
  647.     
  648.     /* check if we have timestamps for all the times */ 
  649.     /* if not disable tournament by setting "start_preliminary" to 0 */
  650.     if (tournament_info->end_signup == 0 || tournament_info->end_preliminary == 0 ||
  651.     tournament_info->start_round_1 == 0 || tournament_info->start_round_2 == 0 ||
  652.     tournament_info->start_round_3 == 0 || tournament_info->start_round_4 == 0 ||
  653.     tournament_info->tournament_end == 0) {
  654. tournament_info->start_preliminary = 0;
  655. eventlog(eventlog_level_warn,__FUNCTION__,"one or more timestamps for tournaments is not valid, tournament has been disabled");
  656.     } else {
  657.      if (tournamentlist_create()<0) {
  658.     tournament_info->start_preliminary = 0;
  659.     eventlog(eventlog_level_warn,__FUNCTION__,"unable to create tournament list, tournament has been disabled");
  660. }
  661.     }
  662.     
  663.     return 0;
  664. }
  665. extern int tournament_destroy(void)
  666. {
  667.     if (tournament_info->format) free((void *)tournament_info->format);
  668.     if (tournament_info->sponsor) free((void *)tournament_info->sponsor);
  669.     if (tournament_info) free((void *)tournament_info);
  670.     tournament_info = NULL;
  671.     gamelist_destroy();
  672.     return 0;
  673. }
  674. extern int tournament_reload(char const * filename)
  675. {
  676. time_t tm;
  677. time(&tm);
  678. if((tm >= tournament_info->start_preliminary) && (tm <= tournament_info->tournament_end))
  679. {
  680. eventlog(eventlog_level_info,__FUNCTION__,"unable to reload tournament, tournament is in process");
  681. return -1;
  682. }
  683. tournament_destroy();
  684. return tournament_init(filename);
  685. }
  686. /*****/
  687. extern unsigned int tournament_get_start_preliminary(void)
  688. {
  689.     return tournament_info->start_preliminary;
  690. }
  691. extern unsigned int tournament_get_end_signup(void)
  692. {
  693.     return tournament_info->end_signup;
  694. }
  695. extern unsigned int tournament_get_end_preliminary(void)
  696. {
  697.     return tournament_info->end_preliminary;
  698. }
  699. extern unsigned int tournament_get_start_round_1(void)
  700. {
  701.     return tournament_info->start_round_1;
  702. }
  703. extern unsigned int tournament_get_start_round_2(void)
  704. {
  705.     return tournament_info->start_round_2;
  706. }
  707. extern unsigned int tournament_get_start_round_3(void)
  708. {
  709.     return tournament_info->start_round_3;
  710. }
  711. extern unsigned int tournament_get_start_round_4(void)
  712. {
  713.     return tournament_info->start_round_4;
  714. }
  715. extern unsigned int tournament_get_tournament_end(void)
  716. {
  717.     return tournament_info->tournament_end;
  718. }
  719. extern unsigned int tournament_get_game_selection(void)
  720. {
  721.     return tournament_info->game_selection;
  722. }
  723. extern unsigned int tournament_get_game_type(void)
  724. {
  725.     return tournament_info->game_type;
  726. }
  727. extern unsigned int tournament_get_races(void)
  728. {
  729.     return tournament_info->races;
  730. }
  731. extern char * tournament_get_format(void)
  732. {
  733.     return tournament_info->format;
  734. }
  735. extern char * tournament_get_sponsor(void)
  736. {
  737.     return tournament_info->sponsor;
  738. }
  739. extern unsigned int tournament_get_thumbs_down(void)
  740. {
  741.     return tournament_info->thumbs_down;
  742. }
  743. /****/