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-03-06 02:20:41 +01:00
internal sealed class BotConfig {
[JsonProperty(Required = Required.DisallowNull)]
internal bool Enabled { get ; private set ; } = false ;
[JsonProperty(Required = Required.DisallowNull)]
internal bool StartOnLaunch { get ; private set ; } = true ;
[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]
internal string SteamApiKey { get ; private set ; } = null ;
[JsonProperty(Required = Required.DisallowNull)]
internal ulong SteamMasterID { get ; private set ; } = 0 ;
[JsonProperty(Required = Required.DisallowNull)]
internal ulong SteamMasterClanID { get ; private set ; } = 0 ;
[JsonProperty(Required = Required.DisallowNull)]
internal bool CardDropsRestricted { get ; private set ; } = false ;
2016-03-06 14:15:59 +01:00
[JsonProperty(Required = Required.DisallowNull)]
internal bool DismissInventoryNotifications { get ; private set ; } = true ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
internal bool FarmOffline { get ; private set ; } = false ;
[JsonProperty(Required = Required.DisallowNull)]
internal bool HandleOfflineMessages { get ; private set ; } = false ;
2016-03-27 23:07:00 +02:00
[JsonProperty(Required = Required.DisallowNull)]
internal bool AcceptGifts { get ; private set ; } = false ;
2016-06-04 22:02:38 +02:00
[JsonProperty(Required = Required.DisallowNull)]
internal bool IsBotAccount { get ; private set ; } = false ;
2016-04-20 21:27:57 +02:00
[JsonProperty(Required = Required.DisallowNull)]
internal bool SteamTradeMatcher { get ; private set ; } = false ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
internal bool ForwardKeysToOtherBots { get ; private set ; } = false ;
[JsonProperty(Required = Required.DisallowNull)]
internal bool DistributeKeys { get ; private set ; } = false ;
[JsonProperty(Required = Required.DisallowNull)]
internal bool ShutdownOnFarmingFinished { get ; private set ; } = false ;
[JsonProperty(Required = Required.DisallowNull)]
internal bool SendOnFarmingFinished { get ; private set ; } = false ;
2016-03-06 02:27:43 +01:00
[JsonProperty]
2016-03-06 02:20:41 +01:00
internal string SteamTradeToken { get ; private set ; } = null ;
[JsonProperty(Required = Required.DisallowNull)]
internal byte SendTradePeriod { get ; private set ; } = 0 ;
2016-03-10 21:17:48 +01:00
[JsonProperty(Required = Required.DisallowNull)]
internal byte AcceptConfirmationsPeriod { get ; private set ; } = 0 ;
2016-07-12 04:40:56 +02:00
[JsonProperty]
internal string CustomGamePlayedWhileFarming { get ; private set ; } = null ;
2016-03-08 03:18:50 +01:00
[JsonProperty]
internal string CustomGamePlayedWhileIdle { get ; private set ; } = null ;
2016-03-06 02:20:41 +01:00
[JsonProperty(Required = Required.DisallowNull)]
2016-07-12 04:40:56 +02:00
internal HashSet < uint > GamesPlayedWhileIdle { get ; private set ; } = 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-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" ) ;
botConfig . GamesPlayedWhileIdle = new HashSet < uint > ( botConfig . GamesPlayedWhileIdle . Take ( CardsFarmer . MaxGamesPlayedConcurrently ) ) ;
2016-03-06 02:20:41 +01:00
return botConfig ;
}
// This constructor is used only by deserializer
private BotConfig ( ) { }
}
}