/**
 * Create an array of all dibs for processing during the lot reset process
 */
function umc_lot_manager_dibs_get_all()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $dibs_sql = 'SELECT * FROM minecraft_srvr.lot_reservation ORDER BY lot, date;';
    $R = umc_mysql_fetch_all($dibs_sql);
    $dibs = array();
    $a_user = umc_get_active_members();
    foreach ($R as $r) {
        // check if the user is active or not
        if (isset($a_user[$r['uuid']])) {
            $dibs[$r['lot']][$r['date']] = array('uuid' => $r['uuid'], 'action' => $r['action']);
        } else {
            umc_lot_manager_dib_delete($r['uuid']);
        }
    }
    return $dibs;
}
function umc_usericon_get($users = false, $update = true)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_PATH_MC;
    $steve_head = '/home/minecraft/server/bin/data/steve.png';
    if (!$users) {
        $users = umc_get_active_members();
    } else {
        if (is_array($users) && count($users) == 0) {
            XMPP_ERROR_send_msg("umc_update_usericons got zero users!");
        } else {
            if (!is_array($users)) {
                $U = umc_uuid_getboth($users);
                $users = array($U['uuid'] => $U['username']);
            }
        }
    }
    $users_raw = array();
    foreach ($users as $uuid => $username) {
        $uuid_raw = str_replace("-", "", $uuid);
        $users_raw[$uuid] = $url = "https://sessionserver.mojang.com/session/minecraft/profile/{$uuid_raw}";
    }
    $no_skin = array();
    $failed_users = array();
    $skin_urls = array();
    $D = unc_serial_curl($users_raw, 0, 50, '/home/includes/unc_serial_curl/google.crt');
    foreach ($D as $uuid => $d) {
        // we only update the skin if it does not exist
        if (!$update && file_exists("{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png")) {
            continue;
        }
        if ($uuid == 'abandone-0000-0000-0000-000000000000') {
            continue;
        }
        if ($d['response']['http_code'] !== 200) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $d['response']['url'], 'reason' => 'Could not download user data');
        }
        $base64_texture = '';
        $d_arr = json_decode($d['content']);
        if (!$d_arr) {
            XMPP_ERROR_trigger("Failed to retrieve session profile for {$uuid}");
        }
        //object(stdClass)#2 (3) {
        //  ["id"]=>
        //  string(32) "ab3bc877443445a993bdbab6df41eabf"
        //  ["name"]=>
        //  string(8) "uncovery"
        //  ["properties"]=>
        //  array(1) {
        //    [0]=>
        //    object(stdClass)#3 (2) {
        //      ["name"]=>
        //      string(8) "textures"
        //      ["value"]=>
        //      string(308) "eyJ0aW1lc3RhbXAiOjE0NDA0NzUyOTQ2NDksInByb2ZpbGVJZCI6ImFiM2JjODc3NDQzNDQ1YTk5M2JkYmFiNmRmNDFlYWJmIiwicHJvZmlsZU5hbWUiOiJ1bmNvdmVyeSIsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9jYWVhMjljODY2ZDkyMTVhYWJjMTk5MDQyMTE1ZWMwNTUzMzJkNjZlMGI4ZWY2ZjkyNjNmZTRiMWZlNzZlIn19fQ=="
        //    }
        //  }
        //}
        if (!isset($d_arr->properties)) {
            XMPP_ERROR_trace("json", $d_arr);
            XMPP_ERROR_trigger("Failed to retrieve properties for {$uuid}");
        }
        $prop_count = count($d_arr->properties);
        for ($i = 0; $i < $prop_count; $i++) {
            if ($d_arr->properties[$i]->name == 'textures') {
                $base64_texture = $d_arr->properties[$i]->value;
            } else {
                echo "Wrong property: " . $d_arr->properties[$i]->name;
            }
        }
        $raw_texture = base64_decode($base64_texture);
        // {"timestamp":1440475294649,"profileId":"ab3bc877443445a993bdbab6df41eabf","profileName":"uncovery","textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/caea29c866d9215aabc199042115ec055332d66e0b8ef6f9263fe4b1fe76e"}}}
        $texture_arr = json_decode($raw_texture);
        if (!$texture_arr) {
            XMPP_ERROR_trigger("Failed to decode texture: {$raw_texture}");
        }
        $time_stamp = $texture_arr->timestamp;
        // check if the file on the drive is newer
        $current_file = "{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png";
        if (!file_exists($current_file) || filemtime($current_file) > $time_stamp) {
            if (isset($texture_arr->textures->SKIN)) {
                // user did not set skin
                $skin_urls[$uuid] = $texture_arr->textures->SKIN->url;
                // echo $texture_arr->textures->SKIN->url . "<br>\n";
            } else {
                XMPP_ERROR_trace("{$uuid} does not have a skin: {$raw_texture}");
                $no_skin[] = $uuid;
            }
        }
    }
    $S = unc_serial_curl($skin_urls);
    foreach ($S as $uuid => $s) {
        $skin_file = "{$UMC_PATH_MC}/server/bin/data/full_skins/{$uuid}.png";
        $head_file = "{$UMC_PATH_MC}/server/bin/data/user_icons/{$uuid}.png";
        if ($s['response']['content_type'] !== 'image/png' && $s['response']['http_code'] !== 200) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $s['response']['url'], 'reason' => 'Could not download image');
            continue;
        }
        $written = file_put_contents($skin_file, $s['content']);
        if (!$written) {
            $failed_users[] = array('uuid' => $uuid, 'url' => $s['response']['url'], 'reason' => "Could not save file to {$skin_file}");
            continue;
        }
        // convert to head icon, resize to 20x20
        $command = "convert -crop '8x8+8+8' -scale 20 \"{$skin_file}\" \"{$head_file}\"";
        exec($command);
    }
    // process users w/o skin
    foreach ($no_skin as $uuid) {
        $head_file = "{$UMC_PATH_MC}/server/bin/data/user_icons/{$uuid}.png";
        if (!file_exists($steve_head)) {
            XMPP_ERROR_trigger("Steve head icon not available");
        } else {
            $check = copy($steve_head, $head_file);
            if (!$check || !file_exists($head_file)) {
                XMPP_ERROR_trigger("Could not create steve head for file {$head_file}");
            } else {
                XMPP_ERROR_trace("used steve head for {$head_file}");
            }
        }
    }
    if (count($failed_users) > 0) {
        XMPP_ERROR_trace("failed users:", $failed_users);
        XMPP_ERROR_trigger("Users failed to get icon, see error report for details");
    }
}
function umc_webkarma()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $members = umc_get_active_members();
    // list onliny active receivers
    $all_sql = "SELECT SUM(karma), receiver_uuid, receivers.username AS username\r\n        FROM minecraft_srvr.karma\r\n        LEFT JOIN minecraft_srvr.UUID AS receivers ON receiver_uuid=receivers.uuid\r\n        LEFT JOIN minecraft_srvr.UUID AS senders ON sender_uuid=senders.uuid\r\n\tWHERE senders.lot_count > 0\r\n        GROUP BY receiver_uuid\r\n        ORDER BY SUM(karma) DESC, username ASC";
    $all_data = umc_mysql_fetch_all($all_sql);
    $out_data = array();
    foreach ($all_data as $row) {
        $receiver = $row['username'];
        $receiver_uuid = $row['receiver_uuid'];
        if (!isset($members[$receiver_uuid]) || $receiver == 'uncovery') {
            continue;
        }
        $sql = "SELECT karma FROM minecraft_srvr.karma\r\n            LEFT JOIN minecraft_srvr.UUID AS sender ON sender_uuid=sender.uuid\r\n            WHERE receiver_uuid = '{$receiver_uuid}'\r\n\t      AND sender.lot_count > 0";
        $sender_data = umc_mysql_fetch_all($sql);
        $pos_karma = 0;
        $neg_karma = 0;
        foreach ($sender_data as $send_row) {
            if ($send_row['karma'] > 0) {
                $pos_karma = $pos_karma + $send_row['karma'];
            } else {
                if ($send_row['karma'] < 0) {
                    $neg_karma = $neg_karma + $send_row['karma'];
                }
            }
        }
        $sum_karma = $pos_karma + $neg_karma;
        $out_data[] = array('username' => $receiver, 'karma' => $sum_karma, 'Positive Karma' => $pos_karma, 'Negative Karma' => $neg_karma);
    }
    echo umc_web_table("karma", 1, $out_data, '', array(), array('username'), false);
}
Esempio n. 4
0
function umc_lot_addrem()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    /// /lotmember lot world add target
    if (count($args) <= 3) {
        umc_echo("{red}Not enough arguments given");
        umc_show_help($args);
        return;
    }
    $addrem = $args[1];
    $lot = strtolower($args[2]);
    $action = $args[3];
    $worlds = array('emp' => 'empire', 'fla' => 'flatlands', 'dar' => 'darklands', 'aet' => 'aether', 'kin' => 'kingdom', 'dra' => 'draftlands', 'blo' => 'skyblock', 'con' => 'aether');
    $world_abr = substr($lot, 0, 3);
    if (!isset($worlds[$world_abr])) {
        umc_error("Your used an invalid lot name!");
    }
    $world = $worlds[$world_abr];
    if ($player == '@Console') {
        $player = 'uncovery';
    }
    $user_id = umc_get_worldguard_id('user', strtolower($player));
    if (!$user_id) {
        umc_error("Your user id cannot be found!");
    }
    $player_group = umc_get_userlevel($player);
    $world_id = umc_get_worldguard_id('world', $world);
    if (!$world_id) {
        umc_show_help($args);
        umc_error("The lot '{$lot}' cannot be found in any world!");
    }
    if (!umc_check_lot_exists($world_id, $lot)) {
        umc_show_help($args);
        umc_error("There is no lot {$lot} in world {$world}!");
    }
    if ($action == 'snow' || $action == 'ice') {
        // check if the user has DonatorPlus status.
        if ($player_group !== 'Owner') {
            if (!stristr($player_group, 'DonatorPlus')) {
                umc_error("You need to be DonatorPlus level to use the snow/ice features!;");
            }
            $owner_switch = 0;
            // check if player is Owner of lot
            $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$user_id} and Owner=1;";
            $D = umc_mysql_fetch_all($sql);
            $num = count($D);
            if ($num != 1) {
                umc_error("It appears you {$player} ({$user_id}) are not Owner of lot {$lot} in world {$world}!");
            }
        }
        // get the current status of the flags
        if ($addrem == 'add') {
            $flag = 'allow';
            umc_echo("Allowing {$action} forming on lot {$lot}... ");
        } else {
            if ($addrem == 'rem') {
                $flag = 'deny';
                umc_echo("Preventing {$action} forming on lot {$lot}... ");
            } else {
                umc_show_help($args);
            }
        }
        if ($action == 'snow') {
            $flagname = 'snow-fall';
        } else {
            if ($action == 'ice') {
                $flagname = 'ice-form';
            }
        }
        // does flag exist?
        $check_sql = "SELECT * FROM minecraft_worldguard.region_flag WHERE region_id='{$lot}' AND world_id={$world_id} AND flag='{$flagname}';";
        $D2 = umc_mysql_fetch_all($check_sql);
        $count = count($D2);
        if ($count == 0) {
            // insert
            $ins_sql = "INSERT INTO minecraft_worldguard.region_flag (region_id, world_id, flag, value) VALUES ('{$lot}', {$world_id}, '{$flagname}', '{$flag}');";
            umc_mysql_query($ins_sql, true);
        } else {
            // update
            $upd_sql = "UPDATE minecraft_worldguard.region_flag SET value='{$flag}' WHERE region_id='{$lot}' AND world_id={$world_id} AND flag='{$flagname}';";
            umc_mysql_query($upd_sql, true);
        }
        umc_echo("done!");
        umc_log('lot', 'addrem', "{$player} changed {$action} property of {$lot}");
    } else {
        if ($action == 'owner' || $action == 'give') {
            if ($player != 'uncovery' && $player != '@Console') {
                umc_error("Nice try, {$player}. Think I am stupid? Want to get banned?");
            }
            $owner_switch = 1;
        } else {
            if ($action == 'member') {
                $user_id = umc_get_worldguard_id('user', strtolower($player));
                if (!$user_id && $player !== 'uncovery') {
                    umc_error("Your user id cannot be found!");
                }
                $owner_switch = 0;
                // check if player is Owner of lot
                if ($player_group !== 'Owner') {
                    $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$user_id} and Owner=1;";
                    $D3 = umc_mysql_fetch_all($sql);
                    $count = count($D3);
                    if ($count != 1) {
                        umc_error("It appears you ({$player} {$user_id}) are not Owner of lot {$lot} in world {$world}!");
                    }
                }
            } else {
                umc_echo("Action {$action} not recognized!");
                umc_show_help($args);
                return;
            }
        }
        // get list of active users
        $active_users = umc_get_active_members();
        for ($i = 4; $i < count($args); $i++) {
            $target = strtolower($args[$i]);
            // check if target player exists
            $target_id = umc_get_worldguard_id('user', strtolower($target));
            if (!$target_id) {
                umc_error("The user {$target} does not exist in the database. Please check spelling of username");
            }
            if ($player != 'uncovery') {
                $targ_group = umc_get_userlevel($target);
                if ($targ_group == 'Guest') {
                    umc_error("You cannnot add Guests to your lot!;");
                } else {
                    if (!in_array($target, $active_users)) {
                        XMPP_ERROR_trigger("{$player} tried to add {$target} to his lot {$lot}, but {$target} is not an active member!");
                        umc_error("{$target} is not an active user! You can only add people who have their own lot! See FAQ entry #32 please.");
                    }
                }
            }
            // add / remove target player from lot
            if ($addrem == 'add') {
                // make sure target is not already there
                $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$target_id};";
                $D3 = umc_mysql_fetch_all($sql);
                $num = count($D3);
                if ($num == 1) {
                    umc_error("It appears {$target} is already member of lot {$lot} in world {$world}!");
                }
                // add to the lot
                umc_lot_add_player($target, $lot, 0);
                umc_echo("Added {$target} to {$lot} in the {$world}!");
            } else {
                if ($addrem == 'rem') {
                    // check if target is there at all
                    $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id={$world_id} AND user_id={$target_id} AND Owner={$owner_switch} LIMIT 1;";
                    $D3 = umc_mysql_fetch_all($sql);
                    $num = count($D3);
                    if ($num !== 1) {
                        umc_error("It appears user {$target} is not a member of lot {$lot} in world {$world}!");
                    }
                    umc_lot_rem_player($target, $lot, 0);
                    umc_echo("Removed {$target} from {$lot} in the {$world}!");
                } else {
                    if ($addrem == 'give') {
                        // remove all members and owners
                        umc_lot_remove_all($lot);
                        umc_lot_add_player($target, $lot, 1);
                        umc_echo("Gave {$lot} to {$target} in the {$world}! All other user removed!");
                        // logfile entry
                        umc_log('lot', 'addrem', "{$player} gave lot to {$target}");
                    } else {
                        umc_show_help($args);
                    }
                }
            }
        }
    }
    umc_ws_cmd("region load -w {$world}", 'asConsole');
}
Esempio n. 5
0
function umc_donation_chart()
{
    global $UMC_SETTING, $UMC_USER, $UMC_DONATION;
    if (!$UMC_USER) {
        $out = "Please <a href=\"{$UMC_SETTING['path']['url']}/wp-admin/profile.php\">login</a> to buy donator status!" . "<a href=\"{$UMC_SETTING['path']['url']}/wp-admin/profile.php\"><img src=\"https://www.paypalobjects.com/en_GB/HK/i/btn/btn_paynowCC_LG.gif\"></a>";
        return $out;
    } else {
        $uuid = $UMC_USER['uuid'];
        $username = $UMC_USER['username'];
    }
    $chart_data = umc_donation_java_chart();
    $outstanding = $chart_data['outstanding'];
    $chart = $chart_data['chart'];
    $donation_avg = umc_donation_calc_average();
    $table = umc_donation_top_table($outstanding);
    $active_users = umc_get_active_members();
    $out = "<div style=\"float:right; width:440px; margin-left: 30px;\">\n{$chart}\n{$table}</div>\n" . "<div style=\"width:auto; overflow:hidden; \">Uncovery Minecraft is run privately, without advertising or mandatory fees. We also want to stay away from \"pay-to-win\"\r\n        and therefore also want to only provide non-essential benefits to donators. Those benefits can be seen on the bottom of\r\n        the \"<a href=\"http://uncovery.me/user-levels/\">Userlevels &amp; Commands</a>\" page. If you ask me what I am doing with the donation money,\r\n        you have to understand that the server is already paid by me in advance on a 2 year contract since that's much cheaper than paying month-by-month.\r\n        So the donations that I receive go into my PayPal account that I use to pay other things through PayPal. I sometimes donate to other\r\n        plugin authors if I want them to speed up some features for example. The target is however that if we ever have a surplus, that\r\n        this will be used to either improve or advertise the server. The monthly server costs are 135 USD. Donations are always welcome\r\n        and encourage me to spend more time on the server and continue to fix, upgrade and enhance it, run contests and provide an adequate support to the users.\r\n        <h2>Donation Status</h2>\nWe have a target to cover our monthly costs with donations.<br>\n" . umc_donation_monthly_target() . "If the donation target is exceeded, we will use the excess to fill the gaps of the past months.<br>\n" . "On the right, you can see the long term development of the server income vs. expenses and does not include pre-payments done for the 2-year contract, but only the monthly costs as time goes by as if we were paying every month.\n</div>" . '<h2 style="clear:both;">Donate now!</h2>' . "\n<strong>Donations are processed manually.</strong> You will get an email from PayPal, but you will get a confirmation from the server only after we received an email from PayPal and manually processed it. \n" . "This can take up to 24 hours. Once you received a confirmation email from the server, your userlevel will be updated once you (re-) login to the minecraft server.\n" . '<br><br><form style="display:inline;" action="' . $UMC_DONATION['paypal_url'] . '" method="post" target="_top">' . '<input type="hidden" name="cmd" value="_s-xclick">' . '<input type="hidden" name="hosted_button_id" value="' . $UMC_DONATION['button_id'] . '">' . '<p style="text-align:center;"><input type="hidden" name="on0" value="DonatorPlus Status">' . "The average donation amount is <strong>{$donation_avg} USD</strong><br>\r\n        Buy DonatorPlus Status as user <strong>{$username}<br>\r\n            (UUID: {$uuid})" . '</strong><br> Duration <select style="font-size:12px" name="os0">
            <option value="1 Month">1 Month $2.00 USD</option>
            <option value="6 Months">6 Months $7.00 USD</option>
            <option value="1 Year">1 Year $13.00 USD</option>
            <option value="2 Years">2 Years $25.00 USD</option>
            <option value="4 Years">4 Years $50.00 USD</option>
        </select>
        <input type="hidden" name="on1" value="Your Username"><input type="hidden" name="os1" value="' . $uuid . '"><br>
        <input type="hidden" name="on2" value="for Recipient(s)">Recipient: ' . umc_web_dropdown($active_users, 'os2', $uuid) . '<input type="hidden" name="currency_code" value="USD"><br>
            <strong>Important:</strong> If you want the amount split between several users, please do not make several donations.<br>
            Make the donation for yourself and then send me a message with the details.<br>
        <input type="image" src="https://www.paypalobjects.com/en_GB/HK/i/btn/btn_paynowCC_LG.gif" name="submit" alt="PayPal — The safer, easier way to pay online.">
        <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
        </p>
        </form>';
    return $out;
}
function umc_home_import()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // global $UMC_USER;
    // we automatically import old homes for all players on login, but only once
    // include spyc to parse YAML https://github.com/mustangostang/spyc
    require_once '/home/includes/spyc/Spyc.php';
    $users = umc_get_active_members();
    foreach ($users as $uuid => $username) {
        $path = '/home/minecraft/server/bukkit/plugins/Essentials/userdata/' . $uuid . ".yml";
        $A = Spyc::YAMLLoad($path);
        $existing_count = umc_home_count(false, $uuid);
        if ($existing_count > 0) {
            continue;
        }
        if (!isset($A['homes'])) {
            continue;
        }
        $count = count($A['homes']);
        if ($count == 0) {
            continue;
        }
        $H = $A['homes'];
        // iterate homes and import them
        foreach ($H as $home_name => $h) {
            $name = umc_mysql_real_escape_string($home_name);
            // XMPP_ERROR_trigger($h);
            $sql = "INSERT INTO minecraft_srvr.`homes`(`name`, `uuid`, `world`, `x`, `y`, `z`, `yaw`) VALUES " . "({$name},'{$uuid}','{$h['world']}','{$h['x']}','{$h['y']}','{$h['z']}','{$h['yaw']}');";
            umc_mysql_query($sql, true);
        }
        umc_log('home', 'import', "{$uuid}/{$username} {$count} homes have been imported!");
    }
}