Skip to content

Commit

Permalink
[Core] Refactor Protobuf Push
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 26, 2023
1 parent bbca98f commit 1eac08f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 109 deletions.
32 changes: 0 additions & 32 deletions Lagrange.Core/Internal/Packets/Message/C2C/C2CMsgInfo.cs

This file was deleted.

18 changes: 0 additions & 18 deletions Lagrange.Core/Internal/Packets/Message/C2C/C2CMsgWithDrawReq.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Lagrange.Core/Internal/Packets/Message/C2C/C2CMsgWithDrawResp.cs

This file was deleted.

32 changes: 0 additions & 32 deletions Lagrange.Core/Internal/Packets/Message/C2C/C2CTempMessageHead.cs

This file was deleted.

8 changes: 4 additions & 4 deletions Lagrange.Core/Internal/Packets/Message/ContentHead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Lagrange.Core.Internal.Packets.Message;
[ProtoContract]
internal class ContentHead
{
[ProtoMember(1)] public uint? PkgNum { get; set; }
[ProtoMember(1)] public uint Type { get; set; }

[ProtoMember(2)] public uint? PkgIndex { get; set; }
[ProtoMember(2)] public uint? SubType { get; set; }

[ProtoMember(3)] public uint? DivSeq { get; set; }

Expand All @@ -19,13 +19,13 @@ internal class ContentHead

[ProtoMember(6)] public long? Timestamp { get; set; }

[ProtoMember(7)] public long? Type { get; set; }
[ProtoMember(7)] public long? Field7 { get; set; }

[ProtoMember(8)] public uint? Field8 { get; set; }

[ProtoMember(9)] public uint? Field9 { get; set; }

[ProtoMember(12)] public long? NewId { get; set; }
[ProtoMember(12)] public ulong? NewId { get; set; }

[ProtoMember(15)] public ForwardHead? Forward { get; set; }
}
4 changes: 2 additions & 2 deletions Lagrange.Core/Internal/Service/Message/PushMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo app
out PushMessageEvent output, out List<ProtocolEvent>? extraEvents)
{
var message = Serializer.Deserialize<PushMsg>(input.AsSpan());
var packetType = (PkgType)message.Message.ContentHead.PkgNum!;
var packetType = (PkgType)message.Message.ContentHead.Type;

output = null!;
extraEvents = new List<ProtocolEvent>();
Expand Down Expand Up @@ -97,7 +97,7 @@ protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo app

public static void ProcessEvent0x2DC(byte[] payload, PushMsg msg)
{
var pkgType = (Event0x2DCSubType)(msg.Message.ContentHead.PkgIndex ?? 0);
var pkgType = (Event0x2DCSubType)(msg.Message.ContentHead.SubType ?? 0);
switch (pkgType)
{
case Event0x2DCSubType.GroupRecallNotice:
Expand Down
23 changes: 16 additions & 7 deletions Lagrange.Core/Message/MessagePacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ public static MessageChain Parse(PushMsgBody message)
},
ContentHead = new ContentHead
{
PkgNum = 1, // regarded as the const
PkgIndex = 0,
Type = 1, // regarded as the const
SubType = 0,
DivSeq = 0
},
Body = new MessageBody { RichText = new RichText { Elems = new List<Elem>() } },
Expand All @@ -202,13 +202,13 @@ public static MessageChain Parse(PushMsgBody message)
},
ContentHead = new ContentHead
{
PkgNum = (uint)(chain.IsGroup ? 82 : 529),
PkgIndex = chain.IsGroup ? null : 4,
Type = (uint)(chain.IsGroup ? 82 : 529),
SubType = chain.IsGroup ? null : 4,
DivSeq = chain.IsGroup ? null : 4,
MsgId = (uint)Random.Shared.Next(100000000, int.MaxValue),
Sequence = Random.Shared.Next(1000000, 9999999),
Timestamp = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Type = 1,
Field7 = 1,
Field8 = 0,
Field9 = 0,
Forward = new ForwardHead
Expand All @@ -224,7 +224,16 @@ public static MessageChain Parse(PushMsgBody message)
private static MessageChain ParseChain(PushMsgBody message)
{
return message.ResponseHead.Grp == null
? new MessageChain(message.ResponseHead.FromUin,message.ResponseHead.ToUid ?? string.Empty ,message.ResponseHead.FromUid ?? string.Empty)
: new MessageChain(message.ResponseHead.Grp.GroupUin, message.ResponseHead.FromUin, (uint)(message.ContentHead.Sequence ?? 0));
? new MessageChain(
message.ResponseHead.FromUin,
message.ResponseHead.ToUid ?? string.Empty ,
message.ResponseHead.FromUid ?? string.Empty,
message.ContentHead.NewId ?? 0)

: new MessageChain(
message.ResponseHead.Grp.GroupUin,
message.ResponseHead.FromUin,
(uint)(message.ContentHead.Sequence ?? 0),
message.ContentHead.NewId ?? 0);
}
}

0 comments on commit 1eac08f

Please sign in to comment.