示例#1
0
        private async Task ReconnectToDcAsync(int dcId)
        {
            if (dcOptions == null || !dcOptions.Any())
            {
                throw new InvalidOperationException($"Can't reconnect. Establish initial connection first.");
            }

            TLExportedAuthorization exported = null;

            if (_session.TLUser != null)
            {
                TLRequestExportAuthorization exportAuthorization = new TLRequestExportAuthorization()
                {
                    DcId = dcId
                };
                exported = await SendRequestAsync <TLExportedAuthorization>(exportAuthorization);
            }

            var dc         = dcOptions.First(d => d.Id == dcId);
            var dataCenter = new DataCenter(dcId, dc.IpAddress, dc.Port);

            _transport          = new TcpTransport(dc.IpAddress, dc.Port, _handler);
            _session.DataCenter = dataCenter;

            await ConnectAsync(true);

            if (_session.TLUser != null)
            {
                TLRequestImportAuthorization importAuthorization = new TLRequestImportAuthorization()
                {
                    Id = exported.Id, Bytes = exported.Bytes
                };
                var imported = await SendRequestAsync <TLAuthorization>(importAuthorization);

                OnUserAuthenticated(((TLUser)imported.User));
            }
        }
示例#2
0
 internal Session(ulong id, AuthKey authKey, int sequence, ulong salt, int timeOffset, long lastMessageId, int expires, TLUser user, DataCenter dc)
 {
     this.Id        = id;
     AuthKey        = authKey;
     Sequence       = sequence;
     Salt           = salt;
     TimeOffset     = timeOffset;
     LastMessageId  = lastMessageId;
     SessionExpires = expires;
     TLUser         = user;
     DataCenter     = dc;
 }