diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2011-08-11 07:02:57 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2011-08-11 15:22:36 +0200 |
commit | 371af9c241c3064d64e1109098aa5471e545d32c (patch) | |
tree | 3e58bd6b0662ba26a008a208024717eb03f667bf /src/client.cpp | |
parent | 88a9bae160dd0bf28fe41b2a45c198d67a65c914 (diff) | |
download | minetest-371af9c241c3064d64e1109098aa5471e545d32c.tar.gz minetest-371af9c241c3064d64e1109098aa5471e545d32c.tar.bz2 minetest-371af9c241c3064d64e1109098aa5471e545d32c.zip |
Notify other players of wielded item change
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp index 398b2602d..edce25381 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1549,6 +1549,47 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) // get damage from falling on ground m_ignore_damage_timer = 3.0; } + else if(command == TOCLIENT_PLAYERITEM) + { + std::string datastring((char*)&data[2], datasize-2); + std::istringstream is(datastring, std::ios_base::binary); + + u16 count = readU16(is); + + for (u16 i = 0; i < count; ++i) { + u16 peer_id = readU16(is); + Player *player = m_env.getPlayer(peer_id); + + if (player == NULL) + { + dout_client<<DTIME<<"Client: ignoring player item " + << deSerializeString(is) + << " for non-existing peer id " << peer_id + << std::endl; + continue; + } else if (player->isLocal()) { + dout_client<<DTIME<<"Client: ignoring player item " + << deSerializeString(is) + << " for local player" << std::endl; + continue; + } else { + InventoryList *inv = player->inventory.getList("main"); + std::string itemstring(deSerializeString(is)); + if (itemstring.empty()) { + inv->deleteItem(0); + dout_client<<DTIME + <<"Client: empty player item for peer " + << peer_id << std::endl; + } else { + std::istringstream iss(itemstring); + delete inv->changeItem(0, InventoryItem::deSerialize(iss)); + dout_client<<DTIME<<"Client: player item for peer " << peer_id << ": "; + player->getWieldItem()->serialize(dout_client); + dout_client<<std::endl; + } + } + } + } else { dout_client<<DTIME<<"WARNING: Client: Ignoring unknown command " |