Skip to content

Commit 168dc5d

Browse files
committed
[Core] Output msg when signer failed
1 parent 54513a2 commit 168dc5d

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

Lagrange.Core/Common/IAndroidBotSignProvider.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface IAndroidBotSignProvider : IBotSignProvider
1515

1616
internal class DefaultAndroidBotSignProvider(BotContext context) : IAndroidBotSignProvider, IDisposable
1717
{
18+
private const string Tag = nameof(DefaultAndroidBotSignProvider);
19+
1820
private readonly HttpClient _client = new();
1921

2022
private readonly string _url = "http://127.0.0.1:8081";
@@ -186,7 +188,7 @@ internal class DefaultAndroidBotSignProvider(BotContext context) : IAndroidBotSi
186188
}
187189
catch (Exception e)
188190
{
189-
// TODO: Log the exception
191+
context.LogWarning(Tag, $"Failed to get sign: {e.Message}");
190192
return null;
191193
}
192194
}
@@ -212,7 +214,7 @@ public async Task<byte[]> GetEnergy(long uin, string data)
212214
}
213215
catch (Exception e)
214216
{
215-
// TODO: Log the exception
217+
context.LogWarning(Tag, $"Failed to get energy: {e.Message}");
216218
return [];
217219
}
218220
}
@@ -237,7 +239,7 @@ public async Task<byte[]> GetDebugXwid(long uin, string data)
237239
}
238240
catch (Exception e)
239241
{
240-
// TODO: Log the exception
242+
context.LogWarning(Tag, $"Failed to get debug_xwid: {e.Message}");
241243
return [];
242244
}
243245
}

Lagrange.Core/Common/IBotSignProvider.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Net.Http.Json;
21
using System.Text;
32
using System.Text.Json.Nodes;
43
using System.Text.Json.Serialization;
@@ -14,8 +13,10 @@ public interface IBotSignProvider
1413
Task<SsoSecureInfo?> GetSecSign(long uin, string cmd, int seq, ReadOnlyMemory<byte> body);
1514
}
1615

17-
internal class DefaultBotSignProvider(Protocols protocol, BotAppInfo appInfo) : IBotSignProvider, IDisposable
16+
internal class DefaultBotSignProvider(BotContext context) : IBotSignProvider, IDisposable
1817
{
18+
private const string Tag = nameof(DefaultBotSignProvider);
19+
1920
private static readonly HashSet<string> WhiteListCommand =
2021
[
2122
"trpc.o3.ecdh_access.EcdhAccess.SsoEstablishShareKey",
@@ -61,14 +62,14 @@ internal class DefaultBotSignProvider(Protocols protocol, BotAppInfo appInfo) :
6162

6263
private readonly HttpClient _client = new();
6364

64-
private readonly string _url = protocol switch
65+
private readonly string _url = context.Config.Protocol switch
6566
{
6667
Protocols.Windows => throw new NotSupportedException("Windows is not supported"),
6768
Protocols.MacOs => throw new NotSupportedException("MacOs is not supported"),
68-
Protocols.Linux => $"https://sign.lagrangecore.org/api/sign/{appInfo.AppClientVersion}",
69+
Protocols.Linux => $"https://sign.lagrangecore.org/api/sign/{context.AppInfo.AppClientVersion}",
6970
Protocols.AndroidPhone => throw new NotSupportedException("AndroidPhone is not supported"),
7071
Protocols.AndroidPad => throw new NotSupportedException("AndroidPad is not supported"),
71-
_ => throw new ArgumentOutOfRangeException(nameof(protocol))
72+
_ => throw new ArgumentOutOfRangeException()
7273
};
7374

7475
public bool IsWhiteListCommand(string cmd) => WhiteListCommand.Contains(cmd);
@@ -99,7 +100,7 @@ internal class DefaultBotSignProvider(Protocols protocol, BotAppInfo appInfo) :
99100
}
100101
catch (Exception e)
101102
{
102-
// TODO: Log the exception
103+
context.LogWarning(Tag, $"Failed to get sign: {e.Message}");
103104
return null;
104105
}
105106
}

Lagrange.Core/Internal/Context/PacketContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class PacketContext(BotContext context)
1515

1616
internal readonly IBotSignProvider SignProvider = context.Config.SignProvider ?? context.Config.Protocol switch
1717
{
18-
Protocols.Linux or Protocols.Windows or Protocols.MacOs => new DefaultBotSignProvider(context.Config.Protocol, context.AppInfo),
18+
Protocols.Linux or Protocols.Windows or Protocols.MacOs => new DefaultBotSignProvider(context),
1919
Protocols.AndroidPhone or Protocols.AndroidPad => new DefaultAndroidBotSignProvider(context),
2020
_ => throw new ArgumentOutOfRangeException(nameof(context.Config.Protocol))
2121
};

0 commit comments

Comments
 (0)