1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

[MP] Add MultiplayerPeer disconnect_peer, close.

Update ENet, WebRTC, and WebSocket to support peer disconnection and
unify the close function.
This commit is contained in:
Fabio Alessandrelli
2022-10-22 17:49:40 +02:00
parent 028db9f2b5
commit 39f3d9d59e
13 changed files with 188 additions and 201 deletions

View File

@@ -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) {
@@ -352,6 +351,18 @@ void WebRTCMultiplayerPeer::remove_peer(int p_peer_id) {
}
}
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)) {