From 397d895fb76d37881933c6e42b6256847ef6f2e6 Mon Sep 17 00:00:00 2001 From: Jordan Schidlowsky Date: Mon, 27 Sep 2021 10:09:32 +0200 Subject: [Net] ENetMultiplayerPeer now sends fragmented packets unreliably too. It used to always send them reliably when transfer mode was unreliable or ordered if the packet size was more then the enet host MTU (1400 bytes by default). This commit also adds a warning when debug is enabled to explain the effects of sending fragmented packets unreliably. --- modules/enet/enet_multiplayer_peer.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules/enet') diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index 2cfae60ad2..5c0a2286d2 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -441,11 +441,11 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size } else { switch (get_transfer_mode()) { case Multiplayer::TRANSFER_MODE_UNRELIABLE: { - packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; + packet_flags = ENET_PACKET_FLAG_UNSEQUENCED | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT; channel = SYSCH_UNRELIABLE; } break; case Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED: { - packet_flags = 0; + packet_flags = ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT; channel = SYSCH_UNRELIABLE; } break; case Multiplayer::TRANSFER_MODE_RELIABLE: { @@ -455,6 +455,12 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size } } +#ifdef DEBUG_ENABLED + if ((packet_flags & ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT) && p_buffer_size + 8 > ENET_HOST_DEFAULT_MTU) { + WARN_PRINT_ONCE(vformat("Sending %d bytes unrealiably which is above the MTU (%d), this will result in higher packet loss", p_buffer_size + 8, ENET_HOST_DEFAULT_MTU)); + } +#endif + ENetPacket *packet = enet_packet_create(nullptr, p_buffer_size + 8, packet_flags); encode_uint32(unique_id, &packet->data[0]); // Source ID encode_uint32(target_peer, &packet->data[4]); // Dest ID -- cgit v1.2.3