summaryrefslogtreecommitdiff
path: root/core/io/multiplayer_api.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-10-25 18:00:49 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-10-25 18:03:58 +0200
commit198af06ff69fb199ab2c865fea304848777a0498 (patch)
treec31b49206159faa6a531c7606b9fd35e2fccdc4b /core/io/multiplayer_api.cpp
parent6ce35e176fdb31a6ff5c570bf72a53bdde343c5d (diff)
MultiplayerAPI cleanup cache when peer disconnects
We used to only cleanup path_get_cache and not path_send_cache causing issues when a peer disconnects and then reconnects with the same ID.
Diffstat (limited to 'core/io/multiplayer_api.cpp')
-rw-r--r--core/io/multiplayer_api.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 0ba84d0c8f..1426dbbd4d 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -602,7 +602,16 @@ void MultiplayerAPI::_add_peer(int p_id) {
void MultiplayerAPI::_del_peer(int p_id) {
connected_peers.erase(p_id);
- path_get_cache.erase(p_id); // I no longer need your cache, sorry.
+ // Cleanup get cache.
+ path_get_cache.erase(p_id);
+ // Cleanup sent cache.
+ // Some refactoring is needed to make this faster and do paths GC.
+ List<NodePath> keys;
+ path_send_cache.get_key_list(&keys);
+ for (List<NodePath>::Element *E = keys.front(); E; E = E->next()) {
+ PathSentCache *psc = path_send_cache.getptr(E->get());
+ psc->confirmed_peers.erase(p_id);
+ }
emit_signal("network_peer_disconnected", p_id);
}