Skip to content

Commit

Permalink
🎨 fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzaz committed Dec 24, 2023
1 parent fd004aa commit 2f704bf
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 65 deletions.
9 changes: 4 additions & 5 deletions src/BD.SteamClient8.Impl/WebApi/SteamAccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ await Policy.Handle<Exception>().WaitAndRetryAsync(sleepDurations).ExecuteAsync(
}
}
}
session.GenerateSetCookie();
sessions.AddOrSetSession(session);
return ApiRspHelper.Ok();
}
Expand Down Expand Up @@ -515,16 +516,14 @@ await WaitAndRetryAsync(sleepDurations).ExecuteAsync(async () =>
//var res = data.Content.ReadAsStringAsync();
});
}

//await client.GetAsync("https://store.steampowered.com/");
//await client.GetAsync("https://steamcommunity.com/");
loginState.Cookies = cookieContainer.GetAllCookies();
}
var session = new SteamSession();
session.SteamId = loginState.SteamId.ToString();
session.AccessToken = loginState.AccessToken;
session.RefreshToken = loginState.RefreshToken;
session.Cookies = cookieContainer.GetAllCookies();
session.GenerateSetCookie();
sessions.AddOrSetSession(session);
return ApiRspHelper.Ok();

Expand Down Expand Up @@ -1116,7 +1115,7 @@ public async IAsyncEnumerable<InventoryTradeHistoryRow> ParseInventoryTradeHisto
}

/// <inheritdoc/>
public async Task<ApiRspImpl<InventoryPageResponse>> GetInventories(ulong steamId, string appId, string contextId, int count = 100, string? startAssetId = null, string language = "schinese")
public async Task<ApiRspImpl<InventoryPageResponse?>> GetInventories(ulong steamId, string appId, string contextId, int count = 100, string? startAssetId = null, string language = "schinese")
{
string url = string.Format("{0}/inventory/{1}/{2}/{3}?l={4}&count={5}{6}",
SteamApiUrls.STEAM_COMMUNITY_URL,
Expand All @@ -1134,7 +1133,7 @@ public async Task<ApiRspImpl<InventoryPageResponse>> GetInventories(ulong steamI
return await ReadFromSJsonAsync<InventoryPageResponse>(resp.Content);
});

return inventories!;
return inventories;
}

/// <inheritdoc/>
Expand Down
4 changes: 3 additions & 1 deletion src/BD.SteamClient8.Impl/WebApi/SteamIdleCardServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ public class SteamIdleCardServiceImpl : WebApiClientFactoryService, ISteamIdleCa
/// 初始化 <see cref="SteamIdleCardServiceImpl"/> 类的新实例
/// </summary>
/// <param name="s"></param>
/// <param name="sessions"></param>
/// <param name="loggerFactory"></param>
public SteamIdleCardServiceImpl(
IServiceProvider s,
ISteamSessionService sessions,
ILoggerFactory loggerFactory) : base(
loggerFactory.CreateLogger(TAG),
s)
{
_sessionService = s.GetRequiredService<ISteamSessionService>();
_sessionService = sessions;
}

#region Public
Expand Down
5 changes: 4 additions & 1 deletion src/BD.SteamClient8.Impl/WebApi/SteamTradeServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public sealed partial class SteamTradeServiceImpl : WebApiClientFactoryService,
/// 初始化 <see cref="SteamTradeServiceImpl"/> 类的新实例
/// </summary>
/// <param name="s"></param>
/// <param name="sessions"></param>
/// <param name="loggerFactory"></param>
public SteamTradeServiceImpl(
IServiceProvider s,
ISteamSessionService sessions,
ILoggerFactory loggerFactory) : base(
loggerFactory.CreateLogger(TAG),
s)
{
_tasks = new ConcurrentDictionary<string, CancellationTokenSource>();
_sessionService = s.GetRequiredService<ISteamSessionService>();
_sessionService = sessions;
}

