Skip to content

Commit 66bb295

Browse files
authoredNov 5, 2016
PlayerSAO saving fix (#4734)
PlayerSAO::disconnected() function was historical and remove the link between SAO and RemotePlayer session. With previous attributes linked to RemotePlayer saving was working. But now attributes are read from SAO not RemotePlayer and the current serialize function verify SAO exists to save the player attributes. Because PlayerSAO::disconnected marks playersao for removal, only mark playerSAO for removal and let PlayerSAO::removingFromEnvironment do the correct saving behaviour and all the disconnection process instead of doing a partial removal and let the server loop doing the RemotePlayer cleanup and remove some saved attributes...
1 parent b5c84c3 commit 66bb295

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed
 

‎src/content_sao.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,7 @@ void PlayerSAO::removingFromEnvironment()
838838
{
839839
ServerActiveObject::removingFromEnvironment();
840840
if (m_player->getPlayerSAO() == this) {
841-
m_player->peer_id = 0;
842-
m_env->savePlayer(m_player);
843-
m_player->setPlayerSAO(NULL);
844-
m_env->removePlayer(m_player);
841+
unlinkPlayerSessionAndSave();
845842
for (UNORDERED_SET<u32>::iterator it = m_attached_particle_spawners.begin();
846843
it != m_attached_particle_spawners.end(); ++it) {
847844
m_env->deleteParticleSpawner(*it, false);
@@ -1340,15 +1337,20 @@ void PlayerSAO::setWieldIndex(int i)
13401337
}
13411338
}
13421339

1340+
// Erase the peer id and make the object for removal
13431341
void PlayerSAO::disconnected()
13441342
{
13451343
m_peer_id = 0;
13461344
m_removed = true;
1347-
if(m_player->getPlayerSAO() == this)
1348-
{
1349-
m_player->setPlayerSAO(NULL);
1350-
m_player->peer_id = 0;
1351-
}
1345+
}
1346+
1347+
void PlayerSAO::unlinkPlayerSessionAndSave()
1348+
{
1349+
assert(m_player->getPlayerSAO() == this);
1350+
m_player->peer_id = 0;
1351+
m_env->savePlayer(m_player);
1352+
m_player->setPlayerSAO(NULL);
1353+
m_env->removePlayer(m_player);
13521354
}
13531355

13541356
std::string PlayerSAO::getPropertyPacket()

‎src/content_sao.h

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class PlayerSAO : public UnitSAO
318318

319319
private:
320320
std::string getPropertyPacket();
321+
void unlinkPlayerSessionAndSave();
321322

322323
RemotePlayer *m_player;
323324
u16 m_peer_id;

‎src/remoteplayer.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ void RemotePlayer::serialize(std::ostream &os)
177177
args.set("name", m_name);
178178
//args.set("password", m_password);
179179

180-
if (m_sao) {
181-
args.setS32("hp", m_sao->getHP());
182-
args.setV3F("position", m_sao->getBasePosition());
183-
args.setFloat("pitch", m_sao->getPitch());
184-
args.setFloat("yaw", m_sao->getYaw());
185-
args.setS32("breath", m_sao->getBreath());
186-
}
180+
// This should not happen
181+
assert(m_sao);
182+
args.setS32("hp", m_sao->getHP());
183+
args.setV3F("position", m_sao->getBasePosition());
184+
args.setFloat("pitch", m_sao->getPitch());
185+
args.setFloat("yaw", m_sao->getYaw());
186+
args.setS32("breath", m_sao->getBreath());
187187

188188
args.writeLines(os);
189189

‎src/server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason)
26542654
RemotePlayer *player = m_env->getPlayer(peer_id);
26552655

26562656
/* Run scripts and remove from environment */
2657-
if(player != NULL) {
2657+
if (player != NULL) {
26582658
PlayerSAO *playersao = player->getPlayerSAO();
26592659
assert(playersao);
26602660

0 commit comments

Comments
 (0)
Please sign in to comment.