/** * 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; } }
/** * * @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'); }
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); }
function umc_depositbox_consolidate() { global $UMC_USER; $uuid = $UMC_USER['uuid']; // find all doupliecate entries $sql_doubles = " SELECT count(id) AS counter, item_name, damage, meta\r\n FROM minecraft_iconomy.deposit\r\n WHERE recipient_uuid='{$uuid}'\r\n GROUP BY item_name, damage, meta HAVING COUNT(id) > 1"; $doubles = umc_mysql_fetch_all($sql_doubles); $source_boxes = count($doubles); $target_boxes = 0; if ($source_boxes > 0) { foreach ($doubles as $row) { // then we take each entry that is not created by the user and move it to a box created by the user $sql_fix = "SELECT * FROM minecraft_iconomy.deposit\r\n WHERE item_name='{$row['item_name']}'\r\n\t\t AND damage='{$row['damage']}\r\n\t\t AND meta='{$row['meta']}\r\n\t\t AND recipient_uuid='{$uuid}'\r\n\t\t AND sender_uuid !='{$uuid}';;"; $fix_data = umc_mysql_fetch_all($sql_fix); if (count($fix_data) > 0) { $target_boxes++; foreach ($fix_data as $fix_row) { umc_db_take_item('deposit', $fix_row['id'], $fix_row['amount'], $uuid); umc_deposit_give_item($uuid, $fix_row['item_name'], $fix_row['damage'], $fix_row['meta'], $fix_row['amount'], $uuid); } } } } if ($source_boxes > 0) { umc_echo("{green}[+]{gray} Found {yellow}{$source_boxes}{gray} items spread over several boxes consolidated them to {$target_boxes} deposit boxes!."); } else { umc_echo("{yellow}[?]{gray} Unable to consolidate depositbox, no compatible items found."); } }
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!;"; }