mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-09 08:25:13 +00:00
TLSharp and Tests
This commit is contained in:
parent
9cf850e9b8
commit
3bb487a194
39 changed files with 21943 additions and 0 deletions
39
TLSharp.Core/Requests/AckRequest.cs
Normal file
39
TLSharp.Core/Requests/AckRequest.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class AckRequest : MTProtoRequest
|
||||
{
|
||||
private readonly List<ulong> _msgs;
|
||||
public AckRequest(List<ulong> msgs)
|
||||
{
|
||||
_msgs = msgs;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0x62d6b459); // msgs_ack
|
||||
writer.Write(0x1cb5c415); // Vector
|
||||
writer.Write(_msgs.Count);
|
||||
foreach (ulong messageId in _msgs)
|
||||
{
|
||||
writer.Write(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => false;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
39
TLSharp.Core/Requests/AuthCheckPhoneRequest.cs
Normal file
39
TLSharp.Core/Requests/AuthCheckPhoneRequest.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class AuthCheckPhoneRequest : MTProtoRequest
|
||||
{
|
||||
private string _phoneNumber;
|
||||
public bool _phoneRegistered;
|
||||
private bool _phoneInvited;
|
||||
|
||||
public AuthCheckPhoneRequest(string phoneNumber)
|
||||
{
|
||||
_phoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0x6fe51dfb);
|
||||
Serializers.String.write(writer, _phoneNumber);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
var dataCode = reader.ReadUInt32(); // #e300cc3b
|
||||
this._phoneRegistered = reader.ReadUInt32() == 0x997275b5;
|
||||
this._phoneInvited = reader.ReadUInt32() == 0x997275b5;
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
54
TLSharp.Core/Requests/AuthSendCodeRequest.cs
Normal file
54
TLSharp.Core/Requests/AuthSendCodeRequest.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class AuthSendCodeRequest : MTProtoRequest
|
||||
{
|
||||
private readonly string _phoneNumber;
|
||||
private readonly int _smsType;
|
||||
private readonly int _apiId;
|
||||
private readonly string _apiHash;
|
||||
private readonly string _langCode;
|
||||
public bool _phoneRegistered;
|
||||
public string _phoneCodeHash;
|
||||
|
||||
public AuthSendCodeRequest(string phoneNumber, int smsType, int apiId, string apiHash, string langCode)
|
||||
{
|
||||
_phoneNumber = phoneNumber;
|
||||
_smsType = smsType;
|
||||
_apiId = apiId;
|
||||
_apiHash = apiHash;
|
||||
_langCode = langCode;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0x768d5f4d);
|
||||
Serializers.String.write(writer, _phoneNumber);
|
||||
writer.Write(_smsType);
|
||||
writer.Write(_apiId);
|
||||
Serializers.String.write(writer, _apiHash);
|
||||
Serializers.String.write(writer, _langCode);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
var boolTrue = 0x997275b5;
|
||||
var dataCode = reader.ReadUInt32(); // 0x2215bcbd
|
||||
_phoneRegistered = reader.ReadUInt32() == boolTrue;
|
||||
_phoneCodeHash = Serializers.String.read(reader);
|
||||
var sendCodeTimeout = reader.ReadInt32();
|
||||
var isPassword = reader.ReadUInt32() == boolTrue;
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
45
TLSharp.Core/Requests/AuthSignInRequest.cs
Normal file
45
TLSharp.Core/Requests/AuthSignInRequest.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class AuthSignInRequest : MTProtoRequest
|
||||
{
|
||||
private readonly string _phoneNumber;
|
||||
private readonly string _phoneCodeHash;
|
||||
private readonly string _code;
|
||||
public User user;
|
||||
public int SessionExpires;
|
||||
|
||||
public AuthSignInRequest(string phoneNumber, string phoneCodeHash, string code)
|
||||
{
|
||||
_phoneNumber = phoneNumber;
|
||||
_phoneCodeHash = phoneCodeHash;
|
||||
_code = code;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0xbcd51581);
|
||||
Serializers.String.write(writer, _phoneNumber);
|
||||
Serializers.String.write(writer, _phoneCodeHash);
|
||||
Serializers.String.write(writer, _code);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
var dataCode = reader.ReadUInt32(); //0xf6b673a4
|
||||
var expires = reader.ReadInt32();
|
||||
user = TL.Parse<User>(reader);
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
62
TLSharp.Core/Requests/ImportContactRequest.cs
Normal file
62
TLSharp.Core/Requests/ImportContactRequest.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class ImportContactRequest : MTProtoRequest
|
||||
{
|
||||
private InputContact Contact { get; set; }
|
||||
private bool Replace { get; set; }
|
||||
|
||||
public List<ImportedContact> imported;
|
||||
public List<User> users;
|
||||
|
||||
public ImportContactRequest(InputContact contact, bool shouldReplace = true)
|
||||
{
|
||||
Contact = contact;
|
||||
Replace = shouldReplace;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0xda30b32d);
|
||||
writer.Write(0x1cb5c415);
|
||||
writer.Write(1);
|
||||
Contact.Write(writer);
|
||||
writer.Write(Replace ? 0x997275b5 : 0xbc799737);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
var code = reader.ReadUInt32();
|
||||
var result = reader.ReadInt32(); // vector code
|
||||
int imported_len = reader.ReadInt32();
|
||||
this.imported = new List<ImportedContact>(imported_len);
|
||||
for (int imported_index = 0; imported_index < imported_len; imported_index++)
|
||||
{
|
||||
ImportedContact imported_element;
|
||||
imported_element = TL.Parse<ImportedContact>(reader);
|
||||
this.imported.Add(imported_element);
|
||||
}
|
||||
reader.ReadInt32(); // vector code
|
||||
int users_len = reader.ReadInt32();
|
||||
this.users = new List<User>(users_len);
|
||||
for (int users_index = 0; users_index < users_len; users_index++)
|
||||
{
|
||||
User users_element;
|
||||
users_element = TL.Parse<User>(reader);
|
||||
this.users.Add(users_element);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
55
TLSharp.Core/Requests/InitConnectionRequest.cs
Normal file
55
TLSharp.Core/Requests/InitConnectionRequest.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class InitConnectionRequest : MTProtoRequest
|
||||
{
|
||||
private int _apiId;
|
||||
public ConfigConstructor ConfigConstructor { get; set; }
|
||||
|
||||
public InitConnectionRequest(int apiId)
|
||||
{
|
||||
_apiId = apiId;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0x39620c41); // invokeWithLayer10#39620c41, invokeWithLayer11#a6b88fdf
|
||||
writer.Write(0x69796de9); // initConnection
|
||||
writer.Write(_apiId); // api id
|
||||
Serializers.String.write(writer, "WinPhone Emulator"); // device model
|
||||
Serializers.String.write(writer, "WinPhone 8.0"); // system version
|
||||
Serializers.String.write(writer, "1.0-SNAPSHOT"); // app version
|
||||
Serializers.String.write(writer, "en"); // lang code
|
||||
|
||||
writer.Write(0xc4f9186b); // help.getConfig
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
uint code = reader.ReadUInt32();
|
||||
ConfigConstructor config = new ConfigConstructor();
|
||||
config.Read(reader);
|
||||
|
||||
ConfigConstructor = config;
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Responded
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override void OnSendSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
public override bool Confirmed => true;
|
||||
}
|
||||
}
|
||||
46
TLSharp.Core/Requests/MTProtoRequest.cs
Normal file
46
TLSharp.Core/Requests/MTProtoRequest.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public abstract class MTProtoRequest
|
||||
{
|
||||
public MTProtoRequest()
|
||||
{
|
||||
Sended = false;
|
||||
}
|
||||
|
||||
public long MessageId { get; set; }
|
||||
public int Sequence { get; set; }
|
||||
|
||||
public bool Dirty { get; set; }
|
||||
|
||||
public bool Sended { get; private set; }
|
||||
public DateTime SendTime { get; private set; }
|
||||
public bool ConfirmReceived { get; set; }
|
||||
public abstract void OnSend(BinaryWriter writer);
|
||||
public abstract void OnResponse(BinaryReader reader);
|
||||
public abstract void OnException(Exception exception);
|
||||
public abstract bool Confirmed { get; }
|
||||
public abstract bool Responded { get; }
|
||||
|
||||
public virtual void OnSendSuccess()
|
||||
{
|
||||
SendTime = DateTime.Now;
|
||||
Sended = true;
|
||||
}
|
||||
|
||||
public virtual void OnConfirm()
|
||||
{
|
||||
ConfirmReceived = true;
|
||||
}
|
||||
|
||||
public bool NeedResend
|
||||
{
|
||||
get
|
||||
{
|
||||
return Dirty || (Confirmed && !ConfirmReceived && DateTime.Now - SendTime > TimeSpan.FromSeconds(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
TLSharp.Core/Requests/SendMessageRequest.cs
Normal file
46
TLSharp.Core/Requests/SendMessageRequest.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class SendMessageRequest : MTProtoRequest
|
||||
{
|
||||
private InputPeer _peer;
|
||||
private string _message;
|
||||
|
||||
public SendMessageRequest(InputPeer peer, string message)
|
||||
{
|
||||
_peer = peer;
|
||||
_message = message;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
long random_id = Helpers.GenerateRandomLong();
|
||||
writer.Write(0x4cde0aab);
|
||||
_peer.Write(writer);
|
||||
Serializers.String.write(writer, _message);
|
||||
writer.Write(random_id);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
var code = reader.ReadUInt32();
|
||||
|
||||
var id = reader.ReadInt32();
|
||||
var date = reader.ReadInt32();
|
||||
var pts = reader.ReadInt32();
|
||||
var seq = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue