From d75e0de729ab3f6e809f025e632be41ad2e476b7 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 11 Oct 2019 18:39:03 +0200 Subject: [PATCH 1/2] Fix HTML5 build after 67a4c30. I messed up a rebase and a commit was partly skipped --- modules/websocket/emws_client.cpp | 10 ++++++++-- modules/websocket/emws_client.h | 2 +- modules/websocket/emws_server.cpp | 2 +- modules/websocket/emws_server.h | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp index fad766ea5d8..983db60d5e5 100644 --- a/modules/websocket/emws_client.cpp +++ b/modules/websocket/emws_client.cpp @@ -64,9 +64,15 @@ EMSCRIPTEN_KEEPALIVE void _esws_on_close(void *obj, int code, char *reason, int } } -Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const PoolVector p_protocols, const Vector p_custom_headers) { +Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector p_protocols, const Vector p_custom_headers) { + + String proto_string; + for (int i = 0; i < p_protocols.size(); i++) { + if (i != 0) + proto_string += ","; + proto_string += p_protocols[i]; + } - String proto_string = p_protocols.join(","); String str = "ws://"; if (p_custom_headers.size()) { diff --git a/modules/websocket/emws_client.h b/modules/websocket/emws_client.h index 2d35f7f0f67..67705891b25 100644 --- a/modules/websocket/emws_client.h +++ b/modules/websocket/emws_client.h @@ -50,7 +50,7 @@ public: bool _is_connecting; Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets); - Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const PoolVector p_protocol = PoolVector(), const Dictionary p_custom_headers = Dictionary()); + Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector p_protocol = Vector(), const Vector p_custom_headers = Vector()); Ref get_peer(int p_peer_id) const; void disconnect_from_host(int p_code = 1000, String p_reason = ""); IP_Address get_connected_host() const; diff --git a/modules/websocket/emws_server.cpp b/modules/websocket/emws_server.cpp index c4bb459ad08..9a6a30d6132 100644 --- a/modules/websocket/emws_server.cpp +++ b/modules/websocket/emws_server.cpp @@ -33,7 +33,7 @@ #include "emws_server.h" #include "core/os/os.h" -Error EMWSServer::listen(int p_port, PoolVector p_protocols, bool gd_mp_api) { +Error EMWSServer::listen(int p_port, Vector p_protocols, bool gd_mp_api) { return FAILED; } diff --git a/modules/websocket/emws_server.h b/modules/websocket/emws_server.h index a5e5b4090ec..e8da8c26b49 100644 --- a/modules/websocket/emws_server.h +++ b/modules/websocket/emws_server.h @@ -43,7 +43,7 @@ class EMWSServer : public WebSocketServer { public: Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets); - Error listen(int p_port, PoolVector p_protocols = PoolVector(), bool gd_mp_api = false); + Error listen(int p_port, Vector p_protocols = Vector(), bool gd_mp_api = false); void stop(); bool is_listening() const; bool has_peer(int p_id) const; From 2bb3e358e037768ca84d3b8b290018cfaf83e0dc Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 11 Oct 2019 19:46:29 +0200 Subject: [PATCH 2/2] Trim protocol field from spaces in WS classes. --- modules/websocket/wsl_client.cpp | 8 ++++++-- modules/websocket/wsl_server.cpp | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index a422f65cfc7..ad70c9c0e13 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -181,8 +181,12 @@ Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, _connection = _tcp; _use_ssl = p_ssl; _host = p_host; - _protocols.clear(); - _protocols.append_array(p_protocols); + // Strip edges from protocols. + _protocols.resize(p_protocols.size()); + String *pw = _protocols.ptrw(); + for (int i = 0; i < p_protocols.size(); i++) { + pw[i] = p_protocols[i].strip_edges(); + } _key = WSLPeer::generate_key(); // TODO custom extra headers (allow overriding this too?) diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index 993dceafb9c..2181775b994 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -80,11 +80,12 @@ bool WSLServer::PendingPeer::_parse_request(const Vector p_protocols) { if (headers.has("sec-websocket-protocol")) { Vector protos = headers["sec-websocket-protocol"].split(","); for (int i = 0; i < protos.size(); i++) { + String proto = protos[i].strip_edges(); // Check if we have the given protocol for (int j = 0; j < p_protocols.size(); j++) { - if (protos[i] != p_protocols[j]) + if (proto != p_protocols[j]) continue; - protocol = protos[i]; + protocol = proto; break; } // Found a protocol @@ -158,7 +159,12 @@ Error WSLServer::listen(int p_port, const Vector p_protocols, bool gd_mp ERR_FAIL_COND_V(is_listening(), ERR_ALREADY_IN_USE); _is_multiplayer = gd_mp_api; - _protocols.append_array(p_protocols); + // Strip edges from protocols. + _protocols.resize(p_protocols.size()); + String *pw = _protocols.ptrw(); + for (int i = 0; i < p_protocols.size(); i++) { + pw[i] = p_protocols[i].strip_edges(); + } _server->listen(p_port); return OK;