1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Allow restricting detached inventories to one player

This combats the problem of sending the hundreds of
"creative" / "armor" or whatever detached invs that
exist on popular servers to each and every player
on join or on change of said invs.
This commit is contained in:
sfan5 2016-11-26 17:35:25 +01:00
parent 2fe3bf5a18
commit c38985825f
5 changed files with 25 additions and 13 deletions

View file

@ -2487,11 +2487,16 @@ void Server::sendDetachedInventory(const std::string &name, u16 peer_id)
NetworkPacket pkt(TOCLIENT_DETACHED_INVENTORY, 0, peer_id);
pkt.putRawString(s.c_str(), s.size());
if (peer_id != PEER_ID_INEXISTENT) {
Send(&pkt);
}
else {
m_clients.sendToAll(0, &pkt, true);
const std::string &check = m_detached_inventories_player[name];
if (peer_id == PEER_ID_INEXISTENT) {
if (check == "")
return m_clients.sendToAll(0, &pkt, true);
RemotePlayer *p = m_env->getPlayer(check.c_str());
if (p)
m_clients.send(p->peer_id, 0, &pkt, true);
} else {
if (check == "" || getPlayerName(peer_id) == check)
Send(&pkt);
}
}
@ -3224,7 +3229,7 @@ void Server::deleteParticleSpawner(const std::string &playername, u32 id)
SendDeleteParticleSpawner(peer_id, id);
}
Inventory* Server::createDetachedInventory(const std::string &name)
Inventory* Server::createDetachedInventory(const std::string &name, const std::string &player)
{
if(m_detached_inventories.count(name) > 0){
infostream<<"Server clearing detached inventory \""<<name<<"\""<<std::endl;
@ -3235,6 +3240,7 @@ Inventory* Server::createDetachedInventory(const std::string &name)
Inventory *inv = new Inventory(m_itemdef);
sanity_check(inv);
m_detached_inventories[name] = inv;
m_detached_inventories_player[name] = player;
//TODO find a better way to do this
sendDetachedInventory(name,PEER_ID_INEXISTENT);
return inv;