summaryrefslogtreecommitdiff
path: root/modules/websocket
diff options
context:
space:
mode:
Diffstat (limited to 'modules/websocket')
-rw-r--r--modules/websocket/doc_classes/WebSocketClient.xml1
-rw-r--r--modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml5
-rw-r--r--modules/websocket/doc_classes/WebSocketPeer.xml2
-rw-r--r--modules/websocket/doc_classes/WebSocketServer.xml1
-rw-r--r--modules/websocket/websocket_client.cpp2
-rw-r--r--modules/websocket/websocket_multiplayer_peer.cpp45
-rw-r--r--modules/websocket/websocket_multiplayer_peer.h7
-rw-r--r--modules/websocket/websocket_server.cpp8
-rw-r--r--modules/websocket/wsl_server.cpp12
9 files changed, 25 insertions, 58 deletions
diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml
index ed8f3ba867..4b515c12a1 100644
--- a/modules/websocket/doc_classes/WebSocketClient.xml
+++ b/modules/websocket/doc_classes/WebSocketClient.xml
@@ -8,6 +8,7 @@
This client can be optionally used as a multiplayer peer for the [MultiplayerAPI].
After starting the client ([method connect_to_url]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]).
You will receive appropriate signals when connecting, disconnecting, or when new data is available.
+ [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] 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.
</description>
<tutorials>
</tutorials>
diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml
index bf35acbd11..8d8ab220e2 100644
--- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml
+++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml
@@ -5,6 +5,7 @@
</brief_description>
<description>
Base class for WebSocket server and client, allowing them to be used as multiplayer peer for the [MultiplayerAPI].
+ [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] 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.
</description>
<tutorials>
</tutorials>
@@ -30,10 +31,6 @@
</description>
</method>
</methods>
- <members>
- <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" />
- <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" />
- </members>
<signals>
<signal name="peer_packet">
<argument index="0" name="peer_source" type="int" />
diff --git a/modules/websocket/doc_classes/WebSocketPeer.xml b/modules/websocket/doc_classes/WebSocketPeer.xml
index ab7ef6c4d0..2f455c32fd 100644
--- a/modules/websocket/doc_classes/WebSocketPeer.xml
+++ b/modules/websocket/doc_classes/WebSocketPeer.xml
@@ -4,7 +4,7 @@
A class representing a specific WebSocket connection.
</brief_description>
<description>
- This class represent a specific WebSocket connection, you can do lower level operations with it.
+ This class represents a specific WebSocket connection, allowing you to 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.
</description>
<tutorials>
diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml
index 2bb705b384..f901b089ea 100644
--- a/modules/websocket/doc_classes/WebSocketServer.xml
+++ b/modules/websocket/doc_classes/WebSocketServer.xml
@@ -7,6 +7,7 @@
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 MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal.
[b]Note:[/b] Not available in HTML5 exports.
+ [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] 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.
</description>
<tutorials>
</tutorials>
diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp
index f7a8944745..bf35c91c7f 100644
--- a/modules/websocket/websocket_client.cpp
+++ b/modules/websocket/websocket_client.cpp
@@ -129,7 +129,7 @@ void WebSocketClient::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "verify_ssl", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_verify_ssl_enabled", "is_verify_ssl_enabled");
ClassDB::bind_method(D_METHOD("get_trusted_ssl_certificate"), &WebSocketClient::get_trusted_ssl_certificate);
- ClassDB::bind_method(D_METHOD("set_trusted_ssl_certificate"), &WebSocketClient::set_trusted_ssl_certificate);
+ ClassDB::bind_method(D_METHOD("set_trusted_ssl_certificate", "cert"), &WebSocketClient::set_trusted_ssl_certificate);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "trusted_ssl_certificate", PROPERTY_HINT_RESOURCE_TYPE, "X509Certificate", PROPERTY_USAGE_NONE), "set_trusted_ssl_certificate", "get_trusted_ssl_certificate");
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp
index 7464cf2bf5..e54bfbca12 100644
--- a/modules/websocket/websocket_multiplayer_peer.cpp
+++ b/modules/websocket/websocket_multiplayer_peer.cpp
@@ -105,23 +105,6 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer
//
// MultiplayerPeer
//
-void WebSocketMultiplayerPeer::set_transfer_channel(int p_channel) {
- // Websocket does not have channels.
-}
-
-int WebSocketMultiplayerPeer::get_transfer_channel() const {
- return 0;
-}
-
-void WebSocketMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) {
- // Websocket uses TCP, reliable
-}
-
-Multiplayer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const {
- // Websocket uses TCP, reliable
- return Multiplayer::TRANSFER_MODE_RELIABLE;
-}
-
void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) {
_target_peer = p_target_peer;
}
@@ -137,14 +120,6 @@ int WebSocketMultiplayerPeer::get_unique_id() const {
return _peer_id;
}
-void WebSocketMultiplayerPeer::set_refuse_new_connections(bool p_enable) {
- _refusing = p_enable;
-}
-
-bool WebSocketMultiplayerPeer::is_refusing_new_connections() const {
- return _refusing;
-}
-
void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id) {
ERR_FAIL_COND(!p_peer.is_valid());
ERR_FAIL_COND(!p_peer->is_connected_to_host());
@@ -173,8 +148,8 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) {
// Then send the server peer (which will trigger connection_succeded in client)
_send_sys(get_peer(p_peer_id), SYS_ADD, 1);
- for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- int32_t id = E->key();
+ for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) {
+ int32_t id = E.key;
if (p_peer_id == id) {
continue; // Skip the newly added peer (already confirmed)
}
@@ -187,8 +162,8 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) {
}
void WebSocketMultiplayerPeer::_send_del(int32_t p_peer_id) {
- for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- int32_t id = E->key();
+ for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) {
+ int32_t id = E.key;
if (p_peer_id != id) {
_send_sys(get_peer(id), SYS_DEL, p_peer_id);
}
@@ -211,17 +186,17 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons
return OK; // Will not send to self
} else if (p_to == 0) {
- for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- if (E->key() != p_from) {
- E->get()->put_packet(p_buffer, p_buffer_size);
+ for (KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) {
+ if (E.key != p_from) {
+ E.value->put_packet(p_buffer, p_buffer_size);
}
}
return OK; // Sent to all but sender
} else if (p_to < 0) {
- for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- if (E->key() != p_from && E->key() != -p_to) {
- E->get()->put_packet(p_buffer, p_buffer_size);
+ for (KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) {
+ if (E.key != p_from && E.key != -p_to) {
+ E.value->put_packet(p_buffer, p_buffer_size);
}
}
return OK; // Sent to all but sender and excluded
diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h
index d97a599fe9..380edf67ed 100644
--- a/modules/websocket/websocket_multiplayer_peer.h
+++ b/modules/websocket/websocket_multiplayer_peer.h
@@ -68,7 +68,6 @@ protected:
bool _is_multiplayer = false;
int _target_peer = 0;
int _peer_id = 0;
- int _refusing = false;
static void _bind_methods();
@@ -78,15 +77,9 @@ protected:
public:
/* MultiplayerPeer */
- void set_transfer_channel(int p_channel) override;
- int get_transfer_channel() const override;
- void set_transfer_mode(Multiplayer::TransferMode p_mode) override;
- Multiplayer::TransferMode get_transfer_mode() const override;
void set_target_peer(int p_target_peer) override;
int get_packet_peer() const override;
int get_unique_id() const override;
- void set_refuse_new_connections(bool p_enable) override;
- bool is_refusing_new_connections() const override;
/* PacketPeer */
virtual int get_available_packet_count() const override;
diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp
index fb838109f3..e7f90fdeba 100644
--- a/modules/websocket/websocket_server.cpp
+++ b/modules/websocket/websocket_server.cpp
@@ -50,19 +50,19 @@ void WebSocketServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "code", "reason"), &WebSocketServer::disconnect_peer, DEFVAL(1000), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_bind_ip"), &WebSocketServer::get_bind_ip);
- ClassDB::bind_method(D_METHOD("set_bind_ip"), &WebSocketServer::set_bind_ip);
+ ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &WebSocketServer::set_bind_ip);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bind_ip"), "set_bind_ip", "get_bind_ip");
ClassDB::bind_method(D_METHOD("get_private_key"), &WebSocketServer::get_private_key);
- ClassDB::bind_method(D_METHOD("set_private_key"), &WebSocketServer::set_private_key);
+ ClassDB::bind_method(D_METHOD("set_private_key", "key"), &WebSocketServer::set_private_key);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "private_key", PROPERTY_HINT_RESOURCE_TYPE, "CryptoKey", PROPERTY_USAGE_NONE), "set_private_key", "get_private_key");
ClassDB::bind_method(D_METHOD("get_ssl_certificate"), &WebSocketServer::get_ssl_certificate);
- ClassDB::bind_method(D_METHOD("set_ssl_certificate"), &WebSocketServer::set_ssl_certificate);
+ ClassDB::bind_method(D_METHOD("set_ssl_certificate", "cert"), &WebSocketServer::set_ssl_certificate);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ssl_certificate", PROPERTY_HINT_RESOURCE_TYPE, "X509Certificate", PROPERTY_USAGE_NONE), "set_ssl_certificate", "get_ssl_certificate");
ClassDB::bind_method(D_METHOD("get_ca_chain"), &WebSocketServer::get_ca_chain);
- ClassDB::bind_method(D_METHOD("set_ca_chain"), &WebSocketServer::set_ca_chain);
+ ClassDB::bind_method(D_METHOD("set_ca_chain", "ca_chain"), &WebSocketServer::set_ca_chain);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ca_chain", PROPERTY_HINT_RESOURCE_TYPE, "X509Certificate", PROPERTY_USAGE_NONE), "set_ca_chain", "get_ca_chain");
ClassDB::bind_method(D_METHOD("get_handshake_timeout"), &WebSocketServer::get_handshake_timeout);
diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp
index 7402bbb46e..514b2d055f 100644
--- a/modules/websocket/wsl_server.cpp
+++ b/modules/websocket/wsl_server.cpp
@@ -182,12 +182,12 @@ Error WSLServer::listen(int p_port, const Vector<String> p_protocols, bool gd_mp
void WSLServer::poll() {
List<int> remove_ids;
- for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- Ref<WSLPeer> peer = (WSLPeer *)E->get().ptr();
+ for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) {
+ Ref<WSLPeer> peer = (WSLPeer *)E.value.ptr();
peer->poll();
if (!peer->is_connected_to_host()) {
- _on_disconnect(E->key(), peer->close_code != -1);
- remove_ids.push_back(E->key());
+ _on_disconnect(E.key, peer->close_code != -1);
+ remove_ids.push_back(E.key);
}
}
for (int &E : remove_ids) {
@@ -265,8 +265,8 @@ int WSLServer::get_max_packet_size() const {
void WSLServer::stop() {
_server->stop();
- for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- Ref<WSLPeer> peer = (WSLPeer *)E->get().ptr();
+ for (const KeyValue<int, Ref<WebSocketPeer>> &E : _peer_map) {
+ Ref<WSLPeer> peer = (WSLPeer *)E.value.ptr();
peer->close_now();
}
_pending.clear();