mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Support GZipped array in RpcResult
This commit is contained in:
parent
cba347dc89
commit
0ed77ef984
32
FAQ.md
32
FAQ.md
|
|
@ -36,7 +36,8 @@ An easy solution is to call `Interaction.InputBox("Enter verification code")` in
|
|||
This might require adding a reference *(and `using`)* to the Microsoft.VisualBasic assembly.
|
||||
|
||||
A more complex solution requires the use of a `ManualResetEventSlim` that you will wait for in Config callback,
|
||||
and when the user has provided the verification_code through your GUI, you "set" the event to release your Config callback so it can return the code. ([see example](https://stackoverflow.com/a/70379582/3365403))
|
||||
and when the user has provided the verification_code through your GUI, you "set" the event to release your Config callback so it can return the code.
|
||||
([download a full example](https://github.com/wiz0u/WTelegramClient/raw/master/Examples/WinForms_app.zip))
|
||||
|
||||
<a name="access-hash"></a>
|
||||
#### 4. Where to get the access_hash? Why the error `CHANNEL_INVALID` or `USER_ID_INVALID`?
|
||||
|
|
@ -84,8 +85,22 @@ If you use the Github source project in an old .NET Framework 4.x or .NET Core x
|
|||
|
||||
To fix this, you should also switch to using the [WTelegramClient Nuget package](https://www.nuget.org/packages/WTelegramClient) as it will install the required dependencies for it to work.
|
||||
|
||||
<a name="abuse"></a>
|
||||
#### 7. I get error FLOOD_WAIT_8xxxx or PEER_FLOOD, PHONE_NUMBER_BANNED. I can't import phone numbers.
|
||||
|
||||
You can get these kind of problems if you abuse Telegram [Terms of Service](https://telegram.org/tos), or the [API Terms of Service](https://core.telegram.org/api/terms), or make excessive requests.
|
||||
|
||||
You can try to wait more between the requests, wait for a day or two to see if the requests become possible again.
|
||||
>ℹ️ For FLOOD_WAIT_X with X < 60 seconds (see `client.FloodRetryThreshold`), WTelegramClient will automatically wait the specified delay and retry the request for you.
|
||||
|
||||
An account that was limited due to reported spam might receive PEER_FLOOD errors. Read [Telegram Spam FAQ](https://telegram.org/faq_spam) to learn more.
|
||||
|
||||
If you think your phone number was banned from Telegram for a wrong reason, you may try to contact [recover@telegram.org](mailto:recover@telegram.org), explaining what you were doing.
|
||||
|
||||
In any case, WTelegramClient is not responsible for the bad usage of the library and we are not affiliated to Telegram teams, so there is nothing we can do.
|
||||
|
||||
<a name="prevent-ban"></a>
|
||||
#### 7. How to not get banned from Telegram?
|
||||
#### 8. How to not get banned from Telegram?
|
||||
|
||||
**Do not share publicly your app's ID and hash!** They cannot be regenerated and are bound to your Telegram account.
|
||||
|
||||
|
|
@ -112,19 +127,6 @@ Here are some key points:
|
|||
|
||||
If your client displays Telegram channels to the user, you have to support and display [official sponsored messages](https://core.telegram.org/api/sponsored-messages).
|
||||
|
||||
<a name="abuse"></a>
|
||||
#### 8. I can't import phone numbers. I get error PHONE_NUMBER_BANNED, FLOOD_WAIT_8xxxx or PEER_FLOOD
|
||||
|
||||
You can get these kind of problems if you abuse Telegram [Terms of Service](https://telegram.org/tos), or the [API Terms of Service](https://core.telegram.org/api/terms), or make excessive requests.
|
||||
|
||||
You can try to wait more between the requests, wait for a day or two to see if the requests become possible again.
|
||||
|
||||
An account that was limited due to reported spam might receive PEER_FLOOD errors. Read [Telegram Spam FAQ](https://telegram.org/faq_spam) to learn more.
|
||||
|
||||
If you think your phone number was banned from Telegram for a wrong reason, you may try to contact [recover@telegram.org](mailto:recover@telegram.org), explaining what you were doing.
|
||||
|
||||
In any case, WTelegramClient is not responsible for the bad usage of the library and we are not affiliated to Telegram teams, so there is nothing we can do.
|
||||
|
||||
<a name="chat-id"></a>
|
||||
#### 9. Why the error `CHAT_ID_INVALID`?
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
|
@ -777,12 +778,19 @@ namespace WTelegram
|
|||
{
|
||||
if (!type.IsArray)
|
||||
result = reader.ReadTLValue(type);
|
||||
else if (reader.ReadUInt32() == Layer.RpcErrorCtor)
|
||||
result = reader.ReadTLObject(Layer.RpcErrorCtor);
|
||||
else
|
||||
{
|
||||
reader.BaseStream.Position -= 4;
|
||||
result = reader.ReadTLValue(type);
|
||||
var peek = reader.ReadUInt32();
|
||||
if (peek == Layer.RpcErrorCtor)
|
||||
result = reader.ReadTLObject(Layer.RpcErrorCtor);
|
||||
else if (peek == Layer.GZipedCtor)
|
||||
using (var gzipReader = new TL.BinaryReader(new GZipStream(new MemoryStream(reader.ReadTLBytes()), CompressionMode.Decompress), reader.Client))
|
||||
result = gzipReader.ReadTLValue(type);
|
||||
else
|
||||
{
|
||||
reader.BaseStream.Position -= 4;
|
||||
result = reader.ReadTLValue(type);
|
||||
}
|
||||
}
|
||||
if (type.IsEnum) result = Enum.ToObject(type, result);
|
||||
if (result is RpcError rpcError)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace TL
|
|||
internal const uint RpcErrorCtor = 0x2144CA19;
|
||||
internal const uint MsgContainerCtor = 0x73F1F8DC;
|
||||
internal const uint BadMsgCtor = 0xA7EFF811;
|
||||
internal const uint GZipedCtor = 0x3072CFA1;
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public readonly static Dictionary<uint, Type> Table = new()
|
||||
|
|
|
|||
12
src/TL.cs
12
src/TL.cs
|
|
@ -53,6 +53,9 @@ namespace TL
|
|||
internal static IObject ReadTLObject(this BinaryReader reader, uint ctorNb = 0)
|
||||
{
|
||||
if (ctorNb == 0) ctorNb = reader.ReadUInt32();
|
||||
if (ctorNb == Layer.GZipedCtor)
|
||||
using (var gzipReader = new BinaryReader(new GZipStream(new MemoryStream(reader.ReadTLBytes()), CompressionMode.Decompress), reader.Client))
|
||||
return ReadTLObject(gzipReader);
|
||||
if (!Layer.Table.TryGetValue(ctorNb, out var type))
|
||||
throw new ApplicationException($"Cannot find type for ctor #{ctorNb:x}");
|
||||
if (type == null) return null; // nullable ctor (class meaning is associated with null)
|
||||
|
|
@ -70,7 +73,7 @@ namespace TL
|
|||
if (field.Name == "flags") flags = (int)value;
|
||||
else if (field.Name == "access_hash") reader.Client?.UpdateAccessHash(obj, type, value);
|
||||
}
|
||||
return type == typeof(GzipPacked) ? UnzipPacket((GzipPacked)obj, reader.Client) : (IObject)obj;
|
||||
return (IObject)obj;
|
||||
}
|
||||
|
||||
internal static void WriteTLValue(this BinaryWriter writer, object value, Type valueType)
|
||||
|
|
@ -292,13 +295,6 @@ namespace TL
|
|||
writer.Write(0); // null arrays/strings are serialized as empty
|
||||
}
|
||||
|
||||
internal static IObject UnzipPacket(GzipPacked obj, WTelegram.Client client)
|
||||
{
|
||||
using var reader = new BinaryReader(new GZipStream(new MemoryStream(obj.packed_data), CompressionMode.Decompress), client);
|
||||
var result = reader.ReadTLObject();
|
||||
return result;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
private static void ShouldntBeHere() => System.Diagnostics.Debugger.Break();
|
||||
#else
|
||||
|
|
|
|||
Loading…
Reference in a new issue