Add size header to information packet (#409)

By creating this pull request, I understand that code that is AI
generated or otherwise automatically generated may be rejected without
further discussion.
I declare that I fully understand all code I pushed into this PR, and
wrote all this code myself and own the rights to this code.
This commit is contained in:
Tixx 2025-01-18 20:52:20 +01:00 committed by GitHub
commit c78775bfd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -258,8 +258,16 @@ void TNetwork::Identify(TConnection&& RawConnection) {
write(RawConnection.Socket, buffer("P"), ec); write(RawConnection.Socket, buffer("P"), ec);
return; return;
} else if (Code == 'I') { } else if (Code == 'I') {
const std::string Data = Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? THeartbeatThread::lastCall : "";
const auto Size = static_cast<int32_t>(Data.size());
std::vector<uint8_t> ToSend;
ToSend.resize(Data.size() + sizeof(Size));
std::memcpy(ToSend.data(), &Size, sizeof(Size));
std::memcpy(ToSend.data() + sizeof(Size), Data.data(), Data.size());
boost::system::error_code ec; boost::system::error_code ec;
write(RawConnection.Socket, buffer(Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? THeartbeatThread::lastCall : ""), ec); write(RawConnection.Socket, buffer(ToSend), ec);
} else { } else {
beammp_errorf("Invalid code got in Identify: '{}'", Code); beammp_errorf("Invalid code got in Identify: '{}'", Code);
} }