Skip to content

Commit

Permalink
[Core] Replaced trpc.qq_new_tech.status_svc.StatusService.Register to…
Browse files Browse the repository at this point in the history
… trpc.msg.register_proxy.RegisterProxy.SsoInfoSync
  • Loading branch information
Linwenxuan04 committed Nov 11, 2024
1 parent ae400c0 commit a5e8e10
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ private async Task QueryTransEmpState(Func<TransEmpEvent, Task<bool>> callback)

public async Task<bool> 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");
Expand All @@ -448,9 +448,7 @@ public async Task<bool> 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");
}
Expand Down
17 changes: 8 additions & 9 deletions Lagrange.Core/Internal/Event/System/InfoSyncEvent.cs
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions Lagrange.Core/Internal/Packets/System/OnlineBusinessInfo.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Lagrange.Core.Internal.Packets.System;
/// trpc.qq_new_tech.status_svc.StatusService.Register
/// </summary>
[ProtoContract]
internal class ServiceRegister
internal class RegisterInfo
{
[ProtoMember(1)] public string? Guid { get; set; }

Expand All @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Lagrange.Core.Internal.Packets.System;

[ProtoContract]
internal class ServiceRegisterResponse
internal class RegisterInfoResponse
{
[ProtoMember(2)] public string? Message { get; set; }

Expand Down
68 changes: 68 additions & 0 deletions Lagrange.Core/Internal/Packets/System/SsoInfoSync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.System;

/// <summary>
/// trpc.msg.register_proxy.RegisterProxy.SsoInfoSync
/// </summary>
[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<uint, int>? 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; }
}
17 changes: 17 additions & 0 deletions Lagrange.Core/Internal/Packets/System/SsoInfoSyncResponse.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
92 changes: 92 additions & 0 deletions Lagrange.Core/Internal/Service/System/InfoSyncService.cs
Original file line number Diff line number Diff line change
@@ -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<InfoSyncEvent>
{
protected override bool Build(InfoSyncEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? 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<uint, int>()
},
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<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out InfoSyncEvent output, out List<ProtocolEvent>? extraEvents)
{
var response = Serializer.Deserialize<SsoInfoSyncResponse>(input);

output = InfoSyncEvent.Result(response?.RegisterInfoResponse?.Message ?? "IDK");
extraEvents = null;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class StatusRegisterService : BaseService<StatusRegisterEvent>
protected override bool Build(StatusRegisterEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
var packet = new ServiceRegister
var packet = new RegisterInfo
{
Guid = device.Guid.ToByteArray().Hex(true),
KickPC = 0,
Expand Down Expand Up @@ -42,7 +42,7 @@ protected override bool Build(StatusRegisterEvent input, BotKeystore keystore, B
protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out StatusRegisterEvent output, out List<ProtocolEvent>? extraEvents)
{
var response = Serializer.Deserialize<ServiceRegisterResponse>(input);
var response = Serializer.Deserialize<RegisterInfoResponse>(input);

output = StatusRegisterEvent.Result(response.Message ?? "OK");
extraEvents = null;
Expand Down

0 comments on commit a5e8e10

Please sign in to comment.