diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-06-01 13:11:37 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-06-23 15:45:59 -0400 |
commit | e491f8cd485f5602c056b8b6c5e0c8c395e4a633 (patch) | |
tree | 003321151f1c1654bb6d6681a13fbd3c0c4affaa /src/environment.cpp | |
parent | 7e6db1b80344a519e53a9967a159c8d3585a9b9d (diff) | |
download | minetest-e491f8cd485f5602c056b8b6c5e0c8c395e4a633.tar.gz minetest-e491f8cd485f5602c056b8b6c5e0c8c395e4a633.tar.bz2 minetest-e491f8cd485f5602c056b8b6c5e0c8c395e4a633.zip |
Only try to load from possible player files
Diffstat (limited to 'src/environment.cpp')
-rw-r--r-- | src/environment.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/environment.cpp b/src/environment.cpp index 91f5ea2b6..d068aa788 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -443,46 +443,35 @@ void ServerEnvironment::savePlayer(const std::string &playername) Player *ServerEnvironment::loadPlayer(const std::string &playername) { - std::string players_path = m_path_world + DIR_DELIM "players"; + std::string players_path = m_path_world + DIR_DELIM "players" DIR_DELIM; RemotePlayer *player = static_cast<RemotePlayer*>(getPlayer(playername.c_str())); bool newplayer = false; - bool foundplayer = false; + bool found = false; if (!player) { player = new RemotePlayer(m_gamedef); newplayer = true; } - std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path); - for (u32 i = 0; i < player_files.size(); i++) { - if (player_files[i].dir) - continue; - - // Full path to this file - std::string path = players_path + "/" + player_files[i].name; - - // Load player to see what is its name + RemotePlayer testplayer(m_gamedef); + std::string path = players_path + playername; + for (u32 i = 0; i < 1000; i++) { + // Open file and deserialize std::ifstream is(path.c_str(), std::ios_base::binary); if (!is.good()) { - infostream << "Failed to read " << path << std::endl; - continue; + return NULL; } - player->deSerialize(is, player_files[i].name); - - if (!string_allowed(player->getName(), PLAYERNAME_ALLOWED_CHARS)) { - infostream << "Not loading player with invalid name: " - << player->getName() << std::endl; - continue; - } - - if (player->getName() == playername) { - // We found our player - foundplayer = true; + testplayer.deSerialize(is, path); + if (testplayer.getName() == playername) { + *player = testplayer; + found = true; break; } - + path = players_path + playername + itos(i); } - if (!foundplayer) { + if (!found) { + infostream << "Player file for player " << playername + << " not found" << std::endl; return NULL; } if (newplayer) { |