diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-12-15 10:58:48 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-12-15 11:07:46 +0100 |
commit | 84112d96103073578820e045bb0017a25488ab93 (patch) | |
tree | 7de8230ef854cc1fe64d0b1d739065b491c7943a /modules/webrtc/webrtc_multiplayer_peer.cpp | |
parent | 1930fc8b3150e3084c16557d82dc2c517e3f292b (diff) |
[Net] Fix WebRTC returning packets from peers too early.
Due to the async nature of WebRTC implementations, the multiplayer peer
could end up having queued packets from a given connection before it is
able to emit the "peer_added" signal.
This commit ensures that packets from peers which are not notified yet
are skipped by `get_packet` and `get_available_packet_count`.
Diffstat (limited to 'modules/webrtc/webrtc_multiplayer_peer.cpp')
-rw-r--r-- | modules/webrtc/webrtc_multiplayer_peer.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 133bd71ddb..20fe63bf7d 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -146,6 +146,10 @@ void WebRTCMultiplayerPeer::_find_next_peer() { } // After last. while (E) { + if (!E->get()->connected) { + E = E->next(); + continue; + } for (const Ref<WebRTCDataChannel> &F : E->get()->channels) { if (F->get_available_packet_count()) { next_packet_peer = E->key(); @@ -157,6 +161,10 @@ void WebRTCMultiplayerPeer::_find_next_peer() { E = peer_map.front(); // Before last while (E) { + if (!E->get()->connected) { + E = E->next(); + continue; + } for (const Ref<WebRTCDataChannel> &F : E->get()->channels) { if (F->get_available_packet_count()) { next_packet_peer = E->key(); @@ -378,6 +386,9 @@ int WebRTCMultiplayerPeer::get_available_packet_count() const { } int size = 0; for (const KeyValue<int, Ref<ConnectedPeer>> &E : peer_map) { + if (!E.value->connected) { + continue; + } for (const Ref<WebRTCDataChannel> &F : E.value->channels) { size += F->get_available_packet_count(); } |