-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dca81f6
commit abe76bc
Showing
13 changed files
with
385 additions
and
28 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,23 +1,90 @@ | ||
using Lagrange.Core.Internal.Event.Message; | ||
using Lagrange.Core.Internal.Event.System; | ||
using Lagrange.Core.Internal.Packets.Service.Highway; | ||
using Lagrange.Core.Message; | ||
using Lagrange.Core.Message.Entity; | ||
using Lagrange.Core.Utility.Extension; | ||
|
||
namespace Lagrange.Core.Internal.Context.Uploader; | ||
|
||
[HighwayUploader(typeof(FileEntity))] | ||
internal class FileUploader : IHighwayUploader | ||
/// <summary> | ||
/// This FileUploader should be called manually | ||
/// </summary> | ||
internal static class FileUploader | ||
{ | ||
public Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
public static Task<bool> UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
public static async Task<bool> UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity) | ||
{ | ||
if (entity is FileEntity { FileStream: not null } file) | ||
if (entity is not FileEntity { FileStream: not null } file) return false; | ||
|
||
var uploadEvent = GroupFSUploadEvent.Create(chain.GroupUin ?? 0, file); | ||
var result = await context.Business.SendEvent(uploadEvent); | ||
var uploadResp = (GroupFSUploadEvent)result[0]; | ||
|
||
var hwUrlEvent = HighwayUrlEvent.Create(); | ||
var highwayUrlResult = await context.Business.SendEvent(hwUrlEvent); | ||
var ticketResult = (HighwayUrlEvent)highwayUrlResult[0]; | ||
|
||
var ext = new FileUploadExt | ||
{ | ||
var uploadEvent = GroupFSUploadEvent.Create(chain.GroupUin ?? 0, file); | ||
var result = await context.Business.SendEvent(uploadEvent); | ||
} | ||
Unknown1 = 100, | ||
Unknown2 = 1, | ||
Entry = new FileUploadEntry | ||
{ | ||
BusiBuff = new ExcitingBusiInfo | ||
{ | ||
SenderUin = context.Keystore.Uin, | ||
ReceiverUin = chain.GroupUin ?? 0, | ||
GroupCode = chain.GroupUin ?? 0 | ||
}, | ||
FileEntry = new ExcitingFileEntry | ||
{ | ||
FileSize = file.FileStream.Length, | ||
Md5 = file.FileMd5, | ||
CheckKey = uploadResp.CheckKey, | ||
Md5S2 = file.FileMd5, | ||
FileId = uploadResp.FileId, | ||
UploadKey = uploadResp.UploadKey | ||
}, | ||
ClientInfo = new ExcitingClientInfo | ||
{ | ||
ClientType = 3, | ||
AppId = "100", | ||
TerminalType = 3, | ||
ClientVer = "1.1.1", | ||
Unknown = 4 | ||
}, | ||
FileNameInfo = new ExcitingFileNameInfo | ||
{ | ||
FileName = file.FileName | ||
}, | ||
Host = new ExcitingHostConfig | ||
{ | ||
Hosts = new List<ExcitingHostInfo> | ||
{ | ||
new() | ||
{ | ||
Url = new ExcitingUrlInfo | ||
{ | ||
Unknown = 1, | ||
Host = uploadResp.Ip | ||
}, | ||
Port = uploadResp.Port | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(71, file.FileStream, ticketResult.SigSession, file.FileMd5, ext.Serialize().ToArray()); | ||
if (!hwSuccess) return false; | ||
|
||
var sendEvent = GroupSendFileEvent.Create(chain.GroupUin ?? 0, uploadResp.FileId); | ||
var sendResult = await context.Business.SendEvent(sendEvent); | ||
return sendResult.Count != 0 && ((GroupSendFileEvent)sendResult[0]).ResultCode == 0; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
Lagrange.Core/Internal/Event/Message/GroupSendFileEvent.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,20 @@ | ||
namespace Lagrange.Core.Internal.Event.Message; | ||
|
||
internal class GroupSendFileEvent : ProtocolEvent | ||
{ | ||
public uint GroupUin { get; } | ||
|
||
public string FileKey { get; } = string.Empty; | ||
|
||
private GroupSendFileEvent(uint groupUin, string fileKey) : base(true) | ||
{ | ||
GroupUin = groupUin; | ||
FileKey = fileKey; | ||
} | ||
|
||
private GroupSendFileEvent(int resultCode) : base(resultCode) { } | ||
|
||
public static GroupSendFileEvent Create(uint groupUin, string fileKey) => new(groupUin, fileKey); | ||
|
||
public static GroupSendFileEvent Result(int resultCode) => new(resultCode); | ||
} |
103 changes: 103 additions & 0 deletions
103
Lagrange.Core/Internal/Packets/Service/Highway/FileUploadExt.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,103 @@ | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Service.Highway; | ||
|
||
#pragma warning disable CS8618 | ||
|
||
[ProtoContract] | ||
internal class FileUploadExt | ||
{ | ||
[ProtoMember(1)] public int Unknown1 { get; set; } | ||
|
||
[ProtoMember(2)] public int Unknown2 { get; set; } | ||
|
||
[ProtoMember(3)] public int Unknown3 { get; set; } | ||
|
||
[ProtoMember(100)] public FileUploadEntry Entry { get; set; } | ||
|
||
[ProtoMember(200)] public int Unknown200 { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class FileUploadEntry | ||
{ | ||
[ProtoMember(100)] public ExcitingBusiInfo BusiBuff { get; set; } | ||
|
||
[ProtoMember(200)] public ExcitingFileEntry FileEntry { get; set; } | ||
|
||
[ProtoMember(300)] public ExcitingClientInfo ClientInfo { get; set; } | ||
|
||
[ProtoMember(400)] public ExcitingFileNameInfo FileNameInfo { get; set; } | ||
|
||
[ProtoMember(500)] public ExcitingHostConfig Host { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingBusiInfo | ||
{ | ||
[ProtoMember(1)] public int BusId { get; set; } | ||
|
||
[ProtoMember(100)] public long SenderUin { get; set; } | ||
|
||
[ProtoMember(200)] public long ReceiverUin { get; set; } | ||
|
||
[ProtoMember(400)] public long GroupCode { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingFileEntry | ||
{ | ||
[ProtoMember(100)] public long FileSize { get; set; } | ||
|
||
[ProtoMember(200)] public byte[] Md5 { get; set; } | ||
|
||
[ProtoMember(300)] public byte[] CheckKey { get; set; } | ||
|
||
[ProtoMember(400)] public byte[] Md5S2 { get; set; } | ||
|
||
[ProtoMember(600)] public string FileId { get; set; } | ||
|
||
[ProtoMember(700)] public byte[] UploadKey { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingClientInfo | ||
{ | ||
[ProtoMember(100)] public int ClientType { get; set; } | ||
|
||
[ProtoMember(200)] public string AppId { get; set; } | ||
|
||
[ProtoMember(300)] public int TerminalType { get; set; } | ||
|
||
[ProtoMember(400)] public string ClientVer { get; set; } | ||
|
||
[ProtoMember(600)] public int Unknown { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingFileNameInfo | ||
{ | ||
[ProtoMember(100)] public string FileName { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingHostConfig | ||
{ | ||
[ProtoMember(200)] public List<ExcitingHostInfo> Hosts { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingHostInfo | ||
{ | ||
[ProtoMember(1)] public ExcitingUrlInfo Url { get; set; } | ||
|
||
[ProtoMember(2)] public uint Port { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class ExcitingUrlInfo | ||
{ | ||
[ProtoMember(1)] public int Unknown { get; set; } | ||
|
||
[ProtoMember(2)] public string Host { get; set; } | ||
} |
40 changes: 40 additions & 0 deletions
40
Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x6D9_4.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,40 @@ | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
|
||
#pragma warning disable CS8618 | ||
// ReSharper disable InconsistentNaming | ||
|
||
/// <summary> | ||
/// Group Send File | ||
/// </summary> | ||
[ProtoContract] | ||
[OidbSvcTrpcTcp(0x6D9, 4)] | ||
internal class OidbSvcTrpcTcp0x6D9_4 | ||
{ | ||
[ProtoMember(5)] public OidbSvcTrpcTcp0x6D9_4Body Body { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class OidbSvcTrpcTcp0x6D9_4Body | ||
{ | ||
[ProtoMember(1)] public uint GroupUin { get; set; } | ||
|
||
[ProtoMember(2)] public uint Type { get; set; } // 2 | ||
|
||
[ProtoMember(3)] public OidbSvcTrpcTcp0x6D9_4Info Info { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class OidbSvcTrpcTcp0x6D9_4Info | ||
{ | ||
[ProtoMember(1)] public uint BusiType { get; set; } // 102 | ||
|
||
[ProtoMember(2)] public string FileId { get; set; } | ||
|
||
[ProtoMember(3)] public uint Field3 { get; set; } // random | ||
|
||
[ProtoMember(4)] public string? Field4 { get; set; } // null | ||
|
||
[ProtoMember(5)] public bool Field5 { get; set; } // true | ||
} |
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.