summaryrefslogtreecommitdiff
path: root/src/server/player_sao.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/player_sao.cpp')
-rw-r--r--src/server/player_sao.cpp57
1 files changed, 16 insertions, 41 deletions
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index 9ea0743f7..67efed210 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -120,24 +120,26 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
msg_os << serializeLongString(getPropertyPacket()); // message 1
msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2
msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
- for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator
- ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
- msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first,
- (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
+ for (const auto &bone_pos : m_bone_position) {
+ msg_os << serializeLongString(generateUpdateBonePositionCommand(
+ bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // m_bone_position.size
}
msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5
+
int message_count = 5 + m_bone_position.size();
- for (std::unordered_set<int>::const_iterator ii = m_attachment_child_ids.begin();
- ii != m_attachment_child_ids.end(); ++ii) {
- if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
+
+ for (const auto &id : getAttachmentChildIds()) {
+ if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
message_count++;
- msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version));
+ msg_os << serializeLongString(obj->generateUpdateInfantCommand(
+ id, protocol_version));
}
}
writeU8(os, message_count);
- os.write(msg_os.str().c_str(), msg_os.str().size());
+ std::string serialized = msg_os.str();
+ os.write(serialized.c_str(), serialized.size());
// return result
return os.str();
@@ -227,10 +229,10 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// If attached, check that our parent is still there. If it isn't, detach.
if (m_attachment_parent_id && !isAttached()) {
- m_attachment_parent_id = 0;
- m_attachment_bone = "";
- m_attachment_position = v3f(0.0f, 0.0f, 0.0f);
- m_attachment_rotation = v3f(0.0f, 0.0f, 0.0f);
+ // This is handled when objects are removed from the map
+ warningstream << "PlayerSAO::step() id=" << m_id <<
+ " is attached to nonexistent parent. This is a bug." << std::endl;
+ clearParentAttachment();
setBasePosition(m_last_good_position);
m_env->getGameDef()->SendMovePlayer(m_peer_id);
}
@@ -290,40 +292,13 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.emplace(getId(), false, str);
}
- if (!m_armor_groups_sent) {
- m_armor_groups_sent = true;
- // create message and add to list
- m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand());
- }
-
if (!m_physics_override_sent) {
m_physics_override_sent = true;
// create message and add to list
m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand());
}
- if (!m_animation_sent) {
- m_animation_sent = true;
- // create message and add to list
- m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand());
- }
-
- if (!m_bone_position_sent) {
- m_bone_position_sent = true;
- for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator
- ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
- std::string str = generateUpdateBonePositionCommand((*ii).first,
- (*ii).second.X, (*ii).second.Y);
- // create message and add to list
- m_messages_out.emplace(getId(), true, str);
- }
- }
-
- if (!m_attachment_sent) {
- m_attachment_sent = true;
- // create message and add to list
- m_messages_out.emplace(getId(), true, generateUpdateAttachmentCommand());
- }
+ sendOutdatedData();
}
std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const