コード例 #1
0
function umc_do_deposit_internal($all = false)
{
    global $UMC_USER, $UMC_SETTING, $UMC_DATA;
    $player = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    // make sure user holds item
    $all_inv = $UMC_USER['inv'];
    if (!$all) {
        $item_slot = $UMC_USER['current_item'];
        if (!isset($all_inv[$item_slot])) {
            umc_error("{red}You need to hold the item you want to deposit! (current slot: {$item_slot});");
        }
        $all_inv = array($item_slot => $all_inv[$item_slot]);
    }
    $sent_out_of_space_msg = 0;
    $seen = array();
    foreach ($all_inv as $slot) {
        $item_id = $slot['item_name'];
        if (!isset($UMC_DATA[$item_id])) {
            XMPP_ERROR_trigger("Invalid item deposit cancelled!");
            umc_error("Sorry, the item in your inventory is bugged, uncovery was notfied and this should be fixed soon. IF you want to speed it up, please send a ticket with as much detail as possible.");
        }
        $data = $slot['data'];
        if ($slot['meta']) {
            $meta = serialize($slot['meta']);
        } else {
            $meta = false;
        }
        // don't assign the same twice
        $item = umc_goods_get_text($slot['item_name'], $slot['data'], $slot['meta']);
        if (isset($seen[$item['full']])) {
            continue;
        }
        $inv = umc_check_inventory($slot['item_name'], $slot['data'], $slot['meta']);
        if ($inv == 0) {
            XMPP_ERROR_trigger("Item held could not be found in inventory: {$slot['item_name']}, {$slot['data']}, " . var_export($slot['meta'], true));
            umc_error("There was a system error. The admin has been notified. Deposit aborted.");
        }
        if (isset($args[2]) && $args[2] != 'lot_reset') {
            $recipient = umc_sanitize_input($args[2], 'player');
            $recipient_uuid = umc_user2uuid($recipient);
        } else {
            if (isset($args[2]) && $args[2] == 'lot_reset') {
                $recipient_uuid = 'reset000-lot0-0000-0000-000000000000';
                $recipient = $args[2];
            } else {
                $recipient = $player;
                $recipient_uuid = $uuid;
                if (!$all) {
                    umc_echo("{yellow}[!]{gray} No recipient given. Depositing for {gold}{$player}");
                }
            }
        }
        if (!$all && isset($args[3])) {
            $amount = umc_sanitize_input($args[3], 'amount');
            $amount_str = $amount;
            if ($amount > $inv) {
                umc_echo("{yellow}[!]{gray} You do not have {yellow}{$amount} {green}{$item['full']}{gray}. Depositing {yellow}{$inv}{gray}.");
                $amount = $inv;
                $amount_str = $inv;
            }
        } else {
            $amount = $inv;
            $amount_str = $inv;
        }
        umc_echo("{yellow}[!]{gray} You have {yellow}{$inv}{gray} items in your inventory, depositing {yellow}{$amount}");
        // check if recipient has space
        $userlevel = umc_get_uuid_level($recipient_uuid);
        $allowed = $UMC_SETTING['depositbox_limit'][$userlevel];
        $remaining = umc_depositbox_checkspace($recipient_uuid, $userlevel);
        $count = $allowed - $remaining;
        // umc_echo("Group: $userlevel Allowed: $allowed Remaining $remaining");
        $sql = "SELECT * FROM minecraft_iconomy.deposit\r\n            WHERE item_name='{$item['item_name']}' AND recipient_uuid='{$recipient_uuid}'\r\n            AND damage='{$data}' AND meta='{$meta}' AND sender_uuid='{$uuid}';";
        $D = umc_mysql_fetch_all($sql);
        // create the seen entry so we do not do this again
        $seen[$item['full']] = 1;
        // check first if item already is being sold
        if (count($D) > 0) {
            $row = $D[0];
            umc_echo("{green}[+]{gray} You already have {$item['full']}{gray} in the deposit for {gold}{$recipient}{gray}, adding {yellow}{$amount}{gray}.");
            $sql = "UPDATE minecraft_iconomy.`deposit` SET `amount`=amount+'{$amount}' WHERE `id`={$row['id']} LIMIT 1;";
        } else {
            //check if recipient has space
            if ($count >= $allowed && $player != 'uncovery' && $recipient != 'lot_reset') {
                if (!$sent_out_of_space_msg) {
                    umc_echo("{red}[!] {gold}{$recipient}{gray} does not have any more deposit spaces left " . "(Used {white}{$count} of {$allowed}{gray} available for group {white}{$userlevel}{gray})!");
                    $sent_out_of_space_msg = 1;
                }
                continue;
            }
            // check if recipient is an active user
            $target_active = umc_user_countlots($recipient);
            if ($target_active == 0 && $recipient != 'lot_reset') {
                umc_error("{red}[!] {gold}{$recipient}{gray} is not an active user, so you cannot deposit items for them!");
            }
            // create a new deposit box
            if (strlen($item['item_name']) < 3) {
                XMPP_ERROR_trigger("Error depositing, item name too short!");
                umc_error("There was an error with the deposit. Please send a ticket to the admin so this can be fixed.");
            }
            $text = "{green}[+]{gray} Depositing {yellow}{$amount_str} {$item['full']}{gray} for {gold}{$recipient}";
            umc_echo($text);
            $sql = "INSERT INTO minecraft_iconomy.`deposit` (`damage` ,`sender_uuid` ,`item_name` ,`recipient_uuid` ,`amount` ,`meta`)\r\n                    VALUES ('{$data}', '{$uuid}', '{$item['item_name']}', '{$recipient_uuid}', '{$amount}', '{$meta}');";
            $count++;
            umc_log("Deposit", "do_deposit", $text);
        }
        umc_mysql_query($sql, true);
        umc_clear_inv($item['item_name'], $data, $amount, $meta);
    }
    if ($recipient == 'lot_reset') {
        $allowed = 'unlimited';
    }
    umc_echo("{green}[+]{gray} You have now used {white}{$count} of {$allowed}{gray} deposit boxes");
}
コード例 #2
0
/**
 * Buy items
 *
 * @global type $UMC_USER
 * @param type $to_deposit
 * @return type
 */
