/**
 *  This function displays the proposals the user has not voted on yet. It's displayed on user login
**/
function umc_vote_get_votable($username = false, $web = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_DOMAIN, $vote_ranks, $UMC_USER;
    $out = '';
    if (!$username) {
        $username = $UMC_USER['username'];
        $uuid = $UMC_USER['uuid'];
    } else {
        $uuid = umc_uuid_getone($username, 'uuid');
    }
    if (!$username && !isset($UMC_USER['username'])) {
        XMPP_ERROR_trigger("websend player undidentified");
    }
    $user_lvl = umc_get_userlevel($username);
    $user_lvl_id = $vote_ranks[$user_lvl]['lvl'];
    if ($user_lvl_id < 3) {
        // start voting only for designers
        return;
    }
    $sql = "SELECT proposals.pr_id, proposals.uuid, proposals.date, 60 - DATEDIFF(NOW(), proposals.date) as remainder, UUID.username as username FROM minecraft_srvr.proposals\r\n        LEFT JOIN minecraft_srvr.proposals_votes ON proposals.pr_id=proposals_votes.pr_id AND voter_uuid='{$uuid}'\r\n        LEFT JOIN minecraft_srvr.UUID ON proposals.uuid=UUID.UUID\r\n        WHERE proposals_votes.pr_id IS NULL AND status='voting' ORDER BY proposals.`date` ASC";
    $D = umc_mysql_fetch_all($sql);
    $no_votes = array();
    // echo $sql;
    foreach ($D as $row) {
        $proposal = $row['uuid'];
        $proposal_username = $row['username'];
        $prop_lvl = umc_get_uuid_level($proposal);
        $prop_lvl_id = $vote_ranks[$prop_lvl]['lvl'];
        if ($prop_lvl_id < $user_lvl_id) {
            $days_left = $row['remainder'];
            $no_votes[$proposal_username] = $days_left;
        }
    }
    if (count($no_votes) > 0) {
        if ($web) {
            $out .= "<strong><a href=\"{$UMC_DOMAIN}/vote-for-users/\">Please vote</a>:</strong> (" . count($no_votes) . ") ";
            foreach ($no_votes as $proposee => $days) {
                $out .= "{$proposee}, ";
            }
            $out = rtrim($out, ", ");
            return $out;
        } else {
            umc_header('Your missing votes: (days remaining)', true);
            foreach ($no_votes as $proposee => $days) {
                $out .= "{red}{$proposee} {grey}({$days}){white}, ";
            }
            umc_echo($out, true);
            umc_echo("{gold}Please vote ASAP! Only YOU can determine the future of the server! {$UMC_DOMAIN}/vote-for-users/", true);
            umc_footer(true);
        }
    } else {
        return false;
    }
}
Example #2
0
function umc_lot_mod()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    /// /lotmember lot world add target
    $addrem = $args[3];
    $lot = strtolower($args[2]);
    if (count($args) <= 2) {
        umc_echo("Too few arguments!");
        umc_show_help($args);
        return;
    }
    $world = 'flatlands';
    $user_id = umc_get_worldguard_id('user', strtolower($player));
    if (!$user_id) {
        umc_error("Your user id cannot be found!");
    }
    $player_group = umc_get_userlevel($player);
    $world_id = umc_get_worldguard_id('world', $world);
    if (!$world_id) {
        umc_error("The lot '{$lot}' cannot be found in any world!");
    }
    if (!umc_check_lot_exists($world_id, $lot)) {
        umc_error("There is no lot {$lot} in world {$world};");
    }
    if ($player_group !== 'Owner' && $player_group !== 'Elder' && $player_group !== 'ElderDonator' && $player_group !== 'ElderDonatorPlus') {
        umc_error("You are not Elder or Owner, you are {$player_group}!");
    }
    if ($addrem == 'add') {
        $sql_ins = "INSERT INTO minecraft_worldguard.region_players (`region_id`, `world_id`, `user_id`, `Owner`)\r\n            VALUES ('{$lot}', '{$world_id}', {$user_id}, 0);";
        umc_mysql_query($sql_ins, true);
        umc_echo("Added you to {$lot} in the {$world}!");
    } else {
        if ($addrem == 'rem') {
            // check if target is there at all
            $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$user_id} AND Owner=0 LIMIT 1;";
            $D = umc_mysql_fetch_all($sql);
            if (count($D) !== 1) {
                umc_error("It appears you are not a member of lot {$lot} in world {$world}!");
            }
            $sql_del = "DELETE FROM minecraft_worldguard.region_players WHERE region_id = '{$lot}' AND world_id = {$world_id} AND user_id = {$user_id} AND Owner=0;";
            umc_mysql_query($sql_del, true);
            umc_echo("Removed you from {$lot} in the {$world}!");
        } else {
            umc_error("You can only use [add] or [rem], not {$args[1]}!");
        }
    }
    umc_ws_cmd('region load -w flatlands', 'asConsole');
    umc_log('lot', 'mod', "{$player} added himself to lot {$lot} to fix something");
    XMPP_ERROR_trigger("{$player} added himself to lot {$lot} to fix something");
}
Example #3
0
/**
 * This adds the Wordpress features for the admin pages
 *
 * @global type $UNC_GALLERY
 */
function unc_gallery_admin_init()
{
    global $UNC_GALLERY;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    add_settings_section('unc_gallery_pluginPage_section', __('Settings', 'wordpress'), 'unc_gallery_settings_section_callback', 'unc_gallery_settings_page');
    // we iterate the plugin settings and creat the menus dynamically from there
    foreach ($UNC_GALLERY['user_settings'] as $setting => $D) {
        $prefix = $UNC_GALLERY['settings_prefix'];
        register_setting('unc_gallery_settings_page', $prefix . $setting);
        $setting_value = get_option($prefix . $setting, $D['default']);
        $args = array('setting' => $prefix . $setting, 'value' => $setting_value, 'help' => $D['help'], 'default' => $D['default']);
        if ($D['type'] == 'text') {
            $callback = 'unc_gallery_setting_text_field_render';
        } else {
            if ($D['type'] == 'dropdown') {
                $callback = 'unc_gallery_setting_drodown_render';
                $args['options'] = $D['options'];
            } else {
                if ($D['type'] == 'multiple') {
                    $callback = 'unc_gallery_setting_multiple_render';
                    $args['options'] = $D['options'];
                } else {
                    if ($UNC_GALLERY['debug']) {
                        if ($UNC_GALLERY['debug']) {
                            XMPP_ERROR_trigger("Illegal option type " . $D['type']);
                        }
                    }
                }
            }
        }
        add_settings_field($prefix . $setting, __($D['title'], 'wordpress'), $callback, 'unc_gallery_settings_page', 'unc_gallery_pluginPage_section', $args);
    }
    // check if the upload folder exists:
    $dirPath = $UNC_GALLERY['upload_path'];
    if (!file_exists($dirPath)) {
        echo unc_display_errormsg("The upload folder {$dirPath} does not exist!");
        unc_gallery_plugin_activate();
    }
}
Example #4
0
/**
 * Converts a JSON date to a DateTime Object
 *
 * @param string $json_date
 * @return DateTimeObj or false
 */
function umc_timer_from_json($json_date)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // do we have a timezone string or not?
    if (strlen($json_date) == 13) {
        $json_date .= "-0000";
    }
    //1433044095000 <- No timezone
    //1365004652303-0500 <- timezone
    $pattern = '/(\\d{10})(\\d{3})([\\+\\-]\\d{4})/';
    $format = "U.u.O";
    $mask = '%2$s.%3$s.%4$s';
    $matches = false;
    $r = preg_match($pattern, $json_date, $matches);
    if (!$r) {
        XMPP_ERROR_trigger("Failed to match date in {$json_date}");
    }
    $buffer = vsprintf($mask, $matches);
    $result = DateTime::createFromFormat($format, $buffer);
    if (!$result) {
        XMPP_ERROR_trigger(sprintf('Failed To Create from Format "%s" for "%s".', $format, $buffer));
    }
    return $result;
}
/**
 * Settler  test
 *
 * @global type $UMC_USER
 * @global type $UMC_SETTING
 * @global type $UMC_DOMAIN
 * @return string
 */
function umc_settler_new()
{
    global $UMC_USER, $UMC_SETTING, $UMC_DOMAIN;
    $out = '';
    if (!$UMC_USER) {
        return "You have to be <a href=\"{$UMC_DOMAIN}/wp-login.php\">logged in</a> to use this!";
    }
    $steps = array(1 => array('begging' => true, 'griefing' => true, 'pixel_art' => true, 'minimaps' => false, 'xray_and_cheats' => true, 'not_reading_the_website' => true, 'swearing' => true, 'walls_around_your_lot' => true, 'shaders' => false));
    $player = strtolower($UMC_USER['username']);
    $uuid = $UMC_USER['uuid'];
    $userlevel = $UMC_USER['userlevel'];
    $email = $UMC_USER['email'];
    if ($userlevel != 'Guest') {
        $out .= "You are not a Guest and can use the <a href=\"http://uncovery.me/server-access/lot-manager/\">Lot manager</a> to get a lot!";
    }
    if (umc_user_is_banned($uuid)) {
        return "Sorry, you are banned from the server!";
    }
    $icon_url = umc_user_get_icon_url($player);
    $user_icon = "<img src=\"{$icon_url}\">";
    // get user location
    $s_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
    $step = 0;
    if (isset($s_post['step'])) {
        $step = $s_post['step'];
    }
    $loc = umc_read_markers_file('array');
    $lot = false;
    if (isset($s_post['lot'])) {
        $lot = $s_post['lot'];
    }
    $world = false;
    if (isset($s_post['world'])) {
        $world = $s_post['world'];
    }
    if (isset($loc[$player])) {
        $player_world = $loc[$player]['world'];
        $player_lot = umc_lot_get_from_coords($loc[$player]['x'], $loc[$player]['z'], $loc[$player]['world']);
        $x = $loc[$player]['x'];
        $z = $loc[$player]['z'];
    } else {
        $player_lot = false;
        $player_world = false;
        $x = false;
        $z = false;
    }
    $error = '';
    // answer check
    switch ($step) {
        case 2:
            if (!isset($s_post['stepone'])) {
                $step = 1;
                umc_log('settler_test', 'step_1_fail', "{$player} did not answer any questions!");
                $error = "You need to answer the questions on the previous page!";
            } else {
                $problem = false;
                $answers = array();
                foreach ($steps[1] as $choice => $value) {
                    if ($value == true && !in_array($choice, $s_post['stepone'])) {
                        // Bad stuff
                        $problem = true;
                        $answers[] = $choice;
                    } else {
                        if ($value == false && in_array($choice, $s_post['stepone'])) {
                            // but is
                            $problem = true;
                            $answers[] = $choice;
                        }
                    }
                }
                if ($problem) {
                    umc_log('settler_test', 'step_1_fail', "{$player} failed step 1 with wrong answers " . implode("|", $answers));
                    $error = "<h1>Error</h1>One or more answers in the previous page were wrong.<br>Please go back and check before proceeding.<br>" . "If you need help, please read the <a href=\"{$UMC_DOMAIN}/about-this-server/rules/\">rest of the rules</a>";
                    $step = 1;
                }
            }
            break;
        case 3:
            if (!isset($s_post['world'])) {
                $step = 2;
                umc_log('settler_test', 'step_2_fail', "{$player} failed step 2");
                $error = 'You need to choose a playing mode to continue!';
            }
            break;
        case 4:
            if (!isset($s_post['lot'])) {
                $step = 3;
                umc_log('settler_test', 'step_3_fail', "{$player} failed step 3");
                $error = 'You need to choose lot to continue!';
            }
            break;
        case 5:
            if (!$player_world) {
                $step = 4;
                umc_log('settler_test', 'step_4_fail', "{$player} failed step 4 (not in game)");
                $error = 'You need to be in the game to continue!';
                // var_dump($loc);
            } else {
                if ($player_world != 'city' || $x > 953 || $x < 938 || $z < -814 || $z > -793) {
                    $step = 4;
                    umc_log('settler_test', 'step_4_fail', "{$player} failed step 4 (not in spawn house)");
                    $error = 'You need to type /warp spawn and then continue!';
                }
            }
            break;
        case 6:
            if ($player_world != $s_post['world']) {
                $step = 5;
                umc_log('settler_test', 'step_5_fail', "{$player} failed step 5");
                $error = "You need to go through the {$s_post['world']} portal! Type <strong>/warp spawn</strong> and try again!";
            }
            break;
        case 8:
            if (strtolower($player_lot) != strtolower($s_post['check_lot'])) {
                $step = 7;
                umc_log('settler_test', 'step_7_fail', "{$player} failed step 7 by entering " . $s_post['check_lot'] . "instead of {$player_lot}");
                $error = 'You need to enter the lot you see on-screen into the form to continue!';
            }
            break;
        case 9:
            if (!$player_lot) {
                $step = 8;
                umc_log('settler_test', 'step_8_fail', "{$player} failed step 8");
                $error = "We could not find you on the map. Please make sure you are on the server!";
            } else {
                if ($player_lot != $s_post['lot']) {
                    $step = 8;
                    umc_log('settler_test', 'step_8_fail', "{$player} failed step 8");
                    $error = "You need to get lot {$s_post['lot']} before you can continue. Please either walk there or use /jump {$s_post['lot']}. You are now in lot {$player_lot}!";
                }
            }
            break;
    }
    // questions
    $out .= "<strong>{$error}</strong><br>";
    switch ($step) {
        case 0:
            umc_log('settler_test', 'start', "{$player} started the settler test");
            $out .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "<h1>Step 1: Welcome!</h1>\n" . "<h2>Once you finish this test, you will be settler!</h2>\n" . "<h2>Before Applying</h2>\n" . "<ul>\n" . "    <li>You must have some experience playing Minecraft.</li>\n" . "    <li>Read the <a href=\"{$UMC_DOMAIN}/faq/\">FAQ</a></li>\n" . "    <li>Read the <a href=\"{$UMC_DOMAIN}/rules/\">Rules</a></li>\n" . "    <li>Read the <a href=\"{$UMC_DOMAIN}/user-levels/\">User Levels and Commands</a> page.</li>\n" . "</ul>\n" . "This process will guide you through the process of getting building rights on the server and at the same time give you a lot and make sure you get there. " . "You will need to login to the server with your minecraft client during the process and keep this website open.<br>" . "<input type=\"hidden\" name=\"step\" value=\"1\">\n" . "<input type=\"submit\" name=\"Next\" value=\"Next\">\n";
            break;
        case 1:
            $warning = '';
            $failcount = umc_settler_get_fails($player);
            if ($failcount > 10) {
                $warning = "<div style=\"color:red;font-weight:bold;font-size:120%;\">You have failed the test more than 10 times. If you fail too often, you will be banned from the server!</div>";
            } else {
                if ($failcount > 20) {
                    umc_user_ban($player, "Settler test failed");
                    return $warning = "<div style=\"color:red;font-weight:bold;font-size:120%;\">You have failed the test too often. You are now banned from the server!</div>";
                }
            }
            umc_log('settler_test', 'step_1', "{$player} is at step 1");
            $out .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "<h1>Step 2: Rules & regulations</h1>\n" . $warning . "Here are some basic rules you should know:" . "<ul>\n<li><strong>Do not beg for anything</strong> - Including upgrades, handouts or help with this process.</li>\n" . "<li><strong>No pixel-art</strong>. This is not 'paint by numbers'. We build stuff.</li>\n" . "<li><strong>Be considerate of others</strong>. No griefing, no stealing, no killing. We log everything, we will find out.</li>\n" . "<li><strong>Don't cheat!</strong> No Xray, no mods, no bug abuse.</li>\n" . "<li><strong>Learn yourself!</strong> Look on the <a href=\"{$UMC_DOMAIN}/about-this-server/\">website</a> for answers first, then ask other users.</li>\n" . "<li><strong>We ban forever - no appeals!</strong> You better read the <a href=\"{$UMC_DOMAIN}/about-this-server/rules/\">rest of the rules</a>.</li>\n" . "</ul>\n" . "<strong>Pick the items that are not allowed (and will therefore get you banned) (Note: Asking others about the answers will get you banned, too!): </strong><br>\n" . "<input type=\"hidden\" name=\"step\" value=\"2\">\n";
            foreach ($steps[1] as $image => $check) {
                $image_text = umc_pretty_name($image);
                $out .= "<span style=\"float:left; text-align:center;\"><img height=\"180\" src=\"{$UMC_DOMAIN}/websend/{$image}.png\"><br>" . "<input type=\"checkbox\" name=\"stepone[]\" value=\"{$image}\">{$image_text}</span>\n";
            }
            $out .= '<br style="clear:both;">' . "<input type=\"submit\" name=\"Next\" value=\"Next\">\n";
            break;
        case 2:
            umc_log('settler_test', 'step_2', "{$player} is at step 2");
            $out .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . '<h1>Step 3: Creative or Survival?</h1>' . 'You can either build in a flat, creative world or a wild, survival world!<br>Choose one:<br>' . "<span style=\"float:left; text-align:center;\"><img width=\"400\" src=\"{$UMC_DOMAIN}/websend/empire.png\"><br><input type=\"radio\" name=\"world\" value=\"empire\">Survival mode in the Empire world</span>" . "<span style=\"float:left; text-align:center;\"><img width=\"400\" src=\"{$UMC_DOMAIN}/websend/flatlands.png\"><br><input type=\"radio\" name=\"world\" value=\"flatlands\">Creative mode in the Flatlands world</span><br style=\"clear:both;\">" . "<input type=\"hidden\" name=\"step\" value=\"3\">\n" . "<input type=\"submit\" name=\"Next\" value=\"Next\">\n";
            break;
        case 3:
            umc_log('settler_test', 'step_3', "{$player} is at step 3");
            $spawn_lot = $UMC_SETTING['world_data'][$world]['spawn'];
            $tile = umc_user_get_lot_tile(strtolower($spawn_lot));
            $out .= "<form action=\"{$UMC_DOMAIN}/admin/index.php?function=create_map&world={$world}&freeonly=true\" method=\"post\">\n" . "<h1>Step 4: Find a lot!</h1>\n" . "<img style=\"float:right;\" width=\"300\" src=\"{$UMC_DOMAIN}/websend/{$world}.png\">Great! You chose to build in the <strong>{$world}</strong> world!<br>" . "You are now ready to pick a lot!<br>" . "If you made a mistake and want to play a different mode, please go back now and chose another mode. There will be no going back later.<br><br>" . "<strong>Now you need to find a lot that you like.</strong><br>" . "When you click 'Next', a map of the {$world} world will open.<br>" . "Click on the \"Find Spawn\" button in the top-left corner. It looks like this:<br>" . "<img src=\"/websend/find_spawn.png\"><br>" . "You will now see a flashing lot, which is the entrance to the {$world} world.<br>" . "It's convenient to find a lot close to it. <br>" . "The spawn lot looks like this:<br>{$tile}" . "<input type=\"hidden\" name=\"settler_test\" value=\"settler_test\">\n" . "<br><br><input type=\"submit\" name=\"Next\" value=\"Next\">\n";
            break;
        case 4:
            umc_log('settler_test', 'step_4', "{$player} is at step 4");
            $tile = umc_user_get_lot_tile(strtolower($lot));
            $out .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . '<h1>Step 5: You chose a lot!</h1>' . "<span style=\"float:left;\">{$tile}</span>The lot you have chosen is <strong>{$lot} in the {$world}</strong> world. You can see a satellite image of it on the left.<br>You should now go there, to make sure it's what you want!<br>";
            if ($player_world) {
                $out .= "<br>To go there, you need to go to the portal house. From there you can get into the {$world} world.<br>" . "Please type <strong>/warp spawn</strong> in game to get there, it should look like this inside:<br><img src=\"/websend/portals.png\">" . "Once you see this, please come back here and press " . "<input type=\"submit\" name=\"Next\" value=\"Next\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"step\" value=\"5\">\n";
            } else {
                $out .= "Please <strong>login to the server</strong> now with your minecraft client at <strong>uncovery.me</strong> and then press " . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"submit\" name=\"action\" value=\"Continue\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n" . "<input type=\"hidden\" name=\"step\" value=\"5\">\n";
            }
            break;
        case 5:
            umc_log('settler_test', 'step_5', "{$player} is at step 5");
            $out .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "<h1>Step 6: Get to the {$world} world</h1>";
            // check if the player is actually in the portal house
            // player is not in portal house
            if ($player_world != 'city' || $x > 953 || $x < 938 || $z < -814 || $z > -793) {
                $out .= "You need to be in the portal house to continue. Please type <strong>/warp spawn</strong> again to get there. " . "It should look like this inside:<br><img src=\"/websend/portals.png\"> Once you see this, press\n" . "<input type=\"submit\" name=\"Next\" value=\"Next\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"step\" value=\"5\">\n";
            } else {
                $out .= "Since you chose a lot in the {$world} world, you need to go through the {$world} portal. " . "It looks like this: Notice the name of the world is written on the sign." . "<img src=\"/websend/{$world}_portal.png\">" . "Please step through and press " . "<input type=\"submit\" name=\"Next\" value=\"Next\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"step\" value=\"6\">\n";
            }
            break;
        case 6:
            umc_log('settler_test', 'step_6', "{$player} is at step 6");
            $spawn_lot = strtoupper($UMC_SETTING['world_data'][$world]['spawn']);
            $lower_lot = strtolower($lot);
            $lot_sql = "SELECT region_cuboid.region_id AS lot, sqrt(pow(max_x,2)+pow(max_z,2)) AS distance, max_x, max_z\r\n                FROM minecraft_worldguard.world\r\n                LEFT JOIN minecraft_worldguard.region_cuboid ON world.id=region_cuboid.world_id\r\n                WHERE region_cuboid.region_id='{$lower_lot}';";
            $D = umc_mysql_fetch_all($lot_sql);
            $lot_data = $D[0];
            // north/south difference
            if ($lot_data['max_x'] < 0) {
                $direction1 = "north";
            } else {
                if ($lot_data['max_x'] >= 0) {
                    $direction1 = "south";
                }
            }
            // north/south difference
            if ($lot_data['max_z'] < 0) {
                $direction2 = "west";
            } else {
                if ($lot_data['max_z'] >= 0) {
                    $direction2 = "east";
                }
            }
            $out .= "<form action=\"{$UMC_DOMAIN}/admin/index.php?function=create_map&world={$world}&freeonly=true\" method=\"post\">\n" . "<h1>Step 7: Getting to lot {$lot} in the {$world} world</h1>" . "Getting to your world is easy! You are now at the center of the {$world} world." . "Your lot is <strong>{$direction1}/{$direction2}</strong> from spawn! <br>" . "You can find out which direction you are looking with the <strong>/compass</strong> command.<br>" . "As a Guest level player, you cannot be killed by mobs until you finished this here.<br>" . "So you have to leave the spawn lot either through the {$direction1} or the {$direction2} exit.<br>" . "To know where you are, you can follow your icon {$user_icon} on the map while you get around.<br>" . "Please click NEXT to open the map, there you find your icon click the button next to it!<br><br>" . "<input type=\"submit\" name=\"next\" value=\"Next\">\n" . "<input type=\"hidden\" name=\"track_player\" value=\"{$player}\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n";
            $x = $loc[$player]['x'];
            $z = $loc[$player]['z'];
            break;
        case 7:
            umc_log('settler_test', 'step_7', "{$player} is at step 7");
            // whereami
            $out .= "<h1>Step 8: Find out where you are in-game</h1>" . "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "Now that you know how to find yourself on the map, you need to find out where you are when in-game.<br>" . "The command to find your location in-game is called <strong>/whereami</strong>.<br>" . "Please go into the game and type <strong>/whereami</strong><br>" . "You will see something like this:<br>" . "<img src=\"/websend/whereami.png\"><br>" . "In this example, you can see the Lot (in the first line) is <img src=\"/websend/whereami_detail.png\"> So you would enter 'emp_z7'.<br>" . "Please go now into the game, type <strong>/whereami</strong>, and enter the information here:<br>" . "I am now in lot <input type=\"text\" name=\"check_lot\" value=\"\" size=\"7\"> and then press " . "<input type=\"submit\" name=\"next\" value=\"Next\">\n" . "<input type=\"hidden\" name=\"step\" value=\"8\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n";
            // enter which lot you are in right now
            break;
        case 8:
            // walk to your lot
            umc_log('settler_test', 'step_8', "{$player} is at step 8");
            $lower_lot = strtolower($lot);
            $out .= "<form action=\"{$UMC_DOMAIN}/admin/index.php\" method=\"post\">\n" . "<h1>Step 9: Walk to your lot {$lot}!</h1>" . "Now you have everything you need to get to your lot!<br>You should follow your steps on the 2D map.<br>" . "You can either walk there, or use the command <pre>/lot warp {$lot}</pre> to get there. Please note that this command is only available while you are Guest.<br>" . "Press 'Next' to open the 2D map and follow your icon to lot {$lot}!<br>" . "<input type=\"submit\" name=\"next\" value=\"Next\">\n" . "<input type=\"hidden\" name=\"guide_lot\" value=\"{$player}\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"freeonly\" value=\"true\">\n" . "<input type=\"hidden\" name=\"function\" value=\"create_map\">\n" . "<input type=\"hidden\" name=\"step\" value=\"9\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"hidden\" name=\"lot\" value=\"{$lower_lot}\">\n";
            break;
        case 9:
            umc_log('settler_test', 'step_9', "{$player} is at step 9");
            // do you like it? claim it
            $out .= "<h1>Step 10: Do you like the lot {$s_post['lot']}?</h1>" . "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . '<input type="radio" name="step" value="10" checked>Yes! I take it! I will type <strong>/homes buy ' . $world . '</strong> now so I can warp back here!<br>' . '<input type="radio" name="step" value="1">No,I would like to start over!<br>' . "<input type=\"hidden\" name=\"lot\" value=\"{$lot}\">\n" . "<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n" . "<input type=\"submit\" name=\"next\" value=\"Finish!\">\n";
            break;
        case 10:
            umc_log('settler_test', 'step_10', "{$player} is at step 10");
            // final confirmation
            $out .= "<h1>Step 11: Congratulations!</h1>" . "You have been promoted to Settler!<br>";
            if ($userlevel == 'Guest') {
                $cmd = "pex promote {$UMC_USER['uuid']}";
                umc_exec_command($cmd);
                // update UUID database
                $sql = "UPDATE minecraft_srvr.UUID SET userlevel='Settler' WHERE UUID='{$UMC_USER['uuid']}';";
                umc_mysql_query($sql);
                umc_exec_command('pex reload');
                umc_exec_command("ch qm u Congrats {$player} for becoming Settler!");
                XMPP_ERROR_send_msg("{$userlevel} {$player} got promoted with command " . $cmd);
                umc_log('settler_test', 'promotion', "{$player} ({$UMC_USER['uuid']})was promoted to settler (new test)");
                $headers = "From: minecraft@uncovery.me\r\n" . "Reply-To: minecraft@uncovery.me\r\n" . 'X-Mailer: PHP/' . phpversion();
                $subject = "[Uncovery Minecraft] Settler applicaton";
                $mailtext = "The user: {$player} (email: {$email}) was promoted to Settler and got lot {$lot}.\n\n";
                $check = mail('*****@*****.**', $subject, $mailtext, $headers);
                if (!$check) {
                    XMPP_ERROR_trigger("The settler promotion email could not be sent!");
                }
                // check userlevel to make sure
                $new_level = umc_get_userlevel($player);
                if ($new_level != 'Settler') {
                    XMPP_ERROR_trigger("{$userlevel} {$player} did NOT got promoted with command " . $cmd . " he's still {$new_level}");
                }
            } else {
                $out .= "Thanks for taking this test! Since you are {$userlevel} already, we will not promote you to Settler.<br>";
            }
            // try to assign the lot
            $check = umc_lot_manager_check_before_assign($uuid, $lot);
            $out .= "Trying to assign this lot to you: <strong>{$check['text']}</strong><br>";
            if ($check['result'] == false) {
                XMPP_ERROR_send_msg("Settler Test lot assignment failed!");
                $out .= "There was an error giving the lot you reserved to you. You can get any other through your <a hreaf=\"{$UMC_DOMAIN}/server-access/lot-manager/\">lot manager</a>!<br>";
            } else {
                umc_lot_add_player($uuid, $lot, 1, $check['cost']);
                $out .= $check['text'];
            }
            break;
        default:
            $out .= "This option was not recognized, please reload the page!";
    }
    $out .= "</form>\n";
    return $out;
}
function umc_lot_addrem()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    /// /lotmember lot world add target
    if (count($args) <= 3) {
        umc_echo("{red}Not enough arguments given");
        umc_show_help($args);
        return;
    }
    $addrem = $args[1];
    $lot = strtolower($args[2]);
    $action = $args[3];
    $worlds = array('emp' => 'empire', 'fla' => 'flatlands', 'dar' => 'darklands', 'aet' => 'aether', 'kin' => 'kingdom', 'dra' => 'draftlands', 'blo' => 'skyblock', 'con' => 'aether');
    $world_abr = substr($lot, 0, 3);
    if (!isset($worlds[$world_abr])) {
        umc_error("Your used an invalid lot name!");
    }
    $world = $worlds[$world_abr];
    if ($player == '@Console') {
        $player = 'uncovery';
    }
    $user_id = umc_get_worldguard_id('user', strtolower($player));
    if (!$user_id) {
        umc_error("Your user id cannot be found!");
    }
    $player_group = umc_get_userlevel($player);
    $world_id = umc_get_worldguard_id('world', $world);
    if (!$world_id) {
        umc_show_help($args);
        umc_error("The lot '{$lot}' cannot be found in any world!");
    }
    if (!umc_check_lot_exists($world_id, $lot)) {
        umc_show_help($args);
        umc_error("There is no lot {$lot} in world {$world}!");
    }
    if ($action == 'snow' || $action == 'ice') {
        // check if the user has DonatorPlus status.
        if ($player_group !== 'Owner') {
            if (!stristr($player_group, 'DonatorPlus')) {
                umc_error("You need to be DonatorPlus level to use the snow/ice features!;");
            }
            $owner_switch = 0;
            // check if player is Owner of lot
            $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$user_id} and Owner=1;";
            $D = umc_mysql_fetch_all($sql);
            $num = count($D);
            if ($num != 1) {
                umc_error("It appears you {$player} ({$user_id}) are not Owner of lot {$lot} in world {$world}!");
            }
        }
        // get the current status of the flags
        if ($addrem == 'add') {
            $flag = 'allow';
            umc_echo("Allowing {$action} forming on lot {$lot}... ");
        } else {
            if ($addrem == 'rem') {
                $flag = 'deny';
                umc_echo("Preventing {$action} forming on lot {$lot}... ");
            } else {
                umc_show_help($args);
            }
        }
        if ($action == 'snow') {
            $flagname = 'snow-fall';
        } else {
            if ($action == 'ice') {
                $flagname = 'ice-form';
            }
        }
        // does flag exist?
        $check_sql = "SELECT * FROM minecraft_worldguard.region_flag WHERE region_id='{$lot}' AND world_id={$world_id} AND flag='{$flagname}';";
        $D2 = umc_mysql_fetch_all($check_sql);
        $count = count($D2);
        if ($count == 0) {
            // insert
            $ins_sql = "INSERT INTO minecraft_worldguard.region_flag (region_id, world_id, flag, value) VALUES ('{$lot}', {$world_id}, '{$flagname}', '{$flag}');";
            umc_mysql_query($ins_sql, true);
        } else {
            // update
            $upd_sql = "UPDATE minecraft_worldguard.region_flag SET value='{$flag}' WHERE region_id='{$lot}' AND world_id={$world_id} AND flag='{$flagname}';";
            umc_mysql_query($upd_sql, true);
        }
        umc_echo("done!");
        umc_log('lot', 'addrem', "{$player} changed {$action} property of {$lot}");
    } else {
        if ($action == 'owner' || $action == 'give') {
            if ($player != 'uncovery' && $player != '@Console') {
                umc_error("Nice try, {$player}. Think I am stupid? Want to get banned?");
            }
            $owner_switch = 1;
        } else {
            if ($action == 'member') {
                $user_id = umc_get_worldguard_id('user', strtolower($player));
                if (!$user_id && $player !== 'uncovery') {
                    umc_error("Your user id cannot be found!");
                }
                $owner_switch = 0;
                // check if player is Owner of lot
                if ($player_group !== 'Owner') {
                    $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$user_id} and Owner=1;";
                    $D3 = umc_mysql_fetch_all($sql);
                    $count = count($D3);
                    if ($count != 1) {
                        umc_error("It appears you ({$player} {$user_id}) are not Owner of lot {$lot} in world {$world}!");
                    }
                }
            } else {
                umc_echo("Action {$action} not recognized!");
                umc_show_help($args);
                return;
            }
        }
        // get list of active users
        $active_users = umc_get_active_members();
        for ($i = 4; $i < count($args); $i++) {
            $target = strtolower($args[$i]);
            // check if target player exists
            $target_id = umc_get_worldguard_id('user', strtolower($target));
            if (!$target_id) {
                umc_error("The user {$target} does not exist in the database. Please check spelling of username");
            }
            if ($player != 'uncovery') {
                $targ_group = umc_get_userlevel($target);
                if ($targ_group == 'Guest') {
                    umc_error("You cannnot add Guests to your lot!;");
                } else {
                    if (!in_array($target, $active_users)) {
                        XMPP_ERROR_trigger("{$player} tried to add {$target} to his lot {$lot}, but {$target} is not an active member!");
                        umc_error("{$target} is not an active user! You can only add people who have their own lot! See FAQ entry #32 please.");
                    }
                }
            }
            // add / remove target player from lot
            if ($addrem == 'add') {
                // make sure target is not already there
                $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$target_id};";
                $D3 = umc_mysql_fetch_all($sql);
                $num = count($D3);
                if ($num == 1) {
                    umc_error("It appears {$target} is already member of lot {$lot} in world {$world}!");
                }
                // add to the lot
                umc_lot_add_player($target, $lot, 0);
                umc_echo("Added {$target} to {$lot} in the {$world}!");
            } else {
                if ($addrem == 'rem') {
                    // check if target is there at all
                    $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$target_id} AND Owner={$owner_switch} LIMIT 1;";
                    $D3 = umc_mysql_fetch_all($sql);
                    $num = count($D3);
                    if ($num !== 1) {
                        umc_error("It appears user {$target} is not a member of lot {$lot} in world {$world}!");
                    }
                    umc_lot_rem_player($target, $lot, 0);
                    umc_echo("Removed {$target} from {$lot} in the {$world}!");
                } else {
                    if ($addrem == 'give') {
                        // remove all members and owners
                        umc_lot_remove_all($lot);
                        umc_lot_add_player($target, $lot, 1);
                        umc_echo("Gave {$lot} to {$target} in the {$world}! All other user removed!");
                        // logfile entry
                        umc_log('lot', 'addrem', "{$player} gave lot to {$target}");
                    } else {
                        umc_show_help($args);
                    }
                }
            }
        }
    }
    umc_ws_cmd("region load -w {$world}", 'asConsole');
}
Example #7
0
/**
 *
 * @param string $table_name name of the table to enable several per page
 * @param string $sort_column initial sorting column, format "7, 'desc'"
 * @param misc $data recordset of all data in the table or array
 * @param string $pre_table html to insert before table
 * @param int $hide_cols one colums to hide
 * @param array $non_numeric_cols names of columens that are not numerical
 * @param array array('column' => 'function');
 * @return string
 */
