diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-04 12:19:26 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-04 12:19:26 +0100 |
commit | 40bf1d7b5f2a190ae89885c9ea99f52c476ea6be (patch) | |
tree | a8547067308dd42775ee54f3aeed7009a7559d95 /src | |
parent | 7f8f9785d7e9e120a6708d2f51e32dfef3e50c19 (diff) | |
download | minetest-40bf1d7b5f2a190ae89885c9ea99f52c476ea6be.tar.gz minetest-40bf1d7b5f2a190ae89885c9ea99f52c476ea6be.tar.bz2 minetest-40bf1d7b5f2a190ae89885c9ea99f52c476ea6be.zip |
Send Position packet on event, don't check it at each AsyncRunStep.
* This permit to cleanup the player checking loop
Diffstat (limited to 'src')
-rw-r--r-- | src/content_sao.cpp | 17 | ||||
-rw-r--r-- | src/content_sao.h | 3 | ||||
-rw-r--r-- | src/network/packethandlers/server.cpp | 4 | ||||
-rw-r--r-- | src/server.cpp | 27 | ||||
-rw-r--r-- | src/server.h | 4 |
5 files changed, 10 insertions, 45 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp index ad48f95fb..9dadcede9 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tool.h" // For ToolCapabilities #include "gamedef.h" #include "player.h" +#include "server.h" #include "scripting_game.h" #include "genericobject.h" #include "log.h" @@ -716,7 +717,6 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_, m_attachment_parent_id(0), m_attachment_sent(false), // public - m_moved(false), m_physics_override_speed(1), m_physics_override_jump(1), m_physics_override_gravity(1), @@ -867,7 +867,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) m_attachment_position = v3f(0,0,0); m_attachment_rotation = v3f(0,0,0); m_player->setPosition(m_last_good_position); - m_moved = true; + ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id); } //dstream<<"PlayerSAO::step: dtime: "<<dtime<<std::endl; @@ -982,8 +982,7 @@ void PlayerSAO::setPos(v3f pos) m_player->setPosition(pos); // Movement caused by this command is always valid m_last_good_position = pos; - // Force position change on client - m_moved = true; + ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id); } void PlayerSAO::moveTo(v3f pos, bool continuous) @@ -993,22 +992,19 @@ void PlayerSAO::moveTo(v3f pos, bool continuous) m_player->setPosition(pos); // Movement caused by this command is always valid m_last_good_position = pos; - // Force position change on client - m_moved = true; + ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id); } void PlayerSAO::setYaw(float yaw) { m_player->setYaw(yaw); - // Force change on client - m_moved = true; + ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id); } void PlayerSAO::setPitch(float pitch) { m_player->setPitch(pitch); - // Force change on client - m_moved = true; + ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id); } int PlayerSAO::punch(v3f dir, @@ -1241,7 +1237,6 @@ bool PlayerSAO::checkMovementCheat() <<" moved too fast; resetting position" <<std::endl; m_player->setPosition(m_last_good_position); - m_moved = true; cheated = true; } } diff --git a/src/content_sao.h b/src/content_sao.h index a93029154..cc372ff55 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -314,9 +314,6 @@ private: bool m_attachment_sent; public: - // Some flags used by Server - bool m_moved; - float m_physics_override_speed; float m_physics_override_jump; float m_physics_override_gravity; diff --git a/src/network/packethandlers/server.cpp b/src/network/packethandlers/server.cpp index 9dd1c95dd..526c17344 100644 --- a/src/network/packethandlers/server.cpp +++ b/src/network/packethandlers/server.cpp @@ -579,10 +579,10 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt) player->control.LMB = (keyPressed & 128); player->control.RMB = (keyPressed & 256); - bool cheated = playersao->checkMovementCheat(); - if (cheated) { + if (playersao->checkMovementCheat()) { // Call callbacks m_script->on_cheat(playersao, "moved_too_fast"); + SendMovePlayer(pkt->getPeerId()); } } diff --git a/src/server.cpp b/src/server.cpp index d2af9f5ac..625ab2231 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -581,32 +581,6 @@ void Server::AsyncRunStep(bool initial_step) Do background stuff */ - /* - Handle players - */ - { - JMutexAutoLock lock(m_env_mutex); - - std::list<u16> clientids = m_clients.getClientIDs(); - - ScopeProfiler sp(g_profiler, "Server: handle players"); - - for(std::list<u16>::iterator - i = clientids.begin(); - i != clientids.end(); ++i) - { - PlayerSAO *playersao = getPlayerSAO(*i); - if(playersao == NULL) - continue; - - - if(playersao->m_moved) { - SendMovePlayer(*i); - playersao->m_moved = false; - } - } - } - /* Transform liquids */ m_liquid_transform_timer += dtime; if(m_liquid_transform_timer >= m_liquid_transform_every) @@ -2590,6 +2564,7 @@ void Server::RespawnPlayer(u16 peer_id) bool repositioned = m_script->on_respawnplayer(playersao); if(!repositioned){ v3f pos = findSpawnPos(m_env->getServerMap()); + // setPos will send the new position to client playersao->setPos(pos); } } diff --git a/src/server.h b/src/server.h index b3d5d0fec..2fea0db4c 100644 --- a/src/server.h +++ b/src/server.h @@ -374,9 +374,8 @@ public: void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); } void SendPlayerBreath(u16 peer_id); - - // Envlock and conlock should be locked when calling these void SendInventory(u16 peer_id); + void SendMovePlayer(u16 peer_id); // Bind address Address m_bind_addr; @@ -402,7 +401,6 @@ private: void SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed); void SendPlayerHP(u16 peer_id); - void SendMovePlayer(u16 peer_id); void SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed); void SendEyeOffset(u16 peer_id, v3f first, v3f third); void SendPlayerPrivileges(u16 peer_id); |