aboutsummaryrefslogtreecommitdiff
path: root/src/network/clientpackethandler.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-07-13 23:29:29 -0400
committerkwolekr <kwolekr@minetest.net>2015-07-13 23:29:29 -0400
commit5006ce82609b2260f191b132f2dabcfdb06d6e20 (patch)
tree37dff0c7114047e67571bc8f853df7257b957be9 /src/network/clientpackethandler.cpp
parent6f07f79c2f36b007b4c0385b7df2fc4612af7aba (diff)
downloadminetest-5006ce82609b2260f191b132f2dabcfdb06d6e20.tar.gz
minetest-5006ce82609b2260f191b132f2dabcfdb06d6e20.tar.bz2
minetest-5006ce82609b2260f191b132f2dabcfdb06d6e20.zip
Remove raw message output on AOM deserialization failure
Improve TOCLIENT_ACTIVE_OBJECT_MESSAGES robustness for handling invalid data
Diffstat (limited to 'src/network/clientpackethandler.cpp')
-rw-r--r--src/network/clientpackethandler.cpp28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 4cebb2184..15d5456fa 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -449,33 +449,23 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
string message
}
*/
- char buf[6];
- // Get all data except the command number
std::string datastring(pkt->getString(0), pkt->getSize());
- // Throw them in an istringstream
std::istringstream is(datastring, std::ios_base::binary);
try {
- while(is.eof() == false) {
- is.read(buf, 2);
- u16 id = readU16((u8*)buf);
- if (is.eof())
+ while (is.good()) {
+ u16 id = readU16(is);
+ if (!is.good())
break;
- is.read(buf, 2);
- size_t message_size = readU16((u8*)buf);
- std::string message;
- message.reserve(message_size);
- for (u32 i = 0; i < message_size; i++) {
- is.read(buf, 1);
- message.append(buf, 1);
- }
+
+ std::string message = deSerializeString(is);
+
// Pass on to the environment
m_env.processActiveObjectMessage(id, message);
}
- // Packet could be unreliable then ignore it
- } catch (PacketError &e) {
- infostream << "handleCommand_ActiveObjectMessages: " << e.what()
- << ". The packet is unreliable, ignoring" << std::endl;
+ } catch (SerializationError &e) {
+ errorstream << "Client::handleCommand_ActiveObjectMessages: "
+ << "caught SerializationError: " << e.what() << std::endl;
}
}