This class implements most of the logic behind the high level multiplayer API.
By default, [SceneTree] has a reference to this class that is used to provide multiplayer capabilities (i.e. RPC/RSET) across the whole scene.
It is possible to override the MultiplayerAPI instance used by specific Nodes by setting the [member Node.custom_multiplayer] property, effectively allowing to run both client and server in the same scene.
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<methodname="add_peer">
<returntype="void">
</return>
<argumentindex="0"name="id"type="int">
</argument>
<description>
</description>
</method>
<methodname="clear">
<returntype="void">
</return>
<description>
</description>
</method>
<methodname="connected_to_server">
<returntype="void">
</return>
<description>
</description>
</method>
<methodname="connection_failed">
<returntype="void">
</return>
<description>
</description>
</method>
<methodname="del_peer">
<returntype="void">
</return>
<argumentindex="0"name="id"type="int">
</argument>
<description>
Clears the current MultiplayerAPI network state (you shouldn't call this unless you know what you are doing).
Returns [code]true[/code] if this MultiplayerAPI's [member network_peer] is in server mode (listening for connections).
</description>
</method>
<methodname="poll">
<returntype="void">
</return>
<description>
</description>
</method>
<methodname="server_disconnected">
<returntype="void">
</return>
<description>
Method used for polling the MultiplayerAPI.
You only need to worry about this if you are using [memeber Node.custom_multplayer] override.
SceneTree will poll the default MultiplayerAPI for you.
</description>
</method>
<methodname="set_root_node">
...
...
@@ -91,38 +71,47 @@
<argumentindex="0"name="node"type="Node">
</argument>
<description>
Sets the base root node to use for RPCs. Instead of an absolute path, a relative path will be used to find the node upon which the RPC should be executed.
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.
The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the MultiplayerAPI will become a network server (check with [method is_network_server()]) and will set root node's network mode to master (see NETWORK_MODE_* constants in [Node]), or it will become a regular peer with root node set to slave. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to MultiplayerAPI's signals.
If [code]true[/code] the MultiplayerAPI's [member network_peer] refuses new incoming connections.
</member>
</members>
<signals>
<signalname="connected_to_server">
<description>
Emitted whenever this MultiplayerAPI's [member network_peer] successfully connected to a server. Only emitted on clients.
</description>
</signal>
<signalname="connection_failed">
<description>
Emitted whenever this MultiplayerAPI's [member network_peer] fails to establish a connection to a server. Only emitted on clients.
</description>
</signal>
<signalname="network_peer_connected">
<argumentindex="0"name="id"type="int">
</argument>
<description>
Emitted whenever this MultiplayerAPI's [member network_peer] connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1).
</description>
</signal>
<signalname="network_peer_disconnected">
<argumentindex="0"name="id"type="int">
</argument>
<description>
Emitted whenever this MultiplayerAPI's [member network_peer] disconnects from a peer. Clients get notified when other clients disconnect from the same server.
</description>
</signal>
<signalname="server_disconnected">
<description>
Emitted whenever this MultiplayerAPI's [member network_peer] disconnected from server. Only emitted on clients.
The name of the node. This name is unique among the siblings (other child nodes from the same parent). When set to an existing name, the node will be automatically renamed
The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the SceneTree will become a network server (check with [method is_network_server()]) and will set root node's network mode to master (see NETWORK_MODE_* constants in [Node]), or it will become a regular peer with root node set to slave. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to SceneTree's signals.
Closes the connection. Ignored if no connection is currently established. If this is a server it tries to notify all clients before forcibly disconnecting them. If this is a client it simply closes the connection to the server.
Create client that connects to a server at address [code]ip[/code] using specified [code]port[/code]. The given IP needs to be in IPv4 or IPv6 address format, for example: [code]192.168.1.1[/code]. The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [code]OK[/code] if a client was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the client could not be created.
Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain nome (e.g. [code]www.example.com[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]192.168.1.1[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [code]OK[/code] if a client was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the client could not be created. If [code]client_port[/code] is specified, the client will also listen to the given port, this is useful in some NAT traveral technique.
</description>
</method>
<methodname="create_server">
...
...
@@ -50,6 +54,35 @@
Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]*[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4096 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [code]OK[/code] if a server was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the server could not be created.
This class implements a WebSocket client compatible with any RFC 6455 complaint WebSocket server.
This client can be optionally used as a network peer for the [MultiplayerAPI].
After starting the client ([method connect_to_url]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]).
You will received appropriate signals when connecting, disconnecting, or when new data is available.
Connect to the given URL requesting one of the given [code]protocols[/code] as sub-protocol.
If [code]true[/code] is passed as [code]gd_mp_api[/code], the client will behave like a network peer for the [MultiplayerAPI]. Note: connnections to non Godot servers will not work, and [signal data_received] will not be emitted when this option is true.
</description>
</method>
<methodname="disconnect_from_host">
<returntype="void">
</return>
<description>
Disconnect from the server if currently connected.
Enable or disable SSL certificate verification. Note: You must specify the certificates to be used in the project settings for it to work when exported.
</member>
</members>
<signals>
<signalname="connection_closed">
<description>
Emitted when the connection to the server is closed.
</description>
</signal>
<signalname="connection_error">
<description>
Emitted when the connection to the server fails.
</description>
</signal>
<signalname="connection_established">
<argumentindex="0"name="protocol"type="String">
</argument>
<description>
Emitted when a connection with the server is established, [code]protocol[/code] will contain the sub-protocol agreed with the server.
</description>
</signal>
<signalname="data_received">
<description>
Emitted when a WebSocket message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
This class implements a WebSocket server that can also support the high level multiplayer API.
After starting the server ([method listen]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal.
Note: This class will not work in HTML5 exports due to browser restrictions.
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<methodname="disconnect_peer">
<returntype="void">
</return>
<argumentindex="0"name="id"type="int">
</argument>
<description>
Disconnects the given peer.
</description>
</method>
<methodname="get_peer_address"qualifiers="const">
<returntype="String">
</return>
<argumentindex="0"name="id"type="int">
</argument>
<description>
Returns the IP address of the given peer.
</description>
</method>
<methodname="get_peer_port"qualifiers="const">
<returntype="int">
</return>
<argumentindex="0"name="id"type="int">
</argument>
<description>
Returns the remote port of the given peer.
</description>
</method>
<methodname="has_peer"qualifiers="const">
<returntype="bool">
</return>
<argumentindex="0"name="id"type="int">
</argument>
<description>
Returns [code]true[/code] if a peer with the given ID is connected.
</description>
</method>
<methodname="is_listening"qualifiers="const">
<returntype="bool">
</return>
<description>
Returns [code]true[/code] if the server is actively listening on a port.
You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
You can use this server as a network peer for [MultiplayerAPI] by passing true as "gd_mp_api". Note: [signal data_received] will not be fired and clients other than Godot will not work in this case.
</description>
</method>
<methodname="stop">
<returntype="void">
</return>
<description>
Stop the server and clear its state.
</description>
</method>
</methods>
...
...
@@ -49,18 +86,21 @@
<argumentindex="1"name="protocol"type="String">
</argument>
<description>
Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
</description>
</signal>
<signalname="client_disconnected">
<argumentindex="0"name="id"type="int">
</argument>
<description>
Emitted when a client disconnects.
</description>
</signal>
<signalname="data_received">
<argumentindex="0"name="id"type="int">
</argument>
<description>
Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.