Ejemplo n.º 1
0
        /// <summary>
        /// Fires when a user wants to delete some transactions
        /// </summary>
        private async void ctxDeleteTransactionConfirm_Click(object sender, EventArgs e)
        {
            gvTransactions.Enabled  = false;
            gvAccounts.Enabled      = false;
            btnRefreshTrans.Enabled = false;
            btnResetTrans.Enabled   = false;

            await Task.Factory.StartNew(() => {
                int count = gvTransactions.SelectedRows.Count;

                for (int i = 0; i < gvTransactions.SelectedRows.Count; i++)
                {
                    DataGridViewRow selectedItem = gvTransactions.SelectedRows[i];

                    if (selectedItem.DataBoundItem != null)
                    {
                        Journal.IBankAccount bankAccount;
                        Journal.ITransaction selectedTrans = selectedItem.DataBoundItem as Journal.ITransaction;

                        if (selectedTrans != null)
                        {
                            bankAccount = selectedTrans.BankAccount;

                            //invoke GUI updates on gui thread
                            this.MainThreadInvoke(() => {
                                lblStatus.Text = string.Format("Deleted transaction {0} for {1}", selectedTrans.BankAccountTransactionK, ((Money)selectedTrans.Amount).ToLongString(true));
                                toolStripProgressBar1.Value = Convert.ToInt32(((double)i / (double)count) * 100);
                            });

                            bankAccount.Transactions.Remove(selectedTrans);
                        }
                    }
                }
            });

            this.MainThreadInvoke(async() => {
                AccountSummary summary = gvAccounts.SelectedRows[0].DataBoundItem as AccountSummary;
                Journal.IBankAccount selectedUserAccount = SEconomyPlugin.Instance.RunningJournal.BankAccounts.FirstOrDefault(i => i.BankAccountK == summary.Value);

                if (selectedUserAccount != null)
                {
                    await selectedUserAccount.SyncBalanceAsync();
                    AccountSummary selectedSummary = accList.FirstOrDefault(i => i.Value == selectedUserAccount.BankAccountK);

                    if (selectedSummary != null)
                    {
                        selectedSummary.Balance = selectedUserAccount.Balance;
                    }
                }

                toolStripProgressBar1.Value = 100;
                gvTransactions.Enabled      = true;
                gvAccounts.Enabled          = true;
                btnRefreshTrans.Enabled     = true;
                btnResetTrans.Enabled       = true;
                btnShowFrom.Enabled         = true;

                await LoadTransactionsForUser(summary.Value);
            });
        }
