/// <summary> /// Setup a new bot with some details. /// </summary> /// <param name="details"></param> /// <param name="extensions">any extensions you want on the state machine.</param> public LobbyBot(SteamUser.LogOnDetails details, params IExtension<States, Events>[] extensions) { reconnect = true; this.details = details; log = LogManager.GetLogger("LobbyBot " + details.Username); log.Debug("Initializing a new LobbyBot, username: " + details.Username); reconnectTimer.Elapsed += (sender, args) => { reconnectTimer.Stop(); fsm.Fire(Events.AttemptReconnect); }; fsm = new ActiveStateMachine<States, Events>(); foreach (var ext in extensions) fsm.AddExtension(ext); fsm.DefineHierarchyOn(States.Connecting) .WithHistoryType(HistoryType.None); fsm.DefineHierarchyOn(States.Connected) .WithHistoryType(HistoryType.None) .WithInitialSubState(States.Dota); fsm.DefineHierarchyOn(States.Dota) .WithHistoryType(HistoryType.None) .WithInitialSubState(States.DotaConnect) .WithSubState(States.DotaMenu) .WithSubState(States.DotaLobby); fsm.DefineHierarchyOn(States.Disconnected) .WithHistoryType(HistoryType.None) .WithInitialSubState(States.DisconnectNoRetry) .WithSubState(States.DisconnectRetry); fsm.DefineHierarchyOn(States.DotaLobby) .WithHistoryType(HistoryType.None); fsm.In(States.Connecting) .ExecuteOnEntry(InitAndConnect) .On(Events.Connected).Goto(States.Connected) .On(Events.Disconnected).Goto(States.DisconnectRetry) .On(Events.LogonFailSteamDown).Execute(SteamIsDown) .On(Events.LogonFailSteamGuard).Goto(States.DisconnectNoRetry) //.Execute(() => reconnect = false) .On(Events.LogonFailBadCreds).Goto(States.DisconnectNoRetry); fsm.In(States.Connected) .ExecuteOnExit(DisconnectAndCleanup) .On(Events.Disconnected).If(ShouldReconnect).Goto(States.Connecting) .Otherwise().Goto(States.Disconnected); fsm.In(States.Disconnected) .ExecuteOnEntry(DisconnectAndCleanup) .ExecuteOnExit(ClearReconnectTimer) .On(Events.AttemptReconnect).Goto(States.Connecting); fsm.In(States.DisconnectRetry) .ExecuteOnEntry(StartReconnectTimer); fsm.In(States.Dota) .ExecuteOnExit(DisconnectDota); fsm.In(States.DotaConnect) .ExecuteOnEntry(ConnectDota) .On(Events.DotaGCReady).Goto(States.DotaMenu); fsm.In(States.DotaMenu) .ExecuteOnEntry(SetOnlinePresence); fsm.In(States.DotaLobby) .ExecuteOnEntry(EnterLobbyChat) .ExecuteOnEntry(EnterBroadcastChannel) .On(Events.DotaLeftLobby).Goto(States.DotaMenu).Execute(LeaveChatChannel); fsm.Initialize(States.Connecting); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = 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; 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; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); log.Info ("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); CallbackThread.Start(); log.Success ("Done Loading Bot!"); CallbackThread.Join(); }
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 Dictionary<Tuple<uint, string>, SteamApps.CDNAuthTokenCallback>(); this.AppInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); this.PackageInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>(); 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); Console.Write( "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(); }
public SteamInterface(String username, String password, String ssfn, SteamID channel) { lastRefresh = DateTime.Now; this.channel = channel; logon = new SteamUser.LogOnDetails() { Username = username, Password = password, SentryFileHash = SHA1.Create().ComputeHash((File.ReadAllBytes(ssfn))) }; admins = new List<SteamID>(); client = new SteamClient(System.Net.Sockets.ProtocolType.Tcp); manager = new CallbackManager(client); message = new Message() { MessageString = SteamInterface.NoCommand }; user = client.GetHandler<SteamUser>(); friends = client.GetHandler<SteamFriends>(); new Callback<SteamClient.ConnectedCallback>(this.OnConnected, manager); new Callback<SteamClient.DisconnectedCallback>(this.OnDisconnected, manager); new Callback<SteamUser.LoggedOnCallback>(this.OnLoggedOn, manager); new Callback<SteamUser.LoggedOffCallback>(this.OnLoggedOff, manager); new Callback<SteamFriends.ChatMsgCallback>(this.OnChatMessage, manager); }
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; Admins = config.Admins; 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; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler<SteamGameCoordinator>(); backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; backgroundWorker.DoWork += BackgroundWorkerOnDoWork; backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
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(); }
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); }
private void OnConnected(SteamClient.ConnectedCallback callback) { if (callback == null) { Logging.LogNullError(nameof(callback), BotName); return; } if (callback.Result != EResult.OK) { Logging.LogGenericError("Unable to connect to Steam: " + callback.Result, BotName); return; } Logging.LogGenericInfo("Connected to Steam!", BotName); if (!KeepRunning) { Logging.LogGenericInfo("Disconnecting...", BotName); Disconnect(); return; } byte[] sentryFileHash = null; if (File.Exists(SentryFile)) { try { byte[] sentryFileContent = File.ReadAllBytes(SentryFile); sentryFileHash = SteamKit2.CryptoHelper.SHAHash(sentryFileContent); } catch (Exception e) { Logging.LogGenericException(e, BotName); } } if (!InitializeLoginAndPassword(false)) { Stop(); return; } Logging.LogGenericInfo("Logging in...", BotName); string password = BotConfig.SteamPassword; if (!string.IsNullOrEmpty(password)) { // Steam silently ignores non-ASCII characters in password, we're going to do the same // Don't ask me why, I know it's stupid password = Regex.Replace(password, @"[^\u0000-\u007F]+", ""); } // Decrypt login key if needed string loginKey = BotDatabase.LoginKey; if (!string.IsNullOrEmpty(loginKey) && (loginKey.Length > 19)) { loginKey = CryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); } SteamUser.LogOnDetails logOnDetails = new SteamUser.LogOnDetails { Username = BotConfig.SteamLogin, Password = password, AuthCode = AuthCode, CellID = Program.GlobalDatabase.CellID, LoginID = LoginID, LoginKey = loginKey, TwoFactorCode = TwoFactorCode, SentryFileHash = sentryFileHash, ShouldRememberPassword = true }; try { SteamUser.LogOn(logOnDetails); } catch { // TODO: Remove me once https://github.com/SteamRE/SteamKit/issues/305 is fixed ArchiHandler.LogOnWithoutMachineID(logOnDetails); } }
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; Log = new Log(logFile, DisplayName, consoleLogLevel, fileLogLevel); 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(); }
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 virtual void OnConnect(SteamClient.ConnectedCallback e) { if (e.Result != EResult.OK) { VersatileIO.Error("Unable to connect to Steam: " + e.Result.ToString()); Stop(); return; } VersatileIO.Success("Connected to Steam!"); VersatileIO.Debug("Logging in user '{0}'...", LoginUsername); byte[] hash = null; if (!File.Exists(SentryFilePath)) { byte[] sentryFile = File.ReadAllBytes(SentryFilePath); hash = CryptoHelper.SHAHash(sentryFile); } SteamUser.LogOnDetails logon = new SteamUser.LogOnDetails(); logon.Username = LoginUsername; logon.Password = password; logon.AuthCode = steamGuardCode; logon.TwoFactorCode = twoFactorAuth; logon.SentryFileHash = hash; User.LogOn(logon); }
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 = 500; Admins = new ulong[1]; Admins[0] = 0; 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(); SteamClient.AddHandler(new ClientPlayerNicknameListHandler()); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler<SteamGameCoordinator>(); SteamNicknames = SteamClient.GetHandler<ClientPlayerNicknameListHandler>(); 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); new Thread(() => HandleSteamMessage(msg)).Start(); } }); CallbackThread.Start(); CallbackThread.Join(); log.Success("Done loading account!"); main.Invoke((Action)(() => { main.label_status.Text = "Done loading account!"; })); }
/// <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> public Bot(SteamUser.LogOnDetails details, double reconnectDelay=3000) { 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")); })); _state.Configure(State.Conceived) .Permit(Trigger.ShutdownRequested, State.SignedOff); _state.Configure(State.SignedOff) .SubstateOf(State.Conceived) //.OnEntryFrom(Trigger.SteamInvalidCreds, () => ) todo: handle invalid login .Permit(Trigger.ConnectRequested, State.Steam); _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) #if TEST_IMPL .OnEntry(CreateLobby); #endif ; _state.Configure(State.DotaLobby) .SubstateOf(State.Dota) .Ignore(Trigger.DotaEnteredLobbyUI) .Permit(Trigger.DotaEnteredLobbyPlay, State.DotaPlay) .Permit(Trigger.DotaNoLobby, State.DotaMenu) #if TEST_IMPL .OnEntry(JoinLobbySlot) #endif .OnEntry(JoinLobbyChat) .OnExit(LeaveLobbyChat) ; _state.Configure(State.DotaPlay) .SubstateOf(State.Dota) .Ignore(Trigger.DotaEnteredLobbyPlay) .Permit(Trigger.DotaEnteredLobbyUI, State.DotaLobby) .Permit(Trigger.DotaNoLobby, State.DotaMenu) .OnEntry(()=> _connAttempts = 0) .OnEntry(() => { //Brief delay before starting connection Task.Run(() => { Thread.Sleep(500); if(_state.State == State.DotaPlay) StartDotaGameConnection(); }); }) .OnExit(ReleaseDotaGameConnection); }
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(); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = 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; hatBuyPrice= config.HatBuyPrice; hatSellPrice= config.HatSellPrice; maxRequestTime= config.MaxRequestTime; craftHatSellPrice = config.CraftHatSellPrice; 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; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); log.Info ("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); new Thread(() => { while (true) { Thread.Sleep(1000); if (currentRequest.User != null) { DateTime RequestTimeout = RequestTime.AddSeconds(maxRequestTime); int untilTradeTimeout = (int)Math.Round((RequestTimeout - DateTime.Now).TotalSeconds); if (untilTradeTimeout <= 0 && (MySQL.getItem().User != null)) { SteamFriends.SendChatMessage(currentRequest.User, EChatEntryType.ChatMsg, "Sorry, but your request took too long"); NewRequest(MySQL.RequestStatus.Timedout); log.Warn("Request timedout"); } } } }).Start(); CallbackThread.Start(); log.Success ("Done Loading Bot!"); CallbackThread.Join(); }