diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index c8a613e..e3efabf 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -11,7 +11,7 @@ using TLSharp.Core.Exceptions; using TLSharp.Core.MTProto; using TLSharp.Core.MTProto.Crypto; using TLSharp.Core.Network.Exceptions; -using TLSharp.Core.Requests; +using TLSharp.Core.Network.Requests; using TLSharp.Core.Utils; namespace TLSharp.Core.Network diff --git a/TLSharp.Core/Requests/AckRequest.cs b/TLSharp.Core/Network/Requests/AckRequest.cs similarity index 92% rename from TLSharp.Core/Requests/AckRequest.cs rename to TLSharp.Core/Network/Requests/AckRequest.cs index b85ddc3..5530301 100644 --- a/TLSharp.Core/Requests/AckRequest.cs +++ b/TLSharp.Core/Network/Requests/AckRequest.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.IO; using TeleSharp.TL; -namespace TLSharp.Core.Requests +namespace TLSharp.Core.Network.Requests { - public class AckRequest : TeleSharp.TL.TLMethod + public class AckRequest : TLMethod { private readonly List _msgs; @@ -36,6 +36,7 @@ namespace TLSharp.Core.Requests } public override bool Confirmed => false; + public override bool Responded { get; } public override int Constructor diff --git a/TLSharp.Core/Requests/PingRequest.cs b/TLSharp.Core/Network/Requests/PingRequest.cs similarity index 86% rename from TLSharp.Core/Requests/PingRequest.cs rename to TLSharp.Core/Network/Requests/PingRequest.cs index 34997cf..d6c910a 100644 --- a/TLSharp.Core/Requests/PingRequest.cs +++ b/TLSharp.Core/Network/Requests/PingRequest.cs @@ -1,12 +1,11 @@ using System; -using System.Collections.Generic; using System.IO; using TeleSharp.TL; using TLSharp.Core.Utils; -namespace TLSharp.Core.Requests +namespace TLSharp.Core.Network.Requests { - public class PingRequest : TeleSharp.TL.TLMethod + public class PingRequest : TLMethod { public PingRequest() { diff --git a/TLSharp.Core/Requests/AuthSendCodeRequest.cs b/TLSharp.Core/Requests/AuthSendCodeRequest.cs deleted file mode 100644 index 06852a8..0000000 --- a/TLSharp.Core/Requests/AuthSendCodeRequest.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.IO; -using TLSharp.Core.MTProto; -using TeleSharp.TL; -namespace TLSharp.Core.Requests -{ - public class AuthSendCodeRequest : MTProtoRequest - { - - public bool _phoneRegistered; - public string _phoneCodeHash; - public SendCodeArgs args=new SendCodeArgs(); - public AuthSendCodeRequest(string phoneNumber, int smsType, int apiId, string apiHash, string langCode) - { - - args.phone_number = phoneNumber; - args.api_id = apiId; - args.api_hash = apiHash; - args.allow_flashcall = false; - args.current_number = true; - } - - public override void OnSend(BinaryWriter writer) - { - writer.Write(0x86AEF0EC); - writer.Write(0); - Serializers.String.write(writer, args.phone_number); - writer.Write(args.api_id.Value); - Serializers.String.write(writer, args.api_hash); - } - - public override void OnResponse(BinaryReader reader) - { - - var s = Deserializer.Deserialize(typeof(SentCode), reader); - _phoneRegistered = ((SentCode)s).phone_registered; - _phoneCodeHash = ((SentCode)s).phone_code_hash; - } - - public override void OnException(Exception exception) - { - throw new NotImplementedException(); - } - - public override bool Confirmed => true; - public override bool Responded { get; } - } -} diff --git a/TLSharp.Core/Requests/AuthSignInRequest.cs b/TLSharp.Core/Requests/AuthSignInRequest.cs deleted file mode 100644 index 83dc2c2..0000000 --- a/TLSharp.Core/Requests/AuthSignInRequest.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.IO; -using TeleSharp.TL; -namespace TLSharp.Core.Requests -{ - public class AuthSignInRequest : MTProtoRequest - { - private SignInArgs args = new SignInArgs(); - public User user; - public int SessionExpires; - - public AuthSignInRequest(string phoneNumber, string phoneCodeHash, string code) - { - args.phone_number = phoneNumber; - args.phone_code_hash = phoneCodeHash; - args.phone_code = code; - } - - public override void OnSend(BinaryWriter writer) - { - Serializer.Serialize(args, typeof(SignInArgs), writer); - } - - public override void OnResponse(BinaryReader reader) - { - var auth = (Authorization)Deserializer.Deserialize(typeof(Authorization), reader); - user = auth.user; - } - - public override void OnException(Exception exception) - { - throw new NotImplementedException(); - } - - public override bool Confirmed => true; - public override bool Responded { get; } - } -} diff --git a/TLSharp.Core/Requests/DownloadFileRequest.cs b/TLSharp.Core/Requests/DownloadFileRequest.cs deleted file mode 100644 index 4574a9b..0000000 --- a/TLSharp.Core/Requests/DownloadFileRequest.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.IO; -using TeleSharp.TL; -namespace TLSharp.Core.Requests -{ - public class DownloadFileRequest : MTProtoRequest - { - private GetFileArgs args = new GetFileArgs(); - public TeleSharp.TL.File file; - - public DownloadFileRequest(InputFileLocation loc,int offset=0,int limit=0) - { - args.location = loc; - args.offset = offset; - args.limit = limit; - } - - public override void OnSend(BinaryWriter writer) - { - Serializer.Serialize(args, typeof(InputFileLocation), writer); - } - - public override void OnResponse(BinaryReader reader) - { - file = (TeleSharp.TL.File)Deserializer.Deserialize(typeof(TeleSharp.TL.File), reader); - } - - public override void OnException(Exception exception) - { - throw new NotImplementedException(); - } - - public override bool Confirmed => true; - public override bool Responded { get; } - } -} diff --git a/TLSharp.Core/Requests/InitConnectionRequest.cs b/TLSharp.Core/Requests/InitConnectionRequest.cs deleted file mode 100644 index b428e8d..0000000 --- a/TLSharp.Core/Requests/InitConnectionRequest.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using TeleSharp.TL; -using TLSharp.Core.MTProto; - -namespace TLSharp.Core.Requests -{ - public class InitConnectionRequest : MTProtoRequest - { - public InvokeWithLayerArgs invokeWithLayer { get; set; } - public InitConnectionArgs initConn { get; set; } - public GetConfigArgs getConfig { get; set; } - public TeleSharp.TL.Config Configs { get; set; } - - public InitConnectionRequest(int apiId) - { - invokeWithLayer = new InvokeWithLayerArgs(); - initConn = new InitConnectionArgs(); - invokeWithLayer.layer = 53; - initConn.api_id = apiId; - initConn.app_version = "1.0-SNAPSHOT"; - initConn.lang_code = "en"; - initConn.system_version = "WinPhone 8.0"; - initConn.device_model = "WinPhone Emulator"; - initConn.query = new GetConfigArgs(); - invokeWithLayer.query = initConn; - } - - public override void OnSend(BinaryWriter writer) - { - Serializer.Serialize(invokeWithLayer, invokeWithLayer.GetType(), writer); - } - - - public override void OnResponse(BinaryReader reader) - { - Configs = (TeleSharp.TL.Config)Deserializer.Deserialize(typeof(TeleSharp.TL.Config), reader); - } - - 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; - } -} diff --git a/TLSharp.Core/Requests/MTProtoRequest.cs b/TLSharp.Core/Requests/MTProtoRequest.cs deleted file mode 100644 index c095d39..0000000 --- a/TLSharp.Core/Requests/MTProtoRequest.cs +++ /dev/null @@ -1,46 +0,0 @@ -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)); - } - } - } -} diff --git a/TLSharp.Core/TLSharp.Core.csproj b/TLSharp.Core/TLSharp.Core.csproj index 237eccb..c09f394 100644 --- a/TLSharp.Core/TLSharp.Core.csproj +++ b/TLSharp.Core/TLSharp.Core.csproj @@ -71,8 +71,8 @@ - - + + @@ -88,6 +88,7 @@ TeleSharp.TL +