Skip to content

Commit

Permalink
Add error messages and docs to explain restrictions when calling Netw…
Browse files Browse the repository at this point in the history
…orkedMultiplayerCustom.initialize()
  • Loading branch information
dsnopek committed Jul 29, 2022
1 parent 97d7c7c commit 5eaf83f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions core/io/networked_multiplayer_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion doc/classes/NetworkedMultiplayerCustom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
Expand Down

0 comments on commit 5eaf83f

Please sign in to comment.