Skip to content

Commit

Permalink
refactor: Payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 11, 2023
1 parent c28fef6 commit 5650001
Show file tree
Hide file tree
Showing 44 changed files with 97 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Lagrange.Core.Internal.Event.EventArg;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Login;
using Lagrange.Core.Internal.Event.Protocol.Login.Ecdh;
using Lagrange.Core.Internal.Event.Protocol.System;
using Lagrange.Core.Internal.Packets.Login.NTLogin;
using Lagrange.Core.Internal.Packets.Login.WtLogin.Entity;
Expand Down
7 changes: 4 additions & 3 deletions Lagrange.Core/Internal/Context/ServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Service;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;

Expand Down Expand Up @@ -92,15 +91,16 @@ public List<SsoPacket> ResolvePacketByEvent(ProtocolEvent protocolEvent)
public List<ProtocolEvent> ResolveEventByPacket(SsoPacket packet)
{
var result = new List<ProtocolEvent>();
var payload = packet.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);

if (!_services.TryGetValue(packet.Command, out var service))
{
Collection.Log.LogWarning(Tag, $"Unsupported SSOFrame Received: {packet.Command}");
var payload = packet.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
Collection.Log.LogDebug(Tag, $"Unsuccessful SSOFrame Payload: {payload.Hex()}");
return result; // 没找到 滚蛋吧
}

bool success = service.Parse(packet, Keystore, AppInfo, DeviceInfo, out var @event, out var extraEvents);
bool success = service.Parse(payload, Keystore, AppInfo, DeviceInfo, out var @event, out var extraEvents);

if (success)
{
Expand All @@ -109,6 +109,7 @@ public List<ProtocolEvent> ResolveEventByPacket(SsoPacket packet)

Collection.Log.LogDebug(Tag, $"Incoming SSOFrame: {packet.Command}");
}
packet.Dispose();

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Lagrange.Core.Internal.Event.Protocol.Login.Ecdh;
namespace Lagrange.Core.Internal.Event.Protocol.Login;

internal class KeyExchangeEvent : ProtocolEvent
{
Expand Down
4 changes: 3 additions & 1 deletion Lagrange.Core/Internal/Packets/SsoPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lagrange.Core.Internal.Packets;

internal class SsoPacket
internal class SsoPacket : IDisposable
{
public byte PacketType { get; set; }

Expand All @@ -19,4 +19,6 @@ public SsoPacket(byte packetType, string command, uint sequence, BinaryPacket pa
Sequence = sequence;
Payload = payload;
}

public void Dispose() => Payload.Dispose();

Check failure on line 23 in Lagrange.Core/Internal/Packets/SsoPacket.cs

View workflow job for this annotation

GitHub Actions / build

'BinaryPacket' does not contain a definition for 'Dispose' and no accessible extension method 'Dispose' accepting a first argument of type 'BinaryPacket' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in Lagrange.Core/Internal/Packets/SsoPacket.cs

View workflow job for this annotation

GitHub Actions / build

'BinaryPacket' does not contain a definition for 'Dispose' and no accessible extension method 'Dispose' accepting a first argument of type 'BinaryPacket' could be found (are you missing a using directive or an assembly reference?)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;
Expand Down Expand Up @@ -40,12 +38,9 @@ protected override bool Build(AcceptGroupRequestEvent input, BotKeystore keystor
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out AcceptGroupRequestEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
Console.WriteLine(payload.Hex());

output = AcceptGroupRequestEvent.Result(0);
extraEvents = null;
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Extension;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;
Expand Down Expand Up @@ -38,11 +36,10 @@ protected override bool Build(GroupFSDownloadEvent input, BotKeystore keystore,
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupFSDownloadEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTco0x6D6Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTco0x6D6Response>>(input.AsSpan());
var download = packet.Body.Download;

string url = $"https://{download.DownloadIp}:443/ftn_handler/{download.DownloadUrl.Hex(true)}/?fname=";
Expand Down
8 changes: 2 additions & 6 deletions Lagrange.Core/Internal/Service/Action/GroupFSMoveService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Extension;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

Expand Down Expand Up @@ -39,11 +36,10 @@ protected override bool Build(GroupFSMoveEvent input, BotKeystore keystore, BotA
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out GroupFSMoveEvent output,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out GroupFSMoveEvent output,
out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<byte[]>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<byte[]>>(input.AsSpan());

output = GroupFSMoveEvent.Result((int)packet.ErrorCode);
extraEvents = null;
Expand Down
7 changes: 2 additions & 5 deletions Lagrange.Core/Internal/Service/Action/GroupFSViewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
using Lagrange.Core.Common.Entity;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

Expand Down Expand Up @@ -59,11 +57,10 @@ protected override bool Build(GroupFSViewEvent input, BotKeystore keystore, BotA
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupFSViewEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x6D8_1Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x6D8_1Response>>(input.AsSpan());

extraEvents = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

Expand Down Expand Up @@ -34,11 +32,10 @@ protected override bool Build(GroupKickMemberEvent input, BotKeystore keystore,
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupKickMemberEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x8A0_1Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x8A0_1Response>>(input.AsSpan());

output = GroupKickMemberEvent.Result((int)packet.ErrorCode);
extraEvents = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using ProtoBuf.Meta;

Expand Down Expand Up @@ -36,11 +34,10 @@ protected override bool Build(GroupMuteGlobalEvent input, BotKeystore keystore,
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupMuteGlobalEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x89A_0Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x89A_0Response>>(input.AsSpan());

output = GroupMuteGlobalEvent.Result((int)(packet.ErrorCode));
extraEvents = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

Expand Down Expand Up @@ -37,11 +35,10 @@ protected override bool Build(GroupMuteMemberEvent input, BotKeystore keystore,
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupMuteMemberEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x1253_1Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x1253_1Response>>(input.AsSpan());

output = GroupMuteMemberEvent.Result((int)packet.ErrorCode);
extraEvents = null;
Expand Down
7 changes: 2 additions & 5 deletions Lagrange.Core/Internal/Service/Action/GroupSetAdminService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

Expand Down Expand Up @@ -33,11 +31,10 @@ protected override bool Build(GroupSetAdminEvent input, BotKeystore keystore, Bo
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupSetAdminEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x1096_1Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x1096_1Response>>(input.AsSpan());

output = GroupSetAdminEvent.Result((int)packet.ErrorCode);
extraEvents = null;
Expand Down
7 changes: 2 additions & 5 deletions Lagrange.Core/Internal/Service/Action/RenameMemberService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

Expand Down Expand Up @@ -36,11 +34,10 @@ protected override bool Build(RenameMemberEvent input, BotKeystore keystore, Bot
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out RenameMemberEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x8FC_3Response>>(payload.AsSpan());
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x8FC_3Response>>(input.AsSpan());

output = RenameMemberEvent.Result((int)packet.ErrorCode);
extraEvents = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Action;
Expand Down Expand Up @@ -37,13 +34,9 @@ protected override bool Build(RequestFriendSearchEvent input, BotKeystore keysto
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out RequestFriendSearchEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);

Console.WriteLine(payload.Hex());

output = RequestFriendSearchEvent.Result(0);
extraEvents = null;
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
using ProtoBuf.Meta;
Expand Down Expand Up @@ -53,13 +51,9 @@ protected override bool Build(RequestFriendEvent input, BotKeystore keystore, Bo
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out RequestFriendEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);

Console.WriteLine(payload.Hex());

output = RequestFriendEvent.Result(0);
extraEvents = null;
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Action;
Expand Down Expand Up @@ -35,13 +32,9 @@ protected override bool Build(RequestFriendSettingEvent input, BotKeystore keyst
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out RequestFriendSettingEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);

Console.WriteLine(payload.Hex());

output = RequestFriendSettingEvent.Result(0);
extraEvents = null;
return true;
Expand Down
Loading

0 comments on commit 5650001

Please sign in to comment.