2016-03-06 02:20:41 +01:00
/ *
_ _ _ ____ _ _____
/ \ _ __ ___ | | __ ( _ ) / ___ | | | _ ___ __ _ _ __ ___ | ___ | __ _ _ __ _ __ ___
/ _ \ | ' __ | / __ | | ' _ \ | | \ ___ \ | __ | / _ \ / _ ` | | ' _ ` _ \ | | _ / _ ` | | ' __ | | ' _ ` _ \
/ ___ \ | | | ( __ | | | | | | ___ ) | | | _ | __ / | ( _ | | | | | | | | | _ | | ( _ | | | | | | | | | |
/ _ / \ _ \ | _ | \ ___ | | _ | | _ | | _ | | ____ / \ __ | \ ___ | \ __ , _ | | _ | | _ | | _ | | _ | \ __ , _ | | _ | | _ | | _ | | _ |
Copyright 2015 - 2016 Ł ukasz "JustArchi" Domeradzki
Contact : JustArchi @JustArchi . net
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
using Newtonsoft.Json ;
using System ;
using System.Collections.Generic ;
2016-06-09 01:15:48 +02:00
using System.Diagnostics.CodeAnalysis ;
2016-03-06 02:20:41 +01:00
using System.IO ;
2016-06-27 21:09:58 +02:00
using System.Linq ;
2016-03-06 02:20:41 +01:00
namespace ArchiSteamFarm {
2016-06-09 01:15:48 +02:00
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
2016-07-25 06:08:45 +02:00
[SuppressMessage("ReSharper", "ConvertToConstant.Global")]
2016-03-06 02:20:41 +01:00
internal sealed class BotConfig {
2016-07-30 05:06:40 +08:00
internal enum EFarmingOrder : byte {
Unordered ,
2016-07-30 20:55:43 +02:00
AppIDsAscending ,
AppIDsDescending ,
CardDropsAscending ,
CardDropsDescending ,
HoursAscending ,
HoursDescending ,
NamesAscending ,
NamesDescending
2016-07-30 05:06:40 +08:00
}
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool Enabled = false ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool StartOnLaunch = true ;
2016-03-06 02:20:41 +01:00
[JsonProperty]
2016-05-13 06:32:42 +02:00
internal string SteamLogin { get ; set ; }
2016-03-06 02:20:41 +01:00
[JsonProperty]
2016-05-13 06:32:42 +02:00
internal string SteamPassword { get ; set ; }
2016-03-06 02:20:41 +01:00
2016-06-28 04:32:48 +02:00
[JsonProperty(Required = Required.DisallowNull)]
[SuppressMessage("ReSharper", "ConvertToConstant.Local")]
private readonly CryptoHelper . ECryptoMethod PasswordFormat = CryptoHelper . ECryptoMethod . PlainText ;
2016-03-06 02:20:41 +01:00
[JsonProperty]
internal string SteamParentalPIN { get ; set ; } = "0" ;
[JsonProperty]
2016-07-25 06:08:45 +02:00
internal readonly string SteamApiKey = null ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly ulong SteamMasterID = 0 ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly ulong SteamMasterClanID = 0 ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-08-03 17:16:11 +02:00
internal readonly bool CardDropsRestricted = true ;
2016-03-06 02:20:41 +01:00
2016-03-06 14:15:59 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool DismissInventoryNotifications = true ;
2016-03-06 14:15:59 +01:00
2016-07-30 00:17:58 +02:00
[JsonProperty(Required = Required.DisallowNull)]
internal readonly EFarmingOrder FarmingOrder = EFarmingOrder . Unordered ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool FarmOffline = false ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool HandleOfflineMessages = false ;
2016-03-06 02:20:41 +01:00
2016-03-27 23:07:00 +02:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool AcceptGifts = false ;
2016-03-27 23:07:00 +02:00
2016-06-04 22:02:38 +02:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool IsBotAccount = false ;
2016-06-04 22:02:38 +02:00
2016-04-20 21:27:57 +02:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool SteamTradeMatcher = false ;
2016-04-20 21:27:57 +02:00
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool ForwardKeysToOtherBots = false ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool DistributeKeys = false ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool ShutdownOnFarmingFinished = false ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly bool SendOnFarmingFinished = false ;
2016-03-06 02:20:41 +01:00
2016-03-06 02:27:43 +01:00
[JsonProperty]
2016-07-25 06:08:45 +02:00
internal readonly string SteamTradeToken = null ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly byte SendTradePeriod = 0 ;
2016-03-06 02:20:41 +01:00
2016-03-10 21:17:48 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly byte AcceptConfirmationsPeriod = 0 ;
2016-03-10 21:17:48 +01:00
2016-07-12 04:40:56 +02:00
[JsonProperty]
2016-07-25 06:08:45 +02:00
internal readonly string CustomGamePlayedWhileFarming = null ;
2016-07-12 04:40:56 +02:00
2016-03-08 03:18:50 +01:00
[JsonProperty]
2016-07-25 06:08:45 +02:00
internal readonly string CustomGamePlayedWhileIdle = null ;
2016-03-08 03:18:50 +01:00
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-25 06:08:45 +02:00
internal readonly HashSet < uint > GamesPlayedWhileIdle = new HashSet < uint > ( ) ;
2016-03-06 02:20:41 +01:00
2016-03-28 13:11:02 +02:00
internal static BotConfig Load ( string filePath ) {
2016-05-30 01:57:06 +02:00
if ( string . IsNullOrEmpty ( filePath ) ) {
Logging . LogNullError ( nameof ( filePath ) ) ;
return null ;
}
if ( ! File . Exists ( filePath ) ) {
2016-03-06 02:20:41 +01:00
return null ;
}
BotConfig botConfig ;
2016-05-30 01:57:06 +02:00
2016-03-06 02:20:41 +01:00
try {
2016-03-28 13:11:02 +02:00
botConfig = JsonConvert . DeserializeObject < BotConfig > ( File . ReadAllText ( filePath ) ) ;
2016-03-06 02:20:41 +01:00
} catch ( Exception e ) {
Logging . LogGenericException ( e ) ;
return null ;
}
2016-07-31 17:38:14 +02:00
if ( botConfig = = null ) {
Logging . LogNullError ( nameof ( botConfig ) ) ;
return null ;
}
2016-06-28 04:32:48 +02:00
// Support encrypted passwords
2016-06-28 04:34:51 +02:00
if ( ( botConfig . PasswordFormat ! = CryptoHelper . ECryptoMethod . PlainText ) & & ! string . IsNullOrEmpty ( botConfig . SteamPassword ) ) {
2016-06-28 04:32:48 +02:00
// In worst case password will result in null, which will have to be corrected by user during runtime
botConfig . SteamPassword = CryptoHelper . Decrypt ( botConfig . PasswordFormat , botConfig . SteamPassword ) ;
}
2016-06-27 21:09:58 +02:00
// User might not know what he's doing
// Ensure that he can't screw core ASF variables
if ( botConfig . GamesPlayedWhileIdle . Count < = CardsFarmer . MaxGamesPlayedConcurrently ) {
return botConfig ;
}
Logging . LogGenericWarning ( "Playing more than " + CardsFarmer . MaxGamesPlayedConcurrently + " games concurrently is not possible, only first " + CardsFarmer . MaxGamesPlayedConcurrently + " entries from GamesPlayedWhileIdle will be used" ) ;
2016-07-25 06:08:45 +02:00
HashSet < uint > validGames = new HashSet < uint > ( botConfig . GamesPlayedWhileIdle . Take ( CardsFarmer . MaxGamesPlayedConcurrently ) ) ;
botConfig . GamesPlayedWhileIdle . IntersectWith ( validGames ) ;
botConfig . GamesPlayedWhileIdle . TrimExcess ( ) ;
2016-06-27 21:09:58 +02:00
2016-03-06 02:20:41 +01:00
return botConfig ;
}
// This constructor is used only by deserializer
private BotConfig ( ) { }
}
}