aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-12-02 17:19:42 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-12-02 17:19:42 +0200
commit67c21fc42f79f5efe74e4c8194944ac834224069 (patch)
treefc9eae9ffcb1ac48fea0c84340262bef9a1d7e65 /src
parentc2d266efc69ad9a578e50dd0a2594f3c20d14eba (diff)
downloadminetest-67c21fc42f79f5efe74e4c8194944ac834224069.tar.gz
minetest-67c21fc42f79f5efe74e4c8194944ac834224069.tar.bz2
minetest-67c21fc42f79f5efe74e4c8194944ac834224069.zip
Fix sending of player hp (was sent all the time)
Diffstat (limited to 'src')
-rw-r--r--src/server.cpp61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 786a3600e..cb515e0d0 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1283,6 +1283,8 @@ void Server::AsyncRunStep()
JMutexAutoLock lock(m_env_mutex);
JMutexAutoLock lock2(m_con_mutex);
+ ScopeProfiler sp(g_profiler, "Server: handle players");
+
//float player_max_speed = BS * 4.0; // Normal speed
float player_max_speed = BS * 20; // Fast speed
float player_max_speed_up = BS * 20;
@@ -1332,7 +1334,7 @@ void Server::AsyncRunStep()
}
/*
- Handle player HPs
+ Handle player HPs (die if hp=0)
*/
HandlePlayerHP(player, 0);
@@ -1591,7 +1593,7 @@ void Server::AsyncRunStep()
JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex);
- //ScopeProfiler sp(g_profiler, "Server: sending object messages");
+ ScopeProfiler sp(g_profiler, "Server: sending object messages");
// Key = object id
// Value = data sent by object
@@ -3983,6 +3985,7 @@ void Server::BroadcastChatMessage(const std::wstring &message)
void Server::SendPlayerHP(Player *player)
{
SendHP(m_con, player->peer_id, player->hp);
+ static_cast<ServerRemotePlayer*>(player)->m_hp_not_sent = false;
}
void Server::SendMovePlayer(Player *player)
@@ -4381,39 +4384,41 @@ void Server::HandlePlayerHP(Player *player, s16 damage)
if(srp->m_respawn_active)
return;
+ if(damage == 0)
+ return;
+
if(player->hp > damage)
{
player->hp -= damage;
SendPlayerHP(player);
+ return;
+ }
+
+ infostream<<"Server::HandlePlayerHP(): Player "
+ <<player->getName()<<" dies"<<std::endl;
+
+ player->hp = 0;
+
+ //TODO: Throw items around
+
+ // Handle players that are not connected
+ if(player->peer_id == PEER_ID_INEXISTENT){
+ RespawnPlayer(player);
+ return;
+ }
+
+ SendPlayerHP(player);
+
+ RemoteClient *client = getClient(player->peer_id);
+ if(client->net_proto_version >= 3)
+ {
+ SendDeathscreen(m_con, player->peer_id, false, v3f(0,0,0));
+ srp->m_removed = true;
+ srp->m_respawn_active = true;
}
else
{
- infostream<<"Server::HandlePlayerHP(): Player "
- <<player->getName()<<" dies"<<std::endl;
-
- player->hp = 0;
-
- //TODO: Throw items around
-
- // Handle players that are not connected
- if(player->peer_id == PEER_ID_INEXISTENT){
- RespawnPlayer(player);
- return;
- }
-
- SendPlayerHP(player);
-
- RemoteClient *client = getClient(player->peer_id);
- if(client->net_proto_version >= 3)
- {
- SendDeathscreen(m_con, player->peer_id, false, v3f(0,0,0));
- srp->m_removed = true;
- srp->m_respawn_active = true;
- }
- else
- {
- RespawnPlayer(player);
- }
+ RespawnPlayer(player);
}
}