Don't use uninitialized ps from BotAI_GetClientState

If BotAI_GetPlayerState returns qfalse, ps is untouched and in
some cases means uninitialized. So don't use it if not valid.
This commit is contained in:
Zack Middleton 2017-06-07 19:02:01 -05:00
parent 74aa4268b2
commit 6e340f9a5b
4 changed files with 18 additions and 13 deletions

View File

@ -100,8 +100,7 @@ int BotIsFirstInRankings(bot_state_t *bs) {
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (score < ps.persistant[PERS_SCORE]) return qfalse;
if (BotAI_GetClientState(i, &ps) && score < ps.persistant[PERS_SCORE]) return qfalse;
}
return qtrue;
}
@ -124,8 +123,7 @@ int BotIsLastInRankings(bot_state_t *bs) {
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (score > ps.persistant[PERS_SCORE]) return qfalse;
if (BotAI_GetClientState(i, &ps) && score > ps.persistant[PERS_SCORE]) return qfalse;
}
return qtrue;
}
@ -150,8 +148,7 @@ char *BotFirstClientInRankings(void) {
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (ps.persistant[PERS_SCORE] > bestscore) {
if (BotAI_GetClientState(i, &ps) && ps.persistant[PERS_SCORE] > bestscore) {
bestscore = ps.persistant[PERS_SCORE];
bestclient = i;
}
@ -180,8 +177,7 @@ char *BotLastClientInRankings(void) {
//skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
//
BotAI_GetClientState(i, &ps);
if (ps.persistant[PERS_SCORE] < worstscore) {
if (BotAI_GetClientState(i, &ps) && ps.persistant[PERS_SCORE] < worstscore) {
worstscore = ps.persistant[PERS_SCORE];
bestclient = i;
}

View File

@ -206,7 +206,10 @@ qboolean EntityIsDead(aas_entityinfo_t *entinfo) {
if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) {
//retrieve the current client state
BotAI_GetClientState( entinfo->number, &ps );
if (!BotAI_GetClientState(entinfo->number, &ps)) {
return qfalse;
}
if (ps.pm_type != PM_NORMAL) return qtrue;
}
return qfalse;

View File

@ -990,8 +990,10 @@ int BotAI(int client, float thinktime) {
}
//retrieve the current client state
BotAI_GetClientState( client, &bs->cur_ps );
if (!BotAI_GetClientState(client, &bs->cur_ps)) {
BotAI_Print(PRT_FATAL, "BotAI: failed to get player state for player %d\n", client);
return qfalse;
}
//retrieve any waiting server commands
while( trap_BotGetServerCommand(client, buf, sizeof(buf)) ) {
//have buf point to the command and args to the command arguments

View File

@ -108,8 +108,12 @@ int BotClientTravelTimeToGoal(int client, bot_goal_t *goal) {
playerState_t ps;
int areanum;
BotAI_GetClientState(client, &ps);
if (BotAI_GetClientState(client, &ps)) {
areanum = BotPointAreaNum(ps.origin);
} else {
areanum = 0;
}
if (!areanum) return 1;
return trap_AAS_AreaTravelTimeToGoalArea(areanum, ps.origin, goal->areanum, TFL_DEFAULT);
}