function umc_web_table($table_name, $sort_column, $data, $pre_table = '', $hide_cols = array(), $non_numeric_cols = false, $formats = false)
{
    $headers = '';
    if (!$non_numeric_cols) {
        // default numeric cols if nothing else defined
        // this should disappear once all inputing functions are updated
        $non_numeric_cols = array('username', 'item', 'buyer', 'seller', 'meta', 'item_name');
    }
    $numeric_columns = array();
    if (is_array($data)) {
        if (count($data) == 0) {
            return "{$pre_table}<br>No data found<hr>";
        }
        $keys = array_keys(current($data));
    } else {
        XMPP_ERROR_trigger("Data type passed to umc_web_table is not array!");
        return '';
    }
    $counter = 0;
    foreach ($keys as $col) {
        if (in_array($col, $hide_cols)) {
            continue;
        } else {
            $style = "style='text-align:left'";
            $input_class = "";
            if (!in_array($col, $non_numeric_cols)) {
                array_push($numeric_columns, $counter);
                $style = "style='text-align:right'";
                $input_class = " numeric";
            }
            $headers .= "<th {$style}>" . umc_pretty_name($col) . "</th>\n";
            $counter++;
        }
    }
    $data_out = '';
    foreach ($data as $row) {
        $data_out .= umc_web_table_create_line($row, $numeric_columns, $formats, $hide_cols);
    }
    $numeric_columns_str = implode(",", $numeric_columns);
    $out = "<script type=\"text/javascript\">\n            var table_name = \"{$table_name}\";\n            var numeric_columns = [{$numeric_columns_str}];\n            var sort_columns = [[{$sort_column}]];\n            var strnum_columns = [];\n        </script>";
    $out .= "<script type=\"text/javascript\" src=\"/admin/js/jquery.dataTables.min.js\"></script>\n" . "<script type=\"text/javascript\">" . 'jQuery(document).ready(function() {jQuery' . "('#shoptable_{$table_name}').dataTable( {\"autoWidth\": false, \"order\": [[ {$sort_column} ]],\"paging\": false,\"ordering\": true,\"info\": false} );;} );" . "</script>";
    $out .= "{$pre_table}\n        <table id='shoptable_{$table_name}'>\n          <thead>\n            <tr>\n              {$headers}\n            </tr>\n          </thead>\n          <tbody>\n            {$data_out}\n          </tbody>\n        </table>";
    return $out;
}
Example #8
0
/**
 * Open a folder of a certain date and display all the images in there
 *
 * @global type $UNC_GALLERY
 * @return string
 */
function unc_display_images()
{
    global $UNC_GALLERY;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__);
    }
    $D = $UNC_GALLERY['display'];
    $header = '';
    if (isset($D['dates'])) {
        $date_str = $D['dates'][0];
        if (current_user_can('manage_options') && is_admin()) {
            $url = admin_url('admin.php?page=unc_gallery_admin_menu');
            $header .= "\r\n            <span class=\"delete_folder_link\">\r\n                Sample shortcode for this day: <input id=\"short_code_sample\" onClick=\"SelectAll('short_code_sample');\" type=\"text\" value=\"[unc_gallery date=&quot;{$date_str}&quot;]\">\r\n                <a href=\"{$url}&amp;folder_del={$date_str}\">\r\n                    Delete Date: {$date_str}\r\n                </a>\r\n            </span>\n";
        }
    }
    // get all the files in the folder with attributes
    $files = $D['files'];
    // display except for skipped files and files out of time range
    $images = '';
    $featured = '';
    $featured_fixed = false;
    if ($UNC_GALLERY['featured_size_for_mixed_sizes'] != 'dynamic' && count($D['featured_image']) > 1) {
        $featured_fixed = $UNC_GALLERY['featured_size_for_mixed_sizes'];
    }
    /*if ($D['slideshow']) {
          $images .= '<ul id="lightSlider">';
      } */
    $i = 0;
    // limit images
    $max_images = intval($D['limit_images']);
    $counter = 0;
    foreach ($files as $F) {
        // stop looping once we have the max number of images
        if ($max_images && $i >= $max_images) {
            break;
        } else {
            if ($max_images && $i == $max_images - 1) {
                $not_shown = count($files) - $max_images;
                if ($not_shown > 0) {
                    $UNC_GALLERY['not_shown'] = $not_shown;
                }
            }
        }
        $F['index'] = $i;
        if (!$D['slideshow'] && $F['featured']) {
            // select size for featured images
            if ($featured_fixed) {
                $feat_size = $featured_fixed;
            } else {
                if ($UNC_GALLERY['featured_size'] != 'dynamic') {
                    $feat_size = $UNC_GALLERY['featured_size'];
                } else {
                    if ($F['orientation'] == 'portrait') {
                        $feat_size = $UNC_GALLERY['featured_size_for_portrait'];
                    } else {
                        $feat_size = $UNC_GALLERY['featured_size_for_landscape'];
                    }
                }
            }
            $height_css = 'rows_' . $feat_size;
            $counter++;
            $featured .= "<div class=\"featured_photo {$height_css}\">\n" . unc_display_image_html($F['file_path'], false, $F) . "</div>\n";
            /*} else if ($Df['slideshow']) { // slideshow does not have features
              $images .= "<li>\n"
                  . unc_display_image_html($F['file_path'], false, $F)
                  . '<p>' . unc_tools_file_desc($F) . '</p>'
                  . "</li>\n";*/
        } else {
            $counter++;
            $images .= "<div class=\"one_photo\">\n" . unc_display_image_html($F['file_path'], true, $F) . "</div>\n";
        }
        $i++;
    }
    /* if ($D['slideshow']) {
           $images .= '</ul>';
       } **/
    $photoswipe = '';
    if ($UNC_GALLERY['image_view_method'] == 'photoswipe') {
        $photoswipe = unc_display_photoswipe_js($files);
    }
    if ($UNC_GALLERY['post_keywords'] != 'none') {
        $check_tags = unc_tags_apply($files);
        if ($check_tags) {
            if ($UNC_GALLERY['debug']) {
                XMPP_ERROR_trigger("Tags have been updated");
            }
        }
    }
    if ($UNC_GALLERY['post_categories'] != 'none') {
        $check_cats = unc_categories_apply($files);
        if ($check_cats) {
            if ($UNC_GALLERY['debug']) {
                XMPP_ERROR_send_msg("Categories have been updated");
            }
        }
    }
    if ($D['slideshow']) {
        $photoswipe = '';
        /*'<script type="text/javascript">
          jQuery(document).ready(function() {
              var slider = jQuery("#lightSlider").lightSlider({
                  adaptiveHeight:true,
                  item:1,
                  auto:true,
                  slideMargin:0,
                  loop:true,
                  adaptiveHeight:true,
                  mode:\'fade\',
                  speed:800,
                  pause:4000,
                  });
          });
          </script>'; */
    }
    $summary = "<div class=\"images_summary\">{$counter} images found.</div>";
    $out = $header . $featured . $images . $photoswipe . $summary;
    if ($D['echo']) {
        ob_clean();
        echo $out;
        wp_die();
    } else {
        return $out;
    }
}
Example #9
0
function umc_donation_level($user, $debug = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $U = umc_uuid_getboth($user);
    $uuid = $U['uuid'];
    $username = $U['username'];
    $debug_txt = '';
    global $UMC_SETTING;
    $date_now = new DateTime("now");
    $sql = "SELECT amount, date FROM minecraft_srvr.donations WHERE uuid='{$uuid}';";
    $level = umc_get_uuid_level($uuid);
    if ($level == 'Owner') {
        return false;
    }
    $D = umc_mysql_fetch_all($sql);
    // if there are 0 donations, user should not be changes
    if (count($D) == 0 && strstr($level, "Donator")) {
        XMPP_ERROR_trigger("User {$username} ({$uuid}) never donated but has a donator level ({$level})");
    } else {
        if (count($D) == 0) {
            $debug_txt .= "{$username} ({$uuid}) does not have any donations\n";
            return;
        }
    }
    $debug_txt .= "Checking donation upgrade of user {$username}, current UserLevel: {$level}\n";
    $donation_level = 0;
    // go through all donations and find out how much is still active
    foreach ($D as $row) {
        $date_donation = new DateTime($row['date']);
        $interval = $date_donation->diff($date_now);
        $years = $interval->format('%y');
        $months = $interval->format('%m');
        $donation_term = $years * 12 + $months;
        $donation_leftover = $row['amount'] - $donation_term;
        if ($donation_leftover < 0) {
            $donation_leftover = 0;
            // do not create negative carryforward
        }
        $donation_level = $donation_level + $donation_leftover;
        $debug_txt .= "Amount donated {$row['amount']} {$years} years {$months} m ago = {$donation_term} months ago, {$donation_leftover} leftover, level: {$donation_level}\n";
    }
    $donation_level_rounded = ceil($donation_level);
    // get userlevel and check if demotion / promotion is needed
    $debug_txt .= "user {$username} ({$uuid}) has donation level of {$donation_level_rounded}, now is {$level}\n";
    // current userlevel
    $ranks_lvl = array_flip($UMC_SETTING['ranks']);
    $cur_lvl = $ranks_lvl[$level];
    // get current promotion level
    if (strpos($level, 'DonatorPlus')) {
        $current = 2;
    } else {
        if (strpos($level, 'Donator')) {
            $current = 1;
        } else {
            $current = 0;
        }
    }
    // get future promotion level
    if (count($D) == 0) {
        // this never happens since it's excluded above
        $future = 0;
    } else {
        if ($donation_level_rounded >= 1) {
            $future = 2;
        } else {
            if ($donation_level_rounded < 1) {
                $future = 1;
            }
        }
    }
    $debug_txt .= "future = {$future}, current = {$current}\n";
    $change = $future - $current;
    if ($change == 0) {
        $debug_txt .= "User has right level, nothing to do\n";
        return false;
        // bail if no change needed
    } else {
        // we have a change in level, let's get an error report
        $debug = true;
    }
    $debug_txt .= "User will change {$change} levels\n";
    // get currect rank index
    $debug_txt .= "Current Rank index = {$cur_lvl}\n";
    // calculate base level
    $base_lvl = $cur_lvl - $current;
    $debug_txt .= "User base level = {$base_lvl}\n";
    $new_lvl = $base_lvl + $future;
    if ($new_lvl == $cur_lvl) {
        XMPP_ERROR_send_msg("Donations upgrade: Nothing to do, CHECK this should have bailed earlier!");
        return false;
    }
    $new_rank = $UMC_SETTING['ranks'][$new_lvl];
    $debug_txt .= "User {$username} upgraded from {$level} to {$new_rank}\n";
    umc_exec_command("pex user {$uuid} group set {$new_rank}");
    umc_log('Donations', 'User Level de/promotion', "User {$username} upgraded from {$level} to {$new_rank}");
    if ($debug) {
        XMPP_ERROR_send_msg($debug_txt);
    }
    return $donation_level_rounded;
    // . "($donation_level $current - $future - $change)";
}
Example #10
0
/**
 * This downloads all icons from Minecraft Wiki and stores it on the website
 *
 * @global array $UMC_DATA_ID2NAME
 */
function umc_get_icons()
{
    global $UMC_DATA, $UMC_PATH_MC;
    $base_url = 'http://hydra-media.cursecdn.com/minecraft.gamepedia.com';
    $base_path = "{$UMC_PATH_MC}/server/bin/data/icons/";
    $img_arr = array();
    foreach ($UMC_DATA as $item => $D) {
        if (isset($D['subtypes'])) {
            foreach ($D['subtypes'] as $id => $S) {
                if ($S['icon_url'] != '?') {
                    $img_arr[$S['name']] = $base_url . $S['icon_url'];
                }
            }
        }
        if ($D['icon_url'] === '?') {
            continue;
        } else {
            $img_arr[$item] = $base_url . $D['icon_url'];
        }
    }
    // pass all arrays to mass-downloader
    $complete_count = count($img_arr);
    $D = unc_serial_curl($img_arr);
    $failed_icons = array();
    foreach ($D as $img => $R) {
        if ($R['response']['http_code'] !== 200) {
            $failed_icons[] = array('img' => $img, 'url' => $R['response']['url'], 'reason' => "failed to get file from source");
        } else {
            // assemble target path
            $full_url = $R['response']['url'];
            $path_info = pathinfo($full_url);
            if (!isset($path_info['extension'])) {
                XMPP_ERROR_trace("Extension missning for {$img}", $full_url);
            }
            $ext = $path_info['extension'];
            $target_path = $base_path . "{$img}.{$ext}";
            // write target file
            $written = file_put_contents($target_path, $R['content']);
            if (!$written) {
                $failed_icons[] = array('img' => $img, 'url' => $R['response']['url'], 'reason' => 'failed to write file to $target_path');
            }
        }
    }
    $count = count($failed_icons);
    if ($count > 0) {
        XMPP_ERROR_trace("failed users:", $failed_icons);
        XMPP_ERROR_trigger("Failed to get {$count} of {$complete_count} Block icons, see error report for details");
    }
}
function umc_skyblock_challenge_select()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    if (!is_numeric($args[2])) {
        umc_error("Your challenge ID needs to be a number!");
    } else {
        $lot_sql = "SELECT region_cuboid.region_id as lot FROM `region_cuboid`\r\n            LEFT JOIN region_players ON region_cuboid.region_id=region_players.region_id\r\n            WHERE user_id IS NULL\r\n\t\tAND region_cuboid.`region_id` LIKE 'block%'\r\n\t\tAND min_z<-768\r\n\t\tAND min_x>=-1152\r\n\t\tAND max_x<1024;";
        $D = umc_mysql_fetch_all($lot_sql);
        if (count($D) == 0) {
            XMPP_ERROR_trigger("We ran out of challenge lots!");
            umc_error("Sorry, there are currently no challenge lots free!");
        } else {
            $lot_row = $D[0];
            $challenge_lot = $lot;
        }
        $id = $args[2];
        $sql = "SELECT * FROM minecraft_quiz.block_challenges WHERE challenge_id={$id};";
        $rst = umc_mysql_query($sql);
        $row = umc_mysql_fetch_array($rst);
        $lot = $row['lot'];
        $biome = $row['biome'];
        $inventory = $row['inventory'];
        $name = $row['name'];
        $desc = $row['desc'];
        $win_conditions = $row['win_conditions'];
        umc_header("Challenge {$id}: {$name}");
        umc_echo("{white}{$desc}");
        $lot_str = $lot;
        if ($lot == null) {
            $lot_str = 'standard';
        }
        umc_echo("{green}Lot type: {white}{$lot_str}");
        $biome_str = $biome;
        if ($biome == null) {
            $biome_str = 'standard';
        }
        umc_echo("{green}Lot type: {white}{$biome_str}");
        if (umc_skyblock_web_display_table($id)) {
            umc_echo("{green}Sub challenges: {white}This challenge has subchallenges. Please see the website for details.");
        }
        $inv_str = umc_skyblock_inv_to_desc($inventory);
        umc_echo("{green}Starting Inventory:{white}{$inv_str}");
        $winstr = umc_skyblock_inv_to_desc($win_conditions);
        umc_echo("{green}Winning conditions:{white}{$winstr}");
        $sub_challenge = $row['sub_challenge'];
        $challenge = $id;
        if ($sub_challenge !== null) {
            $challenge = $sub_challenge;
        }
        $sql = "INSERT INTO `minecraft_quiz`.`block_games` (`game_id`, `username`, `start`, `end`, `status`, `challenge_id`, `sub_challenge_id`, `lot`)\r\n            VALUES (NULL, '{$player}', NOW(), NULL, 'selected', '{$challenge}', '{$sub_challenge}', '{$challenge_lot}');";
        umc_mysql_query($sql, true);
        umc_echo("Please type {green}/skyblock start{white} or {green}/skyblock cancel");
        umc_footer();
    }
}
Example #12
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");
}
Example #13
0
/**
 * tries to find a location far out that was not used as a hunger game before
 * this will also create the warp point in essentials
 *
 * @return array('x' => $center_x, 'z' => $center_z)
 */
function umc_hunger_find_random_location()
{
    // 30 Mio is the MC hard limit
    $min_val = 1000;
    $max_val = 30000000 - 2000;
    //we take the max and some margin
    // find a center
    $center_x = rand($min_val, $max_val);
    $center_z = rand($min_val, $max_val);
    // which quarter of the map?
    $dir_x = rand(0, 1);
    if ($dir_x == 0) {
        $center_x = $center_x * -1;
    }
    $dir_z = rand(0, 1);
    if ($dir_z == 0) {
        $center_z = $center_z * -1;
    }
    // check if a game existed on that location
    $sql = "SELECT id FROM minecraft_iconomy.hunger_games\r\n        WHERE x > ({$center_x} - 500)\r\n\t    AND x < ({$center_x} + 500)\r\n\t    AND z < ({$center_z} + 500)\r\n\t    AND z > ({$center_z} - 500);";
    $data = umc_mysql_fetch_all($sql);
    // too close, try again
    if (count($data) > 0) {
        umc_log('hunger', 'found_location_fail', "Found alrady existing location X: {$center_x} Z: {$center_z} - retrying");
        XMPP_ERROR_trigger("hunger rejected location X: {$center_x} Z: {$center_z}, trying again");
        return umc_hunger_find_random_location();
    } else {
        XMPP_ERROR_send_msg("hunger Found location X: {$center_x} Z: {$center_z}");
        // update warp point
        $text = "yaw: 0.0\nname: hunger\npitch: 0.0\nz: {$center_z}\ny: 250\nworld: hunger\nx: {$center_x}";
        $filename = '/home/minecraft/server/bukkit/plugins/Essentials/warps/hunger.yml';
        file_put_contents($filename, $text);
        // reload essentials
        umc_ws_cmd('ess reload', 'asConsole');
        return array('x' => $center_x, 'z' => $center_z);
    }
}
function umc_lottery_lot_fix_time($datetime)
{
    if (!strstr($datetime, ':')) {
        // unix timestamp
        $datetime = "@{$datetime}";
        if (strlen($datetime) > 10) {
            $datetime = substr($datetime, 0, 11);
        }
        $date_new = new DateTime($datetime);
    } else {
        $pieces = explode(" ", $datetime);
        if (count($pieces) == 2) {
            $date_new = new DateTime($datetime);
        } else {
            // 2014-07-18 09:07:48 -0700
            $date_new = DateTime::createFromFormat('Y-m-d H:i:s T', $datetime);
        }
    }
    if (!$date_new) {
        XMPP_ERROR_trigger("Error: failed to parse date format {$datetime} (umc_lottery_lot_fix_time)");
    }
    $date_new->setTimezone(new DateTimeZone('Asia/Hong_Kong'));
    $time = $date_new->format('Y-m-d H:i:s');
    return $time;
}
Example #15
0
/**
 * Iterate all files in a folder and make a list of all the images with all the info
 * for them
 *
 * @global type $UNC_GALLERY
 * @param type $folder
 * @return array
 */
function unc_day_images_list($D = false)
{
    global $UNC_GALLERY, $wpdb;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    if (!$D) {
        $D = $UNC_GALLERY['display'];
    }
    $dates = $D['dates'];
    if (count($dates) == 0) {
        return false;
    }
    $files = array();
    $featured_list = array();
    // SQL construction
    $sql_filter = '';
    // both end_time and start_time are set
    if ($D['range']['end_time'] && $D['range']['start_time']) {
        $start_time = $D['date_range']['start_time'];
        $end_time = $D['date_range']['end_time'];
        $date = $D['dates'][0];
        if ($D['range']['start_time'] < $D['range']['end_time']) {
            $sql_filter = " (file_time >= '{$start_time}' AND file_time <= '{$end_time}')";
        } else {
            if ($D['range']['start_time'] > $D['range']['end_time']) {
                $sql_filter = " ((file_time >= '{$date} 00:00:00' AND file_time <= '{$end_time}') OR (file_time >= '{$start_time}' AND file_time <= '{$date} 23:59:59'))";
            }
        }
    } else {
        if ($D['range']['end_time']) {
            // get everything from day start until end time
            $end_time = $D['date_range']['end_time'];
            $date = $D['dates'][0];
            $sql_filter = " (file_time >= '{$date} 00:00:00' AND file_time <= '{$end_time}')";
        } else {
            if ($D['range']['start_time']) {
                // get everything from start till day end
                $start_time = $D['date_range']['start_time'];
                $date = $D['dates'][0];
                $sql_filter = " (file_time >= '{$start_time}' AND file_time <= '{$date} 23:59:59')";
            } else {
                $dates = $D['dates'];
                $date_sql = implode($dates, "','");
                $sql_filter = " (att_value IN('{$date_sql}'))";
            }
        }
    }
    // get all images for the selected dates
    $img_table_name = $wpdb->prefix . "unc_gallery_img";
    $att_table_name = $wpdb->prefix . "unc_gallery_att";
    $sql = "SELECT * FROM `{$img_table_name}`\r\n        LEFT JOIN {$att_table_name} ON {$img_table_name}.id={$att_table_name}.file_id\r\n        WHERE ({$att_table_name}.att_name='date_str') AND {$sql_filter}\r\n        ORDER BY file_time ASC;";
    $file_data = $wpdb->get_results($sql, 'ARRAY_A');
    XMPP_ERROR_trace("sql", $sql);
    //XMPP_ERROR_trace("sql_dates", $file_data);
    //XMPP_ERROR_trace("Date settings", $D);
    //XMPP_ERROR_trigger("test");
    foreach ($file_data as $F) {
        $I = unc_image_info_read($F['file_path']);
        if (in_array($F['file_name'], $D['featured_image'])) {
            $I['featured'] = true;
            $featured_list[] = $I;
        } else {
            $I['featured'] = false;
            $files[] = $I;
        }
    }
    // TODO: Move this to the SQL string
    // random featured file
    if (in_array('random', $D['featured_image'])) {
        $new_featured_key = array_rand($files);
        $new_featured_arr = $files[$new_featured_key];
        $new_featured_arr['featured'] = true;
        $featured_list[] = $new_featured_arr;
        unset($files[$new_featured_key]);
    }
    // TODO: Move this to the SQL string
    if (in_array('latest', $D['featured_image'])) {
        reset($files);
        $first_key = key($files);
        $new_featured_arr = $files[$first_key];
        $new_featured_arr['featured'] = true;
        $featured_list[] = $new_featured_arr;
        unset($files[$first_key]);
    }
    foreach ($featured_list as $feat) {
        array_unshift($files, $feat);
    }
    if (count($files) == 0) {
        if ($UNC_GALLERY['debug']) {
            XMPP_ERROR_trigger("Zero images found");
        }
    }
    return $files;
}
/**
 * Set a meta-value for a user
 *
 * @param string $uuid
 * @param string $meta_key
 * @param string $meta_value
 */
function umc_wp_set_meta($uuid, $meta_key, $meta_value)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER;
    $current_uuid = $UMC_USER['uuid'];
    if ($uuid == $current_uuid) {
        $user = wp_get_current_user();
    } else {
        $user_login = umc_wp_get_login_from_uuid($uuid);
        $user = get_user_by('login', $user_login);
    }
    $check = update_user_meta($user->ID, $meta_key, $meta_value);
    if (!$check) {
        XMPP_ERROR_trigger("Unable to set User Meta {$meta_key} to {$meta_value} for user {$uuid} and ID" . $user->ID);
    }
}
function umc_mysql_fetch_all($sql)
{
    global $UNC_DB;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $stmt = $UNC_DB['link']->prepare($sql);
    if (!$stmt) {
        $error = $UNC_DB['link']->errorInfo();
        XMPP_ERROR_trigger($error);
        return false;
    } else {
        $stmt->execute();
    }
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
    return $result;
}
Example #18
0
function umc_story_admin()
{
    global $UMC_USER;
    if (!$UMC_USER) {
        die('You need to be online to use this!');
    }
    if (!isset($UMC_USER['uuid'])) {
        XMPP_ERROR_trigger("UUID not set");
    }
    $uuid = $UMC_USER['uuid'];
    $story = 'Please enter text here';
    $pass = umc_get_code();
    $action_text = "Add a new entry";
    $action_code = "add";
    $title = "Insert a title";
    $survival = 0;
    $items = '';
    $warp = '';
    $clear_inv = 0;
    if (isset($_POST['delete'])) {
        $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
        $sql = "DELETE FROM minecraft_iconomy.story WHERE uuid='{$uuid}' AND code={$code};";
        $rst = umc_mysql_query($sql);
    } else {
        if (isset($_POST['add'])) {
            $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
            $warp = umc_mysql_real_escape_string(strip_tags($_POST['warp']));
            $save_story = umc_mysql_real_escape_string(strip_tags($_POST['story']));
            $save_title = umc_mysql_real_escape_string(strip_tags($_POST['storyline']));
            $save_items = umc_mysql_real_escape_string(strip_tags($_POST['items']));
            $save_survival = 0;
            if (isset($_POST['survival'])) {
                $save_survival = -1;
            }
            $save_clear_inv = 0;
            if (isset($_POST['clear_inv'])) {
                $save_clear_inv = -1;
            }
            if ($save_story != 'Please enter text here') {
                $sql2_raw = "INSERT INTO minecraft_iconomy.story (`uuid`, `story`, `code`, `storyline`, `forcesurvival`, `items`, `clear_inv`, `warp`)\r\n                VALUES ('{$uuid}', {$save_story}, {$code}, {$save_title}, '{$save_survival}', {$save_items}, '{$save_clear_inv}', {$warp})";
                $sql2 = str_replace('&', '_', $sql2_raw);
                // this removes strings that can be abused by the minimap
                umc_mysql_query($sql2);
            }
        } else {
            if (isset($_POST['edit'])) {
                $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
                $sql = "SELECT * FROM minecraft_iconomy.story WHERE uuid='{$uuid}' AND code={$code};";
                $D = umc_mysql_fetch_all($sql);
                if (count($D) > 0) {
                    $row = $D[0];
                    $story = stripslashes(strip_tags($row['story']));
                    $pass = $row['code'];
                    $warp = $row['warp'];
                    $action_text = "Edit story and save";
                    $action_code = "update";
                    $title = $row['storyline'];
                    $survival = $row['forcesurvival'];
                    $items = $row['items'];
                    $clear_inv = $row['clear_inv'];
                }
            } else {
                if (isset($_POST['update'])) {
                    $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
                    $save_story = umc_mysql_real_escape_string(strip_tags($_POST['story']));
                    $save_title = umc_mysql_real_escape_string(strip_tags($_POST['storyline']));
                    $save_items = umc_mysql_real_escape_string(strip_tags($_POST['items']));
                    $save_survival = 0;
                    if (isset($_POST['survival'])) {
                        $save_survival = -1;
                    }
                    $warp = '';
                    if (isset($_POST['warp'])) {
                        $warp = umc_mysql_real_escape_string(strip_tags($_POST['warp']));
                    }
                    $save_clear_inv = 0;
                    if (isset($_POST['clear_inv'])) {
                        $save_clear_inv = -1;
                    }
                    $sql = "UPDATE minecraft_iconomy.story\r\n\t    SET story= {$save_story},\r\n\t\tstoryline={$save_title},\r\n\t\twarp={$warp},\r\n\t\tforcesurvival='{$save_survival}',\r\n            \t`items`={$save_items},\r\n\t\t`clear_inv`='{$save_clear_inv}'\r\n            WHERE uuid='{$uuid}' and code={$code};";
                    $sql = str_replace('&', '_', $sql);
                    // this removes strings that can be abused by the minimap
                    umc_mysql_query($sql, true);
                }
            }
        }
    }
    $sql = "SELECT * FROM minecraft_iconomy.story WHERE uuid='{$uuid}' ORDER BY storyline, id;";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) > 0) {
        echo "<table><tr><td style=\"padding:3px;\"><strong>Storyline</strong></td><td style=\"padding:3px;\"><strong>Survival?<br>Clear Inv?</strong></td><td style=\"padding:3px;\"><strong>Code</strong></td>" . "<td style=\"padding:3px;\"><strong>Hits</strong></td>" . "<td style=\"padding:3px;\"><strong>Story & items</strong></td><td style=\"padding:3px;\"><strong>Actions</strong></td></tr>\n";
        foreach ($D as $row) {
            $count_sql = "SELECT count(uuid) as counter FROM minecraft_iconomy.story_users WHERE story_id='{$row['id']} GROUP BY story_id';";
            $D = umc_mysql_fetch_all($count_sql);
            $count_row = $D[0];
            $hitcount = $count_row['counter'];
            $story_short = substr($row['story'], 0, 50) . '...';
            $txt_survival = 'No';
            if ($row['forcesurvival'] == -1) {
                $txt_survival = 'Yes';
            }
            $txt_clear_inv = 'No';
            if ($row['clear_inv'] == -1) {
                $txt_clear_inv = 'Yes';
            }
            if (strlen($row['items']) > 0) {
                $story_short = $story_short . "<br><strong>Items:</strong>" . $row['items'];
            }
            $buttons = "<form action=\"#result\" method=\"post\"><input type=\"submit\" name=\"edit\" class=\"button-primary\"value=\"Edit\"/> " . "<input type=\"submit\" name=\"delete\" class=\"button-primary\"value=\"Delete\"/><input type=\"hidden\" name=\"storycode\" value=\"{$row['code']}\"></form>";
            echo "<tr><td>{$row['storyline']}</td><td>{$txt_survival} / {$txt_clear_inv}</td><td>{$row['code']}</td><td>{$hitcount}</td><td>{$story_short}</td><td>{$buttons}</td></tr>\n";
        }
        echo "</table>";
    }
    // add new content form
    $surv_checked = '';
    if ($survival == -1) {
        $surv_checked = ' checked="checked"';
    }
    $inv_checked = '';
    if ($clear_inv == -1) {
        $inv_checked = ' checked="checked"';
    }
    $out = "<hr><a name=\"result\">{$action_text}:</a><form action=\"#result\" method=\"post\">\n" . "<strong>Your story code: {$pass}</strong><br>" . "Title: <input type=\"text\" name=\"storyline\" value=\"{$title}\"> Force Survival mode? <input type=\"checkbox\" name=\"survival\" value=\"survival\"{$surv_checked}/>" . " Clear inventory? <input type=\"checkbox\" name=\"clear_inv\" value=\"clear_inv\"{$inv_checked}/> (city & flatlands only)<br>" . "Give items: <input type=\"text\" name=\"items\" value=\"{$items}\"> (Format: item_id:damage:amount;... city & flatlands only)<br>" . "Warp to point: <input type=\"text\" name=\"warp\" value=\"{$warp}\"> (Format: 'story_yourwarp'; Ask Uncovery to create a warp point for you, only works in city. Do not include the story_ here)<br>" . "<textarea rows=\"10\" name=\"story\">{$story}</textarea>" . "<input type=\"hidden\" name=\"storycode\" value=\"{$pass}\">" . "<input type=\"submit\" name=\"{$action_code}\" id=\"wp-submit\" class=\"button-primary\" " . "value=\"Save\" tabindex=\"100\" /></form>\n\n";
    echo $out;
}
Example #19
0
/**
 * Give the user every possible block and make sure that he actually got it!
 */
function umc_mod_blockcheck()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER;
    $username = $UMC_USER['username'];
    umc_ws_cmd("ci {$username};", 'asConsole');
    $result['item_name'] = 'air';
    if (!isset($UMC_USER['args'][1])) {
        $start = 0;
    } else {
        $start = $UMC_USER['args'][1];
    }
    umc_echo("Starting to fill inventory!");
    $result = umc_mod_blockcheck_fill_inv($start);
    $count = $result['count'];
    umc_echo("Filled inventory until " . $result['item_name'], ", at number {$count}");
    umc_mod_blockcheck_check_inv($count);
    XMPP_ERROR_trigger("Blockcheck Done!");
}
Example #20
0
function umc_read_markers_file($format = 'html', $world = 'empire', $user = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    /*   [0]=>
          object(stdClass)#1 (5) {
            ["timestamp"]=> string(19) "2011-01-31 14:14:47"
            ["z"]=> float(-319.54668819556)
            ["msg"]=> string(8) "Thegiant"
            ["y"]=> float(50)
            ["x"]=> float(448.69999998808)
        */
    global $UMC_SETTING, $UMC_PATH_MC;
    $file = "{$UMC_PATH_MC}/server/bin/data/markers.json";
    // $UMC_SETTING['markers_file'];
    $text = file_get_contents($file);
    if (!$file) {
        XMPP_ERROR_trigger("Could not read markers file (umc_read_markers_file)");
    }
    $m = json_decode($text);
    // no users
    if (!$m) {
        return '';
    }
    $out_arr = array();
    $map = $UMC_SETTING['world_img_dim'][$world];
    if (count($m) == 0) {
        return '';
    }
    if ($format == 'scrollto') {
        $out = "<div id=\"scroll_to_icons\">\n";
    } else {
        $out = "<div id=\"marker_list\">\n";
    }
    // check if we find the single user from the marker
    $foundplayer = false;
    // var_dump($format);
    foreach ($m as $marker) {
        $z = $marker->z;
        $x = $marker->x;
        $x_text = round($x);
        $z_text = round($z);
        $top = conv_z($marker->z, $map);
        // + $map['img_top_offset'];
        $left = conv_x($marker->x, $map);
        // + $map['img_left_offset'];
        $username = strtolower($marker->msg);
        $playerworld = $marker->world;
        if ($username == 'uncovery') {
            //continue;
        }
        $icon_url = umc_user_get_icon_url($username);
        if ($format == 'identify_user' && $username == $user) {
            $out .= '   <span class="marker" style="z-index:100; top:' . $top . 'px; left:' . $left . "px;\"><img src=\"{$icon_url}\" title=\"{$username}\" alt=\"{$username}\"> <input type=\"submit\" name=\"track_player\" value=\"That's me!\"></span>\n" . "\n";
            $foundplayer = true;
        } else {
            if ($format == 'track_user' && $username == $user) {
                $out .= '   <span class="marker"  id="' . $username . '_marker" style="z-index:100; top:' . $top . 'px; left:' . $left . "px;\"><img src=\"{$icon_url}\" title=\"{$username}\" alt=\"{$username}\"></span>\n" . "\n";
                $foundplayer = true;
            } else {
                if ($format == 'scrollto' && $marker->world == $world) {
                    $out .= "<img src=\"{$icon_url}\" title=\"{$username}\" alt=\"{$username}\" onclick=\"find_user({$left}, {$top}, '{$username}_marker')\">\n";
                } else {
                    if ($format == 'html' && $marker->world == $world) {
                        if ($world == 'hunger') {
                            $out .= '<div class="marker" style="position:relative">' . $username . '</div>' . "\n";
                        } else {
                            $out .= '   <img id="' . $username . '_marker" class="marker" style="z-index:100; top:' . $top . 'px; left:' . $left . "px;\" src=\"{$icon_url}\" title=\"{$username} (x:{$x_text} z:{$z_text})\" alt=\"{$username} (x:{$x_text} z:{$z_text})\">\n";
                        }
                    } else {
                        if ($format == 'json') {
                            $arr[] = array('name' => $username, 'url' => $icon_url, 'top' => $top, 'left' => $left);
                        } else {
                            if ($format == 'all_users') {
                                // list all users for website status
                                $out .= $username . " ";
                            } else {
                                if ($format == 'array') {
                                    $out_arr[$username] = array('name' => $username, 'url' => $icon_url, 'top' => $top, 'left' => $left, 'world' => $playerworld, 'x' => $x_text, 'z' => $z_text);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (($format == 'identify_user' || $format == 'track_user') && $foundplayer == false) {
        // umc_error_notify("Could not find single player $user in Json Data: \n" . var_export($m, true));
    }
    if ($format == 'json') {
        $out = json_encode($arr);
    } else {
        if ($format == 'array') {
            return $out_arr;
        }
    }
    if ($format == 'scrollto') {
        $out .= "</div>\n";
    } else {
        if ($format == 'html') {
            // no idea why this was here. it would duplicate the output.
            // $out .= umc_read_markers_file('scrollto', $world);
        }
        $out .= "</div>\n";
    }
    return $out;
}
Example #21
0
/**
 * Converts EXIF GPS Data to decimal coordinates
 *
 * @global array $UNC_GALLERY
 * @param type $gps_arr
 * @return type
 */
function unc_exif_convert_gps($gps_arr)
{
    global $UNC_GALLERY;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    // $gps array elelemt 1 is the reference, 0 is the coordinate
    if (!isset($gps_arr['Coordinates'])) {
        XMPP_ERROR_trigger("GPS Coord not set!");
    }
    if (!isset($gps_arr['Hemisphere'])) {
        XMPP_ERROR_trigger("GPS Hemisphere not set!");
    }
    $coord = $gps_arr['Coordinates'];
    $hemi = $gps_arr['Hemisphere'];
    $degrees = count($coord) > 0 ? unc_exif_convert_gps_2_Num($coord[0]) : 0;
    $minutes = count($coord) > 1 ? unc_exif_convert_gps_2_Num($coord[1]) : 0;
    $seconds = count($coord) > 2 ? unc_exif_convert_gps_2_Num($coord[2]) : 0;
    $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
    $out = $flip * ($degrees + $minutes / 60 + $seconds / 3600);
    return $out;
}
function umc_usericon_get($users = false, $update = true)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_PATH_MC;
    $steve_head = '/home/minecraft/server/bin/data/steve.png';
    if (!$users) {
        $users = umc_get_active_members();
    } else {
        if (is_array($users) && count($users) == 0) {
            XMPP_ERROR_send_msg("umc_update_usericons got zero users!");
        } else {
            if (!is_array($users)) {
                $U = umc_uuid_getboth($users);
                $users = array($U['uuid'] => $U['username']);
            }
        }
    }
    $users_raw = array();
    foreach ($users as $uuid => $username) {
        $uuid_raw = str_replace("-", "", $uuid);
        $users_raw[$uuid] = $url = "https://sessionserver.mojang.com/session/minecraft/profile/{$uuid_raw}";
    }
    $no_skin = array();
    $failed_users = array();
    $skin_urls = array();
    $D = unc_serial_curl($users_raw, 0, 50, '/home/includes/unc_serial_curl/google.crt');
    foreach ($D as $uuid => $d) {
        // we only update the skin if it does not exist
        if (!$update && file_exists("{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png")) {
            continue;
        }
        if ($uuid == 'abandone-0000-0000-0000-000000000000') {
            continue;
        }
        if ($d['response']['http_code'] !== 200) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $d['response']['url'], 'reason' => 'Could not download user data');
        }
        $base64_texture = '';
        $d_arr = json_decode($d['content']);
        if (!$d_arr) {
            XMPP_ERROR_trigger("Failed to retrieve session profile for {$uuid}");
        }
        //object(stdClass)#2 (3) {
        //  ["id"]=>
        //  string(32) "ab3bc877443445a993bdbab6df41eabf"
        //  ["name"]=>
        //  string(8) "uncovery"
        //  ["properties"]=>
        //  array(1) {
        //    [0]=>
        //    object(stdClass)#3 (2) {
        //      ["name"]=>
        //      string(8) "textures"
        //      ["value"]=>
        //      string(308) "eyJ0aW1lc3RhbXAiOjE0NDA0NzUyOTQ2NDksInByb2ZpbGVJZCI6ImFiM2JjODc3NDQzNDQ1YTk5M2JkYmFiNmRmNDFlYWJmIiwicHJvZmlsZU5hbWUiOiJ1bmNvdmVyeSIsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9jYWVhMjljODY2ZDkyMTVhYWJjMTk5MDQyMTE1ZWMwNTUzMzJkNjZlMGI4ZWY2ZjkyNjNmZTRiMWZlNzZlIn19fQ=="
        //    }
        //  }
        //}
        if (!isset($d_arr->properties)) {
            XMPP_ERROR_trace("json", $d_arr);
            XMPP_ERROR_trigger("Failed to retrieve properties for {$uuid}");
        }
        $prop_count = count($d_arr->properties);
        for ($i = 0; $i < $prop_count; $i++) {
            if ($d_arr->properties[$i]->name == 'textures') {
                $base64_texture = $d_arr->properties[$i]->value;
            } else {
                echo "Wrong property: " . $d_arr->properties[$i]->name;
            }
        }
        $raw_texture = base64_decode($base64_texture);
        // {"timestamp":1440475294649,"profileId":"ab3bc877443445a993bdbab6df41eabf","profileName":"uncovery","textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/caea29c866d9215aabc199042115ec055332d66e0b8ef6f9263fe4b1fe76e"}}}
        $texture_arr = json_decode($raw_texture);
        if (!$texture_arr) {
            XMPP_ERROR_trigger("Failed to decode texture: {$raw_texture}");
        }
        $time_stamp = $texture_arr->timestamp;
        // check if the file on the drive is newer
        $current_file = "{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png";
        if (!file_exists($current_file) || filemtime($current_file) > $time_stamp) {
            if (isset($texture_arr->textures->SKIN)) {
                // user did not set skin
                $skin_urls[$uuid] = $texture_arr->textures->SKIN->url;
                // echo $texture_arr->textures->SKIN->url . "<br>\n";
            } else {
                XMPP_ERROR_trace("{$uuid} does not have a skin: {$raw_texture}");
                $no_skin[] = $uuid;
            }
        }
    }
    $S = unc_serial_curl($skin_urls);
    foreach ($S as $uuid => $s) {
        $skin_file = "{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png";
        $head_file = "{$UMC_PATH_MC}/server/bin/data/user_icons/{$uuid}.png";
        if ($s['response']['content_type'] !== 'image/png' && $s['response']['http_code'] !== 200) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $s['response']['url'], 'reason' => 'Could not download image');
            continue;
        }
        $written = file_put_contents($skin_file, $s['content']);
        if (!$written) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $s['response']['url'], 'reason' => "Could not save file to {$skin_file}");
            continue;
        }
        // convert to head icon, resize to 20x20
        $command = "convert -crop '8x8+8+8' -scale 20 \"{$skin_file}\" \"{$head_file}\"";
        exec($command);
    }
    // process users w/o skin
    foreach ($no_skin as $uuid) {
        $head_file = "{$UMC_PATH_MC}/server/bin/data/user_icons/{$uuid}.png";
        if (!file_exists($steve_head)) {
            XMPP_ERROR_trigger("Steve head icon not available");
        } else {
            $check = copy($steve_head, $head_file);
            if (!$check || !file_exists($head_file)) {
                XMPP_ERROR_trigger("Could not create steve head for file {$head_file}");
            } else {
                XMPP_ERROR_trace("used steve head for {$head_file}");
            }
        }
    }
    if (count($failed_users) > 0) {
        XMPP_ERROR_trace("failed users:", $failed_users);
        XMPP_ERROR_trigger("Users failed to get icon, see error report for details");
    }
}
Example #23
0
function umc_wp_get_uncovery_avatar($avatar, $id_or_email, $size, $default, $alt)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if ($default == 'uncovery') {
        $filename = '/home/minecraft/server/bin/core_include.php';
        require_once $filename;
        if (!function_exists('umc_user_ban')) {
            XMPP_ERROR_trigger("Failed to include {$filename}!");
        }
        //Alternative text
        if (false === $alt) {
            $safe_alt = '';
        } else {
            $safe_alt = esc_attr($alt);
        }
        //Get username
        if (is_numeric($id_or_email)) {
            $id = (int) $id_or_email;
            $user = get_userdata($id);
            if ($user) {
                $username = $user->user_login;
            } else {
                return false;
                // user cannot be found, probably deleted
            }
        } else {
            if (is_object($id_or_email)) {
                if (!empty($id_or_email->user_id)) {
                    $id = (int) $id_or_email->user_id;
                    $user = get_userdata($id);
                    if ($user) {
                        $username = $user->user_login;
                    } else {
                        return '';
                    }
                } else {
                    if (!empty($id_or_email->comment_author)) {
                        $username = $id_or_email->comment_author;
                    }
                }
            } else {
                if (strstr($id_or_email, '@')) {
                    // email
                    require_once ABSPATH . WPINC . '/ms-functions.php';
                    $user = get_user_by('email', $id_or_email);
                    $username = $user->user_login;
                } else {
                    // by displayname
                    $username = $id_or_email;
                }
            }
        }
        $uuid = umc_wp_get_uuid_from_userlogin($username);
        $icon = umc_user_get_icon_url($uuid);
        // 'https://crafatar.com/avatars/' . $uuid . '?size=' . $size;
        $avatar = "<img  class='avatar avatar-64 photo' alt='" . $safe_alt . "' src='" . $icon . "' class='avatar avatar-" . $size . " photo' height='" . $size . "' width='" . $size . "' />";
    }
    return $avatar;
}
/**
 * Return an array of the logged-in player's inventory
 *
 * @param json_data $inv_data
 * @return type
 */
function umc_ws_get_inv($inv_data)
{
    global $UMC_DATA_SPIGOT2ITEM, $UMC_DATA, $UMC_DATA_ID2NAME;
    // XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $inv = array();
    foreach ($inv_data as $item) {
        $slot = $item['Slot'];
        $inv[$slot] = array();
        $inv[$slot]['meta'] = false;
        foreach ($item as $name => $value) {
            if ($name == 'TypeName') {
                $item_typename = strtolower($item['TypeName']);
                if (isset($UMC_DATA_SPIGOT2ITEM[$item_typename])) {
                    $inv[$slot]['item_name'] = $UMC_DATA_SPIGOT2ITEM[$item_typename];
                } else {
                    if (isset($UMC_DATA[$item_typename])) {
                        $inv[$slot]['item_name'] = $item_typename;
                    } else {
                        $inv[$slot]['item_name'] = $UMC_DATA_ID2NAME[$item['Type']];
                        XMPP_ERROR_trigger("ITEM ISSUE: {$item_typename} not found in \$UMC_DATA, item {$item['Type']} : {$item['Durability']}, should be {$inv[$slot]['item_name']}");
                    }
                }
            } else {
                if ($name == "Type") {
                    $inv[$slot]['id'] = $item['Type'];
                } else {
                    if ($name == 'Durability') {
                        $name = 'data';
                        if ($value == -1) {
                            // case 1) saplings of dark oak harvested from minecart maniah have a -1 data
                            umc_clear_inv($data['item_name'], $data['data'], $data['amount']);
                            umc_echo("{red}You had a bugged item in your inventory, it had to be removed!");
                            XMPP_ERROR_trigger("Invalid item with -1 damage found!");
                        } else {
                            $inv[$slot][$name] = $value;
                        }
                    } else {
                        if ($name == 'Meta') {
                            foreach ($value as $meta_type => $meta_value) {
                                // enchantments
                                if ($meta_type == 'Enchantments' || $meta_type == 'EnchantmentStorage') {
                                    foreach ($meta_value as $ench_data) {
                                        $e_name = $ench_data['Name'];
                                        $inv[$slot]['meta'][$e_name] = $ench_data['Level'];
                                    }
                                }
                                if ($meta_type == 'BaseColor') {
                                    $inv[$slot]['meta'] = array($meta_value => $value['Patterns']);
                                }
                            }
                        } else {
                            $name = strtolower($name);
                            $inv[$slot][$name] = $value;
                        }
                    }
                }
            }
        }
    }
    return $inv;
}
/**
 * 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;
    }
}
Example #26
0
/**
 * promotes a user to Citizen if applicable
 *
 * @param type $user_login
 * @param type $userlevel
 * @return type
 */
