[MP] Remove connection state signals from MultiplayerPeer.
Now handled directly by the MultiplayerAPI implementation.
This commit is contained in:
parent
9773803e4e
commit
33dda2e68a
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
/*************/
|
||||
|
|
Loading…
Reference in New Issue