Create PacketError exception and use it with ACTIVEOBJECT_REMOVE_ADD handler which can be unreliable
parent
92f20696eb
commit
aa340fd857
|
@ -70,6 +70,11 @@ public:
|
||||||
SerializationError(const std::string &s): BaseException(s) {}
|
SerializationError(const std::string &s): BaseException(s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PacketError : public BaseException {
|
||||||
|
public:
|
||||||
|
PacketError(const std::string &s): BaseException(s) {}
|
||||||
|
};
|
||||||
|
|
||||||
class LoadError : public BaseException {
|
class LoadError : public BaseException {
|
||||||
public:
|
public:
|
||||||
LoadError(const std::string &s): BaseException(s) {}
|
LoadError(const std::string &s): BaseException(s) {}
|
||||||
|
|
|
@ -336,7 +336,6 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt)
|
||||||
void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
|
void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
u16 command
|
|
||||||
u16 count of removed objects
|
u16 count of removed objects
|
||||||
for all removed objects {
|
for all removed objects {
|
||||||
u16 id
|
u16 id
|
||||||
|
@ -350,23 +349,28 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Read removed objects
|
try {
|
||||||
u8 type;
|
u8 type;
|
||||||
u16 removed_count, added_count, id;
|
u16 removed_count, added_count, id;
|
||||||
|
|
||||||
*pkt >> removed_count;
|
// Read removed objects
|
||||||
|
*pkt >> removed_count;
|
||||||
|
|
||||||
for (u16 i = 0; i < removed_count; i++) {
|
for (u16 i = 0; i < removed_count; i++) {
|
||||||
*pkt >> id;
|
*pkt >> id;
|
||||||
m_env.removeActiveObject(id);
|
m_env.removeActiveObject(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read added objects
|
// Read added objects
|
||||||
*pkt >> added_count;
|
*pkt >> added_count;
|
||||||
|
|
||||||
for (u16 i = 0; i < added_count; i++) {
|
for (u16 i = 0; i < added_count; i++) {
|
||||||
*pkt >> id >> type;
|
*pkt >> id >> type;
|
||||||
m_env.addActiveObject(id, type, pkt->readLongString());
|
m_env.addActiveObject(id, type, pkt->readLongString());
|
||||||
|
}
|
||||||
|
} catch (PacketError &e) {
|
||||||
|
infostream << "handleCommand_ActiveObjectRemoveAdd: " << e.what()
|
||||||
|
<< ". The packet is unreliable, ignoring" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ void NetworkPacket::checkReadOffset(u32 from_offset)
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Reading outside packet (offset: " <<
|
ss << "Reading outside packet (offset: " <<
|
||||||
from_offset << ", packet size: " << getSize() << ")";
|
from_offset << ", packet size: " << getSize() << ")";
|
||||||
throw SerializationError(ss.str());
|
throw PacketError(ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue