diff --git a/doc/classes/WebSocketClient.xml b/doc/classes/WebSocketClient.xml deleted file mode 100644 index 496baa5787..0000000000 --- a/doc/classes/WebSocketClient.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/classes/WebSocketPeer.xml b/doc/classes/WebSocketPeer.xml deleted file mode 100644 index 276249e65a..0000000000 --- a/doc/classes/WebSocketPeer.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/classes/WebSocketServer.xml b/doc/classes/WebSocketServer.xml deleted file mode 100644 index 9a7108952f..0000000000 --- a/doc/classes/WebSocketServer.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml index 7bee63019b..4b2a9df8c4 100644 --- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml +++ b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml @@ -16,6 +16,8 @@ + + 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. @@ -23,7 +25,7 @@ - + @@ -31,8 +33,10 @@ + + - 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. @@ -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. + + + + + + + + + Disconnect the given peer. If "now" is set to true, the connection will be closed immediately without flushing queued messages. + + + + + + + + + Returns the IP address of the given peer. + + + + + + + + + Returns the remote port of the given peer. + + diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index bd76c766a0..e948df2742 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -768,8 +768,8 @@ void NetworkedMultiplayerENet::_bind_methods() { ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &NetworkedMultiplayerENet::set_compression_mode); ClassDB::bind_method(D_METHOD("get_compression_mode"), &NetworkedMultiplayerENet::get_compression_mode); ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &NetworkedMultiplayerENet::set_bind_ip); - ClassDB::bind_method(D_METHOD("get_peer_address"), &NetworkedMultiplayerENet::get_peer_address); - ClassDB::bind_method(D_METHOD("get_peer_port"), &NetworkedMultiplayerENet::get_peer_port); + ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &NetworkedMultiplayerENet::get_peer_address); + ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &NetworkedMultiplayerENet::get_peer_port); ADD_PROPERTY(PropertyInfo(Variant::INT, "compression_mode", PROPERTY_HINT_ENUM, "None,Range Coder,FastLZ,ZLib,ZStd"), "set_compression_mode", "get_compression_mode"); diff --git a/modules/websocket/config.py b/modules/websocket/config.py index fb920482f5..399ca88fc1 100644 --- a/modules/websocket/config.py +++ b/modules/websocket/config.py @@ -5,3 +5,14 @@ def can_build(platform): def configure(env): pass + +def get_doc_classes(): + return [ + "WebSocketClient", + "WebSocketMultiplayerPeer", + "WebSocketPeer", + "WebSocketServer" + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml new file mode 100644 index 0000000000..2e11e1a44c --- /dev/null +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -0,0 +1,70 @@ + + + + A WebSocket client implementation + + + 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. + + + + + + + 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. + + + + + + Emitted when the connection to the server is closed. + + + + + Emitted when the connection to the server fails. + + + + + + + Emitted when a connection with the server is established, [code]protocol[/code] will contain the sub-protocol agreed with the server. + + + + + Emitted when a WebSocket message is received. Note: This signal is NOT emitted when used as high level multiplayer peer. + + + + + + diff --git a/doc/classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml similarity index 64% rename from doc/classes/WebSocketMultiplayerPeer.xml rename to modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml index a1014350f5..1a841f85ed 100644 --- a/doc/classes/WebSocketMultiplayerPeer.xml +++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml @@ -1,8 +1,10 @@ + Base class for WebSocket server and client. + Base class for WebSocket server and client, allowing them to be used as network peer for the [MultiplayerAPI]. @@ -15,6 +17,7 @@ + Returns the [WebSocketPeer] associated to the given [code]peer_id[/code]. @@ -23,6 +26,7 @@ + Emitted when a packet is received from a peer. Note: this signal is only emitted when the client or server is configured to use Godot multiplayer API. diff --git a/modules/websocket/doc_classes/WebSocketPeer.xml b/modules/websocket/doc_classes/WebSocketPeer.xml new file mode 100644 index 0000000000..85a08e0c0b --- /dev/null +++ b/modules/websocket/doc_classes/WebSocketPeer.xml @@ -0,0 +1,75 @@ + + + + A class representing a specific WebSocket connection. + + + This class represent a specific WebSocket connection, you can do lower level operations with it. + You can choose to write to the socket in binary or text mode, and you can recognize the mode used for writing by the other peer. + + + + + + + + + + + Close this WebSocket connection, actively disconnecting the peer. + + + + + + + Returns the IP Address of the connected peer. (Not available in HTML5 export) + + + + + + + Returns the remote port of the connected peer. (Not available in HTML5 export) + + + + + + + Get the current selected write mode. See [enum WriteMode]. + + + + + + + Returns [code]true[/code] if this peer is currently connected. + + + + + + + + + Sets the socket to use the given [enum WriteMode]. + + + + + + + Returns [code]true[/code] if the last received packet was sent as a text payload. See [enum WriteMode] + + + + + + Specify that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed). + + + Specify that WebSockets messages should be transferred as binary payload (any byte combination is allowed). + + + diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml new file mode 100644 index 0000000000..a1061e446b --- /dev/null +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -0,0 +1,109 @@ + + + + A WebSocket server implementation + + + 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. + + + + + + + + + + + + + Disconnects the given peer. + + + + + + + + + Returns the IP address of the given peer. + + + + + + + + + Returns the remote port of the given peer. + + + + + + + + + Returns [code]true[/code] if a peer with the given ID is connected. + + + + + + + Returns [code]true[/code] if the server is actively listening on a port. + + + + + + + + + + + + + Start listening on the given 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. + + + + + + + Stop the server and clear its state. + + + + + + + + + + + Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client. + + + + + + + Emitted when a client disconnects. + + + + + + + Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer. + + + + + + diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp index 2693b26e47..53dd7b51b7 100644 --- a/modules/websocket/websocket_server.cpp +++ b/modules/websocket/websocket_server.cpp @@ -44,9 +44,9 @@ void WebSocketServer::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "protocols", "gd_mp_api"), &WebSocketServer::listen, DEFVAL(PoolVector()), DEFVAL(false)); ClassDB::bind_method(D_METHOD("stop"), &WebSocketServer::stop); ClassDB::bind_method(D_METHOD("has_peer", "id"), &WebSocketServer::has_peer); - ClassDB::bind_method(D_METHOD("get_peer_address"), &WebSocketServer::get_peer_address); - ClassDB::bind_method(D_METHOD("get_peer_port"), &WebSocketServer::get_peer_port); - ClassDB::bind_method(D_METHOD("disconnect_peer"), &WebSocketServer::disconnect_peer); + ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &WebSocketServer::get_peer_address); + ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &WebSocketServer::get_peer_port); + ClassDB::bind_method(D_METHOD("disconnect_peer", "id"), &WebSocketServer::disconnect_peer); ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol")));