#region Public
Expand Down Expand Up @@ -695,6 +697,7 @@ private async Task RunTask(Action action, TimeSpan interval, CancellationToken c
/// <summary>
/// 获取 SessionId
/// </summary>
/// <param name="domain"></param>
/// <param name="steamSession"></param>
/// <returns></returns>
private async Task<string?> FetchSessionId(SteamSession steamSession)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ namespace BD.SteamClient8.Models.WebApi;
[SystemTextJsonSerializable(typeof(SteamAppSaveFile))]
//// SteamGridDB
[SystemTextJsonSerializable(typeof(SteamGridApp))]
[SystemTextJsonSerializable(typeof(SteamGridItemData))]
[SystemTextJsonSerializable(typeof(SteamGridItem))]
[SystemTextJsonSerializable(typeof(SteamGridAppData))]
//// Trade
[SystemTextJsonSerializable(typeof(Asset))]
[SystemTextJsonSerializable(typeof(Confirmation))]
Expand Down
17 changes: 13 additions & 4 deletions src/BD.SteamClient8.Models/WebApi/Login/SteamSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ public bool GenerateSetCookie()

var steamLoginSecure = this.SteamId + "%7C%7C" + this.AccessToken;
var sessionid = GetRandomHexNumber(32);
Cookies.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "steamcommunity.com"));
Cookies.Add(new Cookie("sessionid", sessionid, "/", "steamcommunity.com"));
Cookies.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "steampowered.com"));
Cookies.Add(new Cookie("sessionid", sessionid, "/", "steampowered.com"));
Cookies.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", new Uri(SteamApiUrls.STEAM_COMMUNITY_URL).Host));
Cookies.Add(new Cookie("sessionid", sessionid, "/", new Uri(SteamApiUrls.STEAM_COMMUNITY_URL).Host));
Cookies.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", new Uri(SteamApiUrls.STEAM_STORE_URL).Host));
Cookies.Add(new Cookie("sessionid", sessionid, "/", new Uri(SteamApiUrls.STEAM_STORE_URL).Host));

// Cookie 去重保留最新
var deduplicated = new CookieCollection();
Cookies.Cast<Cookie>()
.GroupBy(cookie => new { cookie.Domain, cookie.Name })
.SelectMany(group =>
{
return group.OrderByDescending(cookie => cookie.TimeStamp).Take(1);
}).ForEach(deduplicated.Add);
Cookies = deduplicated;
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/BD.SteamClient8.Models/WebApi/SteamApp/SteamApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public SteamApp(uint app_id)
/// <summary>
/// AppId 唯一标识
/// </summary>
[SystemTextJsonProperty("appid")]
public uint AppId { get; set; }

/// <summary>
Expand All @@ -88,6 +89,7 @@ public SteamApp(uint app_id)
/// <summary>
/// 名称
/// </summary>
[SystemTextJsonProperty("name")]
public string? Name
{
get => _Name;
Expand Down
3 changes: 1 addition & 2 deletions src/BD.SteamClient8.Models/WebApi/SteamApp/SteamAppList.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace BD.SteamClient8.Models.WebApi.SteamApp;

#pragma warning disable SA1600 // Elements should be documented

/// <summary>
/// <see cref="SteamApp"/> Collection Model
/// </summary>
Expand All @@ -10,5 +8,6 @@ public class SteamAppList
/// <summary>
/// <see cref="SteamApp"/> Collection
/// </summary>
[SystemTextJsonProperty("apps")]
public List<SteamApp>? Apps { get; set; }
}
1 change: 1 addition & 0 deletions src/BD.SteamClient8.Models/WebApi/SteamApp/SteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class SteamApps
/// <summary>
/// <see cref="SteamAppList"/> Instance
/// </summary>
[SystemTextJsonProperty("applist")]
public SteamAppList? AppList { get; set; }
}
7 changes: 7 additions & 0 deletions src/BD.SteamClient8.Models/WebApi/SteamGridDB/SteamGridApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ public record class SteamGridApp
/// <summary>
/// 唯一标识符
/// </summary>
[SystemTextJsonProperty("id")]
public int Id { get; set; }

/// <summary>
/// 名称
/// </summary>
[SystemTextJsonProperty("name")]
public string Name { get; set; } = "";

/// <summary>
/// 类型列表
/// </summary>
[SystemTextJsonProperty("types")]
public List<string> Types { get; set; } = [];

/// <summary>
/// 是否验证
/// </summary>
[SystemTextJsonProperty("verified")]
public bool Verified { get; set; }
}

Expand All @@ -30,15 +34,18 @@ public class SteamGridAppData
/// <summary>
/// 是否成功
/// </summary>
[SystemTextJsonProperty("success")]
public bool Success { get; set; }

/// <summary>
/// 数据内容
/// </summary>
[SystemTextJsonProperty("data")]
public SteamGridApp Data { get; set; } = new();

/// <summary>
/// 错误列表
/// </summary>
[SystemTextJsonProperty("errors")]
public List<string> Errors { get; set; } = [];
}
14 changes: 14 additions & 0 deletions src/BD.SteamClient8.Models/WebApi/SteamGridDB/SteamGridItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,46 @@ public record class SteamGridItem
/// <summary>
/// 唯一标识符
/// </summary>
[SystemTextJsonProperty("id")]
public int Id { get; set; }

/// <summary>
/// 分数
/// </summary>
[SystemTextJsonProperty("score")]
public int Score { get; set; }

/// <summary>
/// 风格
/// </summary>
[SystemTextJsonProperty("style")]
public string Style { get; set; } = "";

/// <summary>
/// 链接地址
/// </summary>
[SystemTextJsonProperty("url")]
public string Url { get; set; } = "";

[SystemTextJsonProperty("thumb")]
public string Thumb { get; set; } = "";

/// <summary>
/// 标签
/// </summary>
[SystemTextJsonProperty("tags")]
public List<string> Tags { get; set; } = [];

