private void SetLoginDetails(SteamUser.LogOnDetails details) { this.AppTickets = new Dictionary <uint, byte[]>(); this.AppTokens = new Dictionary <uint, ulong>(); this.DepotKeys = new Dictionary <uint, byte[]>(); this.CDNAuthTokens = new ConcurrentDictionary <string, SteamApps.CDNAuthTokenCallback>(); this.AppInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.PackageInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.AppBetaPasswords = new Dictionary <string, byte[]>(); this.logonDetails = details; this.authenticatedUser = details.Username != null; this.credentials = new Credentials(); if (authenticatedUser) { if (ConfigStore.TheConfig.SentryData != null && ConfigStore.TheConfig.SentryData.ContainsKey(logonDetails.Username)) { logonDetails.SentryFileHash = Util.SHAHash(ConfigStore.TheConfig.SentryData[logonDetails.Username]); } isLoggingIn = true; } }
private void OnConnected(SteamClient.ConnectedCallback callback) { Console.WriteLine("Connected to Steam! Logging in '{0}'...", username); if (File.Exists("sentry.bin")) { // if we have a saved sentry file, read and sha-1 hash it byte[] sentryFile = File.ReadAllBytes("sentry.bin"); sentryHash = CryptoHelper.SHAHash(sentryFile); } String loginKey = IniModel.GetSteamLoginKey(); SteamUser.LogOnDetails logonDetails = new SteamUser.LogOnDetails(); logonDetails.Username = username; logonDetails.Password = password; logonDetails.LoginKey = loginKey; logonDetails.LoginID = LoginID; logonDetails.AuthCode = authCode; logonDetails.TwoFactorCode = twoFactorAuth; logonDetails.SentryFileHash = sentryHash; logonDetails.ShouldRememberPassword = true; try { steamUser.LogOn(logonDetails); }catch (ArgumentException) { isRunning = false; } }
// TODO: Please remove me immediately after https://github.com/SteamRE/SteamKit/issues/254 gets fixed internal void HackedLogOn(SteamUser.LogOnDetails details) { if (!Client.IsConnected) { return; } SteamID steamID = new SteamID(details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual); ClientMsgProtobuf <CMsgClientLogon> logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon); if (details.LoginID != null) { logon.Body.obfustucated_private_ip = details.LoginID.Value; } logon.ProtoHeader.client_sessionid = 0; logon.ProtoHeader.steamid = steamID.ConvertToUInt64(); logon.Body.account_name = details.Username; logon.Body.password = details.Password; logon.Body.should_remember_password = details.ShouldRememberPassword; logon.Body.protocol_version = MsgClientLogon.CurrentProtocol; logon.Body.client_os_type = (uint)details.ClientOSType; logon.Body.client_language = details.ClientLanguage; logon.Body.cell_id = details.CellID; logon.Body.steam2_ticket_request = details.RequestSteam2Ticket; logon.Body.client_package_version = 1771; logon.Body.auth_code = details.AuthCode; logon.Body.two_factor_code = details.TwoFactorCode; logon.Body.login_key = details.LoginKey; logon.Body.sha_sentryfile = details.SentryFileHash; logon.Body.eresult_sentryfile = (int)(details.SentryFileHash != null ? EResult.OK : EResult.FileNotFound); Client.Send(logon); }
public Steam(Action <bool> OnLogOn, Action <EPurchaseResultDetail, string> OnKeyRedeem) { this.onLogOn = OnLogOn; this.onKeyRedeem = OnKeyRedeem; if (File.Exists("auth.json")) { Program.Context.Log("Using saved auth details."); logOnDetails = JsonConvert.DeserializeObject <SteamUser.LogOnDetails>(File.ReadAllText("auth.json")); } if (logOnDetails.Username != null && (logOnDetails.Password != null || logOnDetails.LoginKey != null)) { EResult logInResult = AttemptLogIn(); if (logInResult == EResult.OK) { loggedOn = true; OnLogOn(true); return; } else { Console.WriteLine(logInResult); } } previousResult = EResult.OK; askForm = new GetLogonDetails(HandleFormResponse); askForm.Show(); }
public Steam3Session(SteamUser.LogOnDetails details) { this.logonDetails = details; this.authenticatedUser = details.Username != null; this.credentials = new Credentials(); this.bConnected = false; this.bConnecting = false; this.bAborted = false; this.bExpectingDisconnectRemote = false; this.bDidDisconnect = false; this.bDidReceiveLoginKey = false; this.seq = 0; this.AppTickets = new Dictionary <uint, byte[]>(); this.AppTokens = new Dictionary <uint, ulong>(); this.DepotKeys = new Dictionary <uint, byte[]>(); this.CDNAuthTokens = new ConcurrentDictionary <string, TaskCompletionSource <SteamApps.CDNAuthTokenCallback> >(); this.AppInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.PackageInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.AppBetaPasswords = new Dictionary <string, byte[]>(); this.steamClient = new SteamClient(); this.steamUser = this.steamClient.GetHandler <SteamUser>(); this.steamApps = this.steamClient.GetHandler <SteamApps>(); var steamUnifiedMessages = this.steamClient.GetHandler <SteamUnifiedMessages>(); this.steamPublishedFile = steamUnifiedMessages.CreateService <IPublishedFile>(); this.callbacks = new CallbackManager(this.steamClient); this.callbacks.Subscribe <SteamClient.ConnectedCallback>(ConnectedCallback); this.callbacks.Subscribe <SteamClient.DisconnectedCallback>(DisconnectedCallback); this.callbacks.Subscribe <SteamUser.LoggedOnCallback>(LogOnCallback); this.callbacks.Subscribe <SteamUser.SessionTokenCallback>(SessionTokenCallback); this.callbacks.Subscribe <SteamApps.LicenseListCallback>(LicenseListCallback); this.callbacks.Subscribe <SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback); this.callbacks.Subscribe <SteamUser.LoginKeyCallback>(LoginKeyCallback); Console.Write("Connecting to Steam3..."); if (authenticatedUser) { FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username)); if (AccountSettingsStore.Instance.SentryData != null && AccountSettingsStore.Instance.SentryData.ContainsKey(logonDetails.Username)) { logonDetails.SentryFileHash = Util.SHAHash(AccountSettingsStore.Instance.SentryData[logonDetails.Username]); } else if (fi.Exists && fi.Length > 0) { var sentryData = File.ReadAllBytes(fi.FullName); logonDetails.SentryFileHash = Util.SHAHash(sentryData); AccountSettingsStore.Instance.SentryData[logonDetails.Username] = sentryData; AccountSettingsStore.Save(); } } Connect(); }
internal FuseClient() { this._Details = new SteamUser.LogOnDetails(); this._Details.ShouldRememberPassword = true; this._Config = SteamConfiguration.Create(builder => { builder.WithConnectionTimeout(TimeSpan.FromMinutes(1)); builder.WithProtocolTypes(ProtocolTypes.WebSocket); }); this._ClientHandler = new SteamClient(this._Config); this._Manager = new CallbackManager(this._ClientHandler); this._UserHandler = this._ClientHandler.GetHandler <SteamUser>(); this._FriendsHandler = this._ClientHandler.GetHandler <SteamFriends>(); this._AppsHandler = this._ClientHandler.GetHandler <SteamKit2.SteamApps>(); this._User = new FuseUser(this._FriendsHandler); this._UI = new FuseUI(this); this._StoredApps = null; this._CallbackThread = new Thread(AwaitCallbackResults); this._CallbackThread.Start(); this._Manager.Subscribe <SteamClient.ConnectedCallback>(this.OnConnected); this._Manager.Subscribe <SteamClient.DisconnectedCallback>(this.OnDisconnected); this._Manager.Subscribe <SteamUser.LoggedOnCallback>(this.OnLoggedOn); this._Manager.Subscribe <SteamUser.LoginKeyCallback>(this.OnLoginKey); this._Manager.Subscribe <SteamUser.AccountInfoCallback>(this.OnAccountInfo); this._Manager.Subscribe <SteamFriends.PersonaStateCallback>(this.OnFriendPersonaStateChange); this._Manager.Subscribe <SteamFriends.FriendMsgCallback>(this.OnFriendMessage); this._Manager.Subscribe <SteamFriends.FriendMsgEchoCallback>(this.OnFriendMessageEcho); }
public void LoginAs(SteamUser.LogOnDetails details) { SetLoginDetails(details); DebugLog.WriteLine("Steam3Session", "Connecting to Steam3..."); Connect(); }
/* * __ __ _ _ _ | \/ | ___ | |_ | |__ ___ __| | ___ | |\/| | / _ \| __|| '_ \ / _ \ / _` |/ __| | | | || __/| |_ | | | || (_) || (_| |\__ \ |_| |_| \___| \__||_| |_| \___/ \__,_||___/ | */ // TODO: Remove me once https://github.com/SteamRE/SteamKit/issues/305 is fixed internal void LogOnWithoutMachineID(SteamUser.LogOnDetails details) { if (details == null) { throw new ArgumentNullException(nameof(details)); } if (string.IsNullOrEmpty(details.Username) || (string.IsNullOrEmpty(details.Password) && string.IsNullOrEmpty(details.LoginKey))) { throw new ArgumentException("LogOn requires a username and password to be set in 'details'."); } if (!string.IsNullOrEmpty(details.LoginKey) && !details.ShouldRememberPassword) { // Prevent consumers from screwing this up. // If should_remember_password is false, the login_key is ignored server-side. // The inverse is not applicable (you can log in with should_remember_password and no login_key). throw new ArgumentException("ShouldRememberPassword is required to be set to true in order to use LoginKey."); } ClientMsgProtobuf <CMsgClientLogon> logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon); SteamID steamId = new SteamID(details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual); if (details.LoginID.HasValue) { logon.Body.obfustucated_private_ip = details.LoginID.Value; } logon.ProtoHeader.client_sessionid = 0; logon.ProtoHeader.steamid = steamId.ConvertToUInt64(); logon.Body.account_name = details.Username; logon.Body.password = details.Password; logon.Body.should_remember_password = details.ShouldRememberPassword; logon.Body.protocol_version = MsgClientLogon.CurrentProtocol; logon.Body.client_os_type = (uint)details.ClientOSType; logon.Body.client_language = details.ClientLanguage; logon.Body.cell_id = details.CellID; logon.Body.steam2_ticket_request = details.RequestSteam2Ticket; logon.Body.client_package_version = 1771; logon.Body.supports_rate_limit_response = true; // steam guard logon.Body.auth_code = details.AuthCode; logon.Body.two_factor_code = details.TwoFactorCode; logon.Body.login_key = details.LoginKey; logon.Body.sha_sentryfile = details.SentryFileHash; logon.Body.eresult_sentryfile = (int)(details.SentryFileHash != null ? EResult.OK : EResult.FileNotFound); Client.Send(logon); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; BackpackUrl = config.Backpack; sNumberTradeFile = config.TradeNumberSaveFile; this.apiKey = apiKey; this.isprocess = process; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log(config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; dReserved = new Dictionary <ulong, SteamID>(); dDonated = new Dictionary <ulong, SteamID>(); log.Debug("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler <SteamGameCoordinator>(); craftHandler = new CraftingHandler(this); informHandler = new InformHandler(this, BotControlClass.Substring(9)); AdvertiseHandler = new AdvertiseHandler(this, BotControlClass.Substring(9), clsFunctions.BotGroup); backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; if (!Directory.Exists(FriendsFolder)) { Directory.CreateDirectory(FriendsFolder); } this.FriendActivity = FriendActivity.LoadFriendActivity(FriendsFolder + logOnDetails.Username + ".json"); backgroundWorker.DoWork += BackgroundWorkerOnDoWork; backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
public void LogOn() { var logDetails = new SteamUser.LogOnDetails(); logDetails.Username = Credentials.Username; logDetails.Password = Credentials.Password; Logger.WriteLine("Logging in to the Steam network..."); SteamUser.LogOn(logDetails); }
public SteamInterface() { string user = config["username"].ToString(); string pass = config["password"].ToString(); bool shouldrememberpass = (bool)config["ShouldRememberPassword"]; SteamBotData SteamBotLoginData = new SteamBotData(user, pass, shouldrememberpass); LoginData = SteamBotLoginData.LoginData; ResetConnection(SteamBotLoginData); }
public BotControlForm(Configuration.BotInfo config, string apiKey, bool debug = false) { InitializeComponent(); foreach (EPersonaState state in Enum.GetValues(typeof(EPersonaState))) { this.cbxPersonaState.Items.Add(state); } SetStatus("Setting variables..."); logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; this.apiKey = apiKey; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log(config.LogFile, this.DisplayName, LogLevel); //CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); SetStatus("Connecting to Steam..."); SteamClient.Connect(); masterThread = new Thread(this.pollSteam); masterThread.Start(); }
public Steam3Session(SteamUser.LogOnDetails details) { this.logonDetails = details; this.authenticatedUser = details.Username != null; this.credentials = new Credentials(); this.bConnected = false; this.bConnecting = false; this.bAborted = false; this.seq = 0; this.AppTickets = new Dictionary <uint, byte[]>(); this.AppTokens = new Dictionary <uint, ulong>(); this.DepotKeys = new Dictionary <uint, byte[]>(); this.CDNAuthTokens = new ConcurrentDictionary <string, SteamApps.CDNAuthTokenCallback>(); this.AppInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.PackageInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.AppBetaPasswords = new Dictionary <string, byte[]>(); this.steamClient = new SteamClient(); this.steamUser = this.steamClient.GetHandler <SteamUser>(); this.steamApps = this.steamClient.GetHandler <SteamApps>(); this.callbacks = new CallbackManager(this.steamClient); this.callbacks.Subscribe <SteamClient.ConnectedCallback>(ConnectedCallback); this.callbacks.Subscribe <SteamClient.DisconnectedCallback>(DisconnectedCallback); this.callbacks.Subscribe <SteamUser.LoggedOnCallback>(LogOnCallback); this.callbacks.Subscribe <SteamUser.SessionTokenCallback>(SessionTokenCallback); this.callbacks.Subscribe <SteamApps.LicenseListCallback>(LicenseListCallback); this.callbacks.Subscribe <SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback); this.callbacks.Subscribe <SteamUser.LoginKeyCallback>(LoginKeyCallback); Logger.Info("Connecting to Steam3..."); if (authenticatedUser) { FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username)); if (ConfigStore.TheConfig.SentryData != null && ConfigStore.TheConfig.SentryData.ContainsKey(logonDetails.Username)) { logonDetails.SentryFileHash = Util.SHAHash(ConfigStore.TheConfig.SentryData[logonDetails.Username]); } else if (fi.Exists && fi.Length > 0) { var sentryData = File.ReadAllBytes(fi.FullName); logonDetails.SentryFileHash = Util.SHAHash(sentryData); ConfigStore.TheConfig.SentryData[logonDetails.Username] = sentryData; ConfigStore.Save(); } } Connect(); }
void OnConnected(SteamClient.ConnectedCallback pData) { Console.WriteLine("Connected to Steam! Logging in '{0}'...", GetConfigValue("username")); SteamUser.LogOnDetails details = new SteamUser.LogOnDetails { Username = GetConfigValue("username"), Password = GetConfigValue("password"), }; m_SteamUser.LogOn(details); m_SteamID = m_SteamClient.SteamID; }
public SteamBotData(string user, string pass, bool shouldrememberpass) { LoginData = new SteamUser.LogOnDetails(); LoginData.Password = pass; LoginData.Username = user; LoginData.ShouldRememberPassword = shouldrememberpass; SavedUsername = user; SavedPassword = pass; }
public void LogOn(string userName, string userPassword) { SteamUser.LogOnDetails userDetails = new SteamUser.LogOnDetails(); userDetails.Username = userName; userDetails.Password = userPassword; user.LogOn(userDetails); while (!loggedOn) { manager.RunWaitCallbacks(TimeSpan.FromMilliseconds(100)); } }
public SteamUserFixture(SteamUser.LogOnDetails logOnDetails) { this.logOnDetails = logOnDetails; Friends = Client.GetHandler <SteamFriends>(); Matchmaking = Client.GetHandler <SteamMatchmaking>(); User = Client.GetHandler <SteamUser>(); CallbackManager = new CallbackManager(Client); CallbackManager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff); CallbackManager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; SchemaLang = config.SchemaLang != null && config.SchemaLang.Length == 2 ? config.SchemaLang.ToLower() : "en"; Admins = config.Admins; this.ApiKey = !String.IsNullOrEmpty(config.ApiKey) ? config.ApiKey : apiKey; this.isprocess = process; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log(config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; SteamWeb = new SteamWeb(); // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamClient.AddHandler(new SteamNotifications()); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler <SteamGameCoordinator>(); SteamNotifications = SteamClient.GetHandler <SteamNotifications>(); backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; backgroundWorker.DoWork += BackgroundWorkerOnDoWork; backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
public void Login(string username, string password, string authCode) { client.Connect(); var callback = client.WaitForCallback(); var connect = callback as ConnectCallback; if (connect == null || connect.Result != EResult.OK) { Fatal("Connection failed"); return; } var credentials = new SteamUser.LogOnDetails { Username = username, Password = password, AuthCode = authCode, }; user.LogOn(credentials); callback = client.WaitForCallback(); LogOnCallback login = callback as LogOnCallback; if (login == null) { Fatal("Login failed"); return; } else { switch (login.Result) { case EResult.OK: break; case EResult.AccountLogonDenied: case EResult.AccountLogonDeniedNoMailSent: Fatal("Steam guard authentication needed"); return; default: Fatal("Login failed"); return; } } foreach (var friend in friends.GetFriends()) { NotifyAddedBuddy(friend); } }
public Task <SteamUser.LoggedOnCallback> LoginAsync(SteamUser.LogOnDetails logOnDetails) { _loginTaskCompletionSource = new TaskCompletionSource <SteamUser.LoggedOnCallback>(); Task.Run(() => { _lastLoginDetails = logOnDetails; if (_applicationSettingsService.Settings.SentryHashStore != null && _applicationSettingsService.Settings.SentryHashStore.ContainsKey(logOnDetails.Username)) { logOnDetails.SentryFileHash = _applicationSettingsService.Settings.SentryHashStore[logOnDetails.Username]; } _steamUser.LogOn(logOnDetails); }); ThrowIfTimeout(_loginTaskCompletionSource); return(_loginTaskCompletionSource.Task); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, Interface gui, bool debug = false) { while (Interface.loginClicked == false) { // Wait for user to login } logOnDetails = new SteamUser.LogOnDetails { Username = Interface.username, Password = Interface.password }; Admins = new ulong[1]; Admins[0] = 123456789; this.apiKey = apiKey; LogLevel = Log.LogLevel.Info; //log = new Log(config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; ////log.Debug("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); gui.UpdateLog("\r\nConnecting, please wait..."); ////log.Info("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback(true); HandleSteamMessage(msg, gui); } }); CallbackThread.Start(); ////log.Success("Done Loading Bot!"); CallbackThread.Join(); }
private void OnSteamConnected(SteamClient.ConnectedCallback data) { var user = Client.GetHandler <SteamUser>(); var sentryHash = SteamSentryManager.GetSentryHash(State.Username); var loginKey = SteamSentryManager.GetLoginKey(State.Username); var logonDetails = new SteamUser.LogOnDetails() { Username = State.Username, Password = State.Password, AuthCode = State.RequiresAuthCode && !requiresTwoFactorCode ? State.AuthCode : null, TwoFactorCode = State.RequiresAuthCode && requiresTwoFactorCode ? State.AuthCode : null, ShouldRememberPassword = State.RememberLogin, SentryFileHash = sentryHash, LoginKey = State.RememberLogin ? loginKey : null, LoginID = 1891 // Can be any integer, as long as it's unique per application }; user.LogOn(logonDetails); }
public Steam3Session(SteamUser.LogOnDetails details) { this.logonDetails = details; this.authenticatedUser = details.Username != null; this.credentials = new Credentials(); this.bConnected = false; this.bAborted = false; this.AppTickets = new Dictionary <uint, byte[]>(); this.AppTokens = new Dictionary <uint, ulong>(); this.DepotKeys = new Dictionary <uint, byte[]>(); this.AppInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.PackageInfo = new Dictionary <uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.AppInfoOverridesCDR = new Dictionary <uint, bool>(); this.steamClient = new SteamClient(); this.steamUser = this.steamClient.GetHandler <SteamUser>(); this.steamApps = this.steamClient.GetHandler <SteamApps>(); this.callbacks = new CallbackManager(this.steamClient); this.callbacks.Register(new Callback <SteamClient.ConnectedCallback>(ConnectedCallback)); this.callbacks.Register(new Callback <SteamClient.DisconnectedCallback>(DisconnectedCallback)); this.callbacks.Register(new Callback <SteamUser.LoggedOnCallback>(LogOnCallback)); this.callbacks.Register(new Callback <SteamUser.SessionTokenCallback>(SessionTokenCallback)); this.callbacks.Register(new Callback <SteamApps.LicenseListCallback>(LicenseListCallback)); this.callbacks.Register(new JobCallback <SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback)); Console.Write("Connecting to Steam3..."); if (authenticatedUser) { FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username)); if (fi.Exists && fi.Length > 0) { logonDetails.SentryFileHash = Util.SHAHash(File.ReadAllBytes(fi.FullName)); } } Connect(); }
private void onConnected(SteamClient.ConnectedCallback callback) { byte[] sentryHash = null; if (File.Exists(SteamChatCore.DIR + "\\sentry.bin")) { // if we have a saved sentry file, read and SHA1 hash it byte[] sentryFile = File.ReadAllBytes(SteamChatCore.DIR + "\\sentry.bin"); sentryHash = CryptoHelper.SHAHash(sentryFile); } SteamUser.LogOnDetails logonDetails = new SteamUser.LogOnDetails { Username = this.idTextBox.Text, Password = this.pwTextBox.Text, LoginID = (uint)this.core.Steam.SteamClient.GetHashCode(), SentryFileHash = sentryHash, }; if (this.is2FA) { logonDetails.TwoFactorCode = this.steamGuardTextBox.Text; } else { logonDetails.AuthCode = this.steamGuardTextBox.Text; } try { this.core.Steam.SteamUser.LogOn(logonDetails); } catch (Exception e) { this.setMessageText(e.ToString()); } if (callback.Result == EResult.OK) { this.setMessageText("Connect to Steam..."); } else { this.setMessageText("Unable to connect to Steam" + callback.Result); } }
private Task <EResult> Login() { var taskCompletionSource = TaskHelper.CreateTaskCompletionSourceWithTimeout <EResult>(myWaitTimeInMilliseconds); if (!mySteamClient.IsConnected) { myLogger.LogCritical("Steam client wasn't connected while trying to login. How?"); taskCompletionSource.SetException(new GameCoordinatorException("Steam client wasn't connected while trying to login. How?")); return(taskCompletionSource.Task); } if (mySteamClient.SessionID != null) { taskCompletionSource.SetResult(EResult.OK); } else { var loggedOnCallbackRegistration = myCallbackManager.Subscribe <SteamUser.LoggedOnCallback>((callback) => { myLogger.LogTrace("Log on result: {callBackResult}", callback.Result); taskCompletionSource.SetResult(callback.Result); }); myRegisteredCallbacks.Add(CallbackType.LoggedOn, loggedOnCallbackRegistration); var steamCredentials = new SteamUser.LogOnDetails { Username = Settings.SteamUsername, Password = Settings.SteamPassword }; try { mySteamUser.LogOn(steamCredentials); } catch (ArgumentException) { myLogger.LogCritical("You need to provide a Steam account via the environment variables STEAM_USERNAME and STEAM_PASSWORD"); taskCompletionSource.SetException(new Exception("No steam account provided via environment variables STEAM_USERNAME and STEAM_PASSWORD")); } } return(taskCompletionSource.Task); }
protected static SteamUser.LogOnDetails ReadCredentials(string userPrefix) { try { var s = Path.DirectorySeparatorChar; DotNetEnv.Env.Load($"..{s}..{s}..{s}.env"); } catch (Exception) { // '.env' files are only used during development, and they're optional. } var logOnDetails = new SteamUser.LogOnDetails { Username = Environment.GetEnvironmentVariable($"{userPrefix}_STEAM_USER"), ShouldRememberPassword = true, }; if (logOnDetails.Username == null) { throw new Exception($"The {userPrefix}_STEAM_USER environment variable must be specified"); } logOnDetails.LoginKey = Environment.GetEnvironmentVariable($"{userPrefix}_STEAM_KEY"); if (logOnDetails.LoginKey == null) { logOnDetails.Password = Environment.GetEnvironmentVariable($"{userPrefix}_STEAM_PASSWORD"); if (logOnDetails.Password == null) { throw new Exception($"Either the {userPrefix}_STEAM_KEY or {userPrefix}_STEAM_PASSWORD environment variable must be specified"); } logOnDetails.TwoFactorCode = Environment.GetEnvironmentVariable($"{userPrefix}_STEAM_GUARD_CODE"); } return(logOnDetails); }
public Task <bool> LoginAsAsync(SteamUser.LogOnDetails details) { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); LoggedOnHandler loggedOnCallback = null; LogonFailedHandler logonFailedCallback = null; ConnectedHandler disconnectedCallback = null; loggedOnCallback = () => { tcs.SetResult(true); onLoggedOn -= loggedOnCallback; onLogonFailed -= logonFailedCallback; onDisconnected -= disconnectedCallback; }; logonFailedCallback = (result) => { tcs.SetResult(false); onLogonFailed -= logonFailedCallback; onLoggedOn -= loggedOnCallback; onDisconnected -= disconnectedCallback; }; disconnectedCallback = () => { tcs.SetResult(false); onDisconnected -= disconnectedCallback; onLoggedOn -= loggedOnCallback; onLogonFailed -= logonFailedCallback; }; onLoggedOn += loggedOnCallback; onLogonFailed += logonFailedCallback; onDisconnected += disconnectedCallback; SetLoginDetails(details); DebugLog.WriteLine("Steam3Session", "Connecting to Steam3..."); Connect(); return(tcs.Task); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { userHandlers = new Dictionary <SteamID, UserHandler>(); logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; tradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; schemaLang = config.SchemaLang != null && config.SchemaLang.Length == 2 ? config.SchemaLang.ToLower() : "en"; Admins = config.Admins; ApiKey = !String.IsNullOrEmpty(config.ApiKey) ? config.ApiKey : apiKey; isProccess = process; try { if (config.LogLevel != null) { consoleLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); Console.WriteLine(@"(Console) LogLevel configuration parameter used in bot {0} is depreciated and may be removed in future versions. Please use ConsoleLogLevel instead.", DisplayName); } else { consoleLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.ConsoleLogLevel, true); } } catch (ArgumentException) { Console.WriteLine(@"(Console) ConsoleLogLevel invalid or unspecified for bot {0}. Defaulting to ""Info""", DisplayName); consoleLogLevel = Log.LogLevel.Info; } try { fileLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.FileLogLevel, true); } catch (ArgumentException) { Console.WriteLine(@"(Console) FileLogLevel invalid or unspecified for bot {0}. Defaulting to ""Info""", DisplayName); fileLogLevel = Log.LogLevel.Info; } logFile = config.LogFile; CreateLog(); createHandler = handlerCreator; BotControlClass = config.BotControlClass; SteamWeb = new SteamWeb(); // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; Log.Debug("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamClient.AddHandler(new SteamNotifications()); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler <SteamGameCoordinator>(); SteamNotifications = SteamClient.GetHandler <SteamNotifications>(); botThread = new BackgroundWorker { WorkerSupportsCancellation = true }; botThread.DoWork += BackgroundWorkerOnDoWork; botThread.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; botThread.RunWorkerAsync(); }
/// <summary> /// Create a new game bot /// </summary> /// <param name="details">Auth info</param> /// <param name="reconnectDelay"> /// Delay between reconnection attempts to steam, set to a negative value to disable /// reconnecting /// </param> /// <param name="contrs">Game controllers</param> public DotaBot(SteamUser.LogOnDetails details, double reconnectDelay = 2000) { log = LogManager.GetLogger("Bot " + details.Username); log.Debug("Initializing a new LobbyBot w/username " + details.Username); _logonDetails = details; if (reconnectDelay < 0) { reconnectDelay = 10; _shouldReconnect = false; } _reconnectTimer = new Timer(reconnectDelay); _reconnectTimer.Elapsed += (sender, args) => _state.Fire(Trigger.ConnectRequested); _state = new StateMachine <State, Trigger>(State.SignedOff); _state.OnTransitioned((transition => { log.DebugFormat("{0} => {1}", transition.Source.ToString("G"), transition.Destination.ToString("G")); StateTransitioned?.Invoke(this, transition); })); _state.Configure(State.Conceived) .Permit(Trigger.ShutdownRequested, State.SignedOff); _state.Configure(State.SignedOff) .SubstateOf(State.Conceived) .Ignore(Trigger.SteamDisconnected) .OnEntryFrom(Trigger.SteamInvalidCreds, () => InvalidCreds?.Invoke(this, EventArgs.Empty)) .PermitIf(Trigger.ConnectRequested, State.Steam, () => _isRunning); _state.Configure(State.RetryConnection) .SubstateOf(State.SignedOff) .OnExit(() => _reconnectTimer.Stop()) .OnEntry(() => _reconnectTimer.Start()) .Permit(Trigger.ConnectRequested, State.Steam); _state.Configure(State.Steam) .SubstateOf(State.Conceived) .Permit(Trigger.SteamConnected, State.Dota) .PermitDynamic(Trigger.SteamDisconnected, () => _shouldReconnect ? State.RetryConnection : State.SignedOff) .Permit(Trigger.SteamInvalidCreds, State.SignedOff) .OnEntry(StartSteamConnection) .OnExit(ReleaseSteamConnection); _state.Configure(State.Dota) .SubstateOf(State.Steam) .Permit(Trigger.DotaConnected, State.DotaMenu) .PermitReentry(Trigger.DotaDisconnected) .Permit(Trigger.DotaEnteredLobbyUI, State.DotaLobby) .Permit(Trigger.DotaEnteredLobbyPlay, State.DotaPlay) .OnEntryFrom(Trigger.SteamConnected, StartDotaGCConnection); _state.Configure(State.DotaMenu) .SubstateOf(State.Dota) .Permit(Trigger.DotaEnteredLobbyUI, State.DotaLobby) .Permit(Trigger.DotaEnteredLobbyPlay, State.DotaPlay); _state.Configure(State.DotaLobby) .SubstateOf(State.Dota) .Ignore(Trigger.DotaEnteredLobbyUI) .Permit(Trigger.DotaEnteredLobbyPlay, State.DotaPlay) .Permit(Trigger.DotaNoLobby, State.DotaMenu) .OnEntry(JoinLobbySlot) .OnEntry(JoinLobbyChat) .OnExit(LeaveLobbyChat); _state.Configure(State.DotaPlay) .SubstateOf(State.Dota) .Ignore(Trigger.DotaEnteredLobbyPlay) .Permit(Trigger.DotaEnteredLobbyUI, State.DotaLobby) .Permit(Trigger.DotaNoLobby, State.DotaMenu); }
public Bot(Configuration.BotInfo config, Log log, string apiKey, UserHandlerCreator handlerCreator, Login _login, bool debug = false) { this.main = _login; logOnDetails = new SteamUser.LogOnDetails { Username = _login.Username, Password = _login.Password }; ChatResponse = ""; TradePollingInterval = 50; Admins = new ulong[1]; Admins[0] = 123456789; this.apiKey = apiKey; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), "Debug", true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } this.log = log; CreateHandler = handlerCreator; BotControlClass = "SteamBot.SimpleUserHandler"; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug("Initializing Steam account..."); main.Invoke((Action)(() => { main.label_status.Text = "Initializing Steam account..."; })); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); log.Info("Connecting..."); main.Invoke((Action)(() => { main.label_status.Text = "Connecting to Steam..."; })); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback(true); HandleSteamMessage(msg); } }); CallbackThread.Start(); CallbackThread.Join(); log.Success("Done loading account!"); main.Invoke((Action)(() => { main.label_status.Text = "Done loading account!"; })); }