-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Implemented Group Send & Uploading for RecordEntity.cs
- Loading branch information
1 parent
e2feeb5
commit e742ca5
Showing
12 changed files
with
344 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,69 @@ | ||
using Lagrange.Core.Internal.Event.Message; | ||
using Lagrange.Core.Internal.Event.System; | ||
using Lagrange.Core.Internal.Packets.Service.Highway; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
using Lagrange.Core.Message; | ||
using Lagrange.Core.Message.Entity; | ||
using Lagrange.Core.Utility.Extension; | ||
|
||
namespace Lagrange.Core.Internal.Context.Uploader; | ||
|
||
[HighwayUploader(typeof(RecordEntity))] | ||
internal class PttUploader : IHighwayUploader | ||
{ | ||
private const string Tag = nameof(PttUploader); | ||
|
||
public Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
{ | ||
throw new NotImplementedException(); | ||
if (entity is RecordEntity { AudioStream: not null } record) | ||
{ | ||
var uploadEvent = RecordUploadEvent.Create(record, chain.GroupUin); | ||
var uploadResult = await context.Business.SendEvent(uploadEvent); | ||
var metaResult = (RecordUploadEvent)uploadResult[0]; | ||
|
||
var hwUrlEvent = HighwayUrlEvent.Create(); | ||
var highwayUrlResult = await context.Business.SendEvent(hwUrlEvent); | ||
var ticketResult = (HighwayUrlEvent)highwayUrlResult[0]; | ||
|
||
var index = metaResult.MsgInfo.MsgInfoBody[0].Index; | ||
var extend = new NTV2RichMediaHighwayExt | ||
{ | ||
FileUuid = index.FileUuid, | ||
UKey = metaResult.UKey, | ||
Network = Convert(metaResult.Network), | ||
MsgInfoBody = metaResult.MsgInfo.MsgInfoBody, | ||
BlockSize = 1024 * 1024, | ||
Hash = new NTHighwayHash { FileSha1 = index.Info.FileSha1.UnHex() } | ||
}; | ||
var extStream = extend.Serialize(); | ||
|
||
bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1008, record.AudioStream, ticketResult.SigSession, index.Info.FileHash.UnHex(), extStream.ToArray()); | ||
if (!hwSuccess) throw new Exception(); | ||
|
||
record.MsgInfo = metaResult.MsgInfo; // directly constructed by Tencent's BDH Server | ||
record.Compat = metaResult.Compat; // for legacy QQ | ||
} | ||
} | ||
|
||
private static NTHighwayNetwork Convert(List<IPv4> ipv4s) => new() | ||
{ | ||
IPv4s = ipv4s.Select(x => new NTHighwayIPv4 | ||
{ | ||
Domain = new NTHighwayDomain | ||
{ | ||
IsEnable = true, | ||
IP = ConvertIP(x.OutIP) | ||
}, | ||
Port = x.OutPort | ||
}).ToList() | ||
}; | ||
|
||
private static string ConvertIP(uint raw) | ||
{ | ||
var ip = BitConverter.GetBytes(raw); | ||
return $"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Lagrange.Core.Internal.Packets.Message.Component; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
using Lagrange.Core.Message.Entity; | ||
|
||
#pragma warning disable CS8618 | ||
|
||
namespace Lagrange.Core.Internal.Event.Message; | ||
|
||
internal class RecordUploadEvent : ProtocolEvent | ||
{ | ||
public RecordEntity Entity { get; } | ||
|
||
public uint? GroupUin { get; } | ||
|
||
public string UKey { get; } | ||
|
||
public MsgInfo MsgInfo { get; } | ||
|
||
public List<IPv4> Network { get; } | ||
|
||
public RichText Compat { get; } | ||
|
||
private RecordUploadEvent(RecordEntity entity, uint? groupUin) : base(true) | ||
{ | ||
Entity = entity; | ||
GroupUin = groupUin; | ||
} | ||
|
||
private RecordUploadEvent(int resultCode, string uKey, MsgInfo msgInfo, List<IPv4> network, RichText compat) : base(resultCode) | ||
{ | ||
UKey = uKey; | ||
MsgInfo = msgInfo; | ||
Network = network; | ||
Compat = compat; | ||
} | ||
|
||
public static RecordUploadEvent Create(RecordEntity entity, uint? groupUin) | ||
=> new(entity, groupUin); | ||
|
||
public static RecordUploadEvent Result(int resultCode, string uKey, MsgInfo msgInfo, List<IPv4> network, RichText compat) | ||
=> new(resultCode, uKey, msgInfo, network, compat); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Lagrange.Core/Internal/Packets/Service/Highway/NTV2RichMediaHighwayExt.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Service.Highway; | ||
|
||
//Resharper Disable InconsistentNaming | ||
#pragma warning disable CS8618 | ||
|
||
[ProtoContract] | ||
internal class NTV2RichMediaHighwayExt | ||
{ | ||
[ProtoMember(1)] public string FileUuid { get; set; } | ||
|
||
[ProtoMember(2)] public string UKey { get; set; } | ||
|
||
[ProtoMember(5)] public NTHighwayNetwork Network { get; set; } | ||
|
||
[ProtoMember(6)] public List<MsgInfoBody> MsgInfoBody { get; set; } | ||
|
||
[ProtoMember(10)] public uint BlockSize { get; set; } | ||
|
||
[ProtoMember(11)] public NTHighwayHash Hash { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class NTHighwayHash | ||
{ | ||
[ProtoMember(1)] public byte[] FileSha1 { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class NTHighwayNetwork | ||
{ | ||
[ProtoMember(1)] public List<NTHighwayIPv4> IPv4s { get; set; } | ||
} | ||
|
||
|
||
[ProtoContract] | ||
internal class NTHighwayIPv4 | ||
{ | ||
[ProtoMember(1)] public NTHighwayDomain Domain { get; set; } | ||
|
||
[ProtoMember(2)] public uint Port { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class NTHighwayDomain | ||
{ | ||
[ProtoMember(1)] public bool IsEnable { get; set; } // true | ||
|
||
[ProtoMember(2)] public string IP { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.