diff --git a/td/telegram/ConfigShared.cpp b/td/telegram/ConfigShared.cpp index 0924bf557..4423cb16f 100644 --- a/td/telegram/ConfigShared.cpp +++ b/td/telegram/ConfigShared.cpp @@ -133,8 +133,8 @@ tl_object_ptr ConfigShared::get_option_value_object(Slice v return make_tl_object(value.str()); } -void ConfigShared::on_option_updated(Slice name) { - callback_->on_option_updated(name.str()); +void ConfigShared::on_option_updated(Slice name) const { + callback_->on_option_updated(name.str(), get_option(name)); } } // namespace td diff --git a/td/telegram/ConfigShared.h b/td/telegram/ConfigShared.h index fed5fa5f7..b6c7dbce2 100644 --- a/td/telegram/ConfigShared.h +++ b/td/telegram/ConfigShared.h @@ -25,7 +25,7 @@ class ConfigShared { Callback(const Callback &) = delete; Callback &operator=(const Callback &) = delete; virtual ~Callback() = default; - virtual void on_option_updated(const string &name) = 0; + virtual void on_option_updated(const string &name, const string &value) = 0; }; ConfigShared(BinlogPmcPtr config_pmc, unique_ptr callback); @@ -53,7 +53,7 @@ class ConfigShared { bool set_option(Slice name, Slice value); static tl_object_ptr get_option_value_object(Slice value); - void on_option_updated(Slice name); + void on_option_updated(Slice name) const; }; } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 2067f20db..9405e22b5 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4212,8 +4212,7 @@ void Td::on_config_option_updated(const string &name) { return; } if (name == "auth") { - on_authorization_lost(); - return; + return on_authorization_lost(); } else if (name == "saved_animations_limit") { return animations_manager_->on_update_saved_animations_limit(G()->shared_config().get_option_integer(name)); } else if (name == "recent_stickers_limit") { @@ -4675,7 +4674,18 @@ Status Td::init(DbKey key) { VLOG(td_init) << "Create ConfigManager and ConfigShared"; class ConfigSharedCallback : public ConfigShared::Callback { public: - void on_option_updated(const string &name) override { + void on_option_updated(const string &name, const string &value) override { + if (name == "is_emulator" && !G()->close_flag()) { + // it should be applied immediately, because it affects MtprotoHeader + if (G()->have_mtproto_header()) { + // can't use G()->shared_config(), because it may be not created yet + G()->mtproto_header().set_is_emulator(value == "Btrue"); + } + if (G()->have_net_query_dispatcher()) { + G()->net_query_dispatcher().update_mtproto_header(); + } + } + send_closure(G()->td(), &Td::on_config_option_updated, name); } }; @@ -5087,6 +5097,7 @@ Status Td::set_parameters(td_api::object_ptr parameters options.application_version += ", TDLib "; options.application_version += TDLIB_VERSION; } + options.is_emulator = false; options.proxy = Proxy(); G()->set_mtproto_header(std::make_unique(options)); @@ -6624,6 +6635,11 @@ void Td::on_request(uint64 id, td_api::setOption &request) { return; } break; + case 'i': + if (set_boolean_option("is_emulator")) { + return; + } + break; case 'o': if (request.name_ == "online") { if (value_constructor_id != td_api::optionValueBoolean::ID && diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 3ef76e95e..b130cc136 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -665,34 +665,40 @@ class CliClient final : public Actor { close_flag_ = false; ready_to_stop_ = false; - td_ = create_actor("ClientActor1", make_td_callback()); + bool test_init = false; + + if (test_init) { + td_ = create_actor("ClientActor1", make_td_callback()); + } td_ = create_actor("ClientActor2", make_td_callback()); ready_to_stop_ = false; - for (int i = 0; i < 4; i++) { - send_closure_later(td_, &ClientActor::request, std::numeric_limits::max(), - td_api::make_object(0.001 + 1000 * (i / 2))); + if (test_init) { + for (int i = 0; i < 4; i++) { + send_closure_later(td_, &ClientActor::request, std::numeric_limits::max(), + td_api::make_object(0.001 + 1000 * (i / 2))); + } + + send_request(td_api::make_object( + "@telegram /test_command https://telegram.org telegram.me @gif @test")); + + send_request(td_api::make_object("use_pfs")); + send_request(td_api::make_object( + "use_pfs", td_api::make_object(std::time(nullptr) / 86400 % 2 == 0))); + send_request(td_api::make_object("use_storage_optimizer", + td_api::make_object(false))); + + send_request(td_api::make_object(td_api::make_object())); + send_request(td_api::make_object()); + send_request(td_api::make_object()); + + auto bad_parameters = td_api::make_object(); + bad_parameters->database_directory_ = "/.."; + bad_parameters->api_id_ = api_id_; + bad_parameters->api_hash_ = api_hash_; + send_request(td_api::make_object(std::move(bad_parameters))); } - send_request(td_api::make_object( - "@telegram /test_command https://telegram.org telegram.me @gif @test")); - - send_request(td_api::make_object("use_pfs")); - send_request(td_api::make_object( - "use_pfs", td_api::make_object(std::time(nullptr) / 86400 % 2 == 0))); - send_request(td_api::make_object("use_storage_optimizer", - td_api::make_object(false))); - - send_request(td_api::make_object(td_api::make_object())); - send_request(td_api::make_object()); - send_request(td_api::make_object()); - - auto bad_parameters = td_api::make_object(); - bad_parameters->database_directory_ = "/.."; - bad_parameters->api_id_ = api_id_; - bad_parameters->api_hash_ = api_hash_; - send_request(td_api::make_object(std::move(bad_parameters))); - auto parameters = td_api::make_object(); parameters->use_test_dc_ = use_test_dc_; parameters->use_message_database_ = true; diff --git a/td/telegram/net/MtprotoHeader.cpp b/td/telegram/net/MtprotoHeader.cpp index f0e4f5d7a..83d33b447 100644 --- a/td/telegram/net/MtprotoHeader.cpp +++ b/td/telegram/net/MtprotoHeader.cpp @@ -28,9 +28,13 @@ class HeaderStorer { // system_lang_code:string lang_pack:string lang_code:string proxy:flags.0?InputClientProxy query:!X = X; store(static_cast(0x785188b8), storer); int32 flags = 0; - if (!is_anonymous && options.proxy.type() == Proxy::Type::Mtproto) { + bool have_proxy = !is_anonymous && options.proxy.type() == Proxy::Type::Mtproto; + if (have_proxy) { flags |= 1 << 0; } + if (options.is_emulator) { + flags |= 1 << 10; + } store(flags, storer); store(options.api_id, storer); if (is_anonymous) { @@ -44,7 +48,7 @@ class HeaderStorer { store(options.system_language_code, storer); store(string(), storer); store(string(), storer); - if ((flags & 1) != 0) { + if (have_proxy) { // inputClientProxy#75588b3f address:string port:int = InputClientProxy; store(static_cast(0x75588b3f), storer); store(Slice(options.proxy.server()), storer); diff --git a/td/telegram/net/MtprotoHeader.h b/td/telegram/net/MtprotoHeader.h index 5c9ec6032..c3621337a 100644 --- a/td/telegram/net/MtprotoHeader.h +++ b/td/telegram/net/MtprotoHeader.h @@ -20,6 +20,7 @@ class MtprotoHeader { string system_language_code; string device_model; string system_version; + bool is_emulator = false; string application_version; Proxy proxy; }; @@ -33,6 +34,11 @@ class MtprotoHeader { default_header_ = gen_header(options_, false); } + void set_is_emulator(bool is_emulator) { + options_.is_emulator = is_emulator; + default_header_ = gen_header(options_, false); + } + Slice get_default_header() const { return default_header_; }