diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/http_client.cpp | 10 | ||||
-rw-r--r-- | core/io/http_client.h | 1 | ||||
-rw-r--r-- | core/io/net_socket.h | 2 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 2 | ||||
-rw-r--r-- | core/io/packet_peer_udp.cpp | 11 | ||||
-rw-r--r-- | core/io/packet_peer_udp.h | 2 | ||||
-rw-r--r-- | core/io/pck_packer.cpp | 4 | ||||
-rw-r--r-- | core/io/pck_packer.h | 2 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 53 |
9 files changed, 67 insertions, 20 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 1904c70f42..bfa272e859 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -173,6 +173,7 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector } status = STATUS_REQUESTING; + head_request = p_method == METHOD_HEAD; return OK; } @@ -228,6 +229,7 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector<Str } status = STATUS_REQUESTING; + head_request = p_method == METHOD_HEAD; return OK; } @@ -269,6 +271,7 @@ void HTTPClient::close() { connection.unref(); status = STATUS_DISCONNECTED; + head_request = false; if (resolving != IP::RESOLVER_INVALID_ID) { IP::get_singleton()->erase_resolve_item(resolving); @@ -470,6 +473,12 @@ Error HTTPClient::poll() { } } + // This is a HEAD request, we wont receive anything. + if (head_request) { + body_size = 0; + body_left = 0; + } + if (body_size != -1 || chunked) { status = STATUS_BODY; @@ -724,6 +733,7 @@ HTTPClient::HTTPClient() { tcp_connection.instance(); resolving = IP::RESOLVER_INVALID_ID; status = STATUS_DISCONNECTED; + head_request = false; conn_port = -1; body_size = -1; chunked = false; diff --git a/core/io/http_client.h b/core/io/http_client.h index ce7fe0491b..27c6711bcf 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -166,6 +166,7 @@ private: bool ssl_verify_host; bool blocking; bool handshaking; + bool head_request; Vector<uint8_t> response_str; diff --git a/core/io/net_socket.h b/core/io/net_socket.h index 3bc1369487..914e243b65 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -69,7 +69,7 @@ public: virtual bool is_open() const = 0; virtual int get_available_bytes() const = 0; - virtual void set_broadcasting_enabled(bool p_enabled) = 0; + virtual Error set_broadcasting_enabled(bool p_enabled) = 0; // Returns OK if the socket option has been set successfully. virtual void set_blocking_enabled(bool p_enabled) = 0; virtual void set_ipv6_only_enabled(bool p_enabled) = 0; virtual void set_tcp_no_delay_enabled(bool p_enabled) = 0; diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 23dfc58385..03bc4d453a 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -282,7 +282,7 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0."); //warning may lose packets ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data."); - ring_buffer.resize(nearest_shift(p_max_size + 4)); + ring_buffer.resize(nearest_shift(next_power_of_2(p_max_size + 4)) - 1); input_buffer.resize(next_power_of_2(p_max_size + 4)); } diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 7e9471c053..80a070cf1c 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -37,6 +37,12 @@ void PacketPeerUDP::set_blocking_mode(bool p_enable) { blocking = p_enable; } +void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) { + broadcast = p_enabled; + if (_sock.is_valid() && _sock->is_open()) + _sock->set_broadcasting_enabled(p_enabled); +} + Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); @@ -47,6 +53,7 @@ Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_i Error err = _sock->open(NetSocket::TYPE_UDP, ip_type); ERR_FAIL_COND_V(err != OK, err); _sock->set_blocking_enabled(false); + _sock->set_broadcasting_enabled(broadcast); } return _sock->join_multicast_group(p_multi_address, p_if_name); } @@ -122,6 +129,7 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { err = _sock->open(NetSocket::TYPE_UDP, ip_type); ERR_FAIL_COND_V(err != OK, err); _sock->set_blocking_enabled(false); + _sock->set_broadcasting_enabled(broadcast); } do { @@ -165,6 +173,7 @@ Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_ _sock->set_blocking_enabled(false); _sock->set_reuse_address_enabled(true); + _sock->set_broadcasting_enabled(broadcast); err = _sock->bind(p_bind_address, p_port); if (err != OK) { @@ -258,6 +267,7 @@ void PacketPeerUDP::_bind_methods() { ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); ClassDB::bind_method(D_METHOD("set_dest_address", "host", "port"), &PacketPeerUDP::_set_dest_address); + ClassDB::bind_method(D_METHOD("set_broadcast_enabled", "enabled"), &PacketPeerUDP::set_broadcast_enabled); ClassDB::bind_method(D_METHOD("join_multicast_group", "multicast_address", "interface_name"), &PacketPeerUDP::join_multicast_group); ClassDB::bind_method(D_METHOD("leave_multicast_group", "multicast_address", "interface_name"), &PacketPeerUDP::leave_multicast_group); } @@ -267,6 +277,7 @@ PacketPeerUDP::PacketPeerUDP() : queue_count(0), peer_port(0), blocking(true), + broadcast(false), _sock(Ref<NetSocket>(NetSocket::create())) { rb.resize(16); } diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 068bd5cd5a..dc89e129dd 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -53,6 +53,7 @@ protected: IP_Address peer_addr; int peer_port; bool blocking; + bool broadcast; Ref<NetSocket> _sock; static void _bind_methods(); @@ -77,6 +78,7 @@ public: Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); int get_available_packet_count() const; int get_max_packet_size() const; + void set_broadcast_enabled(bool p_enabled); Error join_multicast_group(IP_Address p_multi_address, String p_if_name); Error leave_multicast_group(IP_Address p_multi_address, String p_if_name); diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 443f390bb7..011ebb1812 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -55,9 +55,9 @@ static void _pad(FileAccess *p_file, int p_bytes) { void PCKPacker::_bind_methods() { - ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment"), &PCKPacker::pck_start); + ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment"), &PCKPacker::pck_start, DEFVAL(0)); ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path"), &PCKPacker::add_file); - ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush); + ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false)); }; Error PCKPacker::pck_start(const String &p_file, int p_alignment) { diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h index 4df495b11f..f5661c55a1 100644 --- a/core/io/pck_packer.h +++ b/core/io/pck_packer.h @@ -54,7 +54,7 @@ class PCKPacker : public Reference { Vector<File> files; public: - Error pck_start(const String &p_file, int p_alignment); + Error pck_start(const String &p_file, int p_alignment = 0); Error add_file(const String &p_file, const String &p_src); Error flush(bool p_verbose = false); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index f3eba44973..6f64543b3e 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -734,26 +734,49 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem String new_path = p_path; - if (translation_remaps.has(new_path)) { + if (translation_remaps.has(p_path)) { + // translation_remaps has the following format: + // { "res://path.png": PoolStringArray( "res://path-ru.png:ru", "res://path-de.png:de" ) } + + // To find the path of the remapped resource, we extract the locale name after + // the last ':' to match the project locale. + // We also fall back in case of regional locales as done in TranslationServer::translate + // (e.g. 'ru_RU' -> 'ru' if the former has no specific mapping). - Vector<String> &v = *translation_remaps.getptr(new_path); String locale = TranslationServer::get_singleton()->get_locale(); - if (r_translation_remapped) { - *r_translation_remapped = true; - } - for (int i = 0; i < v.size(); i++) { + ERR_FAIL_COND_V_MSG(locale.length() < 2, p_path, "Could not remap path '" + p_path + "' for translation as configured locale '" + locale + "' is invalid."); + String lang = TranslationServer::get_language_code(locale); - int split = v[i].find_last(":"); - if (split == -1) - continue; - String l = v[i].right(split + 1).strip_edges(); - if (l == String()) + Vector<String> &res_remaps = *translation_remaps.getptr(new_path); + bool near_match = false; + + for (int i = 0; i < res_remaps.size(); i++) { + int split = res_remaps[i].find_last(":"); + if (split == -1) { continue; + } - if (l.begins_with(locale)) { - new_path = v[i].left(split); + String l = res_remaps[i].right(split + 1).strip_edges(); + if (l == locale) { // Exact match. + new_path = res_remaps[i].left(split); break; + } else if (near_match) { + continue; // Already found near match, keep going for potential exact match. } + + // No exact match (e.g. locale 'ru_RU' but remap is 'ru'), let's look further + // for a near match (same language code, i.e. first 2 or 3 letters before + // regional code, if included). + if (TranslationServer::get_language_code(l) == lang) { + // Language code matches, that's a near match. Keep looking for exact match. + near_match = true; + new_path = res_remaps[i].left(split); + continue; + } + } + + if (r_translation_remapped) { + *r_translation_remapped = true; } } @@ -761,8 +784,8 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem new_path = path_remaps[new_path]; } - if (new_path == p_path) { //did not remap - //try file remap + if (new_path == p_path) { // Did not remap. + // Try file remap. Error err; FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err); |