@ -116,13 +116,13 @@ const void SaveFile::SaveGame(){
utils : : datafile : : INITIAL_SETUP_COMPLETE = true ;
utils : : datafile : : INITIAL_SETUP_COMPLETE = true ;
# ifdef __EMSCRIPTEN__
# ifdef __EMSCRIPTEN__
Server_SaveFile ( ) ;
Server_SaveFile ( [ ] ( std : : string_view response ) { } ) ;
# endif
# endif
}
}
const void SaveFile : : LoadGame ( ) {
const void SaveFile : : LoadGame ( ) {
# ifdef __EMSCRIPTEN__
# ifdef __EMSCRIPTEN__
Server_GetFile ( ) ;
Server_GetFile ( [ ] ( std : : string_view response ) { } ) ;
# else
# else
std : : filesystem : : create_directories ( " save_file_path " _S ) ;
std : : filesystem : : create_directories ( " save_file_path " _S ) ;
utils : : datafile loadFile ;
utils : : datafile loadFile ;
@ -224,23 +224,39 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
operationName = std : : format ( " SAVE_FILE " ) ;
operationName = std : : format ( " SAVE_FILE " ) ;
//Data should contain the entire contents of our save file.
//Data should contain the entire contents of our save file.
} break ;
} break ;
case SaveFileOperation : : SAVE_METADATA_FILE : {
operationName = std : : format ( " SAVE_METADATA_FILE " ) ;
//Data should contain the entire contents of our metadata save file.
} break ;
}
}
dataString + = " &operation= " + operationName ;
dataString + = " &operation= " + operationName ;
dataString + = " &checksum= " + std : : to_string ( CalculateChecksum ( operationName , data ) ) ;
dataString + = " &checksum= " + std : : to_string ( CalculateChecksum ( operationName , data ) ) ;
dataString + = " &data= " + std : : string ( data ) ;
dataString + = " &data= " + std : : string ( data ) ;
return " save_server " _S + dataString ;
return " save_server " _S + dataString ;
}
}
const void SaveFile : : Server_GetLoadInfo ( ) {
const void SaveFile : : Server_GetLoadInfo ( std : : function < void ( std : : string_view ) > respCallbackFunc ) {
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : GET_LOAD_FILES , " 0 " ) , " " ) ;
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : GET_LOAD_FILES , " 0 " ) , " " ) ;
game - > responseCallback = respCallbackFunc ;
}
}
const void SaveFile : : Server_GetFile ( ) {
const void SaveFile : : Server_GetFile ( std : : function < void ( std : : string_view ) > respCallbackFunc ) {
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : GET_FILE , std : : to_string ( saveFileID ) ) , " " ) ;
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : GET_FILE , std : : to_string ( saveFileID ) ) , " " ) ;
game - > responseCallback = respCallbackFunc ;
}
}
const void SaveFile : : Server_SaveFile ( ) {
const void SaveFile : : Server_SaveFile ( std : : function < void ( std : : string_view ) > respCallbackFunc ) {
std : : stringstream fileContents ;
std : : stringstream fileContents ;
std : : ifstream file ( " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
std : : ifstream file ( " save_file_path " _S + std : : format ( " save.{:04} " , saveFileID ) ) ;
while ( file . good ( ) ) {
while ( file . good ( ) ) {
fileContents < < char ( file . get ( ) ) ;
fileContents < < char ( file . get ( ) ) ;
}
}
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : SAVE_FILE , std : : to_string ( saveFileID ) + " | " + fileContents . str ( ) ) , " " ) ;
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : SAVE_FILE , std : : to_string ( saveFileID ) + " | " + fileContents . str ( ) ) , " " ) ;
game - > responseCallback = respCallbackFunc ;
}
const void SaveFile : : Server_SaveMetadataFile ( std : : function < void ( std : : string_view ) > respCallbackFunc ) {
std : : stringstream fileContents ;
std : : ifstream file ( " save_file_path " _S + " metadata.dat " ) ;
while ( file . good ( ) ) {
fileContents < < char ( file . get ( ) ) ;
}
game - > SendRequest ( CreateServerRequest ( SaveFileOperation : : SAVE_METADATA_FILE , fileContents . str ( ) ) , " " ) ;
game - > responseCallback = respCallbackFunc ;
}
}