Skip to content

Commit

Permalink
Disable all HP handling if enable_damage is false
Browse files Browse the repository at this point in the history
  • Loading branch information
PilzAdam committed Jan 7, 2013
1 parent 0437abb commit 8aa1906
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/game.cpp
Expand Up @@ -2099,7 +2099,8 @@ void the_game(
{
break;
}
else if(event.type == CE_PLAYER_DAMAGE)
else if(event.type == CE_PLAYER_DAMAGE &&
client.getHP() != 0)
{
//u16 damage = event.player_damage.amount;
//infostream<<"Player damage: "<<damage<<std::endl;
Expand Down
38 changes: 22 additions & 16 deletions src/server.cpp
Expand Up @@ -1368,11 +1368,16 @@ void Server::AsyncRunStep()
/*
Handle player HPs (die if hp=0)
*/
if(playersao->getHP() == 0 && playersao->m_hp_not_sent)
DiePlayer(client->peer_id);
if(playersao->m_hp_not_sent && g_settings->getBool("enable_damage"))
{
if(playersao->getHP() == 0)
DiePlayer(client->peer_id);
else
SendPlayerHP(client->peer_id);
}

/*
Send player inventories and HPs if necessary
Send player inventories if necessary
*/
if(playersao->m_moved){
SendMovePlayer(client->peer_id);
Expand All @@ -1382,9 +1387,6 @@ void Server::AsyncRunStep()
UpdateCrafting(client->peer_id);
SendInventory(client->peer_id);
}
if(playersao->m_hp_not_sent){
SendPlayerHP(client->peer_id);
}
}
}

Expand Down Expand Up @@ -2311,7 +2313,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
SendInventory(peer_id);

// Send HP
SendPlayerHP(peer_id);
if(g_settings->getBool("enable_damage"))
SendPlayerHP(peer_id);

// Send detached inventories
sendDetachedInventories(peer_id);
Expand Down Expand Up @@ -2764,17 +2767,20 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
std::istringstream is(datastring, std::ios_base::binary);
u8 damage = readU8(is);

actionstream<<player->getName()<<" damaged by "
<<(int)damage<<" hp at "<<PP(player->getPosition()/BS)
<<std::endl;
if(g_settings->getBool("enable_damage"))
{
actionstream<<player->getName()<<" damaged by "
<<(int)damage<<" hp at "<<PP(player->getPosition()/BS)
<<std::endl;

playersao->setHP(playersao->getHP() - damage);
playersao->setHP(playersao->getHP() - damage);

if(playersao->getHP() == 0 && playersao->m_hp_not_sent)
DiePlayer(peer_id);
if(playersao->getHP() == 0 && playersao->m_hp_not_sent)
DiePlayer(peer_id);

if(playersao->m_hp_not_sent)
SendPlayerHP(peer_id);
if(playersao->m_hp_not_sent)
SendPlayerHP(peer_id);
}
}
else if(command == TOSERVER_PASSWORD)
{
Expand Down Expand Up @@ -2850,7 +2856,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
else if(command == TOSERVER_RESPAWN)
{
if(player->hp != 0)
if(player->hp != 0 || !g_settings->getBool("enable_damage"))
return;

RespawnPlayer(peer_id);
Expand Down

0 comments on commit 8aa1906

Please sign in to comment.