ServerActiveObject(env, v3f(0,0,0)),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
- m_additional_items()
+ m_additional_items(),
+ m_inventory_not_sent(false),
+ m_hp_not_sent(false)
{
}
ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,
const char *name_):
Player(env->getGameDef()),
- ServerActiveObject(env, pos_)
+ ServerActiveObject(env, pos_),
+ m_inventory_not_sent(false),
+ m_hp_not_sent(false)
{
setPosition(pos_);
peer_id = peer_id_;
// Add to inventory
InventoryItem *leftover = ilist->addItem(item);
assert(!leftover);
+
+ m_inventory_not_sent = true;
return true;
}
delete leftover;
}
m_additional_items.clear();
+ m_inventory_not_sent = true;
}
void ServerRemotePlayer::setHP(s16 hp_)
{
+ s16 oldhp = hp;
+
hp = hp_;
// FIXME: don't hardcode maximum HP, make configurable per object
hp = 0;
else if(hp > 20)
hp = 20;
+
+ if(hp != oldhp)
+ m_hp_not_sent = true;
}
s16 ServerRemotePlayer::getHP()
{
*/
/*
- Check player movements
-
- NOTE: Actually the server should handle player physics like the
- client does and compare player's position to what is calculated
- on our side. This is required when eg. players fly due to an
- explosion.
+ Handle players
*/
{
JMutexAutoLock lock(m_env_mutex);
(m_env->getPlayer(client->peer_id));
if(player==NULL)
continue;
+
+ /*
+ Check player movements
+
+ NOTE: Actually the server should handle player physics like the
+ client does and compare player's position to what is calculated
+ on our side. This is required when eg. players fly due to an
+ explosion.
+ */
player->m_last_good_position_age += dtime;
if(player->m_last_good_position_age >= 2.0){
float age = player->m_last_good_position_age;
}
player->m_last_good_position_age = 0;
}
+
+ /*
+ Send player inventories and HPs if necessary
+ */
+ if(player->m_inventory_not_sent){
+ UpdateCrafting(player->peer_id);
+ SendInventory(player->peer_id);
+ }
+ if(player->m_hp_not_sent){
+ SendPlayerHP(player);
+ }
}
}
{
mlist->deleteItem(item_i);
}
+
+ srp->m_inventory_not_sent = true;
}
}
{
// Add a item to inventory
player->inventory.addItem("main", item);
+ srp->m_inventory_not_sent = true;
}
item = NULL;
if(mineral != MINERAL_NONE)
- item = getDiggedMineralItem(mineral, this);
+ item = getDiggedMineralItem(mineral, this);
// If not mineral
if(item == NULL)
{
// Add a item to inventory
player->inventory.addItem("main", item);
+ srp->m_inventory_not_sent = true;
}
}
ilist->deleteItem(item_i);
else
mitem->remove(1);
+ srp->m_inventory_not_sent = true;
}
/*
if(remove && g_settings->getBool("creative_mode") == false)
{
InventoryList *ilist = player->inventory.getList("main");
- if(ilist)
+ if(ilist){
// Remove from inventory and send inventory
ilist->deleteItem(item_i);
+ srp->m_inventory_not_sent = true;
+ }
}
}
}
<<", pointing at "<<pointed.dump()<<std::endl;
bool remove = item->use(m_env, srp, pointed);
+
if(remove && g_settings->getBool("creative_mode") == false)
{
InventoryList *ilist = player->inventory.getList("main");
- if(ilist)
+ if(ilist){
// Remove from inventory and send inventory
ilist->deleteItem(item_i);
+ srp->m_inventory_not_sent = true;
+ }
}
} // action == 4
// Complete add_to_inventory_later
srp->completeAddToInventoryLater(item_i);
-
- // Send inventory
- // FIXME: Shouldn't be done unless something changed.
- UpdateCrafting(player->peer_id);
- SendInventory(player->peer_id);
}
else
{
if(id == "current_player")
{
assert(c->current_player);
- // Send inventory
- UpdateCrafting(c->current_player->peer_id);
- SendInventory(c->current_player->peer_id);
+ ServerRemotePlayer *srp =
+ static_cast<ServerRemotePlayer*>(c->current_player);
+ srp->m_inventory_not_sent = true;
return;
}
{
DSTACK(__FUNCTION_NAME);
- Player* player = m_env->getPlayer(peer_id);
+ ServerRemotePlayer* player =
+ static_cast<ServerRemotePlayer*>(m_env->getPlayer(peer_id));
assert(player);
+ player->m_inventory_not_sent = false;
+
/*
Serialize it
*/