Merge pull request #63637 from dsnopek/multiplayer-custom-more-docs-3.x

[3.x] Add error messages and docs to explain restrictions when calling NetworkedMultiplayerCustom.initialize()
This commit is contained in:
Rémi Verschelde 2022-07-29 22:38:19 +02:00 committed by GitHub
commit 5ea00ad3f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -139,9 +139,10 @@ NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerCustom::get_conne
//
void NetworkedMultiplayerCustom::initialize(int p_self_id) {
if (connection_status != ConnectionStatus::CONNECTION_CONNECTING) {
return;
}
ERR_FAIL_COND_MSG(connection_status != ConnectionStatus::CONNECTION_CONNECTING,
"Can only initialize if connection status is CONNECTION_CONNECTING.");
ERR_FAIL_COND_MSG(p_self_id < 0 || p_self_id > ~(1 << 31),
"Cannot initialize with invalid unique network id.");
self_id = p_self_id;
if (self_id == 1) {
@ -159,9 +160,9 @@ void NetworkedMultiplayerCustom::set_connection_status(NetworkedMultiplayerPeer:
}
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");
"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");
"Can only change connection status to CONNECTION_CONNECTED from CONNECTION_CONNECTING.");
if (p_connection_status == ConnectionStatus::CONNECTION_CONNECTED) {
connection_status = p_connection_status;

View file

@ -24,6 +24,7 @@
<argument index="0" name="self_peer_id" type="int" />
<description>
Initialize the peer with the given [code]peer_id[/code] (must be between 1 and 2147483647).
Can only be called if the connection status is [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTING]. See [method set_connection_status].
</description>
</method>
<method name="set_connection_status">
@ -32,7 +33,7 @@
<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].
You can only change to [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTING] from [constant NetworkedMultiplayerPeer.CONNECTION_DISCONNECTED] and to [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] from [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTING].
</description>
</method>
<method name="set_max_packet_size">