예제 #1
0
function umc_mod_unmute()
{
    global $UMC_USER, $UMC_PATH_MC;
    // umc_echo('Unmuting...');
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    } else {
        $user = umc_check_user($args[2]);
        if (!$user) {
            XMPP_ERROR_trigger("{$player} tried to un-mute {$user}, but {$user} does not exist!");
            umc_error("{red}The user {$args[2]} does not exist! See {yellow}/helpme mod");
        }
    }
    // umc_echo('checks done... ');
    $user_uuid = umc_uuid_getone($user);
    $file = "{$UMC_PATH_MC}/server/bukkit/plugins/Essentials/userdata/" . $user_uuid . ".yml";
    $txt = file_get_contents($file);
    $search = "muted: true";
    if (strstr($txt, $search)) {
        // YAML library is not installed,
        //$yml = yaml_parse_file($file);
        //if ($yml['muted'] == 'true') {
        $uuid = umc_user2uuid($user);
        umc_ws_cmd("mute {$user}", 'asPlayer');
        umc_ws_cmd("pex user {$uuid} timed remove -herochat.*;", 'asConsole');
        umc_ws_cmd("pex user {$uuid} timed remove -irc.*;", 'asConsole');
        umc_ws_cmd("pex user {$uuid} timed remove -essentials.msg;", 'asConsole');
        umc_ws_cmd("pex user {$uuid} timed remove -essentials.me;", 'asConsole');
        umc_echo("The user {$user} has been un-muted!");
        umc_log('mod', 'un-mute', "{$player} un-muted {$user}");
    } else {
        umc_log('mod', 'un-mute', "{$player} tried to un-mute {$user}, but {$user} was not muted!");
        umc_error("User {$user} was not muted!");
    }
}
/**
 * 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;
    }
}
예제 #3
0
function umc_info_who()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    // we predefine the array to make sure proper sorting
    $out_arr = array('Guest' => array(), 'Settler' => array(), 'Citizen' => array(), 'Architect' => array(), 'Designer' => array(), 'Master' => array(), 'Elder' => array(), 'Owner' => array());
    $user_worlds = false;
    if (isset($args[2]) && $args[2] == 'where') {
        $user_worlds = umc_read_markers_file('array');
    } else {
        if (isset($args[2])) {
            // single player info
            $user = umc_check_user($args[2]);
            if ($user) {
                $user_info = umc_get_userinfo($user);
                umc_header("User info for {$user}");
                $data_text = '';
                foreach ($user_info as $desc => $data) {
                    if ($desc == 'Last Seen') {
                        if (isset($UMC_USER['player_data'][$user_info['uuid']])) {
                            $data_text = "{$user} is currently online";
                        } else {
                            $datetime = umc_datetime($data);
                            $diff = umc_timer_format_diff($datetime);
                            $data_text = $diff . " ago";
                        }
                    } else {
                        $data_text = $data;
                    }
                    umc_echo("{green}{$desc}: {white}{$data_text}");
                }
                umc_footer();
                return;
            } else {
                umc_echo("{red}Error: Command/user not recognized");
            }
        }
    }
    $players_data = $UMC_USER['player_data'];
    $count = count($players_data);
    foreach ($players_data as $uuid => $players_details) {
        $level = umc_get_uuid_level($uuid);
        $player = $players_details['Name'];
        if (strstr($level, "DonatorPlus")) {
            $new_lvl = substr($level, 0, -11);
            $new_player = "{$player}{yellow}++{white}";
        } else {
            if (strstr($level, "Donator")) {
                $new_lvl = substr($level, 0, -7);
                $new_player = "{$player}{yellow}+{white}";
            } else {
                $new_lvl = $level;
                $new_player = $player;
            }
        }
        $lower_username = strtolower($player);
        if ($user_worlds && isset($user_worlds[$lower_username])) {
            $new_player .= " {grey}({$user_worlds[$lower_username]['world']}){white}";
        }
        $out_arr[$new_lvl][] = $new_player;
    }
    umc_header("{$count} users online:");
    foreach ($out_arr as $level => $players) {
        if (count($players) > 0) {
            umc_echo("{green}{$level}: {white}" . implode(", ", $players));
        }
    }
    umc_footer();
    if ($user_worlds) {
        umc_echo("{blue}Try {grey}/who <player>{blue} for user details");
    } else {
        umc_echo("{blue}Try {grey}/where{blue} or {grey}/who <player>{blue} for more info");
    }
}
예제 #4
0
/**
 * Handles money transfers
 * UUID enabled
 *
 * @global type $UMC_USER
 * @param type $source
 * @param type $target
 * @param type $amount
 * @return boolean
 */
