diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-10-31 14:18:22 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-11-02 15:17:23 +0100 |
commit | 33dda2e68a40888a7fd41e9a8d421873d9dc7fde (patch) | |
tree | 513953b159b1c95c751b67d33c53aae6d2d57ca1 | |
parent | 9773803e4eb5f986750eb4daa726b25bb41e96e8 (diff) |
[MP] Remove connection state signals from MultiplayerPeer.
Now handled directly by the MultiplayerAPI implementation.
-rw-r--r-- | doc/classes/MultiplayerPeer.xml | 35 | ||||
-rw-r--r-- | modules/enet/enet_multiplayer_peer.cpp | 9 | ||||
-rw-r--r-- | modules/multiplayer/scene_multiplayer.cpp | 27 | ||||
-rw-r--r-- | modules/multiplayer/scene_multiplayer.h | 3 | ||||
-rw-r--r-- | modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml | 2 | ||||
-rw-r--r-- | modules/webrtc/webrtc_multiplayer_peer.cpp | 5 | ||||
-rw-r--r-- | modules/websocket/websocket_multiplayer_peer.cpp | 5 | ||||
-rw-r--r-- | scene/main/multiplayer_peer.cpp | 3 |
8 files changed, 21 insertions, 68 deletions
diff --git a/doc/classes/MultiplayerPeer.xml b/doc/classes/MultiplayerPeer.xml index 6661fbfe0b..dd7dac3f23 100644 --- a/doc/classes/MultiplayerPeer.xml +++ b/doc/classes/MultiplayerPeer.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="MultiplayerPeer" inherits="PacketPeer" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> - A high-level network interface to simplify multiplayer interactions. + Abstract class for specialized [PacketPeer]s used by the [MultiplayerAPI]. </brief_description> <description> - Manages the connection to multiplayer peers. Assigns unique IDs to each client connected to the server. See also [MultiplayerAPI]. - [b]Note:[/b] The high-level multiplayer API protocol is an implementation detail and isn't meant to be used by non-Godot servers. It may change without notice. + Manages the connection with one or more remote peers acting as server or client and assigning unique IDs to each of them. See also [MultiplayerAPI]. + [b]Note:[/b] The [MultiplayerAPI] protocol is an implementation detail and isn't meant to be used by non-Godot servers. It may change without notice. [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> @@ -97,49 +97,34 @@ </member> </members> <signals> - <signal name="connection_failed"> - <description> - Emitted when a connection attempt fails. - </description> - </signal> - <signal name="connection_succeeded"> - <description> - Emitted when a connection attempt succeeds. - </description> - </signal> <signal name="peer_connected"> <param index="0" name="id" type="int" /> <description> - Emitted by the server when a client connects. + Emitted when a remote peer connects. </description> </signal> <signal name="peer_disconnected"> <param index="0" name="id" type="int" /> <description> - Emitted by the server when a client disconnects. - </description> - </signal> - <signal name="server_disconnected"> - <description> - Emitted by clients when the server disconnects. + Emitted when a remote peer has disconnected. </description> </signal> </signals> <constants> <constant name="CONNECTION_DISCONNECTED" value="0" enum="ConnectionStatus"> - The ongoing connection disconnected. + The MultiplayerPeer is disconnected. </constant> <constant name="CONNECTION_CONNECTING" value="1" enum="ConnectionStatus"> - A connection attempt is ongoing. + The MultiplayerPeer is currently connecting to a server. </constant> <constant name="CONNECTION_CONNECTED" value="2" enum="ConnectionStatus"> - The connection attempt succeeded. + This MultiplayerPeer is connected. </constant> <constant name="TARGET_PEER_BROADCAST" value="0"> - Packets are sent to the server and then redistributed to other peers. + Packets are sent to all connected peers. </constant> <constant name="TARGET_PEER_SERVER" value="1"> - Packets are sent to the server alone. + Packets are sent to the remote peer acting as server. </constant> <constant name="TRANSFER_MODE_UNRELIABLE" value="0" enum="TransferMode"> Packets are not acknowledged, no resend attempts are made for lost packets. Packets may arrive in any order. Potentially faster than [constant TRANSFER_MODE_UNRELIABLE_ORDERED]. Use for non-critical data, and always consider whether the order matters. diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index 31ae643b59..43c512ae16 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -159,10 +159,7 @@ void ENetMultiplayerPeer::_disconnect_inactive_peers() { if (hosts.has(P)) { hosts.erase(P); } - if (active_mode == MODE_CLIENT) { - ERR_CONTINUE(P != TARGET_PEER_SERVER); - emit_signal(SNAME("server_disconnected")); - } + ERR_CONTINUE(active_mode == MODE_CLIENT && P != TARGET_PEER_SERVER); emit_signal(SNAME("peer_disconnected"), P); } } @@ -186,14 +183,10 @@ void ENetMultiplayerPeer::poll() { if (ret == ENetConnection::EVENT_CONNECT) { connection_status = CONNECTION_CONNECTED; emit_signal(SNAME("peer_connected"), 1); - emit_signal(SNAME("connection_succeeded")); } else if (ret == ENetConnection::EVENT_DISCONNECT) { if (connection_status == CONNECTION_CONNECTED) { // Client just disconnected from server. - emit_signal(SNAME("server_disconnected")); emit_signal(SNAME("peer_disconnected"), 1); - } else { - emit_signal(SNAME("connection_failed")); } close(); } else if (ret == ENetConnection::EVENT_RECEIVE) { diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp index 73c4346d93..db7c5037cd 100644 --- a/modules/multiplayer/scene_multiplayer.cpp +++ b/modules/multiplayer/scene_multiplayer.cpp @@ -55,6 +55,11 @@ void SceneMultiplayer::_update_status() { MultiplayerPeer::ConnectionStatus status = multiplayer_peer.is_valid() ? multiplayer_peer->get_connection_status() : MultiplayerPeer::CONNECTION_DISCONNECTED; if (last_connection_status != status) { if (status == MultiplayerPeer::CONNECTION_DISCONNECTED) { + if (last_connection_status == MultiplayerPeer::CONNECTION_CONNECTING) { + emit_signal(SNAME("connection_failed")); + } else { + emit_signal(SNAME("server_disconnected")); + } clear(); } last_connection_status = status; @@ -195,9 +200,6 @@ void SceneMultiplayer::set_multiplayer_peer(const Ref<MultiplayerPeer> &p_peer) if (multiplayer_peer.is_valid()) { multiplayer_peer->disconnect("peer_connected", callable_mp(this, &SceneMultiplayer::_add_peer)); multiplayer_peer->disconnect("peer_disconnected", callable_mp(this, &SceneMultiplayer::_del_peer)); - multiplayer_peer->disconnect("connection_succeeded", callable_mp(this, &SceneMultiplayer::_connected_to_server)); - multiplayer_peer->disconnect("connection_failed", callable_mp(this, &SceneMultiplayer::_connection_failed)); - multiplayer_peer->disconnect("server_disconnected", callable_mp(this, &SceneMultiplayer::_server_disconnected)); clear(); } @@ -206,9 +208,6 @@ void SceneMultiplayer::set_multiplayer_peer(const Ref<MultiplayerPeer> &p_peer) if (multiplayer_peer.is_valid()) { multiplayer_peer->connect("peer_connected", callable_mp(this, &SceneMultiplayer::_add_peer)); multiplayer_peer->connect("peer_disconnected", callable_mp(this, &SceneMultiplayer::_del_peer)); - multiplayer_peer->connect("connection_succeeded", callable_mp(this, &SceneMultiplayer::_connected_to_server)); - multiplayer_peer->connect("connection_failed", callable_mp(this, &SceneMultiplayer::_connection_failed)); - multiplayer_peer->connect("server_disconnected", callable_mp(this, &SceneMultiplayer::_server_disconnected)); } _update_status(); } @@ -385,6 +384,9 @@ void SceneMultiplayer::_admit_peer(int p_id) { connected_peers.insert(p_id); cache->on_peer_change(p_id, true); replicator->on_peer_change(p_id, true); + if (p_id == 1) { + emit_signal(SNAME("connected_to_server")); + } emit_signal(SNAME("peer_connected"), p_id); } @@ -430,19 +432,6 @@ void SceneMultiplayer::disconnect_peer(int p_id) { multiplayer_peer->disconnect_peer(p_id); } -void SceneMultiplayer::_connected_to_server() { - emit_signal(SNAME("connected_to_server")); -} - -void SceneMultiplayer::_connection_failed() { - emit_signal(SNAME("connection_failed")); -} - -void SceneMultiplayer::_server_disconnected() { - replicator->on_reset(); - emit_signal(SNAME("server_disconnected")); -} - Error SceneMultiplayer::send_bytes(Vector<uint8_t> p_data, int p_to, MultiplayerPeer::TransferMode p_mode, int p_channel) { ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet."); ERR_FAIL_COND_V_MSG(!multiplayer_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no multiplayer peer is active."); diff --git a/modules/multiplayer/scene_multiplayer.h b/modules/multiplayer/scene_multiplayer.h index a8e182db92..b0ecc48f8c 100644 --- a/modules/multiplayer/scene_multiplayer.h +++ b/modules/multiplayer/scene_multiplayer.h @@ -113,9 +113,6 @@ protected: void _add_peer(int p_id); void _admit_peer(int p_id); void _del_peer(int p_id); - void _connected_to_server(); - void _connection_failed(); - void _server_disconnected(); void _update_status(); public: diff --git a/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml index 91ee65e9bd..5266a36637 100644 --- a/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml +++ b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml @@ -6,7 +6,7 @@ <description> This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.multiplayer_peer]. You can add each [WebRTCPeerConnection] via [method add_peer] or remove them via [method remove_peer]. Peers must be added in [constant WebRTCPeerConnection.STATE_NEW] state to allow it to create the appropriate channels. This class will not create offers nor set descriptions, it will only poll them, and notify connections and disconnections. - [signal MultiplayerPeer.connection_succeeded] and [signal MultiplayerPeer.server_disconnected] will not be emitted unless the peer is created using [method create_client]. Beside that data transfer works like in a [MultiplayerPeer]. + When creating the peer via [method create_client] or [method create_server] the [method MultiplayerPeer.is_server_relay_supported] method will return [code]true[/code] enabling peer exchange and packet relaying when supported by the [MultiplayerAPI] implementation. [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 163b17fa6f..38c33a2dbc 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -341,11 +341,6 @@ 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; } } diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 827c618e4e..14f9c0ba4d 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -264,9 +264,7 @@ void WebSocketMultiplayerPeer::_poll_client() { } } else if (peer->get_ready_state() == WebSocketPeer::STATE_CLOSED) { if (connection_status == CONNECTION_CONNECTED) { - emit_signal(SNAME("server_disconnected")); - } else { - emit_signal(SNAME("connection_failed")); + emit_signal(SNAME("peer_disconnected"), 1); } _clear(); return; @@ -276,7 +274,6 @@ void WebSocketMultiplayerPeer::_poll_client() { ERR_FAIL_COND(!pending_peers.has(1)); // Bug. if (OS::get_singleton()->get_ticks_msec() - pending_peers[1].time > handshake_timeout) { print_verbose(vformat("WebSocket handshake timed out after %.3f seconds.", handshake_timeout * 0.001)); - emit_signal(SNAME("connection_failed")); _clear(); return; } diff --git a/scene/main/multiplayer_peer.cpp b/scene/main/multiplayer_peer.cpp index b4e5b11abd..92ba3debd1 100644 --- a/scene/main/multiplayer_peer.cpp +++ b/scene/main/multiplayer_peer.cpp @@ -123,9 +123,6 @@ void MultiplayerPeer::_bind_methods() { ADD_SIGNAL(MethodInfo("peer_connected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("peer_disconnected", PropertyInfo(Variant::INT, "id"))); - ADD_SIGNAL(MethodInfo("server_disconnected")); - ADD_SIGNAL(MethodInfo("connection_succeeded")); - ADD_SIGNAL(MethodInfo("connection_failed")); } /*************/ |