*
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*
 * This file creates a static array from the Essentials/items.csv file.
 * The items.csv file contains a dictionary of possible item names and their 
 * actual item ID and type ID. This is used for the /search command and the 
 * sanitization function in core_include.php. It needs to be run whenever the 
 * Essential plugin gets updated.
 */
require_once '/home/minecraft/server/bin/core_include.php';
// this here creates a new items array file
$search_arr = umc_item_data_get_namelist();
if (($handle = fopen("/home/minecraft/server/bukkit/plugins/Essentials/items.csv", "r")) !== FALSE) {
    while (($items = fgetcsv($handle, 10000, ",")) !== FALSE) {
        $firstletter = substr($items[0], 0, 1);
        if (count($items) == 3 && $firstletter !== '#' && !isset($search_arr[$items[0]])) {
            $item = umc_goods_get_text($items[1], $items[2]);
            $search_arr[$items[0]] = array('item_name' => $item['item_name'], 'type' => $item['type']);
        }
    }
    umc_array2file($search_arr, 'ITEM_SEARCH', '/home/minecraft/server/bin/includes/item_search.inc.php');
} else {
    die("Could not read items file!");
}
/**
 * Add items to a user inventory. If cancel=true, we check if the current user is owner of the goods
 *
 * @global type $UMC_USER
 * @param type $id
 * @param type $amount
 * @param type $table
 * @param boolean $cancel
 * @param type $to_deposit
 * @param string $uuid
 * @return string
 */
