Make sure file hash does not include the | character due to emscripten using it to split a save request.

pull/57/head
sigonasr2 8 months ago
parent ad79910848
commit 3c2c19f822
  1. 5
      Adventures in Lestoria/SaveFile.cpp
  2. 4
      Adventures in Lestoria/olcUTIL_DataFile.h
  3. 5
      Adventures in Lestoria/util.cpp

@ -184,7 +184,7 @@ const void SaveFile::SaveGame(){
std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID)); std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID));
saveFile["Hash"].SetString(fileHash); saveFile["Hash"].SetString(fileHash);
std::cout<<"Setting Hash to "<<fileHash<<". Writing to File..."<<std::endl;
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); //Once the hash has been computed and added, save the file a second time. utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); //Once the hash has been computed and added, save the file a second time.
utils::datafile::Write(saveSystemFile,"save_file_path"_S+"system.conf"); utils::datafile::Write(saveSystemFile,"save_file_path"_S+"system.conf");
utils::datafile metadata; utils::datafile metadata;
@ -298,6 +298,7 @@ void SaveFile::LoadFile(){
if(expectedFileHash!=fileHash){ if(expectedFileHash!=fileHash){
LOG(std::format("WARNING! Filehash for file {} was not identified as proper! Will not load this file!","save_file_path"_S+std::format("save.{:04}",saveFileID))); LOG(std::format("WARNING! Filehash for file {} was not identified as proper! Will not load this file!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
LOG("Expected vs Actual: "<<expectedFileHash<<std::endl<<fileHash<<std::endl)
return; return;
} }
@ -595,7 +596,7 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
*/ */
const std::array uriReserved={';','/','?',':','@','&','=','+','$',',','-','_','.','!','~','*','\'','(',')','#'}; const std::array uriReserved={';','/','?',':','@','&','=','+','$',',','-','_','.','!','~','*','\'','(',')','#'};
if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9'||std::find(uriReserved.begin(),uriReserved.end(),c)!=uriReserved.end())return std::move(str)+c; if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9'||std::find(uriReserved.begin(),uriReserved.end(),c)!=uriReserved.end())return std::move(str)+c;
std::string convertedChar=std::format("%{:02x}",c); std::string convertedChar=std::format("%{:02x}",c);
std::for_each(convertedChar.begin(),convertedChar.end(),[](char&c){c=char(std::toupper(c));}); std::for_each(convertedChar.begin(),convertedChar.end(),[](char&c){c=char(std::toupper(c));});
return std::move(str)+convertedChar; return std::move(str)+convertedChar;

@ -267,9 +267,11 @@ namespace olc::utils
// Value does not contain separator, so just write out // Value does not contain separator, so just write out
file << property.second.GetString(i) << ((nItems > 1) ? sSeperator : ""); file << property.second.GetString(i) << ((nItems > 1) ? sSeperator : "");
} }
std::cout<<"Written: "<<property.second.GetString(i)<<std::endl;
nItems--; nItems--;
} }
std::cout<<"Write newline."<<std::endl;
// Property written, move to next line // Property written, move to next line
file << "\n"; file << "\n";
} }

@ -161,13 +161,14 @@ std::string util::GetHash(std::string fileName){
hashChar=hash[hashIndex]; hashChar=hash[hashIndex];
} }
char newChar=file.get(); char newChar=file.get();
if(newChar=='\r'||newChar=='\n')continue; if(newChar=='\r'||newChar=='\f'||newChar=='\n')continue;
hashChar+=newChar*21-7; hashChar+=newChar*21-7;
hashChar^=hashIndex; hashChar^=hashIndex;
if(hashIndex>0)hashChar+=hash[hashIndex-1]; if(hashIndex>0)hashChar+=hash[hashIndex-1];
hashChar%=94; hashChar%=94;
hashChar+=32; hashChar+=32;
if(hashChar=='"'){hashChar+=60;} if(hashChar=='"'||hashChar==',')hashChar+=60;
if(hashChar=='|')hashChar++; //FORBIDDEN CHARACTER IN EMSCRIPTEN BUILD!
if(hash.size()<std::numeric_limits<uint8_t>::max()){ if(hash.size()<std::numeric_limits<uint8_t>::max()){
hash+=hashChar; hash+=hashChar;
}else{ }else{

Loading…
Cancel
Save