Exemple #1
0
        /// <summary>
        /// Reads the settings from file
        /// </summary>
        /// <returns>Returns false if failed</returns>
        static private bool ReadSettings()
        {
            /*Load settings if file exists, else create one*/
            string filePath = Path.Combine(Application.StartupPath, "Settings.json");

            if (!File.Exists(filePath))
            {
                /*Set up settings class to print*/
                Config.Settings settings = new Config.Settings();

                /*Add example accounts*/
                var tempacc = new Config.AccountInfo();
                tempacc.SetTemporaryValues();
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);

                /*Write settings to file*/
                string settingsJson = JsonConvert.SerializeObject(settings, Formatting.Indented);
                File.WriteAllText(filePath, settingsJson);
                Console.WriteLine("Settings.json has been written. Edit it for your accounts.");
                Thread.Sleep(1500);
            }
            else
            {
                /*Enable missing objects error*/
                JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
                jsonSettings.MissingMemberHandling = MissingMemberHandling.Error;
                string settingsJson = string.Empty;

                try
                {
                    /*Load the settings from file*/
                    settingsJson = File.ReadAllText(filePath);
                    mSettings    = JsonConvert.DeserializeObject <Config.Settings>(settingsJson, jsonSettings);

                    /*Write the class to settins file incase some of the settings were missing from the file originally*/
                    File.WriteAllText(filePath, JsonConvert.SerializeObject(mSettings, Formatting.Indented));
                    return(true);
                }
                catch (JsonReaderException ex)
                {
                    /*There was an error parsing the json file, most likely due to user trying to manually edit it without knowing the syntax*/
                    Console.WriteLine("Error: The settings file is corrupt. Please delete it and restart the program.");
                    Console.WriteLine($"{ex.Message}\n\n");
                }
                catch (Exception ex)
                {
                    /*I wonder what happened here?*/
                    Console.WriteLine("Error: An unhandled exception occured when parsing the settings? What the hell?");
                    Console.WriteLine($"{ex.Message}\n\n");
                }
            }

            Console.WriteLine("Exiting in 10 seconds...");
            Thread.Sleep(10000);
            return(false);
        }
Exemple #2
0
        /// <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();
        }
Exemple #3
0
        /// <summary>
        /// Reads the settings from file
        /// </summary>
        /// <returns>Returns false if failed</returns>
        static private bool ReadSettings()
        {
            /*Load settings if file exists, else create one*/
            string filePath = Path.Combine(Application.StartupPath, "Settings.json");

            if (!File.Exists(filePath))
            {
                /*Set up settings class to print*/
                Config.Settings settings = new Config.Settings();

                /*Add example accounts*/
                var tempacc = new Config.AccountInfo();
                tempacc.SetTemporaryValues();
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);
                settings.Account.Add(tempacc);

                /*Write settings to file*/
                string settingsJson = JsonConvert.SerializeObject(settings, Formatting.Indented);
                File.WriteAllText(filePath, settingsJson);
                Console.WriteLine("Settings.json has been written. Edit it for your accounts.");
                Thread.Sleep(1500);
            }
            else
            {
                try
                {
                    /*Load the settings from file*/
                    string settingsJson = File.ReadAllText(filePath);
                    mSettings = JsonConvert.DeserializeObject <Config.Settings>(settingsJson);
                    return(true);
                }
                catch (JsonException jex)
                {
                    /*User f****d up with the formatting probably*/
                    MessageBox.Show("There was an error parsing Settings.json\n"
                                    + "It's either incorrectly formatted or corrupt.\n"
                                    + "Delete the file and let the app make a new one.\n\nError: " + jex.Message);
                }
            }

            return(false);
        }
Exemple #4
0
        /// <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();
        }