function umc_checkout_goods($id, $amount, $table = 'stock', $cancel = false, $to_deposit = false, $uuid = false)
{
    global $UMC_USER, $UMC_ENV;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if (!$uuid) {
        $player = $UMC_USER['username'];
        $uuid = $UMC_USER['uuid'];
    } else {
        $player = umc_user2uuid($uuid);
    }
    if (!is_numeric($id)) {
        umc_error('{red}Invalid ID. Please use {yellow}/shophelp;');
    }
    // the fact that the source is also a condition prevents people to cancel other users' items.
    if ($table == 'stock') {
        if ($cancel) {
            $sql = "SELECT * FROM minecraft_iconomy.stock WHERE uuid='{$uuid}' AND id='{$id}' LIMIT 1;";
        } else {
            $sql = "SELECT * FROM minecraft_iconomy.stock WHERE id='{$id}' LIMIT 1;";
        }
    } else {
        if ($table == 'deposit') {
            $sql = "SELECT * FROM minecraft_iconomy.deposit WHERE (sender_uuid='{$uuid}' OR recipient_uuid='{$uuid}') AND id='{$id}' LIMIT 1;";
        }
    }
    $D = umc_mysql_fetch_all($sql);
    if (count($D) == 0) {
        umc_error("{red}Id {white}{$id}{red} not found! Please try again.;");
    } else {
        $row = $D[0];
        $item = umc_goods_get_text($row['item_name'], $row['damage'], $row['meta']);
        $meta_cmd = $meta = '';
        if ($row['meta'] != '') {
            $meta_arr = unserialize($row['meta']);
            if (!is_array($meta_arr)) {
                XMPP_ERROR_trigger("Could not get Meta Data array for {$table} id {$id}: " . var_export($row, true));
            }
            if ($row['item_name'] == "banner") {
                $meta_cmd = umc_banner_get_data($meta_arr);
            } else {
                foreach ($meta_arr as $type => $lvl) {
                    $meta_cmd .= " {$type}:{$lvl}";
                }
            }
        }
        // handle unlimited items
        $unlimited = false;
        if ($row['amount'] == -1) {
            $row['amount'] = $amount;
            $unlimited = true;
        }
        //umc_echo('There were ' . $row['amount'] . " pieces of " . $item['item_name'] . "$meta_txt stored.");
        // determine withdrawal amount
        if (is_numeric($amount) && $amount <= $row['amount']) {
            $sellamount = $amount;
        } else {
            if ($amount == 'max') {
                // withdraw all
                $sellamount = $row['amount'];
                //umc_echo("You are withdrawing all ($sellamount) {$item['name']}$meta_txt");
            } else {
                if (is_numeric($amount) && $amount > $row['amount']) {
                    umc_echo("{yellow}[!]{gray} Available amount ({yellow}{$row['amount']}{gray}) less than amount specified ({yellow}{$amount}{gray})");
                    $sellamount = $row['amount'];
                } else {
                    umc_error("{red}Amount {white}'{$amount}'{red} is not numeric;");
                }
            }
        }
        if ($table != 'stock') {
            umc_echo("{green}[+]{gray} You are withdrawing {yellow} {$amount} {gray} of {$item['full']}{gray}.");
        }
        if ($table == 'stock') {
            $cost = $sellamount * $row['price'];
            if ($cancel) {
                $target = $uuid;
                $source = 'cancel00-sell-0000-0000-000000000000';
            } else {
                $target = $uuid;
                $source = $row['uuid'];
            }
        } else {
            if ($table == 'deposit') {
                if ($row['recipient_uuid'] == $uuid) {
                    $cancel = true;
                }
                $cost = 0;
                if ($cancel) {
                    $target = $uuid;
                    $source = 'cancel00-depo-0000-0000-000000000000';
                } else {
                    $target = $row['recipient_uuid'];
                    $source = $row['sender_uuid'];
                }
            }
        }
        if (!$to_deposit) {
            umc_check_space($sellamount, $item['item_name'], $item['type']);
            // the in-game command does not understand item_names yet
            umc_ws_cmd("give {$player} {$item['item_name']}:{$item['type']} {$sellamount}{$meta_cmd};", 'asConsole');
            umc_log('inventory', 'give', "{$player} received {$item['full_clean']} {$sellamount}");
        } else {
            umc_deposit_give_item($target, $item['item_name'], $item['type'], $meta, $sellamount, $source);
            umc_log('inventory', 'give_deposit', "{$player} recived in deposit {$item['full_clean']} {$sellamount}");
        }
        //umc_echo("./give $player {$item['id']}:{$item['type']} $sellamount$meta_cmd");
        // check status
        umc_shop_transaction_record($source, $target, $sellamount, $cost, $item['item_name'], $item['type'], $meta);
        if ($unlimited) {
            return "unlimited";
        }
        // fix the stock levels
        $amount_left = umc_db_take_item($table, $id, $sellamount, $source);
        if ($UMC_ENV == 'websend') {
            if ($amount_left == 0) {
                umc_echo("{green}[+]{gray} No more {green}{$item['full']}{gray} now in stock.");
            } else {
                umc_echo("{green}[+]{yellow} {$amount_left}{green} {$item['full']}{gray} remaining in stock.");
            }
        }
        return $amount_left;
    }
}
function umc_shopmgr_goods_detail($item, $type)
{
    $item_arr = umc_goods_get_text($item, $type);
    $out = $item_arr['full'] . "<hr>\n";
    // show stock
    $out .= umc_shopmgr_stocklist('stock', $item, $type, false);
    //show requests
    $out .= umc_shopmgr_stocklist('request', $item, $type, false);
    return $out;
}
/**
 *
 * @global type $UMC_USER
 * @param type $contest_id contest number to choose from
 * @param type $lot_name contest entry to refund
 * @param type $reset if true, the lot will be reset
 */
