Skip to content

Commit 847bba2

Browse files
author
Casper
committed
Added a random stop/start after 3 hours of idling
After 3 hours (+ random time) it will stop idling games for 5 minutes and then start again. This will hopefully fix the problem where hours stop counting.
1 parent ae0b557 commit 847bba2

3 files changed

Lines changed: 99 additions & 53 deletions

File tree

HourBoostr/BotClass.cs

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Windows.Forms;
66
using SteamKit2;
7+
using System.Timers;
78
using SteamKit2.Internal;
89
using System.Security.Cryptography;
910

@@ -106,6 +107,12 @@ public enum BotState
106107
public Config.AccountInfo mInfo { get; private set; }
107108

108109

110+
/// <summary>
111+
/// Timer to simulate stopping and restarting a game
112+
/// </summary>
113+
private System.Timers.Timer mGameTimer;
114+
115+
109116
/// <summary>
110117
/// Main initializer for each account
111118
/// </summary>
@@ -185,7 +192,7 @@ private void OnConnected(SteamClient.ConnectedCallback callback)
185192
/*Login - NOT OK*/
186193
if(callback.Result != EResult.OK)
187194
{
188-
Print(string.Format("Error: {0}", callback.Result));
195+
Print("Error: {0}", callback.Result);
189196
mIsRunning = false;
190197
return;
191198
}
@@ -223,6 +230,49 @@ private void OnDisconnected(SteamClient.DisconnectedCallback callback)
223230
}
224231

225232

233+
/// <summary>
234+
/// OnMachineAuth Callback
235+
/// Fires when User is authenticating the Steam account
236+
/// </summary>
237+
/// <param name="callback"></param>
238+
private void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
239+
{
240+
/*Handles Sentry file for auth*/
241+
int fileSize;
242+
byte[] sentryHash;
243+
using (var fs = File.Open(mSteam.sentryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
244+
{
245+
/*Fetch data*/
246+
fs.Seek(callback.Offset, SeekOrigin.Begin);
247+
fs.Write(callback.Data, 0, callback.BytesToWrite);
248+
fileSize = (int)fs.Length;
249+
fs.Seek(0, SeekOrigin.Begin);
250+
using (var sha = new SHA1CryptoServiceProvider())
251+
{
252+
sentryHash = sha.ComputeHash(fs);
253+
}
254+
}
255+
256+
/*Inform steam servers that we're accepting this sentry file*/
257+
mSteam.user.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
258+
{
259+
/*Set the information recieved*/
260+
JobID = callback.JobID,
261+
FileName = callback.FileName,
262+
263+
BytesWritten = callback.BytesToWrite,
264+
FileSize = fileSize,
265+
Offset = callback.Offset,
266+
267+
Result = EResult.OK,
268+
LastError = 0,
269+
270+
OneTimePassword = callback.OneTimePassword,
271+
SentryFileHash = sentryHash,
272+
});
273+
}
274+
275+
226276
/// <summary>
227277
/// OnLoggedOn Callback
228278
/// Fires when User logs in successfully
@@ -259,21 +309,21 @@ private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
259309
Properties.Settings.Default.UserInfo.Add(userInfo);
260310
Properties.Settings.Default.Save();
261311

262-
Print(string.Format("{0} - Invalid password! Try again:", callback.Result));
312+
Print("{0} - Invalid password! Try again:", callback.Result);
263313
mSteam.loginDetails.Password = Password.ReadPassword();
264314
}
265315

266316
/*Incorrect two-factor*/
267317
if (callback.Result == EResult.TwoFactorCodeMismatch)
268318
{
269-
Print(string.Format("{0} - Invalid two factor code! Try again:", callback.Result));
319+
Print("{0} - Invalid two factor code! Try again:", callback.Result);
270320
mSteam.loginDetails.TwoFactorCode = Console.ReadLine();
271321
}
272322

273323
/*Incorrect email code*/
274324
if (callback.Result == EResult.AccountLogonDenied)
275325
{
276-
Print(string.Format("{0} - Invalid email auth code! Try again:", callback.Result));
326+
Print("{0} - Invalid email auth code! Try again:", callback.Result);
277327
mSteam.loginDetails.AuthCode = Console.ReadLine();
278328
}
279329

@@ -300,67 +350,58 @@ private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
300350
}
301351
}
302352

353+
/*Gets a random extra time for the timer*/
354+
var random = new Random();
355+
int extraTime = random.Next(20, 60);
356+
357+
/*Set the timer*/
358+
mGameTimer = new System.Timers.Timer();
359+
mGameTimer.Interval = TimeSpan.FromMinutes(180 + extraTime).TotalMilliseconds;
360+
mGameTimer.Elapsed += new ElapsedEventHandler(PreformStopStart);
361+
mGameTimer.Start();
362+
303363
/*Set games playing*/
304-
SetGamesPlaying();
364+
SetGamesPlaying(true);
305365
}
306366

307367

