/**
 * Get all variables of the current user from Wordpress and add it to $UMC_USER
 */
function umc_wp_get_vars()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USERS, $UMC_USER, $UMC_ENV, $user_email, $user_login;
    if ($UMC_ENV !== 'wordpress') {
        XMPP_ERROR_trigger("Tried to get wordpress vars, but environment did not match: " . var_export($UMC_ENV, true));
        die('umc_wp_get_vars');
    }
    get_currentuserinfo();
    if (!isset($user_login) || $user_login == '' || $user_email == '') {
        $UMC_USER = false;
    } else {
        if (!function_exists('umc_get_uuid_level')) {
            XMPP_ERROR_send_msg("Could not get uuid_level, Env = {$UMC_ENV}");
            require_once '/home/minecraft/server/bin/core_include.php';
        }
        $uuid = umc_wp_get_uuid_for_currentuser();
        $UMC_USER['ip'] = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_FLAG_IPV4);
        if (!$uuid) {
            // we have a guest who is trying to register
            $UMC_USER['username'] = $user_login;
            $UMC_USER['email'] = $user_email;
            $uuid = umc_user2uuid($user_login);
            $UMC_USER['uuid'] = $uuid;
            $UMC_USER['userlevel'] = 'Guest';
        } else {
            // there is a logged-in user
            umc_uuid_check_usernamechange($uuid);
            $UMC_USER['email'] = $user_email;
            $UMC_USER['username'] = umc_uuid_getone($uuid, 'username');
            $UMC_USER['uuid'] = $uuid;
            $UMC_USER['userlevel'] = umc_get_uuid_level($uuid);
            if (strstr($UMC_USER['userlevel'], 'DonatorPlus')) {
                $UMC_USER['donator'] = 'DonatorPlus';
            } else {
                if (strstr($UMC_USER['userlevel'], 'Donator')) {
                    $UMC_USER['donator'] = 'Donator';
                } else {
                    $UMC_USER['donator'] = false;
                }
            }
        }
        // if we did not get any UUID
        if (!$uuid) {
            $UMC_USER['username'] = $user_login;
            $UMC_USER['uuid'] = false;
            $UMC_USER['userlevel'] = 'Guest';
        }
    }
    //$UMC_USERS[$uuid] = new UMC_User($uuid);
    //$UMC_USERS[$uuid]->set_username($username);
    //$UMC_USERS[$uuid]->set_userlevel($userlevel);
}
Ejemplo n.º 2
0
/**
 * This allows users in-game to set karma for another user
 *
 * @global type $UMC_USER
 */