function umc_contests_refund($contest_id, $lot_name, $reset)
{
    global $UMC_USER, $UMC_PATH_MC;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    umc_echo("Processing Contest lot {$lot_name}:");
    $entry_id = explode("_", $lot_name);
    $entry_id = $entry[2];
    $sql = "SELECT * FROM minecraft_worldguard.region_cuboid LEFT JOIN minecraft_worldguard.world ON region_cuboid.world_id=world.id WHERE region_id = '{$lot_name}';";
    $rst = mysql_query($sql);
    $lot = mysql_fetch_array($rst, MYSQL_ASSOC);
    $world_id = $lot['world_id'];
    $world_name = $lot['name'];
    $owners = umc_region_check_Owners($world_id, $lot_name);
    $owner = $owners[0];
    $server_path = "{$UMC_PATH_MC}/server";
    $data_path = $server_path . '/minecount/output/' . $lot_name . '.json';
    // read data
    if (!file_exists($data_path)) {
        umc_error("Could not find file {$data_path}");
    }
    $data = file_get_contents($data_path);
    $data = json_decode($data);
    $convert_array = array(2 => 3, 26 => 355, 55 => 331, 59 => 295, 60 => 3, 62 => 61, 63 => 323, 64 => 324, 75 => 76, 68 => 323, 71 => 330, 74 => 73, 78 => 332, 83 => 338, 93 => 356, 94 => 356, 104 => 361, 105 => 362, 115 => 372, 117 => 379, 118 => 380, 124 => 123, 25 => 126, 132 => 287);
    umc_echo("Beginning refund of items in area {$lot_name} to owner {$owner}");
    foreach ($data as $block => $amount) {
        $block_data = explode(".", $block);
        // get block data from JSON
        $block = $block_data[0];
        $data = 0;
        if (isset($block_data[1])) {
            $data = $block_data[1];
        }
        // convert to local function blockdata
        $id = $block;
        $damage = $data;
        // process
        // umc_echo("incoming: $amount of $name (ID: $id:$damage) ($block)");
        switch ($id) {
            case 0:
                // invalid blocks, convert to 0 amount
            // invalid blocks, convert to 0 amount
            case 8:
            case 9:
            case 10:
            case 11:
            case 18:
                // we skip grass, but it should be fixed!
            // we skip grass, but it should be fixed!
            case 19:
            case 30:
            case 31:
            case 34:
            case 51:
            case 52:
            case 90:
            case 92:
            case 95:
            case 97:
            case 119:
            case 120:
            case 122:
            case 137:
            case 401:
                // fireworks
                // umc_echo("Skipped $amount of block $name");
                $amount = 0;
                break;
            case 18:
                // leaves have data 4:
                //$damage = 4;
                break;
            case 29:
            case 33:
                $damage = 7;
                break;
            case 26:
            case 71:
            case 64:
                if ($damage > 7) {
                    // skip bed 2nd half
                    continue;
                }
                //reset data value (rotation etc)
            //reset data value (rotation etc)
            case 53:
            case 25:
                // noteblocks needs to be tested!
            // noteblocks needs to be tested!
            case 65:
            case 67:
            case 108:
            case 109:
            case 114:
            case 128:
            case 134:
            case 135:
            case 136:
                $damage = 0;
                break;
            case 127:
                $id = 351;
                $damage = 3;
                break;
            case 43:
                $id = 44;
                $amount = $amount * 2;
                break;
        }
        if ($amount > 0) {
            if (isset($convert_array[$id])) {
                $id_new = $convert_array[$id];
                // umc_echo("Converted $id to $id_new");
                $id = $id_new;
            }
            $data_new = umc_goods_get_text($id, $damage);
            if (!$data_new) {
                umc_error("Could not find data for {$block}:{$data}");
            }
            $name = $data_new['item_name'];
            $full = $data_new['full'];
            $damage = $data_new['type'];
            umc_echo("Giving: {$amount} of {$full}");
            umc_deposit_give_item($owner, $name, $damage, '', $amount, 'Contest ' . $lot_name . " refunds");
        } else {
            // umc_echo("Amount 0 for $amount of $name (ID: $id:$damage");
        }
    }
    umc_echo("Resetting non-submitted entry {$lot_name}");
    $sql = "DELETE FROM `minecraft_worldguard`.`region` WHERE `region`.`id` = '{$lot_name}' AND `region`.`world_id` = {$world_id}";
    $rst = mysql_query($sql);
    echo mysql_error();
    umc_ws_cmd("region select {$lot_name}", 'asPlayer');
    umc_ws_cmd("region load -w {$world_name}", 'asPlayer');
    // umc_ws_cmd("ws contest warp $contest_id $entry_id", 'asPlayer');
}
Example #5
0
function umc_web_table_format_column($name, $value)
{
    global $ENCH_ITEMS, $UMC_DOMAIN, $UMC_DATA, $UMC_DATA_ID2NAME;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $people_types = array('username', 'buyer', 'seller', 'sender', 'recipient');
    $uuid_types = array('vendor', 'requestor');
    if ($name == 'item_name') {
        $id_parts = explode("|", $value);
        $item_arr = umc_goods_get_text($id_parts[0], $id_parts[1], $id_parts[2]);
        if (!$item_arr) {
            XMPP_ERROR_send_msg("Could not identify {$name} {$value} for web table");
        }
        $type = "&amp;type={$id_parts[1]}";
        $out = "<a href=\"?page=goods&amp;item={$id_parts[0]}{$type}\">" . $item_arr['full'] . "</a>\n";
        return $out;
    } else {
        if ($name == 'item') {
            $meta = '';
            $id_parts = explode("|", $value);
            if (is_numeric($id_parts[0])) {
                $item_name = $UMC_DATA_ID2NAME[$id_parts[0]];
            } else {
                $item_name = $id_parts[0];
            }
            $item = umc_goods_get_text($item_name, $id_parts[1]);
            $item_dmg = $id_parts[1];
            $item_meta = $id_parts[2];
            if ($item_dmg == '' || isset($UMC_DATA[$item_name]['damage']) && $UMC_DATA[$item_name]['damage'] > 0) {
                // damage item have dmg id 0 for icon
                $item_dmg = 0;
            }
            if ($item_meta != '') {
                $meta = unserialize($item_meta);
                $meta_list = array();
                foreach ($meta as $type => $level) {
                    $nice_meta = $ENCH_ITEMS[$type]['short'];
                    array_push($meta_list, "{$nice_meta} {$level}");
                }
                $meta = ", " . implode(", ", $meta_list);
            }
            if (isset($UMC_DATA[$item_name]['subtypes']) && $UMC_DATA[$item_name]['subtypes'][$item_dmg]['icon_url'] == '?') {
                $icon_dmg = 0;
            } else {
                $icon_dmg = $item_dmg;
            }
            if ($item['name']) {
                $text = "{$item['icon']}&nbsp;" . $item['name'] . $meta;
            } else {
                $text = "({$value})";
            }
            $out = "<a href=\"{$UMC_DOMAIN}/trading/shop/?query=stock_detail&amp;item={$item_name}\">{$text}</a>\n";
            return $out;
        } else {
            if (in_array($name, $people_types)) {
                // if ($value == '')
                $icon_url = umc_user_get_icon_url($value);
                return "<a href=\"?page=users&amp;user={$value}\"><img title='{$value}' src='{$icon_url}' width=\"16\" alt=\"{$value}\">&nbsp;{$value}</a>";
            } else {
                if (in_array($name, $uuid_types)) {
                    $username = umc_user2uuid($value);
                    $icon_url = umc_user_get_icon_url($username);
                    return "<a href=\"?page=users&amp;user={$username}\"><img title='{$username}' src='{$icon_url}' width=\"16\" alt=\"{$username}\">&nbsp;{$username}</a>";
                } else {
                    if (preg_match("/price/i", $name)) {
                        return number_format($value, 2, ".", "");
                    } else {
                        if ($name == 'quantity' && $value < 1) {
                            return "&infin;";
                        }
                    }
                }
            }
        }
    }
    return $value;
}
function umc_lottery()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $lottery, $ENCH_ITEMS;
    $user_input = $UMC_USER['args'][2];
    // check if there is a valid user on the server before applying the vote.
    $user = umc_check_user($user_input);
    if (!$user) {
        umc_log("lottery", "voting", "user {$user} does not exist");
        return false;
    }
    // get the voting players uuid
    $uuid = umc_user2uuid($user);
    // give reinforcing feedback - set subtitle (not displayed)
    $subtitle = 'title ' . $user . ' subtitle {text:"Thanks for your vote!",color:gold}';
    umc_ws_cmd($subtitle, 'asConsole');
    // display the feedback - displays subtitle AND title
    $title = 'title ' . $user . ' title {text:"+100 Uncs",color:gold}';
    umc_ws_cmd($title, 'asConsole');
    // allow uncovery to test chance rolls for debugging purposes
    $chance = false;
    if ($user == 'uncovery' && isset($UMC_USER['args'][5])) {
        $chance = $UMC_USER['args'][5];
    }
    // get the roll array based on chance
    $roll = umc_lottery_roll_dice($chance);
    // umc_echo(umc_ws_vardump($roll));
    // define the rewards and item more legibly
    $item = $roll['item'];
    $luck = $roll['luck'];
    $prize = $lottery[$item];
    //echo "type = {$prize['type']}<br>;";
    //echo "complete chance: $chance<br>;";
    //var_dump($prize);
    // get the metadata if required for the item
    if (isset($prize['detail'])) {
        $detail = $prize['detail'];
    }
    $type = $prize['type'];
    // always give 100 uncs irrespective of roll.
    umc_money(false, $user, 100);
    // instantiate block variables
    $given_block_data = 0;
    $given_block_type = 0;
    //var_dump($prize);
    // based on item type, give reward to the player
    switch ($type) {
        case 'item':
            umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'additional_home':
            $newname = 'lottery' . "_" . umc_random_code_gen(4);
            umc_home_add($uuid, $newname, true);
            $item_txt = "an addtional home!!";
            break;
        case 'random_unc':
            $luck2 = mt_rand(1, 500);
            umc_money(false, $user, $luck2);
            $item_txt = "{$luck2} Uncs";
            break;
        case 'random_potion':
            $luck2 = mt_rand(0, 63);
            umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_ench':
            // pick which enchantment
            $rand_ench = array_rand($ENCH_ITEMS);
            $ench_arr = $ENCH_ITEMS[$rand_ench];
            //pick which item to enchant
            $rand_item = array_rand($ench_arr['items']);
            $rand_item_id = $ench_arr['items'][$rand_item];
            // pick level of enchantment
            $lvl_luck = mt_rand(1, $ench_arr['max']);
            //echo "$item $ench_txt $lvl_luck";
            $item_ench_arr = array($rand_ench => $lvl_luck);
            $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr);
            $item_name = $item['item_name'];
            $full = $item['full'];
            umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery');
            $item_txt = "a " . $full;
            break;
        case 'random_pet':
            // same as blocks below but only 1 always
            umc_echo($type);
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "a " . $item['full'];
            break;
        case 'random_common':
        case 'random_ore':
        case 'random_manuf':
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $luck3 = mt_rand(1, 64);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "{$luck3} " . $item['full'];
            break;
    }
    if ($user != 'uncovery') {
        // testing only
        $item_nocolor = umc_ws_color_remove($item_txt);
        umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole');
        umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})");
        $userlevel = umc_get_userlevel($user);
        if (in_array($userlevel, array('Settler', 'Guest'))) {
            $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!";
            umc_msg_user($user, $msg);
        }
    } else {
        umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!");
    }
    // add vote to the database
    $service_raw = strtolower($UMC_USER['args'][3]);
    // fix service
    $search = array('http://www.', 'https://www.', 'http://', 'https://');
    $service = umc_mysql_real_escape_string(str_replace($search, '', $service_raw));
    // sql log
    $sql_reward = umc_mysql_real_escape_string($type);
    $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]);
    $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`, `roll_value`, `reward`)\r\n        VALUES ('{$uuid}', NOW(), {$service}, {$ip}, {$luck}, {$sql_reward});";
    umc_mysql_query($sql, true);
}
Example #7
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");
}
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);
    }
}
Example #9
0
function umc_logores_item_name($type, $data = 0)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $item_arr = umc_goods_get_text($type, $data);
    if (!$item_arr) {
        return "{$type}:{$data}";
    }
    return $item_arr['name'];
}
function umc_skyblock_inv_to_desc($inv)
{
    $inv_arr = unserialize($inv);
    // aggregate items
    $out_arr = array();
    foreach ($inv_arr as $data) {
        $id = $data['id'];
        $type = $data['data'];
        $amount = $data['amount'];
        $meta = $data['meta'];
        if (isset($out_arr[$id][$type][$meta])) {
            $out_arr[$id][$type][$meta] += $amount;
        }
    }
    // now iterate and get text
    $meta = '';
    $final_arr = array();
    foreach ($out_arr as $id => $types) {
        foreach ($types as $type => $metas) {
            $item = umc_goods_get_text($id, $type);
            $final_arr[] = "{$amount} " . $item['full'];
        }
    }
    return implode(", ", $final_arr);
}
Example #11
0
function umc_lottery()
{
    //  umc_error_notify("User $user, $chance (umc_lottery)");
    global $UMC_USER, $lottery, $ENCH_ITEMS;
    $user_input = $UMC_USER['args'][2];
    $user = umc_check_user($user_input);
    if (!$user) {
        umc_log("lottery", "voting", "user {$user} does not exist");
        return false;
    }
    $uuid = umc_user2uuid($user);
    $chance = false;
    if ($user == 'uncovery' && isset($UMC_USER['args'][3])) {
        $chance = $UMC_USER['args'][3];
    }
    $roll = umc_lottery_roll_dice($chance);
    // umc_echo(umc_ws_vardump($roll));
    $item = $roll['item'];
    $luck = $roll['luck'];
    $prize = $lottery[$item];
    //echo "type = {$prize['type']}<br>;";
    //echo "complete chance: $chance<br>;";
    //var_dump($prize);
    if (isset($prize['detail'])) {
        $detail = $prize['detail'];
    }
    $type = $prize['type'];
    // always give 100 uncs
    umc_money(false, $user, 100);
    $given_block_data = 0;
    $given_block_type = 0;
    //var_dump($prize);
    switch ($type) {
        case 'item':
            umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_unc':
            $luck2 = mt_rand(1, 500);
            umc_money(false, $user, $luck2);
            $item_txt = "{$luck2} Uncs";
            break;
        case 'random_potion':
            $luck2 = mt_rand(0, 63);
            umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_ench':
            // pick which enchantment
            $rand_ench = array_rand($ENCH_ITEMS);
            $ench_arr = $ENCH_ITEMS[$rand_ench];
            //pick which item to enchant
            $rand_item = array_rand($ench_arr['items']);
            $rand_item_id = $ench_arr['items'][$rand_item];
            // pick level of enchantment
            $lvl_luck = mt_rand(1, $ench_arr['max']);
            //echo "$item $ench_txt $lvl_luck";
            $item_ench_arr = array($rand_ench => $lvl_luck);
            $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr);
            $item_name = $item['item_name'];
            $full = $item['full'];
            umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery');
            $item_txt = "a " . $full;
            break;
        case 'random_pet':
            // same as blocks below but only 1 always
            umc_echo($type);
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "a " . $item['full'];
            break;
        case 'random_common':
        case 'random_ore':
        case 'random_manuf':
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $luck3 = mt_rand(1, 64);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "{$luck3} " . $item['full'];
            break;
    }
    if ($user != 'uncovery') {
        // testing only
        $item_nocolor = umc_ws_color_remove($item_txt);
        umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole');
        umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})");
        $userlevel = umc_get_userlevel($user);
        if (in_array($userlevel, array('Settler', 'Guest'))) {
            $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!";
            umc_msg_user($user, $msg);
        }
    } else {
        umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!");
    }
    // add vote to the database
    $service = umc_mysql_real_escape_string($UMC_USER['args'][3]);
    $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]);
    $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`)\r\n        VALUES ('{$uuid}', NOW(), {$service}, {$ip});";
    umc_mysql_query($sql, true);
    // echo "$user voted for the server and got $item_txt!;";
}
/**
 * Create a request
 *
 * @global type $UMC_USER
 * @return type
 */
