diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-04-03 08:53:31 +0200 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-04-03 08:53:31 +0200 |
commit | aa340fd857c151384873f2b29a9bad76e49e852a (patch) | |
tree | 60524b27c50de5e8a491c2a4bca941459bba7e71 /src/network/clientpackethandler.cpp | |
parent | 92f20696eb57701d4d59adb5e9278315c2558180 (diff) | |
download | minetest-aa340fd857c151384873f2b29a9bad76e49e852a.tar.gz minetest-aa340fd857c151384873f2b29a9bad76e49e852a.tar.bz2 minetest-aa340fd857c151384873f2b29a9bad76e49e852a.zip |
Create PacketError exception and use it with ACTIVEOBJECT_REMOVE_ADD handler which can be unreliable
Diffstat (limited to 'src/network/clientpackethandler.cpp')
-rw-r--r-- | src/network/clientpackethandler.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 4afe2a2ce..a9096accc 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -336,7 +336,6 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt) void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt) { /* - u16 command u16 count of removed objects for all removed objects { u16 id @@ -350,23 +349,28 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt) } */ - // Read removed objects - u8 type; - u16 removed_count, added_count, id; + try { + u8 type; + u16 removed_count, added_count, id; - *pkt >> removed_count; + // Read removed objects + *pkt >> removed_count; - for (u16 i = 0; i < removed_count; i++) { - *pkt >> id; - m_env.removeActiveObject(id); - } + for (u16 i = 0; i < removed_count; i++) { + *pkt >> id; + m_env.removeActiveObject(id); + } - // Read added objects - *pkt >> added_count; + // Read added objects + *pkt >> added_count; - for (u16 i = 0; i < added_count; i++) { - *pkt >> id >> type; - m_env.addActiveObject(id, type, pkt->readLongString()); + for (u16 i = 0; i < added_count; i++) { + *pkt >> id >> type; + m_env.addActiveObject(id, type, pkt->readLongString()); + } + } catch (PacketError &e) { + infostream << "handleCommand_ActiveObjectRemoveAdd: " << e.what() + << ". The packet is unreliable, ignoring" << std::endl; } } |