public static ReadPassword ( char mask ) : string | ||
mask | char | Mask char |
Résultat | string |
/// <summary> /// Main initializer for each account /// </summary> /// <param name="info">Account info</param> public Bot(Config.AccountSettings info) { /*If a password isn't set we'll ask for user input*/ if (string.IsNullOrWhiteSpace(info.Details.Password) && string.IsNullOrWhiteSpace(info.Details.LoginKey)) { Console.WriteLine("Enter password for account '{0}'", info.Details.Username); info.Details.Password = Password.ReadPassword('*'); } /*Assign bot info*/ mSteam.loginDetails = new SteamUser.LogOnDetails() { Username = info.Details.Username, Password = info.Details.Password, LoginKey = info.Details.LoginKey, ShouldRememberPassword = true, }; mAccountSettings = info; mSteam.games = info.Games; mSteam.customText = info.CustomText; mSteam.sentryPath = string.Format("Sentryfiles/{0}.sentry", info.Details.Username); /*Set up steamweb*/ mSteam.web = new SteamWeb(); ServicePointManager.ServerCertificateValidationCallback += mSteam.web.ValidateRemoteCertificate; /*Create logs*/ mLog = new Log(info.Details.Username, Path.Combine(EndPoint.LOG_FOLDER_PATH, $"{info.Details.Username}.txt"), 1); mLogChat = new Log($"{info.Details.Username} Chat", Path.Combine(EndPoint.LOG_FOLDER_PATH, $"{info.Details.Username} steam chat.txt"), 1); /*Assign clients*/ mSteam.client = new SteamClient(); mSteam.callbackManager = new CallbackManager(mSteam.client); mSteam.user = mSteam.client.GetHandler <SteamUser>(); mSteam.friends = mSteam.client.GetHandler <SteamFriends>(); mSteam.extraHandler = new ExtraHandler(this); mSteam.client.AddHandler(mSteam.extraHandler); /*Subscribe to Callbacks*/ mSteam.callbackManager.Subscribe <SteamClient.ConnectedCallback>(OnConnected); mSteam.callbackManager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected); mSteam.callbackManager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); mSteam.callbackManager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); mSteam.callbackManager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey); mSteam.callbackManager.Subscribe <SteamUser.WebAPIUserNonceCallback>(OnWebAPIUserNonce); mSteam.callbackManager.Subscribe <SteamFriends.FriendMsgCallback>(OnFriendMsgCallback); mSteam.callbackManager.Subscribe <ExtraHandler.PlayingSessionStateCallback>(OnPlayingSessionState); /*Start Callback thread*/ mBotThread.DoWork += BackgroundWorkerOnDoWork; mBotThread.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; mBotThread.RunWorkerAsync(); Connect(); }
/// <summary> /// OnLoggedOn Callback /// Fires when User logs in successfully /// </summary> /// <param name="callback"></param> private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { string userInfo = string.Format("{0},{1}", mInfo.Username, mInfo.Password); switch (callback.Result) { case EResult.AccountLogonDenied: Print("Enter the SteamGuard code from your email:"); mSteam.loginDetails.AuthCode = Console.ReadLine(); return; case EResult.AccountLoginDeniedNeedTwoFactor: Print("Enter your two-way authentication code:"); mSteam.loginDetails.TwoFactorCode = Console.ReadLine(); return; case EResult.InvalidPassword: Properties.Settings.Default.UserInfo.Remove(userInfo); Properties.Settings.Default.Save(); Print("{0} - Invalid password! Try again:", callback.Result); mSteam.loginDetails.Password = Password.ReadPassword(); mSteam.loginDetails.LoginKey = string.Empty; return; case EResult.TwoFactorCodeMismatch: Print("{0} - Invalid two factor code! Try again:", callback.Result); mSteam.loginDetails.TwoFactorCode = Console.ReadLine(); return; case EResult.ServiceUnavailable: Print("{0} - Service unavailable. We'll force a pause here."); mDisconnectedCounter = 4; return; } /*We didn't account for what happened*/ if (callback.Result != EResult.OK) { Print("{0} - Uncaught EResult, what might this be?", callback.Result); return; } /*Logged in successfully*/ Print("Successfully logged in!\n"); mSteam.nounce = callback.WebAPIUserNonce; mBotState = BotState.LoggedIn; LogOnSuccess(userInfo); }
/// <summary> /// Main initializer for each account /// </summary> /// <param name="info">Account info</param> public Bot(Config.AccountInfo info, Config.Settings settings) { /*If a password isn't set we'll ask for user input*/ if (string.IsNullOrEmpty(info.Password)) { Console.WriteLine("Enter password for account '{0}'", info.Username); info.Password = Password.ReadPassword(); } /*Assign bot info*/ mSteam.loginDetails = new SteamUser.LogOnDetails() { Username = info.Username, Password = info.Password, ShouldRememberPassword = true }; mInfo = info; mSettings = settings; mSteam.games = info.Games; mSteam.sentryPath = Path.Combine(Application.StartupPath, string.Format("Sentryfiles\\{0}.sentry", info.Username)); /*Assign clients*/ mSteam.client = new SteamClient(); mSteam.callbackManager = new CallbackManager(mSteam.client); mSteam.user = mSteam.client.GetHandler <SteamUser>(); mSteam.friends = mSteam.client.GetHandler <SteamFriends>(); /*Subscribe to Callbacks*/ mSteam.callbackManager.Subscribe <SteamClient.ConnectedCallback>(OnConnected); mSteam.callbackManager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected); mSteam.callbackManager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); mSteam.callbackManager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); mSteam.callbackManager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey); /*Connect to Steam*/ Connect(); /*Start Callback thread*/ mBotThread = new BackgroundWorker { WorkerSupportsCancellation = true }; mBotThread.DoWork += BackgroundWorkerOnDoWork; mBotThread.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; mBotThread.RunWorkerAsync(); }
/// <summary> /// Main initializer for each account /// </summary> /// <param name="info">Account info</param> public BotClass(Config.AccountInfo info, Config.Settings settings) { /*If a password isn't set we'll ask for user input*/ if (string.IsNullOrEmpty(info.Password)) { Console.WriteLine("Enter password for account '{0}'", info.Username); info.Password = Password.ReadPassword(); } /*Assign bot info*/ mSteam.loginDetails = new SteamUser.LogOnDetails() { Username = info.Username, Password = info.Password }; mInfo = info; mSettings = settings; mSteam.games = info.Games; mSteam.sentryPath = Path.Combine(Application.StartupPath, string.Format("Sentryfiles\\{0}.sentry", info.Username)); /*Assign clients*/ mSteam.client = new SteamClient(); mSteam.callbackManager = new CallbackManager(mSteam.client); mSteam.user = mSteam.client.GetHandler<SteamUser>(); mSteam.friends = mSteam.client.GetHandler<SteamFriends>(); /*Assign Callbacks*/ new Callback<SteamClient.ConnectedCallback>(OnConnected, mSteam.callbackManager); new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, mSteam.callbackManager); new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, mSteam.callbackManager); new Callback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, mSteam.callbackManager); /*Connect to Steam*/ Print("Connecting to steam ...", info.Username); mSteam.client.Connect(); /*Start Callback thread*/ mThreadCallback = new Thread(RunCallback); mThreadCallback.Start(); }
/// <summary> /// OnLoggedOn Callback /// Fires when User logs in successfully /// </summary> /// <param name="callback">SteamUser.LoggedOnCallback</param> private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { switch (callback.Result) { case EResult.AccountLogonDenied: mLog.Write(Log.LogLevel.Text, $"Enter the SteamGuard code from your email:"); mSteam.loginDetails.AuthCode = Console.ReadLine(); return; case EResult.AccountLoginDeniedNeedTwoFactor: mLog.Write(Log.LogLevel.Text, $"Enter your two-way authentication code:"); mSteam.loginDetails.TwoFactorCode = Console.ReadLine(); return; case EResult.InvalidPassword: mLog.Write(Log.LogLevel.Warn, $"The password was not accepted."); if (!mHasConnectedOnce && !string.IsNullOrWhiteSpace(mAccountSettings.Details.LoginKey)) { /*Remove LoginKey if we haven't been logged in before*/ mLog.Write(Log.LogLevel.Info, $"Removed LoginKey for this account because it's invalid"); mSteam.loginDetails.LoginKey = string.Empty; mAccountSettings.Details.LoginKey = string.Empty; } else if (string.IsNullOrWhiteSpace(mAccountSettings.Details.Password)) { /*Re-input password if no password was set in settings*/ mLog.Write(Log.LogLevel.Text, $"Re-enter your Steam password:"******"Invalid two factor code! Try again:"); mSteam.loginDetails.TwoFactorCode = Console.ReadLine(); return; case EResult.Timeout: case EResult.NoConnection: case EResult.TryAnotherCM: case EResult.ServiceUnavailable: mLog.Write(Log.LogLevel.Warn, $"Service unavailable. Waiting 1 minute."); Thread.Sleep(TimeSpan.FromMinutes(1)); return; case EResult.RateLimitExceeded: mLog.Write(Log.LogLevel.Error, $"IP has been rate limited. We will wait for {RATE_LIMITED_DELAY} minutes and try again."); Thread.Sleep(TimeSpan.FromMinutes(RATE_LIMITED_DELAY)); return; } /*We didn't account for what happened*/ if (callback.Result != EResult.OK) { mLog.Write(Log.LogLevel.Warn, $"Unhandled EResult response. Please report this issue. --> {callback.Result}"); return; } /*Logged in successfully*/ mLog.Write(Log.LogLevel.Success, $"Successfully logged in!"); mSteam.nounce = callback.WebAPIUserNonce; mBotState = BotState.LoggedIn; if (callback.CellID != 0 && Program.mGlobalDB.CellID != callback.CellID) { Program.mGlobalDB.CellID = callback.CellID; } mHasConnectedOnce = true; mDisconnectedCounter = 0; mPlayingBlocked = false; LogOnSuccess(); }
/// <summary> /// OnLoggedOn Callback /// Fires when User logs in successfully /// </summary> /// <param name="callback"></param> private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { /*Fetch if SteamGuard is required*/ if (callback.Result == EResult.AccountLogonDenied) { /*SteamGuard required*/ Print("Enter the SteamGuard code from your email:"); mSteam.loginDetails.AuthCode = Console.ReadLine(); return; } /*If two-way authentication*/ if(callback.Result == EResult.AccountLogonDeniedNeedTwoFactorCode) { /*Account requires two-way authentication*/ Print("Enter your two-way authentication code:"); mSteam.loginDetails.TwoFactorCode = Console.ReadLine(); return; } /*Something terrible has happened*/ string userInfo = string.Format("{0},{1}", mInfo.Username, mInfo.Password); if (callback.Result != EResult.OK) { /*Incorrect password*/ if (callback.Result == EResult.InvalidPassword) { /*Delete old user info*/ Properties.Settings.Default.UserInfo.Remove(userInfo); Properties.Settings.Default.Save(); Print("{0} - Invalid password! Try again:", callback.Result); mSteam.loginDetails.Password = Password.ReadPassword(); } /*Incorrect two-factor*/ if (callback.Result == EResult.TwoFactorCodeMismatch) { Print("{0} - Invalid two factor code! Try again:", callback.Result); mSteam.loginDetails.TwoFactorCode = Console.ReadLine(); } /*Incorrect email code*/ if (callback.Result == EResult.AccountLogonDenied) { Print("{0} - Invalid email auth code! Try again:", callback.Result); mSteam.loginDetails.AuthCode = Console.ReadLine(); } /*Disconnect and retry*/ mSteam.client.Disconnect(); mBotState = BotState.LoggedOut; return; } /*Logged in successfully*/ Print("Successfully logged in!\n"); mSteam.nounce = callback.WebAPIUserNonce; mBotState = BotState.LoggedIn; /*Since login was successfull we can save the password here*/ /*Yep, it's done in plaintext is resources. Deal with it.*/ if (!Properties.Settings.Default.UserInfo.Contains(userInfo)) { DialogResult dialogResult = MessageBox.Show("Do you want to save the password?", "Save info", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { Properties.Settings.Default.UserInfo.Add(userInfo); Properties.Settings.Default.Save(); } } /*Gets a random extra time for the timer*/ var random = new Random(); int extraTime = random.Next(20, 60); /*Set the timer if it's not already enabled*/ if (!mGameTimer.Enabled && mSettings.RestartGamesEveryThreeHours) { mGameTimer.Interval = TimeSpan.FromMinutes(180 + extraTime).TotalMilliseconds; mGameTimer.Elapsed += new ElapsedEventHandler(PreformStopStart); mGameTimer.Start(); } /*Set games playing*/ SetGamesPlaying(true); }