mirror of https://github.com/OpenTTD/OpenTTD
(svn r21334) -Fix [FS#4271]: make (more) sure that the savegame and transferred file are the same file and not different ones
parent
c9a186c9ff
commit
67f74559fc
|
@ -55,6 +55,7 @@ ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler()
|
||||||
|
|
||||||
/* If for whatever reason the handle isn't closed, do it now. */
|
/* If for whatever reason the handle isn't closed, do it now. */
|
||||||
if (this->download_file != NULL) fclose(this->download_file);
|
if (this->download_file != NULL) fclose(this->download_file);
|
||||||
|
free(this->download_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
|
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->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
|
||||||
if (this->download_file != NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
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) {
|
if (this->download_file == NULL) {
|
||||||
_switch_mode_errorstr = STR_NETWORK_ERROR_SAVEGAMEERROR;
|
_switch_mode_errorstr = STR_NETWORK_ERROR_SAVEGAMEERROR;
|
||||||
return NETWORK_RECV_STATUS_SAVEGAME;
|
return NETWORK_RECV_STATUS_SAVEGAME;
|
||||||
}
|
}
|
||||||
|
this->download_filename = strdup(filename);
|
||||||
|
|
||||||
_frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32();
|
_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);
|
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
|
||||||
|
|
||||||
/* The map is done downloading, load it */
|
/* 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);
|
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
||||||
_switch_mode_errorstr = STR_NETWORK_ERROR_SAVEGAMEERROR;
|
_switch_mode_errorstr = STR_NETWORK_ERROR_SAVEGAMEERROR;
|
||||||
return NETWORK_RECV_STATUS_SAVEGAME;
|
return NETWORK_RECV_STATUS_SAVEGAME;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
|
class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
|
||||||
private:
|
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. */
|
/** Status of the connection with the server. */
|
||||||
enum ServerStatus {
|
enum ServerStatus {
|
||||||
|
|
|
@ -371,22 +371,23 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->status == STATUS_AUTHORIZED) {
|
if (this->status == STATUS_AUTHORIZED) {
|
||||||
const char *filename = "network_server.tmp";
|
char filename[MAX_PATH];
|
||||||
Packet *p;
|
FioGetDirectory(filename, lengthof(filename), AUTOSAVE_DIR);
|
||||||
|
strecat(filename, "network_server.tmp", lastof(filename));
|
||||||
|
|
||||||
/* Make a dump of the current game */
|
/* 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);
|
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");
|
if (file_pointer == NULL) usererror("network savedump failed - could not open just saved dump");
|
||||||
|
|
||||||
fseek(file_pointer, 0, SEEK_END);
|
fseek(file_pointer, 0, SEEK_END);
|
||||||
if (ftell(file_pointer) == 0) usererror("network savedump failed - zero sized savegame?");
|
if (ftell(file_pointer) == 0) usererror("network savedump failed - zero sized savegame?");
|
||||||
|
|
||||||
/* Now send the _frame_counter and how many packets are coming */
|
/* 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(_frame_counter);
|
||||||
p->Send_uint32(ftell(file_pointer));
|
p->Send_uint32(ftell(file_pointer));
|
||||||
this->Send_Packet(p);
|
this->Send_Packet(p);
|
||||||
|
|
Loading…
Reference in New Issue