Skip to content

Commit

Permalink
[Core] Fixed Bug of Private message sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Jan 5, 2024
1 parent 089014b commit 7776924
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Lagrange.Core/Internal/Packets/Message/ContentHead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class ContentHead

[ProtoMember(4)] public long? MsgId { get; set; }

[ProtoMember(5)] public int? Sequence { get; set; }
[ProtoMember(5)] public uint? Sequence { get; set; }

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

Expand Down
4 changes: 2 additions & 2 deletions Lagrange.Core/Message/MessageChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public sealed class MessageChain : List<IMessageEntity>

#endregion

internal MessageChain(uint friendUin, string selfUid, string friendUid, ulong messageId = 0)
internal MessageChain(uint friendUin, string selfUid, string friendUid, uint sequence = 0, ulong messageId = 0)
{
GroupUin = null;
FriendUin = friendUin;
Sequence = 0; // unuseful at there
Sequence = sequence; // unuseful at there
SelfUid = selfUid;
Uid = friendUid;
MessageId = messageId;
Expand Down
3 changes: 2 additions & 1 deletion Lagrange.Core/Message/MessagePacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private static PushMsgBody BuildFakePacketBase(MessageChain chain) => new()
SubType = chain.IsGroup ? null : 4,
DivSeq = chain.IsGroup ? null : 4,
MsgId = (uint)Random.Shared.Next(100000000, int.MaxValue),
Sequence = Random.Shared.Next(1000000, 9999999),
Sequence = (uint?)Random.Shared.Next(1000000, 9999999),
Timestamp = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Field7 = 1,
Field8 = 0,
Expand All @@ -220,6 +220,7 @@ private static MessageChain ParseChain(PushMsgBody message)
message.ResponseHead.FromUin,
message.ResponseHead.ToUid ?? string.Empty ,
message.ResponseHead.FromUid ?? string.Empty,
message.ContentHead.Sequence ?? 0,
message.ContentHead.NewId ?? 0)

: new MessageChain(
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Database/MessageRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MessageRecord
{
var chain = record.GroupUin != 0
? new MessageChain(record.GroupUin, record.FriendUin, record.Sequence, record.MessageId)
: new MessageChain(record.FriendUin, string.Empty, string.Empty, record.MessageId);
: new MessageChain(record.FriendUin, string.Empty, string.Empty, record.Sequence, record.MessageId);

chain.Time = record.Time;
chain.FriendInfo = record.FriendInfo;
Expand Down Expand Up @@ -56,7 +56,7 @@ private static uint CalcMessageHash(ulong msgId, uint seq)
var messageId = BitConverter.GetBytes(msgId);
var sequence = BitConverter.GetBytes(seq);

byte[] id = [messageId[6], messageId[7], sequence[0], sequence[1]];
byte[] id = [messageId[0], messageId[1], sequence[0], sequence[1]];
return BitConverter.ToUInt32(id.AsSpan());
}
}

0 comments on commit 7776924

Please sign in to comment.