Exemple #1
0
        public async static Task InitializeDatabasePlayer(rFrameworkPlayer rPlayer)
        {
            string SQLQuery = "SELECT * FROM `users` WHERE `identifier` = '" + rPlayer.SteamID + "'";

            DebugWrite(SQLQuery);
            MySqlConnection SQLConnection = GetDBConnection();
            await SQLConnection.OpenAsync();

            MySqlCommand    SQLCommand    = new MySqlCommand(SQLQuery, SQLConnection);
            MySqlDataReader SQLDataReader = (MySqlDataReader)await SQLCommand.ExecuteReaderAsync();

            if (!SQLDataReader.Read())
            {
                SQLQuery = "INSERT INTO `users` (identifier, name) VALUES ('" + rPlayer.SteamID + "', '" + rPlayer.CorePlayer.Name + "')";
                DebugWrite(SQLQuery);
                SQLConnection = GetDBConnection();
                SQLCommand    = new MySqlCommand(SQLQuery, SQLConnection);
                await SQLConnection.OpenAsync();

                await SQLCommand.ExecuteNonQueryAsync();

                rPlayer.BankBalance = 0;
                rPlayer.CashBalance = 0;
                rPlayer.Vehicles    = "";
            }
            else
            {
                rPlayer.BankBalance = SQLDataReader.GetInt64(3);
                rPlayer.CashBalance = SQLDataReader.GetInt64(4);
                rPlayer.Vehicles    = SQLDataReader.GetString(5);

                SQLCommand.Dispose();
                SQLDataReader.Dispose();

                //Get transactions
                SQLQuery      = "SELECT * FROM `transactions` WHERE `from_player` = '" + rPlayer.SteamID + "' OR 'to_player' = '" + rPlayer.SteamID + "'";
                SQLCommand    = new MySqlCommand(SQLQuery, SQLConnection);
                SQLDataReader = (MySqlDataReader)await SQLCommand.ExecuteReaderAsync();

                List <rBankTransfer> transactions = new List <rBankTransfer>();

                while (SQLDataReader.Read())
                {
                    rBankTransfer transaction = new rBankTransfer(SQLDataReader.GetString(1), SQLDataReader.GetString(0),
                                                                  SQLDataReader.GetString(2), (SQLDataReader.GetString(0).Equals(SQLDataReader.GetString(1)) ? true : false),
                                                                  (SQLDataReader.GetString(3).Equals("Cash Withdrawn")) ? true : false, (int)SQLDataReader.GetInt64(3), DateTime.Parse(SQLDataReader.GetString(4)));
                    transactions.Add(transaction);
                }

                rPlayer.Transfers = transactions;
            }

            SQLCommand.Dispose();
            SQLDataReader.Dispose();
            SQLConnection.Dispose();
            return;
        }
        public static void PlayerMoneyTransaction([FromSource] Player player, int amount, bool isWithdrawal)
        {
            rFrameworkPlayer rPlayer = GetrFrameworkPlayer(player);

            amount = Math.Abs(amount);

            //Determine if transaction is a withdrawal (amount less than zero) or deposit (amount greater than zero)
            if (isWithdrawal)
            {
                if (rPlayer.BankBalance - amount >= 0)
                {
                    //Transaction allowed
                    ChangePlayerMoney(rPlayer, -amount, amount);
                    DebugWrite("Player " + player.Name + " withdrew ^2$" + Math.Abs(amount));
                    TriggerClientEvent(player, "rFramework:ATMTransactionSuccess");

                    rBankTransfer transfer = new rBankTransfer(rPlayer.SteamID, rPlayer.SteamID, "Cash Withdrawn", false, true, amount, DateTime.Now);
                    rPlayer.Transfers.Add(transfer);
                    DatabaseUpdateTransaction(transfer);
                    UpdatePlayerTransactions(rPlayer);
                }
                else
                {
                    //Transaction invalid
                }
            }
            else
            {
                if (rPlayer.CashBalance - amount >= 0)
                {
                    //Transaction allowed
                    ChangePlayerMoney(rPlayer, amount, -amount);
                    DebugWrite("Player " + player.Name + " deposited ^1$" + Math.Abs(amount));
                    TriggerClientEvent(player, "rFramework:ATMTransactionSuccess");

                    rBankTransfer transfer = new rBankTransfer(rPlayer.SteamID, rPlayer.SteamID, "Cash Deposited", false, false, amount, DateTime.Now);
                    rPlayer.Transfers.Add(transfer);
                    DatabaseUpdateTransaction(transfer);
                    UpdatePlayerTransactions(rPlayer);
                }
                else
                {
                    //Transaction invalid
                }
            }
        }
Exemple #3
0
        public static void DatabaseUpdateTransaction(rBankTransfer transfer)
        {
            string SQLQuery = "INSERT INTO transactions (to_player, from_player, reason, amount, date) VALUES ";

            SQLQuery += "('" + transfer.sender_steamid + "', '" + transfer.recipient_steamid
                        + "', '" + transfer.reason + "', '" + transfer.amount + "', '" + transfer.time + "')";

            MySqlConnection SQLConnection = GetDBConnection();

            SQLConnection.Open();
            MySqlCommand SQLCommand = new MySqlCommand(SQLQuery, SQLConnection);

            SQLCommand.ExecuteNonQuery();

            SQLCommand.Dispose();
            SQLConnection.Dispose();

            return;
        }