📄 game.c
字号:
}extern t_account * game_get_player(t_game * game, unsigned int i){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } if (!(i<game->count)) { eventlog(eventlog_level_error,__FUNCTION__,"requested illegal player id %u",i); return NULL; } return game->players[i];}extern int game_set_report(t_game * game, t_account * account, char const * rephead, char const * repbody){ unsigned int pos; if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!account) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return -1; } if (!game->players) { eventlog(eventlog_level_error,__FUNCTION__,"player array is NULL"); return -1; } if (!game->report_heads) { eventlog(eventlog_level_error,__FUNCTION__,"report_heads array is NULL"); return -1; } if (!game->report_bodies) { eventlog(eventlog_level_error,__FUNCTION__,"report_bodies array is NULL"); return -1; } if (!rephead) { eventlog(eventlog_level_error,__FUNCTION__,"report head is NULL"); return -1; } if (!repbody) { eventlog(eventlog_level_error,__FUNCTION__,"report body is NULL"); return -1; } { unsigned int i; pos = game->count; for (i=0; i<game->count; i++) if (game->players[i]==account) pos = i; } if (pos==game->count) { eventlog(eventlog_level_error,__FUNCTION__,"could not find player \"%s\" to set result",account_get_name(account)); return -1; } game->report_heads[pos] = xstrdup(rephead); game->report_bodies[pos] = xstrdup(repbody); return 0;}extern int game_set_reported_results(t_game * game, t_account * account, t_game_result * results){ unsigned int i,j; t_game_result result; if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!account) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return -1; } if (!results) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL results"); return -1; } if (!game->players) { eventlog(eventlog_level_error,__FUNCTION__,"player array is NULL"); return -1; } if (!game->reported_results) { eventlog(eventlog_level_error,__FUNCTION__,"reported_results array is NULL"); return -1; } for (i=0;i<game->count;i++) { if ((game->players[i]==account)) break; } if (i==game->count) { eventlog(eventlog_level_error,__FUNCTION__,"could not find player \"%s\" to set reported results",account_get_name(account)); return -1; } if (game->reported_results[i]) { eventlog(eventlog_level_error,__FUNCTION__,"player \"%s\" allready reported results - skipping this report",account_get_name(account)); return -1; } for (j=0;j<game->count;j++) { result = results[j]; switch(result) { case game_result_win: case game_result_loss: case game_result_draw: case game_result_observer: case game_result_disconnect: break; case game_result_none: case game_result_playing: if (i != j) break; /* accept none/playing only from "others" */ default: /* result is invalid */ if (i!=j) { eventlog(eventlog_level_error,__FUNCTION__,"ignoring bad reported result %u for player \"%s\"",(unsigned int)result,account_get_name(game->players[j])); results[i]=game_result_none; } else { eventlog(eventlog_level_error,__FUNCTION__,"got bad reported result %u for self - skipping results",(unsigned int)result); return -1; } } } game->reported_results[i] = results; return 0;}extern int game_set_self_report(t_game * game, t_account * account, t_game_result result){ unsigned int i; t_game_result * results; if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!account) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return -1; } if (!game->players) { eventlog(eventlog_level_error,__FUNCTION__,"player array is NULL"); return -1; } if (!game->reported_results) { eventlog(eventlog_level_error,__FUNCTION__,"reported_results array is NULL"); return -1; } results = xmalloc(sizeof(t_game_result)*game->count); for (i=0;i<game->count;i++) { if ((game->players[i]==account)) results[i]= result; else results[i]= game_result_none; } game_set_reported_results(game,account,results); return 0;}extern t_game_result * game_get_reported_results(t_game * game, t_account * account){ unsigned int i; if (!(game)) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } if (!(account)) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return NULL; } if (!(game->players)) { eventlog(eventlog_level_error,__FUNCTION__,"player array is NULL"); return NULL; } if (!(game->reported_results)) { eventlog(eventlog_level_error,__FUNCTION__,"reported_results array is NULL"); return NULL; } for (i=0;i<game->count;i++) { if ((game->players[i]==account)) break; } if (i==game->count) { eventlog(eventlog_level_error,__FUNCTION__,"could not find player \"%s\" to set reported results",account_get_name(account)); return NULL; } if (!(game->reported_results[i])) { eventlog(eventlog_level_error,__FUNCTION__,"player \"%s\" has not reported any results",account_get_name(account)); return NULL; } return game->reported_results[i];}extern char const * game_get_mapname(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } return game->mapname;}extern int game_set_mapname(t_game * game, char const * mapname){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!mapname) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL mapname"); return -1; } if (game->mapname != NULL) xfree((void *)game->mapname); game->mapname = xstrdup(mapname); return 0;}extern t_connection * game_get_owner(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } return game->owner;}extern time_t game_get_create_time(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return (time_t)0; } return game->create_time;}extern time_t game_get_start_time(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return (time_t)0; } return game->start_time;}extern int game_set_option(t_game * game, t_game_option option){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->option = option; return 0;}extern t_game_option game_get_option(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return game_option_none; } return game->option;}extern int gamelist_create(void){ elist_init(&gamelist_head); glist_length = 0; return 0;}extern int gamelist_destroy(void){ /* FIXME: if called with active games, games are not freed */ elist_init(&gamelist_head); glist_length = 0; return 0;}extern int gamelist_get_length(void){ return glist_length;}extern t_game * gamelist_find_game(char const * name, t_clienttag ctag, t_game_type type){ t_elist *curr; t_game *game; elist_for_each(curr,&gamelist_head) { game = elist_entry(curr,t_game,glist_link); if ((type==game_type_all || game->type==type) && ctag == game->clienttag && game->name && !strcasecmp(name,game->name)) return game; } return NULL;}extern t_game * gamelist_find_game_byid(unsigned int id){ t_elist *curr; t_game *game; elist_for_each(curr,&gamelist_head) { game = elist_entry(curr,t_game,glist_link); if (game->id==id) return game; } return NULL;}extern void gamelist_traverse(t_glist_func cb, void *data){ t_elist *curr; elist_for_each(curr,&gamelist_head) { if (cb(elist_entry(curr,t_game,glist_link),data)<0) return; }}extern int gamelist_total_games(void){ return totalcount;}extern int game_set_realm(t_game * game, unsigned int realm) { if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->realm = realm; return 0;} extern unsigned int game_get_realm(t_game const * game) { if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->realm; } extern int game_set_realmname(t_game * game, char const * realmname) { char const * temp; if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (realmname) temp=xstrdup(realmname); else temp=NULL; if (game->realmname) xfree((void *)game->realmname); /* avoid warning */ game->realmname = temp; return 0; } extern char const * game_get_realmname(t_game const * game) { if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } return game->realmname; } extern void gamelist_check_voidgame(void) { t_elist *curr, *save; t_game *game; elist_for_each_safe(curr,&gamelist_head,save) { game = elist_entry(curr,t_game,glist_link); if (!game->realm) continue; if (game->ref >= 1) continue; if ((now - game->lastaccess_time) > MAX_GAME_EMPTY_TIME) game_destroy(game); }}extern void game_set_flag(t_game * game, t_game_flag flag){ if (!game) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL game"); return; } game->flag = flag;}extern t_game_flag game_get_flag(t_game const * game){ if (!game) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL game"); return 0; } return game->flag;}extern int game_get_count_by_clienttag(t_clienttag ct){ t_game *game; t_elist *curr; int clienttaggames = 0; if (!ct) { eventlog(eventlog_level_error, __FUNCTION__, "got UNKNOWN clienttag"); return 0; } /* Get number of games for client tag specific */ elist_for_each(curr,&gamelist_head) { game = elist_entry(curr,t_game,glist_link); if(game_get_clienttag(game)==ct) clienttaggames++; } return clienttaggames;}static int game_match_name(const char *name, const char *prefix){ /* the easy cases */ if (!name || !*name) return 1; if (!prefix || !*prefix) return 1; if (!strncmp(name,prefix,strlen(prefix))) return 1; return 0;}extern int game_is_ladder(t_game *game){ assert(game); /* all normal ladder games are still counted as ladder games */ if (game->type == game_type_ladder || game->type == game_type_ironman) return 1; /* addition game types are also checked against gamename prefix if set */ if (game_match_type(game_get_type(game),prefs_get_ladder_games()) && game_match_name(game_get_name(game),prefs_get_ladder_prefix())) return 1; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -