Exemplo n.º 1
0
function umc_create_map()
{
    global $UMC_SETTING, $UMC_DOMAIN, $UMC_PATH_MC, $UMC_ENV;
    $timer = array();
    $UMC_ENV = '2Dmap';
    $file = $UMC_SETTING['map_css_file'];
    $css = "\n" . '<style type="text/css">' . file_get_contents($file) . "\n";
    $worlds = array('city', 'empire', 'aether', 'flatlands', 'kingdom', 'draftlands', 'skyblock', 'empire_new');
    $longterm = $UMC_SETTING['longterm'];
    $s_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
    $s_get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
    if (isset($s_get['world'])) {
        $world = $s_get['world'];
        if (!in_array($world, $worlds)) {
            exit;
        }
    } else {
        if (isset($s_post['world'])) {
            $world = $s_post['world'];
            if (!in_array($world, $worlds)) {
                exit;
            }
        } else {
            $world = 'empire';
        }
    }
    // get donators
    $donators = umc_users_donators();
    $track_player_icon = '';
    $find_lot = false;
    $settler_test = false;
    $track_player = false;
    // part of the settler test
    if (isset($s_post['settler_test'])) {
        $settler_test = true;
    } else {
        if (isset($s_post['track_player'])) {
            $player = $s_post['track_player'];
            $loc = umc_read_markers_file('array', $world);
            // something is wrong: player is not online or in the wrong world
            if (!isset($loc[$player])) {
                //umc_error_longmsg("Could not find player $player on the 2D map for the settler test! (track_player)\n" . umc_ws_vardump($loc));
                return "You need to be login on the server and be in the {$world} world to do this. Please go back to the previous page and try again.";
            } else {
                // player is in the right world.
                $track_player = true;
                $track_player_icon = "&identify_user={$player}";
            }
        } else {
            if (isset($s_post['guide_lot'])) {
                $player = $s_post['guide_lot'];
                $loc = umc_read_markers_file('array', $world);
                if (!isset($loc[$player])) {
                    XMPP_ERROR_trigger("Could not find player {$player} on the 2D map for the settler test! (guide_lot)\n" . umc_ws_vardump($loc));
                    return "You need to be login on the server and be in the {$world} world to do this. Please go back to the previous page and try again.";
                } else {
                    // player is in the right world.
                    $find_lot = true;
                    $track_player_icon = "&track_user={$player}";
                }
                $player_z = floor($loc[$player]['top']) + 20;
                $player_x = floor($loc[$player]['left']) + 10;
                $player_lot = $s_post['lot'];
            } else {
                $player_x = 0;
                $player_z = 0;
                $lot_x = 0;
                $lot_z = 0;
            }
        }
    }
    $lag = false;
    if (isset($s_get['lag'])) {
        $lag = true;
    }
    $freeonly = false;
    if (isset($s_get['freeonly']) && $s_get['freeonly'] == 'true' || isset($s_post['freeonly']) && $s_post['freeonly'] == 'true') {
        $freeonly = true;
    }
    $menu = '';
    if ($settler_test) {
        $menu .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "<input type=\"hidden\" name=\"step\" value=\"4\">\n<input type=\"hidden\" name=\"world\" value=\"{$world}\">\n";
    } else {
        if ($track_player) {
            $player_lot = $s_post['lot'];
            $menu .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "<input type=\"hidden\" name=\"step\" value=\"7\">\n<input type=\"hidden\" name=\"world\" value=\"{$world}\"><input type=\"hidden\" name=\"lot\" value=\"{$player_lot}\">\n";
        } else {
            if ($find_lot) {
                $menu .= "<form action=\"{$UMC_DOMAIN}/server-access/buildingrights/\" method=\"post\">\n" . "<input type=\"hidden\" name=\"step\" value=\"9\">\n<input type=\"hidden\" name=\"world\" value=\"{$world}\"><input type=\"hidden\" name=\"lot\" value=\"{$player_lot}\">\n";
            }
        }
    }
    $menu .= "<div id=\"menu_2d_map\">\n";
    if (!$settler_test && !$track_player && !$find_lot) {
        // create the top menu
        $menu .= umc_map_menu($worlds, $world, $freeonly);
    } else {
        if ($settler_test) {
            $menu .= "Pick a lot that looks nice to you. Closer to spawn is more convenient. <button type='button' onclick='find_spawn()'>Find Spawn</button> Then click here: " . "<input id=\"settler_test_next\" type=\"submit\" name=\"Next\" value=\"Next\">\n";
        } else {
            if ($find_lot) {
                $menu .= "Walk in-game along the red line to your lot {$player_lot} and then press " . "<input type=\"submit\" name=\"Next\" value=\"Next\"> <button type='button' onclick='find_spawn()'>Find Spawn</button> \n";
            } else {
                $menu .= "Find your user head on the map and click on the button next to it!";
            }
        }
    }
    $menu .= "</div>\n";
    $new_choices = array();
    if ($world == 'empire_new') {
        $rights = umc_region_data('empire');
        // this is for the empire_new move only:
        // var_dump($new_choices);
    } else {
        $rights = umc_region_data($world);
    }
    $timer['after_region_data'] = XMPP_ERROR_ptime();
    $map = $UMC_SETTING['world_img_dim'][$world];
    $image = "{$UMC_PATH_MC}/server/maps/" . $world . ".jpg";
    $size = array(0, 0);
    if (file_exists($image)) {
        $size = getimagesize($image);
    }
    $map_width = $size[0];
    $map_height = $size[1];
    if ($lag) {
        $heatworld = $world;
        $world .= '_heatmap';
    }
    $html = '';
    if ($find_lot) {
        $html = "<canvas id=\"lot_pointer\" style=\"position: absolute; top: 30px; left: 10px; z-index: 99;\" width=\"{$map_width}\" height=\"{$map_height}\"></canvas>\n";
    }
    $html .= '<div id="outer_box">' . "\n" . '    <img src="/map/' . $world . '.jpg" id="image_box" alt="map">' . "\n";
    if ($track_player) {
        $html .= umc_read_markers_file('identify_user', $world, $player);
    } else {
        if ($find_lot) {
            $html .= umc_read_markers_file('track_user', $world, $player);
        } else {
            if ($lag) {
                $html .= umc_read_markers_file('html', $heatworld);
            } else {
                $html .= umc_read_markers_file('html', $world);
            }
        }
    }
    //$repl_arr = array(',','-');
    $kingdom = '';
    if ($world == 'kingdom' || $world == 'draftlands') {
        $kingdom = 'center';
    }
    if (isset($UMC_SETTING['world_data'][$world]['spawn'])) {
        $spawn_lot = strtoupper($UMC_SETTING['world_data'][$world]['spawn']);
    } else {
        $spawn_lot = '';
    }
    // $old_users =
    $timer['before_owner_age'] = XMPP_ERROR_ptime();
    $all_lastlogins = umc_users_active_lastlogin_and_level();
    // what date was 1 month ago?
    $now_datetime = umc_datetime();
    $now_datetime->modify('-1 month');
    $one_months_ago = $now_datetime->format('Y-m-d H:i:s');
    $now_datetime->modify('-1 month');
    // what date was 2 months ago?
    $two_months_ago = $now_datetime->format('Y-m-d H:i:s');
    $timer['after_owner_age'] = XMPP_ERROR_ptime();
    $banned_users = umc_banned_users();
    $timer['after_banned_users'] = XMPP_ERROR_ptime();
    $css_lot_sizes = array();
    //$user_str = "<div class=\"user\">";
    //$css_lot_types = array();
    // var_dump($old_users);
    foreach ($rights as $lot => $opt) {
        $class = '';
        if (substr($lot, 0, 2) == '__') {
            continue;
        }
        // we need to switch for the proper coordinates
        // we need the 1 coordinate to be the top left one
        // Lot A1
        // min: {z: 1152.0, y: 0.0, x: -1280.0}
        // max: {z: 1279.0, y: 128.0, x: -1153.0}
        // take the larger X (west)
        $min = $opt['min'];
        $max = $opt['max'];
        if ($min['z'] < $max['z']) {
            $z1 = $min['z'];
            $z2 = $max['z'];
        } else {
            $z1 = $max['z'];
            $z2 = $min['z'];
        }
        // get the smaller z (north)
        if ($min['x'] < $max['x']) {
            $x1 = $min['x'];
            $x2 = $max['x'];
        } else {
            $x1 = $max['x'];
            $x2 = $min['x'];
        }
        $coord_1 = $x1;
        $coord_2 = $z1;
        $chunk = "Region " . floor($x1 / 512) . "/" . floor($z1 / 512) . ", Chunks " . floor($x1 / 16) . "/" . floor($z1 / 16);
        $x1 = conv_x($x1, $map);
        $x2 = conv_x($x2, $map);
        $z1 = conv_z($z1, $map);
        $z2 = conv_z($z2, $map);
        if ($find_lot && $player_lot == $lot) {
            $lot_x = $x1 + 60;
            $lot_z = $z1 + 60;
        }
        $lowercase_lot = $lot;
        $lot = strtoupper($lot);
        $lot_str = $lot;
        $width = $x2 - $x1 - 3;
        $height = $z2 - $z1 - 3;
        //$css .='#'. $lot . ' {width:'. $width. 'px; height:'. $height . 'px; top:' . $z1 . 'px; left:'. $x1 . 'px;}'. "\n";
        $css_lot_location = ' style="top:' . $z1 . 'px; left:' . $x1 . 'px;"';
        $css_lot_sizes["size{$width}_{$height}"] = '{width:' . $width . 'px; height:' . $height . 'px;}';
        $size_class = " size{$width}_{$height}";
        $user_string = '';
        $owner_string = '';
        // $box_color = '';
        $coord_str = "            <span class=\"coords\">{$coord_1}/{$coord_2}, {$chunk}</span>\n";
        //. '<span class="coords bottomleft">'.$x1.'/'.$z2.'</span>'
        //. '<span class="coords topright">'.$x2.'/'.$z1.'</span>'
        //. '<span class="coords bottomright">'.$x2.'/'.$z2.'</span>';
        if ($opt['owners']) {
            $owner_uuid = key($opt['owners']);
            $owner_username = $opt['owners'][$owner_uuid];
            // donation level
            $donation_level = false;
            if (isset($donators[$owner_uuid])) {
                $donation_level = $donators[$owner_uuid];
            }
            // find out who can keep their lot longer than 1 months
            $retain_lot = false;
            // kick out banned users
            if (isset($owner_uuid, $banned_users)) {
                $class = ' redout';
                $lastlogin_str = "Banned!";
            }
            $owner_lastlogin = $all_lastlogins[$owner_uuid]['lastlogin'];
            if (!isset($all_lastlogins[$owner_uuid]['userlevel'])) {
                XMPP_ERROR_trigger("{$owner_username} has no userlevel for the map!");
            }
            $lastlogin_str = $owner_lastlogin;
            $ownergroup = $all_lastlogins[$owner_uuid]['userlevel'];
            // who should be able to be away for 2 months?
            if (in_array($ownergroup, $longterm)) {
                $retain_lot = true;
            }
            // if we show only free lots, use different class
            $border = '';
            if (!$freeonly) {
                $border = 'border';
                // $box_color = ' background: rgba(0, 255, 255, 0.2);';
            }
            if ($retain_lot && $owner_lastlogin < $two_months_ago && $donation_level < 2) {
                // too late
                $class .= ' red' . $border;
            } else {
                if ($retain_lot && $owner_lastlogin < $one_months_ago && $donation_level < 2) {
                    // still yellow
                    $class .= ' yellow' . $border;
                } else {
                    if (!$retain_lot && $owner_lastlogin < $two_months_ago && $world == 'aether' && $donation_level < 1) {
                        $class .= ' red' . $border;
                    } else {
                        if (!$retain_lot && $owner_lastlogin < $one_months_ago && $donation_level < 1) {
                            $class .= ' red' . $border;
                        } else {
                            if (isset($new_choices[$lowercase_lot]) && !in_array($new_choices[$lowercase_lot]['choice'], array('keep', 'reset'))) {
                                $class .= ' whiteborder';
                            } else {
                                $class .= ' black' . $border;
                            }
                        }
                    }
                }
            }
            if (substr($lot, 0, 3) === 'CON') {
                $owner_string .= "{$owner_username}";
                $lot_str = substr($lot_str, 4);
                $class .= " small";
            } else {
                $owner_string .= "{$owner_username} ({$lastlogin_str})";
                $lot_str = $lot;
            }
        } else {
            $class .= ' whiteborder';
        }
        if ($opt['members']) {
            $members = array_unique($opt['members']);
            foreach ($members as $user) {
                $user_string .= "{$user} ";
            }
        }
        //        if ($opt['members']) {
        //            $members = array_unique($opt['members']);
        //            foreach ($members as $user) {
        //                $user_string .= "$user ";
        //            }
        //        }
        if ($opt['owners']) {
            $owner_string = "            <div class=\"Owner\">{$owner_string}</div>\n";
            if ($opt['members']) {
                $user_string = "            <span class=\"user\">{$user_string}</span>\n";
            }
        }
        $onclick = '';
        if ($settler_test && !$opt['owners']) {
            $onclick = " onclick=\"select_lot('radio_{$lot}', '{$lot}')\"";
        }
        $html .= "    <div id=\"{$lot}\" class=\"outerframe{$class}{$size_class}\"{$css_lot_location}{$onclick}>\n";
        if ($settler_test && !$opt['owners']) {
            $html .= "        <input id=\"radio_{$lot}\" class=\"settler_test\" type=\"radio\" name=\"lot\" value=\"{$lot}\"><label for=\"radio_{$lot}\">{$lot_str}</label>\n";
        } else {
            $html .= "        <div class=\"innertext {$kingdom}\">{$lot_str}<br>\n{$owner_string}{$user_string}{$coord_str}        </div>\n";
        }
        $html .= "    </div>\n";
    }
    $timer['after_regions_display'] = XMPP_ERROR_ptime();
    if ($settler_test || $track_player || $find_lot) {
        $html .= '</form>';
    }
    foreach ($css_lot_sizes as $class => $css_string) {
        $css .= ".{$class} {$css_string}\n";
    }
    if ($lag) {
        $world = $heatworld;
    }
    $css .= "</style>\n";
    $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>Uncovery Minecraft 2D Map: ' . $world . '</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="/admin/js/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="/admin/js/jquery-ui.min.js"></script>
        <script type="text/javascript">
            function find_spawn() {
                window.scrollTo(($(document).width()-$(window).width())/2 + 60,($(document).height()-$(window).height())/2 - 60);
                doBlink("' . $spawn_lot . '");
            }
            function doBlink(element_id) {
                toggleBlink(element_id);
                setTimeout(function() {toggleBlink(element_id);}, 2000);
            }
            function toggleBlink(element_id) {
                $("#" + element_id).toggleClass("blink_me");
            }
            function toggleLotDisplay() {
                $(".blackborder").toggleClass("black");
                $(".redborder").toggleClass("red");
                $(".yellowborder").toggleClass("yellow");
            }
            function find_user(left, top, element_id) {
                window.scrollTo(left - ($(window).width() / 2), top - ($(window).height() / 2))
                $("#" + element_id).effect("shake");
            }
            function select_lot(lot_radio, lot_name) {
                $("#" + lot_radio).prop("checked", true);
                $("#settler_test_next").prop("value", "Chose Lot " + lot_name);
            }
            var markers_url = "' . $UMC_DOMAIN . '/admin/index.php?function=display_markers&world=' . $world . $track_player_icon . '";
            var markers_menu_url = "' . $UMC_DOMAIN . '/admin/index.php?function=display_markers&format=scrollto&world=' . $world . '";
            function update_positions() {
                $.ajax({
                    url: markers_menu_url,
                    success: function(data) {
                        $("#scroll_to_icons").remove();
                        $(data).insertAfter( "#link_3d_maps" );
                        // $("#link_3d_maps").html($("#link_3d_maps").html() + data);
                    }
                });
                $.ajax({
                    url: markers_url,
                    success: function(data) {
                        $("#marker_list").remove();
                        $("#outer_box").html(data + $("#outer_box").html());
                        setTimeout("update_positions()", 4000);' . "\n";
    if ($find_lot) {
        $header .= '                draw_line();
                    }
                });

            }
            function draw_line() {
                var player_left = parseInt($("#' . $player . '_marker").css("left"), 10) + 10;
                var player_top = parseInt($("#' . $player . '_marker").css("top"), 10) + 10;
                var c = document.getElementById("lot_pointer");
                var ctx = c.getContext("2d");
                ctx.setTransform(1, 0, 0, 1, 0, 0);
                ctx.beginPath();
                ctx.clearRect(0, 0, ' . $map_width . ', ' . $map_height . ');
                ctx.strokeStyle="red";
                ctx.moveTo(player_left, player_top);
                ctx.lineTo(' . $lot_x . ',' . $lot_z . ');
                ctx.stroke();
            }
';
    } else {
        $header .= '                        }
                    });
                }
';
    }
    if (!$settler_test) {
        $header .= '$(document).ready(function() {update_positions();});';
    }
    $header .= "\n</script>\n";
    $out = $header . $css . "</head>\n<body>\n" . $menu . $html . "</div>n</body>\n</html>\n";
    XMPP_ERROR_trace("construction done");
    echo $out;
}
/**
 * resets lots
 *
 * @global type $UMC_SETTING
 * @global array $UMC_PATH_MC
 * @param type $debug\
 */
function umc_lot_reset_process()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_SETTING, $UMC_PATH_MC;
    // first of all, clean up user dibs
    umc_lot_manager_dib_cleanup();
    // get banned users UUID => username
    $banned_users = umc_banned_users();
    // var_dump($banned_users);
    // donators UUID => leftover days
    $donators = umc_users_donators();
    $dibs = umc_lot_manager_dibs_get_all();
    // Update all userlevels in UUID table
    $upd_sql = 'UPDATE minecraft_srvr.UUID
        LEFT JOIN minecraft_srvr.permissions_inheritance ON UUID.UUID=permissions_inheritance.child
        SET userlevel = parent
        WHERE parent != userlevel';
    umc_mysql_query($upd_sql, true);
    // get dates for -1 Month and -2 months
    $now_datetime = umc_datetime();
    $now_datetime->modify('-1 month');
    $one_months_ago = $now_datetime->format('Y-m-d H:i:s');
    $now_datetime->modify('-1 month');
    // what date was 2 months ago?
    $two_months_ago = $now_datetime->format('Y-m-d H:i:s');
    $longterm = $UMC_SETTING['longterm'];
    $source_path = "{$UMC_PATH_MC}/server/worlds/mint";
    $dest_path = "{$UMC_PATH_MC}/server/bukkit";
    // get all occupied lots and their owners
    // TODO: We should get first all expired users and reset their shop inventory, then do their lots.
    $list_sql = "SELECT region_id as lot, user.UUID as uuid, UUID.username as username, world.name as world, userlevel, lastlogin\n            FROM minecraft_worldguard.region_players LEFT JOIN minecraft_worldguard.user ON user_id=user.id\n            LEFT JOIN minecraft_worldguard.world ON world_id=world.id\n            LEFT JOIN minecraft_srvr.UUID ON user.UUID=UUID.UUID\n            WHERE owner=1 AND LEFT(region_id, 4) IN {$UMC_SETTING['lot_worlds_sql']}";
    $D = umc_mysql_fetch_all($list_sql);
    /**
     * Actions to be taken, with reasons
     */
    $A = array();
    foreach ($D as $row) {
        $owner_username = strtolower($row['username']);
        $owner_uuid = $row['uuid'];
        $owner_lastlogin = $row['lastlogin'];
        $owner_level = $row['userlevel'];
        if ($owner_username == 'uncovery') {
            // we do not reset uncovery's lots
            continue;
        }
        if ($owner_username == 'riedi77') {
            // we do not reset uncovery's lots
            continue;
        }
        // we do not reset active donators, except those who are banned
        if (isset($donators[$owner_uuid]) && !isset($banned_users[$owner_uuid])) {
            continue;
        }
        $lot = $row['lot'];
        $world = $row['world'];
        $lot_dibs = false;
        if (isset($dibs[$lot])) {
            $lot_dibs = $dibs[$lot];
        }
        // sanity check
        if (!isset($row['userlevel']) || !in_array($owner_level, $UMC_SETTING['ranks'])) {
            XMPP_ERROR_trigger("Could not reset lots, userlevel failure for Owner '{$owner_username} / {$owner_uuid} / {$owner_level}': {$list_sql}");
            die("userlevel error");
        }
        if (isset($banned_users[$owner_uuid])) {
            $A[$lot] = array('reason' => "{$lot} was reset because {$owner_username} / {$owner_uuid} was banned", 'source_world' => "{$source_path}/{$world}", 'dest_world' => "{$dest_path}/{$world}", 'remove_users' => true, 'reset_to' => $lot, 'user_shop_clean' => $owner_uuid, 'dibs' => $lot_dibs, 'version_sql' => false, 'del_skyblock_inv' => false);
        } else {
            if ($owner_username == '_abandoned_') {
                $A[$lot] = array('reason' => "{$lot} was reset because Owner was _abandoned_", 'source_world' => "{$source_path}/{$world}", 'dest_world' => "{$dest_path}/{$world}", 'remove_users' => true, 'reset_to' => $lot, 'user_shop_clean' => false, 'dibs' => $lot_dibs, 'version_sql' => false, 'del_skyblock_inv' => false);
            } else {
                $longterm_user = in_array($owner_level, $longterm);
                if ($owner_lastlogin < $two_months_ago && $longterm_user) {
                    $A[$lot] = array('reason' => "{$lot} was reset because {$owner_username} / {$owner_uuid} is 2 months protected but was absent for 2 months (last login {$owner_lastlogin})", 'source_world' => "{$source_path}/{$world}", 'dest_world' => "{$dest_path}/{$world}", 'remove_users' => true, 'reset_to' => $lot, 'user_shop_clean' => $owner_uuid, 'dibs' => $lot_dibs, 'version_sql' => false, 'del_skyblock_inv' => false);
                } else {
                    if ($owner_lastlogin < $one_months_ago && !$longterm_user) {
                        $A[$lot] = array('reason' => "{$lot} was reset because {$owner_username} / {$owner_uuid} was absent for 1 months (last login {$owner_lastlogin})", 'source_world' => "{$source_path}/{$world}", 'dest_world' => "{$dest_path}/{$world}", 'remove_users' => true, 'reset_to' => $lot, 'user_shop_clean' => $owner_uuid, 'dibs' => $lot_dibs, 'version_sql' => false, 'del_skyblock_inv' => false);
                    }
                }
            }
        }
        // reset skyblock inventories
        if ($world == 'skyblock' && isset($A[$lot])) {
            //
            $A[$lot]['del_skyblock_inv'] = $owner_uuid;
        }
    }
    // choice based resets
    $sql = "SELECT lot, world.name as world, choice, version, mint_version\n        FROM minecraft_srvr.lot_version\n        LEFT JOIN minecraft_worldguard.region ON lot=id\n        LEFT JOIN minecraft_worldguard.world ON world_id=world.id\n        WHERE SUBSTR(lot_version.lot, 1, 4) IN {$UMC_SETTING['lot_worlds_sql']} AND choice IS NOT NULL;";
    $R = umc_mysql_fetch_all($sql);
    // fixed choices:
    foreach ($R as $row) {
        $lot = $row['lot'];
        $version = $row['version'];
        $mint_version = $row['mint_version'];
        $choice = $row['choice'];
        $world = $row['world'];
        // reset the lot
        if ($choice == 'reset') {
            // any lot that can be reset
            // set the new version to the chosen lot
            $A[$lot] = array('reason' => "Lot {$lot} version was set from {$version} to {$mint_version} after reset", 'source_world' => "{$source_path}/{$world}", 'dest_world' => "{$dest_path}/{$world}", 'del_skyblock_inv' => false, 'remove_users' => false, 'reset_to' => $lot, 'user_shop_clean' => false, 'dibs' => false, 'version_sql' => "UPDATE minecraft_srvr.lot_version SET choice=NULL, version='{$mint_version}' WHERE lot='{$lot}' LIMIT 1;");
        } else {
            if ($choice == 'mint_king' && $world == 'draftlands') {
                $choice = umc_get_draftlands_kingdom_equivalent($lot);
                $A[$lot] = array('reason' => "Lot {$lot} version was reset to mint kingdom version {$choice} by user choice", 'source_world' => "{$source_path}/kingdom", 'dest_world' => "{$dest_path}/draftlands", 'del_skyblock_inv' => false, 'remove_users' => false, 'reset_to' => $choice, 'user_shop_clean' => false, 'dibs' => false, 'version_sql' => "UPDATE minecraft_srvr.lot_version SET choice=NULL, version='{$choice}' WHERE lot='{$lot}' LIMIT 1;");
            } else {
                if ($choice == 'curr_king' && $world == 'draftlands') {
                    $choice = umc_get_draftlands_kingdom_equivalent($lot);
                    $A[$lot] = array('reason' => "Lot {$lot} version was reset to current kingdom version {$choice} by user choice", 'source_world' => "{$dest_path}/kingdom", 'dest_world' => "{$dest_path}/draftlands", 'del_skyblock_inv' => false, 'remove_users' => false, 'reset_to' => $choice, 'user_shop_clean' => false, 'dibs' => false, 'version_sql' => "UPDATE minecraft_srvr.lot_version SET choice=NULL, version='{$choice}' WHERE lot='{$lot}' LIMIT 1;");
                } else {
                    // other non-default options to reset to, usually lot names on the same world
                    // assume that we always copy from the same world, but mint version
                    $A[$lot] = array('reason' => "Lot {$lot} version was reset to {$choice} (user choice)", 'source_world' => "{$source_path}/" . umc_get_lot_world($choice), 'dest_world' => "{$dest_path}/{$world}", 'del_skyblock_inv' => false, 'remove_users' => false, 'reset_to' => $choice, 'user_shop_clean' => false, 'dibs' => false, 'version_sql' => "UPDATE minecraft_srvr.lot_version SET choice=NULL, version='{$choice}' WHERE lot='{$lot}' LIMIT 1;");
                }
            }
        }
    }
    // iterate the items
    foreach ($A as $lot => $a) {
        umc_lot_manager_reset_lot($lot, $a);
    }
    XMPP_ERROR_trigger("Lot reset process finished");
}
Exemplo n.º 3
0
function umc_user_directory()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // list all users
    $username_get = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_STRING);
    if (!is_null($username_get)) {
        $O = array();
        $wordpress_id = umc_user_get_wordpress_id($username_get);
        $username = strtolower(umc_check_user($username_get));
        if (!$wordpress_id) {
            return "User does not exist!";
        }
        $uuid = umc_user2uuid($username);
        // check if the user is active
        $count_lots = umc_user_countlots($uuid);
        if ($count_lots == 0) {
            return "User is not active!";
        }
        // user icon
        $O['User'] = get_avatar($wordpress_id, $size = '96') . "<p><strong>Username:</strong> {$username}</p>\n" . "<p><strong>UUID:</strong> {$uuid}</p>\n";
        $previous_names = umc_uuid_username_history($uuid);
        if ($previous_names) {
            $O['User'] .= "<p><strong>Usernames History:</strong> {$previous_names}</p>\n";
        }
        // is user banned?
        if (umc_user_is_banned($uuid)) {
            $O['User'] .= "<p><strong>User is BANNED!</strong></p>\n";
            return;
        }
        // get userlevel
        $level = umc_get_uuid_level($uuid);
        $karma = umc_getkarma($uuid, true);
        $money = umc_money_check($uuid);
        $O['User'] .= "<p><strong>Level:</strong> {$level}</p>\n" . "<p><strong>Karma:</strong> {$karma}</p>\n" . "<p><strong>Money:</strong> {$money} Uncs</p>\n";
        // get lots
        $lots = umc_user_getlots($uuid);
        foreach ($lots as $data) {
            $world = ucwords($data['world']);
            $combined_worlds = array('Empire', 'Flatlands', 'Skyblock');
            if (in_array($world, $combined_worlds)) {
                $world = 'Small lots';
            }
            if (!isset($O[$world])) {
                $O[$world] = '';
            }
            $O[$world] .= $data['image'];
        }
        $donator_level = umc_users_donators($uuid);
        if ($donator_level > 12) {
            $donator_str = 'More than 1 year';
        } else {
            if ($donator_level) {
                $donator_level_rounded = round($donator_level, 1);
                $donator_str = "{$donator_level_rounded} Months";
            } else {
                $donator_str = "Not a donator";
            }
        }
        $O['User'] .= "<p><strong>Donations remaining:</strong> {$donator_str}</p>\n";
        // get member since
        $online_time = umc_get_lot_owner_age('days', $uuid);
        if ($online_time) {
            $lastlogin = $online_time[$uuid]['lastlogin']['days'];
            $firstlogin = $online_time[$uuid]['firstlogin']['days'];
            $O['User'] .= "<p><strong>Member since:</strong> {$firstlogin} days</p>\n" . "<p><strong>Offline since:</strong> {$lastlogin} days</p>\n";
        }
        // get user bio
        $sql = "SELECT meta_value FROM minecraft.wp_users\r\n            LEFT JOIN minecraft.wp_usermeta ON wp_users.ID = wp_usermeta.user_id\r\n            WHERE display_name='{$username}' AND meta_key='description';";
        $D = umc_mysql_fetch_all($sql);
        if (count($D) > 0) {
            $row = $D[0];
            $O['User'] .= "<p><strong>Bio:</strong> " . $row['meta_value'] . "</p>\n";
        }
        // comments
        $sql2 = "SELECT comment_date, comment_author, id, comment_id, post_title FROM minecraft.wp_comments\r\n            LEFT JOIN minecraft.wp_posts ON comment_post_id=id\r\n            WHERE comment_author = '{$username}' AND comment_approved='1' AND id <> 'NULL'\r\n            ORDER BY comment_date DESC";
        $D2 = umc_mysql_fetch_all($sql2);
        if (count($D2) > 0) {
            $O['Comments'] = "<strong>Comments:</strong> (" . count($D2) . ")\n<ul>\n";
            foreach ($D2 as $row) {
                $O['Comments'] .= "<li>" . $row['comment_date'] . " on <a href=\"/index.php?p=" . $row['id'] . "#comment-" . $row['comment_id'] . "\">" . $row['post_title'] . "</a></li>\n";
            }
            $O['Comments'] .= "</ul>\n";
        }
        //forum posts
        $sql3 = "SELECT wpp.id AS id, wpp.post_title AS title, wpp.post_date AS date,\r\n\t\twpp.post_parent AS parent, wpp.post_type AS type, parent.post_title AS parent_title\r\n            FROM minecraft.wp_posts AS wpp\r\n\t    LEFT JOIN minecraft.wp_users ON wpp.post_author=wp_users.id\r\n\t    LEFT JOIN minecraft.wp_posts AS parent ON parent.id=wpp.post_parent\r\n\t    WHERE wp_users.display_name='{$username}'\r\n\t\tAND (wpp.post_type='reply' OR wpp.post_type='topic')\r\n\t\tAND wpp.post_status='publish'\r\n\t    ORDER BY wpp.post_date DESC";
        $D3 = umc_mysql_fetch_all($sql3);
        // echo $sql;
        if (count($D3) > 0) {
            $O['Forum'] = "<strong>Forum Posts:</strong> (" . count($D3) . ")\n<ul>\n";
            foreach ($D3 as $row) {
                $date = $row['date'];
                if ($row['type'] == 'reply') {
                    $link = $row['parent'] . "#post-" . $row['id'];
                    $title = $row['parent_title'];
                } else {
                    $link = $row['id'];
                    $title = $row['title'];
                }
                $O['Forum'] .= "<li>{$date} on <a href=\"/index.php?p={$link}\">{$title}</a></li>\n";
            }
            $O['Forum'] .= "</ul>\n";
        }
        echo umc_jquery_tabs($O);
    } else {
        // $bans = umc_get_banned_users();
        //var_dump($bans);
        $out = "<script type=\"text/javascript\" src=\"/admin/js/jquery.dataTables.min.js\"></script>\n" . "<script type=\"text/javascript\">\n" . 'jQuery(document).ready(function() {jQuery' . "('#shoptable_users').dataTable( {\"order\": [[ 2, \"desc\" ]],\"paging\": false,\"ordering\": true,\"info\": true} );;} );\n" . "</script>\n" . "This table only tracks online time since 2013-11-20.<br>" . '<table id="shoptable_users"><thead>' . "<th>Username</th>" . "<th>Level</th>" . "<th>Registered days</th>" . "<th>Offline days</th>" . "<th>Lots</th>" . "<th>Online min/day</th>" . "<th>Online hrs</th>" . "</thead>\n<tbody>\n";
        $sql = "SELECT username, DATEDIFF(NOW(),firstlogin) as registered_since, parent as userlevel, count(owner) as lot_count, onlinetime, DATEDIFF(NOW(), lastlogin) as days_offline\r\n            FROM minecraft_srvr.UUID\r\n            LEFT JOIN minecraft_srvr.permissions_inheritance ON UUID.uuid=child\r\n            LEFT JOIN minecraft_worldguard.user ON UUID.uuid = user.uuid\r\n            LEFT JOIN minecraft_worldguard.region_players ON user.id=region_players.user_id\r\n            WHERE owner = 1 AND firstlogin >'0000-00-00 00:00:00' AND username <> '_abandoned_'\r\n            GROUP BY username, owner\r\n            ORDER BY firstlogin";
        $rst = umc_mysql_query($sql);
        $now = time();
        // or your date as well
        $your_date = strtotime("2013-11-20");
        $datediff = $now - $your_date;
        $alt_days = floor($datediff / (60 * 60 * 24));
        while ($row = umc_mysql_fetch_array($rst)) {
            $days_offline = $row['days_offline'];
            $settler_levels = array('Settler', 'SettlerDonator', 'SettlerDonatorPlus');
            if (in_array($row['userlevel'], $settler_levels) && $row['onlinetime'] >= 60) {
                umc_promote_citizen(strtolower($row['username']), $row['userlevel']);
            }
            if ($row['registered_since'] - $days_offline > 1) {
                if ($alt_days < $row['registered_since']) {
                    // people who are not in the lb-players database should not be listed, they are too old
                    if ($alt_days - $days_offline == 0) {
                        continue;
                    }
                    $avg_online = floor($row['onlinetime'] / 60 / $alt_days);
                } else {
                    $avg_online = floor($row['onlinetime'] / 60 / $row['registered_since']);
                }
            } else {
                $avg_online = 0;
            }
            $online_total = round($row['onlinetime'] / 60 / 60);
            $icon_url = umc_user_get_icon_url($row['username']);
            $out .= "<tr>" . "<td><img title='{$row['username']}' src='{$icon_url}' alt=\"{$row['username']}\"> <a href=\"?u={$row['username']}\">{$row['username']}</a></td>" . "<td>{$row['userlevel']}</td>" . "<td class='numeric_td'>{$row['registered_since']}</td>" . "<td class='numeric_td'>{$days_offline}</td>" . "<td class='numeric_td'>{$row['lot_count']}</td>" . "<td class='numeric_td'>{$avg_online}</td>" . "<td class='numeric_td'>{$online_total}</td>" . "</tr>\n";
        }
        $out .= "</tbody>\n</table>\n";
        echo $out;
    }
}