mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
@@ -62,6 +62,10 @@ namespace ArchiSteamFarm {
|
||||
|
||||
internal readonly ArchiLogger ArchiLogger;
|
||||
internal readonly ArchiWebHandler ArchiWebHandler;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly string BotName;
|
||||
|
||||
internal readonly ConcurrentDictionary<uint, (EPaymentMethod PaymentMethod, DateTime TimeCreated)> OwnedPackageIDs = new ConcurrentDictionary<uint, (EPaymentMethod PaymentMethod, DateTime TimeCreated)>();
|
||||
|
||||
internal bool CanReceiveSteamCards => !IsAccountLimited && !IsAccountLocked;
|
||||
@@ -75,9 +79,6 @@ namespace ArchiSteamFarm {
|
||||
private readonly ArchiHandler ArchiHandler;
|
||||
private readonly BotDatabase BotDatabase;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly string BotName;
|
||||
|
||||
private readonly CallbackManager CallbackManager;
|
||||
private readonly SemaphoreSlim CallbackSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
@@ -567,47 +568,6 @@ namespace ArchiSteamFarm {
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<Dictionary<string, string>> GetKeysFromFile(string filePath) {
|
||||
if (string.IsNullOrEmpty(filePath)) {
|
||||
ArchiLogger.LogNullError(nameof(filePath));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!File.Exists(filePath)) {
|
||||
return new Dictionary<string, string>(0);
|
||||
}
|
||||
|
||||
try {
|
||||
Dictionary<string, string> keys = new Dictionary<string, string>();
|
||||
|
||||
using (StreamReader reader = new StreamReader(filePath)) {
|
||||
string line;
|
||||
|
||||
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null) {
|
||||
if (line.Length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] parsedArgs = line.Split(DefaultBackgroundKeysRedeemerSeparator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parsedArgs.Length < 4) {
|
||||
ArchiLogger.LogGenericWarning(string.Format(Strings.ErrorIsInvalid, line));
|
||||
continue;
|
||||
}
|
||||
|
||||
string name = parsedArgs[0];
|
||||
string key = parsedArgs[parsedArgs.Length - 1];
|
||||
|
||||
keys[key] = name;
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task<HashSet<uint>> GetMarketableAppIDs() => await ArchiWebHandler.GetAppList().ConfigureAwait(false);
|
||||
|
||||
internal async Task<Dictionary<uint, (uint ChangeNumber, HashSet<uint> AppIDs)>> GetPackagesData(IReadOnlyCollection<uint> packageIDs) {
|
||||
@@ -689,14 +649,13 @@ namespace ArchiSteamFarm {
|
||||
return await ArchiWebHandler.GetTradeHoldDurationForTrade(tradeID).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task<(Dictionary<string, string> Used, Dictionary<string, string> Unused)> GetUsedAndUnusedKeys() {
|
||||
IEnumerable<Task<Dictionary<string, string>>> tasks = new string[] { KeysToRedeemUsedFilePath, KeysToRedeemUnusedFilePath }.Select(file => GetKeysFromFile(file));
|
||||
|
||||
internal async Task<(Dictionary<string, string> UnusedKeys, Dictionary<string, string> UsedKeys)> GetUsedAndUnusedKeys() {
|
||||
IEnumerable<Task<Dictionary<string, string>>> tasks = new[] { KeysToRedeemUnusedFilePath, KeysToRedeemUsedFilePath }.Select(GetKeysFromFile);
|
||||
IList<Dictionary<string, string>> results;
|
||||
|
||||
switch (Program.GlobalConfig.OptimizationMode) {
|
||||
case GlobalConfig.EOptimizationMode.MinMemoryUsage:
|
||||
results = new List<Dictionary<string, string>>();
|
||||
results = new List<Dictionary<string, string>>(2);
|
||||
foreach (Task<Dictionary<string, string>> task in tasks) {
|
||||
results.Add(await task.ConfigureAwait(false));
|
||||
}
|
||||
@@ -1405,6 +1364,47 @@ namespace ArchiSteamFarm {
|
||||
|
||||
private ulong GetFirstSteamMasterID() => BotConfig.SteamUserPermissions.Where(kv => (kv.Key != 0) && (kv.Value == BotConfig.EPermission.Master)).Select(kv => kv.Key).OrderByDescending(steamID => steamID != CachedSteamID).ThenBy(steamID => steamID).FirstOrDefault();
|
||||
|
||||
private async Task<Dictionary<string, string>> GetKeysFromFile(string filePath) {
|
||||
if (string.IsNullOrEmpty(filePath)) {
|
||||
ArchiLogger.LogNullError(nameof(filePath));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!File.Exists(filePath)) {
|
||||
return new Dictionary<string, string>(0);
|
||||
}
|
||||
|
||||
try {
|
||||
Dictionary<string, string> keys = new Dictionary<string, string>();
|
||||
|
||||
using (StreamReader reader = new StreamReader(filePath)) {
|
||||
string line;
|
||||
|
||||
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null) {
|
||||
if (line.Length == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] parsedArgs = line.Split(DefaultBackgroundKeysRedeemerSeparator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parsedArgs.Length < 4) {
|
||||
ArchiLogger.LogGenericWarning(string.Format(Strings.ErrorIsInvalid, line));
|
||||
continue;
|
||||
}
|
||||
|
||||
string name = parsedArgs[0];
|
||||
string key = parsedArgs[parsedArgs.Length - 1];
|
||||
|
||||
keys[key] = name;
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BotConfig.EPermission GetSteamUserPermission(ulong steamID) {
|
||||
if (steamID == 0) {
|
||||
ArchiLogger.LogNullError(nameof(steamID));
|
||||
|
||||
@@ -574,13 +574,13 @@ namespace ArchiSteamFarm {
|
||||
return true;
|
||||
}
|
||||
|
||||
IEnumerable<(string BotName, Task<(Dictionary<string, string> Used, Dictionary<string, string> Unused)> Task)> tasks = bots.Select(bot => (bot.BotName, bot.GetUsedAndUnusedKeys()));
|
||||
ICollection<(string BotName, (Dictionary<string, string> Used, Dictionary<string, string> Unused))> results;
|
||||
IEnumerable<(string BotName, Task<(Dictionary<string, string> UnusedKeys, Dictionary<string, string> UsedKeys)> Task)> tasks = bots.Select(bot => (bot.BotName, bot.GetUsedAndUnusedKeys()));
|
||||
ICollection<(string BotName, (Dictionary<string, string> UnusedKeys, Dictionary<string, string> UsedKeys))> results;
|
||||
|
||||
switch (Program.GlobalConfig.OptimizationMode) {
|
||||
case GlobalConfig.EOptimizationMode.MinMemoryUsage:
|
||||
results = new List<(string BotName, (Dictionary<string, string> Used, Dictionary<string, string> Unused))>(bots.Count);
|
||||
foreach ((string botName, Task<(Dictionary<string, string> Used, Dictionary<string, string> Unused)> task) in tasks) {
|
||||
results = new List<(string BotName, (Dictionary<string, string> UnusedKeys, Dictionary<string, string> UsedKeys))>(bots.Count);
|
||||
foreach ((string botName, Task<(Dictionary<string, string> UnusedKeys, Dictionary<string, string> UsedKeys)> task) in tasks) {
|
||||
results.Add((botName, await task.ConfigureAwait(false)));
|
||||
}
|
||||
|
||||
@@ -593,8 +593,8 @@ namespace ArchiSteamFarm {
|
||||
|
||||
Dictionary<string, GamesToRedeemInBackgroundResponse> jsonResponse = new Dictionary<string, GamesToRedeemInBackgroundResponse>();
|
||||
|
||||
foreach((string botName, (Dictionary<string, string> Used, Dictionary<string, string> Unused) keys) in results) {
|
||||
jsonResponse[botName] = new GamesToRedeemInBackgroundResponse(keys.Used, keys.Unused);
|
||||
foreach ((string botName, (Dictionary<string, string> UnusedKeys, Dictionary<string, string> UsedKeys) taskResult) in results) {
|
||||
jsonResponse[botName] = new GamesToRedeemInBackgroundResponse(taskResult.UnusedKeys, taskResult.UsedKeys);
|
||||
}
|
||||
|
||||
await ResponseJsonObject(request, response, new GenericResponse<Dictionary<string, GamesToRedeemInBackgroundResponse>>(true, "OK", jsonResponse)).ConfigureAwait(false);
|
||||
@@ -1351,15 +1351,15 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
private sealed class GamesToRedeemInBackgroundResponse {
|
||||
[JsonProperty]
|
||||
internal readonly Dictionary<string, string> UsedKeys;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly Dictionary<string, string> UnusedKeys;
|
||||
|
||||
internal GamesToRedeemInBackgroundResponse(Dictionary<string, string> usedKeys, Dictionary<string, string> unusedKeys) {
|
||||
UsedKeys = usedKeys;
|
||||
[JsonProperty]
|
||||
internal readonly Dictionary<string, string> UsedKeys;
|
||||
|
||||
internal GamesToRedeemInBackgroundResponse(Dictionary<string, string> unusedKeys = null, Dictionary<string, string> usedKeys = null) {
|
||||
UnusedKeys = unusedKeys;
|
||||
UsedKeys = usedKeys;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user