Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        private TabPage GetAccountsTabPage()
        {
            var grid = new GridView {
                AllowMultipleSelection = false
            };

            RefreshList(ref grid);

            grid.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell("Enabled")
                {
                    TextAlignment = TextAlignment.Center
                },
                HeaderText = "Enabled"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell("Index")
                {
                    TextAlignment = TextAlignment.Center
                },
                HeaderText = "Index"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Username"),
                HeaderText = "Username"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Password"),
                HeaderText = "Password"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell("Sentry")
                {
                    TextAlignment = TextAlignment.Center
                },
                HeaderText = "Steam Guard"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Secret"),
                HeaderText = "Shared Secret"
            });

            var txtBoxUsername = new TextBox {
                PlaceholderText = "Username"
            };
            var txtBoxPassword = new TextBox {
                PlaceholderText = "Password"
            };
            var cbSentry = new CheckBox {
                Text = "Steam Guard", Checked = false
            };

            var btnAddUpdate = new Button {
                Text = "Add / Update"
            };

            btnAddUpdate.Click += delegate
            {
                if (!string.IsNullOrWhiteSpace(txtBoxUsername.Text) && !string.IsNullOrWhiteSpace(txtBoxPassword.Text))
                {
                    if (Titan.Instance.AccountManager.TryGetAccount(txtBoxUsername.Text.Trim(), out var account))
                    {
                        account.JsonAccount.Username = txtBoxUsername.Text.Trim();
                        account.JsonAccount.Password = txtBoxPassword.Text.Trim();
                        account.JsonAccount.Sentry   = cbSentry.Checked != null && (bool)cbSentry.Checked;

                        _uiManager.SendNotification("Titan", "Successfully updated account " + account.JsonAccount.Username);
                    }
                    else
                    {
                        var jsonAccount = new JsonAccounts.JsonAccount
                        {
                            Username     = txtBoxUsername.Text.Trim(),
                            Password     = txtBoxPassword.Text.Trim(),
                            Sentry       = cbSentry.Checked != null && (bool)cbSentry.Checked,
                            Enabled      = true,
                            SharedSecret = null
                        };

                        TitanAccount acc;

                        if (jsonAccount.Sentry)
                        {
                            acc = new ProtectedAccount(jsonAccount);
                        }
                        else
                        {
                            acc = new UnprotectedAccount(jsonAccount);
                        }

                        Titan.Instance.AccountManager.AddAccount(acc);

                        _uiManager.SendNotification("Titan", "Successfully added account " + acc.JsonAccount.Username);

                        var tabControl = (TabControl)Content;
                        foreach (var page in tabControl.Pages)
                        {
                            page.Enabled = true;
                        }

                        if (Titan.Instance.DummyMode)
                        {
                            _log.Information("There are now accounts specified. Turning dummy mode {off}.", "off");

                            Titan.Instance.DummyMode = false;
                        }
                    }

                    RefreshList(ref grid);
                }
                else
                {
                    _uiManager.SendNotification("Titan - Error", "Please input a username and password.");
                }
            };

            var btnRemove = new Button {
                Text = "Remove"
            };

            btnRemove.Click += delegate
            {
                dynamic selected = grid.SelectedItem;

                if (selected != null)
                {
                    _log.Information("{Type}: {@Info}", selected.GetType(), selected);

                    var username = selected.Username;

                    if (username != null)
                    {
                        if (Titan.Instance.AccountManager.TryGetAccount(username, out TitanAccount account))
                        {
                            Titan.Instance.AccountManager.RemoveAccount(account);
                            RefreshList(ref grid);
                        }
                        else
                        {
                            _uiManager.SendNotification("Titan - Error", "The account doesn't exist.");
                        }
                    }
                    else
                    {
                        _uiManager.SendNotification("Titan", "The account could not be found.");
                    }
                }
                else
                {
                    _uiManager.SendNotification("Titan - Error", "Please select a account before removing it.");
                }

                if (Titan.Instance.AccountManager.Count() < 1)
                {
                    var tabControl = (TabControl)Content;
                    foreach (var page in tabControl.Pages)
                    {
                        if (!page.Text.Equals("Accounts"))
                        {
                            page.Enabled = false;
                        }
                    }

                    if (!Titan.Instance.DummyMode)
                    {
                        _log.Warning("There are no longer accounts specified. Turning dummy mode back {on}.", "on");

                        Titan.Instance.DummyMode = true;
                    }
                }
            };

            return(new TabPage
            {
                Text = "Accounts",
                Content = new TableLayout
                {
                    Spacing = new Size(5, 5),
                    Padding = new Padding(10, 10, 10, 10),
                    Rows =
                    {
                        new TableRow(new TableCell(grid,              true))
                        {
                            ScaleHeight = true
                        },
                        new GroupBox
                        {
                            Text = "Edit",
                            Content = new TableLayout
                            {
                                Spacing = new Size(5,                    5),
                                Padding = new Padding(10,                10,  10, 10),
                                Rows =
                                {
                                    new TableRow(
                                        new TableCell(txtBoxUsername, true),
                                        new TableCell(txtBoxPassword, true),
                                        new TableCell(cbSentry)
                                        )
                                }
                            }
                        },
                        new TableLayout
                        {
                            Spacing = new Size(5,                        5),
                            Padding = new Padding(10,                    10,  10, 10),
                            Rows =
                            {
                                new TableRow(
                                    new TableCell(new Panel(), true),
                                    new TableCell(new Panel(), true),
                                    new TableCell(btnRemove),
                                    new TableCell(btnAddUpdate)
                                    )
                            }
                        }
                    }
                }
            });
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        public override TabPage GetTabPage()
        {
            var grid = new GridView {
                AllowMultipleSelection = false
            };

            RefreshList(ref grid);

            grid.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell("Enabled")
                {
                    TextAlignment = TextAlignment.Center
                },
                HeaderText = "Enabled"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell("Index")
                {
                    TextAlignment = TextAlignment.Center
                },
                HeaderText = "Index"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Username"),
                HeaderText = "Username"
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Password"),
                HeaderText = "Password",
                Visible    = !Titan.Instance.Options.Secure
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell("Sentry")
                {
                    TextAlignment = TextAlignment.Center
                },
                HeaderText = "Steam Guard",
                Visible    = !Titan.Instance.Options.Secure
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Secret"),
                HeaderText = "Shared Secret",
                Visible    = !Titan.Instance.Options.Secure
            });

            grid.Columns.Add(new GridColumn
            {
                DataCell   = new TextBoxCell("Cooldown"),
                HeaderText = "Cooldown"
            });

            var txtBoxUsername = new TextBox {
                PlaceholderText = "Username"
            };

            TextControl txtBoxPassword;

            if (Titan.Instance.Options.Secure)
            {
                txtBoxPassword = new PasswordBox {
                    PasswordChar = '\u2022'
                };
            }
            else
            {
                txtBoxPassword = new TextBox {
                    PlaceholderText = "Password"
                };
            }

            var cbSentry = new CheckBox {
                Text = "Steam Guard", Checked = false
            };

            var btnAddUpdate = new Button {
                Text = "Add / Update"
            };

            btnAddUpdate.Click += (sender, args) =>
            {
                if (!string.IsNullOrWhiteSpace(txtBoxUsername.Text) && !string.IsNullOrWhiteSpace(txtBoxPassword.Text))
                {
                    if (Titan.Instance.AccountManager.TryGetAccount(txtBoxUsername.Text.Trim(), out var account))
                    {
                        if (account.JsonAccount.Sentry != (cbSentry.Checked != null && (bool)cbSentry.Checked))
                        {
                            var clone = account.JsonAccount.Clone();

                            Titan.Instance.AccountManager.RemoveAccount(account);
                            if (cbSentry.Checked != null && (bool)cbSentry.Checked)
                            {
                                account = new ProtectedAccount(clone);
                            }
                            else
                            {
                                account = new UnprotectedAccount(clone);
                            }
                            Titan.Instance.AccountManager.AddAccount(account);
                        }

                        account.JsonAccount.Username = txtBoxUsername.Text.Trim();
                        account.JsonAccount.Password = txtBoxPassword.Text.Trim();
                        account.JsonAccount.Sentry   = cbSentry.Checked != null && (bool)cbSentry.Checked;

                        UIManager.SendNotification("Titan", "Successfully updated account " + account.JsonAccount.Username);
                    }
                    else
                    {
                        var jsonAccount = new JsonAccounts.JsonAccount
                        {
                            Username     = txtBoxUsername.Text.Trim(),
                            Password     = txtBoxPassword.Text.Trim(),
                            Sentry       = cbSentry.Checked != null && (bool)cbSentry.Checked,
                            Enabled      = true,
                            SharedSecret = null
                        };

                        TitanAccount acc;

                        if (jsonAccount.Sentry)
                        {
                            acc = new ProtectedAccount(jsonAccount);
                        }
                        else
                        {
                            acc = new UnprotectedAccount(jsonAccount);
                        }

                        Titan.Instance.AccountManager.AddAccount(acc);

                        UIManager.SendNotification("Titan", "Successfully added account " + acc.JsonAccount.Username);

                        var tabControl = (TabControl)_generalUI.Content;
                        foreach (var page in tabControl.Pages)
                        {
                            page.Enabled = true;
                        }

                        if (Titan.Instance.DummyMode)
                        {
                            _log.Information("There are now accounts specified. Turning dummy mode {off}.", "off");

                            Titan.Instance.DummyMode = false;
                        }
                    }

                    Titan.Instance.AccountManager.SaveAccountsFile();
                    RefreshList(ref grid);
                }
                else
                {
                    UIManager.SendNotification("Titan - Error", "Please input a username and password.");
                }
            };

            var btnRemove = new Button {
                Text = "Remove"
            };

            btnRemove.Click += (sender, args) =>
            {
                dynamic selected = grid.SelectedItem;

                if (selected != null)
                {
                    var username = selected.Username;

                    if (username != null)
                    {
                        if (Titan.Instance.AccountManager.TryGetAccount(username, out TitanAccount account))
                        {
                            Titan.Instance.AccountManager.RemoveAccount(account);
                            Titan.Instance.AccountManager.SaveAccountsFile();
                            RefreshList(ref grid);
                        }
                        else
                        {
                            UIManager.SendNotification("Titan - Error", "The account doesn't exist.");
                        }
                    }
                    else
                    {
                        UIManager.SendNotification("Titan", "The account could not be found.");
                    }
                }
                else
                {
                    UIManager.SendNotification("Titan - Error", "Please select a account before removing it.");
                }

                if (Titan.Instance.AccountManager.Count() < 1)
                {
                    var tabControl = (TabControl)_generalUI.Content;
                    foreach (var page in tabControl.Pages)
                    {
                        if (!page.Text.Equals("Accounts"))
                        {
                            page.Enabled = false;
                        }
                    }

                    if (!Titan.Instance.DummyMode)
                    {
                        _log.Warning("There are no longer accounts specified. Turning dummy mode back {on}.", "on");

                        Titan.Instance.DummyMode = true;
                    }
                }
            };

            var btnImport = new Button {
                Text = "Import"
            };

            btnImport.Click += (sender, args) =>
            {
                var dialog = new OpenFileDialog
                {
                    Title   = "Select file to import",
                    Filters =
                    {
                        new FileFilter("Legacy account files", ".txt")
                    },
                    MultiSelect = false
                };

                var result = UIManager.ShowForm(UIType.FilePicker, dialog);

                if (result != DialogResult.Ok)
                {
                    return;
                }

                if (!dialog.Filenames.Any())
                {
                    UIManager.SendNotification("Titan", "Please select a file.");
                    return;
                }

                AccountImporter importer = new GenericAccountListImporter(dialog.Filenames.First());
                var             accounts = importer.ParseAccounts();

                if (accounts == null || accounts.Count <= 0)
                {
                    UIManager.SendNotification("Titan", "No accounts were imported.");
                    return;
                }

                foreach (var account in accounts)
                {
                    Titan.Instance.AccountManager.AddAccount(account);
                }

                UIManager.SendNotification("Titan", "Successfully imported " + accounts.Count + " accounts.");

                // Disable dummy mode now that accounts are here.
                var tabControl = (TabControl)_generalUI.Content;
                foreach (var page in tabControl.Pages)
                {
                    page.Enabled = true;
                }

                if (Titan.Instance.DummyMode)
                {
                    _log.Information("There are now accounts specified. Turning dummy mode {off}.", "off");

                    Titan.Instance.DummyMode = false;
                }

                RefreshList(ref grid);
            };

            return(new TabPage
            {
                Text = "Accounts",
                Content = new TableLayout
                {
                    Spacing = new Size(5, 5),
                    Padding = new Padding(10, 10, 10, 10),
                    Rows =
                    {
                        new TableRow(new TableCell(grid,              true))
                        {
                            ScaleHeight = true
                        },
                        new GroupBox
                        {
                            Text = "Edit",
                            Content = new TableLayout
                            {
                                Spacing = new Size(5,                    5),
                                Padding = new Padding(10,                10,  10, 10),
                                Rows =
                                {
                                    new TableRow(
                                        new TableCell(txtBoxUsername, true),
                                        new TableCell(txtBoxPassword, true),
                                        new TableCell(cbSentry)
                                        )
                                }
                            }
                        },
                        new TableLayout
                        {
                            Spacing = new Size(5,                        5),
                            Padding = new Padding(10,                    10,  10, 10),
                            Rows =
                            {
                                new TableRow(
                                    new TableCell(new Panel(), true),
                                    new TableCell(new Panel(), true),
                                    new TableCell(btnImport),
                                    new TableCell(btnRemove),
                                    new TableCell(btnAddUpdate)
                                    )
                            }
                        }
                    }
                }
            });
        }