diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-21 15:22:46 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-21 15:22:46 +0100 |
commit | 48a1a78390049ee77b4feb6e4bbb520d5cb1ce83 (patch) | |
tree | 1d34e14c9b33690303e9c0794c2d2df6ab9b0541 | |
parent | 14a05f0e84c10dc4f16a6f4e5024d712e15af849 (diff) | |
parent | 754036f82f8c404972480c18d81130945fcbb3d9 (diff) | |
download | redot-engine-48a1a78390049ee77b4feb6e4bbb520d5cb1ce83.tar.gz |
Merge pull request #86260 from Faless/mp/fix_2way_auth
[MP] Fix auth not waiting for confirmation in some cases
-rw-r--r-- | modules/multiplayer/scene_multiplayer.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp index 5655467df7..6f7a3493a1 100644 --- a/modules/multiplayer/scene_multiplayer.cpp +++ b/modules/multiplayer/scene_multiplayer.cpp @@ -96,35 +96,29 @@ Error SceneMultiplayer::poll() { #endif if (pending_peers.has(sender)) { - if (pending_peers[sender].local) { - // If the auth is over, admit the peer at the first packet. - pending_peers.erase(sender); - _admit_peer(sender); + ERR_CONTINUE(len < 2 || (packet[0] & CMD_MASK) != NETWORK_COMMAND_SYS || packet[1] != SYS_COMMAND_AUTH); + // Auth message. + PackedByteArray pba; + pba.resize(len - 2); + if (pba.size()) { + memcpy(pba.ptrw(), &packet[2], len - 2); + // User callback + const Variant sv = sender; + const Variant pbav = pba; + const Variant *argv[2] = { &sv, &pbav }; + Variant ret; + Callable::CallError ce; + auth_callback.callp(argv, 2, ret, ce); + ERR_CONTINUE_MSG(ce.error != Callable::CallError::CALL_OK, "Failed to call authentication callback"); } else { - ERR_CONTINUE(len < 2 || (packet[0] & CMD_MASK) != NETWORK_COMMAND_SYS || packet[1] != SYS_COMMAND_AUTH); - // Auth message. - PackedByteArray pba; - pba.resize(len - 2); - if (pba.size()) { - memcpy(pba.ptrw(), &packet[2], len - 2); - // User callback - const Variant sv = sender; - const Variant pbav = pba; - const Variant *argv[2] = { &sv, &pbav }; - Variant ret; - Callable::CallError ce; - auth_callback.callp(argv, 2, ret, ce); - ERR_CONTINUE_MSG(ce.error != Callable::CallError::CALL_OK, "Failed to call authentication callback"); - } else { - // Remote complete notification. - pending_peers[sender].remote = true; - if (pending_peers[sender].local) { - pending_peers.erase(sender); - _admit_peer(sender); - } + // Remote complete notification. + pending_peers[sender].remote = true; + if (pending_peers[sender].local) { + pending_peers.erase(sender); + _admit_peer(sender); } - continue; // Auth in progress. } + continue; // Auth in progress. } ERR_CONTINUE(!connected_peers.has(sender)); |