function umc_skyblock_warp()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $world = $UMC_USER['world'];
    $args = $UMC_USER['args'];
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    } else {
        if ($world !== 'skyblock') {
            umc_error('You need to be in the skyblock world to teleport!');
        } 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!');
            }
        }
    }
    $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='skyblock' AND region.id = '{$lot}' ";
    $D = umc_mysql_fetch_all($sql);
    $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 skyblock");
    umc_echo("You are now on skyblock {$lot}!");
    umc_footer();
}
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();
}
function umc_ticket_new()
{
    global $WSEND;
    $player = $WSEND['player'];
    $player_email = umc_user_email($player);
    $player_id = umc_user_id($player);
    $devOptions = umc_ticket_options();
    $args = $WSEND['args'];
    if (!isset($args[1])) {
        umc_show_help($args);
    }
    array_shift($args);
    array_shift($args);
    $text = trim(implode(' ', $args));
    if (stristr($text, 'have a problem') || strlen($text) < 8) {
        umc_error("You need to specify the problem better!");
    }
    $sql_text = mysql_real_escape_string($text);
    $wpscst_title = base64_encode(strip_tags($text));
    $wpscst_initial_message = base64_encode($text);
    $wpscst_department = base64_encode(strip_tags('in-game'));
    $sql = "\r\n    INSERT INTO minecraft.`wp_wpscst_tickets` (\r\n        `primkey`, `title`, `initial_message`, `user_id`, `email`, `assigned_to`, `severity`, `resolution`,\r\n        `time_posted`, `last_updated`, `last_staff_reply`, `target_response_time`, `type`) VALUES (\r\n            NULL,\r\n            '{$wpscst_title}',\r\n            '{$wpscst_initial_message}',\r\n            '{$player_id}',\r\n            '{$player_email}',\r\n            '0',\r\n            'Normal',\r\n            'Open',\r\n            '" . current_time('timestamp') . "',\r\n            '" . current_time('timestamp') . "',\r\n            '',\r\n            '2 days',\r\n            '{$wpscst_department}'\r\n        );\r\n    ";
    $rst = mysql_query($sql);
    $lastID = mysql_insert_id();
    // user email
    $to = $player_email;
    // Send this to the ticket creator
    $subject = $devOptions['email_new_ticket_subject'] . " Ticket ID [{$lastID}]";
    $message = $devOptions['email_new_ticket_body'] . "\r\nTicket contents: \r\n{$text}";
    $headers = 'From: ' . $devOptions['email'] . "\r\n" . 'Reply-To: ' . $devOptions['email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
    // admin email
    $to = $devOptions['email'];
    // Send this to the admin^M
    $subject = __("[Uncovery Minecraft] New Ticket from {$player}", 'wpsc-support-tickets');
    $message = __("New Ticket [{$lastID}] from {$player}:\r\n" . $text . "\r\n", 'wpsc-support-tickets') . get_admin_url() . 'admin.php?page=wpscSupportTickets-edit&primkey=' . $lastID . "\r\n" . var_dump($devOptions);
    $headers = 'From: ' . $player_email . "\r\n" . 'Reply-To: ' . $player_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
    umc_pretty_bar('red', '-', ' Help Ticket Created ', $width = 52);
    umc_echo('Your question:');
    umc_echo("{yellow}{$text}");
    umc_echo('You also received an email. Please check your inbox.');
    umc_pretty_bar('red', '-', '', $width = 52);
}
Example #5
0
/**
 * Show a list of deposit box contents
 *
 * @global type $UMC_USER
 * @global array $UMC_SETTING
 * @param type $silent
 * @param type $user
 * @param type $web
 * @return string|boolean
 */
function umc_show_depotlist($silent = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $UMC_SETTING, $UMC_ENV;
    $player = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    if (isset($UMC_USER['args'][2]) && !in_array($player, $UMC_SETTING['admins'])) {
        umc_error("You are not allowed to look at other's boxes'");
    } else {
        if (isset($UMC_USER['args'][2])) {
            $player = $UMC_USER['args'][2];
            $uuid = umc_uuid_getone($player, 'uuid');
        }
    }
    $userlevel = umc_get_uuid_level($uuid);
    $web = false;
    if ($UMC_ENV == 'wordpress') {
        $web = true;
    }
    $sql = "SELECT * FROM minecraft_iconomy.deposit WHERE sender_uuid='{$uuid}' OR recipient_uuid='{$uuid}' ORDER BY id, damage, amount DESC;";
    $D = umc_mysql_fetch_all($sql);
    $num_rows = count($D);
    $web_arr = array();
    if ($silent && $num_rows == 0) {
        return '';
    } else {
        if ($num_rows == 0) {
            if ($web) {
                return false;
            } else {
                umc_error("{gold}{$player}{red} has nothing in the deposit!");
            }
        } else {
            if (!$web) {
                umc_header();
                umc_echo("{gray}Depot-Id   Description");
            }
            $count = 0;
            foreach ($D as $row) {
                $sender_uuid = $row['sender_uuid'];
                $sender = umc_user2uuid($sender_uuid);
                $recipient_uuid = $row['recipient_uuid'];
                $recipient = umc_user2uuid($recipient_uuid);
                $item = umc_goods_get_text($row["item_name"], $row["damage"], $row['meta']);
                if (!$item) {
                    // could not identify item_name
                    XMPP_ERROR_trigger("Error deposit ID {$row['id']}, Item Name {$row["item_name"]} could not be found!");
                }
                if ($row['amount'] == -1) {
                    $row['amount'] = 'inf.';
                }
                if ($recipient_uuid == $uuid) {
                    $count++;
                }
                $label = "";
                if ($sender_uuid != $uuid && $recipient_uuid == $uuid) {
                    $label = "{green}from {gold}" . $sender;
                } elseif ($sender_uuid == $uuid && $recipient_uuid != $uuid) {
                    $label = "{blue}for {gold}" . $recipient;
                }
                if ($web) {
                    $web_arr[$row['id']] = array('item' => "{$row['amount']} {$item['full']}", 'sender' => $sender, 'recipient' => $recipient);
                } else {
                    umc_echo(sprintf("{green}%7d     {yellow}%s", $row['id'], $row['amount'] . " {$item['full']} {$label}"));
                }
            }
            if (!$web) {
                $allowed = $UMC_SETTING['depositbox_limit'][$userlevel];
                umc_pretty_bar("darkblue", "-", " {green}{$count} / {$allowed} slots used ");
                umc_echo("{cyan}[*] {green}Withdraw with {yellow}/withdraw <Depot-Id>");
                umc_footer();
            } else {
                return $web_arr;
            }
        }
    }
}
/**
 * Sends an error message to the user
 * Terminates  with a ;
 *
 * @param $message to send
 */
function umc_error($message, $silent = false)
{
    umc_pretty_bar('red', '-', ' ERROR ', 52);
    umc_echo($message, $silent);
    umc_pretty_bar('red', '-', '', 52);
    die('umc_error');
}
Example #7
0
function umc_show_help($args = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $WS_INIT;
    $player = $UMC_USER['username'];
    $userlevel = umc_get_userlevel($player);
    if ($args) {
        // if show_help is called from another program, we simulate a /help command being issued.
        $args = array_merge(array('call'), $UMC_USER['args']);
    } else {
        $args = $UMC_USER['args'];
    }
    $command = false;
    $command_name = '';
    $plugin_name = '';
    if (isset($args[1])) {
        $command = umc_wsplg_find_command($args[1]);
        $command_name = $args[1];
    }
    // If we have a help query, a command name, but it didn't match any known commands
    if ($args[0] == 'help' && $command_name && !$command) {
        umc_error("{white}Action {green}{$command_name}{white} not recognized, try {yellow}/helpme");
    }
    umc_header('Uncovery Help', true);
    umc_echo("{gray}   <..> = mandatory   [..] = optional   {ro} = request or offer", true);
    $non_commands = array('default', 'events', 'disabled');
    if ($command_name) {
        if (isset($command['help']['title'])) {
            // This is a 'default' listing
            umc_pretty_bar("darkblue", "-", "{darkcyan}" . $command['help']['title'], 52, true);
            umc_echo($command['help']['long'], true);
            foreach ($WS_INIT[$command_name] as $cmd => $cmd_data) {
                if (!in_array($cmd, $non_commands)) {
                    // This command is restricted to a user level or higher
                    if (isset($cmd_data['security']['level']) && $player != 'uncovery') {
                        if (!umc_rank_check($userlevel, $cmd_data['security']['level'])) {
                            continue;
                        }
                    }
                    if (!isset($cmd_data['top']) || !$cmd_data['top']) {
                        $plugin_name = $command_name . ' ';
                    }
                    $command_args = '';
                    if (isset($cmd_data['help']['args'])) {
                        $command_args = "{yellow}" . $cmd_data['help']['args'];
                    }
                    umc_echo("{green}/{$plugin_name}{$cmd} {$command_args}{gray} => {white}" . $cmd_data['help']['short'], true);
                }
            }
        } else {
            if (isset($command)) {
                // sub-command help
                if (!isset($command['top']) || !$command['top']) {
                    $plugin_name = $command_name . ' ';
                }
                $args_str = '';
                if (isset($command['help']['args'])) {
                    $args_str = "{yellow}" . $command['help']['args'];
                }
                umc_echo("{green}/{$plugin_name}{$command_name} {$args_str}{gray} => {white}" . $command['help']['short'], true);
                umc_pretty_bar("darkgray", "-", "", 49, true);
                foreach (split(';', $command['help']['long']) as $line) {
                    if ($line != '') {
                        umc_echo($line, true);
                    }
                }
            } else {
                umc_echo("{white}No help found for command {red}/{$args[1]} {$args[2]}{white}.", true);
                // umc_show_help($args);
                // umc_echo("{white}Try {yellow}/helpme {$args[1]}{white} to see valid commands.", true);
            }
        }
    } else {
        // Show general help.
        foreach ($WS_INIT as $plugin => $cmd_data) {
            // This command is restricted to a user level or higher
            if (isset($cmd_data['default']['security']['level']) && $player != 'uncovery') {
                if (!umc_rank_check($userlevel, $cmd_data['default']['security']['level'])) {
                    continue;
                }
            }
            umc_echo("{green}/{$plugin}{gray} - " . $cmd_data['default']['help']['short'], true);
        }
        umc_echo("{gray}Use {yellow}/helpme <command>{gray} for more details.", true);
    }
    umc_footer(true);
    return true;
}
function umc_do_search()
{
    global $UMC_USER, $ITEM_SEARCH;
    $args = $UMC_USER['args'];
    $max = 50;
    // check for nonsense queries returning large sets
    if (!isset($args[2]) || strlen($args[2]) < 3) {
        umc_error("{red}You need at least 3 letters to search for!;");
    }
    $term = $args[2];
    $pageindex = 1;
    // check for multiple search terms, or if it is just a pagination index
    if (isset($args[3])) {
        if (!is_numeric($args[3])) {
            umc_error("You can search only for one term such as '{$term}', not for '{$term} {$args[3]}'!");
        } else {
            $pageindex = $args[3];
        }
    }
    // cast to lowercase so case doesn't remove results
    $term = strtolower($term);
    // chat formatting of results
    umc_header();
    umc_echo("{gray}Searching for {white}{$term}{gray}...");
    umc_echo("{green}Item name => {blue} Alias{grey},{blue}...");
    $finds = array();
    $count = 0;
    // populate array with found results
    foreach ($ITEM_SEARCH as $name => $data) {
        if (strpos($name, $term, 0) !== false || $term == $data['item_name']) {
            //find partial or full matches
            $finds[$data['item_name']][] = $name;
            // make sure we don't duplicate stuff by setting key as well
        }
    }
    // check for broadform too many results
    $len = count($finds);
    if ($len > $max) {
        umc_error("Too many results ({$len})! Please see http://uncovery.me/server-access/shop-manager/?page=goods");
    }
    // return results, paginated if required
    foreach ($finds as $item_name => $data) {
        // if data has more than max subsets
        if (count($data) > $max) {
            // get number of pages of results
            $pagemax = ceil(count($data) / $max);
            // data validation checks
            if ($pageindex > $pagemax) {
                $pageindex = $pagemax;
            }
            if ($pageindex < 1) {
                $pageindex = 1;
            }
            // set the offset based on supplied page
            $offset = ($pageindex - 1) * $max;
            // return the subset array
            $subset = array_slice($data, $offset, $max);
            // output the subset
            $text = "{yellow}Page {$pageindex} of {$pagemax} :{blue}" . implode("{gray}, {blue}", $subset);
        } else {
            $text = implode("{gray}, {blue}", $data);
        }
        umc_echo("{green}{$item_name} {gray}=> {blue}" . $text);
    }
    umc_pretty_bar("darkblue", "-", "{blue} {$len} match(es) found");
}