summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/config_file.cpp94
-rw-r--r--core/io/config_file.h9
-rw-r--r--core/io/file_access_network.cpp1
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/marshalls.cpp7
-rw-r--r--core/io/multiplayer_api.cpp1
-rw-r--r--core/io/multiplayer_api.h2
-rw-r--r--core/io/pck_packer.cpp5
-rw-r--r--core/io/resource_format_binary.cpp4
-rw-r--r--core/io/stream_peer_tcp.cpp1
-rw-r--r--core/io/tcp_server.cpp6
11 files changed, 108 insertions, 24 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 871e21df3e..f7fb72c089 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -30,7 +30,7 @@
#include "config_file.h"
-#include "core/os/file_access.h"
+#include "core/io/file_access_encrypted.h"
#include "core/os/keyboard.h"
#include "core/variant_parser.h"
@@ -137,6 +137,48 @@ Error ConfigFile::save(const String &p_path) {
return err;
}
+ return _internal_save(file);
+}
+
+Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
+
+ Error err;
+ FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
+
+ if (err)
+ return err;
+
+ FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
+ err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256);
+ if (err) {
+ memdelete(fae);
+ memdelete(f);
+ return err;
+ }
+ return _internal_save(fae);
+}
+
+Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) {
+
+ Error err;
+ FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
+
+ if (err)
+ return err;
+
+ FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
+ err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256);
+ if (err) {
+ memdelete(fae);
+ memdelete(f);
+ return err;
+ }
+
+ return _internal_save(fae);
+}
+
+Error ConfigFile::_internal_save(FileAccess *file) {
+
for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::Element E = values.front(); E; E = E.next()) {
if (E != values.front())
@@ -164,6 +206,48 @@ Error ConfigFile::load(const String &p_path) {
if (!f)
return ERR_CANT_OPEN;
+ return _internal_load(p_path, f);
+}
+
+Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
+
+ Error err;
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
+
+ if (err)
+ return err;
+
+ FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
+ err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ);
+ if (err) {
+ memdelete(fae);
+ memdelete(f);
+ return err;
+ }
+ return _internal_load(p_path, fae);
+}
+
+Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) {
+
+ Error err;
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
+
+ if (err)
+ return err;
+
+ FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
+ err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ);
+ if (err) {
+ memdelete(fae);
+ memdelete(f);
+ return err;
+ }
+
+ return _internal_load(p_path, fae);
+}
+
+Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
+
VariantParser::StreamFile stream;
stream.f = f;
@@ -182,7 +266,7 @@ Error ConfigFile::load(const String &p_path) {
next_tag.fields.clear();
next_tag.name = String();
- err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
+ Error err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
if (err == ERR_FILE_EOF) {
memdelete(f);
return OK;
@@ -215,6 +299,12 @@ void ConfigFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("load", "path"), &ConfigFile::load);
ClassDB::bind_method(D_METHOD("save", "path"), &ConfigFile::save);
+
+ ClassDB::bind_method(D_METHOD("load_encrypted", "path", "key"), &ConfigFile::load_encrypted);
+ ClassDB::bind_method(D_METHOD("load_encrypted_pass", "path", "pass"), &ConfigFile::load_encrypted_pass);
+
+ ClassDB::bind_method(D_METHOD("save_encrypted", "path", "key"), &ConfigFile::save_encrypted);
+ ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "pass"), &ConfigFile::save_encrypted_pass);
}
ConfigFile::ConfigFile() {
diff --git a/core/io/config_file.h b/core/io/config_file.h
index 36e5c0ca7d..3ab6fef868 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -32,6 +32,7 @@
#define CONFIG_FILE_H
#include "core/ordered_hash_map.h"
+#include "core/os/file_access.h"
#include "core/reference.h"
class ConfigFile : public Reference {
@@ -42,6 +43,8 @@ class ConfigFile : public Reference {
PoolStringArray _get_sections() const;
PoolStringArray _get_section_keys(const String &p_section) const;
+ Error _internal_load(const String &p_path, FileAccess *f);
+ Error _internal_save(FileAccess *file);
protected:
static void _bind_methods();
@@ -61,6 +64,12 @@ public:
Error save(const String &p_path);
Error load(const String &p_path);
+ Error load_encrypted(const String &p_path, const Vector<uint8_t> &p_key);
+ Error load_encrypted_pass(const String &p_path, const String &p_pass);
+
+ Error save_encrypted(const String &p_path, const Vector<uint8_t> &p_key);
+ Error save_encrypted_pass(const String &p_path, const String &p_pass);
+
ConfigFile();
};
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 5dd167c581..d1c7f5c334 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -435,7 +435,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
_queue_page(page + j);
}
- buff = pages.write[page].buffer.ptrw();
//queue pages
buffer_mutex->unlock();
}
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 891fb7b0ca..c3626bfe31 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -775,7 +775,7 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
get_response_headers(&rh);
Dictionary ret;
for (const List<String>::Element *E = rh.front(); E; E = E->next()) {
- String s = E->get();
+ const String &s = E->get();
int sp = s.find(":");
if (sp == -1)
continue;
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 3c9c5bc2bb..17a3f52a65 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -683,8 +683,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
if (r_len)
(*r_len) += adv;
- len -= adv;
- buf += adv;
}
r_variant = varray;
@@ -721,8 +719,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
if (r_len)
(*r_len) += adv;
- len -= adv;
- buf += adv;
}
r_variant = varray;
@@ -760,8 +756,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
if (r_len)
(*r_len) += adv;
- len -= adv;
- buf += adv;
}
r_variant = carray;
@@ -1094,7 +1088,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
if (!obj) {
if (buf) {
encode_uint32(0, buf);
- buf += 4;
}
r_len += 4;
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 2779837190..33dc4dbde4 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -874,6 +874,7 @@ void MultiplayerAPI::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", 0), "set_network_peer", "get_network_peer");
+ ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false);
ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id")));
ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id")));
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
index 779dd043bd..5258dde5d7 100644
--- a/core/io/multiplayer_api.h
+++ b/core/io/multiplayer_api.h
@@ -77,7 +77,7 @@ protected:
void _process_raw(int p_from, const uint8_t *p_packet, int p_packet_len);
void _send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount);
- bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_from);
+ bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target);
public:
enum NetworkCommands {
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index 8920bbfb81..55685a2d9a 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -109,10 +109,7 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) {
Error PCKPacker::flush(bool p_verbose) {
- if (!file) {
- ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER);
- return ERR_INVALID_PARAMETER;
- };
+ ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER);
// write the index
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index aef2dcfff3..688dfc21e5 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -720,7 +720,7 @@ Error ResourceInteractiveLoaderBinary::poll() {
error = ERR_FILE_CORRUPT;
memdelete(obj); //bye
ERR_EXPLAIN(local_path + ":Resource type in resource field not a resource, type is: " + obj->get_class());
- ERR_FAIL_COND_V(!r, ERR_FILE_CORRUPT);
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
}
RES res = RES(r);
@@ -1694,7 +1694,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
int len = varray.size();
for (int i = 0; i < len; i++) {
- Variant v = varray.get(i);
+ const Variant &v = varray.get(i);
_find_resources(v);
}
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 45f3e46e35..bcdae343b8 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -352,7 +352,6 @@ void StreamPeerTCP::_bind_methods() {
StreamPeerTCP::StreamPeerTCP() :
_sock(Ref<NetSocket>(NetSocket::create())),
status(STATUS_NONE),
- peer_host(IP_Address()),
peer_port(0) {
}
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 6599c4eb5b..be87f47d50 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -83,11 +83,7 @@ bool TCP_Server::is_connection_available() const {
return false;
Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
- if (err != OK) {
- return false;
- }
-
- return true;
+ return (err == OK);
}
Ref<StreamPeerTCP> TCP_Server::take_connection() {