function umc_hardcore_exit()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $C = $UMC_USER['coords'];
    if (abs($C['z']) >= 100 || abs($C['x']) >= 100) {
        umc_error("You need to be in the deathlands spawn area (100 blocks from the center)");
    }
    // get current period
    $P = umc_hardcore_get_period();
    $score_sql = "UPDATE minecraft_srvr.hardcore\r\n        SET `clean_exit` = 1\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);
    umc_ws_cmd("warp spawn {$player}");
}
/**
 * Buy XP in-game // function is still working with usernames instead of UUID since
 * the /xp command does not work with UUIDs (yet) *
 *
 * @global type $UMC_USER
 */
function umc_do_buyxp()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $xp_ratio = 1;
    // check to see if player has entered a value of xp to buy
    if (isset($args[2])) {
        // feedback on current xp point values
        $user_xp = $UMC_USER['xp'];
        umc_echo("{white} You started with {$user_xp} experience points.");
        // amount player is trying to spend
        $amount = $args[2];
        // cast argument to type int to sanitise the data
        settype($amount, 'int');
        // amount of xp calculated
        $xp = floor($amount * $xp_ratio);
        // retrieve the players balance to check if they can afford
        $balance = umc_money_check($player);
        if ($xp < 1 || $amount < 1) {
            umc_error("{red}You need to buy at least 1 XP. For {$amount} Uncs you get only {$xp} XP (ratio is {$xp_ratio}!)");
        }
        if ($amount > $balance) {
            umc_error("{red}Sorry, you cannot afford this purchase. You currently have {$balance} uncs.");
        }
        // calculate the total new xp point value
        $new_xp = $user_xp + $xp;
        // apply purchase
        // send the console command to give the player experience
        umc_ws_cmd("exp set {$player} {$new_xp}", 'asConsole');
        // take the purchase amount from players account.
        // take from, give to, positive value
        umc_money($player, false, $amount);
        // announce the purchase to encourage players to consider buying xp
        umc_announce("{gold}{$player}{gray} just bought {purple}{$xp} XP{gray} for{cyan} {$amount} Uncs{gray}!");
        umc_echo("{white} You ended with {$new_xp} experience points.");
        // log the purchase
        umc_log('buyxp', 'buy', "{$player} paid {$amount} for {$xp} XP, going from {$user_xp} to {$new_xp}");
    } else {
        umc_error("{red}You need to specify the amount of Uncs you want to spend. See {yellow}/helpme buyxp");
    }
}
Exemple #3
0
function umc_home_warp()
{
    global $UMC_USER;
    $playerworld = $UMC_USER['world'];
    $args = $UMC_USER['args'];
    // no home name given
    if (!isset($args[2])) {
        // check if the user has only one home
        $home_count = umc_home_count();
        if ($home_count > 1) {
            umc_error("{red}You need to specify the name of your home!");
        } else {
            if ($home_count == 0) {
                umc_error("{red}You do not have any homeslots yet!");
            } else {
                $sql = "SELECT * FROM minecraft_srvr.homes WHERE uuid='{$UMC_USER['uuid']}' LIMIT 1;";
            }
        }
    } else {
        $name = umc_mysql_real_escape_string(trim($args[2]));
        $home_count = umc_home_count($name);
        if ($home_count < 1) {
            umc_error("{red}You do not have a home with that name!");
        }
        $sql = "SELECT * FROM minecraft_srvr.homes WHERE uuid='{$UMC_USER['uuid']}' AND name={$name};";
    }
    $D = umc_mysql_fetch_all($sql);
    $row = $D[0];
    $world = $row['world'];
    if ($world != $playerworld) {
        umc_ws_cmd("mv tp {$world}", 'asPlayer');
    }
    $x = $row['x'];
    $z = $row['z'];
    $y = $row['y'];
    $yaw = $row['yaw'];
    // todo translate ESSENTIALS yaw into minecraft yaw
    XMPP_ERROR_send_msg("tppos {$x} {$y} {$z} {$yaw}");
    umc_ws_cmd("tppos {$x} {$y} {$z} {$yaw}", 'asPlayer');
}
 public function ban($reason)
 {
     XMPP_ERROR_trace(__CLASS__ . " // " . __FUNCTION__, func_get_args());
     global $UMC_USERS;
     $cmd = "ban {$this->username} {$reason}";
     if ($this->context == 'websend') {
         umc_ws_cmd($cmd, 'asConsole', false, false);
         $admin = $UMC_USERS['current_user']->username;
     } else {
         umc_exec_command($cmd, 'asConsole', false);
         $admin = 'wordpress';
     }
     $sql = "INSERT INTO minecraft_srvr.`banned_users`(`username`, `reason`, `admin`, `uuid`) VALUES ('{$this->username}','{$reason}', '{$admin}', '{$this->uuid}');";
     umc_mysql_query($sql, true);
     // remove shop inventory
     umc_shop_cleanout_olduser($this->uuid);
     // remove from teamspeak
     umc_ts_clear_rights($this->uuid);
     $text = "{$admin} banned \${$this->username} ({$this->uuid}) because of {$reason}";
     umc_log('mod', 'ban', $text);
     XMPP_ERROR_send_msg($text);
     // iterate plugins to check for plugin relared post ban processes
 }
