Send initial dummy packet as empty

No functional change and no compatibility implicatons
but this better matches what is documented everywhere.
This commit is contained in:
sfan5 2024-01-05 11:13:43 +01:00
parent eeb873b23c
commit abf3142b26
2 changed files with 10 additions and 4 deletions

@ -552,6 +552,12 @@ NetworkPacket& NetworkPacket::operator<<(video::SColor src)
Buffer<u8> NetworkPacket::oldForgePacket() Buffer<u8> NetworkPacket::oldForgePacket()
{ {
// this is the dummy packet used to first contact the server
if (m_command == 0) {
assert(m_datasize == 0);
return Buffer<u8>();
}
Buffer<u8> sb(m_datasize + 2); Buffer<u8> sb(m_datasize + 2);
writeU16(&sb[0], m_command); writeU16(&sb[0], m_command);
if (m_datasize > 0) if (m_datasize > 0)

@ -277,8 +277,8 @@ void TestConnection::testConnectSendReceive()
Simple send-receive test Simple send-receive test
*/ */
{ {
NetworkPacket pkt; NetworkPacket pkt(0x4b, 0);
pkt.putRawPacket((u8*) "Hello World !", 14, 0); pkt.putRawString("Hello World !", 14);
auto sentdata = pkt.oldForgePacket(); auto sentdata = pkt.oldForgePacket();
@ -306,9 +306,9 @@ void TestConnection::testConnectSendReceive()
*/ */
{ {
const int datasize = 30000; const int datasize = 30000;
NetworkPacket pkt(0, datasize); NetworkPacket pkt(0xff, datasize);
for (u16 i=0; i<datasize; i++) { for (u16 i=0; i<datasize; i++) {
pkt << (u8) i/4; pkt << static_cast<u8>(i/4);
} }
infostream << "Sending data (size=" << datasize << "):"; infostream << "Sending data (size=" << datasize << "):";