From a5e8e1087ad99ae6e9774fdf5fd6598304000530 Mon Sep 17 00:00:00 2001 From: Linwenxuan04 Date: Mon, 11 Nov 2024 08:58:50 -0500 Subject: [PATCH] [Core] Replaced trpc.qq_new_tech.status_svc.StatusService.Register to trpc.msg.register_proxy.RegisterProxy.SsoInfoSync --- .../Logic/Implementation/WtExchangeLogic.cs | 8 +- .../Internal/Event/System/InfoSyncEvent.cs | 17 ++-- .../Packets/System/OnlineBusinessInfo.cs | 11 +++ .../{ServiceRegister.cs => RegisterInfo.cs} | 8 +- ...terResponse.cs => RegisterInfoResponse.cs} | 2 +- .../Internal/Packets/System/SsoInfoSync.cs | 68 ++++++++++++++ .../Packets/System/SsoInfoSyncResponse.cs | 17 ++++ .../Service/System/InfoSyncService.cs | 92 +++++++++++++++++++ .../Service/System/StatusRegisterService.cs | 4 +- 9 files changed, 209 insertions(+), 18 deletions(-) create mode 100644 Lagrange.Core/Internal/Packets/System/OnlineBusinessInfo.cs rename Lagrange.Core/Internal/Packets/System/{ServiceRegister.cs => RegisterInfo.cs} (76%) rename Lagrange.Core/Internal/Packets/System/{ServiceRegisterResponse.cs => RegisterInfoResponse.cs} (89%) create mode 100644 Lagrange.Core/Internal/Packets/System/SsoInfoSync.cs create mode 100644 Lagrange.Core/Internal/Packets/System/SsoInfoSyncResponse.cs create mode 100644 Lagrange.Core/Internal/Service/System/InfoSyncService.cs diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs index f2e7a7421..1f76515f3 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs @@ -432,13 +432,13 @@ private async Task QueryTransEmpState(Func> callback) public async Task BotOnline(BotOnlineEvent.OnlineReason reason = BotOnlineEvent.OnlineReason.Login) { - var registerEvent = StatusRegisterEvent.Create(); + var registerEvent = InfoSyncEvent.Create(); var registerResponse = await Collection.Business.SendEvent(registerEvent); var heartbeatDelegate = new Action(async () => await Collection.Business.PushEvent(SsoAliveEvent.Create())); if (registerResponse.Count != 0) { - var resp = (StatusRegisterEvent)registerResponse[0]; + var resp = (InfoSyncEvent)registerResponse[0]; Collection.Log.LogInfo(Tag, $"Register Status: {resp.Message}"); bool result = resp.Message.Contains("register success"); @@ -448,9 +448,7 @@ public async Task BotOnline(BotOnlineEvent.OnlineReason reason = BotOnline var onlineEvent = new BotOnlineEvent(reason); Collection.Invoker.PostEvent(onlineEvent); - - await Collection.Business.PushEvent(InfoSyncEvent.Create()); - + _reLoginTimer.Change(TimeSpan.FromDays(15), TimeSpan.FromDays(15)); Collection.Log.LogInfo(Tag, "AutoReLogin Enabled, session would be refreshed in 15 days period"); } diff --git a/Lagrange.Core/Internal/Event/System/InfoSyncEvent.cs b/Lagrange.Core/Internal/Event/System/InfoSyncEvent.cs index edb13300f..3e13c9de0 100644 --- a/Lagrange.Core/Internal/Event/System/InfoSyncEvent.cs +++ b/Lagrange.Core/Internal/Event/System/InfoSyncEvent.cs @@ -1,17 +1,16 @@ +#pragma warning disable CS8618 + namespace Lagrange.Core.Internal.Event.System; internal class InfoSyncEvent : ProtocolEvent { - public uint Random { get; set; } - - private InfoSyncEvent() : base(true) - { - Random = (uint) new Random().Next(); - } + public string Message { get; set; } - private InfoSyncEvent(int resultCode) : base(resultCode) { } + private InfoSyncEvent() : base(true) { } + + private InfoSyncEvent(string result) : base(0) => Message = result; public static InfoSyncEvent Create() => new(); - - public static InfoSyncEvent Result(int resultCode) => new(resultCode); + + public static InfoSyncEvent Result(string result) => new(result); } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/System/OnlineBusinessInfo.cs b/Lagrange.Core/Internal/Packets/System/OnlineBusinessInfo.cs new file mode 100644 index 000000000..20d83ded9 --- /dev/null +++ b/Lagrange.Core/Internal/Packets/System/OnlineBusinessInfo.cs @@ -0,0 +1,11 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.System; + +[ProtoContract] +internal class OnlineBusinessInfo +{ + [ProtoMember(1)] public uint NotifySwitch { get; set; } + + [ProtoMember(2)] public uint BindUinNotifySwitch { get; set; } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/System/ServiceRegister.cs b/Lagrange.Core/Internal/Packets/System/RegisterInfo.cs similarity index 76% rename from Lagrange.Core/Internal/Packets/System/ServiceRegister.cs rename to Lagrange.Core/Internal/Packets/System/RegisterInfo.cs index c9488c851..02a2b666e 100644 --- a/Lagrange.Core/Internal/Packets/System/ServiceRegister.cs +++ b/Lagrange.Core/Internal/Packets/System/RegisterInfo.cs @@ -6,7 +6,7 @@ namespace Lagrange.Core.Internal.Packets.System; /// trpc.qq_new_tech.status_svc.StatusService.Register /// [ProtoContract] -internal class ServiceRegister +internal class RegisterInfo { [ProtoMember(1)] public string? Guid { get; set; } @@ -25,4 +25,10 @@ internal class ServiceRegister [ProtoMember(8)] public int? RegisterVendorType { get; set; } [ProtoMember(9)] public int? RegType { get; set; } + + [ProtoMember(10)] public OnlineBusinessInfo? BusinessInfo { get; set; } + + [ProtoMember(11)] public int? BatteryStatus { get; set; } + + [ProtoMember(12)] public uint? Field12 { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/System/ServiceRegisterResponse.cs b/Lagrange.Core/Internal/Packets/System/RegisterInfoResponse.cs similarity index 89% rename from Lagrange.Core/Internal/Packets/System/ServiceRegisterResponse.cs rename to Lagrange.Core/Internal/Packets/System/RegisterInfoResponse.cs index 8dc82f792..4ca96a805 100644 --- a/Lagrange.Core/Internal/Packets/System/ServiceRegisterResponse.cs +++ b/Lagrange.Core/Internal/Packets/System/RegisterInfoResponse.cs @@ -3,7 +3,7 @@ namespace Lagrange.Core.Internal.Packets.System; [ProtoContract] -internal class ServiceRegisterResponse +internal class RegisterInfoResponse { [ProtoMember(2)] public string? Message { get; set; } diff --git a/Lagrange.Core/Internal/Packets/System/SsoInfoSync.cs b/Lagrange.Core/Internal/Packets/System/SsoInfoSync.cs new file mode 100644 index 000000000..a9ff52d6f --- /dev/null +++ b/Lagrange.Core/Internal/Packets/System/SsoInfoSync.cs @@ -0,0 +1,68 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.System; + +/// +/// trpc.msg.register_proxy.RegisterProxy.SsoInfoSync +/// +[ProtoContract] +internal class SsoInfoSyncRequest +{ + [ProtoMember(1)] public uint SyncFlag { get; set; } + + [ProtoMember(2)] public uint? ReqRandom { get; set; } + + [ProtoMember(4)] public uint? CurActiveStatus { get; set; } + + [ProtoMember(5)] public ulong? GroupLastMsgTime { get; set; } + + [ProtoMember(6)] public SsoC2CInfoSync? C2CInfoSync { get; set; } + + [ProtoMember(8)] public NormalConfig? NormalConfig { get; set; } + + [ProtoMember(9)] public RegisterInfo? RegisterInfo { get; set; } + + [ProtoMember(10)] public UnknownStructure? UnknownStructure { get; set; } + + [ProtoMember(11)] public CurAppState? AppState { get; set; } +} + +[ProtoContract] +internal class SsoC2CMsgCookie +{ + [ProtoMember(1)] public ulong C2CLastMsgTime { get; set; } +} + +[ProtoContract] +internal class SsoC2CInfoSync +{ + [ProtoMember(1)] public SsoC2CMsgCookie? C2CMsgCookie { get; set; } + + [ProtoMember(2)] public ulong C2CLastMsgTime { get; set; } + + [ProtoMember(3)] public SsoC2CMsgCookie? LastC2CMsgCookie { get; set; } +} + +[ProtoContract] +internal class NormalConfig +{ + [ProtoMember(1)] public Dictionary? IntCfg { get; set; } +} + +[ProtoContract] +internal class CurAppState +{ + [ProtoMember(1)] public uint? IsDelayRequest { get; set; } + + [ProtoMember(2)] public uint? AppStatus { get; set; } + + [ProtoMember(3)] public uint? SilenceStatus { get; set; } +} + +[ProtoContract] +internal class UnknownStructure +{ + [ProtoMember(1)] public uint? GroupCode { get; set; } + + [ProtoMember(2)] public uint Flag2 { get; set; } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Packets/System/SsoInfoSyncResponse.cs b/Lagrange.Core/Internal/Packets/System/SsoInfoSyncResponse.cs new file mode 100644 index 000000000..60d4f3036 --- /dev/null +++ b/Lagrange.Core/Internal/Packets/System/SsoInfoSyncResponse.cs @@ -0,0 +1,17 @@ +using ProtoBuf; + +namespace Lagrange.Core.Internal.Packets.System; + +[ProtoContract] +internal class SsoInfoSyncResponse +{ + [ProtoMember(3)] public uint Field3 { get; set; } + + [ProtoMember(4)] public uint Field4 { get; set; } + + [ProtoMember(6)] public uint Field6 { get; set; } + + [ProtoMember(7)] public RegisterInfoResponse? RegisterInfoResponse { get; set; } + + [ProtoMember(9)] public uint Field9 { get; set; } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/System/InfoSyncService.cs b/Lagrange.Core/Internal/Service/System/InfoSyncService.cs new file mode 100644 index 000000000..12b1a332c --- /dev/null +++ b/Lagrange.Core/Internal/Service/System/InfoSyncService.cs @@ -0,0 +1,92 @@ +using Lagrange.Core.Common; +using Lagrange.Core.Internal.Event; +using Lagrange.Core.Internal.Event.System; +using Lagrange.Core.Internal.Packets.System; +using Lagrange.Core.Utility.Extension; +using ProtoBuf; + +namespace Lagrange.Core.Internal.Service.System; + +[EventSubscribe(typeof(InfoSyncEvent))] +[Service("trpc.msg.register_proxy.RegisterProxy.SsoInfoSync")] +internal class InfoSyncService : BaseService +{ + protected override bool Build(InfoSyncEvent input, BotKeystore keystore, BotAppInfo appInfo, + BotDeviceInfo device, out Span output, out List>? extraPackets) + { + var packet = new SsoInfoSyncRequest + { + SyncFlag = 735, + ReqRandom = (uint)Random.Shared.Next(), + CurActiveStatus = 2, + GroupLastMsgTime = 0, + C2CInfoSync = new SsoC2CInfoSync + { + C2CMsgCookie = new SsoC2CMsgCookie + { + C2CLastMsgTime = 0 + }, + C2CLastMsgTime = 0, + LastC2CMsgCookie = new SsoC2CMsgCookie + { + C2CLastMsgTime = 0 + } + }, + NormalConfig = new NormalConfig + { + IntCfg = new Dictionary() + }, + RegisterInfo = new RegisterInfo + { + Guid = device.Guid.ToByteArray().Hex(true), + KickPC = 0, + CurrentVersion = appInfo.CurrentVersion, + IsFirstRegisterProxyOnline = 1, + LocaleId = 2052, + Device = new OnlineDeviceInfo() + { + User = device.DeviceName, + Os = appInfo.Kernel, + OsVer = device.SystemKernel, + VendorName = "", + OsLower = appInfo.VendorOs, + }, + SetMute = 0, + RegisterVendorType = 6, + RegType = 0, + BusinessInfo = new OnlineBusinessInfo + { + NotifySwitch = 1, + BindUinNotifySwitch = 1 + }, + BatteryStatus = 0, + Field12 = 1 + }, + UnknownStructure = new UnknownStructure + { + GroupCode = 0, + Flag2 = 2 + }, + AppState = new CurAppState + { + IsDelayRequest = 0, + AppStatus = 0, + SilenceStatus = 0 + } + }; + + output = packet.Serialize(); + extraPackets = null; + return true; + } + + protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, + out InfoSyncEvent output, out List? extraEvents) + { + var response = Serializer.Deserialize(input); + + output = InfoSyncEvent.Result(response?.RegisterInfoResponse?.Message ?? "IDK"); + extraEvents = null; + return true; + } +} \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/System/StatusRegisterService.cs b/Lagrange.Core/Internal/Service/System/StatusRegisterService.cs index 828f73fd1..7fe6f088c 100644 --- a/Lagrange.Core/Internal/Service/System/StatusRegisterService.cs +++ b/Lagrange.Core/Internal/Service/System/StatusRegisterService.cs @@ -14,7 +14,7 @@ internal class StatusRegisterService : BaseService protected override bool Build(StatusRegisterEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out Span output, out List>? extraPackets) { - var packet = new ServiceRegister + var packet = new RegisterInfo { Guid = device.Guid.ToByteArray().Hex(true), KickPC = 0, @@ -42,7 +42,7 @@ protected override bool Build(StatusRegisterEvent input, BotKeystore keystore, B protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out StatusRegisterEvent output, out List? extraEvents) { - var response = Serializer.Deserialize(input); + var response = Serializer.Deserialize(input); output = StatusRegisterEvent.Result(response.Message ?? "OK"); extraEvents = null;