📄 game.c
字号:
eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->maptype = maptype; return 0;}extern t_game_tileset game_get_tileset(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return game_tileset_none; } return game->tileset;}extern int game_set_tileset(t_game * game, t_game_tileset tileset){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->tileset = tileset; return 0;}extern t_game_speed game_get_speed(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return game_speed_none; } return game->speed;}extern int game_set_speed(t_game * game, t_game_speed speed){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->speed = speed; return 0;}extern unsigned int game_get_mapsize_x(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->mapsize_x;}extern int game_set_mapsize_x(t_game * game, unsigned int x){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->mapsize_x = x; return 0;}extern unsigned int game_get_mapsize_y(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->mapsize_y;}extern int game_set_mapsize_y(t_game * game, unsigned int y){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->mapsize_y = y; return 0;}extern unsigned int game_get_maxplayers(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->maxplayers;}extern int game_set_maxplayers(t_game * game, unsigned int maxplayers){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->maxplayers = maxplayers; return 0;}extern unsigned int game_get_difficulty(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->difficulty;}extern int game_set_difficulty(t_game * game, unsigned int difficulty){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } game->difficulty = difficulty; return 0;}extern char const * game_get_description(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } return game->description;}extern int game_set_description(t_game * game, char const * description){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!description) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL description"); return -1; } if (game->description != NULL) xfree((void *)game->description); game->description = xstrdup(description); return 0;}extern char const * game_get_pass(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } return game->pass;}extern char const * game_get_info(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } return game->info;}extern int game_get_startver(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->startver;}extern unsigned long game_get_version(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->version;}extern unsigned int game_get_ref(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->ref;}extern unsigned int game_get_count(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->count;}extern void game_set_status(t_game * game, t_game_status status){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return; } // [quetzal] 20020829 - this should prevent invalid status changes // its like started game cant become open and so on if (game->status == game_status_started && (status == game_status_open || status == game_status_full)) { eventlog(eventlog_level_error, "game_set_status", "attempting to set status '%s' (%d) to started game", game_status_get_str(status), status); return; } if (game->status == game_status_done && status != game_status_done) { eventlog(eventlog_level_error, "game_set_status", "attempting to set status '%s' (%d) to done game", game_status_get_str(status), status); return; } if (status==game_status_started && game->start_time==(time_t)0) game->start_time = now; game->status = status;}extern t_game_status game_get_status(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->status;}extern unsigned int game_get_addr(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->addr; /* host byte order */}extern unsigned short game_get_port(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->port; /* host byte order */}extern unsigned int game_get_latency(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } if (game->ref<1) { eventlog(eventlog_level_error,__FUNCTION__,"game \"%s\" has no players",game_get_name(game)); return 0; } if (!game->players) { eventlog(eventlog_level_error,__FUNCTION__,"game \"%s\" has NULL players array (ref=%u)",game_get_name(game),game->ref); return 0; } if (!game->players[0]) { eventlog(eventlog_level_error,__FUNCTION__,"game \"%s\" has NULL players[0] entry (ref=%u)",game_get_name(game),game->ref); return 0; } return 0; /* conn_get_latency(game->players[0]); */}extern t_connection * game_get_player_conn(t_game const * game, unsigned int i){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return NULL; } if (game->ref<1) { eventlog(eventlog_level_error,__FUNCTION__,"game \"%s\" has no players",game_get_name(game)); return NULL; } if (!game->players) { eventlog(eventlog_level_error,__FUNCTION__,"game \"%s\" has NULL player array (ref=%u)",game_get_name(game),game->ref); return NULL; } if (!game->players[i]) { eventlog(eventlog_level_error,__FUNCTION__,"game \"%s\" has NULL players[i] entry (ref=%u)",game_get_name(game),game->ref); return NULL; } return game->connections[i];}extern t_clienttag game_get_clienttag(t_game const * game){ if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return 0; } return game->clienttag;}extern int game_add_player(t_game * game, char const * pass, int startver, t_connection * c){ t_connection * * tempc; t_account * * tempp; t_game_result * tempr; t_game_result ** temprr; char const * * temprh; char const * * temprb; unsigned int i = 0; if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!pass) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL password"); return -1; } if (startver!=STARTVER_UNKNOWN && startver!=STARTVER_GW1 && startver!=STARTVER_GW3 && startver!=STARTVER_GW4 && startver!=STARTVER_REALM1) { eventlog(eventlog_level_error,__FUNCTION__,"got bad game startver %d",startver); return -1; } if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } if (game->type==game_type_ladder && account_get_normal_wins(conn_get_account(c),conn_get_clienttag(c))<10) /* if () ... */ { eventlog(eventlog_level_error,__FUNCTION__,"can not join ladder game without 10 normal wins"); return -1; } { t_clienttag gt; if (!(gt = game_get_clienttag(game))) { eventlog(eventlog_level_error,__FUNCTION__,"could not get clienttag for game"); return -1; } } if (game->pass[0]!='\0' && strcasecmp(game->pass,pass)!=0) { eventlog(eventlog_level_debug,__FUNCTION__,"game \"%s\" password mismatch \"%s\"!=\"%s\"",game_get_name(game),game->pass,pass); return -1; } if (game->connections && (game->count > 0)) { for (i=0; i<game->count; i++) { if (game->connections[i] == NULL) { game->connections[i] = c; game->players[i] = conn_get_account(c); game->results[i] = game_result_none; game->reported_results[i] = NULL; game->report_heads[i] = NULL; game->report_bodies[i] = NULL; game->ref++; game->lastaccess_time = now; break; } } } if ((i == game->count) || (game->count == 0)) { if (!game->connections) /* some realloc()s are broken */ tempc = xmalloc((game->count+1)*sizeof(t_connection *)); else tempc = xrealloc(game->connections,(game->count+1)*sizeof(t_connection *)); game->connections = tempc; if (!game->players) /* some realloc()s are broken */ tempp = xmalloc((game->count+1)*sizeof(t_account *)); else tempp = xrealloc(game->players,(game->count+1)*sizeof(t_account *)); game->players = tempp; if (!game->results) /* some realloc()s are broken */ tempr = xmalloc((game->count+1)*sizeof(t_game_result)); else tempr = xrealloc(game->results,(game->count+1)*sizeof(t_game_result)); game->results = tempr; if (!game->reported_results) temprr = xmalloc((game->count+1)*sizeof(t_game_result *)); else temprr = xrealloc(game->reported_results,(game->count+1)*sizeof(t_game_result *)); game->reported_results = temprr; if (!game->report_heads) /* some xrealloc()s are broken */ temprh = xmalloc((game->count+1)*sizeof(char const *)); else temprh = xrealloc((void *)game->report_heads,(game->count+1)*sizeof(char const *)); /* avoid compiler warning */ game->report_heads = temprh; if (!game->report_bodies) /* some xrealloc()s are broken */ temprb = xmalloc((game->count+1)*sizeof(char const *)); else temprb = xrealloc((void *)game->report_bodies,(game->count+1)*sizeof(char const *)); /* avoid compiler warning */ game->report_bodies = temprb; game->connections[game->count] = c; game->players[game->count] = conn_get_account(c); game->results[game->count] = game_result_none; game->reported_results[game->count] = NULL; game->report_heads[game->count] = NULL; game->report_bodies[game->count] = NULL; game->count++; game->ref++; game->lastaccess_time = now; } // end of "if ((i == game->count) || (game->count == 0))" if (game->startver!=startver && startver!=STARTVER_UNKNOWN) /* with join startver ALWAYS unknown [KWS] */ eventlog(eventlog_level_error,__FUNCTION__,"player \"%s\" client \"%s\" startver %u joining game startver %u (count=%u ref=%u)",account_get_name(conn_get_account(c)),clienttag_uint_to_str(conn_get_clienttag(c)),startver,game->startver,game->count,game->ref); game_choose_host(game); return 0;}extern int game_del_player(t_game * game, t_connection * c){ char const * tname; unsigned int i; t_account * account; if (!game) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL game"); return -1; } if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); 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; } account = conn_get_account(c); if(conn_get_leavegamewhisper_ack(c)==0) { watchlist_notify_event(conn_get_account(c),NULL,conn_get_clienttag(c),watch_event_leavegame); conn_set_leavegamewhisper_ack(c,1); //1 = already whispered. We reset this each time user joins a channel } eventlog(eventlog_level_debug,__FUNCTION__,"game \"%s\" has ref=%u, count=%u; trying to remove player \"%s\"",game_get_name(game),game->ref,game->count,account_get_name(account)); for (i=0; i<game->count; i++) if (game->players[i]==account && game->connections[i]) { eventlog(eventlog_level_debug,__FUNCTION__,"removing player #%u \"%s\" from \"%s\", %u players left",i,(tname = account_get_name(account)),game_get_name(game),game->ref-1); game->connections[i] = NULL; if (!(game->reported_results[i])) eventlog(eventlog_level_debug,__FUNCTION__,"player \"%s\" left without reporting (valid) results",tname); eventlog(eventlog_level_debug,__FUNCTION__,"player deleted... (ref=%u)",game->ref); if (game->ref<2) { eventlog(eventlog_level_debug,__FUNCTION__,"no more players, reporting game"); game_report(game); eventlog(eventlog_level_debug,__FUNCTION__,"no more players, destroying game"); game_destroy(game); return 0; } game->ref--; game->lastaccess_time = now; game_choose_host(game); return 0; } eventlog(eventlog_level_error,__FUNCTION__,"player \"%s\" was not in the game",account_get_name(account)); return -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -