Generator creates the mapping table.

Added a delay for SignUp
This commit is contained in:
Wizou 2021-08-06 20:17:19 +02:00
parent 6315b78803
commit 498aa2c319
7 changed files with 2620 additions and 1306 deletions

View file

@ -222,7 +222,7 @@ namespace WTelegram
if (length != data.Length - 20) throw new ApplicationException($"Unexpected unencrypted length {length} != {data.Length - 20}");
var ctorNb = reader.ReadUInt32();
if (!Schema.Mappings.TryGetValue(ctorNb, out var realType))
if (!Schema.Table.TryGetValue(ctorNb, out var realType))
throw new ApplicationException($"Cannot find type for ctor #{ctorNb:x}");
Helpers.Log(1, $"Receiving {realType.Name,-50} timestamp={_session.MsgIdToStamp(msgId)} isResponse={(msgId & 2) != 0} unencrypted");
return Schema.DeserializeObject(reader, realType);
@ -256,7 +256,7 @@ namespace WTelegram
throw new ApplicationException($"Mismatch between MsgKey & decrypted SHA1");
var ctorNb = reader.ReadUInt32();
if (!Schema.Mappings.TryGetValue(ctorNb, out var realType))
if (!Schema.Table.TryGetValue(ctorNb, out var realType))
throw new ApplicationException($"Cannot find type for ctor #{ctorNb:x}");
Helpers.Log(1, $"Receiving {realType.Name,-50} timestamp={_session.MsgIdToStamp(msgId)} isResponse={(msgId & 2) != 0} {(seqno == -1 ? "clearText" : "isContent")}={(seqno & 1) != 0}");
if (realType == typeof(RpcResult))
@ -434,15 +434,19 @@ namespace WTelegram
}
if (authorization is Auth_AuthorizationSignUpRequired signUpRequired)
{
var waitUntil = DateTime.UtcNow.AddSeconds(3);
if (signUpRequired.terms_of_service != null && _updateHandler != null)
await _updateHandler?.Invoke(signUpRequired.terms_of_service); // give caller the possibility to read and accept TOS
authorization = await CallAsync(new Fn.Auth_SignUp
var signUp = new Fn.Auth_SignUp
{
phone_number = phone_number,
phone_code_hash = sentCode.phone_code_hash,
first_name = Config("first_name"),
last_name = Config("last_name"),
});
};
var wait = waitUntil - DateTime.UtcNow;
if (wait > TimeSpan.Zero) await Task.Delay(wait); // we get a FLOOD_WAIT_3 if we SignUp too fast
authorization = await CallAsync(signUp);
}
if (authorization is not Auth_Authorization { user: User user })
throw new ApplicationException("Failed to get Authorization: " + authorization.GetType().Name);

View file

@ -8,18 +8,17 @@ namespace WTelegram
{
public static class Generator
{
//TODO: generate/merge ctor mapping table to avoid creating those at runtime from TLDefAttribute
//TODO: generate BinaryReader/Writer serialization directly to avoid using Reflection
//TODO: generate partial class with methods for functions to avoid using request classes
//TODO: generate partial class with methods for functions instead of exposing request classes
public static void FromJson(string jsonPath, string outputCs)
public static void FromJson(string jsonPath, string outputCs, string tableCs = null)
{
var schema = JsonSerializer.Deserialize<SchemaJson>(File.ReadAllText(jsonPath));
using var sw = File.CreateText(outputCs);
sw.WriteLine("using System;");
sw.WriteLine();
sw.WriteLine("namespace TL");
sw.WriteLine("{");
sw.Write("{");
string tabIndent = "\t";
Dictionary<string, TypeInfo> typeInfos = new();
foreach (var ctor in schema.constructors)
@ -70,25 +69,30 @@ namespace WTelegram
foreach (var typeInfo in typeInfos.Values)
WriteTypeInfo(sw, typeInfo);
sw.WriteLine();
sw.WriteLine("\tpublic static partial class Fn // ---functions---");
sw.WriteLine("\t{");
sw.Write("\t{");
tabIndent = "\t\t";
var methods = new List<TypeInfo>();
foreach (var method in schema.methods)
{
var typeInfo = new TypeInfo { ReturnName = method.type };
typeInfo.Structs.Add(new Constructor { id = method.id, @params = method.@params, predicate = method.method, type = method.type });
methods.Add(typeInfo);
WriteTypeInfo(sw, typeInfo, true);
}
sw.WriteLine("\t}");
sw.WriteLine("}");
if (tableCs != null) UpdateTable();
void WriteTypeInfo(StreamWriter sw, TypeInfo typeInfo, bool isMethod = false)
{
var parentClass = typeInfo.NeedAbstract != 0 ? typeInfo.ReturnName : "ITLObject";
var genericType = typeInfo.ReturnName.Length == 1 ? $"<{typeInfo.ReturnName}>" : null;
if (isMethod)
parentClass = $"ITLFunction<{MapType(typeInfo.ReturnName, "")}>";
sw.WriteLine();
if (typeInfo.NeedAbstract == -1)
sw.WriteLine($"{tabIndent}public abstract class {parentClass} : ITLObject {{ }}");
int skipParams = 0;
@ -100,10 +104,10 @@ namespace WTelegram
else
{
int ctorId = int.Parse(ctor.id);
sw.Write($"{tabIndent}[TLDef(0x{ctorId:X}, \"{ctor.predicate}#{ctorId:x8} ");
sw.Write($"{tabIndent}[TLDef(0x{ctorId:X8})] //{ctor.predicate}#{ctorId:x8} ");
if (genericType != null) sw.Write($"{{{typeInfo.ReturnName}:Type}} ");
foreach (var parm in ctor.@params) sw.Write($"{parm.name}:{parm.type} ");
sw.WriteLine($"= {ctor.type}\")]");
sw.WriteLine($"= {ctor.type}");
sw.Write($"{tabIndent}public class {className} : ");
sw.Write(skipParams == 0 && typeInfo.NeedAbstract > 0 ? "ITLObject" : parentClass);
}
@ -176,7 +180,6 @@ namespace WTelegram
sw.WriteLine(" }");
skipParams = typeInfo.NeedAbstract;
}
sw.WriteLine();
string MapName(string name) => name switch
{
"out" => "out_",
@ -221,6 +224,38 @@ namespace WTelegram
return type;
}
}
void UpdateTable()
{
var myTag = $"\t\t\t// from {Path.GetFileNameWithoutExtension(jsonPath)}:";
using (var sr = new StreamReader(tableCs))
using (var sw = new StreamWriter(tableCs + ".new"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
sw.WriteLine(line);
if (line == myTag)
{
foreach (var typeInfo in typeInfos.Values)
foreach (var ctor in typeInfo.Structs)
if (ctor.id != null)
sw.WriteLine($"\t\t\t[0x{int.Parse(ctor.id):X8}] = typeof({CSharpName(ctor.predicate)}),");
foreach (var typeInfo in methods)
foreach (var ctor in typeInfo.Structs)
{
var generic = typeInfo.ReturnName.Length == 1 ? "<>" : "";
sw.WriteLine($"\t\t\t[0x{int.Parse(ctor.id):X8}] = typeof(Fn.{CSharpName(ctor.predicate)}{generic}),");
}
while ((line = sr.ReadLine()) != null)
if (line.StartsWith("\t\t\t// "))
break;
sw.WriteLine(line);
}
}
}
File.Replace(tableCs + ".new", tableCs, null);
}
}
static readonly HashSet<string> ctorNeedClone = new() { /*"User"*/ };

View file

@ -2,7 +2,7 @@
namespace TL
{
[TLDef(0x5162463, "resPQ#05162463 nonce:int128 server_nonce:int128 pq:bytes server_public_key_fingerprints:Vector<long> = ResPQ")]
[TLDef(0x05162463)] //resPQ#05162463 nonce:int128 server_nonce:int128 pq:bytes server_public_key_fingerprints:Vector<long> = ResPQ
public class ResPQ : ITLObject
{
public Int128 nonce;
@ -11,7 +11,7 @@ namespace TL
public long[] server_public_key_fingerprints;
}
[TLDef(0X83C95AEC, "p_q_inner_data# pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 = P_Q_inner_data")]
[TLDef(0x83C95AEC)] //p_q_inner_data# pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 = P_Q_inner_data
public class PQInnerData : ITLObject
{
public byte[] pq;
@ -21,12 +21,12 @@ namespace TL
public Int128 server_nonce;
public Int256 new_nonce;
}
[TLDef(0xA9F55F95, "p_q_inner_data_dc#a9f55f95 pq:bytes p:bytes q:bytes nonce:int128 server_nonce:int128 new_nonce:int256 dc:int = P_Q_inner_data")]
[TLDef(0xA9F55F95)] //p_q_inner_data_dc#a9f55f95 pq:bytes p:bytes q:bytes nonce:int128 server_nonce:int128 new_nonce:int256 dc:int = P_Q_inner_data
public class PQInnerDataDC : PQInnerData
{
public int dc;
}
[TLDef(0x56FDDF88, "p_q_inner_data_temp_dc#56fddf88 pq:bytes p:bytes q:bytes nonce:int128 server_nonce:int128 new_nonce:int256 dc:int expires_in:int = P_Q_inner_data")]
[TLDef(0x56FDDF88)] //p_q_inner_data_temp_dc#56fddf88 pq:bytes p:bytes q:bytes nonce:int128 server_nonce:int128 new_nonce:int256 dc:int expires_in:int = P_Q_inner_data
public class PQInnerDataTempDC : PQInnerData
{
public int dc;
@ -38,12 +38,12 @@ namespace TL
public Int128 nonce;
public Int128 server_nonce;
}
[TLDef(0X79CB045D, "server_DH_params_fail#79cb045d nonce:int128 server_nonce:int128 new_nonce_hash:int128 = Server_DH_Params")]
[TLDef(0x79CB045D)] //server_DH_params_fail#79cb045d nonce:int128 server_nonce:int128 new_nonce_hash:int128 = Server_DH_Params
public class ServerDHParamsFail : ServerDHParams { public Int128 new_nonce_hash; }
[TLDef(0XD0E8075C, "server_DH_params_ok#d0e8075c nonce:int128 server_nonce:int128 encrypted_answer:bytes = Server_DH_Params")]
[TLDef(0xD0E8075C)] //server_DH_params_ok#d0e8075c nonce:int128 server_nonce:int128 encrypted_answer:bytes = Server_DH_Params
public class ServerDHParamsOk : ServerDHParams { public byte[] encrypted_answer; }
[TLDef(0xB5890DBA, "server_DH_inner_data#b5890dba nonce:int128 server_nonce:int128 g:int dh_prime:bytes g_a:bytes server_time:int = Server_DH_inner_data")]
[TLDef(0xB5890DBA)] //server_DH_inner_data#b5890dba nonce:int128 server_nonce:int128 g:int dh_prime:bytes g_a:bytes server_time:int = Server_DH_inner_data
public class ServerDHInnerData : ITLObject
{
public Int128 nonce;
@ -54,7 +54,7 @@ namespace TL
public DateTime server_time;
}
[TLDef(0x6643B654, "client_DH_inner_data#6643b654 nonce:int128 server_nonce:int128 retry_id:long g_b:bytes = Client_DH_Inner_Data")]
[TLDef(0x6643B654)] //client_DH_inner_data#6643b654 nonce:int128 server_nonce:int128 retry_id:long g_b:bytes = Client_DH_Inner_Data
public class ClientDHInnerData : ITLObject
{
public Int128 nonce;
@ -69,14 +69,14 @@ namespace TL
public Int128 server_nonce;
public Int128 new_nonce_hashN; // 16 low order bytes from SHA1(new_nonce + (01=ok, 02=retry, 03=fail) + 8 high order bytes from SHA1(auth_key))
}
[TLDef(0x3BCBF734, "dh_gen_ok#3bcbf734 nonce:int128 server_nonce:int128 new_nonce_hash1:int128 = Set_client_DH_params_answer")]
[TLDef(0x3BCBF734)] //dh_gen_ok#3bcbf734 nonce:int128 server_nonce:int128 new_nonce_hash1:int128 = Set_client_DH_params_answer
public class DHGenOk : SetClientDHParamsAnswer { }
[TLDef(0x46DC1FB9, "dh_gen_retry#46dc1fb9 nonce:int128 server_nonce:int128 new_nonce_hash2:int128 = Set_client_DH_params_answer")]
[TLDef(0x46DC1FB9)] //dh_gen_retry#46dc1fb9 nonce:int128 server_nonce:int128 new_nonce_hash2:int128 = Set_client_DH_params_answer
public class DHGenRetry : SetClientDHParamsAnswer { }
[TLDef(0xA69DAE02, "dh_gen_fail#a69dae02 nonce:int128 server_nonce:int128 new_nonce_hash3:int128 = Set_client_DH_params_answer")]
[TLDef(0xA69DAE02)] //dh_gen_fail#a69dae02 nonce:int128 server_nonce:int128 new_nonce_hash3:int128 = Set_client_DH_params_answer
public class DHGenFail : SetClientDHParamsAnswer { }
[TLDef(0x75A3F765, "bind_auth_key_inner#75a3f765 nonce:long temp_auth_key_id:long perm_auth_key_id:long temp_session_id:long expires_at:int = BindAuthKeyInner")]
[TLDef(0x75A3F765)] //bind_auth_key_inner#75a3f765 nonce:long temp_auth_key_id:long perm_auth_key_id:long temp_session_id:long expires_at:int = BindAuthKeyInner
public class BindAuthKeyInner : ITLObject
{
public long nonce;
@ -86,14 +86,14 @@ namespace TL
public DateTime expires_at;
}
[TLDef(0xF35C6D01, "rpc_result#f35c6d01 req_msg_id:long result:Object = RpcResult")]
[TLDef(0xF35C6D01)] //rpc_result#f35c6d01 req_msg_id:long result:Object = RpcResult
public class RpcResult : ITLObject
{
public long req_msg_id;
public object result;
}
[TLDef(0x2144CA19, "rpc_error#2144ca19 error_code:int error_message:string = RpcError")]
[TLDef(0x2144CA19)] //rpc_error#2144ca19 error_code:int error_message:string = RpcError
public class RpcError : ITLObject
{
public int error_code;
@ -101,11 +101,11 @@ namespace TL
}
public abstract class RpcDropAnswer : ITLObject { }
[TLDef(0x5E2AD36E, "rpc_answer_unknown#5e2ad36e = RpcDropAnswer")]
[TLDef(0x5E2AD36E)] //rpc_answer_unknown#5e2ad36e = RpcDropAnswer
public class RpcAnswerUnknown : RpcDropAnswer { }
[TLDef(0xCD78E586, "rpc_answer_dropped_running#cd78e586 = RpcDropAnswer")]
[TLDef(0xCD78E586)] //rpc_answer_dropped_running#cd78e586 = RpcDropAnswer
public class RpcAnswerDroppedRunning : RpcDropAnswer { }
[TLDef(0xA43AD8B7, "rpc_answer_dropped#a43ad8b7 msg_id:long seq_no:int bytes:int = RpcDropAnswer")]
[TLDef(0xA43AD8B7)] //rpc_answer_dropped#a43ad8b7 msg_id:long seq_no:int bytes:int = RpcDropAnswer
public class RpcAnswerDropped : RpcDropAnswer
{
public long msg_id;
@ -113,7 +113,7 @@ namespace TL
public int bytes;
}
[TLDef(0x949D9DC, "future_salt#0949d9dc valid_since:int valid_until:int salt:long = FutureSalt")]
[TLDef(0x949D9DC)] //future_salt#0949d9dc valid_since:int valid_until:int salt:long = FutureSalt
public class FutureSalt : ITLObject
{
public DateTime valid_since;
@ -121,7 +121,7 @@ namespace TL
public long salt;
}
[TLDef(0xAE500895, "future_salts#ae500895 req_msg_id:long now:int salts:vector<future_salt> = FutureSalts")]
[TLDef(0xAE500895)] //future_salts#ae500895 req_msg_id:long now:int salts:vector<future_salt> = FutureSalts
public class FutureSalts : ITLObject
{
public long req_msg_id;
@ -129,7 +129,7 @@ namespace TL
public FutureSalt[] salts;
}
[TLDef(0x347773C5, "pong#347773c5 msg_id:long ping_id:long = Pong")]
[TLDef(0x347773C5)] //pong#347773c5 msg_id:long ping_id:long = Pong
public class Pong : ITLObject
{
public long msg_id;
@ -137,13 +137,13 @@ namespace TL
}
public abstract class DestroySessionRes : ITLObject { public long session_id; }
[TLDef(0xE22045FC, "destroy_session_ok#e22045fc session_id:long = DestroySessionRes")]
[TLDef(0xE22045FC)] //destroy_session_ok#e22045fc session_id:long = DestroySessionRes
public class DestroySessionOk : DestroySessionRes { }
[TLDef(0x62D350C9, "destroy_session_none#62d350c9 session_id:long = DestroySessionRes")]
[TLDef(0x62D350C9)] //destroy_session_none#62d350c9 session_id:long = DestroySessionRes
public class DestroySessionNone : DestroySessionRes { }
public abstract class NewSession : ITLObject { }
[TLDef(0x9EC20908, "new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession")]
[TLDef(0x9EC20908)] //new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession
public class NewSessionCreated : NewSession
{
public long first_msg_id;
@ -152,11 +152,11 @@ namespace TL
}
public abstract class MessageContainer : ITLObject { }
[TLDef(0x73F1F8DC, "msg_container#73f1f8dc messages:vector<%Message> = MessageContainer")]
[TLDef(0x73F1F8DC)] //msg_container#73f1f8dc messages:vector<%Message> = MessageContainer
public class MsgContainer : MessageContainer { public _Message[] messages; }
#pragma warning disable IDE1006 // Naming Styles
//[TLDef("message msg_id:long seqno:int bytes:int body:Object = Message")]
//[TLDef(0x5BB8E511)] //message#5bb8e511 msg_id:long seqno:int bytes:int body:Object = Message
public class _Message
{
public long msg_id;
@ -167,39 +167,39 @@ namespace TL
#pragma warning restore IDE1006 // Naming Styles
public abstract class MessageCopy : ITLObject { }
[TLDef(0xE06046B2, "msg_copy#e06046b2 orig_message:Message = MessageCopy")]
[TLDef(0xE06046B2)] //msg_copy#e06046b2 orig_message:Message = MessageCopy
public class MsgCopy : MessageCopy { public _Message orig_message; }
[TLDef(0x3072CFA1, "gzip_packed#3072cfa1 packed_data:bytes = Object")]
[TLDef(0x3072CFA1)] //gzip_packed#3072cfa1 packed_data:bytes = Object
public class GzipPacked : ITLObject { public byte[] packed_data; }
[TLDef(0x62D6B459, "msgs_ack#62d6b459 msg_ids:Vector<long> = MsgsAck")]
[TLDef(0x62D6B459)] //msgs_ack#62d6b459 msg_ids:Vector<long> = MsgsAck
public class MsgsAck : ITLObject { public long[] msg_ids; }
[TLDef(0xA7EFF811, "bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int error_code:int = BadMsgNotification")]
[TLDef(0xA7EFF811)] //bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int error_code:int = BadMsgNotification
public class BadMsgNotification : ITLObject
{
public long bad_msg_id;
public int bad_msg_seqno;
public int error_code;
}
[TLDef(0xEDAB447B, "bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int error_code:int new_server_salt:long = BadMsgNotification")]
[TLDef(0xEDAB447B)] //bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int error_code:int new_server_salt:long = BadMsgNotification
public class BadServerSalt : BadMsgNotification { public long new_server_salt; }
[TLDef(0x7D861A08, "msg_resend_req#7d861a08 msg_ids:Vector<long> = MsgResendReq")]
[TLDef(0x7D861A08)] //msg_resend_req#7d861a08 msg_ids:Vector<long> = MsgResendReq
public class MsgResendReq : ITLObject { public long[] msg_ids; }
[TLDef(0xDA69FB52, "msgs_state_req#da69fb52 msg_ids:Vector<long> = MsgsStateReq")]
[TLDef(0xDA69FB52)] //msgs_state_req#da69fb52 msg_ids:Vector<long> = MsgsStateReq
public class MsgsStateReq : ITLObject { public long[] msg_ids; }
[TLDef(0x4DEB57D, "msgs_state_info#04deb57d req_msg_id:long info:bytes = MsgsStateInfo")]
[TLDef(0x04DEB57D)] //msgs_state_info#04deb57d req_msg_id:long info:bytes = MsgsStateInfo
public class MsgsStateInfo : ITLObject
{
public long req_msg_id;
public byte[] info;
}
[TLDef(0x8CC0D131, "msgs_all_info#8cc0d131 msg_ids:Vector<long> info:bytes = MsgsAllInfo")]
[TLDef(0x8CC0D131)] //msgs_all_info#8cc0d131 msg_ids:Vector<long> info:bytes = MsgsAllInfo
public class MsgsAllInfo : ITLObject
{
public long[] msg_ids;
@ -207,7 +207,7 @@ namespace TL
}
public abstract class MsgDetailedInfoBase : ITLObject { }
[TLDef(0x276D3EC6, "msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long bytes:int status:int = MsgDetailedInfo")]
[TLDef(0x276D3EC6)] //msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long bytes:int status:int = MsgDetailedInfo
public class MsgDetailedInfo : MsgDetailedInfoBase
{
public long msg_id;
@ -215,7 +215,7 @@ namespace TL
public int bytes;
public int status;
}
[TLDef(0x809DB6DF, "msg_new_detailed_info#809db6df answer_msg_id:long bytes:int status:int = MsgDetailedInfo")]
[TLDef(0x809DB6DF)] //msg_new_detailed_info#809db6df answer_msg_id:long bytes:int status:int = MsgDetailedInfo
public class MsgNewDetailedInfo : MsgDetailedInfoBase
{
public long answer_msg_id;
@ -223,7 +223,7 @@ namespace TL
public int status;
}
[TLDef(0x7A19CB76, "rsa_public_key n:string e:string = RSAPublicKey")]
[TLDef(0x7A19CB76)] //rsa_public_key n:string e:string = RSAPublicKey
public class RSAPublicKey : ITLObject
{
public byte[] n;
@ -231,21 +231,21 @@ namespace TL
}
public abstract class DestroyAuthKeyRes : ITLObject { }
[TLDef(0xF660E1D4, "destroy_auth_key_ok#f660e1d4 = DestroyAuthKeyRes")]
[TLDef(0xF660E1D4)] //destroy_auth_key_ok#f660e1d4 = DestroyAuthKeyRes
public class DestroyAuthKeyOk : DestroyAuthKeyRes { }
[TLDef(0xA9F2259, "destroy_auth_key_none#0a9f2259 = DestroyAuthKeyRes")]
[TLDef(0x0A9F2259)] //destroy_auth_key_none#0a9f2259 = DestroyAuthKeyRes
public class DestroyAuthKeyNone : DestroyAuthKeyRes { }
[TLDef(0xEA109B13, "destroy_auth_key_fail#ea109b13 = DestroyAuthKeyRes")]
[TLDef(0xEA109B13)] //destroy_auth_key_fail#ea109b13 = DestroyAuthKeyRes
public class DestroyAuthKeyFail : DestroyAuthKeyRes { }
public static partial class Fn // ---functions---
{
[TLDef(0X60469778, "req_pq#60469778 nonce:int128 = ResPQ")]
[TLDef(0x60469778)] //req_pq#60469778 nonce:int128 = ResPQ
public class ReqPQ : ITLFunction<ResPQ> { public Int128 nonce; }
[TLDef(0xBE7E8EF1, "req_pq_multi#be7e8ef1 nonce:int128 = ResPQ")]
[TLDef(0xBE7E8EF1)] //req_pq_multi#be7e8ef1 nonce:int128 = ResPQ
public class ReqPQmulti : ResPQ { }
[TLDef(0xD712E4BE, "req_DH_params#d712e4be nonce:int128 server_nonce:int128 p:bytes q:bytes public_key_fingerprint:long encrypted_data:bytes = Server_DH_Params")]
[TLDef(0xD712E4BE)] //req_DH_params#d712e4be nonce:int128 server_nonce:int128 p:bytes q:bytes public_key_fingerprint:long encrypted_data:bytes = Server_DH_Params
public class ReqDHParams : ITLFunction<ServerDHParams>
{
public Int128 nonce;
@ -256,7 +256,7 @@ namespace TL
public byte[] encrypted_data;
}
[TLDef(0xF5045F1F, "set_client_DH_params#f5045f1f nonce:int128 server_nonce:int128 encrypted_data:bytes = Set_client_DH_params_answer")]
[TLDef(0xF5045F1F)] //set_client_DH_params#f5045f1f nonce:int128 server_nonce:int128 encrypted_data:bytes = Set_client_DH_params_answer
public class SetClientDHParams : ITLFunction<SetClientDHParamsAnswer>
{
public Int128 nonce;
@ -264,26 +264,26 @@ namespace TL
public byte[] encrypted_data;
}
[TLDef(0x58E4A740, "rpc_drop_answer#58e4a740 req_msg_id:long = RpcDropAnswer")]
[TLDef(0x58E4A740)] //rpc_drop_answer#58e4a740 req_msg_id:long = RpcDropAnswer
public class ReqRpcDropAnswer : ITLFunction<RpcDropAnswer> { public long req_msg_id; }
[TLDef(0xB921BD04, "get_future_salts#b921bd04 num:int = FutureSalts")]
[TLDef(0xB921BD04)] //get_future_salts#b921bd04 num:int = FutureSalts
public class GetFutureSalts : ITLFunction<FutureSalts> { public int num; }
[TLDef(0x7ABE77EC, "ping#7abe77ec ping_id:long = Pong")]
[TLDef(0x7ABE77EC)] //ping#7abe77ec ping_id:long = Pong
public class Ping : ITLFunction<Pong> { public long ping_id; }
[TLDef(0xF3427B8C, "ping_delay_disconnect#f3427b8c ping_id:long disconnect_delay:int = Pong")]
[TLDef(0xF3427B8C)] //ping_delay_disconnect#f3427b8c ping_id:long disconnect_delay:int = Pong
public class PingDelayDisconnect : ITLFunction<Pong>
{
public long ping_id;
public int disconnect_delay; // seconds
}
[TLDef(0xE7512126, "destroy_session#e7512126 session_id:long = DestroySessionRes")]
[TLDef(0xE7512126)] //destroy_session#e7512126 session_id:long = DestroySessionRes
public class DestroySession : ITLFunction<DestroySessionRes> { public long session_id; }
[TLDef(0x9299359F, "http_wait#9299359f max_delay:int wait_after:int max_wait:int = HttpWait")]
[TLDef(0x9299359F)] //http_wait#9299359f max_delay:int wait_after:int max_wait:int = HttpWait
public class HttpWait : ITLObject
{
public int max_delay; // ms
@ -291,8 +291,7 @@ namespace TL
public int max_wait; // ms
}
[TLDef(0xD1435160, "destroy_auth_key#d1435160 = DestroyAuthKeyRes")]
[TLDef(0xD1435160)] //destroy_auth_key#d1435160 = DestroyAuthKeyRes
public class DestroyAuthKey : ITLFunction<DestroyAuthKeyRes> { }
}
}

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@ using System;
namespace TL
{
public abstract class DecryptedMessageBase : ITLObject { }
[TLDef(0x1F814F1F, "decryptedMessage#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage")]
[TLDef(0x1F814F1F)] //decryptedMessage#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage
public class DecryptedMessage : DecryptedMessageBase
{
public long random_id;
@ -11,7 +11,7 @@ namespace TL
public string message;
public DecryptedMessageMedia media;
}
[TLDef(0xAA48327D, "decryptedMessageService#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage")]
[TLDef(0xAA48327D)] //decryptedMessageService#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage
public class DecryptedMessageService : DecryptedMessageBase
{
public long random_id;
@ -20,9 +20,9 @@ namespace TL
}
public abstract class DecryptedMessageMedia : ITLObject { }
[TLDef(0x89F5C4A, "decryptedMessageMediaEmpty#089f5c4a = DecryptedMessageMedia")]
[TLDef(0x089F5C4A)] //decryptedMessageMediaEmpty#089f5c4a = DecryptedMessageMedia
public class DecryptedMessageMediaEmpty : DecryptedMessageMedia { }
[TLDef(0x32798A8C, "decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia")]
[TLDef(0x32798A8C)] //decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaPhoto : DecryptedMessageMedia
{
public byte[] thumb;
@ -34,7 +34,7 @@ namespace TL
public byte[] key;
public byte[] iv;
}
[TLDef(0x4CEE6EF3, "decryptedMessageMediaVideo#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia")]
[TLDef(0x4CEE6EF3)] //decryptedMessageMediaVideo#4cee6ef3 thumb:bytes thumb_w:int thumb_h:int duration:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaVideo : DecryptedMessageMedia
{
public byte[] thumb;
@ -47,13 +47,13 @@ namespace TL
public byte[] key;
public byte[] iv;
}
[TLDef(0x35480A59, "decryptedMessageMediaGeoPoint#35480a59 lat:double long:double = DecryptedMessageMedia")]
[TLDef(0x35480A59)] //decryptedMessageMediaGeoPoint#35480a59 lat:double long:double = DecryptedMessageMedia
public class DecryptedMessageMediaGeoPoint : DecryptedMessageMedia
{
public double lat;
public double long_;
}
[TLDef(0x588A0A97, "decryptedMessageMediaContact#588a0a97 phone_number:string first_name:string last_name:string user_id:int = DecryptedMessageMedia")]
[TLDef(0x588A0A97)] //decryptedMessageMediaContact#588a0a97 phone_number:string first_name:string last_name:string user_id:int = DecryptedMessageMedia
public class DecryptedMessageMediaContact : DecryptedMessageMedia
{
public string phone_number;
@ -61,7 +61,7 @@ namespace TL
public string last_name;
public int user_id;
}
[TLDef(0xB095434B, "decryptedMessageMediaDocument#b095434b thumb:bytes thumb_w:int thumb_h:int file_name:string mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia")]
[TLDef(0xB095434B)] //decryptedMessageMediaDocument#b095434b thumb:bytes thumb_w:int thumb_h:int file_name:string mime_type:string size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaDocument : DecryptedMessageMedia
{
public byte[] thumb;
@ -73,7 +73,7 @@ namespace TL
public byte[] key;
public byte[] iv;
}
[TLDef(0x6080758F, "decryptedMessageMediaAudio#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia")]
[TLDef(0x6080758F)] //decryptedMessageMediaAudio#6080758f duration:int size:int key:bytes iv:bytes = DecryptedMessageMedia
public class DecryptedMessageMediaAudio : DecryptedMessageMedia
{
public int duration;
@ -81,7 +81,7 @@ namespace TL
public byte[] key;
public byte[] iv;
}
[TLDef(0xFA95B0DD, "decryptedMessageMediaExternalDocument#fa95b0dd id:long access_hash:long date:int mime_type:string size:int thumb:PhotoSize dc_id:int attributes:Vector<DocumentAttribute> = DecryptedMessageMedia")]
[TLDef(0xFA95B0DD)] //decryptedMessageMediaExternalDocument#fa95b0dd id:long access_hash:long date:int mime_type:string size:int thumb:PhotoSize dc_id:int attributes:Vector<DocumentAttribute> = DecryptedMessageMedia
public class DecryptedMessageMediaExternalDocument : DecryptedMessageMedia
{
public long id;
@ -93,7 +93,7 @@ namespace TL
public int dc_id;
public DocumentAttribute[] attributes;
}
[TLDef(0x8A0DF56F, "decryptedMessageMediaVenue#8a0df56f lat:double long:double title:string address:string provider:string venue_id:string = DecryptedMessageMedia")]
[TLDef(0x8A0DF56F)] //decryptedMessageMediaVenue#8a0df56f lat:double long:double title:string address:string provider:string venue_id:string = DecryptedMessageMedia
public class DecryptedMessageMediaVenue : DecryptedMessageMedia
{
public double lat;
@ -103,55 +103,55 @@ namespace TL
public string provider;
public string venue_id;
}
[TLDef(0xE50511D8, "decryptedMessageMediaWebPage#e50511d8 url:string = DecryptedMessageMedia")]
[TLDef(0xE50511D8)] //decryptedMessageMediaWebPage#e50511d8 url:string = DecryptedMessageMedia
public class DecryptedMessageMediaWebPage : DecryptedMessageMedia { public string url; }
public abstract class DecryptedMessageAction : ITLObject { }
[TLDef(0xA1733AEC, "decryptedMessageActionSetMessageTTL#a1733aec ttl_seconds:int = DecryptedMessageAction")]
[TLDef(0xA1733AEC)] //decryptedMessageActionSetMessageTTL#a1733aec ttl_seconds:int = DecryptedMessageAction
public class DecryptedMessageActionSetMessageTTL : DecryptedMessageAction { public int ttl_seconds; }
[TLDef(0xC4F40BE, "decryptedMessageActionReadMessages#0c4f40be random_ids:Vector<long> = DecryptedMessageAction")]
[TLDef(0x0C4F40BE)] //decryptedMessageActionReadMessages#0c4f40be random_ids:Vector<long> = DecryptedMessageAction
public class DecryptedMessageActionReadMessages : DecryptedMessageAction { public long[] random_ids; }
[TLDef(0x65614304, "decryptedMessageActionDeleteMessages#65614304 random_ids:Vector<long> = DecryptedMessageAction")]
[TLDef(0x65614304)] //decryptedMessageActionDeleteMessages#65614304 random_ids:Vector<long> = DecryptedMessageAction
public class DecryptedMessageActionDeleteMessages : DecryptedMessageAction { public long[] random_ids; }
[TLDef(0x8AC1F475, "decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector<long> = DecryptedMessageAction")]
[TLDef(0x8AC1F475)] //decryptedMessageActionScreenshotMessages#8ac1f475 random_ids:Vector<long> = DecryptedMessageAction
public class DecryptedMessageActionScreenshotMessages : DecryptedMessageAction { public long[] random_ids; }
[TLDef(0x6719E45C, "decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction")]
[TLDef(0x6719E45C)] //decryptedMessageActionFlushHistory#6719e45c = DecryptedMessageAction
public class DecryptedMessageActionFlushHistory : DecryptedMessageAction { }
[TLDef(0x511110B0, "decryptedMessageActionResend#511110b0 start_seq_no:int end_seq_no:int = DecryptedMessageAction")]
[TLDef(0x511110B0)] //decryptedMessageActionResend#511110b0 start_seq_no:int end_seq_no:int = DecryptedMessageAction
public class DecryptedMessageActionResend : DecryptedMessageAction
{
public int start_seq_no;
public int end_seq_no;
}
[TLDef(0xF3048883, "decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction")]
[TLDef(0xF3048883)] //decryptedMessageActionNotifyLayer#f3048883 layer:int = DecryptedMessageAction
public class DecryptedMessageActionNotifyLayer : DecryptedMessageAction { public int layer; }
[TLDef(0xCCB27641, "decryptedMessageActionTyping#ccb27641 action:SendMessageAction = DecryptedMessageAction")]
[TLDef(0xCCB27641)] //decryptedMessageActionTyping#ccb27641 action:SendMessageAction = DecryptedMessageAction
public class DecryptedMessageActionTyping : DecryptedMessageAction { public SendMessageAction action; }
[TLDef(0xF3C9611B, "decryptedMessageActionRequestKey#f3c9611b exchange_id:long g_a:bytes = DecryptedMessageAction")]
[TLDef(0xF3C9611B)] //decryptedMessageActionRequestKey#f3c9611b exchange_id:long g_a:bytes = DecryptedMessageAction
public class DecryptedMessageActionRequestKey : DecryptedMessageAction
{
public long exchange_id;
public byte[] g_a;
}
[TLDef(0x6FE1735B, "decryptedMessageActionAcceptKey#6fe1735b exchange_id:long g_b:bytes key_fingerprint:long = DecryptedMessageAction")]
[TLDef(0x6FE1735B)] //decryptedMessageActionAcceptKey#6fe1735b exchange_id:long g_b:bytes key_fingerprint:long = DecryptedMessageAction
public class DecryptedMessageActionAcceptKey : DecryptedMessageAction
{
public long exchange_id;
public byte[] g_b;
public long key_fingerprint;
}
[TLDef(0xDD05EC6B, "decryptedMessageActionAbortKey#dd05ec6b exchange_id:long = DecryptedMessageAction")]
[TLDef(0xDD05EC6B)] //decryptedMessageActionAbortKey#dd05ec6b exchange_id:long = DecryptedMessageAction
public class DecryptedMessageActionAbortKey : DecryptedMessageAction { public long exchange_id; }
[TLDef(0xEC2E0B9B, "decryptedMessageActionCommitKey#ec2e0b9b exchange_id:long key_fingerprint:long = DecryptedMessageAction")]
[TLDef(0xEC2E0B9B)] //decryptedMessageActionCommitKey#ec2e0b9b exchange_id:long key_fingerprint:long = DecryptedMessageAction
public class DecryptedMessageActionCommitKey : DecryptedMessageAction
{
public long exchange_id;
public long key_fingerprint;
}
[TLDef(0xA82FDD63, "decryptedMessageActionNoop#a82fdd63 = DecryptedMessageAction")]
[TLDef(0xA82FDD63)] //decryptedMessageActionNoop#a82fdd63 = DecryptedMessageAction
public class DecryptedMessageActionNoop : DecryptedMessageAction { }
[TLDef(0x1BE31789, "decryptedMessageLayer#1be31789 random_bytes:bytes layer:int in_seq_no:int out_seq_no:int message:DecryptedMessage = DecryptedMessageLayer")]
[TLDef(0x1BE31789)] //decryptedMessageLayer#1be31789 random_bytes:bytes layer:int in_seq_no:int out_seq_no:int message:DecryptedMessage = DecryptedMessageLayer
public class DecryptedMessageLayer : ITLObject
{
public byte[] random_bytes;
@ -161,14 +161,14 @@ namespace TL
public DecryptedMessageBase message;
}
[TLDef(0x7C596B46, "fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileLocation")]
[TLDef(0x7C596B46)] //fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileLocation
public class FileLocationUnavailable : FileLocation
{
public long volume_id;
public int local_id;
public long secret;
}
[TLDef(0x53D69076, "fileLocation#53d69076 dc_id:int volume_id:long local_id:int secret:long = FileLocation")]
[TLDef(0x53D69076)] //fileLocation#53d69076 dc_id:int volume_id:long local_id:int secret:long = FileLocation
public class FileLocation_ : FileLocation
{
public int dc_id;
@ -178,6 +178,5 @@ namespace TL
}
public static partial class Fn // ---functions---
{
}
{ }
}

1288
TL.Table.cs Normal file

File diff suppressed because it is too large Load diff

18
TL.cs
View file

@ -13,20 +13,10 @@ namespace TL
public interface ITLObject { }
public interface ITLFunction<R> : ITLObject { }
public static class Schema
public static partial class Schema
{
public const int Layer = 121;
public readonly static Dictionary<uint, Type> Mappings = new();
public const int VectorCtor = 0X1CB5C415;
static Schema()
{
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
var tlDef = type.GetCustomAttribute<TLDefAttribute>(false);
if (tlDef != null) Mappings[tlDef.CtorNb] = type;
}
}
public const int VectorCtor = 0x1CB5C415;
internal static byte[] Serialize(ITLObject msg)
{
@ -54,7 +44,7 @@ namespace TL
internal static T Deserialize<T>(BinaryReader reader) where T : ITLObject
{
var ctorNb = reader.ReadUInt32();
if (!Mappings.TryGetValue(ctorNb, out var realType))
if (!Table.TryGetValue(ctorNb, out var realType))
throw new ApplicationException($"Cannot find type for ctor #{ctorNb:x}");
return (T)DeserializeObject(reader, realType);
}
@ -265,7 +255,7 @@ namespace TL
public class TLDefAttribute : Attribute
{
public readonly uint CtorNb;
public TLDefAttribute(uint ctorNb, string _) => CtorNb = ctorNb;
public TLDefAttribute(uint ctorNb) => CtorNb = ctorNb;
/*public TLDefAttribute(string def)
{
var hash = def.IndexOfAny(new[] { '#', ' ' });