From 0867c044fa55e0d1fdeb1c20e6392a454f08d893 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Wed, 12 Mar 2025 02:17:36 +0100 Subject: [PATCH] Handle CONNECTION_NOT_INITED --- .github/workflows/dev.yml | 2 +- src/Client.cs | 44 ++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 6130d21..a30001c 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -47,7 +47,7 @@ jobs: JSON: | { "status": "success", "complete": true, "commitMessage": ${{ toJSON(github.event.head_commit.message) }}, - "message": "{ \"commitId\": \"${{ github.event.head_commit.id }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"teamProjectName\": \"${{ github.event.repository.name }}\"}" + "message": "{ \"commitId\": \"${{ github.sha }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"repoName\": \"${{ github.repository }}\"}" } run: | curl -X POST -H "Content-Type: application/json" -d "$JSON" ${{ secrets.DEPLOYED_WEBHOOK }} diff --git a/src/Client.cs b/src/Client.cs index fa172e6..2dc60d6 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -985,23 +985,7 @@ namespace WTelegram else { if (_dcSession.Layer != 0 && _dcSession.Layer != Layer.Version) _dcSession.Renew(); - var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement); - TLConfig = await this.InvokeWithLayer(Layer.Version, - new TL.Methods.InitConnection - { - flags = TL.Methods.InitConnection.Flags.has_params, - api_id = _session.ApiId, - device_model = Config("device_model"), - system_version = Config("system_version"), - app_version = Config("app_version"), - system_lang_code = Config("system_lang_code"), - lang_pack = Config("lang_pack"), - lang_code = Config("lang_code"), - params_ = initParams, - query = new TL.Methods.Help_GetConfig() - }); - _dcSession.Layer = Layer.Version; - _session.DcOptions = TLConfig.dc_options; + await InitConnection(); if (_dcSession.DataCenter == null) { _dcSession.DataCenter = _session.DcOptions.Where(dc => dc.id == TLConfig.this_dc) @@ -1022,6 +1006,27 @@ namespace WTelegram Helpers.Log(2, $"Connected to {(TLConfig.test_mode ? "Test DC" : "DC")} {TLConfig.this_dc}... {TLConfig.flags & (Config.Flags)~0x18E00U}"); } + private async Task InitConnection() + { + var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement); + TLConfig = await this.InvokeWithLayer(Layer.Version, + new TL.Methods.InitConnection + { + flags = TL.Methods.InitConnection.Flags.has_params, + api_id = _session.ApiId, + device_model = Config("device_model"), + system_version = Config("system_version"), + app_version = Config("app_version"), + system_lang_code = Config("system_lang_code"), + lang_pack = Config("lang_pack"), + lang_code = Config("lang_code"), + params_ = initParams, + query = new TL.Methods.Help_GetConfig() + }); + _dcSession.Layer = Layer.Version; + _session.DcOptions = TLConfig.dc_options; + } + private async Task KeepAlive(CancellationToken ct) { int ping_id = _random.Next(); @@ -1615,6 +1620,11 @@ namespace WTelegram got503 = true; goto retry; } + else if (code == 400 && message == "CONNECTION_NOT_INITED") + { + await InitConnection(); + goto retry; + } else if (code == 500 && message == "AUTH_RESTART") { _session.UserId = 0; // force a full login authorization flow, next time