Ejemplo n.º 2
0
        public async void SEconomyTransferAsync(Journal.IBankAccount From, Journal.IBankAccount To, Money Amount, string TxMessage, JsValue completedCallback)
        {
            BankTransferEventArgs result = null;

            if (JistPlugin.Instance == null ||
                SEconomyPlugin.Instance == null ||
                From == null ||
                To == null)
            {
                return;
            }

            result = await From.TransferToAsync(To, Amount,
                                                Journal.BankAccountTransferOptions.AnnounceToSender,
                                                TxMessage, TxMessage);

            if (result == null)
            {
                result = new BankTransferEventArgs()
                {
                    TransferSucceeded = false
                };
            }

            Jist.JistPlugin.Instance.CallFunction(completedCallback, null, result);
        }
        /// <summary>
        /// Processes all elements in the queue and transfers them
        /// </summary>
        protected async Task ProcessQueueAsync()
        {
            List <CachedTransaction> aggregatedFunds = new List <CachedTransaction>();
            CachedTransaction        fund;

            while (CachedTransactions.TryDequeue(out fund))
            {
                //The idea of this is that the concurrent queue will aggregate everything with the same message.
                //So instead of spamming eye of ctaltlatlatututlutultu (shut up) it'll just agg them into one
                //and print something like "You gained 60 silver from 20 eyes" instead of spamming both the chat log
                //and the journal with bullshit
                CachedTransaction existingFund = aggregatedFunds.FirstOrDefault(i => i.Message == fund.Message && i.SourceBankAccountK == fund.SourceBankAccountK && i.DestinationBankAccountK == fund.DestinationBankAccountK);
                if (existingFund != null)
                {
                    existingFund.Amount += fund.Amount;

                    //indicate that this is an aggregate of a previous uncommitted fund
                    existingFund.Aggregations++;
                }
                else
                {
                    aggregatedFunds.Add(fund);
                }
            }

            foreach (CachedTransaction aggregatedFund in aggregatedFunds)
            {
                Journal.IBankAccount sourceAccount = SEconomyPlugin.Instance.RunningJournal.GetBankAccount(aggregatedFund.SourceBankAccountK);
                Journal.IBankAccount destAccount   = SEconomyPlugin.Instance.RunningJournal.GetBankAccount(aggregatedFund.DestinationBankAccountK);

                if (sourceAccount != null && destAccount != null)
                {
                    StringBuilder messageBuilder = new StringBuilder(aggregatedFund.Message);

                    if (aggregatedFund.Aggregations > 1)
                    {
                        messageBuilder.Insert(0, aggregatedFund.Aggregations + " ");
                        messageBuilder.Append("s");
                    }
                    //transfer the money
                    BankTransferEventArgs transfer = await sourceAccount.TransferToAsync(destAccount, aggregatedFund.Amount, aggregatedFund.Options, messageBuilder.ToString(), messageBuilder.ToString());

                    if (!transfer.TransferSucceeded)
                    {
                        if (transfer.Exception != null)
                        {
                            TShock.Log.ConsoleError(string.Format("seconomy cache: error source={0} dest={1}: {2}", aggregatedFund.SourceBankAccountK, aggregatedFund.DestinationBankAccountK, transfer.Exception));
                        }
                    }
                }
                else
                {
                    TShock.Log.ConsoleError(string.Format("seconomy cache: transaction cache has no source or destination. source key={0} dest key={1}", aggregatedFund.SourceBankAccountK, aggregatedFund.DestinationBankAccountK));
                }
            }
        }
Ejemplo n.º 4
0
        private async void btnModifyBalance_Click(object sender, EventArgs e)
        {
            Journal.IBankAccount account             = SecInstance.RunningJournal.GetBankAccount(currentlySelectedAccount.Value);
            CModifyBalanceWnd    modifyBalanceWindow = new CModifyBalanceWnd(SecInstance, account);

            modifyBalanceWindow.ShowDialog(this);

            //when the dialog has finished, reload the account
            await LoadTransactionsForUser(account.BankAccountK);
        }
Ejemplo n.º 5
0
        private async void btnResetTrans_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("This will delete all transactions for this user.  This could take a long time and SEconomy performance could be impacted.  The user's balance will be reset to 0 copper.", "Delete all Transactions", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                Journal.IBankAccount account = SecInstance.RunningJournal.GetBankAccount(currentlySelectedAccount.Value);

                gvTransactions.Enabled  = false;
                gvAccounts.Enabled      = false;
                btnRefreshTrans.Enabled = false;
                btnResetTrans.Enabled   = false;
                btnShowFrom.Enabled     = false;

                lblStatus.Text = "Resetting all transactions for " + currentlySelectedAccount.Name;
                toolStripProgressBar1.Value = 0;
                toolStripProgressBar1.Style = ProgressBarStyle.Marquee;


                await Task.Factory.StartNew(() => {
                    account.Transactions.Clear();
                });

                Journal.IBankAccount selectedUserAccount = SecInstance.RunningJournal.GetBankAccount(currentlySelectedAccount.Value);
                if (selectedUserAccount != null)
                {
                    await selectedUserAccount.SyncBalanceAsync();

                    AccountSummary summary = accList.FirstOrDefault(i => i.Value == selectedUserAccount.BankAccountK);

                    if (summary != null)
                    {
                        summary.Balance = selectedUserAccount.Balance;
                    }

                    this.MainThreadInvoke(async() => {
                        toolStripProgressBar1.Value = 100;
                        toolStripProgressBar1.Style = ProgressBarStyle.Continuous;
                        gvTransactions.DataSource   = null;
                        gvTransactions.Enabled      = true;
                        gvAccounts.Enabled          = true;
                        btnRefreshTrans.Enabled     = true;
                        btnResetTrans.Enabled       = true;

                        //force the bindinglist to raise the reset event updating the right hand side
                        accList.ResetBindings();

                        await LoadTransactionsForUser(currentlySelectedAccount.Value);
                    });
                }
            }
        }
