Files
ArchiSteamFarm/ConfigGenerator/GlobalConfig.cs

172 lines
6.1 KiB
C#
Raw Normal View History

2016-03-20 05:27:30 +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;
using System.IO;
using System.Net.Sockets;
namespace ConfigGenerator {
2016-03-20 06:41:12 +01:00
internal sealed class GlobalConfig : ASFConfig {
2016-03-20 05:27:30 +01:00
internal enum EUpdateChannel : byte {
Unknown,
Stable,
Experimental
}
2016-03-23 13:39:56 +01:00
private const byte DefaultMaxFarmingTime = 10;
private const byte DefaultFarmingDelay = 5;
private const byte DefaultHttpTimeout = 60;
private const ushort DefaultWCFPort = 1242;
2016-03-26 22:51:19 +01:00
private const ProtocolType DefaultSteamProtocol = ProtocolType.Tcp;
2016-03-23 13:39:56 +01:00
2016-03-20 05:27:30 +01:00
// This is hardcoded blacklist which should not be possible to change
internal static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 267420, 303700, 335590, 368020, 425280 };
[JsonProperty(Required = Required.DisallowNull)]
public bool Debug { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public bool AutoUpdates { get; set; } = true;
[JsonProperty(Required = Required.DisallowNull)]
public EUpdateChannel UpdateChannel { get; set; } = EUpdateChannel.Stable;
[JsonProperty(Required = Required.DisallowNull)]
2016-03-23 13:39:56 +01:00
public ProtocolType SteamProtocol { get; set; } = DefaultSteamProtocol;
2016-03-20 05:27:30 +01:00
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamOwnerID { get; set; } = 0;
[JsonProperty(Required = Required.DisallowNull)]
2016-03-23 13:39:56 +01:00
public byte MaxFarmingTime { get; set; } = DefaultMaxFarmingTime;
2016-03-20 05:27:30 +01:00
[JsonProperty(Required = Required.DisallowNull)]
public byte IdleFarmingPeriod { get; set; } = 3;
[JsonProperty(Required = Required.DisallowNull)]
2016-03-23 13:39:56 +01:00
public byte FarmingDelay { get; set; } = DefaultFarmingDelay;
2016-03-20 05:27:30 +01:00
[JsonProperty(Required = Required.DisallowNull)]
public byte AccountPlayingDelay { get; set; } = 5;
[JsonProperty(Required = Required.DisallowNull)]
public byte LoginLimiterDelay { get; set; } = 7;
[JsonProperty(Required = Required.DisallowNull)]
public byte InventoryLimiterDelay { get; set; } = 3;
[JsonProperty(Required = Required.DisallowNull)]
public bool ForceHttp { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
2016-03-23 13:39:56 +01:00
public byte HttpTimeout { get; set; } = DefaultHttpTimeout;
2016-03-20 05:27:30 +01:00
2016-03-23 13:39:56 +01:00
[JsonProperty]
2016-03-20 05:27:30 +01:00
public string WCFHostname { get; set; } = "localhost";
[JsonProperty(Required = Required.DisallowNull)]
2016-03-23 13:39:56 +01:00
public ushort WCFPort { get; set; } = DefaultWCFPort;
2016-03-20 05:27:30 +01:00
[JsonProperty(Required = Required.DisallowNull)]
public bool LogToFile { get; set; } = true;
[JsonProperty(Required = Required.DisallowNull)]
public bool Statistics { get; set; } = true;
// TODO: Please remove me immediately after https://github.com/SteamRE/SteamKit/issues/254 gets fixed
[JsonProperty(Required = Required.DisallowNull)]
public bool HackIgnoreMachineID { get; set; } = false;
[JsonProperty(Required = Required.DisallowNull)]
public List<uint> Blacklist { get; set; } = new List<uint>();
internal static GlobalConfig Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
return null;
}
if (!File.Exists(filePath)) {
return new GlobalConfig(filePath);
}
GlobalConfig globalConfig;
try {
globalConfig = JsonConvert.DeserializeObject<GlobalConfig>(File.ReadAllText(filePath));
} catch (Exception e) {
Logging.LogGenericException(e);
2016-03-23 13:42:16 +01:00
return new GlobalConfig(filePath);
2016-03-20 05:27:30 +01:00
}
2016-03-23 18:38:19 +01:00
globalConfig.FilePath = filePath;
2016-03-20 05:27:30 +01:00
// SK2 supports only TCP and UDP steam protocols
2016-03-23 13:39:56 +01:00
// Ensure that user can't screw this up
2016-03-20 05:27:30 +01:00
switch (globalConfig.SteamProtocol) {
case ProtocolType.Tcp:
case ProtocolType.Udp:
break;
default:
2016-03-23 13:39:56 +01:00
Logging.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol + ". Value of " + DefaultSteamProtocol + " will be used instead");
globalConfig.SteamProtocol = DefaultSteamProtocol;
2016-03-20 05:27:30 +01:00
break;
}
2016-03-23 13:39:56 +01:00
// User might not know what he's doing
// Ensure that he can't screw core ASF variables
if (globalConfig.MaxFarmingTime == 0) {
Logging.LogGenericWarning("Configured MaxFarmingTime is invalid: " + globalConfig.MaxFarmingTime + ". Value of " + DefaultMaxFarmingTime + " will be used instead");
globalConfig.MaxFarmingTime = DefaultMaxFarmingTime;
}
if (globalConfig.FarmingDelay == 0) {
Logging.LogGenericWarning("Configured FarmingDelay is invalid: " + globalConfig.FarmingDelay + ". Value of " + DefaultFarmingDelay + " will be used instead");
globalConfig.FarmingDelay = DefaultFarmingDelay;
}
if (globalConfig.HttpTimeout == 0) {
Logging.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout + ". Value of " + DefaultHttpTimeout + " will be used instead");
globalConfig.HttpTimeout = DefaultHttpTimeout;
}
if (globalConfig.WCFPort == 0) {
Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort + ". Value of " + DefaultWCFPort + " will be used instead");
globalConfig.WCFPort = DefaultWCFPort;
}
2016-03-20 05:27:30 +01:00
return globalConfig;
}
// This constructor is used only by deserializer
2016-03-26 22:51:19 +01:00
private GlobalConfig() { }
2016-03-20 05:27:30 +01:00
2016-03-20 06:41:12 +01:00
private GlobalConfig(string filePath) : base(filePath) {
2016-03-20 05:27:30 +01:00
FilePath = filePath;
Blacklist.AddRange(GlobalBlacklist);
2016-03-20 08:29:27 +01:00
Save();
2016-03-20 05:27:30 +01:00
}
}
}