Fix usage of destroyed mutex

Also fix a memory leak
Fix overloaded virtual warning in Player::move()
Remove some trailing whitespace
This commit is contained in:
kwolekr 2015-03-31 23:33:30 -04:00
parent 699e066bea
commit b4247dff2e
2 changed files with 85 additions and 80 deletions

View File

@ -453,41 +453,43 @@ void ServerEnvironment::savePlayer(const std::string &playername)
Player *ServerEnvironment::loadPlayer(const std::string &playername)
{
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 found = false;
std::string players_path = m_path_world + DIR_DELIM "players" DIR_DELIM;
std::string path = players_path + playername;
RemotePlayer *player = static_cast<RemotePlayer *>(getPlayer(playername.c_str()));
if (!player) {
player = new RemotePlayer(m_gamedef, playername.c_str());
player = new RemotePlayer(m_gamedef, "");
newplayer = true;
}
RemotePlayer testplayer(m_gamedef, "");
std::string path = players_path + playername;
for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES; i++) {
// Open file and deserialize
//// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
if (!is.good()) {
return NULL;
}
testplayer.deSerialize(is, path);
if (!is.good())
continue;
player->deSerialize(is, path);
is.close();
if (testplayer.getName() == playername) {
*player = testplayer;
if (player->getName() == playername) {
found = true;
break;
}
path = players_path + playername + itos(i);
}
if (!found) {
infostream << "Player file for player " << playername
<< " not found" << std::endl;
if (newplayer)
delete player;
return NULL;
}
if (newplayer) {
if (newplayer)
addPlayer(player);
}
player->setModified(false);
return player;
}

View File

@ -92,6 +92,9 @@ class PlayerSAO;
struct HudElement;
class Environment;
// IMPORTANT:
// Do *not* perform an assignment or copy operation on a Player or
// RemotePlayer object! This will copy the lock held for HUD synchronization
class Player
{
public:
@ -102,7 +105,7 @@ public:
virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
{}
virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
std::list<CollisionInfo> *collision_info)
std::vector<CollisionInfo> *collision_info)
{}
v3f getSpeed()