diff --git a/src/exceptions.h b/src/exceptions.h index 5b716c2ca862691fdf195b946e43fded2dddf62e..0ea4c935036573811ff57073022b7913992154ab 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -70,6 +70,11 @@ class SerializationError : public BaseException { SerializationError(const std::string &s): BaseException(s) {} }; +class PacketError : public BaseException { +public: + PacketError(const std::string &s): BaseException(s) {} +}; + class LoadError : public BaseException { public: LoadError(const std::string &s): BaseException(s) {} diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 4afe2a2ce07999e721c238dbb0b7f08b0bc6bbb2..a9096accc1adac85e0febe777c4913b2b84dcc33 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; } } diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index 95605d410b258ea5e9d460de8d4f4c230b7a42bf..a4a481db48352c313c4acaa82be4109f5660b0b9 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -45,7 +45,7 @@ void NetworkPacket::checkReadOffset(u32 from_offset) std::stringstream ss; ss << "Reading outside packet (offset: " << from_offset << ", packet size: " << getSize() << ")"; - throw SerializationError(ss.str()); + throw PacketError(ss.str()); } }