Exemple #1
0
std::string gob_cmd_update_position(
	v3f position,
	v3f velocity,
	v3f acceleration,
	f32 yaw,
	bool do_interpolate,
	bool is_movement_end,
	f32 update_interval
){
	std::ostringstream os(std::ios::binary);
	// command
	writeU8(os, GENERIC_CMD_UPDATE_POSITION);
	// pos
	writeV3F1000(os, position);
	// velocity
	writeV3F1000(os, velocity);
	// acceleration
	writeV3F1000(os, acceleration);
	// yaw
	writeF1000(os, yaw);
	// do_interpolate
	writeU8(os, do_interpolate);
	// is_end_position (for interpolation)
	writeU8(os, is_movement_end);
	// update_interval (for interpolation)
	writeF1000(os, update_interval);
	return os.str();
}
Exemple #2
0
void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const
{
	if(protocol_version <= 17)
		writeU8(os, 1); // version
	else
		writeU8(os, 2); // version
	writeF1000(os, full_punch_interval);
	writeS16(os, max_drop_level);
	writeU32(os, groupcaps.size());
	for(std::map<std::string, ToolGroupCap>::const_iterator
			i = groupcaps.begin(); i != groupcaps.end(); i++){
		const std::string *name = &i->first;
		const ToolGroupCap *cap = &i->second;
		os<<serializeString(*name);
		writeS16(os, cap->uses);
		writeS16(os, cap->maxlevel);
		writeU32(os, cap->times.size());
		for(std::map<int, float>::const_iterator
				i = cap->times.begin(); i != cap->times.end(); i++){
			writeS16(os, i->first);
			writeF1000(os, i->second);
		}
	}
	if(protocol_version > 17){
		writeU32(os, damageGroups.size());
		for(std::map<std::string, s16>::const_iterator
				i = damageGroups.begin(); i != damageGroups.end(); i++){
			os<<serializeString(i->first);
			writeS16(os, i->second);
		}
	}
}
void TileAnimationParams::serialize(std::ostream &os, u16 protocol_version) const
{
	if (protocol_version < 29) {
		if (type == TAT_VERTICAL_FRAMES) {
			writeU8(os, type);
			writeU16(os, vertical_frames.aspect_w);
			writeU16(os, vertical_frames.aspect_h);
			writeF1000(os, vertical_frames.length);
		} else {
			writeU8(os, TAT_NONE);
			writeU16(os, 1);
			writeU16(os, 1);
			writeF1000(os, 1.0);
		}
		return;
	}

	writeU8(os, type);
	if (type == TAT_VERTICAL_FRAMES) {
		writeU16(os, vertical_frames.aspect_w);
		writeU16(os, vertical_frames.aspect_h);
		writeF1000(os, vertical_frames.length);
	} else if (type == TAT_SHEET_2D) {
		writeU8(os, sheet_2d.frames_w);
		writeU8(os, sheet_2d.frames_h);
		writeF1000(os, sheet_2d.frame_length);
	}
}
Exemple #4
0
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
	m_last_sent_move_precision = m_base_position.getDistanceFrom(
			m_last_sent_position);
	m_last_sent_position_timer = 0;
	m_last_sent_yaw = m_yaw;
	m_last_sent_position = m_base_position;
	m_last_sent_velocity = m_velocity;
	//m_last_sent_acceleration = m_acceleration;

	float update_interval = m_env->getSendRecommendedInterval();

	std::ostringstream os(std::ios::binary);
	// command (0 = update position)
	writeU8(os, 0);

	// do_interpolate
	writeU8(os, do_interpolate);
	// pos
	writeV3F1000(os, m_base_position);
	// velocity
	writeV3F1000(os, m_velocity);
	// acceleration
	writeV3F1000(os, m_acceleration);
	// yaw
	writeF1000(os, m_yaw);
	// is_end_position (for interpolation)
	writeU8(os, is_movement_end);
	// update_interval (for interpolation)
	writeF1000(os, update_interval);

	// create message and add to list
	ActiveObjectMessage aom(getId(), false, os.str());
	m_messages_out.push_back(aom);
}
Exemple #5
0
static void serializeSimpleSoundSpec(const SimpleSoundSpec &ss,
		std::ostream &os, u8 version)
{
	os<<serializeString(ss.name);
	writeF1000(os, ss.gain);
	writeF1000(os, ss.pitch);
}
Exemple #6
0
std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
{
	std::ostringstream os(std::ios::binary);

	if(protocol_version >= 15)
	{
		writeU8(os, 1); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeS16(os, getId()); //id
		writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
		writeF1000(os, m_yaw);
		writeS16(os, getHP());

		std::ostringstream msg_os(std::ios::binary);
		msg_os << serializeLongString(getPropertyPacket()); // message 1
		msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
		msg_os << serializeLongString(gob_cmd_update_animation(
			m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
		for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
				ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
			msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
				(*ii).second.X, (*ii).second.Y)); // m_bone_position.size
		}
		msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id,
			m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
		msg_os << serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
				m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
				m_physics_override_sneak_glitch)); // 5
		// (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
		msg_os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6
		int message_count = 6 + m_bone_position.size();
		for (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)) {
				message_count++;
				msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(),
					obj->getClientInitializationData(protocol_version)));
			}
		}

		writeU8(os, message_count);
		os.write(msg_os.str().c_str(), msg_os.str().size());
	}
	else
	{
		writeU8(os, 0); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
		writeF1000(os, m_yaw);
		writeS16(os, getHP());
		writeU8(os, 2); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	}

	// return result
	return os.str();
}
void ObjectProperties::serialize(std::ostream &os) const
{
	writeU8(os, 1); // version
	writeS16(os, hp_max);
	writeU8(os, physical);
	writeF1000(os, weight);
	writeV3F1000(os, collisionbox.MinEdge);
	writeV3F1000(os, collisionbox.MaxEdge);
	os<<serializeString(visual);
	os<<serializeString(meshfile);
	writeV2F1000(os, visual_size);
	writeU16(os, textures.size());
	for(u32 i=0; i<textures.size(); i++){
		os<<serializeString(textures[i]);
	}
	writeU16(os, textures_3d.size());
	for(u32 i=0; i<textures_3d.size(); i++){
		os<<serializeString(textures_3d[i]);
	}
	writeV2S16(os, spritediv);
	writeV2S16(os, initial_sprite_basepos);
	writeU8(os, is_visible);
	writeU8(os, makes_footstep_sound);
	writeF1000(os, automatic_rotate);
}
Exemple #8
0
void ObjectProperties::serialize(std::ostream &os) const
{
	writeU8(os, 1); // version
	writeS16(os, hp_max);
	writeU8(os, physical);
	writeF1000(os, weight);
	writeV3F1000(os, collisionbox.MinEdge);
	writeV3F1000(os, collisionbox.MaxEdge);
	os<<serializeString(visual);
	writeV2F1000(os, visual_size);
	writeU16(os, textures.size());
	for(u32 i=0; i<textures.size(); i++){
		os<<serializeString(textures[i]);
	}
	writeV2S16(os, spritediv);
	writeV2S16(os, initial_sprite_basepos);
	writeU8(os, is_visible);
	writeU8(os, makes_footstep_sound);
	writeF1000(os, automatic_rotate);
	// Added in protocol version 14
	os<<serializeString(mesh);
	writeU16(os, colors.size());
	for(u32 i=0; i<colors.size(); i++){
		writeARGB8(os, colors[i]);
	}
	writeU8(os, collideWithObjects);
	writeF1000(os,stepheight);
	writeU8(os, automatic_face_movement_dir);
	writeF1000(os, automatic_face_movement_dir_offset);
	// Add stuff only at the bottom.
	// Never remove anything, because we don't want new versions of this
}
Exemple #9
0
void MapBlock::serializeNetworkSpecific(std::ostream &os)
{
	if (!data) {
		throw SerializationError("ERROR: Not writing dummy block.");
	}

	writeU8(os, 1); // version
	writeF1000(os, 0); // deprecated heat
	writeF1000(os, 0); // deprecated humidity
}
Exemple #10
0
std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
{
	std::ostringstream os(std::ios::binary);

	if(protocol_version >= 14)
	{
		writeU8(os, 1); // version
		os<<serializeString(""); // name
		writeU8(os, 0); // is_player
		writeS16(os, getId()); //id
		writeV3F1000(os, m_base_position);
		writeF1000(os, m_yaw);
		writeS16(os, m_hp);

		std::ostringstream msg_os(std::ios::binary);
		msg_os << serializeLongString(getPropertyPacket()); // message 1
		msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
		msg_os << serializeLongString(gob_cmd_update_animation(
			m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
		for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
				ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
			msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
					(*ii).second.X, (*ii).second.Y)); // m_bone_position.size
		}
		msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id,
			m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
		int message_count = 4 + m_bone_position.size();
		for (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)) {
				message_count++;
				msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(),
					obj->getClientInitializationData(protocol_version)));
			}
		}

		writeU8(os, message_count);
		os.write(msg_os.str().c_str(), msg_os.str().size());
	}
	else
	{
		writeU8(os, 0); // version
		os<<serializeString(""); // name
		writeU8(os, 0); // is_player
		writeV3F1000(os, m_base_position);
		writeF1000(os, m_yaw);
		writeS16(os, m_hp);
		writeU8(os, 2); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	}

	// return result
	return os.str();
}
Exemple #11
0
std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend)
{
	std::ostringstream os(std::ios::binary);
	// command 
	writeU8(os, GENERIC_CMD_SET_ANIMATION);
	// parameters
	writeV2F1000(os, frames);
	writeF1000(os, frame_speed);
	writeF1000(os, frame_blend);
	return os.str();
}
Exemple #12
0
std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
{
	std::ostringstream os(std::ios::binary);
	// command
	writeU8(os, GENERIC_CMD_SET_ANIMATION);
	// parameters
	writeV2F1000(os, frames);
	writeF1000(os, frame_speed);
	writeF1000(os, frame_blend);
	// these are sent inverted so we get true when the server sends nothing
	writeU8(os, !frame_loop);
	return os.str();
}
Exemple #13
0
void MapBlock::serializeNetworkSpecific(std::ostream &os, u16 net_proto_version)
{
	if(data == NULL)
	{
		throw SerializationError("ERROR: Not writing dummy block.");
	}

	if(net_proto_version >= 21){
		int version = 1;
		writeU8(os, version);
		writeF1000(os, heat); // deprecated heat
		writeF1000(os, humidity); // deprecated humidity
	}
}
Exemple #14
0
std::string gob_cmd_update_physics_override(float physics_override_speed, float physics_override_jump,
		float physics_override_gravity, bool sneak, bool sneak_glitch)
{
	std::ostringstream os(std::ios::binary);
	// command 
	writeU8(os, GENERIC_CMD_SET_PHYSICS_OVERRIDE);
	// parameters
	writeF1000(os, physics_override_speed);
	writeF1000(os, physics_override_jump);
	writeF1000(os, physics_override_gravity);
	// these are sent inverted so we get true when the server sends nothing
	writeU8(os, !sneak);
	writeU8(os, !sneak_glitch);
	return os.str();
}
Exemple #15
0
void CraftDefinitionCooking::serializeBody(std::ostream &os) const
{
	os<<serializeString(output);
	os<<serializeString(recipe);
	writeF1000(os, cooktime);
	replacements.serialize(os);
}
Exemple #16
0
void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
{
    if(protocol_version <= 17)
        writeU8(os, 1); // version
    else
        writeU8(os, 2); // version
    writeU8(os, type);
    os<<serializeString(name);
    os<<serializeString(description);
    os<<serializeString(inventory_image);
    os<<serializeString(wield_image);
    writeV3F1000(os, wield_scale);
    writeS16(os, stack_max);
    writeU8(os, usable);
    writeU8(os, liquids_pointable);
    std::string tool_capabilities_s = "";
    if(tool_capabilities) {
        std::ostringstream tmp_os(std::ios::binary);
        tool_capabilities->serialize(tmp_os, protocol_version);
        tool_capabilities_s = tmp_os.str();
    }
    os<<serializeString(tool_capabilities_s);
    writeU16(os, groups.size());
    for(std::map<std::string, int>::const_iterator
            i = groups.begin(); i != groups.end(); i++) {
        os<<serializeString(i->first);
        writeS16(os, i->second);
    }
    os<<serializeString(node_placement_prediction);
    if(protocol_version > 17) {
        //serializeSimpleSoundSpec(sound_place, os);
        os<<serializeString(sound_place.name);
        writeF1000(os, sound_place.gain);
    }
}
Exemple #17
0
std::string LuaEntitySAO::getStaticData()
{
/*
	verbosestream<<FUNCTION_NAME<<std::endl;
*/
	std::ostringstream os(std::ios::binary);
	// version
	writeU8(os, 1);
	// name
	os<<serializeString(m_init_name);
	// state
	if(m_registered){
		std::string state = m_env->getScriptIface()->
			luaentity_GetStaticdata(m_id);
		os<<serializeLongString(state);
	} else {
		os<<serializeLongString(m_init_state);
	}
	// hp
	writeS16(os, m_hp);
	// velocity
	writeV3F1000(os, m_velocity);
	// yaw
	writeF1000(os, m_yaw);
	return os.str();
}
Exemple #18
0
void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
{
	if(protocol_version < 14){
		serializeOld(os, protocol_version);
		return;
	}

	writeU8(os, 6); // version
	os<<serializeString(name);
	writeU16(os, groups.size());
	for(ItemGroupList::const_iterator
			i = groups.begin(); i != groups.end(); i++){
		os<<serializeString(i->first);
		writeS16(os, i->second);
	}
	writeU8(os, drawtype);
	writeF1000(os, visual_scale);
	writeU8(os, 6);
	for(u32 i=0; i<6; i++)
		tiledef[i].serialize(os, protocol_version);
	writeU8(os, CF_SPECIAL_COUNT);
	for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
		tiledef_special[i].serialize(os, protocol_version);
	}
	writeU8(os, alpha);
	writeU8(os, post_effect_color.getAlpha());
	writeU8(os, post_effect_color.getRed());
	writeU8(os, post_effect_color.getGreen());
	writeU8(os, post_effect_color.getBlue());
	writeU8(os, param_type);
	writeU8(os, param_type_2);
	writeU8(os, is_ground_content);
	writeU8(os, light_propagates);
	writeU8(os, sunlight_propagates);
	writeU8(os, walkable);
	writeU8(os, pointable);
	writeU8(os, diggable);
	writeU8(os, climbable);
	writeU8(os, buildable_to);
	os<<serializeString(""); // legacy: used to be metadata_name
	writeU8(os, liquid_type);
	os<<serializeString(liquid_alternative_flowing);
	os<<serializeString(liquid_alternative_source);
	writeU8(os, liquid_viscosity);
	writeU8(os, liquid_renewable);
	writeU8(os, light_source);
	writeU32(os, damage_per_second);
	node_box.serialize(os);
	selection_box.serialize(os);
	writeU8(os, legacy_facedir_simple);
	writeU8(os, legacy_wallmounted);
	serializeSimpleSoundSpec(sound_footstep, os);
	serializeSimpleSoundSpec(sound_dig, os);
	serializeSimpleSoundSpec(sound_dug, os);
	writeU8(os, rightclickable);
	// Stuff below should be moved to correct place in a version that otherwise changes
	// the protocol version
	writeU8(os, drowning);
}
void TestSerialization::testStreamWrite()
{
	std::ostringstream os(std::ios_base::binary);
	std::string data;

	writeU8(os, 0x11);
	writeU16(os, 0x2233);
	writeU32(os, 0x44556677);
	writeU64(os, 0x8899AABBCCDDEEFF);

	writeS8(os, -128);
	writeS16(os, 30000);
	writeS32(os, -6);
	writeS64(os, -43);

	writeF1000(os, 53.53467f);
	writeF1000(os, -300000.32f);
	writeF1000(os, F1000_MIN);
	writeF1000(os, F1000_MAX);

	os << serializeString("foobar!");

	data = os.str();
	UASSERT(data.size() < sizeof(test_serialized_data));
	UASSERT(!memcmp(&data[0], test_serialized_data, data.size()));

	writeV2S16(os, v2s16(500, 500));
	writeV3S16(os, v3s16(4207, 604, -30));
	writeV2S32(os, v2s32(1920, 1080));
	writeV3S32(os, v3s32(-400, 6400054, 290549855));
	writeV2F1000(os, v2f(500.65661f, 350.34567f));

	os << serializeWideString(L"\x02~woof~\x5455");

	writeV3F1000(os, v3f(500, 10024.2f, -192.54f));
	writeARGB8(os, video::SColor(255, 128, 50, 128));

	os << serializeLongString("some longer string here");

	writeU16(os, 0xF00D);

	data = os.str();
	UASSERT(data.size() == sizeof(test_serialized_data));
	UASSERT(!memcmp(&data[0], test_serialized_data, sizeof(test_serialized_data)));
}
Exemple #20
0
void TileDef::serialize(std::ostream &os) const
{
	writeU8(os, 0); // version
	os<<serializeString(name);
	writeU8(os, animation.type);
	writeU16(os, animation.aspect_w);
	writeU16(os, animation.aspect_h);
	writeF1000(os, animation.length);
}
Exemple #21
0
std::string gob_cmd_update_animation_speed(float frame_speed)
{
	std::ostringstream os(std::ios::binary);
	// command
	writeU8(os, GENERIC_CMD_SET_ANIMATION_SPEED);
	// parameters
	writeF1000(os, frame_speed);
	return os.str();
}
Exemple #22
0
std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
{
	std::ostringstream os(std::ios::binary);

	if(protocol_version >= 15)
	{
		writeU8(os, 1); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeS16(os, getId()); //id
		writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
		writeF1000(os, m_player->getYaw());
		writeS16(os, getHP());

		writeU8(os, 6 + m_bone_position.size()); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
		os<<serializeLongString(gob_cmd_update_animation(
			m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
		for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
			os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
		}
		os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
		os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
				m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
				m_physics_override_sneak_glitch)); // 5
		os << serializeLongString(gob_cmd_update_nametag_attributes(m_nametag_color)); // 6
	}
	else
	{
		writeU8(os, 0); // version
		os<<serializeString(m_player->getName()); // name
		writeU8(os, 1); // is_player
		writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
		writeF1000(os, m_player->getYaw());
		writeS16(os, getHP());
		writeU8(os, 2); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	}

	// return result
	return os.str();
}
Exemple #23
0
void ContentFeatures::serializeOld(std::ostream &os, u16 protocol_version)
{
	if(protocol_version == 13)
	{
		writeU8(os, 5); // version
		os<<serializeString(name);
		writeU16(os, groups.size());
		for(ItemGroupList::const_iterator
				i = groups.begin(); i != groups.end(); i++){
			os<<serializeString(i->first);
			writeS16(os, i->second);
		}
		writeU8(os, drawtype);
		writeF1000(os, visual_scale);
		writeU8(os, 6);
		for(u32 i=0; i<6; i++)
			tiledef[i].serialize(os, protocol_version);
		writeU8(os, CF_SPECIAL_COUNT);
		for(u32 i=0; i<CF_SPECIAL_COUNT; i++){
			tiledef_special[i].serialize(os, protocol_version);
		}
		writeU8(os, alpha);
		writeU8(os, post_effect_color.getAlpha());
		writeU8(os, post_effect_color.getRed());
		writeU8(os, post_effect_color.getGreen());
		writeU8(os, post_effect_color.getBlue());
		writeU8(os, param_type);
		writeU8(os, param_type_2);
		writeU8(os, is_ground_content);
		writeU8(os, light_propagates);
		writeU8(os, sunlight_propagates);
		writeU8(os, walkable);
		writeU8(os, pointable);
		writeU8(os, diggable);
		writeU8(os, climbable);
		writeU8(os, buildable_to);
		os<<serializeString(""); // legacy: used to be metadata_name
		writeU8(os, liquid_type);
		os<<serializeString(liquid_alternative_flowing);
		os<<serializeString(liquid_alternative_source);
		writeU8(os, liquid_viscosity);
		writeU8(os, light_source);
		writeU32(os, damage_per_second);
		node_box.serialize(os, protocol_version);
		selection_box.serialize(os, protocol_version);
		writeU8(os, legacy_facedir_simple);
		writeU8(os, legacy_wallmounted);
		serializeSimpleSoundSpec(sound_footstep, os);
		serializeSimpleSoundSpec(sound_dig, os);
		serializeSimpleSoundSpec(sound_dug, os);
	}
	else
	{
		throw SerializationError("ContentFeatures::serialize(): Unsupported version requested");
	}
}
Exemple #24
0
void ToolCapabilities::serialize(std::ostream &os) const
{
	writeU8(os, 0); // version
	writeF1000(os, full_punch_interval);
	writeS16(os, max_drop_level);
	writeU32(os, groupcaps.size());
	for(std::map<std::string, ToolGroupCap>::const_iterator
			i = groupcaps.begin(); i != groupcaps.end(); i++){
		const std::string *name = &i->first;
		const ToolGroupCap *cap = &i->second;
		os<<serializeString(*name);
		writeF1000(os, cap->maxwear);
		writeF1000(os, cap->maxlevel);
		writeU32(os, cap->times.size());
		for(std::map<int, float>::const_iterator
				i = cap->times.begin(); i != cap->times.end(); i++){
			writeS16(os, i->first);
			writeF1000(os, i->second);
		}
	}
}
Exemple #25
0
std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
{
	std::ostringstream os(std::ios::binary);

	if(protocol_version >= 14)
	{
		writeU8(os, 1); // version
		os<<serializeString(""); // name
		writeU8(os, 0); // is_player
		writeS16(os, getId()); //id
		writeV3F1000(os, m_base_position);
		writeF1000(os, m_yaw);
		writeS16(os, m_hp);

		writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
		os<<serializeLongString(gob_cmd_update_animation(
			m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
		for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
			os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
		}
		os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
	}
	else
	{
		writeU8(os, 0); // version
		os<<serializeString(""); // name
		writeU8(os, 0); // is_player
		writeV3F1000(os, m_base_position);
		writeF1000(os, m_yaw);
		writeS16(os, m_hp);
		writeU8(os, 2); // number of messages stuffed in here
		os<<serializeLongString(getPropertyPacket()); // message 1
		os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	}

	// return result
	return os.str();
}
Exemple #26
0
void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
{
	// protocol_version >= 36
	u8 version = 5;
	writeU8(os, version);
	writeU8(os, type);
	os << serializeString(name);
	os << serializeString(description);
	os << serializeString(inventory_image);
	os << serializeString(wield_image);
	writeV3F1000(os, wield_scale);
	writeS16(os, stack_max);
	writeU8(os, usable);
	writeU8(os, liquids_pointable);
	std::string tool_capabilities_s;
	if(tool_capabilities){
		std::ostringstream tmp_os(std::ios::binary);
		tool_capabilities->serialize(tmp_os, protocol_version);
		tool_capabilities_s = tmp_os.str();
	}
	os << serializeString(tool_capabilities_s);
	writeU16(os, groups.size());
	for (const auto &group : groups) {
		os << serializeString(group.first);
		writeS16(os, group.second);
	}
	os << serializeString(node_placement_prediction);
	os << serializeString(sound_place.name);
	writeF1000(os, sound_place.gain);
	writeF1000(os, range);
	os << serializeString(sound_place_failed.name);
	writeF1000(os, sound_place_failed.gain);
	os << serializeString(palette_image);
	writeARGB8(os, color);

	writeF1000(os, sound_place.pitch);
	writeF1000(os, sound_place_failed.pitch);
	os << serializeString(inventory_overlay);
	os << serializeString(wield_overlay);
}
Exemple #27
0
void TileDef::serialize(std::ostream &os, u16 protocol_version) const
{
	if(protocol_version >= 17)
		writeU8(os, 1); 
	else
		writeU8(os, 0);
	os<<serializeString(name);
	writeU8(os, animation.type);
	writeU16(os, animation.aspect_w);
	writeU16(os, animation.aspect_h);
	writeF1000(os, animation.length);
	if(protocol_version >= 17)
		writeU8(os, backface_culling);
}
Exemple #28
0
std::string PlayerSAO::getClientInitializationData()
{
	std::ostringstream os(std::ios::binary);
	writeU8(os, 0); // version
	os<<serializeString(m_player->getName()); // name
	writeU8(os, 1); // is_player
	writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
	writeF1000(os, m_player->getYaw());
	writeS16(os, getHP());
	writeU8(os, 2); // number of messages stuffed in here
	os<<serializeLongString(getPropertyPacket()); // message 1
	os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
	return os.str();
}
Exemple #29
0
void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength,
		bool select_horiz_by_yawpitch)
{
	std::ostringstream os(std::ios::binary);
	// command (2 = set sprite)
	writeU8(os, 2);
	// parameters
	writeV2S16(os, p);
	writeU16(os, num_frames);
	writeF1000(os, framelength);
	writeU8(os, select_horiz_by_yawpitch);
	// create message and add to list
	ActiveObjectMessage aom(getId(), false, os.str());
	m_messages_out.push_back(aom);
}
Exemple #30
0
void MobV2SAO::sendPosition()
{
	m_last_sent_position = m_base_position;

	std::ostringstream os(std::ios::binary);
	// command (0 = update position)
	writeU8(os, 0);
	// pos
	writeV3F1000(os, m_base_position);
	// yaw
	writeF1000(os, m_yaw);
	// create message and add to list
	ActiveObjectMessage aom(getId(), false, os.str());
	m_messages_out.push_back(aom);
}