Ejemplo n.º 1
0
function ryzom_user_get_info($cid, $webprivs = false, $player_stats = false)
{
    // User information
    global $_RYZOM_API_CONFIG;
    if (isset($_SESSION['dev_shard']) && $_SESSION['dev_shard']) {
        $db = new ServerDatabase(RYAPI_NELDB_HOST, RYAPI_NELDB_LOGIN, RYAPI_NELDB_PASS, RYAPI_NELDB_RING_DEV);
    } else {
        $db = new ServerDatabase(RYAPI_NELDB_HOST, RYAPI_NELDB_LOGIN, RYAPI_NELDB_PASS, RYAPI_NELDB_RING);
    }
    $sql = "SELECT char_name, race, civilisation, cult, guild_id, creation_date, last_played_date FROM characters WHERE char_id = {$cid}";
    $result = $db->query($sql) or die('Could not query on ryzom_user_get_info');
    $found = $db->num_rows($result) >= 1;
    if (!$found) {
        return array('char_name' => _t('guest'), 'cid' => $cid, 'ERROR' => 'unknown_user', 'groups' => array('GUEST'));
    }
    $row = $db->fetch_assoc($result);
    $db->free_result($result);
    if ($row) {
        $row['race'] = substr($row['race'], 2);
        $row['cult'] = substr($row['cult'], 2);
        $row['civ'] = substr($row['civilisation'], 2);
        if ($row['guild_id'] != '0') {
            $xml = @simplexml_load_file(ryzom_guild($row['guild_id'], false));
            //	$xml = false;
            if ($xml !== false) {
                $row['guild_icon'] = (string) $xml->icon;
                $row['guild_name'] = (string) $xml->name;
                $result = $xml->xpath("/guild/members/member[cid={$cid}]");
                while (list(, $item) = each($result)) {
                    $row['grade'] = (string) $item->grade;
                }
            } else {
                $row['guild_name'] = 'UNKNOWN_GUILD_' . $row['guild_id'];
                // Unknow name (normal in yubo shard)
            }
        }
    }
    $uid = intval($cid / 16);
    $db = new ServerDatabase(RYAPI_NELDB_HOST, RYAPI_NELDB_LOGIN, RYAPI_NELDB_PASS, RYAPI_NELDB_NEL);
    $sql = "SELECT Privilege FROM user WHERE UId = {$uid}";
    $result = $db->query($sql) or die("Could not query.");
    $priv_row = $db->fetch_row($result, MYSQLI_NUM);
    $priv = $priv_row[0];
    $db->free_result($result);
    $groups = array();
    $row['uid'] = $uid;
    $row['cid'] = $cid;
    $row['slot'] = $cid % 16;
    if (strpos($priv, ':DEV:') !== false) {
        $groups[] = 'DEV';
        $groups[] = 'SGM';
        $groups[] = 'GM';
        $groups[] = 'EM';
        $groups[] = 'EG';
        $groups[] = 'VG';
        $groups[] = 'G';
    }
    if (strpos($priv, ':SGM:') !== false) {
        $groups[] = 'SGM';
        $groups[] = 'GM';
        $groups[] = 'VG';
        $groups[] = 'G';
    }
    if (strpos($priv, ':GM:') !== false) {
        $groups[] = 'GM';
        $groups[] = 'VG';
        $groups[] = 'G';
    }
    if (strpos($priv, ':VG:') !== false) {
        $groups[] = 'VG';
        $groups[] = 'G';
    }
    if (strpos($priv, ':G:') !== false) {
        $groups[] = 'G';
    }
    if (strpos($priv, ':SEM:') !== false) {
        $groups[] = 'SEM';
        $groups[] = 'EM';
        $groups[] = 'EG';
    }
    if (strpos($priv, ':EM:') !== false) {
        $groups[] = 'EM';
        $groups[] = 'EG';
    }
    if (strpos($priv, ':EG:') !== false) {
        $groups[] = 'EG';
    }
    $groups[] = 'PLAYER';
    if (isset($_SESSION['dev_shard']) && $_SESSION['dev_shard']) {
        $groups[] = 'DEV_SHARD';
    }
    if ($webprivs) {
        $db = new ServerDatabase(RYAPI_WEBDB_HOST, RYAPI_WEBDB_LOGIN, RYAPI_WEBDB_PASS, 'webig');
        $sql = 'SELECT web_privs FROM accounts WHERE uid = ' . intval($cid / 16);
        $result = $db->query($sql) or die("Could not query." . $db->get_error());
        if ($result->num_rows == 0) {
            $db->query('INSERT INTO accounts (`uid`, `web_privs`) VALUES (' . intval($cid / 16) . ', \'\')') or die("Could not query." . $db->get_error());
        }
        $priv_row = $db->fetch_row($result, MYSQLI_NUM);
        $privs = $priv_row[0];
        $db->free_result($result);
        $groups = array_merge($groups, explode(':', $privs));
    }
    if ($player_stats) {
        include_once RYAPI_PATH . 'server/player_stats.php';
        $row['fames'] = ryzom_player_fames_array($cid);
    }
    $row['groups'] = $groups;
    return $row;
}