Exemple #5
0
function umc_mod_warp_lot()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    }
    $lot = strtolower($args[2]);
    $world = umc_get_lot_world($lot);
    $playerworld = $UMC_USER['world'];
    if ($world != $playerworld) {
        umc_ws_cmd("mv tp {$world}", 'asPlayer');
    }
    $sql = "SELECT min_x, min_z FROM minecraft_worldguard.`region_cuboid` WHERE region_id='{$lot}';";
    $D = umc_mysql_fetch_all($sql);
    $row = $D[0];
    $x = $row['min_x'];
    $z = $row['min_z'];
    $y = 70;
    umc_ws_cmd("tppos {$x} {$y} {$z} 135", 'asPlayer');
}
function umc_lot_warp()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $userlevel = $UMC_USER['userlevel'];
    $world = $UMC_USER['world'];
    $args = $UMC_USER['args'];
    $allowed_ranks = array('Owner', 'Guest');
    if (!in_array($userlevel, $allowed_ranks)) {
        umc_error("Sorry, this command is only for Guests!");
    }
    $allowed_worlds = array('empire', 'flatlands');
    if (!in_array($world, $allowed_worlds)) {
        umc_error('Sorry, you need to be in the Empire or Flatlands to warp!');
    } else {
        $lot = strtolower(umc_sanitize_input($args[2], 'lot'));
        // the above one fails already if the lot is not a proper lot
        $target_world = umc_get_lot_world($lot);
        if (!in_array($target_world, $allowed_worlds)) {
            umc_error('Sorry, you need to be in the Empire or Flatlands to warp!');
        }
        if ($target_world != $world) {
            umc_error("Sorry, you need to be in {$target_world} to warp to {$lot}!");
        }
    }
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        WHERE world.name='{$target_world}' AND region.id = '{$lot}' ";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) != 1) {
        umc_error("There was an error teleporting you to your lot, the admin was notified, please wait for it to be fixed!");
    }
    $lots = $D[0];
    $c_x = $lots['min_x'] + 64;
    $c_z = $lots['min_z'] + 64;
    $c_y = 256;
    $cmd = "tppos {$player} {$c_x} {$c_y} {$c_z} 0";
    umc_ws_cmd($cmd, 'asConsole');
    umc_pretty_bar("darkblue", "-", "{darkcyan} Warping to lot {$lot}");
    umc_echo("You are now in the center of lot {$lot}!");
    umc_footer();
}
function umc_contests_join()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    $player = $UMC_USER['username'];
    $debug = true;
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    }
    $id = $args[2];
    umc_pretty_bar("darkblue", "-", "{darkcyan} Joining contest {$id} ");
    if (!is_numeric($id)) {
        umc_error("You have to enter a numeric contest ID ({$id}). See /contest list");
    }
    // find out if the contest is creative or survival
    $sql = "SELECT * FROM minecraft_srvr.contest_contests WHERE id = {$id};";
    $rst = mysql_query($sql);
    $contest = mysql_fetch_array($rst, MYSQL_ASSOC);
    $status = $contest['status'];
    if ($status !== 'active') {
        umc_error("Contest number {$id} is not active. Please chose a different contest!");
    }
    $min = array('aether' => array('x' => -1532, 'z' => -1532, 'y' => 11, 'parent' => 'aet_p1'), 'flatlands' => array('x' => 1028, 'z' => 1028, 'y' => 64, 'parent' => 'flat_b19'));
    $max = array('aether' => array('x' => -1157, 'z' => -1157, 'y' => 255), 'flatlands' => array('x' => 1275, 'z' => 1275, 'y' => 255));
    $gap = 4;
    $type = 'survival';
    $world = 'aether';
    if ($contest['type'] == 'creative') {
        $type = 'creative';
        $world = 'flatlands';
    }
    $parent = $min[$world]['parent'];
    $min_coords = $min[$world];
    $min_x = $min_coords['x'];
    $min_z = $min_coords['z'];
    $min_y = $min_coords['y'];
    if ($debug) {
        umc_echo("Min coords are {$min_x}/{$min_y}/{$min_z}");
    }
    $max_coords = $max[$world];
    $max_x = $max_coords['x'];
    $max_z = $max_coords['z'];
    $max_y = $max_coords['y'];
    if ($debug) {
        umc_echo("MAx coords are {$max_x}/{$max_y}/{$max_z}");
    }
    $user_id = umc_get_worldguard_id('user', strtolower($player));
    $world_id = umc_get_worldguard_id('world', strtolower($world));
    // find out if the user can have additional contest entries in this contest
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        LEFT JOIN minecraft_worldguard.region_players ON region_cuboid.region_id=region_players.region_id\r\n        WHERE world.name='{$world}' AND region.id LIKE 'con_" . $id . "%' AND user_id={$user_id} AND Owner=1\r\n        ORDER BY max_z, max_x";
    $rst = mysql_query($sql);
    $count = mysql_num_rows($rst);
    if ($count >= $contest['max_entries'] && $player != 'uncovery') {
        umc_error("You have reached the max number of entries for this contest!;");
    }
    // find out if a contest lot already exists
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        WHERE world.name='{$world}' AND region.id LIKE 'con%' ORDER BY max_z, max_x";
    $rst = mysql_query($sql);
    $count = mysql_num_rows($rst);
    if ($debug) {
        umc_echo("{$count} entries already entered!");
    }
    $lotnumber = $count + 1;
    $lot = 'con_' . $id . '_' . $lotnumber;
    if ($debug) {
        umc_echo("Trying to create entry {$lot}");
    }
    // how many lots can I fit into the space across?
    $fullwidth = $max_x - $min_x;
    if ($debug) {
        umc_echo("Lot width is {$fullwidth}");
    }
    $single_width = $contest['x'] + $gap;
    if ($debug) {
        umc_echo("One lot (with gap) is {$single_width} wide");
    }
    $width_lots = floor($fullwidth / $single_width);
    if ($debug) {
        umc_echo("Fitting {$width_lots} per line");
    }
    $fulldepth = $max_z - $min_z;
    $single_depth = $contest['z'] + $gap;
    if ($debug) {
        umc_echo("One lot (with gap) is {$single_depth} deep");
    }
    $depth_lots = floor($fulldepth / $single_depth);
    if ($debug) {
        umc_echo("Fitting {$depth_lots} per row");
    }
    $full_lines = floor($count / $width_lots);
    if ($debug) {
        umc_echo("{$full_lines} lines already full");
    }
    $lastline_lots = $count - $full_lines * $width_lots;
    if ($debug) {
        umc_echo("Last line has {$lastline_lots} lots");
    }
    $start_x = $lastline_lots * ($contest['x'] + $gap) + $min_coords['x'];
    $start_z = $full_lines * ($contest['z'] + $gap) + $min_coords['z'];
    $start_y = $min_coords['y'];
    if ($debug) {
        umc_echo("Starting coords are {$start_x}/{$start_y}/{$start_z}");
    }
    $end_x = $start_x + $contest['x'] - 1;
    $end_z = $start_z + $contest['z'] - 1;
    $end_y = $min_coords['y'] + $contest['y'] - 1;
    if ($debug) {
        umc_echo("End coords are {$end_x}/{$end_y}/{$end_z}");
    }
    if ($end_x > $max_x || $end_z > $max_z) {
        umc_error('There is no more space for additional contest entries!;');
    }
    umc_echo("New lot {gold}{$lot}{white} in {gold}{$world}{white} was created at ");
    umc_echo("coordinates {gold}{$start_x}/{$start_y}/{$start_z}{white} - {gold}{$end_x}/{$end_y}/{$end_z}{white};");
    umc_echo("Use {gold}/contest warp {$id} {$lotnumber}{white} to get there.");
    // create insert SQL 	id 	world_id 	type 	priority 	parent
    $ins_region_sql = "INSERT INTO region (id, world_id, type, priority, parent)\r\n        VALUES ('{$lot}', {$world_id}, 'cuboid', 0, '{$parent}');";
    $ins_region_rst = mysql_query($ins_region_sql);
    // insert cuboid region_id 	world_id 	min_x 	min_y 	min_z 	max_x 	max_y 	max_z
    $ins_cuboid_sql = "INSERT INTO region_cuboid (region_id, world_id, min_x, min_y, min_z, max_x, max_y, max_z)\r\n        VALUES ('{$lot}', {$world_id}, {$start_x}, {$start_y}, {$start_z}, {$end_x}, {$end_y}, {$end_z});";
    $ins_cuboid_rst = mysql_query($ins_cuboid_sql);
    // add user to lot as Owner  region_id 	world_id 	user_id 	Owner
    $ins_user_sql = "INSERT INTO region_players (region_id, world_id, user_id, Owner)\r\n        VALUES ('{$lot}', {$world_id}, {$user_id}, 1);";
    $inc_user_rst = mysql_query($ins_user_sql);
    umc_ws_cmd("region load -w {$world}", 'asConsole');
    umc_footer();
}
Exemple #8
0
function umc_info_settler()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    $players = $UMC_USER['online_players'];
    if (isset($args[2]) && in_array($args[2], $players)) {
        $cmd = "msg {$args[2]} Dear {$args[2]}, welcome to Uncovery Minecraft! " . "You have so far only gotten Guest-status to look around. If you want to start building,; please click here http://bit.ly/1GUDhgg and follow the instructions!";
        umc_ws_cmd($cmd, 'asPlayer');
    } else {
        umc_echo("You have to name an online user to receive the message");
    }
}
/**
 * Bans a user
 * can make the difference between UUID and username
 * can make the difference between websend and wordpress
 *
 * @param type $user
 */
