Merge branch 'master' of github.com:Thomas776/SAE102-SpaceInvaders
This commit is contained in:
		
						commit
						b0c029b2be
					
				| @ -1,3 +1,6 @@ | ||||
| 11083679872916328441 | ||||
| 13363418835389185581 | ||||
| thomas2,2 | ||||
| thomas2,2 | ||||
| thomas2,2 | ||||
| thomas2,2 | ||||
| thomas2,2 | ||||
| thomas,1 | ||||
|  | ||||
| @ -21,7 +21,7 @@ static std::hash<string> hasher; | ||||
| bool verifyHash(size_t savedHash, string& content){ | ||||
| 	// non-cryptographic hash, but it is part of the std, and openssl is REALLY difficult
 | ||||
| 	// to use in C++ while keeping semantic, because there are no wrappers...
 | ||||
| 	int actualHash = hasher(content+SECRET_KEY); | ||||
| 	size_t actualHash = hasher(content+SECRET_KEY); | ||||
| 	return actualHash==savedHash; | ||||
| } | ||||
| 
 | ||||
| @ -35,6 +35,7 @@ void ScoresManager::readFile() { | ||||
| 	 */ | ||||
| 	size_t hash; | ||||
| 	ifs >> hash; | ||||
| 	ifs.get(); // remove \n
 | ||||
| 
 | ||||
| 	string content; | ||||
| 	readWholeFile(ifs, content); | ||||
| @ -44,14 +45,12 @@ void ScoresManager::readFile() { | ||||
| 		stringstream ss(content); | ||||
| 
 | ||||
| 		string line; | ||||
| 		Score s; | ||||
| 		while(true){ | ||||
| 			getline(ss, line); | ||||
| 			if(ss.eof())break; | ||||
| 
 | ||||
| 			size_t index = line.find(','); | ||||
| 			s.name = line.substr(0, index); | ||||
| 			s.points = stoi(line.substr(index)); | ||||
| 			scores.emplace_back(line.substr(0, index), stoi(line.substr(index+1))); | ||||
| 		} | ||||
| 	}else{ | ||||
| 		cerr << "Integrity check of the save file failed. Has it been tampered ?" << endl; | ||||
| @ -61,8 +60,7 @@ void ScoresManager::readFile() { | ||||
| void ScoresManager::writeFile() { | ||||
| 	ofstream ofs(SCORE_FILE); | ||||
| 
 | ||||
| 	string str; | ||||
| 	cout << scores.size() << endl; | ||||
| 	string str; // this one must be counted in the hash too
 | ||||
| 	for(Score& sc : scores){ | ||||
| 		str.append(sc.name); | ||||
| 		str.append(","); | ||||
| @ -70,7 +68,7 @@ void ScoresManager::writeFile() { | ||||
| 		str.append("\n"); | ||||
| 	} | ||||
| 
 | ||||
| 	ofs << hasher(str) << endl << str; | ||||
| 	ofs << hasher(str+SECRET_KEY) << endl << str; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user