fixed token loading crash
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -38,4 +38,5 @@ project/export/
|
||||
# venv
|
||||
venv/
|
||||
|
||||
|
||||
# docs
|
||||
src/gen/
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
static const char *_doc_data_hash = "-6554240314929274002";
|
||||
static const char *_doc_data_hash = "8311200392454987859";
|
||||
static const int _doc_data_uncompressed_size = 4148;
|
||||
static const int _doc_data_compressed_size = 684;
|
||||
static const unsigned char _doc_data_compressed[] = {
|
||||
|
@@ -35,40 +35,43 @@ DiscordConnector *DiscordConnector::get_singleton()
|
||||
void DiscordConnector::_ready()
|
||||
{
|
||||
client = std::make_shared<discordpp::Client>();
|
||||
if (auto_encryption_key == "" || !auto_token_manage)
|
||||
|
||||
if (Engine::get_singleton()->is_editor_hint() || editor_process)
|
||||
return;
|
||||
|
||||
if (auto_token_manage)
|
||||
{
|
||||
if (!Engine::get_singleton()->is_editor_hint() && !editor_process)
|
||||
if (auto_encryption_key.is_empty())
|
||||
{
|
||||
if (auto_connect)
|
||||
connect_user();
|
||||
auto_encryption_key = DiscordUtil::get_singleton()->generate_auto_encryption_key();
|
||||
}
|
||||
}
|
||||
else if (auto_token_manage)
|
||||
{
|
||||
ConfigFile config = DiscordUtil::get_singleton()->get_tokens(auto_encryption_key);
|
||||
if (config.has_section_key("tokens", "access_token") && config.has_section_key("tokens", "refresh_token") && config.has_section_key("tokens", "expires_in"))
|
||||
|
||||
Ref<godot::ConfigFile> config = DiscordUtil::get_singleton()->get_tokens(auto_encryption_key);
|
||||
if (config->has_section_key("tokens", "access_token") &&
|
||||
config->has_section_key("tokens", "refresh_token") &&
|
||||
config->has_section_key("tokens", "expires_in"))
|
||||
{
|
||||
access_token = config.get_value("tokens", "access_token");
|
||||
refresh_token = config.get_value("tokens", "refresh_token");
|
||||
expires_in = config.get_value("tokens", "expires_in");
|
||||
access_token = config->get_value("tokens", "access_token");
|
||||
refresh_token = config->get_value("tokens", "refresh_token");
|
||||
expires_in = config->get_value("tokens", "expires_in");
|
||||
update_user_token(access_token);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Engine::get_singleton()->is_editor_hint())
|
||||
DiscordUtil::get_singleton()->delete_tokens();
|
||||
if (auto_connect)
|
||||
{
|
||||
if (auto_encryption_key.is_empty() && auto_token_manage)
|
||||
{
|
||||
DiscordUtil::get_singleton()->delete_tokens();
|
||||
auto_encryption_key = DiscordUtil::get_singleton()->generate_auto_encryption_key();
|
||||
}
|
||||
if (auto_connect && !editor_process)
|
||||
{
|
||||
connect_user();
|
||||
}
|
||||
connect_user();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (auto_connect)
|
||||
{
|
||||
connect_user();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiscordConnector::_process(double delta)
|
||||
|
29
src/util.cpp
29
src/util.cpp
@@ -210,31 +210,34 @@ String DiscordUtil::generate_auto_encryption_key()
|
||||
|
||||
void DiscordUtil::save_tokens(String access_token, String refresh_token, int64_t expires_in, String auto_encryption_key)
|
||||
{
|
||||
ConfigFile config;
|
||||
config.set_value("tokens", "access_token", access_token);
|
||||
config.set_value("tokens", "refresh_token", refresh_token);
|
||||
config.set_value("tokens", "expires_in", expires_in);
|
||||
config.save_encrypted_pass("user://discord_data.binary", auto_encryption_key);
|
||||
Ref<ConfigFile> config;
|
||||
config.instantiate();
|
||||
config->set_value("tokens", "access_token", access_token);
|
||||
config->set_value("tokens", "refresh_token", refresh_token);
|
||||
config->set_value("tokens", "expires_in", expires_in);
|
||||
config->save_encrypted_pass("user://discord_data.binary", auto_encryption_key);
|
||||
}
|
||||
|
||||
void DiscordUtil::delete_tokens()
|
||||
{
|
||||
ConfigFile config;
|
||||
config.save("user://discord_data.binary");
|
||||
Ref<ConfigFile> config;
|
||||
config.instantiate();
|
||||
config->save("user://discord_data.binary");
|
||||
}
|
||||
|
||||
ConfigFile DiscordUtil::get_tokens(String auto_encryption_key)
|
||||
Ref<ConfigFile> DiscordUtil::get_tokens(String auto_encryption_key)
|
||||
{
|
||||
ConfigFile config;
|
||||
Ref<ConfigFile> config;
|
||||
config.instantiate();
|
||||
if (!FileAccess::file_exists("user://discord_data.binary"))
|
||||
{
|
||||
return ConfigFile();
|
||||
return config;
|
||||
}
|
||||
Error err = config.load_encrypted_pass("user://discord_data.binary", auto_encryption_key);
|
||||
Error err = config->load_encrypted_pass("user://discord_data.binary", auto_encryption_key);
|
||||
if (err != OK)
|
||||
{
|
||||
config.save("user://discord_data.binary");
|
||||
return ConfigFile();
|
||||
config->save("user://discord_data.binary");
|
||||
return config;
|
||||
}
|
||||
return config;
|
||||
}
|
@@ -35,7 +35,7 @@ public:
|
||||
void save_tokens(String access_token, String refresh_token, int64_t expires_in, String auto_encryption_key);
|
||||
String generate_auto_encryption_key();
|
||||
void delete_tokens();
|
||||
ConfigFile get_tokens(String auto_encryption_key);
|
||||
Ref<ConfigFile> get_tokens(String auto_encryption_key);
|
||||
|
||||
void debug();
|
||||
void run_callbacks();
|
||||
|
Reference in New Issue
Block a user