diff options
Diffstat (limited to 'modules/websocket')
-rw-r--r-- | modules/websocket/doc_classes/WebSocketClient.xml | 4 | ||||
-rw-r--r-- | modules/websocket/doc_classes/WebSocketServer.xml | 2 | ||||
-rw-r--r-- | modules/websocket/emws_client.cpp | 22 | ||||
-rw-r--r-- | modules/websocket/emws_peer.cpp | 17 | ||||
-rw-r--r-- | modules/websocket/emws_peer.h | 2 | ||||
-rw-r--r-- | modules/websocket/emws_server.cpp | 4 | ||||
-rw-r--r-- | modules/websocket/emws_server.h | 2 | ||||
-rw-r--r-- | modules/websocket/websocket_multiplayer_peer.cpp | 16 | ||||
-rw-r--r-- | modules/websocket/websocket_multiplayer_peer.h | 2 | ||||
-rw-r--r-- | modules/websocket/wsl_peer.cpp | 10 | ||||
-rw-r--r-- | modules/websocket/wsl_peer.h | 2 |
11 files changed, 47 insertions, 36 deletions
diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml index 2549321db3..45db49c913 100644 --- a/modules/websocket/doc_classes/WebSocketClient.xml +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -17,11 +17,11 @@ </return> <argument index="0" name="url" type="String"> </argument> - <argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )"> + <argument index="1" name="protocols" type="PackedStringArray" default="PackedStringArray( )"> </argument> <argument index="2" name="gd_mp_api" type="bool" default="false"> </argument> - <argument index="3" name="custom_headers" type="PoolStringArray" default="PoolStringArray( )"> + <argument index="3" name="custom_headers" type="PackedStringArray" default="PackedStringArray( )"> </argument> <description> Connects to the given URL requesting one of the given [code]protocols[/code] as sub-protocol. If the list empty (default), no sub-protocol will be requested. diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index f66e1bf54b..f7805209e2 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -63,7 +63,7 @@ </return> <argument index="0" name="port" type="int"> </argument> - <argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )"> + <argument index="1" name="protocols" type="PackedStringArray" default="PackedStringArray( )"> </argument> <argument index="2" name="gd_mp_api" type="bool" default="false"> </argument> diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp index 7e68936fc3..e5680ce2e9 100644 --- a/modules/websocket/emws_client.cpp +++ b/modules/websocket/emws_client.cpp @@ -91,10 +91,14 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, int peer_sock = EM_ASM_INT({ var proto_str = UTF8ToString($2); var socket = null; - if (proto_str) { - socket = new WebSocket(UTF8ToString($1), proto_str.split(",")); - } else { - socket = new WebSocket(UTF8ToString($1)); + try { + if (proto_str) { + socket = new WebSocket(UTF8ToString($1), proto_str.split(",")); + } else { + socket = new WebSocket(UTF8ToString($1)); + } + } catch (e) { + return -1; } var c_ptr = Module.IDHandler.get($0); socket.binaryType = "arraybuffer"; @@ -174,6 +178,8 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, return Module.IDHandler.add(socket); }, _js_id, str.utf8().get_data(), proto_string.utf8().get_data()); /* clang-format on */ + if (peer_sock == -1) + return FAILED; static_cast<Ref<EMWSPeer> >(_peer)->set_sock(peer_sock, _in_buf_size, _in_pkt_size); @@ -190,11 +196,11 @@ Ref<WebSocketPeer> EMWSClient::get_peer(int p_peer_id) const { NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const { - if (_peer->is_connected_to_host()) + if (_peer->is_connected_to_host()) { + if (_is_connecting) + return CONNECTION_CONNECTING; return CONNECTION_CONNECTED; - - if (_is_connecting) - return CONNECTION_CONNECTING; + } return CONNECTION_DISCONNECTED; }; diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index effed8e4d9..f396a1c812 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -68,12 +68,17 @@ Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { bytes_array[i] = getValue($1+i, 'i8'); } - if ($3) { - sock.send(bytes_array.buffer); - } else { - var string = new TextDecoder("utf-8").decode(bytes_array); - sock.send(string); + try { + if ($3) { + sock.send(bytes_array.buffer); + } else { + var string = new TextDecoder("utf-8").decode(bytes_array); + sock.send(string); + } + } catch (e) { + return 1; } + return 0; }, peer_sock, p_buffer, p_buffer_size, is_bin); /* clang-format on */ @@ -85,7 +90,7 @@ Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { if (_in_buffer.packets_left() == 0) return ERR_UNAVAILABLE; - PoolVector<uint8_t>::Write rw = _packet_buffer.write(); + uint8_t *rw = _packet_buffer.ptrw(); int read = 0; Error err = _in_buffer.read_packet(rw.ptr(), _packet_buffer.size(), &_is_string, read); ERR_FAIL_COND_V(err != OK, err); diff --git a/modules/websocket/emws_peer.h b/modules/websocket/emws_peer.h index 43b42f9be6..6308ebe490 100644 --- a/modules/websocket/emws_peer.h +++ b/modules/websocket/emws_peer.h @@ -48,7 +48,7 @@ private: int peer_sock; WriteMode write_mode; - PoolVector<uint8_t> _packet_buffer; + Vector<uint8_t> _packet_buffer; PacketBuffer<uint8_t> _in_buffer; uint8_t _is_string; diff --git a/modules/websocket/emws_server.cpp b/modules/websocket/emws_server.cpp index 23faa05365..8ceefa42b6 100644 --- a/modules/websocket/emws_server.cpp +++ b/modules/websocket/emws_server.cpp @@ -53,8 +53,8 @@ Ref<WebSocketPeer> EMWSServer::get_peer(int p_id) const { return NULL; } -PoolVector<String> EMWSServer::get_protocols() const { - PoolVector<String> out; +Vector<String> EMWSServer::get_protocols() const { + Vector<String> out; return out; } diff --git a/modules/websocket/emws_server.h b/modules/websocket/emws_server.h index 869e59fe03..f273fd078f 100644 --- a/modules/websocket/emws_server.h +++ b/modules/websocket/emws_server.h @@ -53,7 +53,7 @@ public: void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = ""); int get_max_packet_size() const; virtual void poll(); - virtual PoolVector<String> get_protocols() const; + virtual Vector<String> get_protocols() const; EMWSServer(); ~EMWSServer(); diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 27ea50b524..5c01d44ede 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -127,12 +127,12 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer ERR_FAIL_COND_V_MSG(!_is_multiplayer, ERR_UNCONFIGURED, "Please use get_peer(ID).put_packet/var to communicate with peers when not using the MultiplayerAPI."); - PoolVector<uint8_t> buffer = _make_pkt(SYS_NONE, get_unique_id(), _target_peer, p_buffer, p_buffer_size); + Vector<uint8_t> buffer = _make_pkt(SYS_NONE, get_unique_id(), _target_peer, p_buffer, p_buffer_size); if (is_server()) { - return _server_relay(1, _target_peer, &(buffer.read()[0]), buffer.size()); + return _server_relay(1, _target_peer, &(buffer.ptr()[0]), buffer.size()); } else { - return get_peer(1)->put_packet(&(buffer.read()[0]), buffer.size()); + return get_peer(1)->put_packet(&(buffer.ptr()[0]), buffer.size()); } } @@ -183,16 +183,16 @@ void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_ty ERR_FAIL_COND(!p_peer.is_valid()); ERR_FAIL_COND(!p_peer->is_connected_to_host()); - PoolVector<uint8_t> message = _make_pkt(p_type, 1, 0, (uint8_t *)&p_peer_id, 4); - p_peer->put_packet(&(message.read()[0]), message.size()); + Vector<uint8_t> message = _make_pkt(p_type, 1, 0, (uint8_t *)&p_peer_id, 4); + p_peer->put_packet(&(message.ptr()[0]), message.size()); } -PoolVector<uint8_t> WebSocketMultiplayerPeer::_make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size) { +Vector<uint8_t> WebSocketMultiplayerPeer::_make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size) { - PoolVector<uint8_t> out; + Vector<uint8_t> out; out.resize(PROTO_SIZE + p_data_size); - PoolVector<uint8_t>::Write w = out.write(); + uint8_t *w = out.ptrw(); copymem(&w[0], &p_type, 1); copymem(&w[1], &p_from, 4); copymem(&w[5], &p_to, 4); diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index 27cb6e4eb7..579972ada2 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -41,7 +41,7 @@ class WebSocketMultiplayerPeer : public NetworkedMultiplayerPeer { GDCLASS(WebSocketMultiplayerPeer, NetworkedMultiplayerPeer); private: - PoolVector<uint8_t> _make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size); + Vector<uint8_t> _make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size); void _store_pkt(int32_t p_source, int32_t p_dest, const uint8_t *p_data, uint32_t p_data_size); Error _server_relay(int32_t p_from, int32_t p_to, const uint8_t *p_buffer, uint32_t p_buffer_size); diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 08079145e4..ff32e83dc1 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -43,10 +43,10 @@ String WSLPeer::generate_key() { // Random key RandomNumberGenerator rng; rng.set_seed(OS::get_singleton()->get_unix_time()); - PoolVector<uint8_t> bkey; + Vector<uint8_t> bkey; int len = 16; // 16 bytes, as per RFC bkey.resize(len); - PoolVector<uint8_t>::Write w = bkey.write(); + uint8_t *w = bkey.ptrw(); for (int i = 0; i < len; i++) { w[i] = (uint8_t)rng.randi_range(0, 255); } @@ -260,10 +260,10 @@ Error WSLPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { return ERR_UNAVAILABLE; int read = 0; - PoolVector<uint8_t>::Write rw = _packet_buffer.write(); - _in_buffer.read_packet(rw.ptr(), _packet_buffer.size(), &_is_string, read); + uint8_t *rw = _packet_buffer.ptrw(); + _in_buffer.read_packet(rw, _packet_buffer.size(), &_is_string, read); - *r_buffer = rw.ptr(); + *r_buffer = rw; r_buffer_size = read; return OK; diff --git a/modules/websocket/wsl_peer.h b/modules/websocket/wsl_peer.h index f1c45ee859..00549cd9bc 100644 --- a/modules/websocket/wsl_peer.h +++ b/modules/websocket/wsl_peer.h @@ -86,7 +86,7 @@ private: // Our packet info is just a boolean (is_string), using uint8_t for it. PacketBuffer<uint8_t> _in_buffer; - PoolVector<uint8_t> _packet_buffer; + Vector<uint8_t> _packet_buffer; WriteMode write_mode; |