mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Added possibility to do ping request (SendPingAsync method)
This commit is contained in:
parent
ca78532b34
commit
8b2f227142
|
|
@ -160,6 +160,7 @@ For your convenience TLSharp have wrappers for several Telegram API methods. You
|
||||||
1. SendUploadedDocument
|
1. SendUploadedDocument
|
||||||
1. GetFile
|
1. GetFile
|
||||||
1. UploadFile
|
1. UploadFile
|
||||||
|
1. SendPingAsync
|
||||||
|
|
||||||
**What if you can't find needed method at the list?**
|
**What if you can't find needed method at the list?**
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,19 @@ namespace TLSharp.Core.Network
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SendPingAsync()
|
||||||
|
{
|
||||||
|
var pingRequest = new PingRequest();
|
||||||
|
using (var memory = new MemoryStream())
|
||||||
|
using (var writer = new BinaryWriter(memory))
|
||||||
|
{
|
||||||
|
pingRequest.SerializeBody(writer);
|
||||||
|
await Send(memory.ToArray(), pingRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Receive(pingRequest);
|
||||||
|
}
|
||||||
|
|
||||||
private bool processMessage(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
|
private bool processMessage(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
|
||||||
{
|
{
|
||||||
// TODO: check salt
|
// TODO: check salt
|
||||||
|
|
@ -169,7 +182,7 @@ namespace TLSharp.Core.Network
|
||||||
return HandlePing(messageId, sequence, messageReader);
|
return HandlePing(messageId, sequence, messageReader);
|
||||||
case 0x347773c5: // pong
|
case 0x347773c5: // pong
|
||||||
//logger.debug("MSG pong");
|
//logger.debug("MSG pong");
|
||||||
return HandlePong(messageId, sequence, messageReader);
|
return HandlePong(messageId, sequence, messageReader, request);
|
||||||
case 0xae500895: // future_salts
|
case 0xae500895: // future_salts
|
||||||
//logger.debug("MSG future_salts");
|
//logger.debug("MSG future_salts");
|
||||||
return HandleFutureSalts(messageId, sequence, messageReader);
|
return HandleFutureSalts(messageId, sequence, messageReader);
|
||||||
|
|
@ -455,8 +468,16 @@ namespace TLSharp.Core.Network
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HandlePong(ulong messageId, int sequence, BinaryReader messageReader)
|
private bool HandlePong(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
|
||||||
{
|
{
|
||||||
|
uint code = messageReader.ReadUInt32();
|
||||||
|
ulong msgId = messageReader.ReadUInt64();
|
||||||
|
|
||||||
|
if (msgId == (ulong)request.MessageId)
|
||||||
|
{
|
||||||
|
request.ConfirmReceived = true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
39
TLSharp.Core/Requests/PingRequest.cs
Normal file
39
TLSharp.Core/Requests/PingRequest.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using TeleSharp.TL;
|
||||||
|
using TLSharp.Core.Utils;
|
||||||
|
|
||||||
|
namespace TLSharp.Core.Requests
|
||||||
|
{
|
||||||
|
public class PingRequest : TeleSharp.TL.TLMethod
|
||||||
|
{
|
||||||
|
public PingRequest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SerializeBody(BinaryWriter writer)
|
||||||
|
{
|
||||||
|
writer.Write(Constructor);
|
||||||
|
writer.Write(Helpers.GenerateRandomLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeserializeBody(BinaryReader reader)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void deserializeResponse(BinaryReader stream)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Constructor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 0x7abe77ec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -63,6 +63,7 @@
|
||||||
<Compile Include="Network\TcpTransport.cs" />
|
<Compile Include="Network\TcpTransport.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Requests\AckRequest.cs" />
|
<Compile Include="Requests\AckRequest.cs" />
|
||||||
|
<Compile Include="Requests\PingRequest.cs" />
|
||||||
<Compile Include="Utils\UploadHelper.cs" />
|
<Compile Include="Utils\UploadHelper.cs" />
|
||||||
<Compile Include="Session.cs" />
|
<Compile Include="Session.cs" />
|
||||||
<Compile Include="TelegramClient.cs" />
|
<Compile Include="TelegramClient.cs" />
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ namespace TLSharp.Core
|
||||||
{
|
{
|
||||||
await _sender.Send(methodToExecute);
|
await _sender.Send(methodToExecute);
|
||||||
await _sender.Receive(methodToExecute);
|
await _sender.Receive(methodToExecute);
|
||||||
|
|
||||||
var result = methodToExecute.GetType().GetProperty("Response").GetValue(methodToExecute);
|
var result = methodToExecute.GetType().GetProperty("Response").GetValue(methodToExecute);
|
||||||
|
|
||||||
return (T)result;
|
return (T)result;
|
||||||
|
|
@ -292,6 +292,11 @@ namespace TLSharp.Core
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SendPingAsync()
|
||||||
|
{
|
||||||
|
await _sender.SendPingAsync();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnUserAuthenticated(TLUser TLUser)
|
private void OnUserAuthenticated(TLUser TLUser)
|
||||||
{
|
{
|
||||||
_session.TLUser = TLUser;
|
_session.TLUser = TLUser;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue