aboutsummaryrefslogtreecommitdiff
path: root/src/remoteplayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/remoteplayer.cpp')
-rw-r--r--src/remoteplayer.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp
index f64d1d690..605346928 100644
--- a/src/remoteplayer.cpp
+++ b/src/remoteplayer.cpp
@@ -96,7 +96,7 @@ void RemotePlayer::save(std::string savedir, IGameDef *gamedef)
infostream << "Failed to open " << path << std::endl;
return;
}
- testplayer.deSerialize(is, path);
+ testplayer.deSerialize(is, path, NULL);
is.close();
if (strcmp(testplayer.getName(), m_name) == 0) {
// Open file and serialize
@@ -115,37 +115,46 @@ void RemotePlayer::save(std::string savedir, IGameDef *gamedef)
return;
}
-void RemotePlayer::deSerialize(std::istream &is, const std::string &playername)
+void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
+ PlayerSAO *sao)
{
Settings args;
if (!args.parseConfigLines(is, "PlayerArgsEnd")) {
- throw SerializationError("PlayerArgsEnd of player " +
- playername + " not found!");
+ throw SerializationError("PlayerArgsEnd of player " + 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);
- setPitch(args.getFloat("pitch"));
- setYaw(args.getFloat("yaw"));
- setPosition(args.getV3F("position"));
- try {
- hp = args.getS32("hp");
- } catch(SettingNotFoundException &e) {
- hp = PLAYER_MAX_HP;
- }
- try {
- m_breath = args.getS32("breath");
- } catch(SettingNotFoundException &e) {
- m_breath = PLAYER_MAX_BREATH;
+ if (sao) {
+ try {
+ sao->setHP(args.getS32("hp"), true);
+ } catch(SettingNotFoundException &e) {
+ sao->setHP(PLAYER_MAX_HP, true);
+ }
+
+ try {
+ sao->setBasePosition(args.getV3F("position"));
+ } catch (SettingNotFoundException &e) {}
+
+ try {
+ sao->setPitch(args.getFloat("pitch"), false);
+ } catch (SettingNotFoundException &e) {}
+ try {
+ sao->setYaw(args.getFloat("yaw"), false);
+ } catch (SettingNotFoundException &e) {}
+
+ try {
+ sao->setBreath(args.getS32("breath"));
+ } catch (SettingNotFoundException &e) {}
}
inventory.deSerialize(is);
- if(inventory.getList("craftpreview") == NULL) {
+ if (inventory.getList("craftpreview") == NULL) {
// Convert players without craftpreview
inventory.addList("craftpreview", 1);
@@ -167,11 +176,14 @@ void RemotePlayer::serialize(std::ostream &os)
args.setS32("version", 1);
args.set("name", m_name);
//args.set("password", m_password);
- args.setFloat("pitch", m_pitch);
- args.setFloat("yaw", m_yaw);
- args.setV3F("position", m_position);
- args.setS32("hp", hp);
- args.setS32("breath", m_breath);
+
+ if (m_sao) {
+ args.setS32("hp", m_sao->getHP());
+ args.setV3F("position", m_sao->getBasePosition());
+ args.setFloat("pitch", m_sao->getPitch());
+ args.setFloat("yaw", m_sao->getYaw());
+ args.setS32("breath", m_sao->getBreath());
+ }
args.writeLines(os);
@@ -180,16 +192,6 @@ void RemotePlayer::serialize(std::ostream &os)
inventory.serialize(os);
}
-void RemotePlayer::setPosition(const v3f &position)
-{
- if (position != m_position)
- m_dirty = true;
-
- Player::setPosition(position);
- if(m_sao)
- m_sao->setBasePosition(position);
-}
-
const RemotePlayerChatResult RemotePlayer::canSendChatMessage()
{
// Rate limit messages