Remove raw message output on AOM deserialization failure
Improve TOCLIENT_ACTIVE_OBJECT_MESSAGES robustness for handling invalid datamutilcraft-mt53
parent
6f07f79c2f
commit
5006ce8260
|
@ -2535,27 +2535,22 @@ void ClientEnvironment::removeActiveObject(u16 id)
|
||||||
m_active_objects.erase(id);
|
m_active_objects.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientEnvironment::processActiveObjectMessage(u16 id,
|
void ClientEnvironment::processActiveObjectMessage(u16 id, const std::string &data)
|
||||||
const std::string &data)
|
|
||||||
{
|
{
|
||||||
ClientActiveObject *obj = getActiveObject(id);
|
ClientActiveObject *obj = getActiveObject(id);
|
||||||
if(obj == NULL)
|
if (obj == NULL) {
|
||||||
{
|
|
||||||
infostream << "ClientEnvironment::processActiveObjectMessage():"
|
infostream << "ClientEnvironment::processActiveObjectMessage():"
|
||||||
<< " got message for id=" << id << ", which doesn't exist."
|
<< " got message for id=" << id << ", which doesn't exist."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
|
||||||
{
|
try {
|
||||||
obj->processMessage(data);
|
obj->processMessage(data);
|
||||||
}
|
} catch (SerializationError &e) {
|
||||||
catch(SerializationError &e)
|
|
||||||
{
|
|
||||||
errorstream<<"ClientEnvironment::processActiveObjectMessage():"
|
errorstream<<"ClientEnvironment::processActiveObjectMessage():"
|
||||||
<< " id=" << id << " type=" << obj->getType()
|
<< " id=" << id << " type=" << obj->getType()
|
||||||
<<" SerializationError in processMessage(),"
|
<< " SerializationError in processMessage(): " << e.what()
|
||||||
<<" message="<<serializeJsonString(data)
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,33 +449,23 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
|
||||||
string message
|
string message
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
char buf[6];
|
|
||||||
// Get all data except the command number
|
|
||||||
std::string datastring(pkt->getString(0), pkt->getSize());
|
std::string datastring(pkt->getString(0), pkt->getSize());
|
||||||
// Throw them in an istringstream
|
|
||||||
std::istringstream is(datastring, std::ios_base::binary);
|
std::istringstream is(datastring, std::ios_base::binary);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while(is.eof() == false) {
|
while (is.good()) {
|
||||||
is.read(buf, 2);
|
u16 id = readU16(is);
|
||||||
u16 id = readU16((u8*)buf);
|
if (!is.good())
|
||||||
if (is.eof())
|
|
||||||
break;
|
break;
|
||||||
is.read(buf, 2);
|
|
||||||
size_t message_size = readU16((u8*)buf);
|
std::string message = deSerializeString(is);
|
||||||
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
|
// Pass on to the environment
|
||||||
m_env.processActiveObjectMessage(id, message);
|
m_env.processActiveObjectMessage(id, message);
|
||||||
}
|
}
|
||||||
// Packet could be unreliable then ignore it
|
} catch (SerializationError &e) {
|
||||||
} catch (PacketError &e) {
|
errorstream << "Client::handleCommand_ActiveObjectMessages: "
|
||||||
infostream << "handleCommand_ActiveObjectMessages: " << e.what()
|
<< "caught SerializationError: " << e.what() << std::endl;
|
||||||
<< ". The packet is unreliable, ignoring" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue