/**
 * 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);
}
示例#2
0
function umc_get_userinfo($user_raw)
{
    $username = strtolower($user_raw);
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // get registration date from Wordpress
    $uuid = umc_user2uuid($username);
    $user['uuid'] = $uuid;
    // get userlevel, balance, onlinetime
    $sql = "SELECT userlevel, onlinetime, lastlogin, lastlogout, username, UUID.UUID, balance, lot_count, firstlogin\r\n        FROM minecraft_srvr.UUID\r\n        LEFT JOIN minecraft_iconomy.mineconomy_accounts ON UUID.`UUID` = mineconomy_accounts.uuid\r\n        WHERE UUID.`UUID` = '{$uuid}'";
    $D = umc_mysql_fetch_all($sql);
    $d = $D[0];
    if ($d['userlevel'] == null) {
        $level = 'Guest';
    } else {
        $level = $d['userlevel'];
    }
    $username_history = umc_uuid_username_history($uuid);
    if ($username_history) {
        $user['Username History'] = $username_history;
    }
    $user['Level'] = $level;
    $user['Last Seen'] = $d['lastlogin'];
    if ($d['onlinetime'] == NULL) {
        $online_time = "n/a";
    } else {
        $online_time = umc_seconds_to_time($d['onlinetime']);
    }
    $firstdate = substr($d['firstlogin'], 0, 10);
    $today_ts = strtotime("now");
    $firsttime_ts = strtotime($firstdate);
    $days = round(abs($today_ts - $firsttime_ts) / 60 / 60 / 24);
    $user['User since'] = "{$firstdate} ({$days} days)";
    if ($firstdate > '2013-11-20') {
        // not all play time recorded
        $user['Online time since 2013-11-20'] = $online_time;
    } else {
        $user['Online time'] = $online_time;
    }
    if ($d['balance'] == NULL) {
        $user['Uncs'] = '0.00';
    } else {
        $user['Uncs'] = number_format($d['balance'], 2, ".", "'");
    }
    $user['First login'] = $d['firstlogin'];
    $homes_count = umc_home_count(false, $uuid);
    $user['Homes count'] = $homes_count;
    $karma = umc_getkarma($user['uuid'], true);
    $user['Karma'] = $karma;
    $lots = umc_user_getlots($uuid);
    $display_lots = array();
    foreach ($lots as $lot => $data) {
        $display_lots[$data['world']][] = $lot;
    }
    foreach ($display_lots as $world => $lots) {
        $World = ucfirst($world);
        if (count($lots) < 5) {
            $user["{$World} lots"] = implode(", ", $lots);
        } else {
            $user["{$World} lots"] = count($lots) . " lots";
        }
    }
    return $user;
}