File tree 2 files changed +21
-36
lines changed
2 files changed +21
-36
lines changed Original file line number Diff line number Diff line change @@ -2535,28 +2535,23 @@ void ClientEnvironment::removeActiveObject(u16 id)
2535
2535
m_active_objects.erase (id);
2536
2536
}
2537
2537
2538
- void ClientEnvironment::processActiveObjectMessage (u16 id,
2539
- const std::string &data)
2538
+ void ClientEnvironment::processActiveObjectMessage (u16 id, const std::string &data)
2540
2539
{
2541
- ClientActiveObject* obj = getActiveObject (id);
2542
- if (obj == NULL )
2543
- {
2544
- infostream<<" ClientEnvironment::processActiveObjectMessage():"
2545
- <<" got message for id=" <<id<<" , which doesn't exist."
2546
- <<std::endl;
2540
+ ClientActiveObject *obj = getActiveObject (id);
2541
+ if (obj == NULL ) {
2542
+ infostream << " ClientEnvironment::processActiveObjectMessage():"
2543
+ << " got message for id=" << id << " , which doesn't exist."
2544
+ << std::endl;
2547
2545
return ;
2548
2546
}
2549
- try
2550
- {
2547
+
2548
+ try {
2551
2549
obj->processMessage (data);
2552
- }
2553
- catch (SerializationError &e)
2554
- {
2550
+ } catch (SerializationError &e) {
2555
2551
errorstream<<" ClientEnvironment::processActiveObjectMessage():"
2556
- <<" id=" <<id<<" type=" <<obj->getType ()
2557
- <<" SerializationError in processMessage(),"
2558
- <<" message=" <<serializeJsonString (data)
2559
- <<std::endl;
2552
+ << " id=" << id << " type=" << obj->getType ()
2553
+ << " SerializationError in processMessage(): " << e.what ()
2554
+ << std::endl;
2560
2555
}
2561
2556
}
2562
2557
Original file line number Diff line number Diff line change @@ -449,33 +449,23 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
449
449
string message
450
450
}
451
451
*/
452
- char buf[6 ];
453
- // Get all data except the command number
454
452
std::string datastring (pkt->getString (0 ), pkt->getSize ());
455
- // Throw them in an istringstream
456
453
std::istringstream is (datastring, std::ios_base::binary);
457
454
458
455
try {
459
- while (is.eof () == false ) {
460
- is.read (buf, 2 );
461
- u16 id = readU16 ((u8*)buf);
462
- if (is.eof ())
456
+ while (is.good ()) {
457
+ u16 id = readU16 (is);
458
+ if (!is.good ())
463
459
break ;
464
- is.read (buf, 2 );
465
- size_t message_size = readU16 ((u8*)buf);
466
- std::string message;
467
- message.reserve (message_size);
468
- for (u32 i = 0 ; i < message_size; i++) {
469
- is.read (buf, 1 );
470
- message.append (buf, 1 );
471
- }
460
+
461
+ std::string message = deSerializeString (is);
462
+
472
463
// Pass on to the environment
473
464
m_env.processActiveObjectMessage (id, message);
474
465
}
475
- // Packet could be unreliable then ignore it
476
- } catch (PacketError &e) {
477
- infostream << " handleCommand_ActiveObjectMessages: " << e.what ()
478
- << " . The packet is unreliable, ignoring" << std::endl;
466
+ } catch (SerializationError &e) {
467
+ errorstream << " Client::handleCommand_ActiveObjectMessages: "
468
+ << " caught SerializationError: " << e.what () << std::endl;
479
469
}
480
470
}
481
471
You can’t perform that action at this time.
0 commit comments