function umc_setkarma()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER;
    $sender_uuid = $UMC_USER['uuid'];
    $sender = $UMC_USER['username'];
    $sender_lvl = $UMC_USER['userlevel'];
    $args = $UMC_USER['args'];
    if ($sender_lvl == 'guest') {
        umc_error('Guests cannot give karma to others');
    }
    // get user age
    $age_sql = "SELECT DATEDIFF(NOW(),firstlogin) as online_days FROM minecraft_srvr.UUID\r\n        WHERE uuid='{$sender_uuid}'";
    $age_data = umc_mysql_fetch_all($age_sql);
    $online_time = $age_data[0]['online_days'];
    if ($online_time < 10) {
        umc_error("You cannot give karma yet, you are too new on the server!");
    }
    $karma_arr = array('+' => 1, '-' => -1, '0' => 0);
    if (isset($args[1]) && array_key_exists($args[1], $karma_arr)) {
        $new_karma = $karma_arr[$args[1]];
    } else {
        umc_error('You need to indicate the karma value with +,- or 0;');
    }
    if (!isset($args[2])) {
        umc_error('You need to enter the user to give karma to!;');
    } else {
        if (strtolower($args[2]) == strtolower($sender)) {
            umc_error('You cannot give karma to yourself!;');
        }
    }
    $receiver = umc_sanitize_input($args[2], 'player');
    if ($receiver == 'uncovery') {
        umc_error("Thou shalt not judge the maker of all things!");
    }
    // get receiver UUID
    $receiver_uuid = umc_user2uuid($receiver);
    // get user age
    $rec_age_sql = "SELECT DATEDIFF(NOW(),firstlogin) as online_days FROM minecraft_srvr.UUID\r\n        WHERE uuid='{$receiver_uuid}'";
    $rec_age_data = umc_mysql_fetch_all($rec_age_sql);
    $rec_online_time = $rec_age_data[0]['online_days'];
    // receiver user level
    $receiver_lvl = umc_get_uuid_level($receiver_uuid);
    if ($rec_online_time < 10 || $receiver_lvl == 'Guest') {
        umc_error("You cannot give karma to this user, he is too new!");
    }
    // check if there is the same karma already, otherwise fix
    $sql = "SELECT karma FROM minecraft_srvr.karma\r\n        WHERE sender_uuid='{$sender_uuid}' AND receiver_uuid='{$receiver_uuid}';";
    $data_arr = umc_mysql_fetch_all($sql);
    if (count($data_arr) > 0) {
        $oldkarma = $data_arr[0]['karma'];
        if ($new_karma == $oldkarma) {
            umc_echo("You already gave {$receiver} {$oldkarma} karma!");
            // show the karma of the recipient to the user
            umc_getkarma($receiver_uuid);
            exit;
        } else {
            umc_echo("Giving {$receiver} {$new_karma} karma instead of {$oldkarma} karma.");
            $update_sql = "UPDATE minecraft_srvr.karma set karma={$new_karma}\r\n                WHERE sender_uuid='{$sender_uuid}' AND receiver_uuid='{$receiver_uuid}';";
            umc_mysql_query($update_sql, true);
        }
    } else {
        umc_echo("Giving {$new_karma} karma to {$receiver}.");
        $update_sql = "INSERT INTO minecraft_srvr.karma (sender_uuid, receiver_uuid, karma)\r\n            VALUES ('{$sender_uuid}', '{$receiver_uuid}', {$new_karma});";
        umc_mysql_query($update_sql, true);
    }
    umc_log('karma', 'set', "{$sender} ({$sender_uuid}) set {$new_karma} for {$receiver} ({$receiver_uuid})");
    umc_getkarma($receiver_uuid);
}
Ejemplo n.º 3
0
function umc_donation_level($user, $debug = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $U = umc_uuid_getboth($user);
    $uuid = $U['uuid'];
    $username = $U['username'];
    $debug_txt = '';
    global $UMC_SETTING;
    $date_now = new DateTime("now");
    $sql = "SELECT amount, date FROM minecraft_srvr.donations WHERE uuid='{$uuid}';";
    $level = umc_get_uuid_level($uuid);
    if ($level == 'Owner') {
        return false;
    }
    $D = umc_mysql_fetch_all($sql);
    // if there are 0 donations, user should not be changes
    if (count($D) == 0 && strstr($level, "Donator")) {
        XMPP_ERROR_trigger("User {$username} ({$uuid}) never donated but has a donator level ({$level})");
    } else {
        if (count($D) == 0) {
            $debug_txt .= "{$username} ({$uuid}) does not have any donations\n";
            return;
        }
    }
    $debug_txt .= "Checking donation upgrade of user {$username}, current UserLevel: {$level}\n";
    $donation_level = 0;
    // go through all donations and find out how much is still active
    foreach ($D as $row) {
        $date_donation = new DateTime($row['date']);
        $interval = $date_donation->diff($date_now);
        $years = $interval->format('%y');
        $months = $interval->format('%m');
        $donation_term = $years * 12 + $months;
        $donation_leftover = $row['amount'] - $donation_term;
        if ($donation_leftover < 0) {
            $donation_leftover = 0;
            // do not create negative carryforward
        }
        $donation_level = $donation_level + $donation_leftover;
        $debug_txt .= "Amount donated {$row['amount']} {$years} years {$months} m ago = {$donation_term} months ago, {$donation_leftover} leftover, level: {$donation_level}\n";
    }
    $donation_level_rounded = ceil($donation_level);
    // get userlevel and check if demotion / promotion is needed
    $debug_txt .= "user {$username} ({$uuid}) has donation level of {$donation_level_rounded}, now is {$level}\n";
    // current userlevel
    $ranks_lvl = array_flip($UMC_SETTING['ranks']);
    $cur_lvl = $ranks_lvl[$level];
    // get current promotion level
    if (strpos($level, 'DonatorPlus')) {
        $current = 2;
    } else {
        if (strpos($level, 'Donator')) {
            $current = 1;
        } else {
            $current = 0;
        }
    }
    // get future promotion level
    if (count($D) == 0) {
        // this never happens since it's excluded above
        $future = 0;
    } else {
        if ($donation_level_rounded >= 1) {
            $future = 2;
        } else {
            if ($donation_level_rounded < 1) {
                $future = 1;
            }
        }
    }
    $debug_txt .= "future = {$future}, current = {$current}\n";
    $change = $future - $current;
    if ($change == 0) {
        $debug_txt .= "User has right level, nothing to do\n";
        return false;
        // bail if no change needed
    } else {
        // we have a change in level, let's get an error report
        $debug = true;
    }
    $debug_txt .= "User will change {$change} levels\n";
    // get currect rank index
    $debug_txt .= "Current Rank index = {$cur_lvl}\n";
    // calculate base level
    $base_lvl = $cur_lvl - $current;
    $debug_txt .= "User base level = {$base_lvl}\n";
    $new_lvl = $base_lvl + $future;
    if ($new_lvl == $cur_lvl) {
        XMPP_ERROR_send_msg("Donations upgrade: Nothing to do, CHECK this should have bailed earlier!");
        return false;
    }
    $new_rank = $UMC_SETTING['ranks'][$new_lvl];
    $debug_txt .= "User {$username} upgraded from {$level} to {$new_rank}\n";
    umc_exec_command("pex user {$uuid} group set {$new_rank}");
    umc_log('Donations', 'User Level de/promotion', "User {$username} upgraded from {$level} to {$new_rank}");
    if ($debug) {
        XMPP_ERROR_send_msg($debug_txt);
    }
    return $donation_level_rounded;
    // . "($donation_level $current - $future - $change)";
}
Ejemplo n.º 4
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");
    }
}
Ejemplo n.º 5
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;
    }
}
Ejemplo n.º 6
0
/**
 * Check how much space someone has left in their deposit, depending on their user level
 *
 * @global array $UMC_SETTING
 * @param type $uuid
 * @param type $userlevel
 * @return type
 */
