Skip to content

Commit abe76bc

Browse files
committed
[Core] Implemented GroupFSUpload
1 parent dca81f6 commit abe76bc

File tree

13 files changed

+385
-28
lines changed

13 files changed

+385
-28
lines changed

Lagrange.Core/Common/Interface/Api/GroupExt.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Lagrange.Core.Common.Entity;
22
using Lagrange.Core.Event.EventArg;
3+
using Lagrange.Core.Message.Entity;
34

45
namespace Lagrange.Core.Common.Interface.Api;
56

@@ -77,6 +78,9 @@ public static Task<string> FetchGroupFSDownload(this BotContext bot, uint groupU
7778

7879
public static Task<bool> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory)
7980
=> bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory);
81+
82+
public static Task<bool> GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity)
83+
=> bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity);
8084

8185
#endregion
8286
}

Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Lagrange.Core.Common.Entity;
22
using Lagrange.Core.Internal.Context.Attributes;
3+
using Lagrange.Core.Internal.Context.Uploader;
34
using Lagrange.Core.Internal.Event.Action;
45
using Lagrange.Core.Internal.Event.Message;
56
using Lagrange.Core.Internal.Event.System;
67
using Lagrange.Core.Message;
8+
using Lagrange.Core.Message.Entity;
79

810
namespace Lagrange.Core.Internal.Context.Logic.Implementation;
911

@@ -144,6 +146,18 @@ public async Task<bool> GroupFSMove(uint groupUin, string fileId, string parentD
144146
return events.Count != 0 && ((GroupFSMoveEvent)events[0]).ResultCode == 0;
145147
}
146148

149+
public Task<bool> GroupFSUpload(uint groupUin, FileEntity fileEntity)
150+
{
151+
try
152+
{
153+
return FileUploader.UploadGroup(Collection, MessageBuilder.Group(groupUin).Build(), fileEntity);
154+
}
155+
catch
156+
{
157+
return Task.FromResult(false);
158+
}
159+
}
160+
147161
public async Task<bool> RecallGroupMessage(uint groupUin, MessageResult result)
148162
{
149163
if (result.Sequence == null) return false;
Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,90 @@
11
using Lagrange.Core.Internal.Event.Message;
2+
using Lagrange.Core.Internal.Event.System;
3+
using Lagrange.Core.Internal.Packets.Service.Highway;
24
using Lagrange.Core.Message;
35
using Lagrange.Core.Message.Entity;
6+
using Lagrange.Core.Utility.Extension;
47

58
namespace Lagrange.Core.Internal.Context.Uploader;
69

7-
[HighwayUploader(typeof(FileEntity))]
8-
internal class FileUploader : IHighwayUploader
10+
/// <summary>
11+
/// This FileUploader should be called manually
12+
/// </summary>
13+
internal static class FileUploader
914
{
10-
public Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity)
15+
public static Task<bool> UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity)
1116
{
1217
throw new NotImplementedException();
1318
}
1419

15-
public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity)
20+
public static async Task<bool> UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity)
1621
{
17-
if (entity is FileEntity { FileStream: not null } file)
22+
if (entity is not FileEntity { FileStream: not null } file) return false;
23+
24+
var uploadEvent = GroupFSUploadEvent.Create(chain.GroupUin ?? 0, file);
25+
var result = await context.Business.SendEvent(uploadEvent);
26+
var uploadResp = (GroupFSUploadEvent)result[0];
27+
28+
var hwUrlEvent = HighwayUrlEvent.Create();
29+
var highwayUrlResult = await context.Business.SendEvent(hwUrlEvent);
30+
var ticketResult = (HighwayUrlEvent)highwayUrlResult[0];
31+
32+
var ext = new FileUploadExt
1833
{
19-
var uploadEvent = GroupFSUploadEvent.Create(chain.GroupUin ?? 0, file);
20-
var result = await context.Business.SendEvent(uploadEvent);
21-
}
34+
Unknown1 = 100,
35+
Unknown2 = 1,
36+
Entry = new FileUploadEntry
37+
{
38+
BusiBuff = new ExcitingBusiInfo
39+
{
40+
SenderUin = context.Keystore.Uin,
41+
ReceiverUin = chain.GroupUin ?? 0,
42+
GroupCode = chain.GroupUin ?? 0
43+
},
44+
FileEntry = new ExcitingFileEntry
45+
{
46+
FileSize = file.FileStream.Length,
47+
Md5 = file.FileMd5,
48+
CheckKey = uploadResp.CheckKey,
49+
Md5S2 = file.FileMd5,
50+
FileId = uploadResp.FileId,
51+
UploadKey = uploadResp.UploadKey
52+
},
53+
ClientInfo = new ExcitingClientInfo
54+
{
55+
ClientType = 3,
56+
AppId = "100",
57+
TerminalType = 3,
58+
ClientVer = "1.1.1",
59+
Unknown = 4
60+
},
61+
FileNameInfo = new ExcitingFileNameInfo
62+
{
63+
FileName = file.FileName
64+
},
65+
Host = new ExcitingHostConfig
66+
{
67+
Hosts = new List<ExcitingHostInfo>
68+
{
69+
new()
70+
{
71+
Url = new ExcitingUrlInfo
72+
{
73+
Unknown = 1,
74+
Host = uploadResp.Ip
75+
},
76+
Port = uploadResp.Port
77+
}
78+
}
79+
}
80+
}
81+
};
82+
83+
bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(71, file.FileStream, ticketResult.SigSession, file.FileMd5, ext.Serialize().ToArray());
84+
if (!hwSuccess) return false;
85+
86+
var sendEvent = GroupSendFileEvent.Create(chain.GroupUin ?? 0, uploadResp.FileId);
87+
var sendResult = await context.Business.SendEvent(sendEvent);
88+
return sendResult.Count != 0 && ((GroupSendFileEvent)sendResult[0]).ResultCode == 0;
2289
}
2390
}

