Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Add error messages and docs to explain allowed transitions in NetworkedMultiplayerCustom.set_connection_status() #63628

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions core/io/networked_multiplayer_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ void NetworkedMultiplayerCustom::set_max_packet_size(int p_max_packet_size) {
}

void NetworkedMultiplayerCustom::set_connection_status(NetworkedMultiplayerPeer::ConnectionStatus p_connection_status) {
// Can only go to connecting, if we are disconnected.
if (p_connection_status == ConnectionStatus::CONNECTION_CONNECTING && connection_status == ConnectionStatus::CONNECTION_DISCONNECTED) {
connection_status = p_connection_status;
if (connection_status == p_connection_status) {
return;
}
// Can only go to connected, if we are connecting.
else if (p_connection_status == ConnectionStatus::CONNECTION_CONNECTED && connection_status == ConnectionStatus::CONNECTION_CONNECTING) {

ERR_FAIL_COND_MSG(p_connection_status == ConnectionStatus::CONNECTION_CONNECTING && connection_status != ConnectionStatus::CONNECTION_DISCONNECTED,
"Can only change connection status to CONNECTION_CONNECTING from CONNECTION_DISCONNECTED");
ERR_FAIL_COND_MSG(p_connection_status == ConnectionStatus::CONNECTION_CONNECTED && connection_status != ConnectionStatus::CONNECTION_CONNECTING,
"Can only change connection status to CONNECTION_CONNECTED from CONNECTION_CONNECTING");

if (p_connection_status == ConnectionStatus::CONNECTION_CONNECTED) {
connection_status = p_connection_status;
emit_signal("connection_succeeded");
}
// Can only go to disconnected, if we aren't already disconnected.
else if (p_connection_status == ConnectionStatus::CONNECTION_DISCONNECTED && connection_status != ConnectionStatus::CONNECTION_DISCONNECTED) {
} else if (p_connection_status == ConnectionStatus::CONNECTION_DISCONNECTED) {
ConnectionStatus old_connection_status = connection_status;
connection_status = p_connection_status;

Expand All @@ -175,6 +177,8 @@ void NetworkedMultiplayerCustom::set_connection_status(NetworkedMultiplayerPeer:
emit_signal("server_disconnected");
}
}
} else {
connection_status = p_connection_status;
}
}

Expand Down
2 changes: 2 additions & 0 deletions doc/classes/NetworkedMultiplayerCustom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<argument index="0" name="connection_status" type="int" enum="NetworkedMultiplayerPeer.ConnectionStatus" />
<description>
Set the state of the connection. See [enum NetworkedMultiplayerPeer.ConnectionStatus].
This will emit the [signal NetworkedMultiplayerPeer.connection_succeeded], [signal NetworkedMultiplayerPeer.connection_failed] or [signal NetworkedMultiplayerPeer.server_disconnected] signals depending on the status and if the peer has the unique network id of [code]1[/code].
You can only change to [code]CONNECTION_CONNECTING[/code] from [code]CONNECTION_DISCONNECTED[/code] and to [code]CONNECTION_CONNECTED[/code] from [code]CONNECTION_CONNECTING[/code].
</description>
</method>
<method name="set_max_packet_size">
Expand Down