2016-03-06 23:28:56 +01:00
|
|
|
|
/*
|
|
|
|
|
|
_ _ _ ____ _ _____
|
|
|
|
|
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
|
|
|
|
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
|
|
|
|
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
|
|
|
|
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
|
|
|
|
|
|
2017-01-02 20:05:21 +01:00
|
|
|
|
Copyright 2015-2017 Łukasz "JustArchi" Domeradzki
|
2016-03-06 23:28:56 +01:00
|
|
|
|
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 System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-13 06:32:42 +02:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
using System.IO;
|
2016-03-19 11:33:39 +01:00
|
|
|
|
using System.Net.Sockets;
|
2017-01-06 16:29:34 +01:00
|
|
|
|
using ArchiSteamFarm.Localization;
|
2016-11-24 07:32:16 +01:00
|
|
|
|
using Newtonsoft.Json;
|
2016-03-06 23:28:56 +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 23:28:56 +01:00
|
|
|
|
internal sealed class GlobalConfig {
|
2017-01-22 20:10:28 +01:00
|
|
|
|
internal const byte DefaultConnectionTimeout = 60;
|
2016-12-27 17:44:00 +01:00
|
|
|
|
internal const ushort DefaultWCFPort = 1242;
|
2016-03-29 14:33:05 +02:00
|
|
|
|
|
2016-03-06 23:28:56 +01:00
|
|
|
|
// This is hardcoded blacklist which should not be possible to change
|
2017-06-15 20:33:50 +02:00
|
|
|
|
internal static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 267420, 303700, 335590, 368020, 425280, 480730, 566020, 639900 };
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
2016-03-07 18:12:05 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal readonly bool AutoRestart = true;
|
2016-03-07 18:12:05 +01:00
|
|
|
|
|
2016-04-06 16:37:45 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal readonly bool AutoUpdates = true;
|
2016-04-06 16:37:45 +02:00
|
|
|
|
|
2017-02-27 19:59:52 +01:00
|
|
|
|
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
internal readonly HashSet<uint> Blacklist = new HashSet<uint>();
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
2017-01-22 20:10:28 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
internal readonly byte ConnectionTimeout = DefaultConnectionTimeout;
|
|
|
|
|
|
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning disable 649
|
2017-01-08 05:32:59 +01:00
|
|
|
|
[JsonProperty]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
internal readonly string CurrentCulture;
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning restore 649
|
2017-01-08 05:32:59 +01:00
|
|
|
|
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning disable 649
|
2016-04-18 18:38:48 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
internal readonly bool Debug;
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning restore 649
|
2016-04-18 18:38:48 +02:00
|
|
|
|
|
2016-03-06 23:28:56 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-02-03 09:54:09 +01:00
|
|
|
|
internal readonly byte FarmingDelay = 15;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
2016-03-18 03:52:36 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal readonly byte GiftsLimiterDelay = 1;
|
2016-03-18 03:52:36 +01:00
|
|
|
|
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning disable 649
|
2016-03-06 23:28:56 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
internal readonly bool Headless;
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning restore 649
|
2016-11-24 07:32:16 +01:00
|
|
|
|
|
2016-03-11 02:07:20 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-07-25 06:08:45 +02:00
|
|
|
|
internal readonly byte IdleFarmingPeriod = 3;
|
2016-03-11 02:07:20 +01:00
|
|
|
|
|
2016-03-09 19:25:45 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal readonly byte InventoryLimiterDelay = 3;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-07-25 06:08:45 +02:00
|
|
|
|
internal readonly byte LoginLimiterDelay = 10;
|
2016-03-09 18:58:14 +01:00
|
|
|
|
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-02-03 09:54:09 +01:00
|
|
|
|
internal readonly byte MaxFarmingTime = 10;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
2016-06-24 22:26:52 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal readonly byte MaxTradeHoldDuration = 15;
|
2016-06-24 22:26:52 +02:00
|
|
|
|
|
2017-01-30 22:17:25 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-01-30 22:42:05 +01:00
|
|
|
|
internal readonly EOptimizationMode OptimizationMode = EOptimizationMode.MaxPerformance;
|
2017-01-30 22:17:25 +01:00
|
|
|
|
|
2016-06-27 01:45:41 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal readonly bool Statistics = true;
|
2016-06-27 01:45:41 +02:00
|
|
|
|
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning disable 649
|
2016-03-13 20:19:52 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
internal readonly ulong SteamOwnerID;
|
2017-04-05 16:25:55 +02:00
|
|
|
|
#pragma warning restore 649
|
2016-03-13 20:19:52 +01:00
|
|
|
|
|
2016-03-09 19:25:45 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-02-03 09:54:09 +01:00
|
|
|
|
internal readonly ProtocolType SteamProtocol = ProtocolType.Tcp;
|
2016-03-09 19:25:45 +01:00
|
|
|
|
|
2016-11-24 07:32:16 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
internal readonly EUpdateChannel UpdateChannel = EUpdateChannel.Stable;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-02-03 09:59:02 +01:00
|
|
|
|
internal readonly EWCFBinding WCFBinding = EWCFBinding.NetTcp;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
2017-02-03 09:54:09 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-02-03 09:59:02 +01:00
|
|
|
|
internal readonly ushort WCFPort = DefaultWCFPort;
|
2016-03-09 05:02:07 +01:00
|
|
|
|
|
2017-02-03 09:56:18 +01:00
|
|
|
|
[JsonProperty]
|
|
|
|
|
|
internal string WCFHost { get; set; } = "127.0.0.1";
|
|
|
|
|
|
|
2016-11-24 07:32:16 +01:00
|
|
|
|
// This constructor is used only by deserializer
|
|
|
|
|
|
private GlobalConfig() { }
|
2016-03-06 23:28:56 +01:00
|
|
|
|
|
2016-04-12 19:12:45 +02:00
|
|
|
|
internal static GlobalConfig Load(string filePath) {
|
|
|
|
|
|
if (string.IsNullOrEmpty(filePath)) {
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogNullError(nameof(filePath));
|
2016-04-12 19:12:45 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-06 23:28:56 +01:00
|
|
|
|
if (!File.Exists(filePath)) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GlobalConfig globalConfig;
|
2016-05-30 01:57:06 +02:00
|
|
|
|
|
2016-03-06 23:28:56 +01:00
|
|
|
|
try {
|
|
|
|
|
|
globalConfig = JsonConvert.DeserializeObject<GlobalConfig>(File.ReadAllText(filePath));
|
|
|
|
|
|
} catch (Exception e) {
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogGenericException(e);
|
2016-03-06 23:28:56 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-28 13:11:02 +02:00
|
|
|
|
if (globalConfig == null) {
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogNullError(nameof(globalConfig));
|
2016-03-28 13:11:02 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-19 11:33:39 +01:00
|
|
|
|
// SK2 supports only TCP and UDP steam protocols
|
2016-03-22 17:26:39 +01:00
|
|
|
|
// Ensure that user can't screw this up
|
2016-03-19 11:33:39 +01:00
|
|
|
|
switch (globalConfig.SteamProtocol) {
|
|
|
|
|
|
case ProtocolType.Tcp:
|
|
|
|
|
|
case ProtocolType.Udp:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(globalConfig.SteamProtocol), globalConfig.SteamProtocol));
|
2016-07-25 06:08:45 +02:00
|
|
|
|
return null;
|
2016-03-19 11:33:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-22 17:26:39 +01:00
|
|
|
|
// User might not know what he's doing
|
|
|
|
|
|
// Ensure that he can't screw core ASF variables
|
|
|
|
|
|
if (globalConfig.MaxFarmingTime == 0) {
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(globalConfig.MaxFarmingTime), globalConfig.MaxFarmingTime));
|
2016-07-25 06:08:45 +02:00
|
|
|
|
return null;
|
2016-03-22 17:26:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (globalConfig.FarmingDelay == 0) {
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(globalConfig.FarmingDelay), globalConfig.FarmingDelay));
|
2016-07-25 06:08:45 +02:00
|
|
|
|
return null;
|
2016-03-22 17:26:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-22 20:10:28 +01:00
|
|
|
|
if (globalConfig.ConnectionTimeout == 0) {
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(globalConfig.ConnectionTimeout), globalConfig.ConnectionTimeout));
|
2016-07-25 06:08:45 +02:00
|
|
|
|
return null;
|
2016-03-22 17:26:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-13 06:32:42 +02:00
|
|
|
|
if (globalConfig.WCFPort != 0) {
|
|
|
|
|
|
return globalConfig;
|
2016-03-22 17:26:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-31 01:10:01 +01:00
|
|
|
|
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(globalConfig.WCFPort), globalConfig.WCFPort));
|
2016-07-25 06:08:45 +02:00
|
|
|
|
return null;
|
2016-03-06 23:28:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-30 22:17:25 +01:00
|
|
|
|
internal enum EOptimizationMode : byte {
|
|
|
|
|
|
MaxPerformance,
|
|
|
|
|
|
MinMemoryUsage
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-24 07:32:16 +01:00
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
|
|
|
|
|
internal enum EUpdateChannel : byte {
|
|
|
|
|
|
None,
|
|
|
|
|
|
Stable,
|
|
|
|
|
|
Experimental
|
|
|
|
|
|
}
|
2017-02-03 09:54:09 +01:00
|
|
|
|
|
2017-02-03 09:59:02 +01:00
|
|
|
|
internal enum EWCFBinding : byte {
|
2017-02-03 09:54:09 +01:00
|
|
|
|
NetTcp,
|
|
|
|
|
|
BasicHttp,
|
|
|
|
|
|
WSHttp
|
|
|
|
|
|
}
|
2016-03-06 23:28:56 +01:00
|
|
|
|
}
|
2016-11-24 07:32:16 +01:00
|
|
|
|
}
|