2 /* Copyright (C) 2009 Winch Gate Property Limited
4 * This file is part of ryzom_api.
5 * ryzom_api is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * ryzom_api is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
19 include_once(RYAPI_PATH
.'server/guilds.php');
22 function ryzom_get_user_id($cid, $name, $creation_date) {
23 $name = strtolower($name);
25 $db = ryDB
::getInstance('webig');
27 $dev_shard = ((isset($_SESSION['dev_shard']) && $_SESSION['dev_shard']) ||
(isset($_GET['shardid']) && $_GET['shardid'] == RYAPI_DEV_SHARDID
))?
1:0;
29 $_SESSION['dev_shard'] = 1;
30 $charsWithSameName = $db->query('players', array('name' => $name, 'deleted' => 0, 'dev_shard' => $dev_shard));
32 foreach ($charsWithSameName as $charWithSameName) {
33 // Another char with same name => delete it
34 if (intval($cid) != intval($charWithSameName['cid'])) {
35 $db->update('players', array('deleted' => 1), array('id' => $charWithSameName['id']));
39 $charProps = $db->querySingle('players', array('cid' => intval($cid), 'deleted' => 0, 'dev_shard' => $dev_shard));
40 // new char => create record
42 $charProps = array('name' => $name, 'cid' => $cid, 'creation_date' => $creation_date, 'deleted' => 0, 'dev_shard' => $dev_shard);
43 $charProps['id'] = $db->insert('players', $charProps);
44 if (!$charProps['id'])
45 die('ryDb New Char Error');
47 // char deleted and recreated => change to deleted
48 if ($charProps['creation_date'] != $creation_date) {
49 if (!$db->update('players', array('deleted' => 1), array('id' => $charProps['id'])))
50 die('ryDb Delete char Error: '.$db->getErrors());
51 $charProps = array('name' => $name, 'cid' => $cid, 'creation_date' => $creation_date, 'deleted' => 0, 'dev_shard' => $dev_shard);
52 if (!$charProps['id'] = $db->insert('players', $charProps))
53 die('ryDb New Char in Slot Error');
55 // char renamed => update record
56 if ($charProps['name'] != $name)
57 if (!$db->update('players', array('name' => $name), array('id' => $charProps['id'])))
58 die('ryDb Rename Char Error');
61 return $charProps['id'];
64 function ryzom_get_user_gender($id) {
65 $db = ryDB
::getInstance('webig');
66 $player = $db->querySingle('players', array('id' => $id));
68 if ($player['gender'])
69 return intval($player['gender']);
70 $cid = $player['cid'];
71 $xml = @simplexml_load_file
(RYAPI_PATH
.'data/cache/players/public/'.substr($cid, strlen($cid)-1).'/'.$cid.'.xml');
73 $gender = (string)$xml->public->_gender
;
74 $db->update('players', array('gender' => intval($gender)+
1), array('id' => $id));
81 function ryzom_user_get_info($cid, $webprivs=false, $player_stats=false) {
83 global $_RYZOM_API_CONFIG;
85 if (isset($_SESSION['dev_shard']) && $_SESSION['dev_shard'])
86 $db = new ServerDatabase(RYAPI_NELDB_HOST
, RYAPI_NELDB_LOGIN
, RYAPI_NELDB_PASS
, RYAPI_NELDB_RING_DEV
);
88 $db = new ServerDatabase(RYAPI_NELDB_HOST
, RYAPI_NELDB_LOGIN
, RYAPI_NELDB_PASS
, RYAPI_NELDB_RING
);
89 $sql = "SELECT char_name, race, civilisation, cult, guild_id, creation_date, last_played_date FROM characters WHERE char_id = $cid";
90 $result = $db->query($sql) or die('Could not query on ryzom_user_get_info');
91 $found = $db->num_rows($result) >= 1;
93 return array('char_name' => _t('guest'), 'cid' => $cid, 'ERROR' => 'unknown_user', 'groups' => array('GUEST'));
94 $row = $db->fetch_assoc($result);
95 $db->free_result($result);
97 $row['race'] = substr($row['race'], 2);
98 $row['cult'] = substr($row['cult'], 2);
99 $row['civ'] = substr($row['civilisation'], 2);
100 if ($row['guild_id'] != '0') {
101 $xml = @simplexml_load_file
(ryzom_guild($row['guild_id'], false));
103 if ($xml !== false) {
104 $row['guild_icon'] = (string)$xml->icon
;
105 $row['guild_name'] = (string)$xml->name
;
106 $result = $xml->xpath("/guild/members/member[cid=$cid]");
107 while(list( , $item) = each($result))
108 $row['grade'] = (string)$item->grade
;
110 $row['guild_name'] = 'UNKNOWN_GUILD_'.$row['guild_id']; // Unknow name (normal in yubo shard)
115 $uid = intval($cid / 16);
116 $db = new ServerDatabase(RYAPI_NELDB_HOST
, RYAPI_NELDB_LOGIN
, RYAPI_NELDB_PASS
, RYAPI_NELDB_NEL
);
117 $sql = "SELECT Privilege FROM user WHERE UId = $uid";
118 $result = $db->query($sql) or die("Could not query.");
119 $priv_row = $db->fetch_row($result, MYSQLI_NUM
);
120 $priv = $priv_row[0];
121 $db->free_result($result);
126 $row['slot'] = $cid%16
;
128 if (strpos($priv, ':DEV:') !== false) {
138 if (strpos($priv, ':SGM:') !== false) {
145 if (strpos($priv, ':GM:') !== false) {
151 if (strpos($priv, ':VG:') !== false) {
156 if (strpos($priv, ':G:') !== false) {
160 if (strpos($priv, ':SEM:') !== false) {
166 if (strpos($priv, ':EM:') !== false) {
171 if (strpos($priv, ':EG:') !== false) {
175 $groups[] = 'PLAYER';
176 if (isset($_SESSION['dev_shard']) && $_SESSION['dev_shard'])
177 $groups[] = 'DEV_SHARD';
180 $db = new ServerDatabase(RYAPI_WEBDB_HOST
, RYAPI_WEBDB_LOGIN
, RYAPI_WEBDB_PASS
, 'webig');
181 $sql = 'SELECT web_privs FROM accounts WHERE uid = '.intval($cid/16);
182 $result = $db->query($sql) or die("Could not query.".$db->get_error());
183 if ($result->num_rows
== 0)
184 $db->query('INSERT INTO accounts (`uid`, `web_privs`) VALUES ('.intval($cid/16).', \'\')') or die("Could not query.".$db->get_error());
185 $priv_row = $db->fetch_row($result, MYSQLI_NUM
);
186 $privs = $priv_row[0];
187 $db->free_result($result);
188 $groups = array_merge($groups, explode(':', $privs));
192 include_once(RYAPI_PATH
.'server/player_stats.php');
193 $row['fames'] = ryzom_player_fames_array($cid);
195 $row['groups'] = $groups;