function umc_depositbox_checkspace($uuid, $userlevel = false)
{
    global $UMC_SETTING;
    $sql = "SELECT * FROM minecraft_iconomy.deposit WHERE recipient_uuid='{$uuid}';";
    $data = umc_mysql_fetch_all($sql);
    $count = count($data);
    if (!$userlevel) {
        $userlevel = umc_get_uuid_level($uuid);
    }
    $allowed = $UMC_SETTING['depositbox_limit'][$userlevel];
    $remaining = $allowed - $count;
    return $remaining;
}
Ejemplo n.º 7
0
function umc_home_add($uuid, $name, $force = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_SETTING;
    $count = umc_home_count();
    // add a prefix string to lottery home name to prevent conflict
    if (!$force) {
        $userlevel = umc_get_uuid_level($uuid);
        $max_homes = $UMC_SETTING['max_homes'][$userlevel];
        if ($count >= $max_homes) {
            umc_error("You already reached your maximum home count ({$max_homes})!");
        }
    }
    $uuid_sql = umc_mysql_real_escape_string($uuid);
    $name_sql = umc_mysql_real_escape_string($name);
    // add the new entry to the database
    $sql = "INSERT INTO minecraft_srvr.`homes`(`name`, `uuid`, `world`, `x`, `y`, `z`, `yaw`) VALUES " . "({$name_sql},{$uuid_sql},'empire','66.565','64','-57.219','0');";
    // home is empire spawn
    umc_mysql_query($sql, true);
}
Ejemplo n.º 8
0
/**
 * This retrieves the websend environment variables and returns them
 */
