function umc_hardcore_commit()
{
    global $UMC_USER;
    $uuid = $UMC_USER['uuid'];
    $rates = array('diamond_block' => 100);
    // always the current item
    $all_inv = $UMC_USER['inv'];
    $item_slot = $UMC_USER['current_item'];
    if (!isset($all_inv[$item_slot])) {
        umc_error("{red}You need to hold the item you want to commit! (current slot: {$item_slot});");
    }
    // current held item
    $curr_item = $all_inv[$item_slot];
    if (isset($rates[$curr_item['item_name']])) {
        $inv = umc_check_inventory($curr_item['item_name'], $curr_item['data'], $curr_item['meta']);
        $amount = $inv;
        $block_value = $rates[$curr_item['item_name']];
        $item_txt = umc_goods_get_text($curr_item['item_name'], 0);
        umc_echo("{yellow}[!]{gray} You have {yellow}{$inv} {$item_txt['full_clean']}{gray} in your inventory, committing {yellow}{$amount}{gray} for {yellow}{$block_value}{gray} points each");
        umc_clear_inv($curr_item['item_name'], 0, $inv);
        $points = $inv * $block_value;
        umc_echo("{yellow}[!]{gray} You received {$points} points for this commit!");
        // get current period
        $P = umc_hardcore_get_period();
        $score_sql = "UPDATE minecraft_srvr.hardcore\r\n            SET `score`=score+'{$points}'\r\n            WHERE `uuid`='{$uuid}' AND entry_date >= '{$P['start_date']}' AND entry_date < '{$P['end_date']}'\r\n            LIMIT 1;";
        umc_mysql_query($score_sql, true);
    } else {
        $itemlist = '';
        foreach ($rates as $item_name => $value) {
            $item_txt = umc_goods_get_text($item_name, 0);
            $itemlist .= $item_txt['full_clean'] . "({$value} points) ";
        }
        umc_error("You cannot commit this item. The list of acceptable items are:" . $itemlist);
    }
}
예제 #2
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");
}
/**
 * Return an array of the logged-in player's inventory
 *
 * @param json_data $inv_data
 * @return type
 */