function umc_money($source = false, $target = false, $amount_raw = 0)
{
    global $UMC_ENV;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if ($source) {
        $source = umc_check_user($source);
    }
    if ($target) {
        $target = umc_check_user($target);
    }
    $amount = abs($amount_raw);
    if ($source) {
        // take from someone
        $source_uuid = umc_uuid_getone($source, 'uuid');
        $balance = umc_money_check($source);
        if ($balance > $amount) {
            $sql = "UPDATE `minecraft_iconomy`.`mineconomy_accounts`\r\n                SET `balance`=`balance`-'{$amount}'\r\n\t\tWHERE `mineconomy_accounts`.`uuid` = '{$source_uuid}';";
            umc_mysql_query($sql);
        } else {
            if ($UMC_ENV == 'websend') {
                umc_error("There is not enough money in the account! You need {$amount} but have only {$balance} Uncs.");
            }
        }
    }
    if ($target) {
        // give to someone
        $target_uuid = umc_uuid_getone($target, 'uuid');
        $balance = umc_money_check($target);
        $sql = "UPDATE `minecraft_iconomy`.`mineconomy_accounts`\r\n\t    SET `balance` = `balance` + '{$amount}'\r\n            WHERE `mineconomy_accounts`.`uuid` = '{$target_uuid}';";
        umc_mysql_query($sql);
    }
    // logging
    if (!$target) {
        $target = "System";
    }
    if (!$source) {
        $source = "System";
    }
    umc_log('money', 'transfer', "{$amount} was transferred from {$source} to {$target}");
}
function umc_lottery()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $lottery, $ENCH_ITEMS;
    $user_input = $UMC_USER['args'][2];
    // check if there is a valid user on the server before applying the vote.
    $user = umc_check_user($user_input);
    if (!$user) {
        umc_log("lottery", "voting", "user {$user} does not exist");
        return false;
    }
    // get the voting players uuid
    $uuid = umc_user2uuid($user);
    // give reinforcing feedback - set subtitle (not displayed)
    $subtitle = 'title ' . $user . ' subtitle {text:"Thanks for your vote!",color:gold}';
    umc_ws_cmd($subtitle, 'asConsole');
    // display the feedback - displays subtitle AND title
    $title = 'title ' . $user . ' title {text:"+100 Uncs",color:gold}';
    umc_ws_cmd($title, 'asConsole');
    // allow uncovery to test chance rolls for debugging purposes
    $chance = false;
    if ($user == 'uncovery' && isset($UMC_USER['args'][5])) {
        $chance = $UMC_USER['args'][5];
    }
    // get the roll array based on chance
    $roll = umc_lottery_roll_dice($chance);
    // umc_echo(umc_ws_vardump($roll));
    // define the rewards and item more legibly
    $item = $roll['item'];
    $luck = $roll['luck'];
    $prize = $lottery[$item];
    //echo "type = {$prize['type']}<br>;";
    //echo "complete chance: $chance<br>;";
    //var_dump($prize);
    // get the metadata if required for the item
    if (isset($prize['detail'])) {
        $detail = $prize['detail'];
    }
    $type = $prize['type'];
    // always give 100 uncs irrespective of roll.
    umc_money(false, $user, 100);
    // instantiate block variables
    $given_block_data = 0;
    $given_block_type = 0;
    //var_dump($prize);
    // based on item type, give reward to the player
    switch ($type) {
        case 'item':
            umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'additional_home':
            $newname = 'lottery' . "_" . umc_random_code_gen(4);
            umc_home_add($uuid, $newname, true);
            $item_txt = "an addtional home!!";
            break;
        case 'random_unc':
            $luck2 = mt_rand(1, 500);
            umc_money(false, $user, $luck2);
            $item_txt = "{$luck2} Uncs";
            break;
        case 'random_potion':
            $luck2 = mt_rand(0, 63);
            umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_ench':
            // pick which enchantment
            $rand_ench = array_rand($ENCH_ITEMS);
            $ench_arr = $ENCH_ITEMS[$rand_ench];
            //pick which item to enchant
            $rand_item = array_rand($ench_arr['items']);
            $rand_item_id = $ench_arr['items'][$rand_item];
            // pick level of enchantment
            $lvl_luck = mt_rand(1, $ench_arr['max']);
            //echo "$item $ench_txt $lvl_luck";
            $item_ench_arr = array($rand_ench => $lvl_luck);
            $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr);
            $item_name = $item['item_name'];
            $full = $item['full'];
            umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery');
            $item_txt = "a " . $full;
            break;
        case 'random_pet':
            // same as blocks below but only 1 always
            umc_echo($type);
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "a " . $item['full'];
            break;
        case 'random_common':
        case 'random_ore':
        case 'random_manuf':
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $luck3 = mt_rand(1, 64);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "{$luck3} " . $item['full'];
            break;
    }
    if ($user != 'uncovery') {
        // testing only
        $item_nocolor = umc_ws_color_remove($item_txt);
        umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole');
        umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})");
        $userlevel = umc_get_userlevel($user);
        if (in_array($userlevel, array('Settler', 'Guest'))) {
            $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!";
            umc_msg_user($user, $msg);
        }
    } else {
        umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!");
    }
    // add vote to the database
    $service_raw = strtolower($UMC_USER['args'][3]);
    // fix service
    $search = array('http://www.', 'https://www.', 'http://', 'https://');
    $service = umc_mysql_real_escape_string(str_replace($search, '', $service_raw));
    // sql log
    $sql_reward = umc_mysql_real_escape_string($type);
    $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]);
    $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`, `roll_value`, `reward`)\r\n        VALUES ('{$uuid}', NOW(), {$service}, {$ip}, {$luck}, {$sql_reward});";
    umc_mysql_query($sql, true);
}
예제 #6
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;
    }
}
예제 #7
0
function umc_display_logores()
{
    global $UMC_DOMAIN, $UMC_USER;
    $out = '';
    if (!$UMC_USER) {
        $out = "Please <a href=\"{$UMC_DOMAIN}/wp-login.php\">login</a>!";
        return $out;
    } else {
        $username = $UMC_USER['username'];
    }
    if ($username !== 'uncovery') {
        return "This page is admin-only!";
    }
    $player = '';
    if (isset($_POST['player']) && !isset($_POST['nolight'])) {
        $player = filter_input(INPUT_POST, 'player', FILTER_SANITIZE_STRING);
        $player = umc_check_user($player);
        if (!$player) {
            $out .= "<h2>Player cannot be found!</h2>";
            $player = '';
        }
    }
    $out .= "<form action=\"\" method=\"post\">\n" . "<span>Person to check: <input type=\"text\" name=\"player\" value=\"{$player}\"> " . "<input type=\"submit\" name=\"proposebutton\" value=\"Check\">" . "<input type=\"submit\" name=\"nolight\" value=\"All No-light\">" . "<input type=\"submit\" name=\"alerts\" value=\"High alert\">" . "<input type=\"submit\" name=\"latest1000\" value=\"Last 1000\">" . "</span></form>";
    if (isset($_POST['latest1000'])) {
        $sql = "SELECT * FROM minecraft_log.logores_log AND world NOT LIKE 'flatlands' ORDER BY `date` DESC LIMIT 1000;";
        $banned_users = umc_get_banned_users();
    } else {
        if (isset($_POST['nolight'])) {
            $sql = "SELECT * FROM minecraft_log.logores_log WHERE light='0' AND y<60 AND world NOT LIKE 'flatlands' ORDER BY `date` DESC LIMIT 1000;";
            $banned_users = umc_get_banned_users();
        } else {
            if (isset($_POST['alerts'])) {
                $sql = "SELECT * FROM minecraft_log.logores_log WHERE INSTR(flagged, 'cave') = 0 AND LENGTH(flagged) > 0 AND y<60 AND world NOT LIKE 'flatlands' ORDER BY `date` DESC LIMIT 1000;";
                $banned_users = umc_get_banned_users();
                //light='0' AND
            } else {
                $sql = "SELECT * FROM minecraft_log.logores_log WHERE username='******' AND world NOT LIKE 'flatlands' ORDER BY `ID` DESC LIMIT 1000;";
            }
        }
    }
    $out .= "<table style=\"font-size:80%\">\n<tr><th>Day</th><th>User</th><th>Ore</th><th>World</th><th>Location</th><th>Ratio</th><th>Light</th><th>Time</th><th>Flags</th></tr>\n";
    $lastuser = '';
    $yesterday = '';
    $D = umc_mysql_fetch_all($sql);
    foreach ($D as $row) {
        // do not list banned users in the nolight section
        $username = $row['username'];
        $lower_user = strtolower($username);
        if (isset($_POST['nolight']) && in_array($lower_user, $banned_users)) {
            continue;
        } else {
            if ($_POST['latest1000'] && in_array($lower_user, $banned_users)) {
                continue;
            } else {
                if ($_POST['alerts'] && in_array($lower_user, $banned_users)) {
                    continue;
                }
            }
        }
        $style = '';
        if ($row['light'] == 0) {
            $style = " style=\"color:red;\"";
        }
        $row_style = '';
        $date_arr = explode(" ", $row['date']);
        if ($yesterday != $date_arr[0]) {
            $row_style = ' style="background-color:#CCCCCC;"';
        }
        $day_time = explode(" ", $row['date']);
        $out .= "<tr{$row_style}><td>{$day_time[0]}</td><td>{$row['username']}</td><td{$style}>{$row['ore']}</td><td>{$row['world']}</td><td{$style}>{$row['x']} / {$row['y']} / {$row['z']}</td><td>{$row['ratio']}</td>" . "<td>{$row['light']}</td><td>{$day_time[1]}</td><td>{$row['flagged']}</td></tr>";
        $lastuser = $row['username'];
        $yesterday = $date_arr[0];
    }
    $out .= "</table>\n";
    return $out;
}
예제 #8
0
/**
 * displays an interface for email on the website
 *
 * @global type $UMC_USER
 * @return string
 */
function umc_mail_web()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $UMC_DOMAIN;
    if (!$UMC_USER) {
        return "You have to be logged in to use this!";
    }
    $uuid = $UMC_USER['uuid'];
    $username = $UMC_USER['username'];
    $folder_arr = array('inbox' => "recipient_uuid='{$uuid}' AND (status='sent' OR status='read')", 'outbox' => "sender_uuid='{$uuid}' AND (status='sent')", 'drafts' => "sender_uuid='{$uuid}' AND (status='draft')", 'trash' => "(recipient_uuid='{$uuid}' AND status IN ('deleted_receiver','deleted_both')) OR (sender_uuid='{$uuid}' AND status IN ('deleted_sender','deleted_both'))");
    $selected = array();
    $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);
    if (!isset($action)) {
        $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
    }
    $out = '<div id="umc_ajax_container" class="webmail" style="display:block">' . "\n";
    // XMPP_ERROR_trigger("Mail");
    $sani_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
    $out .= "\n<!-- POST CHECK // \n" . var_export($sani_post, true) . " \n// end -->\n";
    $sani_get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
    $out .= "\n<!-- GET CHECK // \n" . var_export($sani_get, true) . " \n// end -->\n";
    $subject = '';
    $message = '';
    $recipient = '';
    $error = '';
    $msg_id = '';
    if ($action == 'Mark all read') {
        $read_sql = "UPDATE minecraft_srvr.`user_mail` SET status='read' WHERE recipient_uuid='{$uuid}';";
        umc_mysql_query($read_sql, true);
    }
    if ($action == 'Reply') {
        $recipient = filter_input(INPUT_POST, 'sender', FILTER_SANITIZE_STRING);
        $subject = "Re: " . htmlentities(filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_STRING));
        $action = "New Mail";
    } else {
        if ($action == 'Delete' || $action == 'Undelete') {
            $msg_id = filter_input(INPUT_POST, 'msg_id', FILTER_SANITIZE_NUMBER_INT);
            $recipient_uuid = filter_input(INPUT_POST, 'recipient_uuid', FILTER_SANITIZE_STRING);
            $sender_uuid = filter_input(INPUT_POST, 'sender_uuid', FILTER_SANITIZE_STRING);
            $status = filter_input(INPUT_POST, 'status', FILTER_SANITIZE_STRING);
            if ($sender_uuid == $uuid) {
                $role = 'sender';
            } else {
                if ($recipient_uuid == $uuid) {
                    $role = 'recipient';
                }
            }
            umc_mail_delete_update_status($status, $role, $msg_id);
        } else {
            if ($action == 'Send' || $action == 'Save Draft') {
                // send message
                $subject = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_STRING);
                $message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);
                $recipient = strtolower(filter_input(INPUT_POST, 'recipient', FILTER_SANITIZE_STRING));
                $recipient_uuid = umc_user2uuid($recipient);
                $check = umc_check_user($recipient_uuid);
                if ($recipient == $username) {
                    $check = false;
                    $error = "You cannot send emails to yourself!";
                } else {
                    if (!$check) {
                        $error = "ERROR: Recipient '{$recipient}' could not be found!";
                        $recipient = '';
                    }
                }
                $msg_id = filter_input(INPUT_GET, 'msg_id', FILTER_SANITIZE_NUMBER_INT);
                if (strlen($message) < 5) {
                    $error = "Your message is too short!";
                    $action = "New Mail";
                    $check = false;
                } else {
                    if (strlen($subject) < 5) {
                        $error = "Your subject is too short!";
                        $action = "New Mail";
                        $check = false;
                    }
                }
                if ($action == 'Send' && !$check) {
                    // only complain if we are trying to send
                    $action = "New Mail";
                } else {
                    umc_mail_send_backend($recipient_uuid, $uuid, $message, $subject, $action, $msg_id);
                    $action = '';
                }
            }
        }
    }
    $out .= $error;
    if ($action == 'edit') {
        $msg_id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
        $onemail_sql = "SELECT `msg_id`, `date_time`, `recipient_uuid`, username, `title`, `message`, `status`\r\n                FROM minecraft_srvr.`user_mail`\r\n                LEFT JOIN minecraft_srvr.UUID ON recipient_uuid=UUID\r\n                WHERE msg_id={$msg_id} AND sender_uuid='{$uuid}' AND status='draft';";
        $mail_data = umc_mysql_fetch_all($onemail_sql);
        if (count($mail_data) == 0) {
            $out .= "ERROR: The draft email with ID {$msg_id} could not be found!";
        } else {
            $mail = $mail_data[0];
            $recipient = $mail['username'];
            $subject = htmlentities(trim($mail['subject']));
            $message = htmlentities(trim($mail['message']));
            $msg_id = $mail['msg_id'];
            $action = "New Mail";
        }
    }
    $msg_id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
    if ($action == 'New Mail') {
        //onsubmit=\"return umcAjaxFormProcess('" . umc_web_curr_url() . "', event)\"
        $out .= "<form id=\"newmailform\" method=\"post\"><div>\n" . "<span style=\"max-width:50%;\">Recipient: <input type=\"text\" name=\"recipient\" value=\"{$recipient}\" style=\"width:35%;\" maxlength=\"32\"></span>\n " . "<span style=\"max-width:50%;\">Subject: <input type=\"text\" name=\"subject\" value=\"{$subject}\" style=\"width:35%;\" maxlength=\"32\"></span><br>\n" . "Message:<br><textarea name=\"message\" value=\"\" rows=\"10\" style=\"width:100%;\">{$message}</textarea><input type=\"hidden\" name=\"msg_id\" value=\"\">\n" . "<input type=\"submit\" name=\"action\" value=\"Send\"><input type=\"submit\" name=\"action\" value=\"Save Draft\"><input type=\"submit\" name=\"action\" value=\"Cancel\">\n" . "</div></form>";
    } else {
        if ($action == 'mail' && is_numeric($msg_id)) {
            $onemail_sql = "SELECT `msg_id`, `date_time`, `sender_uuid`, `recipient_uuid`, `title` as subject, `message`, `status` FROM minecraft_srvr.`user_mail`\r\n                WHERE msg_id={$msg_id} AND (recipient_uuid='{$uuid}' OR sender_uuid='{$uuid}');";
            $mail_data = umc_mysql_fetch_all($onemail_sql);
            if (count($mail_data) == 0) {
                $out .= "ERROR: The email with ID {$msg_id} could not be found!<br>";
                $out .= "<a href=\"{$UMC_DOMAIN}/server-access/mail/\">Back</a>";
            } else {
                // onsubmit=\"return umcAjaxFormProcess('" . umc_web_curr_url() . "', event)\"
                $out .= "<a href=\"{$UMC_DOMAIN}/server-access/mail/\">Back</a><br>";
                $out .= "\n<form id=\"newmailform\" method=\"POST\" action=\"{$UMC_DOMAIN}/server-access/mail/\">\n<div>";
                $mail = array();
                foreach ($mail_data[0] as $field => $value) {
                    $mail[$field] = htmlentities(stripslashes(trim($value)));
                }
                $buttons = "<div style=\"float:right\">";
                if (in_array($mail['status'], array('deleted_receiver', 'deleted_both'))) {
                    $buttons .= " <input type=\"submit\" name=\"action\" value=\"Undelete\">";
                } else {
                    $buttons .= " <input type=\"submit\" name=\"action\" value=\"Delete\">";
                }
                if ($mail['recipient_uuid'] == $uuid) {
                    $buttons .= " <input type=\"submit\" name=\"action\" value=\"Reply\">";
                }
                $buttons .= "</div>";
                if ($mail['status'] == 'sent') {
                    $read_sql = "UPDATE minecraft_srvr.`user_mail` SET status='read' WHERE msg_id={$mail['msg_id']};";
                    umc_mysql_query($read_sql, true);
                    $mail['status'] = 'read';
                }
                $sender = umc_user2uuid($mail['sender_uuid']);
                $recipient = umc_user2uuid($mail['recipient_uuid']);
                $out .= "<div class=\"line\"><div style=\"float:left;width:33%;\"><label>From:</label><span class=\"field\">{$sender}</span></div>\n" . "<div style=\"float:left;width:33%;\"><label>To:</label><span class=\"field\">{$recipient}</span></div>\n" . "<div style=\"float:left;width:33%;\"><label>Date:</label><span class=\"field\">{$mail['date_time']}</span></div>\n" . "<div style=\"clear:both;\"></div>\n</div>" . "{$buttons}<div class=\"line\" style=\"overflow:hidden\"><label>Subject:</label><span class=\"field\">{$mail['subject']}</span></div>\n" . "<div style=\"clear:both;\"></div>\n" . "<div class=\"line\"><label>Message:</label><br>" . "<div class=\"field\">{$mail['message']}</div>\n</div>\n" . "<input type=\"hidden\" name=\"status\" value=\"{$mail['status']}\">" . "<input type=\"hidden\" name=\"sender\" value=\"{$sender}\">" . "<input type=\"hidden\" name=\"subject\" value=\"{$mail['subject']}\">" . "<input type=\"hidden\" name=\"recipient_uuid\" value=\"{$mail['recipient_uuid']}\">" . "<input type=\"hidden\" name=\"msg_id\" value=\"{$msg_id}\">" . "<input type=\"hidden\" name=\"sender_uuid\" value=\"{$mail['sender_uuid']}\">" . "</div></form>";
            }
        } else {
            // show folder
            if (!isset($post_folder)) {
                $post_folder = filter_input(INPUT_POST, 'folder', FILTER_SANITIZE_STRING);
            }
            $sql_filter = $folder_arr['inbox'];
            if (isset($post_folder) && $post_folder != 'inbox') {
                if (isset($folder_arr[$post_folder])) {
                    $sql_filter = $folder_arr[$post_folder];
                } else {
                    $out .= "<h2>Folder {$post_folder} cannot be found!</h2>";
                }
            }
            // get the current value
            $alerts_saved = umc_wp_get_meta($uuid, 'mc_mail_alerts');
            $alerts_choice = filter_input(INPUT_POST, 'email_alerts', FILTER_SANITIZE_STRING);
            $submit = filter_input(INPUT_POST, 'submit_form', FILTER_SANITIZE_STRING);
            // update database only if form was submitted
            if ($submit == 'submit_form') {
                if ($alerts_choice == 'email_alerts' && $alerts_saved == 'false') {
                    umc_wp_set_meta($uuid, 'mc_mail_alerts', 'true');
                    $alerts_saved = 'true';
                } else {
                    if ($alerts_choice == NULL && $alerts_saved == 'true') {
                        umc_wp_set_meta($uuid, 'mc_mail_alerts', 'false');
                        $alerts_saved = 'false';
                    }
                }
            }
            $out .= "<form action=\"\" method=\"post\">\n<div class=\"line\">\nFolder: <select name=\"folder\" onchange='this.form.submit()'>";
            $selected[$post_folder] = " selected=\"selected\"";
            foreach ($folder_arr as $folder => $str_filter) {
                $folder_str = ucwords($folder);
                $sel_str = '';
                if (isset($selected[$folder])) {
                    $sel_str = $selected[$folder];
                }
                $out .= "<option value=\"{$folder}\"{$sel_str}>{$folder_str}</option>";
            }
            $checked = '';
            if ($alerts_saved == 'true') {
                $checked = 'checked="checked"';
            }
            $out .= "</select>\n<input type=\"submit\" name=\"action\" value=\"New Mail\"><input type=\"submit\" name=\"action\" value=\"Mark all read\"><input type=\"hidden\" name=\"submit_form\" value=\"submit_form\">\n" . "<span style=\"float:right;\"><input type=\"checkbox\" name=\"email_alerts\" value=\"email_alerts\" {$checked} onchange='this.form.submit()'> Send e-mail alerts</span>" . "</div></form>\n";
            $sql = "SELECT `msg_id`, `date_time`, s_ref.username as sender, r_ref.username as recipient, `title` as subject, status\r\n                FROM minecraft_srvr.`user_mail`\r\n                LEFT JOIN minecraft_srvr.UUID as s_ref on sender_uuid=s_ref.UUID\r\n                LEFT JOIN minecraft_srvr.UUID as r_ref on recipient_uuid=r_ref.UUID\r\n                WHERE {$sql_filter} ORDER BY date_time DESC;";
            $status_header = "";
            if ($post_folder == 'outbox') {
                $status_header = '<th>Status</th>';
            }
            $D = umc_mysql_fetch_all($sql);
            $non_numeric = array('date_time', 'sender', 'recipient', 'subject');
            $formats = array('sender' => 'umc_mail_web_formats', 'status' => 'umc_mail_web_formats', 'recipient' => 'umc_mail_web_formats', 'subject' => 'umc_mail_web_formats');
            $hide_cols = array('msg_id');
            $check = umc_web_table("mail", "0, 'desc'", $D, '', $hide_cols, $non_numeric, $formats);
            if (!$check) {
                XMPP_ERROR_trigger("Error creating web_table with SQL {$sql}");
                $out .= "Error creating data table. Admin was notified, please wait until it is fixed";
            } else {
                $out .= $check;
            }
        }
    }
    $out .= "</div>\n";
    return $out;
}
예제 #9
0
function umc_lottery()
{
    //  umc_error_notify("User $user, $chance (umc_lottery)");
    global $UMC_USER, $lottery, $ENCH_ITEMS;
    $user_input = $UMC_USER['args'][2];
    $user = umc_check_user($user_input);
    if (!$user) {
        umc_log("lottery", "voting", "user {$user} does not exist");
        return false;
    }
    $uuid = umc_user2uuid($user);
    $chance = false;
    if ($user == 'uncovery' && isset($UMC_USER['args'][3])) {
        $chance = $UMC_USER['args'][3];
    }
    $roll = umc_lottery_roll_dice($chance);
    // umc_echo(umc_ws_vardump($roll));
    $item = $roll['item'];
    $luck = $roll['luck'];
    $prize = $lottery[$item];
    //echo "type = {$prize['type']}<br>;";
    //echo "complete chance: $chance<br>;";
    //var_dump($prize);
    if (isset($prize['detail'])) {
        $detail = $prize['detail'];
    }
    $type = $prize['type'];
    // always give 100 uncs
    umc_money(false, $user, 100);
    $given_block_data = 0;
    $given_block_type = 0;
    //var_dump($prize);
    switch ($type) {
        case 'item':
            umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_unc':
            $luck2 = mt_rand(1, 500);
            umc_money(false, $user, $luck2);
            $item_txt = "{$luck2} Uncs";
            break;
        case 'random_potion':
            $luck2 = mt_rand(0, 63);
            umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_ench':
            // pick which enchantment
            $rand_ench = array_rand($ENCH_ITEMS);
            $ench_arr = $ENCH_ITEMS[$rand_ench];
            //pick which item to enchant
            $rand_item = array_rand($ench_arr['items']);
            $rand_item_id = $ench_arr['items'][$rand_item];
            // pick level of enchantment
            $lvl_luck = mt_rand(1, $ench_arr['max']);
            //echo "$item $ench_txt $lvl_luck";
            $item_ench_arr = array($rand_ench => $lvl_luck);
            $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr);
            $item_name = $item['item_name'];
            $full = $item['full'];
            umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery');
            $item_txt = "a " . $full;
            break;
        case 'random_pet':
            // same as blocks below but only 1 always
            umc_echo($type);
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "a " . $item['full'];
            break;
        case 'random_common':
        case 'random_ore':
        case 'random_manuf':
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $luck3 = mt_rand(1, 64);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "{$luck3} " . $item['full'];
            break;
    }
    if ($user != 'uncovery') {
        // testing only
        $item_nocolor = umc_ws_color_remove($item_txt);
        umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole');
        umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})");
        $userlevel = umc_get_userlevel($user);
        if (in_array($userlevel, array('Settler', 'Guest'))) {
            $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!";
            umc_msg_user($user, $msg);
        }
    } else {
        umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!");
    }
    // add vote to the database
    $service = umc_mysql_real_escape_string($UMC_USER['args'][3]);
    $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]);
    $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`)\r\n        VALUES ('{$uuid}', NOW(), {$service}, {$ip});";
    umc_mysql_query($sql, true);
    // echo "$user voted for the server and got $item_txt!;";
}
function umc_sanitize_input(&$value, $type)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $MAX_UNCS = 10000;
    $MIN_UNCS = 1.0E-5;
    if ($type == "price") {
        # Check that this is a number
        # Check that it is greater than zero
        # Check bounds
        if (!is_numeric($value)) {
            umc_error("{red}Invalid amount of uncs ({yellow}{$value}{red}), must be a number.");
        } elseif ($value < $MIN_UNCS) {
            umc_error("{red}Invalid amount of uncs ({yellow}{$value}{red}), must be at least {yellow}{$MIN_UNCS}{red}.");
        } elseif ($value > $MAX_UNCS) {
            umc_error("{red}Invalid amount of uncs ({yellow}{$value}{red}), cannot be more than {yellow}{$MAX_UNCS}{red}.");
        } else {
            return $value;
        }
    }
    if ($type == "amount") {
        if ($value == NULL) {
            // buying all available
            return NULL;
        }
        if (!is_numeric($value)) {
            umc_error("{red}Invalid amount ({yellow}{$value}{red}), must be an integer.");
        } elseif (intval($value) < 1) {
            umc_error("{red}Invalid amount ({yellow}{$value}{red}), must be at least 1.");
        } else {
            return intval(abs($value));
        }
    }
    if ($type == "player") {
        $player = umc_check_user($value);
        if (!$player) {
            umc_error("{red}Invalid player name ({yellow}{$value}{red}), no such player.");
        } else {
            return $player;
        }
    }
    if ($type == "item") {
        // get a list of all possible item names. REquires exact match of the searched item
        $all_names = umc_item_data_get_namelist();
        if (isset($all_names[$value])) {
            return $all_names[$value];
        } else {
            // we searched only for the EXACT item above. We should be looking for possible matches in the
            // search database too.
            global $ITEM_SEARCH;
            if (isset($ITEM_SEARCH[$value])) {
                return $ITEM_SEARCH[$value];
            }
            return false;
        }
    }
    if ($type == "table") {
        if (isset($value[2]) && ($value[2] == 'request' || $value[2] == 'req' || $value[2] == 'r')) {
            return 'request';
        } elseif (isset($value[2]) && ($value[2] == 'offer' || $value[2] == 'off' || $value[2] == 'o')) {
            return 'stock';
        } else {
            array_splice($value, 2, 0, 'offer');
            umc_echo("{yellow}[!]{gray} Didn't specify {yellow}request{gray} or {yellow}offer{gray}, assuming {yellow}offer", true);
            return 'stock';
        }
    }
    if ($type == "lot") {
        $check = !preg_match('/[^A-Za-z0-9_.#\\-$]/', $value);
        if (!$check) {
            umc_error('You need to enter a valid lot name such as "emp_a1"');
        } else {
            return $value;
        }
    }
    if ($type == "meta") {
        $meta_name = umc_parse_meta_input($value);
        if (is_null($meta_name)) {
            umc_error("Unknown Metavalue name: {white}{$value}");
        } else {
            return $meta_nam;
        }
    }
}
예제 #11
0
function umc_vote_web()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $vote_ranks, $UMC_DOMAIN, $UMC_USER;
    $lvl_percent = array('a' => 0.3, 'd' => 0.4, 'm' => 0.7, 'e' => 1);
    $out = umc_vote_stats();
    // return "<h1>Sorry, due to technical issues, voting is temporarily suspended</h1>";
    if (!$UMC_USER) {
        $out = "Please <a href=\"{$UMC_DOMAIN}/wp-login.php\">login</a> to vote!";
        return $out;
    } else {
        $out .= "<h2>Proposals & Votes</h2>";
        $username = $UMC_USER['username'];
        $uuid = $UMC_USER['uuid'];
        $user_lvl = $UMC_USER['userlevel'];
    }
    $user_lvl_id = $vote_ranks[$user_lvl]['lvl'];
    if ($user_lvl_id < 3) {
        // start voting only for designers
        return "Sorry, you need to be Designer or above to vote!";
    }
    // get user numbers for levels
    $lvl_str_arr = array('a' => "'Architect', 'ArchitectDonator', 'ArchitectDonatorPlus'", 'd' => "'Designer', 'DesignerDonator', 'DesignerDonatorPlus'", 'm' => "'Master', 'MasterDonator', 'MasterDonatorPlus'", 'e' => "'Elder', 'ElderDonator', 'ElderDonatorPlus'");
    $lvl_amounts = array('a' => 0, 'd' => 0, 'm' => 0, 'e' => 0);
    $lvl_min_req = array('a' => 0, 'd' => 0, 'm' => 0, 'e' => 0);
    foreach ($lvl_str_arr as $lvl_code => $lvl_str) {
        // This takes all lots where the owners are in one of the user 4 levels that can vote
        $sql = "SELECT user_id, UUID.UUID as uuid, username FROM `minecraft_worldguard`.`region_players`\r\n            LEFT JOIN minecraft_worldguard.user ON region_players.user_id=user.id\r\n            LEFT JOIN minecraft_srvr.UUID ON minecraft_worldguard.user.uuid=minecraft_srvr.UUID.UUID\r\n            LEFT JOIN minecraft_srvr.permissions_inheritance ON minecraft_srvr.UUID.UUID=minecraft_srvr.permissions_inheritance.child\r\n            WHERE parent IN ({$lvl_str}) AND type=1 AND owner=1 GROUP BY user_id;";
        $C = umc_mysql_fetch_all($sql);
        // count all the people in the userlevel to know how many votes are needed
        $lvl_amounts[$lvl_code] = count($C);
    }
    // calc needed votes
    $full_vote = $lvl_amounts['e'] * $vote_ranks['Elder']['vote'];
    foreach ($lvl_amounts as $lvl => $lvl_amount) {
        $lvl_min_req[$lvl] = round($full_vote * $lvl_percent[$lvl]);
    }
    // TODO insert here a cleanup process that deletes old votes of non-promoted users
    $proposed = filter_input(INPUT_POST, 'proposal', FILTER_SANITIZE_STRING);
    if (isset($proposed) && strlen($proposed) > 1) {
        $proposed = umc_check_user($proposed);
        if (!$proposed) {
            $out .= "Sorry {$username}, but you need to input an existing user to propose!";
        } else {
            $proposed_data = umc_uuid_getboth($proposed, 'username');
            $proposed_username = $proposed_data['username'];
            $proposed_uuid = $proposed_data['uuid'];
            // what user level is it?
            $prop_lvl = umc_get_uuid_level($proposed_uuid);
            $prop_lvl_id = $vote_ranks[$prop_lvl]['lvl'];
            // check if the user was recently promoted
            $sql = "SELECT UNIX_TIMESTAMP(`date`) as mysql_ts FROM minecraft_srvr.proposals  WHERE `uuid` LIKE '{$proposed_uuid}' ORDER BY `date` DESC;";
            $D = umc_mysql_fetch_all($sql);
            $row = array();
            if (count($D) > 0) {
                $row = $D[0];
                // get the first (latest) entry
            } else {
                $row['mysql_ts'] = 0;
            }
            if (time() - $row['mysql_ts'] < 5270400) {
                $out .= "<strong>Sorry {$username}, but {$proposed_username} was last proposed for promotion less than 2 months ago!</strong>";
            } else {
                if ($user_lvl_id < 6 && $user_lvl_id < $prop_lvl_id + 1) {
                    $out .= "<strong>Sorry {$username}, but you need to be at a higher level to propose {$proposed_username} for a higher rank!</strong>";
                } else {
                    if ($prop_lvl_id > 5) {
                        $out .= "<strong>Sorry {$username}, but {$proposed_username} has reached max level already!</strong>";
                    } else {
                        if (umc_user_countlots($proposed) < 1) {
                            // is this an active user?
                            $out .= "<strong>Sorry {$username}, but you can only propose users who have a lot!</strong>";
                        } else {
                            if ($prop_lvl_id < 2) {
                                $out .= "<strong>Sorry {$username}, but you can only propose users who are at least Citizen level!</strong>";
                            } else {
                                if ($username == $proposed) {
                                    $out .= "<strong>Sorry {$username}, but you cannot propose yourself!</strong>";
                                } else {
                                    // ok to be promoted
                                    $ins_proposal_sql = "INSERT INTO `minecraft_srvr`.`proposals` (`pr_id`, `uuid`, `proposer_uuid`, `date`, `status`)\r\n                    VALUES (NULL, '{$proposed_uuid}', '{$uuid}', NOW(), 'voting');";
                                    umc_mysql_query($ins_proposal_sql);
                                    $pr_id = umc_mysql_insert_id();
                                    $sql = "INSERT INTO minecraft_srvr.`proposals_votes` (`pr_id`, `voter_uuid`, `date`, `vote`) VALUES ({$pr_id}, '{$uuid}', NOW(), 1);";
                                    umc_mysql_query($sql, true);
                                    $out .= "Thanks {$username}, {$proposed_username} as been submitted for voting, and your vote has been set, too!";
                                    if ($prop_lvl_id == 5) {
                                        // we propose a Master for promotion, inform all elders
                                        $sql = "SELECT user_email, UUID, username FROM minecraft_srvr.`UUID`\r\n                        LEFT JOIN minecraft.wp_usermeta ON UUID.UUID=meta_value\r\n                        LEFT JOIN minecraft.wp_users ON user_id=ID\r\n                        WHERE `userlevel` LIKE 'Elder%' AND lot_count > 0";
                                        $D = umc_mysql_fetch_all($sql);
                                        $subject = "{$proposed} proposed for Elder, please vote!";
                                        $content = "Dear Elder, \r\n\r\nthe user {$proposed} has been proposed to be promoted to Elder. Please go to\r\n\r\n{$UMC_DOMAIN}/vote-for-users/\r\n\r\n" . "and vote on this proposal. Please either SUPPORT or VETO the proposal.\r\n" . "Please note that the vote will be closed as 'failed' unless all Elders cast a vote within the coming 2 months.\r\n" . "Thanks a lot for supporting Uncovery Minecraft!\r\n\r\nBest regards,\r\nUncovery";
                                        $headers = 'From:minecraft@uncovery.me' . "\r\nReply-To:minecraft@uncovery.me\r\n" . 'X-Mailer: PHP/' . phpversion();
                                        mail('*****@*****.**', $subject, $content, $headers);
                                        foreach ($D as $row) {
                                            mail($row['user_email'], '[Uncovery Minecraft] ' . $subject, $content, $headers);
                                            umc_mail_send_backend($row['UUID'], 'ab3bc877-4434-45a9-93bd-bab6df41eabf', $content, $subject, 'send');
                                            // send from uncovery's UUID
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // propose new person
    if ($user_lvl_id > 3) {
        $out .= "<form action=\"\" method=\"post\">\n" . "<span>Propose a person to be upgraded: <input type=\"text\" name=\"proposal\"> " . "<input type=\"submit\" name=\"proposebutton\" value=\"Propose user!\">" . "</span></form>";
    } else {
        $out .= "(Since your level is too low, you cannot propose users yet.)";
    }
    // close old proposals
    $upd_sql = "UPDATE minecraft_srvr.proposals SET `status`='failed' WHERE status = 'voting' AND date < NOW() - INTERVAL 2 month";
    umc_mysql_query($upd_sql, true);
    // list proposed people
    $sql = "SELECT UUID.username, status, pr_id, date, proposals.uuid FROM minecraft_srvr.proposals\r\n        LEFT JOIN minecraft_srvr.UUID ON proposals.uuid=UUID.UUID\r\n        WHERE status IN ('voting','closed') ORDER BY `date` ASC;";
    $D = umc_mysql_fetch_all($sql);
    $header = '';
    if ($username == 'uncovery') {
        $header = '<th>Score</th>';
    }
    $out .= "<br><form action=\"\" method=\"post\">\n<input type=\"hidden\" name=\"uuid\" value=\"{$uuid}\">\n<input type=\"hidden\" name=\"voting\" value=\"true\">\n<table>\n" . "<tr><th>Proposal</th><th>Date</th><th>Current Level</th><th>Your Vote</th><th>Vote date</th>{$header}</tr>\n";
    $proposals = 0;
    $upgraded_users = array();
    foreach ($D as $row) {
        $prop_lvl = umc_get_userlevel($row['username']);
        $prop_status = $row['status'];
        $prop_lvl_id = $vote_ranks[$prop_lvl]['lvl'];
        $proposed = $row['uuid'];
        $proposed_name = $row['username'];
        // check if user is allowed to vote for this person
        if ($user_lvl_id <= $prop_lvl_id) {
            continue;
        }
        $proposals++;
        $sel_support = $sel_veto = '';
        $sel_none = " selected=\"selected\"";
        $vote_date = "n/a";
        $pr_id = $row['pr_id'];
        // check if vote has been cast right now
        if (isset($_POST['voting']) && $_POST['uuid'] == $uuid) {
            if ($prop_status == 'closed' && $username == 'uncovery' && isset($_POST['CL_' . $pr_id]) && $_POST['CL_' . $pr_id] != 'closed') {
                $new_vote = filter_input(INPUT_POST, 'CL_' . $pr_id, FILTER_SANITIZE_STRING);
                // var_dump($_POST);
                $sql = "UPDATE minecraft_srvr.`proposals` SET `status` = '{$new_vote}' WHERE `proposals`.`pr_id`={$pr_id} LIMIT 1;";
                umc_mysql_query($sql);
                // echo $sql;
                if ($new_vote == 'success') {
                    $cmd = "pex promote {$proposed}";
                    umc_exec_command($cmd, 'asConsole', false);
                    umc_exec_command($cmd, 'asConsole', false);
                    umc_exec_command($cmd, 'asConsole', false);
                    $upgraded_users[$proposed_name] = $prop_lvl;
                    umc_log('voting', "promotion", "{$proposed_name} ({$proposed}) was promoted from {$prop_lvl} through votes");
                }
                continue;
            } else {
                if ($prop_status != 'closed') {
                    $new_vote = filter_input(INPUT_POST, 'PR_' . $pr_id, FILTER_SANITIZE_STRING);
                    $sel_support = $sel_veto = $sel_none = '';
                    // find existing votes
                    $sql = "SELECT * FROM minecraft_srvr.`proposals_votes` WHERE pr_id={$pr_id} and voter_uuid='{$uuid}';";
                    $C = umc_mysql_fetch_all($sql);
                    if (count($C) > 0) {
                        $row_check = $C[0];
                        $vote_id = $row_check['vote_id'];
                        if ($new_vote == 0) {
                            $sql = "DELETE FROM minecraft_srvr.`proposals_votes` WHERE pr_id={$pr_id} and voter_uuid='{$uuid}';";
                            umc_mysql_query($sql, true);
                        } else {
                            if ($row_check['vote'] != $new_vote) {
                                $sql = "REPLACE INTO minecraft_srvr.`proposals_votes` (`vote_id`, `pr_id`, `voter_uuid`, `date`, `vote`)\r\n\t\t\t    VALUES ({$vote_id}, {$pr_id}, '{$uuid}', NOW(), {$new_vote});";
                                umc_mysql_query($sql, true);
                            }
                        }
                    } else {
                        if ($new_vote != 0) {
                            $sql = "INSERT INTO minecraft_srvr.`proposals_votes` (`pr_id`, `voter_uuid`, `date`, `vote`)\r\n                        VALUES ({$pr_id}, '{$uuid}', NOW(), {$new_vote});";
                            umc_mysql_query($sql, true);
                        }
                    }
                } else {
                    if ($prop_status == 'closed') {
                        // a user tried to vote on a closed vote... what to do?
                    }
                }
            }
        }
        // load existing votes
        $total_score = 0;
        $sql = "SELECT date, voter_uuid, UUID.username, vote, date FROM minecraft_srvr.proposals_votes\r\n                LEFT JOIN minecraft_srvr.UUID ON voter_uuid=UUID.UUID\r\n                WHERE pr_id={$pr_id} AND vote <> 0 ORDER BY date DESC;";
        $R = umc_mysql_fetch_all($sql);
        $email_close = "{$UMC_DOMAIN}/vote-for-users/\n";
        foreach ($R as $row_calc) {
            $vote_date = $row_calc['date'];
            $voter_lvl = umc_get_uuid_level($row_calc['voter_uuid']);
            $voter_weight = $vote_ranks[$voter_lvl]['vote'];
            $voter_score = $voter_weight * $row_calc['vote'];
            $total_score = $total_score + $voter_score;
            if ($username == 'uncovery') {
                $out .= "<tr><td>Vote:</td><td>{$row_calc['username']}</td><td>{$voter_lvl}</td><td>{$row_calc['vote']}</td><td>{$row_calc['date']}</td><td>{$voter_score}</td></tr>\n";
                // prepare email to send if this will be closed
            }
            $email_close .= "Vote: {$row_calc['username']} ({$voter_lvl}) on {$row_calc['date']} gave points: {$voter_score}\n";
        }
        // close votes that have enough points
        $lvl_code = $vote_ranks[$prop_lvl]['code'];
        $min_req = $lvl_min_req[$lvl_code];
        if (abs($total_score) >= $min_req && $prop_status == 'voting') {
            // close vote
            $sql = "UPDATE minecraft_srvr.`proposals` SET `status` = 'closed' WHERE `proposals`.`pr_id`={$pr_id} LIMIT 1 ";
            umc_mysql_query($sql, true);
            // send email with status report
            $email_text = $email_close . "Total Score: {$total_score}\n\rRequired: " . abs($lvl_min_req[$lvl_code]);
            $headers = 'From:minecraft@uncovery.me' . "\r\nReply-To:minecraft@uncovery.me\r\n" . 'X-Mailer: PHP/' . phpversion();
            mail('*****@*****.**', "Voting closed for " . $row['username'], $email_text, $headers);
            $prop_status = 'closed';
        } else {
            if ($prop_status == 'closed' && $total_score < abs($lvl_min_req[$lvl_code])) {
                //$sql = "UPDATE minecraft_srvr.`proposals` SET `status` = 'voting' WHERE `proposals`.`pr_id`=$pr_id LIMIT 1 ";
                //mysql_query($sql);
            }
        }
        // show total score
        if ($username == 'uncovery') {
            $header = "<td><strong>{$total_score}</strong> (of {$min_req})</td>";
        }
        // load your own score
        $sql = "SELECT * FROM minecraft_srvr.proposals_votes WHERE voter_uuid = '{$uuid}' AND pr_id={$pr_id}";
        $D = umc_mysql_fetch_all($sql);
        $vote_date = "n/a";
        if (count($D) > 0) {
            $row_votes = $D[0];
            $vote_id = $row_votes['vote_id'];
            $your_vote = $row_votes['vote'];
            $vote_date = $row_votes['date'];
            // check if an alternative vote has been cast right now
            if ($your_vote == 1) {
                $sel_support = " selected=\"selected\"";
            } else {
                if ($your_vote == -1) {
                    $sel_veto = " selected=\"selected\"";
                }
            }
        }
        // show voting buttons
        $vote_close = '';
        $min_req = $lvl_min_req[$lvl_code];
        if ($prop_status == 'closed') {
            $vote = "Voting closed!<input type=\"hidden\" name=\"PR_{$pr_id}\" value=\"done\">";
            if ($username == 'uncovery') {
                $vote_date = "<select name=\"CL_{$pr_id}\"><option value=\"closed\">Voting closed</option><option value=\"success\">Upgrade</option><option value=\"failed\">Fail</option></select>";
            }
        } else {
            $vote = "<select name=\"PR_{$pr_id}\"><option value=\"0\" {$sel_none}>Abstain</option><option value=\"1\"{$sel_support}>Supported</option><option value=\"-1\"{$sel_veto}>Vetoed</option></select>";
        }
        $vote_lvl = umc_get_userlevel($row['username']);
        $out .= "<tr><td><strong><a href=\"{$UMC_DOMAIN}/users-2/?u={$row['username']}\">{$row['username']}</a></strong></td><td>{$row['date']}</td><td>{$prop_lvl}</td><td>{$vote}</td><td>{$vote_date}</td>{$header}</tr>\n";
    }
    if ($proposals == 0) {
        $out .= "<tr><td colspan=6>There are no proposals that you can vote for at the moment!</td><tr>\n";
    }
    $out .= "</table>\n<input type=\"submit\" name=\"votebutton\" value=\"Submit votes!\">\n</form><br>\n";
    // process successful votes, create post to blog
    if (count($upgraded_users) > 0) {
        $text = "Please see the latest upgrades from the voting system:<ul>";
        $userlist_arr = array();
        foreach ($upgraded_users as $upgraded_user => $userlvl) {
            $nextrank = $vote_ranks[$userlvl]['next'];
            $text .= "<li>{$upgraded_user} (from {$userlvl} to {$nextrank})</li>";
            $userlist_arr[] = $upgraded_user;
        }
        $userlist = implode(", ", $userlist_arr);
        $text .= "</ul>Congratz and thanks to all voters!";
        $post = array('comment_status' => 'open', 'ping_status' => 'closed', 'post_author' => 1, 'post_content' => $text, 'post_status' => 'publish', 'post_title' => "Today's upgrades: {$userlist}", 'post_type' => 'post');
        wp_insert_post($post);
    }
    return $out;
}