/// <summary> /// Determines if the user is logged out and logs him back in if he is. /// If the bot does not have valid login information, then it will quit. /// </summary> /// <returns>true if we are already logged in or we are able to log in, false if we can't log in</returns> protected virtual bool CheckLogIn(bool readWindow) { //Check several times over several seconds to make sure that we are logged out before trying to log in for (int i = 0; i < 6; i++) { if (!Screen.IsLoggedOut(readWindow)) { return(true); //already logged in } SafeWait(1000); } //see if we have login and password to log in if (string.IsNullOrEmpty(RunParams.Login) || string.IsNullOrEmpty(RunParams.Password)) { MessageBox.Show("Cannot log in without login information"); return(false); } else { return(LogIn()); } }
/// <summary> /// Makes sure that a client is running and starts it if it isn't /// </summary> /// <param name="forceRestart">Set to true to force a client restart even if the client is already running</param> /// <returns>true if client is successfully prepared</returns> public bool PrepareClient(bool forceRestart = false) { if (!forceRestart && ScreenScraper.ProcessExists(Value)) { return(true); } Process client = null; Stopwatch longWatch = new Stopwatch(); longWatch.Start(); while (longWatch.ElapsedMilliseconds < UnitConversions.HoursToMilliseconds(24) && !BotProgram.StopFlag) { if (!ScreenScraper.RestartClient(ref client, RunParams.RuneScapeClient, RunParams.ClientFlags)) { BotProgram.SafeWait(5000); continue; } //Successful restart Value = client; Stopwatch watch = new Stopwatch(); watch.Start(); //Wait for cient to be visually recognized. do { BotProgram.SafeWait(UnitConversions.SecondsToMilliseconds(5)); if (Screen.ReadWindow(false) && (Screen.IsLoggedOut(false) || Screen.IsLoggedIn(false))) { return(true); } }while ((watch.ElapsedMilliseconds < UnitConversions.MinutesToMilliseconds(5)) && !BotProgram.StopFlag); } if (!BotProgram.StopFlag) { const string errorMessage = "Client did not start correctly"; MessageBox.Show(errorMessage); } Value = null; return(false); }