/// <summary>
/// 作者
/// </summary>
[SystemTextJsonProperty("author")]
public SteamGridItemAuthor Author { get; set; } = new();

/// <summary>
/// <see cref="SteamGridItemType" /> 类型
/// </summary>
[SystemTextJsonIgnore]
public SteamGridItemType GridType { get; set; }
}

Expand All @@ -47,16 +55,19 @@ public class SteamGridItemAuthor
/// <summary>
/// 用户名称
/// </summary>
[SystemTextJsonProperty("name")]
public string Name { get; set; } = "";

/// <summary>
/// Steam64 ID
/// </summary>
[SystemTextJsonProperty("steam64")]
public string Steam64 { get; set; } = "";

/// <summary>
/// 头像
/// </summary>
[SystemTextJsonProperty("avatar")]
public string Avatar { get; set; } = "";
}

Expand All @@ -65,15 +76,18 @@ public class SteamGridItemData
/// <summary>
/// 是否成功
/// </summary>
[SystemTextJsonProperty("success")]
public bool Success { get; set; }

/// <summary>
/// 数据列表
/// </summary>
[SystemTextJsonProperty("data")]
public List<SteamGridItem> Data { get; set; } = [];

/// <summary>
/// 错误列表
/// </summary>
[SystemTextJsonProperty("errors")]
public List<string> Errors { get; set; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static async ValueTask<SteamLoginState> GetSteamLoginStateAsync(
session.AccessToken = steamLoginState.AccessToken!;
session.RefreshToken = steamLoginState.RefreshToken!;
session.Cookies.Add(steamLoginState.Cookies!);
session.GenerateSetCookie();
steamSession.AddOrSetSession(session);
}
catch
Expand Down
3 changes: 1 addition & 2 deletions src/BD.SteamClient8.UnitTest/PInvokeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void Test_SteamworksLocal()
var steamId64 = steamworksLocalApiService.GetSteamId64();
Assert.That(steamId64, !Is.EqualTo(0L));

var isOwnsApp = steamworksLocalApiService.OwnsApps(730);
Assert.That(isOwnsApp);
steamworksLocalApiService.OwnsApps(730);

var country = steamworksLocalApiService.GetIPCountry();
Assert.That(country, Is.Not.Empty);
Expand Down
2 changes: 1 addition & 1 deletion src/BD.SteamClient8.UnitTest/SteamDBWebApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task TestGetUserInfos(long[] steamIds)
Assert.Multiple(() =>
{
Assert.That(rsp.IsSuccess);
Assert.That(rsp.Content?.Count, Is.Not.Empty);
Assert.That(rsp.Content?.Count > 0);
});
}

Expand Down
11 changes: 7 additions & 4 deletions src/BD.SteamClient8.UnitTest/SteamIdleServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace BD.SteamClient8.UnitTest;
/// </summary>
sealed class SteamIdleServiceTest : ServiceTestBase
{
SteamLoginState steamLoginState = null!; // ?未引用?
ISteamIdleCardService steamIdleCardService = null!;
ISteamAccountService steamAccountService = null!;
ISteamSessionService steamSessionService = null!;
Expand All @@ -18,6 +17,7 @@ protected override void ConfigureServices(IServiceCollection services)

services.AddSteamAccountService();
services.AddSteamIdleCardService();
services.AddSteamAuthenticatorService();
}

/// <inheritdoc/>
Expand All @@ -31,7 +31,10 @@ public override async ValueTask Setup()
steamSessionService = GetRequiredService<ISteamSessionService>();
configuration = GetRequiredService<IConfiguration>();

steamLoginState = await GetSteamLoginStateAsync(configuration, steamAccountService, steamSessionService);
_ = await GetSteamAuthenticatorAsync(configuration, GetRequiredService<ISteamAuthenticatorService>());
_ = await GetSteamLoginStateAsync(configuration, steamAccountService, steamSessionService);

Assert.That(steamSessionService.RentSession("76561199494800019"), Is.Not.Null);
}

/// <summary>
Expand All @@ -41,7 +44,7 @@ public override async ValueTask Setup()
/// <returns></returns>
[TestCase("76561199494800019")]
[Test]
public async Task TestsGetBadgesAsync(string steam_id)
public async Task TestGetBadgesAsync(string steam_id)
{
var rsp = await steamIdleCardService.GetBadgesAsync(steam_id);

Expand Down Expand Up @@ -71,7 +74,7 @@ public async Task TestGetAppCardsAvgPrice(uint[] appIds, string currency)
{
Assert.That(rsp.IsSuccess);
Assert.That(rsp.Content, Is.Not.Null);
Assert.That(rsp.Content, Is.Not.Empty);
Assert.That(rsp.Content?.Count() > 0);
});
}

Expand Down
Loading

0 comments on commit 2f704bf

Please sign in to comment.