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;
}
Ejemplo n.º 2
0
 static function updateDatabaseStruct($defs)
 {
     if (file_exists(RYAPP_PATH . 'database.versions')) {
         $versions = unserialize(file_get_contents(RYAPP_PATH . 'database.versions'));
     } else {
         $versions = array();
     }
     $c = "Updating DB Structure...\n";
     foreach ($defs as $dbname => $tables) {
         $db = new ServerDatabase(RYAPI_WEBDB_HOST, RYAPI_WEBDB_LOGIN, RYAPI_WEBDB_PASS, $dbname);
         $db->query("SET NAMES utf8");
         $c .= "\n\tSelected DB '{$dbname}'\n";
         foreach ($tables as $table => $sql) {
             $version = count($sql);
             if (array_key_exists($table, $versions)) {
                 $diff = $version - $versions[$table];
             } else {
                 $versions[$table] = 0;
                 $diff = $version;
             }
             $c .= "\t\tTable '{$table}' need v{$version} (current v" . strval($versions[$table] . ') => ');
             if ($diff > 0) {
                 $sql_to_run = array_slice($sql, $versions[$table], $diff);
                 foreach ($sql_to_run as $sql_run) {
                     if ($sql_run) {
                         $c .= "Run sql... ";
                         $result = $db->query($sql_run);
                     } else {
                         $c .= "KO!!!";
                     }
                 }
                 if ($result) {
                     $c .= "OK";
                     $versions[$table] = $version;
                 }
             } else {
                 $c .= "OK";
             }
             $c .= "\n";
         }
         $c .= "\n";
         $db->close();
     }
     file_put_contents(RYAPP_PATH . 'database.versions', serialize($versions));
     return '<pre>' . $c . '<pre>';
 }