44using System . IO ;
55using System . Windows . Forms ;
66using SteamKit2 ;
7+ using System . Timers ;
78using SteamKit2 . Internal ;
89using 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
0 commit comments