From e9c9b66ae92f4b95061d2b93e5db182d0c80b526 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Tue, 2 Sep 2014 12:53:20 -0400 Subject: Make players check inventory modification properly --- src/environment.cpp | 1 + src/inventory.cpp | 7 +++++++ src/inventory.h | 14 +++++++++++++- src/player.cpp | 8 ++++---- src/player.h | 11 +++++++++-- src/server.cpp | 7 +++++-- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index 4106ecdf5..8977ee673 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -478,6 +478,7 @@ Player *ServerEnvironment::loadPlayer(const std::string &playername) if (newplayer) { addPlayer(player); } + player->setModified(false); return player; } diff --git a/src/inventory.cpp b/src/inventory.cpp index 4766524dd..cecef01a0 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -831,6 +831,7 @@ Inventory::~Inventory() void Inventory::clear() { + m_dirty = true; for(u32 i=0; iaddItem(newitem); } - + + bool checkModified() const + { + return m_dirty; + } + + void setModified(const bool x) + { + m_dirty = x; + } + private: // -1 if not found const s32 getListIndex(const std::string &name) const; std::vector m_lists; IItemDefManager *m_itemdef; + bool m_dirty; }; #endif diff --git a/src/player.cpp b/src/player.cpp index a8f95bb99..13866e5f5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -64,6 +64,7 @@ Player::Player(IGameDef *gamedef, const char *name): craft->setWidth(3); inventory.addList("craftpreview", 1); inventory.addList("craftresult", 1); + inventory.setModified(false); // Can be redefined via Lua inventory_formspec = "size[8,7.5]" @@ -203,6 +204,7 @@ void Player::deSerialize(std::istream &is, std::string playername) playername + " not found!"); } + m_dirty = true; //args.getS32("version"); // Version field value not used std::string name = args.get("name"); strlcpy(m_name, name.c_str(), PLAYERNAME_SIZE); @@ -235,8 +237,6 @@ void Player::deSerialize(std::istream &is, std::string playername) inventory.getList("craftresult")->changeItem(0, ItemStack()); } } - - m_dirty = false; } u32 Player::addHud(HudElement *toadd) @@ -299,7 +299,7 @@ void RemotePlayer::save(std::string savedir) if (!fs::safeWriteToFile(path, ss.str())) { infostream << "Failed to write " << path << std::endl; } - m_dirty = false; + setModified(false); return; } // Open file and deserialize @@ -317,7 +317,7 @@ void RemotePlayer::save(std::string savedir) if (!fs::safeWriteToFile(path, ss.str())) { infostream << "Failed to write " << path << std::endl; } - m_dirty = false; + setModified(false); return; } path = savedir + m_name + itos(i); diff --git a/src/player.h b/src/player.h index aa38996a5..a5cc7123f 100644 --- a/src/player.h +++ b/src/player.h @@ -226,9 +226,16 @@ public: void serialize(std::ostream &os); void deSerialize(std::istream &is, std::string playername); - bool checkModified() + bool checkModified() const { - return m_dirty; + return m_dirty || inventory.checkModified(); + } + + void setModified(const bool x) + { + m_dirty = x; + if (x == false) + inventory.setModified(x); } bool touching_ground; diff --git a/src/server.cpp b/src/server.cpp index 4f4763ea4..6afe600ed 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -5039,13 +5039,16 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id) if (!player) { newplayer = true; player = new RemotePlayer(this, name); - /* Set player position */ + // Set player position infostream<<"Server: Finding spawn place for player \"" <getServerMap()); player->setPosition(pos); - /* Add player to environment */ + // Make sure the player is saved + player->setModified(true); + + // Add player to environment m_env->addPlayer(player); } -- cgit v1.2.3