예제 #1
0
        async private void Go()
        {
            string proxy = "5.101.82.125:8000:Bj9BvB:fGtkgw";

            TcpClient TcpHandler(string address, int port)
            {
                string[] split      = proxy.Split(':');
                var      socksProxy = new HttpProxyClient(split[0], int.Parse(split[1]), split[2], split[3]);
                var      tcpClient  = socksProxy.CreateConnection(address, port);

                return(tcpClient);
            }

            if (File.Exists("session.dat"))
            {
                var client = new TelegramClient(apiId, apiHash, sessionUserId: "session", handler: TcpHandler);
                await client.ConnectAsync();

                FileSessionStore     store = new FileSessionStore();
                TLSharp.Core.Session s     = null; s = store.Load("session");
                //var hash = await client.SendCodeRequestAsync("79029828756");
                //string code = await GetCode();

                //var user = await client.MakeAuthAsync("79029828756", hash, code);
                var userByPhoneId = await client.SearchUserAsync("79029828756");
            }
            else
            {
                var client = new TelegramClient(apiId, apiHash, handler: TcpHandler);
                await client.ConnectAsync();

                var hash = await client.SendCodeRequestAsync("79029828756");

                string code = await GetCode();

                var user = await client.MakeAuthAsync("79029828756", hash, code);
            }
        }
예제 #2
-1
파일: Session.cs 프로젝트: ra0o0f/TLSharp
		public void Save(Session session)
		{
			using (var stream = new FileStream($"{session.SessionUserId}.dat", FileMode.OpenOrCreate))
			{
				var result = session.ToBytes();
				stream.Write(result, 0, result.Length);
			}
		}
예제 #3
-1
        public TelegramClient(ISessionStore store, string sessionUserId)
		{
			if (_apiId == 0)
				throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");

			if (string.IsNullOrEmpty(_apiHash))
				throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");

			_transport = new TcpTransport();
			_session = Session.TryLoadOrCreateNew(store, sessionUserId);
		}
예제 #4
-1
파일: Session.cs 프로젝트: ra0o0f/TLSharp
		public void Save(Session session)
		{
			
		}
예제 #5
-1
파일: Session.cs 프로젝트: ra0o0f/TLSharp
		public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
		{
			Session session;

			try
			{
				session = store.Load(sessionUserId);
			}
			catch
			{
				session = new Session(store) { Id = GenerateRandomUlong(), SessionUserId = sessionUserId };
			}

			return session;
		}
예제 #6
-1
		public TelegramClient(ISessionStore store, string sessionUserId)
		{
			_transport = new TcpTransport();
			_session = Session.TryLoadOrCreateNew(store, sessionUserId);
		}
예제 #7
-1
		public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
		{
			Session session;

			try
			{
				session = store.Load(sessionUserId);
			}
			catch
			{
				session = new Session(store)
				{
					Id = GenerateRandomUlong(),
					SessionUserId = sessionUserId,
					ServerAddress = defaultConnectionAddress,
					Port = defaultConnectionPort
				};
			}

			return session;
		}