Esempio n. 1
0
function umc_do_withdraw()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    if (!isset($args[3])) {
        $amount = 'max';
    } else {
        $amount = umc_sanitize_input($args[3], 'amount');
    }
    // get an item by deposit-ID
    if (isset($args[2]) && is_numeric($args[2])) {
        $id = $args[2];
        umc_echo("{green}[+] {gray}Withdrawing ID {green}{$id}{gray}...");
        umc_log('deposit', 'withdraw', "{$player} tried to withdraw {$amount} of {$id}");
        umc_checkout_goods($id, $amount, 'deposit');
        // get several items, either all or by sender name
    } else {
        if (isset($args[2])) {
            $id = $args[2];
            // make list of possible senders to avoid SQL injection
            $checklist = array('@lottery');
            $check_sql = "SELECT * FROM minecraft_iconomy.deposit WHERE recipient_uuid='{$uuid}' OR sender_uuid='{$uuid}';";
            $D = umc_mysql_fetch_all($check_sql);
            foreach ($D as $check_row) {
                $checklist[] = '@' . $check_row['sender_uuid'];
            }
            if (in_array($id, $checklist)) {
                // withdrawing all items from specific sender
                $sender = substr($id, 1);
                // strip the @ from the name
                $sender_uuid = umc_user2uuid($sender);
                umc_echo("{green}[+]{gray} Withdrawing items sent by {gold}{$sender}{gray} from your deposit");
                $sql = "SELECT `id`, `item_name`, `amount` FROM minecraft_iconomy.deposit WHERE sender_uuid='{$sender_uuid}' AND recipient_uuid='{$uuid}'";
                umc_log('deposit', 'withdraw', "{$player} tried to withdraw {$amount} from {$sender}");
            } else {
                if ($id == 'all') {
                    // withdrawing the whole deposit
                    umc_echo("{green}[+]{gray} Withdrawing everything from your deposit...");
                    $sql = "SELECT `id`, `item_name`, `amount` FROM minecraft_iconomy.deposit WHERE recipient_uuid='{$uuid}'";
                    umc_log('deposit', 'withdraw', "{$player} tried to withdraw all");
                } else {
                    // by item name
                    $find_item = umc_goods_get_text($id);
                    //if (in_array($find_item['id'], $umc_unavailable)) {
                    //    umc_echo("{red}This item is unavailable. Please check the wiki for the proper item!",true);
                    //}
                    $sql = "SELECT `id`, `item_name`, `amount` FROM minecraft_iconomy.deposit\r\n                WHERE recipient_uuid='{$uuid}'\r\n\t\t    AND item_name='{$find_item['item_name']}'\r\n\t\t    AND damage='0'";
                    umc_log('deposit', 'withdraw', "{$player} tried to {$find_item['item_name']}:0");
                }
            }
            $D = umc_mysql_fetch_all($sql);
            if (count($D) > 0) {
                $all_items = array();
                foreach ($D as $row) {
                    $id = $row['id'];
                    $item_name = $row['item_name'];
                    if ($amount == 'max') {
                        $this_amount = $row['amount'];
                    } else {
                        if ($row['amount'] > $amount) {
                            $this_amount = $amount;
                            $amount = 0;
                        } else {
                            $this_amount = $row['amount'];
                            $amount -= $this_amount;
                        }
                    }
                    $all_items[$id] = array('item_name' => $item_name, 'amount' => $this_amount);
                }
                umc_check_space_multiple($all_items);
                foreach ($all_items as $id => $data) {
                    umc_checkout_goods($id, $data['amount'], 'deposit');
                }
                if ($amount > 0) {
                    umc_echo("{yellow}[!]{gray} Not enough items were found, withdrew maximum possible.");
                }
            } else {
                umc_error("{red}There are no such items in your deposit.");
            }
        } else {
            umc_error('{red}You need an ID number or a sender name. Please use {yellow}/shophelp');
        }
    }
}
/**
 * move all items from the shop to deposit for a specific user
 * Normally only used when users are banned or inactive, on lot reset
 *
 * @param type $uuid
 */
function umc_shop_cleanout_olduser($uuid)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // delete all requests
    $requests_sql = "DELETE FROM minecraft_iconomy.request WHERE uuid='{$uuid}';";
    umc_mysql_query($requests_sql, true);
    // move all items from stock to deposit
    $sql = "SELECT * FROM minecraft_iconomy.stock WHERE uuid='{$uuid}';";
    $rst = umc_mysql_query($sql);
    while ($row = umc_mysql_fetch_array($rst)) {
        umc_checkout_goods($row['id'], 'max', 'stock', true, true, $uuid);
    }
    umc_log('user_manager', 'shop-cleanout', "{$uuid} had his items moved from stock & request to deposit");
}