function umc_do_request()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    // this returns a item_array already
    $item_check = umc_sanitize_input($args[2], 'item');
    if (!$item_check) {
        umc_error("{red}Unknown item ({yellow}{$args['2']}{red}). Try using {yellow}/search{red} to find names.");
    } else {
        XMPP_ERROR_trace("item_check", $item_check);
        $item = umc_goods_get_text($item_check['item_name'], $item_check['type']);
    }
    $item_name = $item['item_name'];
    $type = $item['type'];
    $meta = '';
    $meta_txt = '';
    $do_check = false;
    $pos = array_search('check', $args);
    if ($pos) {
        $do_check = true;
        array_splice($args, $pos, 1);
    }
    // TODO: This should be checking for the item type instead of assuming 0
    //if ($UMC_ITEMS[$type][0]['avail'] == false) {
    //    umc_error("{red}Sorry, this item (ID $type) is unavailable in the game!",true);
    //}
    $sql = "SELECT * FROM minecraft_iconomy.request\r\n        WHERE item_name='{$item_name}' AND damage='{$type}' AND meta='{$meta}' AND uuid='{$uuid}';";
    $sql_data = umc_mysql_fetch_all($sql);
    if (count($sql_data) == 0) {
        $row = false;
    } else {
        $row = $sql_data[0];
    }
    // buy item at same price, check if exists
    if (!isset($args[3])) {
        if ($row) {
            $price = $row['price'];
        } else {
            umc_error("{red}Since you do not have the same item already in the shop you need to specify a price.;");
        }
    } else {
        $price = umc_sanitize_input($args[3], 'price');
    }
    // check if an argument was given for amount.
    $amount = umc_sanitize_input($args[4], 'amount');
    if ($amount == NULL) {
        // buying 0 amount available is not possible
        umc_error("{red}You need to specify an amount, too!;");
    }
    $cost = $price * $amount;
    // if there is an existing row, recalculate price accordingly
    if ($row) {
        // give money back from the original request
        $refund = $row['amount'] * $row['price'];
        // calculate how much this one + the old item amount would cost
        $new_cost = ($amount + $row['amount']) * $price;
        // do the sum for the balance, can be negative
        $cost = $new_cost - $refund;
    }
    $balance = umc_money_check($uuid);
    if ($balance < $cost) {
        umc_error("{red}[!]{gray} Insufficient funds ({white}{$cost}{gray} needed). " . "{purple}[?]{white} Why don't you vote for the server and try again?");
    }
    if ($do_check) {
        if ($row) {
            $sum = $amount + $row['amount'];
            umc_echo("{white}[?]{gray} This would update your existing request to " . "{yellow}{$sum} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each.");
        } else {
            umc_echo("{white}[?]{gray} This would create a new request for " . "{yellow}{$amount} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each.");
        }
        if ($cost > 0) {
            umc_echo("{white}[?]{white} Your account would be charged {cyan}{$cost}{gray} Uncs.");
        } else {
            umc_echo("{white}[?]{white} Your account would be credited {cyan}" . $cost * -1 . "{gray} Uncs.");
        }
        return;
    }
    $sum = 0;
    $posted_id = 0;
    if ($row) {
        // Update existing listing
        $sum = $amount + $row['amount'];
        umc_echo("{green}[+]{gray} You already requested {yellow}" . "{$row['amount']} {$item['full']}{gray}. Adding another {yellow}{$amount}{gray}.");
        $sql = "UPDATE minecraft_iconomy.`request` SET `amount` = amount + '{$amount}', price='{$price}' WHERE id={$row['id']};";
        $rst = umc_mysql_query($sql);
        $posted_id = $row['id'];
    } else {
        // Create a new listing.
        $sum = $amount;
        umc_echo("{green}[+]{gray} You are now requesting {yellow}" . "{$sum} {$item['full']}{gray} in the shop.");
        $sql = "INSERT INTO minecraft_iconomy.`request` (`id` ,`damage` ,`uuid` ,`item_name` ,`price` ,`amount` ,`meta`)\r\n                VALUES (NULL , '{$type}', '{$uuid}', '{$item['item_name']}', '{$price}', '{$amount}', '{$meta}');";
        //XMPP_ERROR_trigger($sql);
        $rst = umc_mysql_query($sql);
        $posted_id = umc_mysql_insert_id();
    }
    if ($cost > 0) {
        umc_echo("{yellow}[\$]{white} Your account has been charged {cyan}{$cost}{gray} Uncs.");
    } else {
        umc_echo("{green}[\$]{white} Your account has been credited {cyan}" . $cost * -1 . "{gray} Uncs.");
    }
    umc_money($player, false, $cost);
    umc_announce("{gold}{$player}{gray} is {red}requesting to buy {yellow}{$sum}{$meta_txt}{green} " . "{$item['full']}{darkgray} @ {cyan}{$price}{gray} each{darkgray}, shop-id {gray}{$posted_id}");
}