sochix / TLSharp

Telegram client library implemented in C#
1k stars 380 forks source link

How to converted WEB telegram session to C# sochix library code? #577

Open JhonDon opened 7 years ago

JhonDon commented 7 years ago

In web telegram in webstorage params: dc2_auth_key dc2_server_salt dc etc.....

Sochix load session: AuthKey = new AuthKey(authData), Id = id, Salt = salt, Sequence = sequence, LastMessageId = lastMessageId, TimeOffset = timeOffset, SessionExpires = sessionExpires, TLUser = TLUser, SessionUserId = sessionUserId, ServerAddress = serverAddress, Port = port

How convert web to sochix session and run this session? Please help me)

JhonDon commented 7 years ago

I decided dc2_auth_key (hex) 512 length set in Session.cs

public static Session FromBytes(byte[] buffer, ISessionStore store, string sessionUserId){
......
- var authData = Serializers.Bytes.read(reader);
+ var authData = StringToByteArray("hex dc2_auth_key");
......
}

and +

public static byte[] StringToByteArray(string hex)
{
    return Enumerable.Range(0, hex.Length)
        .Where(x => x % 2 == 0)
        .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
        .ToArray();
}