internal Bot(string botName) { if (string.IsNullOrEmpty(botName)) { throw new ArgumentNullException(nameof(botName)); } if (Bots.ContainsKey(botName)) { throw new Exception("That bot is already defined!"); } string botPath = Path.Combine(Program.ConfigDirectory, botName); BotName = botName; SentryFile = botPath + ".bin"; BotConfig = BotConfig.Load(botPath + ".json"); if (BotConfig == null) { Logging.LogGenericError("Your bot config is invalid, refusing to start this bot instance!", botName); return; } if (!BotConfig.Enabled) { Logging.LogGenericInfo("Not initializing this instance because it's disabled in config file", botName); return; } BotDatabase = BotDatabase.Load(botPath + ".db"); if (BotDatabase == null) { Logging.LogGenericError("Bot database could not be loaded, refusing to start this bot instance!", botName); return; } // TODO: Converter code will be removed soon if (BotDatabase.SteamGuardAccount != null) { Logging.LogGenericWarning("Converting old ASF 2FA V2.0 format into new ASF 2FA V2.1 format...", botName); BotDatabase.MobileAuthenticator = MobileAuthenticator.LoadFromSteamGuardAccount(BotDatabase.SteamGuardAccount); Logging.LogGenericInfo("Done! If you didn't make a copy of your revocation code yet, then it's a good moment to do so: " + BotDatabase.SteamGuardAccount.RevocationCode, botName); Logging.LogGenericWarning("ASF will not keep this code anymore!", botName); BotDatabase.SteamGuardAccount = null; } if (BotDatabase.MobileAuthenticator != null) { BotDatabase.MobileAuthenticator.Init(this); } else { // Support and convert SDA files string maFilePath = botPath + ".maFile"; if (File.Exists(maFilePath)) { ImportAuthenticator(maFilePath); } } // Initialize SteamClient = new SteamClient(Program.GlobalConfig.SteamProtocol); if (Program.GlobalConfig.Debug && !Debugging.NetHookAlreadyInitialized && Directory.Exists(Program.DebugDirectory)) { try { Debugging.NetHookAlreadyInitialized = true; SteamClient.DebugNetworkListener = new NetHookNetworkListener(Program.DebugDirectory); } catch (Exception e) { Logging.LogGenericException(e, botName); } } ArchiHandler = new ArchiHandler(this); SteamClient.AddHandler(ArchiHandler); CallbackManager = new CallbackManager(SteamClient); CallbackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnected); CallbackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected); SteamApps = SteamClient.GetHandler<SteamApps>(); CallbackManager.Subscribe<SteamApps.FreeLicenseCallback>(OnFreeLicense); CallbackManager.Subscribe<SteamApps.GuestPassListCallback>(OnGuestPassList); SteamFriends = SteamClient.GetHandler<SteamFriends>(); CallbackManager.Subscribe<SteamFriends.ChatInviteCallback>(OnChatInvite); CallbackManager.Subscribe<SteamFriends.ChatMsgCallback>(OnChatMsg); CallbackManager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList); CallbackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnFriendMsg); CallbackManager.Subscribe<SteamFriends.FriendMsgHistoryCallback>(OnFriendMsgHistory); SteamUser = SteamClient.GetHandler<SteamUser>(); CallbackManager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo); CallbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff); CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn); CallbackManager.Subscribe<SteamUser.LoginKeyCallback>(OnLoginKey); CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); CallbackManager.Subscribe<SteamUser.WebAPIUserNonceCallback>(OnWebAPIUserNonce); CallbackManager.Subscribe<ArchiHandler.NotificationsCallback>(OnNotifications); CallbackManager.Subscribe<ArchiHandler.OfflineMessageCallback>(OnOfflineMessage); CallbackManager.Subscribe<ArchiHandler.PlayingSessionStateCallback>(OnPlayingSessionState); CallbackManager.Subscribe<ArchiHandler.PurchaseResponseCallback>(OnPurchaseResponse); ArchiWebHandler = new ArchiWebHandler(this); CardsFarmer = new CardsFarmer(this); Trading = new Trading(this); if ((AcceptConfirmationsTimer == null) && (BotConfig.AcceptConfirmationsPeriod > 0)) { AcceptConfirmationsTimer = new Timer( async e => await AcceptConfirmations(true).ConfigureAwait(false), null, TimeSpan.FromMinutes(BotConfig.AcceptConfirmationsPeriod), // Delay TimeSpan.FromMinutes(BotConfig.AcceptConfirmationsPeriod) // Period ); } if ((SendItemsTimer == null) && (BotConfig.SendTradePeriod > 0)) { SendItemsTimer = new Timer( async e => await ResponseLoot(BotConfig.SteamMasterID).ConfigureAwait(false), null, TimeSpan.FromHours(BotConfig.SendTradePeriod), // Delay TimeSpan.FromHours(BotConfig.SendTradePeriod) // Period ); } // Register bot as available for ASF Bots[botName] = this; if (!BotConfig.StartOnLaunch) { return; } // Start Start().Forget(); }
internal Bot(string botName) { if (string.IsNullOrEmpty(botName)) { throw new ArgumentNullException(nameof(botName)); } if (Bots.ContainsKey(botName)) { throw new ArgumentException("That bot is already defined!"); } string botPath = Path.Combine(SharedInfo.ConfigDirectory, botName); BotName = botName; SentryFile = botPath + ".bin"; string botConfigFile = botPath + ".json"; BotConfig = BotConfig.Load(botConfigFile); if (BotConfig == null) { Logging.LogGenericError("Your bot config is invalid, please verify content of " + botConfigFile + " and try again!", botName); return; } // Register bot as available for ASF if (!Bots.TryAdd(botName, this)) { throw new ArgumentException("That bot is already defined!"); } string botDatabaseFile = botPath + ".db"; BotDatabase = BotDatabase.Load(botDatabaseFile); if (BotDatabase == null) { Logging.LogGenericError("Bot database could not be loaded, refusing to create this bot instance! In order to recreate it, remove " + botDatabaseFile + " and try again!", botName); return; } if (BotDatabase.MobileAuthenticator != null) { BotDatabase.MobileAuthenticator.Init(this); } else { // Support and convert SDA files string maFilePath = botPath + ".maFile"; if (File.Exists(maFilePath)) { ImportAuthenticator(maFilePath); } } // Initialize SteamClient = new SteamClient(Program.GlobalConfig.SteamProtocol); if (Program.GlobalConfig.Debug && Directory.Exists(SharedInfo.DebugDirectory)) { string debugListenerPath = Path.Combine(SharedInfo.DebugDirectory, botName); try { Directory.CreateDirectory(debugListenerPath); SteamClient.DebugNetworkListener = new NetHookNetworkListener(debugListenerPath); } catch (Exception e) { Logging.LogGenericException(e, botName); } } ArchiHandler = new ArchiHandler(this); SteamClient.AddHandler(ArchiHandler); CallbackManager = new CallbackManager(SteamClient); CallbackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnected); CallbackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected); SteamApps = SteamClient.GetHandler<SteamApps>(); CallbackManager.Subscribe<SteamApps.FreeLicenseCallback>(OnFreeLicense); CallbackManager.Subscribe<SteamApps.GuestPassListCallback>(OnGuestPassList); CallbackManager.Subscribe<SteamApps.LicenseListCallback>(OnLicenseList); SteamFriends = SteamClient.GetHandler<SteamFriends>(); CallbackManager.Subscribe<SteamFriends.ChatInviteCallback>(OnChatInvite); CallbackManager.Subscribe<SteamFriends.ChatMsgCallback>(OnChatMsg); CallbackManager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList); CallbackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnFriendMsg); CallbackManager.Subscribe<SteamFriends.FriendMsgHistoryCallback>(OnFriendMsgHistory); CallbackManager.Subscribe<SteamFriends.PersonaStateCallback>(OnPersonaState); SteamUser = SteamClient.GetHandler<SteamUser>(); CallbackManager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo); CallbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff); CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn); CallbackManager.Subscribe<SteamUser.LoginKeyCallback>(OnLoginKey); CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); CallbackManager.Subscribe<SteamUser.WebAPIUserNonceCallback>(OnWebAPIUserNonce); CallbackManager.Subscribe<ArchiHandler.NotificationsCallback>(OnNotifications); CallbackManager.Subscribe<ArchiHandler.OfflineMessageCallback>(OnOfflineMessage); CallbackManager.Subscribe<ArchiHandler.PlayingSessionStateCallback>(OnPlayingSessionState); CallbackManager.Subscribe<ArchiHandler.PurchaseResponseCallback>(OnPurchaseResponse); CallbackManager.Subscribe<ArchiHandler.SharedLibraryLockStatusCallback>(OnSharedLibraryLockStatus); ArchiWebHandler = new ArchiWebHandler(this); CardsFarmer = new CardsFarmer(this) { Paused = BotConfig.Paused }; Trading = new Trading(this); HeartBeatTimer = new Timer( async e => await HeartBeat().ConfigureAwait(false), null, TimeSpan.FromMinutes(1) + TimeSpan.FromMinutes(0.2 * Bots.Count), // Delay TimeSpan.FromMinutes(1) // Period ); Initialize().Forget(); }
internal Bot(string botName) { if (string.IsNullOrEmpty(botName)) { throw new ArgumentNullException("botName"); } BotName = botName; string botPath = Path.Combine(Program.ConfigDirectory, botName); BotConfig = BotConfig.Load(botPath + ".json"); if (BotConfig == null) { Logging.LogGenericError("Your bot config is invalid, refusing to start this bot instance!", botName); return; } if (!BotConfig.Enabled) { return; } BotDatabase = BotDatabase.Load(botPath + ".db"); if (BotDatabase == null) { Logging.LogGenericError("Bot database could not be loaded, refusing to start this bot instance!", botName); return; } bool alreadyExists; lock (Bots) { alreadyExists = Bots.ContainsKey(botName); if (!alreadyExists) { Bots[botName] = this; } } if (alreadyExists) { return; } SentryFile = botPath + ".bin"; if (BotDatabase.SteamGuardAccount == null) { // Support and convert SDA files string maFilePath = botPath + ".maFile"; if (File.Exists(maFilePath)) { ImportAuthenticator(maFilePath); } } // Initialize SteamClient = new SteamClient(Program.GlobalConfig.SteamProtocol); if (Program.GlobalConfig.Debug && !Debugging.NetHookAlreadyInitialized && Directory.Exists(Program.DebugDirectory)) { try { SteamClient.DebugNetworkListener = new NetHookNetworkListener(Program.DebugDirectory); Debugging.NetHookAlreadyInitialized = true; } catch (Exception e) { Logging.LogGenericException(e, botName); } } ArchiHandler = new ArchiHandler(this); SteamClient.AddHandler(ArchiHandler); CallbackManager = new CallbackManager(SteamClient); CallbackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnected); CallbackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected); SteamApps = SteamClient.GetHandler<SteamApps>(); CallbackManager.Subscribe<SteamApps.FreeLicenseCallback>(OnFreeLicense); CallbackManager.Subscribe<SteamApps.GuestPassListCallback>(OnGuestPassList); SteamFriends = SteamClient.GetHandler<SteamFriends>(); CallbackManager.Subscribe<SteamFriends.ChatInviteCallback>(OnChatInvite); CallbackManager.Subscribe<SteamFriends.ChatMsgCallback>(OnChatMsg); CallbackManager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList); CallbackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnFriendMsg); CallbackManager.Subscribe<SteamFriends.FriendMsgHistoryCallback>(OnFriendMsgHistory); SteamUser = SteamClient.GetHandler<SteamUser>(); CallbackManager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo); CallbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff); CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn); CallbackManager.Subscribe<SteamUser.LoginKeyCallback>(OnLoginKey); CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); CallbackManager.Subscribe<SteamUser.WebAPIUserNonceCallback>(OnWebAPIUserNonce); CallbackManager.Subscribe<ArchiHandler.NotificationsCallback>(OnNotifications); CallbackManager.Subscribe<ArchiHandler.OfflineMessageCallback>(OnOfflineMessage); CallbackManager.Subscribe<ArchiHandler.PurchaseResponseCallback>(OnPurchaseResponse); ArchiWebHandler = new ArchiWebHandler(this); CardsFarmer = new CardsFarmer(this); Trading = new Trading(this); if (AcceptConfirmationsTimer == null && BotConfig.AcceptConfirmationsPeriod > 0) { AcceptConfirmationsTimer = new Timer( async e => await AcceptConfirmations(true).ConfigureAwait(false), null, TimeSpan.FromMinutes(BotConfig.AcceptConfirmationsPeriod), // Delay TimeSpan.FromMinutes(BotConfig.AcceptConfirmationsPeriod) // Period ); } if (SendItemsTimer == null && BotConfig.SendTradePeriod > 0) { SendItemsTimer = new Timer( async e => await ResponseSendTrade(BotConfig.SteamMasterID).ConfigureAwait(false), null, TimeSpan.FromHours(BotConfig.SendTradePeriod), // Delay TimeSpan.FromHours(BotConfig.SendTradePeriod) // Period ); } if (!BotConfig.StartOnLaunch) { return; } // Start Start().Forget(); }