function umc_user_ban($user, $reason)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_ENV, $UMC_USER;
    $U = umc_uuid_getboth($user);
    $uuid = $U['uuid'];
    $username = $U['username'];
    $cmd = "ban {$username} {$reason}";
    if ($UMC_ENV == 'websend') {
        umc_ws_cmd($cmd, 'asConsole', false, false);
        $admin = $UMC_USER['username'];
    } else {
        umc_exec_command($cmd, 'asConsole', false);
        $admin = 'wordpress';
    }
    $sql = "INSERT INTO minecraft_srvr.`banned_users`(`username`, `reason`, `admin`, `uuid`) VALUES ('{$username}','{$reason}', '{$admin}', '{$uuid}');";
    umc_mysql_query($sql, true);
    // remove shop inventory
    umc_shop_cleanout_olduser($uuid);
    // remove from teamspeak
    umc_ts_clear_rights($uuid);
    umc_wp_ban_user($uuid);
    umc_log('mod', 'ban', "{$admin} banned {$username}/{$uuid} because of {$reason}");
    XMPP_ERROR_send_msg("{$admin} banned {$username} because of {$reason}");
}
Exemple #10
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!;";
}
function umc_home_warp()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER;
    $playerworld = $UMC_USER['world'];
    $args = $UMC_USER['args'];
    $player = $UMC_USER['username'];
    // no home name given
    if (!isset($args[2])) {
        // check if the user has only one home
        $home_count = umc_home_count();
        if ($home_count > 1) {
            umc_error("{red}You need to specify the name of your home! Use /homes list to see all homes");
        } else {
            if ($home_count == 0) {
                umc_error("{red}You do not have any homeslots yet! Use /homes buy to get a new home");
            } else {
                $sql = "SELECT * FROM minecraft_srvr.homes WHERE uuid='{$UMC_USER['uuid']}' LIMIT 1;";
            }
        }
    } else {
        $name = umc_mysql_real_escape_string(trim($args[2]));
        $home_count = umc_home_count($name);
        if ($home_count < 1) {
            umc_error("{red}You do not have a home with that name!");
        }
        $sql = "SELECT * FROM minecraft_srvr.homes WHERE uuid='{$UMC_USER['uuid']}' AND name={$name};";
    }
    $D = umc_mysql_fetch_all($sql);
    $row = $D[0];
    $name = $D[0]['name'];
    $world = $row['world'];
    $x = $row['x'];
    $z = $row['z'];
    $y = $row['y'];
    $yaw = $row['yaw'];
    // todo translate ESSENTIALS yaw into minecraft yaw
    $cmd = "consoletp {$player} {$world} {$x} {$y} {$z} {$yaw} 0";
    umc_log('home', 'warp', "{$player} warped to home {$name} at {$world} {$x} {$y} {$z} {$yaw}");
    umc_ws_cmd($cmd, 'asConsole');
}
Exemple #12
0
function umc_story_show()
{
    global $UMC_USER, $UMC_COLORS;
    $username = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    $mode = $UMC_USER['mode'];
    $world = $UMC_USER['world'];
    if (!isset($args[2])) {
        umc_error("You have to enter a story code!");
    } else {
        $code = $args[2];
    }
    if (strpos($code, '?')) {
        umc_error('Your code is incomplete! Please replace the ? with the code that you received at the last station!');
    }
    if (strlen($code) != 5) {
        umc_error('Your code needs to have 5 letters!');
    }
    $sql = "SELECT * FROM minecraft_iconomy.story WHERE code='{$code}';";
    $D = umc_mysql_fetch_all($sql);
    $disallowed_items = array(0, 8, 9, 10, 11, 34, 36, 43, 51, 52, 55, 26, 59, 60, 63, 64, 68, 71, 75, 78, 83, 90, 92, 93, 94, 95, 97, 99, 100, 104, 105, 115, 117, 118, 119, 120, 122);
    $out = '';
    if (count($D) > 0) {
        $row = $D[0];
        $story = stripslashes($row['story']);
        $title = stripslashes($row['storyline']);
        $warp = stripslashes($row['warp']);
        if ($row['forcesurvival'] == -1 && $mode == 'CREATIVE') {
            umc_ws_cmd("gamemode survival {$username};", 'asConsole');
        }
        if ($row['clear_inv'] == -1 && ($world == 'city' || $world == 'flatlands')) {
            umc_ws_cmd("ci {$username};", 'asConsole');
        }
        $items = stripslashes($row['items']);
        if (strlen($items) > 0 && ($world == 'city' || $world == 'flatlands')) {
            $items = explode(";", $items);
            if (count($items) > 0) {
                foreach ($items as $item) {
                    $data = explode(':', $item);
                    if (count($data) == 3 && !in_array($data[0], $disallowed_items)) {
                        if (is_numeric($data[0]) && is_numeric($data[1]) && is_numeric($data[2])) {
                            umc_ws_cmd("give {$username} {$data[0]}:{$data[1]} {$data[2]};", 'asConsole');
                        }
                    }
                }
            }
        }
        if (strlen($warp) > 0 && $world == 'city') {
            $warp = "story_" . $warp;
            umc_ws_cmd("warp {$warp} {$username};", 'asConsole');
        }
        $uuid = $row['uuid'];
        $creator_name = umc_user2uuid($uuid);
        // check for duplicate entries
        $sql = "SELECT * FROM minecraft_iconomy.story_users WHERE `uuid`='{$uuid}' and `story_id`='{$row['id']}';";
        $D3 = umc_mysql_fetch_all($sql);
        $count = count($D3);
        if ($count == 0) {
            $sql = "INSERT INTO minecraft_iconomy.story_users (`uuid`, `story_id`) VALUES ('{$uuid}', '{$row['id']}');";
            umc_mysql_query($sql, true);
        }
        $pages = explode("[BR]", $story);
        $pagecount = count($pages);
        if (isset($args[2]) && is_numeric($args[2]) && isset($pages[$args[2] - 1])) {
            $page = $args[2];
        } else {
            $page = 1;
        }
        $arr_page = $page - 1;
        $this_page_raw = $pages[$arr_page];
        $search = array('[player]', "\n");
        $replace = array($username, ';');
        foreach ($UMC_COLORS as $colorcode => $data) {
            foreach ($data['names'] as $color_name) {
                $search[] = "[" . $color_name . "]";
                $replace[] = "&" . $colorcode;
            }
        }
        $this_page = str_replace($search, $replace, $this_page_raw);
        $out = "{white}----------------- {green}Story Page ({$page}/{$pagecount}): {white}-----------------;" . "{yellow}{$title} {white}by {$creator_name};" . $this_page;
        if (count($pages) > $page) {
            $nextpage = $page + 1;
            $out .= "{white}------- {green}Please type /ws story {$code} {$nextpage} to read on! {white}--------;";
        } else {
            $out .= ";-----------------------------------------------------;";
        }
    } else {
        $out .= "The story code could not be found!";
    }
    $lines = explode(";", $out);
    foreach ($lines as $line) {
        umc_echo($line, true);
    }
}
function umc_trivia_close_quiz($quiz_arr = false)
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    if (!$quiz_arr) {
        $quiz_arr = umc_trivia_get_current_quiz();
    }
    $quiz_id = $quiz_arr['id'];
    // get best user and points
    $sql = "SELECT username, count(result) as points FROM minecraft_quiz.quiz_answers WHERE quiz_id={$quiz_id} AND result='right' GROUP BY username ORDER BY count(result) DESC;";
    $D = umc_mysql_fetch_all($sql);
    $data = array();
    $prev_points = 0;
    foreach ($D as $row) {
        $username = $row['username'];
        $points = $row['points'];
        if ($points < $prev_points) {
            break;
        }
        $data[] = $username;
        // array of the winner(s)
        $prev_points = $points;
    }
    $winner_count = count($data);
    if ($winner_count > 0) {
        $winner_str = implode(", ", $data);
        // how many answers have been given?
        $answer_sql = "SELECT count(answer_id) as counter FROM minecraft_quiz.quiz_answers WHERE quiz_id={$quiz_id};";
        $A = umc_mysql_fetch_all($answer_sql);
        $answer_row = $A[0];
        $answer_count = $answer_row['counter'];
        $prize = $answer_count * $quiz_arr['price'] / $winner_count;
        umc_ws_cmd("ch qm o &3[Trivia]&f We have {$winner_count} winner(s) who each get {$prize}!");
        umc_ws_cmd("ch qm o &3[Trivia]&f Winner(s): {$winner_str}");
        umc_money(false, $row['username'], $prize);
        $sql = "UPDATE minecraft_quiz.quizzes SET end=NOW(), winner='{$winner_str}', points={$prev_points} WHERE quiz_id={$quiz_id};";
    } else {
        $sql = "UPDATE minecraft_quiz.quizzes SET end=NOW(), winner='', points=0 WHERE quiz_id={$quiz_id};";
    }
    umc_mysql_query($sql, true);
    umc_ws_cmd("ch qm o &3[Trivia]&f Thanks for participating. Create your own quiz with /trivia new!");
    umc_log('trivia', 'close', "{$player} closed trivia {$quiz_id} and gave {$prize} to {$winner_str} each");
}
function umc_skyblock_abandon()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    } else {
        $lot = umc_sanitize_input($args[2], 'lot');
        $check = umc_check_lot_exists('skyblock', $lot);
        if (!$check) {
            umc_error("The lot you entered does not exist!");
        }
        if ($lot == 'block_k11') {
            umc_error('You cannot warp to that lot!');
        }
    }
    //check if the user abandoned already
    $abandon_id = umc_get_worldguard_id('user', '_abandoned_');
    $abandon_sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id = '{$lot}' AND Owner=1 AND user_id={$abandon_id};";
    $D3 = umc_mysql_fetch_all($abandon_sql);
    $num = count($D3);
    if ($num > 0) {
        umc_error("You abandoned the entry {$lot} already!");
    }
    // make sure the user actually owns this enrty
    $user_id = umc_get_worldguard_id('user', strtolower($player));
    // find out if the user can have additional contest entries in this contest
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        LEFT JOIN minecraft_worldguard.region_players ON region_cuboid.region_id=region_players.region_id\r\n        LEFT JOIN minecraft_worldguard.user ON region_players.user_id=user.id\r\n        WHERE region.id LIKE '{$lot}' AND Owner=1 AND user.id={$user_id}";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) != 1) {
        umc_error("You do not own the lot {$lot} in skyblock!");
    } else {
        $row = $D[0];
    }
    $world_id = $row['world_id'];
    $ins_user_sql = "INSERT INTO minecraft_worldguard.region_players (region_id, world_id, user_id, Owner)\r\n        VALUES ('{$lot}', {$world_id}, {$abandon_id}, 1);";
    umc_mysql_query($ins_user_sql, true);
    umc_ws_cmd('region load -w skyblock', 'asConsole');
    umc_echo("You have succcessfully abandoned the lot {$lot}! It will be reset with the next reboot. You can then register a new one!");
}
function umc_announce($string, $channel = 't')
{
    $str = preg_replace(color_regex() . "e", 'color_map(\'$1\')', $string);
    umc_ws_cmd("ch qm {$channel} {$str}", 'asConsole');
}
Exemple #16
0
function umc_hunger_kill_all_in_world()
{
    $hunger_world = umc_users_by_world('hunger');
    foreach ($hunger_world as $h_player) {
        umc_ws_cmd("ci {$h_player};", 'asConsole');
        umc_ws_cmd("kill {$h_player};", 'asConsole');
    }
}
/**
 * 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_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);
}