function umc_ws_get_vars()
{
    // make sure we are on websend
    global $UMC_ENV, $UMC_USER, $UMC_USERS;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if ($UMC_ENV !== 'websend') {
        XMPP_ERROR_trigger("Tried to get websend vars, but environment did not match: " . var_export($UMC_ENV, true));
        die('umc_ws_get_vars');
    }
    // TODO: find an appropriate filter to sanitize this data
    // Since the input is authenticated with the code, it should be fine, but better safe than sorry
    $json = json_decode(stripslashes($_POST["jsonData"]), true);
    if (!isset($json['Invoker']['Name'])) {
        XMPP_ERROR_trigger("No invoker name in " . var_export($json, true));
    }
    if ($json['Invoker']['Name'] == '@Console') {
        $UMC_USER['username'] = '******';
        $UMC_USER['userlevel'] = 'Owner';
        $UMC_USER['donator'] = 'DonatorPlus';
        $UMC_USER['uuid'] = 'Console0-0000-0000-0000-000000000000';
    } else {
        $UMC_USER['username'] = $json['Invoker']['Name'];
        if (isset($json['Invoker']['UUID'])) {
            $uuid = $json['Invoker']['UUID'];
        } else {
            // this is mostly used for pre-logins. it will check if the user exists and add them to the table if not.
            XMPP_ERROR_trace("Getting UUID for UMC_USER array", "n/a");
            $uuid = umc_user2uuid($json['Invoker']['Name']);
        }
        $UMC_USER['uuid'] = $uuid;
        $UMC_USER['userlevel'] = umc_get_uuid_level($uuid);
        if (strstr($UMC_USER['userlevel'], 'DonatorPlus')) {
            $UMC_USER['donator'] = 'DonatorPlus';
        } else {
            if (strstr($UMC_USER['userlevel'], 'Donator')) {
                $UMC_USER['donator'] = 'Donator';
            } else {
                $UMC_USER['donator'] = false;
            }
        }
        // following only applies for in-game users
        if (isset($json['Invoker']['Location'])) {
            $UMC_USER['current_item'] = $json['Invoker']['CurrentItemIndex'];
            $UMC_USER['mode'] = $json['Invoker']['GameMode'];
            $UMC_USER['world'] = $json['Invoker']['Location']['World'];
            $UMC_USER['coords'] = array('x' => $json['Invoker']['Location']['X'], 'y' => $json['Invoker']['Location']['Y'], 'z' => $json['Invoker']['Location']['Z'], 'yaw' => umc_ws_yaw_fix($json['Invoker']['Location']['Yaw']));
            // xp converted to points value obtained total. JSON returns fractional value.
            $UMC_USER['xplevel'] = $json['Invoker']['XPLevel'];
            $UMC_USER['xpfraction'] = $json['Invoker']['XP'];
            $UMC_USER['xp'] = umc_ws_convert_xp($json['Invoker']['XP'], $json['Invoker']['XPLevel']);
            //IP Address
            $ip_raw = $json['Invoker']['IP'];
            // ip ⇒ "/210.176.194.100:11567"
            $ip_matches = false;
            $pattern = "/^\\/((?:[0-9]{1,3}\\.){3}[0-9]{1,3})/";
            preg_match($pattern, $ip_raw, $ip_matches);
            $UMC_USER['ip'] = $ip_matches[1];
        }
        $UMC_USER['inv'] = array();
        if (isset($json['Invoker']['Inventory'])) {
            $UMC_USER['inv'] = umc_ws_get_inv($json['Invoker']['Inventory']);
            $UMC_USER['current_item'] = $json['Invoker']['CurrentItemIndex'];
        }
    }
    $UMC_USER["args"] = $_POST['args'];
    // online players; we do not retrieve userlevels etc here yet
    $players = array();
    if (isset($json['ServerStatus']['OnlinePlayers'])) {
        $playerlist = $json['ServerStatus']['OnlinePlayers'];
        $player_all_data = array();
        /*
                Name:Bugsy_danny,
                XP:0.22314094007015228,
                IP:/66.27.153.127:50676,
                GameMode:SURVIVAL,
                UUID:b5e51419-30d0-4920-b7da-c90dabac6b07,
                FoodLevel:20,
                IsOP:false,
                Health:20,
                XPLevel:28,
                Exhaustion:1.4806113243103027,
                UUIDVersion:4
        */
        foreach ($playerlist as $player_data) {
            $players[$player_data['UUID']] = strtolower($player_data['Name']);
            foreach ($player_data as $type => $value) {
                $uuid = $player_data['UUID'];
                $player_all_data[$uuid][$type] = $value;
            }
        }
        $UMC_USER['online_players'] = $players;
        $UMC_USER['player_data'] = $player_all_data;
    }
    /*
        $current_user = new User();                         // create a user object
        $current_user->set_uuid($UMC_USER['uuid']);         // give it a uuid
        $UMC_USERS['current_user'] = $UMC_USER['uuid'];     // remember that this is the current user
        $UMC_USERS[$UMC_USER['uuid']] = $current_user;      // add the object to the list of all users
    *
    */
}
Ejemplo n.º 9
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;
}