Compare commits

...

12 Commits

Author SHA1 Message Date
JustArchi
eb4e9ee077 Fix remaining crash 2016-03-11 21:40:25 +01:00
JustArchi
601a486b13 Bump 2016-03-11 19:58:03 +01:00
JustArchi
14867f470d Derp 2016-03-11 19:49:52 +01:00
JustArchi
187f0800b2 Add !update 2016-03-11 19:48:14 +01:00
JustArchi
3afa202d0b Misc 2016-03-11 19:42:15 +01:00
JustArchi
d33e76c8b0 Add !farm, closes #151 2016-03-11 19:39:25 +01:00
JustArchi
3061c55eaf Bump 2016-03-11 19:15:56 +01:00
JustArchi
621a1dc2cb Do not crash on bad configs 2016-03-11 18:49:29 +01:00
JustArchi
1a832780a2 Bump 2016-03-11 18:35:42 +01:00
JustArchi
ab531c80df Misc 2016-03-11 02:15:25 +01:00
JustArchi
f20ea0a87f Add FarmingPeriod 2016-03-11 02:07:20 +01:00
JustArchi
3e7f726afb Bump 2016-03-11 00:52:15 +01:00
8 changed files with 73 additions and 30 deletions

View File

@@ -46,6 +46,10 @@ namespace ArchiSteamFarm {
}
internal ArchiWebHandler(Bot bot) {
if (bot == null) {
return;
}
Bot = bot;
}

View File

