Esempio n. 1
0
        public void SaveAccountsFile()
        {
            var indexes = (from keyPair in Accounts
                           where keyPair.Key != -1
                           select new JsonAccounts.JsonIndex
            {
                Accounts = keyPair.Value.Select(account => account.JsonAccount).ToArray()
            }).ToList();

            var jsonAccount = new JsonAccounts
            {
                Indexes = indexes.ToArray()
            };

            using (var writer = File.CreateText(_file.ToString()))
            {
                var textToWrite = JsonConvert.SerializeObject(jsonAccount, Formatting.Indented);
                writer.Write(textToWrite);
            }
        }
Esempio n. 2
0
        public void ParseAccountFile()
        {
            if (!_file.Exists)
            {
                _log.Warning("The accounts file at {0} doesn't exist!", _file.ToString());
                _log.Warning("Titan will run in dummy mode and allow you to edit the accounts before using it.");

                var dummy = @"{
    ""indexes"": [
        {
            ""accounts"": []
        }
    ]
}";

                File.WriteAllText(_file.ToString(), dummy);
                Titan.Instance.DummyMode = true;
            }

            using (var reader = File.OpenText(_file.ToString()))
            {
                _parsedAccounts = (JsonAccounts)Titan.Instance.JsonSerializer.Deserialize(reader, typeof(JsonAccounts));
            }

            foreach (var indexes in _parsedAccounts.Indexes)
            {
                var accounts = new List <TitanAccount>();

                foreach (var account in indexes.Accounts)
                {
                    TitanAccount acc;

                    var sentry = account.Sentry ||
                                 account.SharedSecret != null &&
                                 !account.SharedSecret.Equals("Shared Secret for SteamGuard",
                                                              StringComparison.InvariantCultureIgnoreCase); // Paster proofing

                    if (sentry)
                    {
                        acc = new ProtectedAccount(account);
                    }
                    else
                    {
                        acc = new UnprotectedAccount(account);
                    }

                    if (account.Enabled)
                    {
                        accounts.Add(acc);
                        _allAccounts.Add(acc);
                    }

                    if (!Titan.Instance.Options.Secure)
                    {
                        _log.Debug("Found account (specified in index #{Index}): Username: {Username} / " +
                                   "Password: {Password} / Sentry: {sentry} / Enabled: {Enabled}",
                                   Index, account.Username, account.Password, account.Sentry, account.Enabled);
                    }
                }

                if (accounts.Count > 11 && !Titan.Instance.DummyMode)
                {
                    _log.Warning("You have more than 11 account specified in index {Index}. " +
                                 "It is recommend to specify max. 11 accounts.", Index);
                }

                Accounts.Add(Index, accounts);

                Index++;
            }

            if (_allAccounts.Count < 11 && !Titan.Instance.DummyMode && _allAccounts.Count >= 1)
            {
                _log.Warning("Less than 11 (only {Count}) accounts have been parsed. Atleast 11 accounts " +
                             "are required to get a target into Overwatch.", _allAccounts.Count);

                /* TODO: This calls UIManager even thought it wasn't created yet - causes crash of application
                 * Titan.Instance.UIManager.SendNotification(
                 *  "Titan - Error", "You have less than 11 accounts specified. " +
                 *                   "Atleast 11 bot accounts need to specified to get " +
                 *                   "a target into Overwatch."
                 * );*/
            }

            var list = new List <object>();

            foreach (var keyPair in Accounts)
            {
                list.Add(new { Index = keyPair.Key, keyPair.Value.Count });
            }

            _log.Information("Account file has been successfully parsed. {Count} accounts " +
                             "have been parsed. Details: {@List}", _allAccounts.Count, list);

            Accounts.Add(-1, _allAccounts);

            _lastIndex = Index;
            Index      = 0;

            if (_allAccounts.Count < 1 && !Titan.Instance.DummyMode)
            {
                _log.Warning("The {File} file has been created but doesn't have accounts specified.", _file.ToString());
                _log.Warning("Titan will run in dummy mode and allow you to edit the accounts before using it.");

                Titan.Instance.DummyMode = true;
            }

            ParseIndexFile();
        }
Esempio n. 3
0
        public bool ParseAccountFile()
        {
            if (!_file.Exists)
            {
                _log.Error("The accounts file at {0} doesn't exist! It is required and needs to " +
                           "have atleast one account specified.", _file.ToString());

                Titan.Instance.UIManager.SendNotification(
                    "Titan - Error", "The " + _file + " file doesn't exist or has not " +
                    "specified atleast one bot account. Please create it " +
                    "and specify atleast one bot account in it."
                    );

                return(false);
            }

            using (var reader = File.OpenText(_file.ToString()))
            {
                _parsedAccounts = (JsonAccounts) new JsonSerializer().Deserialize(reader, typeof(JsonAccounts));
            }

            foreach (var indexes in _parsedAccounts.Indexes)
            {
                var accounts = new List <TitanAccount>();

                foreach (var account in indexes.Accounts)
                {
                    TitanAccount acc;
                    if (account.Sentry || account.SharedSecret != null)
                    {
                        acc = new ProtectedAccount(account);
                    }
                    else
                    {
                        acc = new UnprotectedAccount(account);
                    }

                    if (account.Enabled)
                    {
                        accounts.Add(acc);
                        _allAccounts.Add(acc);
                    }

                    _log.Debug("Found account (specified in index #{Index}): Username: {Username} / " +
                               "Password: {Password} / Sentry: {sentry} / Enabled: {Enabled}",
                               Index, account.Username, account.Password, account.Sentry, account.Enabled);
                }

                if (accounts.Count > 11)
                {
                    _log.Warning("You have more than 11 account specified in index {Index}. " +
                                 "It is recommend to specify max. 11 accounts.", Index);
                }

                Accounts.Add(Index, accounts);

                Index++;
            }

            if (_allAccounts.Count < 11)
            {
                _log.Warning("Less than 11 (only {Count}) accounts have been parsed. Atleast 11 accounts " +
                             "are required to get a target into Overwatch.", _allAccounts.Count);

                Titan.Instance.UIManager.SendNotification(
                    "Titan - Error", "You have less than 11 accounts specified. " +
                    "Atleast 11 bot accounts need to specified to get " +
                    "a target into Overwatch."
                    );
            }
            else
            {
                var list = new List <object>();

                foreach (var keyPair in Accounts)
                {
                    list.Add(new { Index = keyPair.Key, keyPair.Value.Count });
                }

                _log.Information("Account file has been successfully parsed. {Count} accounts " +
                                 "have been parsed. Details: {@List}", _allAccounts.Count, list);
            }

            Accounts.Add(-1, _allAccounts);

            Index = 0;

            ParseIndexFile();

            return(true);
        }