From 16c56fd6e23135895b73082c11a5ae6a321cc9f9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 2 Jan 2023 15:41:19 +0300 Subject: =?UTF-8?q?fixes=20#3288=20(Telegram:=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=81=D0=B5=D1=81=D1=81=D0=B8=D0=B8=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=83=D1=87?= =?UTF-8?q?=D1=91=D1=82=D0=BA=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/auth.cpp | 7 +------ protocols/Telegram/src/mt_proto.cpp | 11 ++++++----- protocols/Telegram/src/mt_proto.h | 7 ++++++- protocols/Telegram/src/server.cpp | 18 ++++++++++++++---- 4 files changed, 27 insertions(+), 16 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/auth.cpp b/protocols/Telegram/src/auth.cpp index 9591f5fc98..22254ea460 100644 --- a/protocols/Telegram/src/auth.cpp +++ b/protocols/Telegram/src/auth.cpp @@ -100,12 +100,7 @@ void CMTProto::ProcessAuth(TD::updateAuthorizationState *pObj) OnLoggedIn(); break; - case TD::authorizationStateLoggingOut::ID: - debugLogA("Server required us to log out, exiting"); - LogOut(); - break; - - case TD::authorizationStateClosing::ID: + case TD::authorizationStateClosed::ID: debugLogA("Connection terminated, exiting"); LogOut(); break; diff --git a/protocols/Telegram/src/mt_proto.cpp b/protocols/Telegram/src/mt_proto.cpp index a0e90d8573..a99c91eb31 100644 --- a/protocols/Telegram/src/mt_proto.cpp +++ b/protocols/Telegram/src/mt_proto.cpp @@ -19,7 +19,6 @@ static int CompareUsers(const TG_USER *p1, const TG_USER *p2) CMTProto::CMTProto(const char* protoName, const wchar_t* userName) : PROTO(protoName, userName), m_impl(*this), - m_pClientMmanager(std::make_unique()), m_arUsers(10, CompareUsers), m_arRequests(10, CompareRequests), m_szOwnPhone(this, "Phone"), @@ -28,7 +27,6 @@ CMTProto::CMTProto(const char* protoName, const wchar_t* userName) : m_bUsePopups(this, "UsePopups", true), m_bHideGroupchats(this, "HideChats", true) { - m_iClientId = m_pClientMmanager->create_client_id(); m_iOwnId = _atoi64(getMStringA(DBKEY_ID)); CreateProtoService(PS_CREATEACCMGRUI, &CMTProto::SvcCreateAccMgrUI); @@ -83,6 +81,9 @@ void CMTProto::OnShutdown() void CMTProto::OnErase() { + m_bUnregister = true; + ServerThread(0); + DeleteDirectoryTreeW(GetProtoFolder(), false); } @@ -135,19 +136,19 @@ int CMTProto::SetStatus(int iNewStatus) } if (m_iDesiredStatus == ID_STATUS_OFFLINE) { - if (m_bRunning) + if (isRunning()) SendQuery(new TD::close()); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); } - else if (!m_bRunning && !IsStatusConnecting(m_iStatus)) { + else if (!isRunning() && !IsStatusConnecting(m_iStatus)) { m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); ForkThread(&CMTProto::ServerThread); } - else if (m_bRunning) { + else if (isRunning()) { m_iStatus = m_iDesiredStatus; ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); } diff --git a/protocols/Telegram/src/mt_proto.h b/protocols/Telegram/src/mt_proto.h index 7f1011e996..5426ffaf6f 100644 --- a/protocols/Telegram/src/mt_proto.h +++ b/protocols/Telegram/src/mt_proto.h @@ -89,10 +89,14 @@ class CMTProto : public PROTO } } m_impl; + bool __forceinline isRunning() const + { return m_pClientMmanager != nullptr; + } + std::unique_ptr m_pClientMmanager; TD::object_ptr pAuthState; - bool m_bAuthorized, m_bRunning = false, m_bTerminated; + bool m_bAuthorized, m_bTerminated, m_bUnregister = false; int32_t m_iClientId, m_iMsgId; uint64_t m_iQueryId; @@ -108,6 +112,7 @@ class CMTProto : public PROTO void OnUpdateAuth(td::ClientManager::Response &response); void LogOut(void); + void OnEndSession(td::ClientManager::Response &response); void OnLoggedIn(void); void ProcessResponse(td::ClientManager::Response); void SendKeepAlive(void); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 8dede07c4c..8792000d59 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -17,18 +17,25 @@ along with this program. If not, see . #include "stdafx.h" +void CMTProto::OnEndSession(td::ClientManager::Response&) +{ + m_bTerminated = true; +} + void __cdecl CMTProto::ServerThread(void *) { - m_bRunning = true; m_bTerminated = m_bAuthorized = false; + m_pClientMmanager = std::make_unique(); + m_iClientId = m_pClientMmanager->create_client_id(); + SendQuery(new TD::getOption("version")); while (!m_bTerminated) { ProcessResponse(m_pClientMmanager->receive(1)); } - m_bRunning = false; + m_pClientMmanager = std::move(nullptr); } void CMTProto::LogOut() @@ -55,7 +62,11 @@ void CMTProto::OnLoggedIn() ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus); m_iStatus = m_iDesiredStatus; - SendQuery(new TD::getChats(td::tl::unique_ptr(), 1000)); + if (m_bUnregister) { + SendQuery(new TD::terminateSession()); + SendQuery(new TD::logOut(), &CMTProto::OnEndSession); + } + else SendQuery(new TD::getChats(td::tl::unique_ptr(), 1000)); } /////////////////////////////////////////////////////////////////////////////// @@ -254,7 +265,6 @@ void CMTProto::ProcessGroups(TD::updateChatFilters *pObj) Clist_GroupRename(oldGroup, wszFullGroup); setWString(szSetting, wszNewValue); } - } } -- cgit v1.2.3