diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-11-01 20:35:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-01 20:35:04 +0100 |
commit | 0a0e99cadc6e250ff2ee27ef31760eb9c2e21040 (patch) | |
tree | f790d365bebbfad3c39b96c7b879c9cd6f6506f2 /modules/websocket/websocket_multiplayer_peer.cpp | |
parent | e6751549cf7247965d1744b8c464f5e901006f21 (diff) | |
parent | 39f3d9d59e80d5a9f62925abca596d87ce1e4d0f (diff) |
Merge pull request #67982 from Faless/mp/4.x_disconnect_close
[MP] Add MultiplayerPeer disconnect_peer, close.
Diffstat (limited to 'modules/websocket/websocket_multiplayer_peer.cpp')
-rw-r--r-- | modules/websocket/websocket_multiplayer_peer.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 0202c5bac7..827c618e4e 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -75,12 +75,10 @@ void WebSocketMultiplayerPeer::_clear() { void WebSocketMultiplayerPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("create_client", "url", "verify_tls", "tls_certificate"), &WebSocketMultiplayerPeer::create_client, DEFVAL(true), DEFVAL(Ref<X509Certificate>())); ClassDB::bind_method(D_METHOD("create_server", "port", "bind_address", "tls_key", "tls_certificate"), &WebSocketMultiplayerPeer::create_server, DEFVAL("*"), DEFVAL(Ref<CryptoKey>()), DEFVAL(Ref<X509Certificate>())); - ClassDB::bind_method(D_METHOD("close"), &WebSocketMultiplayerPeer::close); ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebSocketMultiplayerPeer::get_peer); ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &WebSocketMultiplayerPeer::get_peer_address); ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &WebSocketMultiplayerPeer::get_peer_port); - ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "code", "reason"), &WebSocketMultiplayerPeer::disconnect_peer, DEFVAL(1000), DEFVAL("")); ClassDB::bind_method(D_METHOD("get_supported_protocols"), &WebSocketMultiplayerPeer::get_supported_protocols); ClassDB::bind_method(D_METHOD("set_supported_protocols", "protocols"), &WebSocketMultiplayerPeer::set_supported_protocols); @@ -488,9 +486,15 @@ int WebSocketMultiplayerPeer::get_peer_port(int p_peer_id) const { return peers_map[p_peer_id]->get_connected_port(); } -void WebSocketMultiplayerPeer::disconnect_peer(int p_peer_id, int p_code, String p_reason) { +void WebSocketMultiplayerPeer::disconnect_peer(int p_peer_id, bool p_force) { ERR_FAIL_COND(!peers_map.has(p_peer_id)); - peers_map[p_peer_id]->close(p_code, p_reason); + peers_map[p_peer_id]->close(); + if (p_force) { + peers_map.erase(p_peer_id); + if (!is_server()) { + _clear(); + } + } } void WebSocketMultiplayerPeer::close() { |