Ejemplo n.º 6
0
        public Journal.IBankAccount GetBankAccount(object PlayerRep)
        {
            Journal.IBankAccount bankAccount = null;
            TShockAPI.TSPlayer   player      = null;

            if (JistPlugin.Instance == null ||
                SEconomyPlugin.Instance == null ||
                (player = JistPlugin.Instance.stdTshock.GetPlayer(PlayerRep)) == null ||
                (bankAccount = SEconomyPlugin.Instance.GetBankAccount(player)) == null)
            {
                return(null);
            }

            return(bankAccount);
        }
Ejemplo n.º 7
0
        async Task LoadTransactionsForUser(long BankAccountK)
        {
            Journal.IBankAccount selectedAccount = null;
            TSPlayer             player;
            List <ITransaction>  qTransactions;

            if (selectionEnabled == false)
            {
                return;
            }

            selectedAccount = SecInstance.RunningJournal.GetBankAccount(BankAccountK);
            qTransactions   = selectedAccount.Transactions;

            gvTransactions.DataSource = null;
            gvTransactions.DataSource = qTransactions;
            tranList = SecInstance.RunningJournal.Transactions;

            player = TShock.Players.FirstOrDefault(i => i != null && i.UserAccountName == selectedAccount.UserAccountName);

            lblStatus.Text = string.Format("Loaded {0} transactions for {1}.", qTransactions.Count(), selectedAccount.UserAccountName);
            if (player != null)
            {
                lblOnline.Text      = "Online";
                lblOnline.ForeColor = System.Drawing.Color.DarkGreen;
            }
            else
            {
                lblOnline.Text      = "Offline";
                lblOnline.ForeColor = System.Drawing.Color.Red;
            }

            await selectedAccount.SyncBalanceAsync();

            AccountSummary summary = accList.FirstOrDefault(i => i.Value == BankAccountK);

            if (summary != null)
            {
                summary.Balance = selectedAccount.Balance;
            }
            this.MainThreadInvoke(() => {
                lblBalance.Text = selectedAccount.Balance.ToLongString(true);
                lblName.Text    = string.Format("{0}, acccount ID {1}", selectedAccount.UserAccountName, selectedAccount.BankAccountK);
            });
        }
Ejemplo n.º 8
0
        internal async Task <Journal.IBankAccount> CreatePlayerAccountAsync(TSPlayer player)
        {
            Money startingMoney;

            Journal.IBankAccount newAccount = SEconomyPlugin.Instance.RunningJournal.AddBankAccount(player.Account.Name,
                                                                                                    Main.worldID,
                                                                                                    Journal.BankAccountFlags.Enabled,
                                                                                                    "");

            TShock.Log.ConsoleInfo(string.Format("[SEconomy] Bank account for {0} logged in as {1} created.", player.Name, player.Account.Name));

            if (Money.TryParse(SEconomyPlugin.Instance.Configuration.StartingMoney, out startingMoney) &&
                startingMoney > 0)
            {
                await SEconomyPlugin.Instance.WorldAccount.TransferToAsync(newAccount, startingMoney,
                                                                           Journal.BankAccountTransferOptions.AnnounceToReceiver,
                                                                           "starting out.", "starting out.");
            }

            return(newAccount);
        }