(svn r21334) -Fix [FS#4271]: make (more) sure that the savegame and transferred file are the same file and not different ones

This commit is contained in:
rubidium 2010-11-26 22:25:02 +00:00
parent c9a186c9ff
commit 67f74559fc
3 changed files with 20 additions and 8 deletions

View File

@ -55,6 +55,7 @@ ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler()
/* If for whatever reason the handle isn't closed, do it now. */
if (this->download_file != NULL) fclose(this->download_file);
free(this->download_filename);
}
NetworkRecvStatus ClientNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
@ -692,11 +693,16 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_BEGIN)
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
if (this->download_file != NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
this->download_file = FioFOpenFile("network_client.tmp", "wb", AUTOSAVE_DIR);
char filename[MAX_PATH];
FioGetDirectory(filename, lengthof(filename), AUTOSAVE_DIR);
strecat(filename, "network_client.tmp", lastof(filename));
this->download_file = FioFOpenFile(filename, "wb", NO_DIRECTORY);
if (this->download_file == NULL) {
_switch_mode_errorstr = STR_NETWORK_ERROR_SAVEGAMEERROR;
return NETWORK_RECV_STATUS_SAVEGAME;
}
this->download_filename = strdup(filename);
_frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32();
@ -748,7 +754,11 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DONE)
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
/* The map is done downloading, load it */
if (!SafeSaveOrLoad("network_client.tmp", SL_LOAD, GM_NORMAL, AUTOSAVE_DIR)) {
bool load_success = SafeSaveOrLoad(this->download_filename, SL_LOAD, GM_NORMAL, NO_DIRECTORY);
free(this->download_filename);
this->download_filename = NULL;
if (!load_success) {
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
_switch_mode_errorstr = STR_NETWORK_ERROR_SAVEGAMEERROR;
return NETWORK_RECV_STATUS_SAVEGAME;

View File

@ -19,7 +19,8 @@
/** Class for handling the client side of the game connection. */
class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
private:
FILE *download_file; ///< Handle used for downloading the savegame.
FILE *download_file; ///< Handle used for downloading the savegame.
char *download_filename; ///< File name of the downloading savegame, so we open the right one.
/** Status of the connection with the server. */
enum ServerStatus {

View File

@ -371,22 +371,23 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
}
if (this->status == STATUS_AUTHORIZED) {
const char *filename = "network_server.tmp";
Packet *p;
char filename[MAX_PATH];
FioGetDirectory(filename, lengthof(filename), AUTOSAVE_DIR);
strecat(filename, "network_server.tmp", lastof(filename));
/* Make a dump of the current game */
if (SaveOrLoad(filename, SL_SAVE, AUTOSAVE_DIR) != SL_OK) usererror("network savedump failed");
if (SaveOrLoad(filename, SL_SAVE, NO_DIRECTORY) != SL_OK) usererror("network savedump failed");
if (file_pointer != NULL) fclose(file_pointer);
file_pointer = FioFOpenFile(filename, "rb", AUTOSAVE_DIR);
file_pointer = FioFOpenFile(filename, "rb", NO_DIRECTORY);
if (file_pointer == NULL) usererror("network savedump failed - could not open just saved dump");
fseek(file_pointer, 0, SEEK_END);
if (ftell(file_pointer) == 0) usererror("network savedump failed - zero sized savegame?");
/* Now send the _frame_counter and how many packets are coming */
p = new Packet(PACKET_SERVER_MAP_BEGIN);
Packet *p = new Packet(PACKET_SERVER_MAP_BEGIN);
p->Send_uint32(_frame_counter);
p->Send_uint32(ftell(file_pointer));
this->Send_Packet(p);