Lagrange.Core/Internal/Event/Message/GroupFSUploadEvent.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,36 @@ namespace Lagrange.Core.Internal.Event.Message;
77
internal class GroupFSUploadEvent : ProtocolEvent
88
{
99
public uint GroupUin { get; }
10+
1011
public FileEntity Entity { get; }
12+
13+
public string FileId { get; }
14+
15+
public byte[] UploadKey { get; }
16+
17+
public byte[] CheckKey { get; }
18+
19+
public string Ip { get; }
20+
21+
public uint Port { get; }
1122

1223
private GroupFSUploadEvent(uint groupUin, FileEntity entity) : base(true)
1324
{
1425
GroupUin = groupUin;
1526
Entity = entity;
1627
}
1728

18-
private GroupFSUploadEvent(int resultCode) : base(resultCode)
29+
private GroupFSUploadEvent(int resultCode, string fileId, byte[] uploadKey, byte[] checkKey, string ip, uint port) : base(resultCode)
1930
{
31+
FileId = fileId;
32+
UploadKey = uploadKey;
33+
CheckKey = checkKey;
34+
Ip = ip;
35+
Port = port;
2036
}
2137

2238
public static GroupFSUploadEvent Create(uint groupUin, FileEntity entity) => new(groupUin, entity);
39+
40+
public static GroupFSUploadEvent Result(int resultCode, string fileId, byte[] uploadKey, byte[] checkKey, string ip, uint port)
41+
=> new(resultCode, fileId, uploadKey, checkKey, ip, port);
2342
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Lagrange.Core.Internal.Event.Message;
2+
3+
internal class GroupSendFileEvent : ProtocolEvent
4+
{
5+
public uint GroupUin { get; }
6+
7+
public string FileKey { get; } = string.Empty;
8+
9+
private GroupSendFileEvent(uint groupUin, string fileKey) : base(true)
10+
{
11+
GroupUin = groupUin;
12+
FileKey = fileKey;
13+
}
14+
15+
private GroupSendFileEvent(int resultCode) : base(resultCode) { }
16+
17+
public static GroupSendFileEvent Create(uint groupUin, string fileKey) => new(groupUin, fileKey);
18+
19+
public static GroupSendFileEvent Result(int resultCode) => new(resultCode);
20+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using ProtoBuf;
2+
3+
namespace Lagrange.Core.Internal.Packets.Service.Highway;
4+
5+
#pragma warning disable CS8618
6+
7+
[ProtoContract]
8+
internal class FileUploadExt
9+
{
10+
[ProtoMember(1)] public int Unknown1 { get; set; }
11+
12+
[ProtoMember(2)] public int Unknown2 { get; set; }
13+
14+
[ProtoMember(3)] public int Unknown3 { get; set; }
15+
16+
[ProtoMember(100)] public FileUploadEntry Entry { get; set; }
17+
18+
[ProtoMember(200)] public int Unknown200 { get; set; }
19+
}
20+
21+
[ProtoContract]
22+
internal class FileUploadEntry
23+
{
24+
[ProtoMember(100)] public ExcitingBusiInfo BusiBuff { get; set; }
25+
26+
[ProtoMember(200)] public ExcitingFileEntry FileEntry { get; set; }
27+
28+
[ProtoMember(300)] public ExcitingClientInfo ClientInfo { get; set; }
29+
30+
[ProtoMember(400)] public ExcitingFileNameInfo FileNameInfo { get; set; }
31+
32+
[ProtoMember(500)] public ExcitingHostConfig Host { get; set; }
33+
}
34+
35+
[ProtoContract]
36+
internal class ExcitingBusiInfo
37+
{
38+
[ProtoMember(1)] public int BusId { get; set; }
39+
40+
[ProtoMember(100)] public long SenderUin { get; set; }
41+
42+
[ProtoMember(200)] public long ReceiverUin { get; set; }
43+
44+
[ProtoMember(400)] public long GroupCode { get; set; }
45+
}
46+
47+
[ProtoContract]
48+
internal class ExcitingFileEntry
49+
{
50+
[ProtoMember(100)] public long FileSize { get; set; }
51+
52+
[ProtoMember(200)] public byte[] Md5 { get; set; }
53+
54+
[ProtoMember(300)] public byte[] CheckKey { get; set; }
55+
56+
[ProtoMember(400)] public byte[] Md5S2 { get; set; }
57+
58+
[ProtoMember(600)] public string FileId { get; set; }
59+
60+
[ProtoMember(700)] public byte[] UploadKey { get; set; }
61+
}
62+
63+
[ProtoContract]
64+
internal class ExcitingClientInfo
65+
{
66+
[ProtoMember(100)] public int ClientType { get; set; }
67+
68+
[ProtoMember(200)] public string AppId { get; set; }
69+
70+
[ProtoMember(300)] public int TerminalType { get; set; }
71+
72+
[ProtoMember(400)] public string ClientVer { get; set; }
73+
74+
[ProtoMember(600)] public int Unknown { get; set; }
75+
}
76+
77+
[ProtoContract]
78+
internal class ExcitingFileNameInfo
79+
{
80+
[ProtoMember(100)] public string FileName { get; set; }
81+
}
82+
83+
[ProtoContract]
84+
internal class ExcitingHostConfig
85+
{
86+
[ProtoMember(200)] public List<ExcitingHostInfo> Hosts { get; set; }
87+
}
88+
89+
[ProtoContract]
90+
internal class ExcitingHostInfo
91+
{
92+
[ProtoMember(1)] public ExcitingUrlInfo Url { get; set; }
93+
94+
[ProtoMember(2)] public uint Port { get; set; }
95+
}
96+
97+
[ProtoContract]
98+
internal class ExcitingUrlInfo
99+
{
100+
[ProtoMember(1)] public int Unknown { get; set; }
101+
102+
[ProtoMember(2)] public string Host { get; set; }
103+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using ProtoBuf;
2+
3+
namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;
4+
5+
#pragma warning disable CS8618
6+
// ReSharper disable InconsistentNaming
7+
8+
/// <summary>
9+
/// Group Send File
10+
/// </summary>
11+
[ProtoContract]
12+
[OidbSvcTrpcTcp(0x6D9, 4)]
13+
internal class OidbSvcTrpcTcp0x6D9_4
14+
{
15+
[ProtoMember(5)] public OidbSvcTrpcTcp0x6D9_4Body Body { get; set; }
16+
}
17+
18+
[ProtoContract]
19+
internal class OidbSvcTrpcTcp0x6D9_4Body
20+
{
21+
[ProtoMember(1)] public uint GroupUin { get; set; }
22+
23+
[ProtoMember(2)] public uint Type { get; set; } // 2
24+
25+
[ProtoMember(3)] public OidbSvcTrpcTcp0x6D9_4Info Info { get; set; }
26+
}
27+
28+
[ProtoContract]
29+
internal class OidbSvcTrpcTcp0x6D9_4Info
30+
{
31+
[ProtoMember(1)] public uint BusiType { get; set; } // 102
32+
33+
[ProtoMember(2)] public string FileId { get; set; }
34+
35+
[ProtoMember(3)] public uint Field3 { get; set; } // random
36+
37+
[ProtoMember(4)] public string? Field4 { get; set; } // null
38+
39+
[ProtoMember(5)] public bool Field5 { get; set; } // true
40+
}

Lagrange.Core/Internal/Packets/Service/Oidb/Response/OidbSvcTrpcTcp0x6D6Response.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response;
88
[ProtoContract]
99
internal class OidbSvcTrpcTcp0x6D6Response
1010
{
11+
[ProtoMember(1)] public OidbSvcTrpcTcp0x6D6_0Response Upload { get; set; }
12+
1113
[ProtoMember(3)] public OidbSvcTrpcTcp0x6D6_2Response Download { get; set; }
1214
}

0 commit comments

Comments
 (0)