aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/luaentity_sao.cpp198
-rw-r--r--src/server/player_sao.cpp123
-rw-r--r--src/server/serveractiveobject.cpp11
-rw-r--r--src/server/serveractiveobject.h128
4 files changed, 225 insertions, 235 deletions
diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp
index d504c42ca..d04516414 100644
--- a/src/server/luaentity_sao.cpp
+++ b/src/server/luaentity_sao.cpp
@@ -26,8 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "serverenvironment.h"
-LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data)
- : UnitSAO(env, pos)
+LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data) :
+ UnitSAO(env, pos)
{
std::string name;
std::string state;
@@ -37,8 +37,9 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
while (!data.empty()) { // breakable, run for one iteration
std::istringstream is(data, std::ios::binary);
- // 'version' does not allow to incrementally extend the parameter list thus
- // we need another variable to build on top of 'version=1'. Ugly hack but works™
+ // 'version' does not allow to incrementally extend the parameter list
+ // thus we need another variable to build on top of 'version=1'. Ugly hack
+ // but works™
u8 version2 = 0;
u8 version = readU8(is);
@@ -69,8 +70,8 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
break;
}
// create object
- infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\""
- << state << "\")" << std::endl;
+ infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\"" << state
+ << "\")" << std::endl;
m_init_name = name;
m_init_state = state;
@@ -81,7 +82,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
LuaEntitySAO::~LuaEntitySAO()
{
- if(m_registered){
+ if (m_registered) {
m_env->getScriptIface()->luaentity_Remove(m_id);
}
@@ -95,18 +96,15 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
ServerActiveObject::addedToEnvironment(dtime_s);
// Create entity from name
- m_registered = m_env->getScriptIface()->
- luaentity_Add(m_id, m_init_name.c_str());
+ m_registered = m_env->getScriptIface()->luaentity_Add(m_id, m_init_name.c_str());
- if(m_registered){
+ if (m_registered) {
// Get properties
- m_env->getScriptIface()->
- luaentity_GetProperties(m_id, this, &m_prop);
+ m_env->getScriptIface()->luaentity_GetProperties(m_id, this, &m_prop);
// Initialize HP from properties
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
- m_env->getScriptIface()->
- luaentity_Activate(m_id, m_init_state, dtime_s);
+ m_env->getScriptIface()->luaentity_Activate(m_id, m_init_state, dtime_s);
} else {
m_prop.infotext = m_init_name;
}
@@ -114,8 +112,7 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
void LuaEntitySAO::step(float dtime, bool send_recommended)
{
- if(!m_properties_sent)
- {
+ if (!m_properties_sent) {
m_properties_sent = true;
std::string str = getPropertyPacket();
// create message and add to list
@@ -125,8 +122,9 @@ void LuaEntitySAO::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()) {
// This is handled when objects are removed from the map
- warningstream << "LuaEntitySAO::step() id=" << m_id <<
- " is attached to nonexistent parent. This is a bug." << std::endl;
+ warningstream << "LuaEntitySAO::step() id=" << m_id
+ << " is attached to nonexistent parent. This is a bug."
+ << std::endl;
clearParentAttachment();
sendPosition(false, true);
}
@@ -135,29 +133,28 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
collisionMoveResult moveresult, *moveresult_p = nullptr;
- // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally
- // If the object gets detached this comes into effect automatically from the last known origin
- if(isAttached())
- {
- v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ // Each frame, parent position is copied if the object is attached, otherwise it's
+ // calculated normally If the object gets detached this comes into effect
+ // automatically from the last known origin
+ if (isAttached()) {
+ v3f pos = m_env->getActiveObject(m_attachment_parent_id)
+ ->getBasePosition();
m_base_position = pos;
- m_velocity = v3f(0,0,0);
- m_acceleration = v3f(0,0,0);
- }
- else
- {
- if(m_prop.physical){
+ m_velocity = v3f(0, 0, 0);
+ m_acceleration = v3f(0, 0, 0);
+ } else {
+ if (m_prop.physical) {
aabb3f box = m_prop.collisionbox;
box.MinEdge *= BS;
box.MaxEdge *= BS;
- f32 pos_max_d = BS*0.25; // Distance per iteration
+ f32 pos_max_d = BS * 0.25; // Distance per iteration
v3f p_pos = m_base_position;
v3f p_velocity = m_velocity;
v3f p_acceleration = m_acceleration;
moveresult = collisionMoveSimple(m_env, m_env->getGameDef(),
- pos_max_d, box, m_prop.stepheight, dtime,
- &p_pos, &p_velocity, p_acceleration,
- this, m_prop.collideWithObjects);
+ pos_max_d, box, m_prop.stepheight, dtime, &p_pos,
+ &p_velocity, p_acceleration, this,
+ m_prop.collideWithObjects);
moveresult_p = &moveresult;
// Apply results
@@ -165,22 +162,24 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
m_velocity = p_velocity;
m_acceleration = p_acceleration;
} else {
- m_base_position += dtime * m_velocity + 0.5 * dtime
- * dtime * m_acceleration;
+ m_base_position += dtime * m_velocity +
+ 0.5 * dtime * dtime * m_acceleration;
m_velocity += dtime * m_acceleration;
}
if (m_prop.automatic_face_movement_dir &&
- (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
- float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
- + m_prop.automatic_face_movement_dir_offset;
+ (fabs(m_velocity.Z) > 0.001 ||
+ fabs(m_velocity.X) > 0.001)) {
+ float target_yaw =
+ atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI +
+ m_prop.automatic_face_movement_dir_offset;
float max_rotation_per_sec =
m_prop.automatic_face_movement_max_rotation_per_sec;
if (max_rotation_per_sec > 0) {
m_rotation.Y = wrapDegrees_0_360(m_rotation.Y);
wrappedApproachShortest(m_rotation.Y, target_yaw,
- dtime * max_rotation_per_sec, 360.f);
+ dtime * max_rotation_per_sec, 360.f);
} else {
// Negative values of max_rotation_per_sec mean disabled.
m_rotation.Y = target_yaw;
@@ -188,21 +187,20 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
}
}
- if(m_registered) {
+ if (m_registered) {
m_env->getScriptIface()->luaentity_Step(m_id, dtime, moveresult_p);
}
if (!send_recommended)
return;
- if(!isAttached())
- {
+ if (!isAttached()) {
// TODO: force send when acceleration changes enough?
- float minchange = 0.2*BS;
- if(m_last_sent_position_timer > 1.0){
- minchange = 0.01*BS;
- } else if(m_last_sent_position_timer > 0.2){
- minchange = 0.05*BS;
+ float minchange = 0.2 * BS;
+ if (m_last_sent_position_timer > 1.0) {
+ minchange = 0.01 * BS;
+ } else if (m_last_sent_position_timer > 0.2) {
+ minchange = 0.05 * BS;
}
float move_d = m_base_position.getDistanceFrom(m_last_sent_position);
move_d += m_last_sent_move_precision;
@@ -224,21 +222,22 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
std::ostringstream os(std::ios::binary);
// PROTOCOL_VERSION >= 37
- writeU8(os, 1); // version
+ writeU8(os, 1); // version
os << serializeString(""); // name
- writeU8(os, 0); // is_player
- writeU16(os, getId()); //id
+ writeU8(os, 0); // is_player
+ writeU16(os, getId()); // id
writeV3F32(os, m_base_position);
writeV3F32(os, m_rotation);
writeU16(os, m_hp);
std::ostringstream msg_os(std::ios::binary);
- msg_os << serializeLongString(getPropertyPacket()); // message 1
+ msg_os << serializeLongString(getPropertyPacket()); // message 1
msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2
- msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
+ msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
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
+ bone_pos.first, bone_pos.second.X,
+ bone_pos.second.Y)); // m_bone_position.size
}
msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
@@ -248,7 +247,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
message_count++;
msg_os << serializeLongString(obj->generateUpdateInfantCommand(
- id, protocol_version));
+ id, protocol_version));
}
}
@@ -265,19 +264,19 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
void LuaEntitySAO::getStaticData(std::string *result) const
{
- verbosestream<<FUNCTION_NAME<<std::endl;
+ verbosestream << FUNCTION_NAME << std::endl;
std::ostringstream os(std::ios::binary);
// version must be 1 to keep backwards-compatibility. See version2
writeU8(os, 1);
// name
- os<<serializeString(m_init_name);
+ os << serializeString(m_init_name);
// state
- if(m_registered){
- std::string state = m_env->getScriptIface()->
- luaentity_GetStaticdata(m_id);
- os<<serializeLongString(state);
+ if (m_registered) {
+ std::string state =
+ m_env->getScriptIface()->luaentity_GetStaticdata(m_id);
+ os << serializeLongString(state);
} else {
- os<<serializeLongString(m_init_state);
+ os << serializeLongString(m_init_state);
}
writeU16(os, m_hp);
writeV3F1000(os, m_velocity);
@@ -295,10 +294,8 @@ void LuaEntitySAO::getStaticData(std::string *result) const
*result = os.str();
}
-u16 LuaEntitySAO::punch(v3f dir,
- const ToolCapabilities *toolcap,
- ServerActiveObject *puncher,
- float time_from_last_punch)
+u16 LuaEntitySAO::punch(v3f dir, const ToolCapabilities *toolcap,
+ ServerActiveObject *puncher, float time_from_last_punch)
{
if (!m_registered) {
// Delete unknown LuaEntities when punched
@@ -313,18 +310,18 @@ u16 LuaEntitySAO::punch(v3f dir,
ItemStack tool_item = puncher->getWieldedItem(&selected_item, &hand_item);
PunchDamageResult result = getPunchDamage(
- m_armor_groups,
- toolcap,
- &tool_item,
- time_from_last_punch);
+ m_armor_groups, toolcap, &tool_item, time_from_last_punch);
bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
- time_from_last_punch, toolcap, dir, result.did_punch ? result.damage : 0);
+ time_from_last_punch, toolcap, dir,
+ result.did_punch ? result.damage : 0);
if (!damage_handled) {
if (result.did_punch) {
setHP((s32)getHP() - result.damage,
- PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
+ PlayerHPChangeReason(PlayerHPChangeReason::
+ PLAYER_PUNCH,
+ puncher));
// create message and add to list
sendPunchCommand();
@@ -338,11 +335,11 @@ u16 LuaEntitySAO::punch(v3f dir,
m_pending_removal = true;
}
- actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
- ", hp=" << puncher->getHP() << ") punched " <<
- getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
- "), damage=" << (old_hp - (s32)getHP()) <<
- (damage_handled ? " (handled by Lua)" : "") << std::endl;
+ actionstream << puncher->getDescription() << " (id=" << puncher->getId()
+ << ", hp=" << puncher->getHP() << ") punched " << getDescription()
+ << " (id=" << m_id << ", hp=" << m_hp
+ << "), damage=" << (old_hp - (s32)getHP())
+ << (damage_handled ? " (handled by Lua)" : "") << std::endl;
// TODO: give Lua control over wear
return result.wear;
@@ -358,7 +355,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
void LuaEntitySAO::setPos(const v3f &pos)
{
- if(isAttached())
+ if (isAttached())
return;
m_base_position = pos;
sendPosition(false, true);
@@ -366,10 +363,10 @@ void LuaEntitySAO::setPos(const v3f &pos)
void LuaEntitySAO::moveTo(v3f pos, bool continuous)
{
- if(isAttached())
+ if (isAttached())
return;
m_base_position = pos;
- if(!continuous)
+ if (!continuous)
sendPosition(true, true);
}
@@ -429,7 +426,6 @@ std::string LuaEntitySAO::getTextureMod() const
return m_current_texture_modifier;
}
-
std::string LuaEntitySAO::generateSetTextureModCommand() const
{
std::ostringstream os(std::ios::binary);
@@ -440,8 +436,8 @@ std::string LuaEntitySAO::generateSetTextureModCommand() const
return os.str();
}
-std::string LuaEntitySAO::generateSetSpriteCommand(v2s16 p, u16 num_frames,
- f32 framelength, bool select_horiz_by_yawpitch)
+std::string LuaEntitySAO::generateSetSpriteCommand(
+ v2s16 p, u16 num_frames, f32 framelength, bool select_horiz_by_yawpitch)
{
std::ostringstream os(std::ios::binary);
// command
@@ -454,15 +450,11 @@ std::string LuaEntitySAO::generateSetSpriteCommand(v2s16 p, u16 num_frames,
return os.str();
}
-void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength,
- bool select_horiz_by_yawpitch)
+void LuaEntitySAO::setSprite(
+ v2s16 p, int num_frames, float framelength, bool select_horiz_by_yawpitch)
{
std::string str = generateSetSpriteCommand(
- p,
- num_frames,
- framelength,
- select_horiz_by_yawpitch
- );
+ p, num_frames, framelength, select_horiz_by_yawpitch);
// create message and add to list
m_messages_out.emplace(getId(), true, str);
}
@@ -479,38 +471,32 @@ std::string LuaEntitySAO::getPropertyPacket()
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
- // If the object is attached client-side, don't waste bandwidth sending its position to clients
- if(isAttached())
+ // If the object is attached client-side, don't waste bandwidth sending its
+ // position to clients
+ if (isAttached())
return;
- m_last_sent_move_precision = m_base_position.getDistanceFrom(
- m_last_sent_position);
+ m_last_sent_move_precision =
+ m_base_position.getDistanceFrom(m_last_sent_position);
m_last_sent_position_timer = 0;
m_last_sent_position = m_base_position;
m_last_sent_velocity = m_velocity;
- //m_last_sent_acceleration = m_acceleration;
+ // m_last_sent_acceleration = m_acceleration;
m_last_sent_rotation = m_rotation;
float update_interval = m_env->getSendRecommendedInterval();
- std::string str = generateUpdatePositionCommand(
- m_base_position,
- m_velocity,
- m_acceleration,
- m_rotation,
- do_interpolate,
- is_movement_end,
- update_interval
- );
+ std::string str = generateUpdatePositionCommand(m_base_position, m_velocity,
+ m_acceleration, m_rotation, do_interpolate, is_movement_end,
+ update_interval);
// create message and add to list
m_messages_out.emplace(getId(), false, str);
}
bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const
{
- if (m_prop.physical)
- {
- //update collision box
+ if (m_prop.physical) {
+ // update collision box
toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index 3d9f08bfa..1aa1a3f9b 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -26,11 +26,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverenvironment.h"
PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
- bool is_singleplayer):
- UnitSAO(env_, v3f(0,0,0)),
- m_player(player_),
- m_peer_id(peer_id_),
- m_is_singleplayer(is_singleplayer)
+ bool is_singleplayer) :
+ UnitSAO(env_, v3f(0, 0, 0)),
+ m_player(player_), m_peer_id(peer_id_), m_is_singleplayer(is_singleplayer)
{
SANITY_CHECK(m_peer_id != PEER_ID_INEXISTENT);
@@ -48,7 +46,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t p
m_prop.textures.emplace_back("player_back.png");
m_prop.colors.clear();
m_prop.colors.emplace_back(255, 255, 255, 255);
- m_prop.spritediv = v2s16(1,1);
+ m_prop.spritediv = v2s16(1, 1);
m_prop.eye_height = 1.625f;
// End of default appearance
m_prop.is_visible = true;
@@ -108,23 +106,24 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
std::ostringstream os(std::ios::binary);
// Protocol >= 15
- writeU8(os, 1); // version
+ writeU8(os, 1); // version
os << serializeString(m_player->getName()); // name
- writeU8(os, 1); // is_player
- writeS16(os, getId()); // id
+ writeU8(os, 1); // is_player
+ writeS16(os, getId()); // id
writeV3F32(os, m_base_position);
writeV3F32(os, m_rotation);
writeU16(os, getHP());
std::ostringstream msg_os(std::ios::binary);
- msg_os << serializeLongString(getPropertyPacket()); // message 1
+ msg_os << serializeLongString(getPropertyPacket()); // message 1
msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2
- msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
+ msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
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
+ bone_pos.first, bone_pos.second.X,
+ bone_pos.second.Y)); // m_bone_position.size
}
- msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
+ msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5
int message_count = 5 + m_bone_position.size();
@@ -133,7 +132,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
message_count++;
msg_os << serializeLongString(obj->generateUpdateInfantCommand(
- id, protocol_version));
+ id, protocol_version));
}
}
@@ -145,7 +144,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
return os.str();
}
-void PlayerSAO::getStaticData(std::string * result) const
+void PlayerSAO::getStaticData(std::string *result) const
{
FATAL_ERROR("Obsolete function");
}
@@ -164,7 +163,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// No more breath, damage player
if (m_breath == 0) {
- PlayerHPChangeReason reason(PlayerHPChangeReason::DROWNING);
+ PlayerHPChangeReason reason(
+ PlayerHPChangeReason::DROWNING);
setHP(m_hp - c.drowning, reason);
m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
}
@@ -176,7 +176,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
v3s16 p = floatToInt(getEyePosition(), BS);
MapNode n = m_env->getMap().getNode(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
- // If player is alive & not drowning & not in ignore & not immortal, breathe
+ // If player is alive & not drowning & not in ignore & not immortal,
+ // breathe
if (m_breath < m_prop.breath_max && c.drowning == 0 &&
n.getContent() != CONTENT_IGNORE && m_hp > 0)
setBreath(m_breath + 1);
@@ -191,8 +192,9 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// Sequence of damage points, starting 0.1 above feet and progressing
// upwards in 1 node intervals, stopping below top damage point.
for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) {
- v3s16 p = floatToInt(m_base_position +
- v3f(0.0f, dam_height * BS, 0.0f), BS);
+ v3s16 p = floatToInt(m_base_position + v3f(0.0f, dam_height * BS,
+ 0.0f),
+ BS);
MapNode n = m_env->getMap().getNode(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
if (c.damage_per_second > damage_per_second) {
@@ -202,8 +204,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
}
// Top damage point
- v3s16 ptop = floatToInt(m_base_position +
- v3f(0.0f, dam_top * BS, 0.0f), BS);
+ v3s16 ptop = floatToInt(
+ m_base_position + v3f(0.0f, dam_top * BS, 0.0f), BS);
MapNode ntop = m_env->getMap().getNode(ptop);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop);
if (c.damage_per_second > damage_per_second) {
@@ -213,7 +215,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
if (damage_per_second != 0 && m_hp > 0) {
s32 newhp = (s32)m_hp - (s32)damage_per_second;
- PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE, nodename);
+ PlayerHPChangeReason reason(
+ PlayerHPChangeReason::NODE_DAMAGE, nodename);
setHP(newhp, reason);
m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
}
@@ -230,19 +233,20 @@ 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()) {
// 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;
+ 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);
}
- //dstream<<"PlayerSAO::step: dtime: "<<dtime<<std::endl;
+ // dstream<<"PlayerSAO::step: dtime: "<<dtime<<std::endl;
// Set lag pool maximums based on estimated lag
const float LAG_POOL_MIN = 5.0f;
float lag_pool_max = m_env->getMaxLagEstimate() * 2.0f;
- if(lag_pool_max < LAG_POOL_MIN)
+ if (lag_pool_max < LAG_POOL_MIN)
lag_pool_max = LAG_POOL_MIN;
m_dig_pool.setMax(lag_pool_max);
m_move_pool.setMax(lag_pool_max);
@@ -260,7 +264,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// If the object gets detached this comes into effect automatically from
// the last known origin.
if (isAttached()) {
- v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ v3f pos = m_env->getActiveObject(m_attachment_parent_id)
+ ->getBasePosition();
m_last_good_position = pos;
setBasePosition(pos);
}
@@ -279,15 +284,9 @@ void PlayerSAO::step(float dtime, bool send_recommended)
else
pos = m_base_position;
- std::string str = generateUpdatePositionCommand(
- pos,
- v3f(0.0f, 0.0f, 0.0f),
- v3f(0.0f, 0.0f, 0.0f),
- m_rotation,
- true,
- false,
- update_interval
- );
+ std::string str = generateUpdatePositionCommand(pos,
+ v3f(0.0f, 0.0f, 0.0f), v3f(0.0f, 0.0f, 0.0f), m_rotation,
+ true, false, update_interval);
// create message and add to list
m_messages_out.emplace(getId(), false, str);
}
@@ -295,7 +294,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
if (!m_physics_override_sent) {
m_physics_override_sent = true;
// create message and add to list
- m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand());
+ m_messages_out.emplace(
+ getId(), true, generateUpdatePhysicsOverrideCommand());
}
sendOutdatedData();
@@ -333,11 +333,12 @@ void PlayerSAO::setBasePosition(const v3f &position)
void PlayerSAO::setPos(const v3f &pos)
{
- if(isAttached())
+ if (isAttached())
return;
// Send mapblock of target location
- v3s16 blockpos = v3s16(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE);
+ v3s16 blockpos = v3s16(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE,
+ pos.Z / MAP_BLOCKSIZE);
m_env->getGameDef()->SendBlock(m_peer_id, blockpos);
setBasePosition(pos);
@@ -350,7 +351,7 @@ void PlayerSAO::setPos(const v3f &pos)
void PlayerSAO::moveTo(v3f pos, bool continuous)
{
- if(isAttached())
+ if (isAttached())
return;
setBasePosition(pos);
@@ -407,10 +408,8 @@ void PlayerSAO::setLookPitchAndSend(const float pitch)
m_env->getGameDef()->SendMovePlayer(m_peer_id);
}
-u16 PlayerSAO::punch(v3f dir,
- const ToolCapabilities *toolcap,
- ServerActiveObject *puncher,
- float time_from_last_punch)
+u16 PlayerSAO::punch(v3f dir, const ToolCapabilities *toolcap,
+ ServerActiveObject *puncher, float time_from_last_punch)
{
if (!toolcap)
return 0;
@@ -427,18 +426,17 @@ u16 PlayerSAO::punch(v3f dir,
}
s32 old_hp = getHP();
- HitParams hitparams = getHitParams(m_armor_groups, toolcap,
- time_from_last_punch);
+ HitParams hitparams = getHitParams(m_armor_groups, toolcap, time_from_last_punch);
PlayerSAO *playersao = m_player->getPlayerSAO();
- bool damage_handled = m_env->getScriptIface()->on_punchplayer(playersao,
- puncher, time_from_last_punch, toolcap, dir,
- hitparams.hp);
+ bool damage_handled = m_env->getScriptIface()->on_punchplayer(playersao, puncher,
+ time_from_last_punch, toolcap, dir, hitparams.hp);
if (!damage_handled) {
setHP((s32)getHP() - (s32)hitparams.hp,
- PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
+ PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH,
+ puncher));
} else { // override client prediction
if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
// create message and add to list
@@ -446,11 +444,11 @@ u16 PlayerSAO::punch(v3f dir,
}
}
- actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
- ", hp=" << puncher->getHP() << ") punched " <<
- getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
- "), damage=" << (old_hp - (s32)getHP()) <<
- (damage_handled ? " (handled by Lua)" : "") << std::endl;
+ actionstream << puncher->getDescription() << " (id=" << puncher->getId()
+ << ", hp=" << puncher->getHP() << ") punched " << getDescription()
+ << " (id=" << m_id << ", hp=" << m_hp
+ << "), damage=" << (old_hp - (s32)getHP())
+ << (damage_handled ? " (handled by Lua)" : "") << std::endl;
return hitparams.wear;
}
@@ -459,10 +457,11 @@ void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{
s32 oldhp = m_hp;
- //hp = rangelim(hp, 0, m_prop.hp_max);
+ // hp = rangelim(hp, 0, m_prop.hp_max);
if (oldhp != hp) {
- s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason);
+ s32 hp_change = m_env->getScriptIface()->on_player_hpchange(
+ this, hp - oldhp, reason);
if (hp_change == 0)
return;
@@ -577,7 +576,8 @@ bool PlayerSAO::checkMovementCheat()
float override_max_H, override_max_V;
if (m_max_speed_override_time > 0.0f) {
- override_max_H = MYMAX(fabs(m_max_speed_override.X), fabs(m_max_speed_override.Z));
+ override_max_H = MYMAX(fabs(m_max_speed_override.X),
+ fabs(m_max_speed_override.Z));
override_max_V = fabs(m_max_speed_override.Y);
} else {
override_max_H = override_max_V = 0.0f;
@@ -627,8 +627,9 @@ bool PlayerSAO::checkMovementCheat()
lag_pool_max = MYMAX(lag_pool_max, LAG_POOL_MIN);
if (m_time_from_last_teleport > lag_pool_max) {
actionstream << "Server: " << m_player->getName()
- << " moved too fast: V=" << d_vert << ", H=" << d_horiz
- << "; resetting position." << std::endl;
+ << " moved too fast: V=" << d_vert
+ << ", H=" << d_horiz << "; resetting position."
+ << std::endl;
cheated = true;
}
setBasePosition(m_last_good_position);
@@ -638,7 +639,7 @@ bool PlayerSAO::checkMovementCheat()
bool PlayerSAO::getCollisionBox(aabb3f *toset) const
{
- //update collision box
+ // update collision box
toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;
diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp
index 3341dc008..3acf4cece 100644
--- a/src/server/serveractiveobject.cpp
+++ b/src/server/serveractiveobject.cpp
@@ -23,16 +23,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h" // BS
#include "log.h"
-ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
- ActiveObject(0),
- m_env(env),
- m_base_position(pos)
+ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos) :
+ ActiveObject(0), m_env(env), m_base_position(pos)
{
}
float ServerActiveObject::getMinimumSavedMovement()
{
- return 2.0*BS;
+ return 2.0 * BS;
}
ItemStack ServerActiveObject::getWieldedItem(ItemStack *selected, ItemStack *hand) const
@@ -49,7 +47,8 @@ bool ServerActiveObject::setWieldedItem(const ItemStack &item)
return false;
}
-std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 protocol_version)
+std::string ServerActiveObject::generateUpdateInfantCommand(
+ u16 infant_id, u16 protocol_version)
{
std::ostringstream os(std::ios::binary);
// command
diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h
index 927009aef..7af1c24c4 100644
--- a/src/server/serveractiveobject.h
+++ b/src/server/serveractiveobject.h
@@ -58,8 +58,7 @@ public:
ServerActiveObject(ServerEnvironment *env, v3f pos);
virtual ~ServerActiveObject() = default;
- virtual ActiveObjectType getSendType() const
- { return getType(); }
+ virtual ActiveObjectType getSendType() const { return getType(); }
// Called after id has been set and has been inserted in environment
virtual void addedToEnvironment(u32 dtime_s){};
@@ -67,35 +66,31 @@ public:
virtual void removingFromEnvironment(){};
// Returns true if object's deletion is the job of the
// environment
- virtual bool environmentDeletes() const
- { return true; }
+ virtual bool environmentDeletes() const { return true; }
// Create a certain type of ServerActiveObject
- static ServerActiveObject* create(ActiveObjectType type,
- ServerEnvironment *env, u16 id, v3f pos,
- const std::string &data);
+ static ServerActiveObject *create(ActiveObjectType type, ServerEnvironment *env,
+ u16 id, v3f pos, const std::string &data);
/*
Some simple getters/setters
*/
v3f getBasePosition() const { return m_base_position; }
- void setBasePosition(v3f pos){ m_base_position = pos; }
- ServerEnvironment* getEnv(){ return m_env; }
+ void setBasePosition(v3f pos) { m_base_position = pos; }
+ ServerEnvironment *getEnv() { return m_env; }
/*
Some more dynamic interface
*/
- virtual void setPos(const v3f &pos)
- { setBasePosition(pos); }
+ virtual void setPos(const v3f &pos) { setBasePosition(pos); }
// continuous: if true, object does not stop immediately at pos
- virtual void moveTo(v3f pos, bool continuous)
- { setBasePosition(pos); }
+ virtual void moveTo(v3f pos, bool continuous) { setBasePosition(pos); }
// If object has moved less than this and data has not changed,
// saving to disk may be omitted
virtual float getMinimumSavedMovement();
- virtual std::string getDescription(){return "SAO";}
+ virtual std::string getDescription() { return "SAO"; }
/*
Step object in time.
@@ -107,13 +102,16 @@ public:
same time so that the data can be combined in a single
packet.
*/
- virtual void step(float dtime, bool send_recommended){}
+ virtual void step(float dtime, bool send_recommended) {}
/*
The return value of this is passed to the client-side object
when it is created
*/
- virtual std::string getClientInitializationData(u16 protocol_version) {return "";}
+ virtual std::string getClientInitializationData(u16 protocol_version)
+ {
+ return "";
+ }
/*
The return value of this is passed to the server-side object
@@ -129,59 +127,65 @@ public:
Return false in here to never save and instead remove object
on unload. getStaticData() will not be called in that case.
*/
- virtual bool isStaticAllowed() const
- {return true;}
+ virtual bool isStaticAllowed() const { return true; }
// Returns tool wear
- virtual u16 punch(v3f dir,
- const ToolCapabilities *toolcap = nullptr,
+ virtual u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
ServerActiveObject *puncher = nullptr,
float time_from_last_punch = 1000000.0f)
- { return 0; }
- virtual void rightClick(ServerActiveObject *clicker)
- {}
- virtual void setHP(s32 hp, const PlayerHPChangeReason &reason)
- {}
- virtual u16 getHP() const
- { return 0; }
-
- virtual void setArmorGroups(const ItemGroupList &armor_groups)
- {}
+ {
+ return 0;
+ }
+ virtual void rightClick(ServerActiveObject *clicker) {}
+ virtual void setHP(s32 hp, const PlayerHPChangeReason &reason) {}
+ virtual u16 getHP() const { return 0; }
+
+ virtual void setArmorGroups(const ItemGroupList &armor_groups) {}
virtual const ItemGroupList &getArmorGroups() const
- { static ItemGroupList rv; return rv; }
- virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity)
- {}
- virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
- {}
- virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop)
- {}
- virtual void setAnimationSpeed(float frame_speed)
- {}
+ {
+ static ItemGroupList rv;
+ return rv;
+ }
+ virtual void setPhysicsOverride(float physics_override_speed,
+ float physics_override_jump, float physics_override_gravity)
+ {
+ }
+ virtual void setAnimation(
+ v2f frames, float frame_speed, float frame_blend, bool frame_loop)
+ {
+ }
+ virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend,
+ bool *frame_loop)
+ {
+ }
+ virtual void setAnimationSpeed(float frame_speed) {}
virtual void setBonePosition(const std::string &bone, v3f position, v3f rotation)
- {}
- virtual void getBonePosition(const std::string &bone, v3f *position, v3f *lotation)
- {}
+ {
+ }
+ virtual void getBonePosition(
+ const std::string &bone, v3f *position, v3f *lotation)
+ {
+ }
virtual const std::unordered_set<int> &getAttachmentChildIds() const
- { static std::unordered_set<int> rv; return rv; }
+ {
+ static std::unordered_set<int> rv;
+ return rv;
+ }
virtual ServerActiveObject *getParent() const { return nullptr; }
- virtual ObjectProperties* accessObjectProperties()
- { return NULL; }
- virtual void notifyObjectPropertiesModified()
- {}
+ virtual ObjectProperties *accessObjectProperties() { return NULL; }
+ virtual void notifyObjectPropertiesModified() {}
// Inventory and wielded item
- virtual Inventory *getInventory() const
- { return NULL; }
+ virtual Inventory *getInventory() const { return NULL; }
virtual InventoryLocation getInventoryLocation() const
- { return InventoryLocation(); }
- virtual void setInventoryModified()
- {}
- virtual std::string getWieldList() const
- { return ""; }
- virtual u16 getWieldIndex() const
- { return 0; }
- virtual ItemStack getWieldedItem(ItemStack *selected,
- ItemStack *hand = nullptr) const;
+ {
+ return InventoryLocation();
+ }
+ virtual void setInventoryModified() {}
+ virtual std::string getWieldList() const { return ""; }
+ virtual u16 getWieldIndex() const { return 0; }
+ virtual ItemStack getWieldedItem(
+ ItemStack *selected, ItemStack *hand = nullptr) const;
virtual bool setWieldedItem(const ItemStack &item);
inline void attachParticleSpawner(u32 id)
{
@@ -193,7 +197,8 @@ public:
}
std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version);
- std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const;
+ std::string generateUpdateNametagAttributesCommand(
+ const video::SColor &color) const;
void dumpAOMessagesToQueue(std::queue<ActiveObjectMessage> &queue);
@@ -227,8 +232,7 @@ public:
A getter that unifies the above to answer the question:
"Can the environment still interact with this object?"
*/
- inline bool isGone() const
- { return m_pending_removal || m_pending_deactivation; }
+ inline bool isGone() const { return m_pending_removal || m_pending_deactivation; }
/*
Whether the object's static data has been stored to a block
@@ -238,7 +242,7 @@ public:
The block from which the object was loaded from, and in which
a copy of the static data resides.
*/
- v3s16 m_static_block = v3s16(1337,1337,1337);
+ v3s16 m_static_block = v3s16(1337, 1337, 1337);
protected:
virtual void onAttach(int parent_id) {}