forked from Mirrorlandia_minetest/minetest
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
This commit is contained in:
parent
ed3ebd633d
commit
8804c47e59
@ -377,7 +377,6 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
|
|||||||
void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
|
void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
u16 command
|
|
||||||
for all objects
|
for all objects
|
||||||
{
|
{
|
||||||
u16 id
|
u16 id
|
||||||
@ -391,21 +390,27 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt)
|
|||||||
// Throw them in an istringstream
|
// Throw them in an istringstream
|
||||||
std::istringstream is(datastring, std::ios_base::binary);
|
std::istringstream is(datastring, std::ios_base::binary);
|
||||||
|
|
||||||
while(is.eof() == false) {
|
try {
|
||||||
is.read(buf, 2);
|
while(is.eof() == false) {
|
||||||
u16 id = readU16((u8*)buf);
|
is.read(buf, 2);
|
||||||
if (is.eof())
|
u16 id = readU16((u8*)buf);
|
||||||
break;
|
if (is.eof())
|
||||||
is.read(buf, 2);
|
break;
|
||||||
size_t message_size = readU16((u8*)buf);
|
is.read(buf, 2);
|
||||||
std::string message;
|
size_t message_size = readU16((u8*)buf);
|
||||||
message.reserve(message_size);
|
std::string message;
|
||||||
for (u32 i = 0; i < message_size; i++) {
|
message.reserve(message_size);
|
||||||
is.read(buf, 1);
|
for (u32 i = 0; i < message_size; i++) {
|
||||||
message.append(buf, 1);
|
is.read(buf, 1);
|
||||||
|
message.append(buf, 1);
|
||||||
|
}
|
||||||
|
// Pass on to the environment
|
||||||
|
m_env.processActiveObjectMessage(id, message);
|
||||||
}
|
}
|
||||||
// Pass on to the environment
|
// Packet could be unreliable then ignore it
|
||||||
m_env.processActiveObjectMessage(id, message);
|
} catch (PacketError &e) {
|
||||||
|
infostream << "handleCommand_ActiveObjectMessages: " << e.what()
|
||||||
|
<< ". The packet is unreliable, ignoring" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1897,7 +1897,7 @@ void Server::SendPlayerInventoryFormspec(u16 peer_id)
|
|||||||
|
|
||||||
u32 Server::SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas)
|
u32 Server::SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas)
|
||||||
{
|
{
|
||||||
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, 0, peer_id);
|
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, datas.size(), peer_id);
|
||||||
pkt.putRawString(datas.c_str(), datas.size());
|
pkt.putRawString(datas.c_str(), datas.size());
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
return pkt.getSize();
|
return pkt.getSize();
|
||||||
@ -1906,7 +1906,7 @@ u32 Server::SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas)
|
|||||||
void Server::SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable)
|
void Server::SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable)
|
||||||
{
|
{
|
||||||
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
|
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
|
||||||
0, peer_id);
|
datas.size(), peer_id);
|
||||||
|
|
||||||
pkt.putRawString(datas.c_str(), datas.size());
|
pkt.putRawString(datas.c_str(), datas.size());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user