This commit is contained in:
JustArchi
2018-07-04 19:13:51 +02:00
parent c1d85852e8
commit 507f6f0775
5 changed files with 159 additions and 37 deletions

View File

@@ -23,7 +23,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Json;
@@ -79,6 +78,9 @@ namespace ArchiSteamFarm {
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
internal readonly HashSet<Steam.Asset.EType> MatchableTypes = new HashSet<Steam.Asset.EType> { Steam.Asset.EType.TradingCard };
[JsonProperty(Required = Required.DisallowNull)]
internal readonly EPersonaState OnlineStatus = EPersonaState.Online;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly CryptoHelper.ECryptoMethod PasswordFormat = CryptoHelper.ECryptoMethod.PlainText;
@@ -112,9 +114,6 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
internal EBotBehaviour BotBehaviour { get; private set; } = EBotBehaviour.None;
[JsonProperty(Required = Required.DisallowNull)]
internal EPersonaState OnlineStatus { get; private set; } = EPersonaState.Online;
[JsonProperty]
internal string SteamLogin { get; set; }
@@ -181,7 +180,61 @@ namespace ArchiSteamFarm {
return null;
}
botConfig.ShouldSerializeSensitiveDetails = false;
if (botConfig.BotBehaviour > EBotBehaviour.All) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.BotBehaviour), botConfig.BotBehaviour));
return null;
}
if (!Enum.IsDefined(typeof(EFarmingOrder), botConfig.FarmingOrder)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.FarmingOrder), botConfig.FarmingOrder));
return null;
}
if (botConfig.GamesPlayedWhileIdle.Count > ArchiHandler.MaxGamesPlayedConcurrently) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.GamesPlayedWhileIdle), botConfig.GamesPlayedWhileIdle.Count + " > " + ArchiHandler.MaxGamesPlayedConcurrently));
return null;
}
foreach (Steam.Asset.EType lootableType in botConfig.LootableTypes) {
if (!Enum.IsDefined(typeof(Steam.Asset.EType), lootableType)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.LootableTypes), lootableType));
return null;
}
}
foreach (Steam.Asset.EType matchableType in botConfig.MatchableTypes) {
if (!Enum.IsDefined(typeof(Steam.Asset.EType), matchableType)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.MatchableTypes), matchableType));
return null;
}
}
if ((botConfig.OnlineStatus < EPersonaState.Offline) || (botConfig.OnlineStatus >= EPersonaState.Max)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.OnlineStatus), botConfig.OnlineStatus));
return null;
}
if (!Enum.IsDefined(typeof(CryptoHelper.ECryptoMethod), botConfig.PasswordFormat)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.PasswordFormat), botConfig.PasswordFormat));
return null;
}
if (botConfig.RedeemingPreferences > ERedeemingPreferences.All) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.RedeemingPreferences), botConfig.RedeemingPreferences));
return null;
}
foreach (EPermission permission in botConfig.SteamUserPermissions.Values) {
if (!Enum.IsDefined(typeof(EPermission), permission)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.SteamUserPermissions), permission));
return null;
}
}
if (botConfig.TradingPreferences > ETradingPreferences.All) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.TradingPreferences), botConfig.TradingPreferences));
return null;
}
// Support encrypted passwords
if ((botConfig.PasswordFormat != CryptoHelper.ECryptoMethod.PlainText) && !string.IsNullOrEmpty(botConfig.SteamPassword)) {
@@ -189,21 +242,7 @@ namespace ArchiSteamFarm {
botConfig.SteamPassword = CryptoHelper.Decrypt(botConfig.PasswordFormat, botConfig.SteamPassword);
}
// User might not know what he's doing
// Ensure that he can't screw core ASF variables
if ((botConfig.OnlineStatus < EPersonaState.Offline) || (botConfig.OnlineStatus >= EPersonaState.Max)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.OnlineStatus), botConfig.OnlineStatus));
return null;
}
if (botConfig.GamesPlayedWhileIdle.Count > ArchiHandler.MaxGamesPlayedConcurrently) {
ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningTooManyGamesToPlay, ArchiHandler.MaxGamesPlayedConcurrently, nameof(botConfig.GamesPlayedWhileIdle)));
HashSet<uint> validGames = botConfig.GamesPlayedWhileIdle.Take(ArchiHandler.MaxGamesPlayedConcurrently).ToHashSet();
botConfig.GamesPlayedWhileIdle.IntersectWith(validGames);
botConfig.GamesPlayedWhileIdle.TrimExcess();
}
botConfig.ShouldSerializeSensitiveDetails = false;
return botConfig;
}
@@ -242,7 +281,8 @@ namespace ArchiSteamFarm {
RejectInvalidFriendInvites = 1,
RejectInvalidTrades = 2,
RejectInvalidGroupInvites = 4,
DismissInventoryNotifications = 8
DismissInventoryNotifications = 8,
All = RejectInvalidFriendInvites | RejectInvalidTrades | RejectInvalidGroupInvites | DismissInventoryNotifications
}
internal enum EFarmingOrder : byte {
@@ -259,7 +299,9 @@ namespace ArchiSteamFarm {
BadgeLevelsAscending,
BadgeLevelsDescending,
RedeemDateTimesAscending,
RedeemDateTimesDescending
RedeemDateTimesDescending,
MarketableAscending,
MarketableDescending
}
internal enum EPermission : byte {
@@ -274,7 +316,8 @@ namespace ArchiSteamFarm {
None = 0,
Forwarding = 1,
Distributing = 2,
KeepMissingGames = 4
KeepMissingGames = 4,
All = Forwarding | Distributing | KeepMissingGames
}
[Flags]
@@ -283,7 +326,8 @@ namespace ArchiSteamFarm {
AcceptDonations = 1,
SteamTradeMatcher = 2,
MatchEverything = 4,
DontAcceptBotTrades = 8
DontAcceptBotTrades = 8,
All = AcceptDonations | SteamTradeMatcher | MatchEverything | DontAcceptBotTrades
}
}
}