class_scenemultiplayer.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/modules/multiplayer/doc_classes/SceneMultiplayer.xml.
  6. .. _class_SceneMultiplayer:
  7. SceneMultiplayer
  8. ================
  9. **Inherits:** :ref:`MultiplayerAPI<class_MultiplayerAPI>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. High-level multiplayer API implementation.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This class is the default implementation of :ref:`MultiplayerAPI<class_MultiplayerAPI>`, used to provide multiplayer functionalities in Godot Engine.
  15. This implementation supports RPCs via :ref:`Node.rpc<class_Node_method_rpc>` and :ref:`Node.rpc_id<class_Node_method_rpc_id>` and requires :ref:`MultiplayerAPI.rpc<class_MultiplayerAPI_method_rpc>` to be passed a :ref:`Node<class_Node>` (it will fail for other object types).
  16. This implementation additionally provide :ref:`SceneTree<class_SceneTree>` replication via the :ref:`MultiplayerSpawner<class_MultiplayerSpawner>` and :ref:`MultiplayerSynchronizer<class_MultiplayerSynchronizer>` nodes, and the :ref:`SceneReplicationConfig<class_SceneReplicationConfig>` resource.
  17. \ **Note:** 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.
  18. \ **Note:** When exporting to Android, make sure to enable the ``INTERNET`` 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.
  19. .. rst-class:: classref-reftable-group
  20. Properties
  21. ----------
  22. .. table::
  23. :widths: auto
  24. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  25. | :ref:`bool<class_bool>` | :ref:`allow_object_decoding<class_SceneMultiplayer_property_allow_object_decoding>` | ``false`` |
  26. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  27. | :ref:`Callable<class_Callable>` | :ref:`auth_callback<class_SceneMultiplayer_property_auth_callback>` | |
  28. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  29. | :ref:`float<class_float>` | :ref:`auth_timeout<class_SceneMultiplayer_property_auth_timeout>` | ``3.0`` |
  30. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  31. | :ref:`bool<class_bool>` | :ref:`refuse_new_connections<class_SceneMultiplayer_property_refuse_new_connections>` | ``false`` |
  32. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  33. | :ref:`NodePath<class_NodePath>` | :ref:`root_path<class_SceneMultiplayer_property_root_path>` | ``NodePath("")`` |
  34. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  35. | :ref:`bool<class_bool>` | :ref:`server_relay<class_SceneMultiplayer_property_server_relay>` | ``true`` |
  36. +---------------------------------+---------------------------------------------------------------------------------------+------------------+
  37. .. rst-class:: classref-reftable-group
  38. Methods
  39. -------
  40. .. table::
  41. :widths: auto
  42. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`clear<class_SceneMultiplayer_method_clear>` **(** **)** |
  44. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`complete_auth<class_SceneMultiplayer_method_complete_auth>` **(** :ref:`int<class_int>` id **)** |
  46. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`disconnect_peer<class_SceneMultiplayer_method_disconnect_peer>` **(** :ref:`int<class_int>` id **)** |
  48. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_authenticating_peers<class_SceneMultiplayer_method_get_authenticating_peers>` **(** **)** |
  50. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_auth<class_SceneMultiplayer_method_send_auth>` **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
  52. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send_bytes<class_SceneMultiplayer_method_send_bytes>` **(** :ref:`PackedByteArray<class_PackedByteArray>` bytes, :ref:`int<class_int>` id=0, :ref:`TransferMode<enum_MultiplayerPeer_TransferMode>` mode=2, :ref:`int<class_int>` channel=0 **)** |
  54. +-------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-section-separator
  56. ----
  57. .. rst-class:: classref-descriptions-group
  58. Signals
  59. -------
  60. .. _class_SceneMultiplayer_signal_peer_authenticating:
  61. .. rst-class:: classref-signal
  62. **peer_authenticating** **(** :ref:`int<class_int>` id **)**
  63. Emitted when this MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` connects to a new peer and a valid :ref:`auth_callback<class_SceneMultiplayer_property_auth_callback>` is set. In this case, the :ref:`MultiplayerAPI.peer_connected<class_MultiplayerAPI_signal_peer_connected>` will not be emitted until :ref:`complete_auth<class_SceneMultiplayer_method_complete_auth>` is called with given peer ``id``. While in this state, the peer will not be included in the list returned by :ref:`MultiplayerAPI.get_peers<class_MultiplayerAPI_method_get_peers>` (but in the one returned by :ref:`get_authenticating_peers<class_SceneMultiplayer_method_get_authenticating_peers>`), and only authentication data will be sent or received. See :ref:`send_auth<class_SceneMultiplayer_method_send_auth>` for sending authentication data.
  64. .. rst-class:: classref-item-separator
  65. ----
  66. .. _class_SceneMultiplayer_signal_peer_authentication_failed:
  67. .. rst-class:: classref-signal
  68. **peer_authentication_failed** **(** :ref:`int<class_int>` id **)**
  69. Emitted when this MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` disconnects from a peer for which authentication had not yet completed. See :ref:`peer_authenticating<class_SceneMultiplayer_signal_peer_authenticating>`.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_SceneMultiplayer_signal_peer_packet:
  73. .. rst-class:: classref-signal
  74. **peer_packet** **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` packet **)**
  75. Emitted when this MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` receives a ``packet`` with custom data (see :ref:`send_bytes<class_SceneMultiplayer_method_send_bytes>`). ID is the peer ID of the peer that sent the packet.
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Property Descriptions
  80. ---------------------
  81. .. _class_SceneMultiplayer_property_allow_object_decoding:
  82. .. rst-class:: classref-property
  83. :ref:`bool<class_bool>` **allow_object_decoding** = ``false``
  84. .. rst-class:: classref-property-setget
  85. - void **set_allow_object_decoding** **(** :ref:`bool<class_bool>` value **)**
  86. - :ref:`bool<class_bool>` **is_object_decoding_allowed** **(** **)**
  87. If ``true``, the MultiplayerAPI will allow encoding and decoding of object during RPCs.
  88. \ **Warning:** Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threat such as remote code execution.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_SceneMultiplayer_property_auth_callback:
  92. .. rst-class:: classref-property
  93. :ref:`Callable<class_Callable>` **auth_callback**
  94. .. rst-class:: classref-property-setget
  95. - void **set_auth_callback** **(** :ref:`Callable<class_Callable>` value **)**
  96. - :ref:`Callable<class_Callable>` **get_auth_callback** **(** **)**
  97. The callback to execute when when receiving authentication data sent via :ref:`send_auth<class_SceneMultiplayer_method_send_auth>`. If the :ref:`Callable<class_Callable>` is empty (default), peers will be automatically accepted as soon as they connect.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_SceneMultiplayer_property_auth_timeout:
  101. .. rst-class:: classref-property
  102. :ref:`float<class_float>` **auth_timeout** = ``3.0``
  103. .. rst-class:: classref-property-setget
  104. - void **set_auth_timeout** **(** :ref:`float<class_float>` value **)**
  105. - :ref:`float<class_float>` **get_auth_timeout** **(** **)**
  106. If set to a value greater than ``0.0``, the maximum amount of time peers can stay in the authenticating state, after which the authentication will automatically fail. See the :ref:`peer_authenticating<class_SceneMultiplayer_signal_peer_authenticating>` and :ref:`peer_authentication_failed<class_SceneMultiplayer_signal_peer_authentication_failed>` signals.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_SceneMultiplayer_property_refuse_new_connections:
  110. .. rst-class:: classref-property
  111. :ref:`bool<class_bool>` **refuse_new_connections** = ``false``
  112. .. rst-class:: classref-property-setget
  113. - void **set_refuse_new_connections** **(** :ref:`bool<class_bool>` value **)**
  114. - :ref:`bool<class_bool>` **is_refusing_new_connections** **(** **)**
  115. If ``true``, the MultiplayerAPI's :ref:`MultiplayerAPI.multiplayer_peer<class_MultiplayerAPI_property_multiplayer_peer>` refuses new incoming connections.
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _class_SceneMultiplayer_property_root_path:
  119. .. rst-class:: classref-property
  120. :ref:`NodePath<class_NodePath>` **root_path** = ``NodePath("")``
  121. .. rst-class:: classref-property-setget
  122. - void **set_root_path** **(** :ref:`NodePath<class_NodePath>` value **)**
  123. - :ref:`NodePath<class_NodePath>` **get_root_path** **(** **)**
  124. The root path to use for RPCs and replication. Instead of an absolute path, a relative path will be used to find the node upon which the RPC should be executed.
  125. This effectively allows to have different branches of the scene tree to be managed by different MultiplayerAPI, allowing for example to run both client and server in the same scene.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_SceneMultiplayer_property_server_relay:
  129. .. rst-class:: classref-property
  130. :ref:`bool<class_bool>` **server_relay** = ``true``
  131. .. rst-class:: classref-property-setget
  132. - void **set_server_relay_enabled** **(** :ref:`bool<class_bool>` value **)**
  133. - :ref:`bool<class_bool>` **is_server_relay_enabled** **(** **)**
  134. Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is ``false``, clients won't be automatically notified of other peers and won't be able to send them packets through the server.
  135. \ **Note:** Changing this option while other peers are connected may lead to unexpected behaviors.
  136. \ **Note:** Support for this feature may depend on the current :ref:`MultiplayerPeer<class_MultiplayerPeer>` configuration. See :ref:`MultiplayerPeer.is_server_relay_supported<class_MultiplayerPeer_method_is_server_relay_supported>`.
  137. .. rst-class:: classref-section-separator
  138. ----
  139. .. rst-class:: classref-descriptions-group
  140. Method Descriptions
  141. -------------------
  142. .. _class_SceneMultiplayer_method_clear:
  143. .. rst-class:: classref-method
  144. void **clear** **(** **)**
  145. Clears the current SceneMultiplayer network state (you shouldn't call this unless you know what you are doing).
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_SceneMultiplayer_method_complete_auth:
  149. .. rst-class:: classref-method
  150. :ref:`Error<enum_@GlobalScope_Error>` **complete_auth** **(** :ref:`int<class_int>` id **)**
  151. Mark the authentication step as completed for the remote peer identified by ``id``. The :ref:`MultiplayerAPI.peer_connected<class_MultiplayerAPI_signal_peer_connected>` signal will be emitted for this peer once the remote side also completes the authentication. No further authentication messages are expected to be received from this peer.
  152. If a peer disconnects before completing authentication, either due to a network issue, the :ref:`auth_timeout<class_SceneMultiplayer_property_auth_timeout>` expiring, or manually calling :ref:`disconnect_peer<class_SceneMultiplayer_method_disconnect_peer>`, the :ref:`peer_authentication_failed<class_SceneMultiplayer_signal_peer_authentication_failed>` signal will be emitted instead of :ref:`MultiplayerAPI.peer_disconnected<class_MultiplayerAPI_signal_peer_disconnected>`.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_SceneMultiplayer_method_disconnect_peer:
  156. .. rst-class:: classref-method
  157. void **disconnect_peer** **(** :ref:`int<class_int>` id **)**
  158. Disconnects the peer identified by ``id``, removing it from the list of connected peers, and closing the underlying connection with it.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. _class_SceneMultiplayer_method_get_authenticating_peers:
  162. .. rst-class:: classref-method
  163. :ref:`PackedInt32Array<class_PackedInt32Array>` **get_authenticating_peers** **(** **)**
  164. Returns the IDs of the peers currently trying to authenticate with this :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_SceneMultiplayer_method_send_auth:
  168. .. rst-class:: classref-method
  169. :ref:`Error<enum_@GlobalScope_Error>` **send_auth** **(** :ref:`int<class_int>` id, :ref:`PackedByteArray<class_PackedByteArray>` data **)**
  170. Sends the specified ``data`` to the remote peer identified by ``id`` as part of an authentication message. This can be used to authenticate peers, and control when :ref:`MultiplayerAPI.peer_connected<class_MultiplayerAPI_signal_peer_connected>` is emitted (and the remote peer accepted as one of the connected peers).
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_SceneMultiplayer_method_send_bytes:
  174. .. rst-class:: classref-method
  175. :ref:`Error<enum_@GlobalScope_Error>` **send_bytes** **(** :ref:`PackedByteArray<class_PackedByteArray>` bytes, :ref:`int<class_int>` id=0, :ref:`TransferMode<enum_MultiplayerPeer_TransferMode>` mode=2, :ref:`int<class_int>` channel=0 **)**
  176. Sends the given raw ``bytes`` to a specific peer identified by ``id`` (see :ref:`MultiplayerPeer.set_target_peer<class_MultiplayerPeer_method_set_target_peer>`). Default ID is ``0``, i.e. broadcast to all peers.
  177. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  178. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  179. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  180. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  181. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  182. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`