diff options
Diffstat (limited to 'modules/webrtc/webrtc_multiplayer_peer.cpp')
-rw-r--r-- | modules/webrtc/webrtc_multiplayer_peer.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 5ea81d5a1b..38c33a2dbc 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -42,7 +42,6 @@ void WebRTCMultiplayerPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("has_peer", "peer_id"), &WebRTCMultiplayerPeer::has_peer); ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebRTCMultiplayerPeer::get_peer); ClassDB::bind_method(D_METHOD("get_peers"), &WebRTCMultiplayerPeer::get_peers); - ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close); } void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) { @@ -342,16 +341,23 @@ void WebRTCMultiplayerPeer::remove_peer(int p_peer_id) { peer->connected = false; emit_signal(SNAME("peer_disconnected"), p_peer_id); if (network_mode == MODE_CLIENT && p_peer_id == TARGET_PEER_SERVER) { - if (connection_status == CONNECTION_CONNECTING) { - emit_signal(SNAME("connection_failed")); - } else { - emit_signal(SNAME("server_disconnected")); - } connection_status = CONNECTION_DISCONNECTED; } } } +void WebRTCMultiplayerPeer::disconnect_peer(int p_peer_id, bool p_force) { + ERR_FAIL_COND(!peer_map.has(p_peer_id)); + if (p_force) { + peer_map.erase(p_peer_id); + if (network_mode == MODE_CLIENT && p_peer_id == TARGET_PEER_SERVER) { + connection_status = CONNECTION_DISCONNECTED; + } + } else { + peer_map[p_peer_id]->connection->close(); // Will be removed during next poll. + } +} + Error WebRTCMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { // Peer not available if (next_packet_peer == 0 || !peer_map.has(next_packet_peer)) { |