Ok so here is some simple function
- server crashed if : file does not exists, file empty or first character in file is not '1' (0x31)
- server clean if : file exists and first character in this file is '1' (0x31)
Code:
bool Crashed () {
// acquire file name
char tempBuffer [1024];
GET_GAME_DIR (tempBuffer);
std::string fileName = tempBuffer;
// fix path, unix syntax
replace (fileName.begin(), fileName.end(), '\\', '/');
// our file
fileName += "/crashstatus.bin";
// open file
std::ifstream file (fileName.c_str());
if (!file.is_open()) // file does not exists, server crashed
return true;
char contents = 0; // important, we must initialize here
file >> contents; // if file is empty, contents will be unchanged
file.close();
if (contents != '1')
return true;
return false; // not crashed
}