Example #1
0
function umc_time_until_restart()
{
    global $UMC_SETTING;
    $restart_time = $UMC_SETTING['restart_time'];
    $target_date = umc_datetime("tomorrow {$restart_time}");
    $interval = umc_timer_array_diff($target_date);
    $out = '';
    if ($interval->h > 0) {
        $out .= $interval->h . " hours and ";
    }
    $out .= $interval->i . " min";
    return $out;
}
Example #2
0
function umc_get_lot_owner_age($format = 'string', $oneuser = false, $debug = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $playerfilter = "";
    if ($oneuser) {
        $uuid = umc_uuid_getone($oneuser, 'uuid');
        $playerfilter = " AND UUID.uuid = '{$uuid}'";
    }
    //temp fix for wrong userlogin
    umc_uuid_firstlogin_update($uuid);
    $sql = "SELECT username, lastlogin, firstlogin, onlinetime\r\n        FROM minecraft_srvr.UUID\r\n        LEFT JOIN minecraft_worldguard.user ON user.uuid=UUID.uuid\r\n        LEFT JOIN minecraft_worldguard.region_players ON id=user_id\r\n        WHERE owner=1 {$playerfilter}\r\n        GROUP BY username, lastlogin\r\n        ORDER BY lastlogin ASC";
    $R = umc_mysql_fetch_all($sql);
    $users = array();
    $diff_steps = array('y' => 'years', 'm' => 'months', 'd' => 'days', 'h' => 'hours', 'i' => 'minutes', 's' => 'seconds');
    /*
    *
       $now = time(); // or your date as well
       $your_date = strtotime("2013-11-20");
       $datediff = $now - $your_date;
       $alt_days = floor($datediff/(60*60*24));
    */
    // umc_error_notify("Could not get player age: $sql");
    if (count($R) == 0) {
        // umc_error_notify("Error to get user age: $sql");
        return false;
    }
    foreach ($R as $row) {
        $username = strtolower($row['username']);
        $last_time = $row['lastlogin'];
        /* if (!function_exists('umc_datetime')) {
                    umc_error_longmsg("umc_Datetime not found ($sql)");
                    include_once("$UMC_PATH_MC/server/bin/includes/timer.inc.php");
                    if (!function_exists('umc_datetime')) {
                        umc_error_longmsg("Datetime function not found (level2)");
                    }
        
                }*/
        $last_datetime = umc_datetime($last_time);
        $first_time = $row['firstlogin'];
        if ($debug) {
            echo "First_time = {$first_time}\n";
        }
        $first_datetime = umc_datetime($first_time);
        if ($debug) {
            echo "First_datetime = " . var_export($first_datetime, true);
        }
        if ($format == 'string') {
            $last_diff = umc_timer_array_diff($last_datetime);
            $first_diff = umc_timer_array_diff($first_datetime);
            foreach ($diff_steps as $code => $text) {
                $last_val = $last_diff->{$code};
                $users[$uuid]['lastlogin'][$text] = $last_val;
                $first_val = $first_diff->{$code};
                $users[$uuid]['firstlogin'][$text] = $first_val;
            }
        } else {
            // days
            $first_seconds = umc_timer_raw_diff($first_datetime);
            if ($debug) {
                echo "First_seconds = " . var_export($first_seconds, true);
            }
            $first_days = round($first_seconds / 60 / 60 / 24);
            $users[$uuid]['firstlogin']['days'] = $first_days;
            $users[$uuid]['firstlogin']['seconds'] = $first_seconds;
            $last_seconds = umc_timer_raw_diff($last_datetime);
            $last_days = round($last_seconds / 60 / 60 / 24);
            $users[$uuid]['lastlogin']['days'] = $last_days;
            $users[$uuid]['lastlogin']['seconds'] = $last_seconds;
        }
        $users[$uuid]['lastlogin']['full'] = $last_time;
        $users[$uuid]['firstlogin']['full'] = $first_time;
        $users[$uuid]['onlinetime']['seconds'] = $row['onlinetime'];
        $users[$uuid]['onlinetime']['days'] = round($row['onlinetime'] / 60 / 60 / 24);
    }
    return $users;
}
function umc_hardcore_get_period()
{
    global $HARDCORE;
    $first_date_obj = umc_datetime($HARDCORE['first_date']);
    $interval = umc_timer_array_diff($first_date_obj);
    $days_count = $interval->format('%a');
    $period_length = $HARDCORE['period_length'];
    $period_no = floor($days_count / $period_length);
    $period_days_since = $period_no * $period_length;
    $first_date_obj->add(new DateInterval('P' . $period_days_since . 'D'));
    $period_start_date = $first_date_obj->format('Y-m-d 00:00:00');
    $first_date_obj->add(new DateInterval('P' . $period_length . 'D'));
    $period_end_date = $first_date_obj->format('Y-m-d 00:00:00');
    $retval = array('number' => $period_no, 'start_date' => $period_start_date, 'end_date' => $period_end_date);
    return $retval;
}