@@ -262,16 +262,16 @@ namespace ArchiSteamFarm {
return;
}
if (!await BotDatabase.SteamGuardAccount.RefreshSessionAsync().ConfigureAwait(false)) {
return;
}
Confirmation[] confirmations = await BotDatabase.SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false);
if (confirmations == null) {
return;
}
try {
if (!await BotDatabase.SteamGuardAccount.RefreshSessionAsync().ConfigureAwait(false)) {
return;
}
Confirmation[] confirmations = await BotDatabase.SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false);
if (confirmations == null) {
return;
}
foreach (Confirmation confirmation in confirmations) {
if (BotDatabase.SteamGuardAccount.AcceptConfirmation(confirmation)) {
Logging.LogGenericInfo("Accepting confirmation: Success!", BotName);
@@ -283,6 +283,9 @@ namespace ArchiSteamFarm {
Logging.LogGenericWarning("Accepting confirmation: Failed!", BotName);
Logging.LogGenericWarning("Confirmation could not be accepted because of invalid token exception", BotName);
Logging.LogGenericWarning("If issue persists, consider removing and readding ASF 2FA", BotName);
} catch (Exception e) {
Logging.LogGenericException(e, BotName);
return;
}
}
@@ -329,6 +332,10 @@ namespace ArchiSteamFarm {
case "!exit":
Program.Exit();
return null;
case "!farm":
return await ResponseFarm().ConfigureAwait(false);
case "!loot":
return await ResponseSendTrade().ConfigureAwait(false);
case "!rejoinchat":
return ResponseRejoinChat();
case "!restart":
@@ -340,8 +347,9 @@ namespace ArchiSteamFarm {
return ResponseStatusAll();
case "!stop":
return ResponseStop();
case "!loot":
return await ResponseSendTrade().ConfigureAwait(false);
case "!update":
await Program.CheckForUpdate().ConfigureAwait(false);
return "Done!";
default:
return "Unrecognized command: " + message;
}
@@ -360,6 +368,10 @@ namespace ArchiSteamFarm {
} else {
return await ResponseAddLicense(BotName, args[1]).ConfigureAwait(false);
}
case "!farm":
return await ResponseFarm(args[1]).ConfigureAwait(false);
case "!loot":
return await ResponseSendTrade(args[1]).ConfigureAwait(false);
case "!play":
if (args.Length > 2) {
return await ResponsePlay(args[1], args[2]).ConfigureAwait(false);
@@ -374,12 +386,10 @@ namespace ArchiSteamFarm {
}
case "!start":
return await ResponseStart(args[1]).ConfigureAwait(false);
case "!stop":
return ResponseStop(args[1]);
case "!status":
return ResponseStatus(args[1]);
case "!loot":
return await ResponseSendTrade(args[1]).ConfigureAwait(false);
case "!stop":
return ResponseStop(args[1]);
default:
return "Unrecognized command: " + args[0];
}
@@ -562,6 +572,24 @@ namespace ArchiSteamFarm {
return await bot.Response2FAOK().ConfigureAwait(false);
}
private async Task<string> ResponseFarm() {
await CardsFarmer.RestartFarming().ConfigureAwait(false);
return "Done!";
}
private static async Task<string> ResponseFarm(string botName) {
if (string.IsNullOrEmpty(botName)) {
return null;
}
Bot bot;
if (!Bots.TryGetValue(botName, out bot)) {
return "Couldn't find any bot named " + botName + "!";
}
return await bot.ResponseFarm().ConfigureAwait(false);
}
private async Task<string> ResponseRedeem(string message, bool validate) {
if (string.IsNullOrEmpty(message)) {
return null;

View File

@@ -35,7 +35,7 @@ using System.Threading.Tasks;
namespace ArchiSteamFarm {
internal sealed class CardsFarmer {
internal readonly ConcurrentDictionary<uint, float> GamesToFarm = new ConcurrentDictionary<uint, float>();
internal readonly List<uint> CurrentGamesFarming = new List<uint>();
internal readonly HashSet<uint> CurrentGamesFarming = new HashSet<uint>();
private readonly ManualResetEvent FarmResetEvent = new ManualResetEvent(false);
private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1);
@@ -47,24 +47,28 @@ namespace ArchiSteamFarm {
private bool NowFarming = false;
internal CardsFarmer(Bot bot) {
if (bot == null) {
return;
}
Bot = bot;
if (Timer == null) {
if (Program.GlobalConfig.IdleFarmingPeriod > 0 && Timer == null) {
Timer = new Timer(
async e => await CheckGamesForFarming().ConfigureAwait(false),
null,
TimeSpan.FromMinutes(15), // Delay
TimeSpan.FromMinutes(60) // Period
TimeSpan.FromHours(Program.GlobalConfig.IdleFarmingPeriod), // Delay
TimeSpan.FromHours(Program.GlobalConfig.IdleFarmingPeriod) // Period
);
}
}
internal static List<uint> GetGamesToFarmSolo(ConcurrentDictionary<uint, float> gamesToFarm) {
internal static HashSet<uint> GetGamesToFarmSolo(ConcurrentDictionary<uint, float> gamesToFarm) {
if (gamesToFarm == null) {
return null;
}
List<uint> result = new List<uint>();
HashSet<uint> result = new HashSet<uint>();
foreach (KeyValuePair<uint, float> keyValue in gamesToFarm) {
if (keyValue.Value >= 2) {
result.Add(keyValue.Key);
@@ -177,10 +181,10 @@ namespace ArchiSteamFarm {
if (Bot.BotConfig.CardDropsRestricted) { // If we have restricted card drops, we use complex algorithm
Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName);
while (GamesToFarm.Count > 0) {
List<uint> gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm);
HashSet<uint> gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm);
if (gamesToFarmSolo.Count > 0) {
while (gamesToFarmSolo.Count > 0) {
uint appID = gamesToFarmSolo[0];
uint appID = gamesToFarmSolo.First();
if (await FarmSolo(appID).ConfigureAwait(false)) {
farmedSomething = true;
Logging.LogGenericInfo("Done farming: " + appID, Bot.BotName);
@@ -193,7 +197,6 @@ namespace ArchiSteamFarm {
}
} else {
if (FarmMultiple(GamesToFarm)) {
farmedSomething = true;
Logging.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Keys), Bot.BotName);
} else {
NowFarming = false;

View File

@@ -50,6 +50,9 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
internal byte MaxFarmingTime { get; private set; } = 10;
[JsonProperty(Required = Required.DisallowNull)]
internal byte IdleFarmingPeriod { get; private set; } = 3;
[JsonProperty(Required = Required.DisallowNull)]
internal byte FarmingDelay { get; private set; } = 5;

View File

@@ -78,7 +78,7 @@ namespace ArchiSteamFarm {
private static Timer AutoUpdatesTimer;
private static EMode Mode = EMode.Normal;
private static async Task CheckForUpdate() {
internal static async Task CheckForUpdate() {
string oldExeFile = ExecutableFile + ".old";
// We booted successfully so we can now remove old exe file
@@ -334,7 +334,7 @@ namespace ArchiSteamFarm {
private static void InitServices() {
GlobalConfig = GlobalConfig.Load();
if (GlobalConfig == null) {
Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.db exists and is valid!");
Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!");
Thread.Sleep(5000);
Exit(1);
}
@@ -454,7 +454,7 @@ namespace ArchiSteamFarm {
}
Bot bot = new Bot(botName);
if (!bot.BotConfig.Enabled) {
if (bot.BotConfig == null || !bot.BotConfig.Enabled) {
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
}
}
@@ -464,7 +464,7 @@ namespace ArchiSteamFarm {
string botName = Path.GetFileNameWithoutExtension(configFile);
Logging.LogGenericWarning("Found legacy " + botName + ".xml config file, it will now be converted to new ASF V2.0 format!");
Bot bot = new Bot(botName);
if (!bot.BotConfig.Enabled) {
if (bot.BotConfig == null || !bot.BotConfig.Enabled) {
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
}
}

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.3")]
[assembly: AssemblyFileVersion("2.0.0.3")]
[assembly: AssemblyVersion("2.0.0.7")]
[assembly: AssemblyFileVersion("2.0.0.7")]

View File

@@ -46,6 +46,10 @@ namespace ArchiSteamFarm {
}
internal Trading(Bot bot) {
if (bot == null) {
return;
}
Bot = bot;
}

View File

@@ -3,6 +3,7 @@
"AutoUpdates": true,
"UpdateChannel": 1,
"MaxFarmingTime": 10,
"IdleFarmingPeriod": 3,
"FarmingDelay": 5,
"AccountPlayingDelay": 5,
"LoginLimiterDelay": 7,