function umc_do_buy_internal($to_deposit = false)
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $uuid = $UMC_USER['uuid'];
    $userlevel = $UMC_USER['userlevel'];
    // we check first if the deposit is empty before we allow trading
    $remaining = umc_depositbox_checkspace($uuid, $userlevel);
    $minimum = 0;
    if ($to_deposit) {
        $minimum = 1;
    }
    if ($remaining < $minimum) {
        umc_log("shop", "cancel_sale", "sale cancelled, inventory full");
        umc_error("You cannot trade items if your deposit is overfilled!");
    }
    $do_check = false;
    $pos = array_search('check', $args);
    if ($pos) {
        $do_check = true;
        array_splice($args, $pos, 1);
    }
    if (!isset($args[2])) {
        umc_show_help();
        return;
    } elseif (!is_numeric($args[2])) {
        umc_error("{red}Invalid shop_id: '{yellow}{$args[2]}{red}'. Did you mean '{yellow}/find {$args[2]}{red}'?;");
    }
    $id = $args[2];
    if (!isset($args[3])) {
        umc_echo("{yellow}[!]{gray} You did not enter an amount. Attempting to buy all.");
        $amount = false;
    }
    $amount = umc_sanitize_input($args[3], 'amount');
    $sql = "SELECT * FROM minecraft_iconomy.stock WHERE id='{$id}' LIMIT 1;";
    $data_row = umc_mysql_fetch_all($sql);
    if (count($data_row) == 0) {
        umc_error("Sorry, there is no shop ID {$id}! Please try again.");
    }
    $row = $data_row[0];
    $seller = umc_user2uuid($row['uuid']);
    $item = umc_goods_get_text($row['item_name'], $row['damage'], $row['meta']);
    if ($row) {
        if (!$amount && $row['amount'] == -1) {
            umc_error("{red}That item has an unlimited supply. Please enter an amount!;");
        }
        if ($row['uuid'] == $uuid && $player != 'uncovery') {
            umc_error("{red}You cannot buy your own goods. Use {yellow}/cancel <id>{red} instead!;");
        }
        if (!$amount || $amount > $row['amount'] && $row['amount'] != -1) {
            // buy as much as possible
            $amount = $row['amount'];
        }
        $sum = $amount * $row['price'];
        if ($do_check) {
            umc_echo("{white}[?] {gray}Buying {yellow}{$amount} {$item['full']}{gray} for {cyan}{$row['price']}{gray} each from {gold}{$seller}");
        } else {
            umc_echo("{green}[+] {gray}Buying {yellow}{$amount} {$item['full']}{gray} for {cyan}{$row['price']}{gray} each from {gold}{$seller}");
        }
        $balance = umc_money_check($player);
        if ($balance < $sum) {
            umc_echo("{red}[!]{gray} Insufficient funds ({white}{$sum}{gray} needed).;{purple}[?]{white} Why don't you vote for the server and try again?");
        } else {
            $new_balance = $balance - $sum;
            if ($do_check) {
                umc_echo("{white}[?]{gray} You would have {green}{$new_balance} Uncs{gray} remaining after spending {cyan}{$sum}", true);
                return;
            }
            if (!$to_deposit) {
                umc_check_space($amount, $item['item_name'], $item['type']);
            }
            umc_echo("{green}[+]{gray} You have {green}{$new_balance} Uncs{gray} remaining after spending {cyan}{$sum}");
            // transfer money player1 > player2
            umc_money($uuid, $row['uuid'], $sum);
            $seller = umc_user2uuid($row['uuid']);
            umc_log('shop', 'buy', "{$player} bought from {$seller}/{$row['uuid']} {$amount} {$item['full_clean']} for {$sum}, money was tranferred");
            // give goods to player1
            $leftover = umc_checkout_goods($id, $amount, 'stock', false, $to_deposit);
            $msg = "{$player} bought {$amount} {$item['name']} for {$row['price']} Uncs/pcs (= {$sum} Uncs)! {$leftover} left in stock!;";
            umc_msg_user($seller, $msg);
        }
    } else {
        umc_error("{red}The shop-id {white}{$id}{red} could not be found. Please use {yellow}/find{red} and{yellow} /shophelp buy;");
    }
}