308368
/// <summary>
309-
/// OnMachineAuth Callback
310-
/// Fires when User is authenticating the Steam account
369+
/// This will simulate stopping playing games and restarting it after a random period
370+
/// This is called from a timer
311371
/// </summary>
312-
/// <param name="callback"></param>
313-
private void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
372+
private void PreformStopStart(object sender, ElapsedEventArgs e)
314373
{
315-
/*Handles Sentry file for auth*/
316-
int fileSize;
317-
byte[] sentryHash;
318-
using (var fs = File.Open(mSteam.sentryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
319-
{
320-
/*Fetch data*/
321-
fs.Seek(callback.Offset, SeekOrigin.Begin);
322-
fs.Write(callback.Data, 0, callback.BytesToWrite);
323-
fileSize = (int)fs.Length;
324-
fs.Seek(0, SeekOrigin.Begin);
325-
using (var sha = new SHA1CryptoServiceProvider())
326-
{
327-
sentryHash = sha.ComputeHash(fs);
328-
}
329-
}
330-
331-
/*Inform steam servers that we're accepting this sentry file*/
332-
mSteam.user.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
333-
{
334-
/*Set the information recieved*/
335-
JobID = callback.JobID,
336-
FileName = callback.FileName,
337-
338-
BytesWritten = callback.BytesToWrite,
339-
FileSize = fileSize,
340-
Offset = callback.Offset,
341-
342-
Result = EResult.OK,
343-
LastError = 0,
344-
345-
OneTimePassword = callback.OneTimePassword,
346-
SentryFileHash = sentryHash,
347-
});
374+
mGameTimer.Stop();
375+
SetGamesPlaying(false);
376+
Print("Stopping games for 5 minutes.");
377+
Thread.Sleep(TimeSpan.FromMinutes(5));
378+
Print("Starting games again.");
379+
SetGamesPlaying(true);
380+
mGameTimer.Start();
348381
}
349382

350383

351384
/// <summary>
352385
/// Set the game currently playing for cooler looks lel
353386
/// </summary>
354-
/// <param name="id"></param>
355-
private void SetGamesPlaying()
387+
/// <param name="state">True to start games, False to stop</param>
388+
private void SetGamesPlaying(bool state)
356389
{
390+
/*Local list*/
391+
var gameList = new List<int>();
392+
393+
/*To start boosting we'll give the local list the values from settings*/
394+
/*To stop boosting we'll simply pass an empty list*/
395+
if (state)
396+
gameList = mSteam.games;
397+
357398
/*Set up requested games*/
358399
var gamesPlaying = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
359-
foreach(int Game in mSteam.games)
400+
foreach(int game in gameList)
360401
{
361402
gamesPlaying.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed
362403
{
363-
game_id = new GameID(Game),
404+
game_id = new GameID(game),
364405
});
365406
}
366407

HourBoostr/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ we need to keep the thread running*/
159159
/// TrayIcon click event
160160
/// Show/Hide the window depending on its state
161161
/// </summary>
162-
/// <param name="sender"></param>
163-
/// <param name="e"></param>
164162
static private void TrayIcon_Click(object sender, EventArgs e)
165163
{
166164
ShowConsole(!mIsHidden);
@@ -170,7 +168,7 @@ static private void TrayIcon_Click(object sender, EventArgs e)
170168
/// <summary>
171169
/// Show/Hide the console window
172170
/// </summary>
173-
/// <param name="b">Display console</param>
171+
/// <param name="b">Toggles console window</param>
174172
static private void ShowConsole(bool b)
175173
{
176174
if(b)
@@ -193,7 +191,7 @@ static private void ShowConsole(bool b)
193191
/// action before windows forces the program to close
194192
/// </summary>
195193
/// <param name="eventType">Event type</param>
196-
/// <returns>Retuurns bool</returns>
194+
/// <returns>Returns bool</returns>
197195
static bool ConsoleEventCallback(int eventType)
198196
{
199197
/*eventType 2 being Exit event*/
@@ -238,6 +236,9 @@ static void Main(string[] args)
238236
ShowConsole(false);
239237
mTrayIcon.ShowBalloonTip(1000, "HourBoostr", "I'm down here!", ToolTipIcon.Info);
240238

239+
/*Make a nice log stuff or whatever*/
240+
Console.WriteLine("\n\n Log:\n ----------------------------------------\n");
241+
241242
/*Keep it alive*/
242243
while (true)
243244
{

HourBoostr/Session.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ namespace HourBoostr
88
class Session
99
{
1010
/// <summary>
11-
/// Private variables
11+
/// Application settings
1212
/// </summary>
1313
private Config.Settings mSettings;
14+
15+
16+
/// <summary>
17+
/// DateTime representing when all accounts were initialized
18+
/// </summary>
1419
private DateTime mInitializedTime;
1520

1621

@@ -21,9 +26,8 @@ class Session
2126

2227

2328
/// <summary>
24-
/// Thread variables
29+
/// Thread for updating title status
2530
/// </summary>
26-
private Thread mThreadMain;
2731
private Thread mThreadStatus;
2832

2933

0 commit comments

Comments
 (0)