function umc_ws_get_inv($inv_data)
{
    global $UMC_DATA_SPIGOT2ITEM, $UMC_DATA, $UMC_DATA_ID2NAME;
    // XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $inv = array();
    foreach ($inv_data as $item) {
        $slot = $item['Slot'];
        $inv[$slot] = array();
        $inv[$slot]['meta'] = false;
        foreach ($item as $name => $value) {
            if ($name == 'TypeName') {
                $item_typename = strtolower($item['TypeName']);
                if (isset($UMC_DATA_SPIGOT2ITEM[$item_typename])) {
                    $inv[$slot]['item_name'] = $UMC_DATA_SPIGOT2ITEM[$item_typename];
                } else {
                    if (isset($UMC_DATA[$item_typename])) {
                        $inv[$slot]['item_name'] = $item_typename;
                    } else {
                        $inv[$slot]['item_name'] = $UMC_DATA_ID2NAME[$item['Type']];
                        XMPP_ERROR_trigger("ITEM ISSUE: {$item_typename} not found in \$UMC_DATA, item {$item['Type']} : {$item['Durability']}, should be {$inv[$slot]['item_name']}");
                    }
                }
            } else {
                if ($name == "Type") {
                    $inv[$slot]['id'] = $item['Type'];
                } else {
                    if ($name == 'Durability') {
                        $name = 'data';
                        if ($value == -1) {
                            // case 1) saplings of dark oak harvested from minecart maniah have a -1 data
                            umc_clear_inv($data['item_name'], $data['data'], $data['amount']);
                            umc_echo("{red}You had a bugged item in your inventory, it had to be removed!");
                            XMPP_ERROR_trigger("Invalid item with -1 damage found!");
                        } else {
                            $inv[$slot][$name] = $value;
                        }
                    } else {
                        if ($name == 'Meta') {
                            foreach ($value as $meta_type => $meta_value) {
                                // enchantments
                                if ($meta_type == 'Enchantments' || $meta_type == 'EnchantmentStorage') {
                                    foreach ($meta_value as $ench_data) {
                                        $e_name = $ench_data['Name'];
                                        $inv[$slot]['meta'][$e_name] = $ench_data['Level'];
                                    }
                                }
                                if ($meta_type == 'BaseColor') {
                                    $inv[$slot]['meta'] = array($meta_value => $value['Patterns']);
                                }
                            }
                        } else {
                            $name = strtolower($name);
                            $inv[$slot][$name] = $value;
                        }
                    }
                }
            }
        }
    }
    return $inv;
}
예제 #4
0
function umc_do_sell_internal($from_deposit = false)
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $uuid = $UMC_USER['uuid'];
    if (!isset($args[2]) || !is_numeric($args[2])) {
        umc_error("{red}You need a valid shop_id to sell to a requester. Use {yellow}/find request ...;");
        umc_error("{red}Maybe you meant {yellow}/offer{red}, for posting an offer for sale in the shop.;");
    }
    $do_check = false;
    $pos = array_search('check', $args);
    if ($pos) {
        $do_check = true;
        array_splice($args, $pos, 1);
    }
    $id = $args[2];
    $sql_request = "SELECT * FROM minecraft_iconomy.request WHERE id='{$id}' LIMIT 1;";
    $request_data = umc_mysql_fetch_all($sql_request);
    if (count($request_data) == 0) {
        umc_error("{red}The shop-id {white}{$id}{red} could not be found. Please use {yellow}/find{red} and{yellow} /shophelp sell;");
    }
    $request = $request_data[0];
    $request_item = umc_goods_get_text($request['item_name'], $request['damage'], $request['meta']);
    if ($request['uuid'] == $uuid && $player != 'uncovery') {
        umc_error("{red}You cannot fulfill your own requests. Use {yellow}/cancel r <id>{red} instead!;");
    }
    // do we sell items from deposit?
    if ($from_deposit) {
        $depot_id = $args[3];
        array_splice($args, 3, 1);
        $sql = "SELECT * from minecraft_iconomy.deposit WHERE recipient_uuid='{$uuid}' and id='{$depot_id}'";
        $D = umc_mysql_fetch_all($sql);
        if (count($D) < 1) {
            umc_error("You have no such deposit ID");
        }
        $depot_row = $D[0];
        $inv = $depot_row['amount'];
        $depot_item = umc_goods_get_text($depot_row['item_name'], $depot_row['damage'], $depot_row['meta']);
        if ($depot_item != $request_item) {
            //umc_echo("{green}$type:$data {gray} => {red}".$check_inv[$item_slot]['id'].":".$check_inv[$item_slot]['data']);
            umc_error("{red}The item in deposit-id {white}{$depot_id}{red} doesn't match request {white}{$id}{red}.");
        }
    } else {
        $item_slot = $UMC_USER['current_item'];
        $check_inv = $UMC_USER['inv'];
        if (!isset($check_inv[$item_slot])) {
            umc_error("{red}You need to hold the item you want to sell!;");
        }
        $inv_item = umc_goods_get_text($check_inv[$item_slot]['id'], $check_inv[$item_slot]['data'], $check_inv[$item_slot]['meta']);
        if ($inv_item != $request_item) {
            //umc_error_longmsg("Sell failed");
            //umc_echo("{green}$type:$data {gray} => {red}".$check_inv[$item_slot]['id'].":".$check_inv[$item_slot]['data']);
            umc_error("{red}The item you're holding doesn't match request id {white}{$id}{red}.");
        }
    }
    if (!isset($args[3])) {
        umc_echo("{yellow}[!]{gray} You did not enter an amount. Attempting to sell all.");
        $amount = false;
    } else {
        $args[3] = intval($args[3]);
        $amount = umc_sanitize_input($args[3], 'amount');
    }
    if (!$amount) {
        // sell as much as possible
        $amount = $request['amount'];
    }
    if ($amount > $request['amount']) {
        umc_error("{red}That's too much, the request is only for {yellow}{$request['amount']}{red} pieces.");
    }
    if (!$from_deposit) {
        $inv = umc_check_inventory($request_item['item_name'], $request_item['type'], $request_item['meta']);
        if ($inv == 0) {
            umc_error("{red}You don't have any of the requested item.");
        }
    }
    if ($inv < $amount) {
        umc_echo("{yellow}[!]{gray} Not enough for entire request.  Selling as much as possible.");
        $amount = $inv;
    }
    $recipient_uuid = $request['uuid'];
    $recipient = umc_user2uuid($recipient_uuid);
    if ($do_check) {
        umc_echo("{white}[?]{gray} This would sell {yellow}{$amount} {$request_item['full']}{darkgray} for {cyan}{$request['price']}{gray} each to {gold}{$recipient}");
        $sum = $amount * $request['price'];
        umc_echo("{white}[?]{gray} Your account would be credited {cyan}{$sum}{gray} Uncs.");
        return;
    }
    umc_echo("{green}[+] {gray}Selling {yellow}{$amount} {$request_item['full']}{darkgray} for {cyan}{$request['price']}{gray} each to {gold}{$recipient}");
    if ($from_deposit) {
        umc_db_take_item('deposit', $depot_id, $amount, $uuid);
    } else {
        umc_clear_inv($request_item['item_name'], $request_item['type'], $amount, $request_item['meta']);
    }
    $sum = $amount * $request['price'];
    umc_money(false, $player, $sum);
    umc_echo("{green}[\$]{gray} Your account has been credited {cyan}{$sum}{gray} Uncs.");
    $sql = "SELECT * FROM minecraft_iconomy.deposit\r\n        WHERE item_name='{$request_item['item_name']}'\r\n\t    AND recipient_uuid='{$request['uuid']}'\r\n            AND damage='{$request_item['type']}'\r\n\t    AND meta='{$request_item['meta']}'\r\n\t    AND sender_uuid='shop0000-0000-0000-0000-000000000000';";
    $D = umc_mysql_fetch_all($sql);
    // check first if item already is in the recipient's deposit
    if (count($D) > 0) {
        $update_row = $D[0];
        umc_echo("{green}[+]{gray} There is already {$request_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`={$update_row['id']} LIMIT 1;";
    } else {
        // create a new deposit box
        umc_echo("{green}[+]{gray} Depositing {yellow} {$amount} {$request_item['full']}{gray} for {gold}{$recipient}");
        $sql = "INSERT INTO minecraft_iconomy.`deposit` (`damage` ,`sender_uuid` ,`item_name` ,`recipient_uuid` ,`amount` ,`meta`)\r\n            VALUES ('{$request_item['type']}', 'shop0000-0000-0000-0000-000000000000', '{$request_item['item_name']}', '{$recipient_uuid}', '{$amount}', '{$request_item['meta']}');";
    }
    umc_mysql_query($sql, true);
    if ($amount < $request['amount']) {
        // Update existing listing
        $sql = "UPDATE minecraft_iconomy.`request` SET `amount`=amount-'{$amount}' WHERE id={$request['id']} LIMIT 1;";
        umc_mysql_query($sql, true);
        //umc_echo("{purple}".$sql);
        //umc_echo("{red}".mysql_error());
    } else {
        // Delete the listing entirely
        $sql = "DELETE FROM minecraft_iconomy.`request` WHERE id={$request['id']}";
        umc_mysql_query($sql, true);
        //umc_echo("{red}".mysql_error());
    }
    // record transaction
    umc_shop_transaction_record($uuid, $request['uuid'], $amount, $sum, $request_item['item_name'], $request_item['type'], $request_item['meta']);
    // message recipient
    $msg = "{$player} sold you {$amount} {$request_item['full']} per your request, check your /depotlist!;";
    umc_msg_user($recipient, $msg);
    // record logfile
    umc_log('shop', 'sell_on_request', "{$player} sold {$amount} of {$request_item['full_clean']} to {$recipient} (ID: {$request['id']})");
}