function umc_promote_citizen($username, $userlevel = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if (!$userlevel) {
        $userlevel = umc_get_userlevel($username);
    }
    $lower_username = strtolower($username);
    $settlers = array('Settler', 'SettlerDonator', 'SettlerDonatorPlus');
    if (in_array($userlevel, $settlers)) {
        /*
        $age = umc_get_lot_owner_age('array', $lower_login);
        if (!$age) {
            return;
        }
        $age_days = $age[$lower_login]['firstlogin']['days'];
        if ($age_days >= 90) {
        *
        */
        $online_hours = umc_get_online_hours($lower_username);
        if ($online_hours >= 60) {
            //user should be Citizen
            $uuid = umc_user2uuid($lower_username);
            if ($userlevel == 'Settler') {
                // pex user <user> group set <group>
                umc_exec_command("pex user {$uuid} group set Citizen");
                umc_log("users", "promotion", "User {$username} ({$uuid}) was promoted from {$userlevel} to Citizen (online hours: {$online_hours})");
            } else {
                if ($userlevel == 'SettlerDonator') {
                    umc_exec_command("pex user {$uuid} group set CitizenDonator");
                    umc_log("users", "promotion", "User {$username} ({$uuid}) was promoted from {$userlevel} to CitizenDonator (online: {$online_hours})");
                } else {
                    if ($userlevel == 'SettlerDonatorPlus') {
                        umc_exec_command("pex user {$uuid} group set CitizenDonatorPlus");
                        umc_log("users", "promotion", "User {$username} ({$uuid}) was promoted from {$userlevel} to CitizenDonatorPlus (online: {$online_hours})");
                    } else {
                        XMPP_ERROR_trigger("{$username} / {$uuid} has level {$userlevel} and could not be promoted to Citizen! Please report to admin!");
                    }
                }
            }
        }
    }
}
/**
 * Creates a list of the given item on stock.
 *
 * @global type $UMC_DATA
 * @param type $table
 * @param type $item
 * @param type $type
 * @param type $uuid
 * @return type
 */
function umc_shopmgr_stocklist($table, $item = false, $type = 0, $uuid = false)
{
    global $UMC_DATA;
    $where = "WHERE damage={$type}";
    // do not show item column if there is only one type
    $what = 'concat(item_name,' | ',damage, ' | ', meta) AS item_name, ';
    if ($item && isset($UMC_DATA[$item])) {
        $where .= " AND item_name='{$item}'";
        $what = '';
    }
    if ($uuid && umc_check_user($uuid)) {
        $where .= " AND uuid='{$uuid}'";
    }
    $sql = "SELECT id AS shop_id, {$what} uuid, amount AS quantity, price FROM minecraft_iconomy.{$table} {$where}";
    $data_rst = umc_mysql_query($sql);
    $sort_column = '0, "desc"';
    $non_numeric = array('item_name', 'uuid');
    $check = umc_web_table('shop' . $table, $sort_column, $data_rst, '', array(), $non_numeric);
    if (!$check) {
        XMPP_ERROR_trigger("Error creating web_table with SQL {$sql}");
        return "Error creating data table. Admin was notified, please wait until it is fixed";
    } else {
        return $check;
    }
}
Example #28
0
function umc_info_whereami()
{
    global $UMC_USER, $UMC_SETTING;
    $world = $UMC_USER['world'];
    $player = $UMC_USER['username'];
    $x = round($UMC_USER['coords']['x'], 1);
    $y = round($UMC_USER['coords']['y'], 1);
    $z = round($UMC_USER['coords']['z'], 1);
    // map coords
    $map_str = '';
    if (isset($UMC_SETTING['world_img_dim'][$world])) {
        $map = $UMC_SETTING['world_img_dim'][$world];
        $map_x = floor(conv_x($x, $map));
        $map_z = floor(conv_z($z, $map));
        $map_str = "{green}2D Map:{white} x: {$map_x}, z: {$map_z}";
    }
    $lot = umc_lot_get_from_coords($x, $z, $world);
    $lot_members = umc_get_lot_members($lot, false);
    $lot_owners = umc_get_lot_members($lot, true);
    if (!$lot) {
        $lot = 'No lot here';
    }
    // chunk
    $chunk_x = floor($x / 16);
    $chunk_z = floor($z / 16);
    // region
    $region_x = floor($x / 512);
    $region_z = floor($z / 512);
    // Yaw
    $yaw = round($UMC_USER['coords']['yaw'], 1);
    // -22.49969482421875 ?
    $yaw_arr = array(0 => 'South', 45 => 'SouthWest', 90 => 'West', 135 => 'NorthWest', 180 => 'North', 225 => 'NorthEast', 270 => 'East', 315 => 'SouthEast', 360 => 'South');
    $var = 22.5;
    $game_yaw = $yaw;
    if ($yaw < 0) {
        $yaw += 360;
    }
    $compass = false;
    foreach ($yaw_arr as $angle => $direction) {
        if ($yaw > $angle - $var && $yaw < $angle + $var) {
            $compass = $direction;
            break;
        }
    }
    // could not identify direction
    if (!$compass) {
        XMPP_ERROR_trigger("Could not idenfiy compass direction in /whereami");
        $compass = "******";
    }
    // time
    $date_today = umc_datetime();
    $today = $date_today->format('Y-m-d H:i:s');
    $world_str = ucwords($world);
    umc_header("Location for {$player}");
    umc_echo("{green}World:{white} {$world_str} {green}Lot:{white} {$lot} {green}Date:{white} {$today}");
    if ($lot_owners) {
        umc_echo("{green}Lot Owner:{white} " . implode(", ", $lot_owners));
        if ($lot_members) {
            umc_echo("{green}Lot Members:{white} " . implode(", ", $lot_members));
        }
    } else {
        umc_echo("{green}Lot Owner:{white} Unoccupied lot");
    }
    umc_echo("{green}Compass:{white} {$compass} {green}Yaw:{white} {$yaw} {green}Game-Yaw:{white} {$game_yaw}");
    umc_echo("{green}Coordinates:{white} x: {$x},  y: {$y},  z: {$z}");
    umc_echo("{green}Chunk:{white} x: {$chunk_x}, z: {$chunk_z} {green}Region:{white} x: {$region_x}, z: {$region_z} {$map_str}");
    umc_footer();
}
/**
 * Moch chunks for lot resets
 *
 * @global array $UMC_PATH_MC
 * @param string $source_lot
 * @param string $source_world
 * @param string $dest_lot
 * @param string $dest_world
 * @param boolean $echo
 * @return boolean
 */
function umc_move_chunks($source_lot, $source_world, $dest_lot, $dest_world, $echo = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_PATH_MC;
    $exec_path = "{$UMC_PATH_MC}/server/chunk/copychunk";
    // get coordinates
    $sql = "SELECT * FROM minecraft_worldguard.region_cuboid WHERE region_id = '{$source_lot}' LIMIT 1;";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) != 1) {
        XMPP_ERROR_trigger("Tried to reset {$source_lot} from {$source_world} to {$dest_lot} on {$dest_world} but {$source_lot} could not be found");
        return false;
    }
    $row = $D[0];
    $min_x = floor($row['min_x'] / 16);
    $max_x = floor($row['max_x'] / 16);
    $min_z = floor($row['min_z'] / 16);
    $max_z = floor($row['max_z'] / 16);
    if ($source_lot != $dest_lot) {
        $sql_dest = "SELECT * FROM minecraft_worldguard.region_cuboid WHERE region_id = '{$dest_lot}' LIMIT 1;";
        $D_dest = umc_mysql_fetch_all($sql_dest);
        if (count($D_dest) != 1) {
            XMPP_ERROR_trigger("Tried to reset {$source_lot} from {$source_world} to {$dest_lot} on {$dest_world} but {$dest_lot} could not be found");
            return false;
        }
        $row_dest = $D_dest[0];
        $min_x_dest = floor($row_dest['min_x'] / 16);
        $max_x_dest = floor($row_dest['max_x'] / 16);
        $min_z_dest = floor($row_dest['min_z'] / 16);
        $max_z_dest = floor($row_dest['max_z'] / 16);
    }
    // check if craftbukkit is running
    $output = array();
    $exec_cmd = 'ps ax | grep -v grep | grep -v -i SCREEN | grep spigot.jar';
    if (!$echo) {
        exec($exec_cmd, $output);
        if (count($output) > 0) {
            XMPP_ERROR_trigger("Tried to move chunks while Minecraft server was running: {$source_lot}, {$source_world}, {$dest_lot}, {$dest_world}");
            return false;
        }
    }
    if ($source_lot == $dest_lot) {
        $exec_cmd = "{$exec_path} {$source_world} {$dest_world} {$min_x} {$min_z} {$max_x} {$max_z}";
    } else {
        $exec_cmd = "{$exec_path} {$source_world} {$dest_world} {$min_x} {$min_z} {$max_x} {$max_z} {$min_x_dest} {$min_z_dest} {$max_x_dest} {$max_z_dest}";
    }
    // $exec_cmd . "<br>";
    if ($echo) {
        echo $exec_cmd . "\n";
    } else {
        exec($exec_cmd, $output);
    }
    umc_log('lot_manager', 'move chunks', "Moved lot from {$source_lot} to {$dest_lot} with command {$exec_cmd}");
    return true;
}
/**
 * this checks if the user exists, and creats it if not. returns the amount in the account.
 * @global type $UMC_ENV
 * @param type $user
 * @return int
 */
function umc_money_check($user)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if ($user == '') {
        XMPP_ERROR_trigger("Failed to get account status for empty user!");
    }
    // check if the user has an acoount
    if (strlen($user) <= 17) {
        $uuid = umc_user2uuid($user);
    } else {
        $uuid = $user;
        $user = umc_user2uuid($uuid);
        if ($user == '') {
            XMPP_ERROR_trigger("Failed to get username for {$uuid}!");
            die;
        }
    }
    $sql = "SELECT balance FROM `minecraft_iconomy`.`mineconomy_accounts` WHERE uuid='{$uuid}';";
    $data = umc_mysql_fetch_all($sql);
    // has account to receive, return value
    if (count($data) > 0) {
        // get amount
        return $data[0]['balance'];
    } else {
        if (count($data) == 0) {
            // create account
            // check if there is a user entry but no UUID
            $sql2 = "SELECT balance FROM `minecraft_iconomy`.`mineconomy_accounts` WHERE account='{$user}';";
            $data2 = umc_mysql_fetch_all($sql2);
            if (count($data2) == 1) {
                // yes, add the UUID
                $fix_sql = "UPDATE `minecraft_iconomy`.`mineconomy_accounts`\r\n\t\t SET uuid='{$uuid}'\r\n                 WHERE account='{$user}';";
                umc_mysql_query($fix_sql, true);
                // try again
                return umc_money_check($user);
            } else {
                // insert row
                $sql3 = "INSERT INTO `minecraft_iconomy`.`mineconomy_accounts` (`uuid`, `account`, `balance`)\r\n                VALUES ('{$uuid}', '{$user}', '100');";
                umc_mysql_query($sql3, true);
                return 0;
            }
        }
    }
}