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_get_code() { $pass = umc_random_code_gen(); $sql = "SELECT * FROM minecraft_iconomy.story WHERE code='{$pass}';"; $D3 = umc_mysql_fetch_all($sql); $count = count($D3); if ($count > 0) { umc_get_code(); } return $pass; }