Fixed multi_all_players_alive(), making sure player is playing and not a ghost; Fixed comparison of callsign_t checks in state.cpp; Added additional check for player status before saving game in case things chenged while host decides upon savegame

This commit is contained in:
zico 2014-10-10 13:20:48 +02:00
parent 870ed653b5
commit 737b66fb96
2 changed files with 27 additions and 6 deletions

View file

@ -3576,7 +3576,9 @@ int multi_all_players_alive()
int i;
for (i=0;i<N_players;i++)
{
if (Players[i].connected)
if ((Players[i].connected == CONNECT_PLAYING) && (Objects[Players[i].objnum].type == OBJ_GHOST)) // player alive?
return (0);
if ((Players[i].connected != CONNECT_DISCONNECTED) && (Players[i].connected != CONNECT_PLAYING)) // ... and actually playing?
return (0);
}
return (1);
@ -4659,7 +4661,7 @@ void multi_initiate_save_game()
}
if (!multi_all_players_alive())
{
HUD_init_message_literal(HM_MULTI, "Can't save! All players must be alive!");
HUD_init_message_literal(HM_MULTI, "Can't save! All players must be alive and playing!");
return;
}
for (i = 0; i < N_players; i++)
@ -4693,6 +4695,24 @@ void multi_initiate_save_game()
if ( game_id == 0 )
game_id = 1; // 0 is invalid
// Execute "alive" and "duplicate callsign" checks again in case things changed while host decided upon the savegame.
if (!multi_all_players_alive())
{
HUD_init_message_literal(HM_MULTI, "Can't save! All players must be alive and playing!");
return;
}
for (i = 0; i < N_players; i++)
{
for (j = i + 1; j < N_players; j++)
{
if (i != j && Players[i].callsign == Players[j].callsign)
{
HUD_init_message_literal(HM_MULTI, "Can't save! Multiple players with same callsign!");
return;
}
}
}
multi_send_save_game( slot, game_id, desc );
multi_do_frame();
multi_save_game( slot,game_id, desc );
@ -4713,7 +4733,7 @@ void multi_initiate_restore_game()
}
if (!multi_all_players_alive())
{
HUD_init_message_literal(HM_MULTI, "Can't load! All players must be alive!");
HUD_init_message_literal(HM_MULTI, "Can't load! All players must be alive and playing!");
return;
}
for (i = 0; i < N_players; i++)

View file

@ -1327,7 +1327,7 @@ int state_restore_all_sub(const char *filename, int secret_restore)
callsign_t saved_callsign;
state_game_id = PHYSFSX_readSXE32(fp, swap);
PHYSFS_read(fp, &saved_callsign, sizeof(char)*CALLSIGN_LEN+1, 1);
if (saved_callsign != Players[Player_num].callsign) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case.
if (!(saved_callsign == Players[Player_num].callsign)) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case.
{
PHYSFS_close(fp);
return 0;
@ -1803,7 +1803,8 @@ int state_get_game_id(const char *filename)
int version;
PHYSFS_file *fp;
int swap = 0; // if file is not endian native, have to swap all shorts and ints
char id[5], saved_callsign[CALLSIGN_LEN+1];
char id[5];
callsign_t saved_callsign;
#ifndef NDEBUG
if (GameArg.SysUsePlayersDir && strncmp(filename, "Players/", 8))
@ -1840,7 +1841,7 @@ int state_get_game_id(const char *filename)
// Read Coop state_game_id to validate the savegame we are about to load matches the others
state_game_id = PHYSFSX_readSXE32(fp, swap);
PHYSFS_read(fp, &saved_callsign, sizeof(char)*CALLSIGN_LEN+1, 1);
if (saved_callsign != Players[Player_num].callsign) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case.
if (!(saved_callsign == Players[Player_num].callsign)) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case.
return 0;
return state_game_id;