aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2020-09-20 13:12:55 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2020-10-01 09:52:59 +0200
commit947466ab28129fd69e6630974c6c4e901f2bebc6 (patch)
tree720b35a5f8c01e42a5078f7fb79d612d1a1484d9 /src/server
parentca5c2dbefab3676514e48b445b36de50993de9f1 (diff)
downloadminetest-947466ab28129fd69e6630974c6c4e901f2bebc6.tar.gz
minetest-947466ab28129fd69e6630974c6c4e901f2bebc6.tar.bz2
minetest-947466ab28129fd69e6630974c6c4e901f2bebc6.zip
(se)SerializeString: Include max length in the name
This commit clarifies the maximal length of the serialized strings. It will avoid accidental use of serializeString() when a larger string can be expected. Removes unused Wide String serialization functions
Diffstat (limited to 'src/server')
-rw-r--r--src/server/luaentity_sao.cpp28
-rw-r--r--src/server/player_sao.cpp16
-rw-r--r--src/server/serveractiveobject.cpp2
-rw-r--r--src/server/unit_sao.cpp6
4 files changed, 26 insertions, 26 deletions
diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp
index d504c42ca..f20914f7f 100644
--- a/src/server/luaentity_sao.cpp
+++ b/src/server/luaentity_sao.cpp
@@ -42,8 +42,8 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
u8 version2 = 0;
u8 version = readU8(is);
- name = deSerializeString(is);
- state = deSerializeLongString(is);
+ name = deSerializeString16(is);
+ state = deSerializeString32(is);
if (version < 1)
break;
@@ -225,7 +225,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
// PROTOCOL_VERSION >= 37
writeU8(os, 1); // version
- os << serializeString(""); // name
+ os << serializeString16(""); // name
writeU8(os, 0); // is_player
writeU16(os, getId()); //id
writeV3F32(os, m_base_position);
@@ -233,26 +233,26 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
writeU16(os, m_hp);
std::ostringstream msg_os(std::ios::binary);
- msg_os << serializeLongString(getPropertyPacket()); // message 1
- msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2
- msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
+ msg_os << serializeString32(getPropertyPacket()); // message 1
+ msg_os << serializeString32(generateUpdateArmorGroupsCommand()); // 2
+ msg_os << serializeString32(generateUpdateAnimationCommand()); // 3
for (const auto &bone_pos : m_bone_position) {
- msg_os << serializeLongString(generateUpdateBonePositionCommand(
+ msg_os << serializeString32(generateUpdateBonePositionCommand(
bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // m_bone_position.size
}
- msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
+ msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4
int message_count = 4 + m_bone_position.size();
for (const auto &id : getAttachmentChildIds()) {
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
message_count++;
- msg_os << serializeLongString(obj->generateUpdateInfantCommand(
+ msg_os << serializeString32(obj->generateUpdateInfantCommand(
id, protocol_version));
}
}
- msg_os << serializeLongString(generateSetTextureModCommand());
+ msg_os << serializeString32(generateSetTextureModCommand());
message_count++;
writeU8(os, message_count);
@@ -270,14 +270,14 @@ void LuaEntitySAO::getStaticData(std::string *result) const
// version must be 1 to keep backwards-compatibility. See version2
writeU8(os, 1);
// name
- os<<serializeString(m_init_name);
+ os<<serializeString16(m_init_name);
// state
if(m_registered){
std::string state = m_env->getScriptIface()->
luaentity_GetStaticdata(m_id);
- os<<serializeLongString(state);
+ os<<serializeString32(state);
} else {
- os<<serializeLongString(m_init_state);
+ os<<serializeString32(m_init_state);
}
writeU16(os, m_hp);
writeV3F1000(os, m_velocity);
@@ -436,7 +436,7 @@ std::string LuaEntitySAO::generateSetTextureModCommand() const
// command
writeU8(os, AO_CMD_SET_TEXTURE_MOD);
// parameters
- os << serializeString(m_current_texture_modifier);
+ os << serializeString16(m_current_texture_modifier);
return os.str();
}
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index e5b239bba..8d4938c3c 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -109,7 +109,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
// Protocol >= 15
writeU8(os, 1); // version
- os << serializeString(m_player->getName()); // name
+ os << serializeString16(m_player->getName()); // name
writeU8(os, 1); // is_player
writeS16(os, getId()); // id
writeV3F32(os, m_base_position);
@@ -117,22 +117,22 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
writeU16(os, getHP());
std::ostringstream msg_os(std::ios::binary);
- msg_os << serializeLongString(getPropertyPacket()); // message 1
- msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2
- msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
+ msg_os << serializeString32(getPropertyPacket()); // message 1
+ msg_os << serializeString32(generateUpdateArmorGroupsCommand()); // 2
+ msg_os << serializeString32(generateUpdateAnimationCommand()); // 3
for (const auto &bone_pos : m_bone_position) {
- msg_os << serializeLongString(generateUpdateBonePositionCommand(
+ msg_os << serializeString32(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
+ msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4
+ msg_os << serializeString32(generateUpdatePhysicsOverrideCommand()); // 5
int message_count = 5 + m_bone_position.size();
for (const auto &id : getAttachmentChildIds()) {
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
message_count++;
- msg_os << serializeLongString(obj->generateUpdateInfantCommand(
+ msg_os << serializeString32(obj->generateUpdateInfantCommand(
id, protocol_version));
}
}
diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp
index 3341dc008..8cb59b2d6 100644
--- a/src/server/serveractiveobject.cpp
+++ b/src/server/serveractiveobject.cpp
@@ -61,7 +61,7 @@ std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 p
// Clients since 4aa9a66 so no longer need this data
// Version 38 is the first bump after that commit.
// See also: ClientEnvironment::addActiveObject
- os << serializeLongString(getClientInitializationData(protocol_version));
+ os << serializeString32(getClientInitializationData(protocol_version));
}
return os.str();
}
diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp
index ef0e87f2c..d906e885e 100644
--- a/src/server/unit_sao.cpp
+++ b/src/server/unit_sao.cpp
@@ -242,7 +242,7 @@ std::string UnitSAO::generateUpdateAttachmentCommand() const
writeU8(os, AO_CMD_ATTACH_TO);
// parameters
writeS16(os, m_attachment_parent_id);
- os << serializeString(m_attachment_bone);
+ os << serializeString16(m_attachment_bone);
writeV3F32(os, m_attachment_position);
writeV3F32(os, m_attachment_rotation);
return os.str();
@@ -255,7 +255,7 @@ std::string UnitSAO::generateUpdateBonePositionCommand(
// command
writeU8(os, AO_CMD_SET_BONE_POSITION);
// parameters
- os << serializeString(bone);
+ os << serializeString16(bone);
writeV3F32(os, position);
writeV3F32(os, rotation);
return os.str();
@@ -291,7 +291,7 @@ std::string UnitSAO::generateUpdateArmorGroupsCommand() const
writeU8(os, AO_CMD_UPDATE_ARMOR_GROUPS);
writeU16(os, m_armor_groups.size());
for (const auto &armor_group : m_armor_groups) {
- os << serializeString(armor_group.first);
+ os << serializeString16(armor_group.first);
writeS16(os, armor_group.second);
}
return os.str();