Skip to content

Commit 9588777

Browse files
authored
Merge pull request #6 from SmallTailTeam/latest
0.2.0
2 parents 78db9b3 + 622f464 commit 9588777

16 files changed

+330
-105
lines changed

BotLooter/BotLooter.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="AngleSharp" Version="1.0.1" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
1314
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1415
<PackageReference Include="Octokit" Version="5.1.0" />
1516
<PackageReference Include="Polly" Version="7.2.3" />
17+
<PackageReference Include="protobuf-net" Version="3.2.26" />
1618
<PackageReference Include="RestSharp" Version="110.2.0" />
1719
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="110.2.0" />
1820
<PackageReference Include="Serilog" Version="2.12.0" />
@@ -23,6 +25,9 @@
2325
<Reference Include="SteamAuth">
2426
<HintPath>..\Dependencies\SteamAuth.dll</HintPath>
2527
</Reference>
28+
<Reference Include="SteamSession">
29+
<HintPath>..\Dependencies\SteamSession.dll</HintPath>
30+
</Reference>
2631
</ItemGroup>
2732

2833
</Project>

BotLooter/FlowUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace BotLooter;
66
public static class FlowUtils
77
{
88
public static bool AskForApproval { get; set; }
9-
public static bool ExitOnFinish { get; set; }
9+
public static bool AskForExit { get; set; }
1010

1111
public static void AbortWithError(string error)
1212
{
@@ -42,7 +42,7 @@ public static void WaitForExit(string? message = null)
4242
Log.Logger.Information(message);
4343
}
4444

45-
if (!ExitOnFinish)
45+
if (AskForExit)
4646
{
4747
Log.Logger.Information("Нажмите '{Keys}' для выхода.", "ctrl + c");
4848

BotLooter/Steam/LootClient.cs renamed to BotLooter/Looting/LootClient.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
using System.Net;
2-
using BotLooter.Resources;
1+
using BotLooter.Resources;
2+
using BotLooter.Steam;
33
using BotLooter.Steam.Contracts;
44
using BotLooter.Steam.Contracts.Responses;
55
using Polly;
66
using Polly.Retry;
77
using RestSharp;
8+
using Serilog;
89

9-
namespace BotLooter.Steam;
10+
namespace BotLooter.Looting;
1011

1112
public class LootClient
1213
{
1314
public SteamAccountCredentials Credentials { get; }
1415

15-
private readonly SteamSession _steamSession;
16+
private readonly SteamUserSession _steamSession;
1617
private readonly SteamWeb _steamWeb;
1718

1819
private readonly AsyncRetryPolicy<RestResponse<GetInventoryResponse>> _getInventoryPolicy;
1920

20-
public LootClient(SteamAccountCredentials credentials, SteamSession steamSession, SteamWeb steamWeb)
21+
public LootClient(SteamAccountCredentials credentials, SteamUserSession steamSession, SteamWeb steamWeb)
2122
{
2223
Credentials = credentials;
2324
_steamSession = steamSession;
@@ -36,6 +37,8 @@ public LootClient(SteamAccountCredentials credentials, SteamSession steamSession
3637
{
3738
return (null, ensureSessionMessage);
3839
}
40+
41+
Log.Logger.Debug("{Login} : {SessionType}", Credentials.Login, ensureSessionMessage);
3942

4043
var (assets, getAssetsMessage) = await GetAssetsToSend(_steamWeb, Credentials.SteamGuardAccount.Session.SteamID, inventories);
4144

BotLooter/Steam/Looter.cs renamed to BotLooter/Looting/Looter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using BotLooter.Steam.Contracts;
33
using Serilog;
44

5-
namespace BotLooter.Steam;
5+
namespace BotLooter.Looting;
66

77
public class Looter
88
{

BotLooter/Program.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System.Text;
22
using BotLooter;
3+
using BotLooter.Looting;
34
using BotLooter.Resources;
45
using BotLooter.Steam;
56
using Serilog;
67

78
Log.Logger = new LoggerConfiguration()
9+
.MinimumLevel.Debug()
810
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} {Level:w3} : {Message:lj}{NewLine}{Exception}")
911
.CreateLogger();
1012

@@ -17,7 +19,7 @@
1719
Console.ReadKey();
1820
};
1921

20-
var version = new Version(0, 1, 4);
22+
var version = new Version(0, 2, 0);
2123

2224
var versionChecker = new VersionChecker(Log.Logger);
2325
await versionChecker.Check(version);
@@ -32,7 +34,7 @@
3234
Log.Logger.Information("Инвентари для лута: {Inventories}", string.Join(", ", config.Inventories));
3335

3436
FlowUtils.AskForApproval = config.AskForApproval;
35-
FlowUtils.ExitOnFinish = config.ExitOnFinish;
37+
FlowUtils.AskForExit = !config.ExitOnFinish;
3638

3739
var clientProvider = await GetClientProvider();
3840
if (clientProvider is null)
@@ -42,7 +44,7 @@
4244

4345
CheckThreadCount();
4446

45-
var credentialsLoadResult = await SteamAccountCredentials.TryLoadFromFiles(config.AccountsFilePath, config.SecretsDirectoryPath);
47+
var credentialsLoadResult = await SteamAccountCredentials.TryLoadFromFiles(config);
4648
if (credentialsLoadResult.LootAccounts is not { } accountCredentials)
4749
{
4850
FlowUtils.AbortWithError(credentialsLoadResult.Message);
@@ -54,58 +56,57 @@
5456
var lootClients = CreateLootClients();
5557

5658
var looter = new Looter(Log.Logger);
57-
5859
await looter.Loot(lootClients, config.LootTradeOfferUrl, config);
59-
60+
6061
FlowUtils.WaitForExit();
6162

62-
async Task<IClientProvider?> GetClientProvider()
63+
async Task<IRestClientProvider?> GetClientProvider()
6364
{
6465
if (string.IsNullOrWhiteSpace(config.ProxiesFilePath))
6566
{
66-
var provider = new LocalClientProvider();
67+
var provider = new LocalRestClientProvider();
6768

6869
FlowUtils.WaitForApproval("Прокси не указаны, используется локальный клиент.");
6970

7071
return provider;
7172
}
7273
else
7374
{
74-
var proxyPoolLoadResult = await ProxyClientProvider.TryLoadFromFile(config.ProxiesFilePath);
75+
var proxyPoolLoadResult = await ProxyRestClientProvider.TryLoadFromFile(config.ProxiesFilePath);
7576

7677
if (proxyPoolLoadResult.ProxyPool is not { } proxyPool)
7778
{
7879
FlowUtils.AbortWithError(proxyPoolLoadResult.Message);
7980
return null;
8081
}
8182

82-
if (proxyPool.ClientCount == 0)
83+
if (proxyPool.AvailableClientsCount == 0)
8384
{
8485
FlowUtils.AbortWithError($"В файле '{config.ProxiesFilePath}' отсутствуют прокси");
8586
return null;
8687
}
8788

88-
FlowUtils.WaitForApproval("Загружено прокси: {Count}", proxyPool.ClientCount);
89+
FlowUtils.WaitForApproval("Загружено прокси: {Count}", proxyPool.AvailableClientsCount);
8990

9091
return proxyPool;
9192
}
9293
}
9394

9495
void CheckThreadCount()
9596
{
96-
if (config.LootThreadCount > clientProvider.ClientCount)
97+
if (config.LootThreadCount > clientProvider.AvailableClientsCount)
9798
{
9899
switch (clientProvider)
99100
{
100-
case ProxyClientProvider:
101-
Log.Logger.Warning("Потоков {ThreadCount} > Прокси {ClientCount}. Количество потоков будет уменьшено до количества прокси.", config.LootThreadCount, clientProvider.ClientCount);
101+
case ProxyRestClientProvider:
102+
Log.Logger.Warning("Потоков {ThreadCount} больше чем прокси {ClientCount}. Количество потоков будет уменьшено до количества прокси.", config.LootThreadCount, clientProvider.AvailableClientsCount);
102103
break;
103-
case LocalClientProvider:
104+
case LocalRestClientProvider:
104105
Log.Logger.Warning("Используется локальный клиент, количество потоков будет уменьшено с {ThreadCount} до {ReducedCount}.", config.LootThreadCount, 1);
105106
break;
106107
}
107108

108-
config.LootThreadCount = clientProvider.ClientCount;
109+
config.LootThreadCount = clientProvider.AvailableClientsCount;
109110
}
110111
}
111112

@@ -117,7 +118,7 @@ List<LootClient> CreateLootClients()
117118
{
118119
var restClient = clientProvider.Provide();
119120

120-
var steamSession = new SteamSession(credentials, restClient);
121+
var steamSession = new SteamUserSession(credentials, restClient, config.SavedSessionsDirectoryPath);
121122
var steamWeb = new SteamWeb(steamSession);
122123
var lootClient = new LootClient(credentials, steamSession, steamWeb);
123124

BotLooter/Resources/Configuration.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ namespace BotLooter.Resources;
55

66
public class Configuration
77
{
8-
public string LootTradeOfferUrl { get; set; }
9-
public string SecretsDirectoryPath { get; set; } = "secrets";
10-
public string AccountsFilePath { get; set; } = "accounts.txt";
8+
public string LootTradeOfferUrl { get; set; } = "";
9+
public string SecretsDirectoryPath { get; set; } = "";
10+
public string AccountsFilePath { get; set; } = "";
11+
public string SteamSessionsDirectoryPath { get; set; } = "";
12+
public string SavedSessionsDirectoryPath { get; set; } = "";
1113
public string ProxiesFilePath { get; set; } = "proxies.txt";
1214
public int DelayBetweenAccountsSeconds { get; set; } = 30;
1315
public int DelayInventoryEmptySeconds { get; set; } = 10;
@@ -61,7 +63,7 @@ public class Configuration
6163
return (null, """
6264
В параметре конфига 'Inventories' не указаны инвентари для лута.
6365
Формат: appId/contextId
64-
Пример указания инвентаря CS:GO
66+
Пример заполнения с инвентарем CS:GO
6567
...
6668
"Inventories": [
6769
"730/2"

BotLooter/Resources/IClientProvider.cs renamed to BotLooter/Resources/IRestClientProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BotLooter.Resources;
44

5-
public interface IClientProvider
5+
public interface IRestClientProvider
66
{
7-
int ClientCount { get; }
7+
int AvailableClientsCount { get; }
88

99
RestClient Provide();
1010
}

BotLooter/Resources/LocalClientProvider.cs renamed to BotLooter/Resources/LocalRestClientProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33

44
namespace BotLooter.Resources;
55

6-
public class LocalClientProvider : IClientProvider
6+
public class LocalRestClientProvider : IRestClientProvider
77
{
8-
public int ClientCount => 1;
8+
public int AvailableClientsCount => 1;
99

1010
private readonly RestClient _restClient;
1111

12-
public LocalClientProvider()
12+
public LocalRestClientProvider()
1313
{
1414
_restClient = new RestClient(new RestClientOptions
1515
{
1616
UserAgent =
17-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
17+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
18+
FollowRedirects = false
1819
}, configureSerialization: b => b.UseNewtonsoftJson());
1920
}
2021

BotLooter/Resources/ProxyClientProvider.cs renamed to BotLooter/Resources/ProxyRestClientProvider.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
namespace BotLooter.Resources;
77

8-
public class ProxyClientProvider : IClientProvider
8+
public class ProxyRestClientProvider : IRestClientProvider
99
{
10-
public int ClientCount => _proxiedClients.Count;
10+
public int AvailableClientsCount => _proxiedClients.Count;
1111

1212
private readonly List<RestClient> _proxiedClients;
1313
private int _proxyIndex;
1414

15-
public ProxyClientProvider(List<RestClient> proxiedClients)
15+
public ProxyRestClientProvider(List<RestClient> proxiedClients)
1616
{
1717
_proxiedClients = proxiedClients;
1818
}
@@ -29,7 +29,7 @@ public RestClient Provide()
2929
return proxiedClient;
3030
}
3131

32-
public static async Task<(ProxyClientProvider? ProxyPool, string Message)> TryLoadFromFile(string filePath)
32+
public static async Task<(ProxyRestClientProvider? ProxyPool, string Message)> TryLoadFromFile(string filePath)
3333
{
3434
if (!File.Exists(filePath))
3535
{
@@ -58,13 +58,14 @@ public RestClient Provide()
5858
{
5959
UserAgent =
6060
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
61-
Proxy = proxy
61+
Proxy = proxy,
62+
FollowRedirects = false
6263
}, configureSerialization: b => b.UseNewtonsoftJson());
6364

6465
proxiedClients.Add(restClient);
6566
}
6667

67-
return (new ProxyClientProvider(proxiedClients), "");
68+
return (new ProxyRestClientProvider(proxiedClients), "");
6869
}
6970

7071
private static WebProxy? TryParseProxy(string line)

0 commit comments

Comments
 (0)