- std::set<Player*> saved_players;
-
- std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
- for(u32 i=0; i<player_files.size(); i++)
- {
- if(player_files[i].dir || player_files[i].name[0] == '.')
- continue;
-
- // Full path to this file
- std::string path = players_path + "/" + player_files[i].name;
-
- //infostream<<"Checking player file "<<path<<std::endl;
-
- // Load player to see what is its name
- RemotePlayer testplayer(m_gamedef);
- {
- // Open file and deserialize
- std::ifstream is(path.c_str(), std::ios_base::binary);
- if(is.good() == false)
- {
- infostream<<"Failed to read "<<path<<std::endl;
- continue;
- }
- testplayer.deSerialize(is, player_files[i].name);
- }
-
- //infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
-
- // Search for the player
- std::string playername = testplayer.getName();
- Player *player = getPlayer(playername.c_str());
- if(player == NULL)
- {
- infostream<<"Didn't find matching player, ignoring file "<<path<<std::endl;
- continue;
- }
-
- //infostream<<"Found matching player, overwriting."<<std::endl;
-
- // OK, found. Save player there.
- if(player->checkModified())
- {
- // Open file and serialize
- std::ostringstream ss(std::ios_base::binary);
- player->serialize(ss);
- if(!fs::safeWriteToFile(path, ss.str()))
- {
- infostream<<"Failed to write "<<path<<std::endl;
- continue;
- }
- saved_players.insert(player);
- } else {
- saved_players.insert(player);