Exemple #1
0
        void AddCurrency(IPlayer player, string TargetName, string TargetId, int amount)
        {
            int originalamount = amount;
            int entamount      = 0;

            // append SQL statement to SELECT amount from database
            var sql = Core.Database.Sql.Builder.Append(SelectAmount, TargetId);

            // query the database and add amount to player
            _mySql.Query(sql, _mySqlConnection, list =>
            {
                if (list.Count > 0)
                {
                    foreach (var ent in list)
                    {
                        entamount = int.Parse(ent["amount"].ToString());
                        amount    = amount + entamount;
                        sql       = Core.Database.Sql.Builder.Append(UpdateAmount, amount, TargetId);
                        _mySql.Update(sql, _mySqlConnection);

                        // update local data file to reflect changes made on database
                        timer.Once(2f, () =>
                        {
                            UpdateDataFile();

                            // display output to console and chat for completion of this command
                            player.Reply(MsgFormat("successadd", player.Id, originalamount, Config["CurrencyName"], TargetName, TargetId));
                            Puts(string.Format("User {0} ({1}) has successfully added {2} {3} to {4} ({5}).", player.Name, player.Id, originalamount, Config["CurrencyName"], TargetName, TargetId));
                        });
                    }
                }
            });
        }
Exemple #2
0
        private void PerformDatabaseUpdate(string dbStatement, Action <int> callbackAction,
                                           Connection optionalConnection = null, params object[] sqlQueryArguments)
        {
            var sqlConnection = optionalConnection ?? GetSqlConnection();

            var query = _mySql.NewSql().Append(dbStatement, sqlQueryArguments);

            _mySql.Update(query, sqlConnection, callbackAction);

            CloseConnection(sqlConnection);
        }