mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
[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`.
(cherry picked from commit 9b8db7c63a
)
This commit is contained in:
parent
b8c1453f49
commit
1d9993936c
1 changed files with 11 additions and 0 deletions
|
@ -154,6 +154,10 @@ void WebRTCMultiplayer::_find_next_peer() {
|
||||||
}
|
}
|
||||||
// After last.
|
// After last.
|
||||||
while (E) {
|
while (E) {
|
||||||
|
if (!E->get()->connected) {
|
||||||
|
E = E->next();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
|
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
|
||||||
if (F->get()->get_available_packet_count()) {
|
if (F->get()->get_available_packet_count()) {
|
||||||
next_packet_peer = E->key();
|
next_packet_peer = E->key();
|
||||||
|
@ -165,6 +169,10 @@ void WebRTCMultiplayer::_find_next_peer() {
|
||||||
E = peer_map.front();
|
E = peer_map.front();
|
||||||
// Before last
|
// Before last
|
||||||
while (E) {
|
while (E) {
|
||||||
|
if (!E->get()->connected) {
|
||||||
|
E = E->next();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
|
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
|
||||||
if (F->get()->get_available_packet_count()) {
|
if (F->get()->get_available_packet_count()) {
|
||||||
next_packet_peer = E->key();
|
next_packet_peer = E->key();
|
||||||
|
@ -357,6 +365,9 @@ int WebRTCMultiplayer::get_available_packet_count() const {
|
||||||
}
|
}
|
||||||
int size = 0;
|
int size = 0;
|
||||||
for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) {
|
for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) {
|
||||||
|
if (!E->get()->connected) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
|
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
|
||||||
size += F->get()->get_available_packet_count();
|
size += F->get()->get_available_packet_count();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue