aboutsummaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-04-05 11:37:53 +0200
committerLoic Blot <loic.blot@unix-experience.fr>2015-04-05 11:39:38 +0200
commit8804c47e59b550ec9a533de662f086af623d68c1 (patch)
tree244d404f2d3b38af062843194929282c6c91615d /src/network
parented3ebd633d23184c65128fae72f2b6c10c932e73 (diff)
downloadminetest-8804c47e59b550ec9a533de662f086af623d68c1.tar.gz
minetest-8804c47e59b550ec9a533de662f086af623d68c1.tar.bz2
minetest-8804c47e59b550ec9a533de662f086af623d68c1.zip
TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD can be unreliable, catch PacketError exception.
Also set the packet size at creation not when pushing rawString, no functional change
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientpackethandler.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index a9096accc..68d4245f8 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -377,7 +377,6 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
{
/*
- u16 command
for all objects
{
u16 id
@@ -391,21 +390,27 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
// Throw them in an istringstream
std::istringstream is(datastring, std::ios_base::binary);
- while(is.eof() == false) {
- is.read(buf, 2);
- u16 id = readU16((u8*)buf);
- if (is.eof())
- 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);
+ try {
+ while(is.eof() == false) {
+ is.read(buf, 2);
+ u16 id = readU16((u8*)buf);
+ if (is.eof())
+ 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);
+ }
+ // Pass on to the environment
+ m_env.processActiveObjectMessage(id, message);
}
- // 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;
}
}