Skip to content

Commit

Permalink
Add a bit of overly-paranoid checking, to detect hard drive failures,…
Browse files Browse the repository at this point in the history
… or similar.
  • Loading branch information
Cyp committed Jun 29, 2012
1 parent ef2b236 commit 134c51c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/netplay/netplay.cpp
Expand Up @@ -1980,6 +1980,7 @@ UBYTE NETrecvFile(NETQUEUE queue)

}
NetPlay.pMapFileHandle = PHYSFS_openWrite(fileName); // create a new file.
NetPlay.mapFileName = fileName;
}

debug(LOG_NET, "New file position is %d", currPos);
Expand All @@ -2006,8 +2007,17 @@ UBYTE NETrecvFile(NETQUEUE queue)

if (currPos + bytesToRead == fileSize) // last packet
{
PHYSFS_close(NetPlay.pMapFileHandle);
int noError = PHYSFS_close(NetPlay.pMapFileHandle);
if (noError == 0)
{
debug(LOG_ERROR, "Could not close file handle after trying to save map: %s", PHYSFS_getLastError());
}
NetPlay.pMapFileHandle = NULL;
PHYSFS_File *file = PHYSFS_openRead(NetPlay.mapFileName.c_str());
int actualFileSize = PHYSFS_fileLength(file);
PHYSFS_close(file);
NetPlay.mapFileName.clear();
ASSERT(actualFileSize == fileSize, "Downloaded map too small! Got %d, expected %d!", actualFileSize, fileSize);
}

//return the percentage count
Expand Down
3 changes: 2 additions & 1 deletion lib/netplay/netplay.h
Expand Up @@ -259,7 +259,8 @@ struct NETPLAY
bool isHost; ///< True if we are hosting the game
bool isUPNP; // if we want the UPnP detection routines to run
bool isHostAlive; /// if the host is still alive
PHYSFS_file *pMapFileHandle;
PHYSFS_file * pMapFileHandle; ///< Only non-NULL during map download.
std::string mapFileName; ///< Only valid during map download.
char gamePassword[password_string_size]; //
bool GamePassworded; // if we have a password or not.
bool ShowedMOTD; // only want to show this once
Expand Down

0 comments on commit 134c51c

Please sign in to comment.