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