mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-22 23:06:18 +00:00
Added: external auth
This commit is contained in:
parent
c322ff5129
commit
c813eb4b12
10 changed files with 90 additions and 65 deletions
|
@ -20,30 +20,28 @@ require_once(RYAPI_PATH.'client/config.php');
|
|||
|
||||
// Og (non-ryzom.com) method
|
||||
function ryzom_authenticate_with_serverkey($cid, $name, $authserver, $authkey) {
|
||||
global $_RYZOM_API_CONFIG;
|
||||
$fn = $_RYZOM_API_CONFIG['auth_script'].'?name='.$name.'&cid='.$cid.'&authkey='.$authkey.'&authserver='.$authserver;
|
||||
|
||||
$res = file_get_contents($fn);
|
||||
return $res == '1';
|
||||
}
|
||||
|
||||
// Ig method
|
||||
function ryzom_authenticate_ingame($cid, $name, $authkey) {
|
||||
global $_RYZOM_API_CONFIG;
|
||||
$fn = $_RYZOM_API_CONFIG['auth_script'].'?name='.$name.'&cid='.$cid.'&authkey='.$authkey.'&ig=1';
|
||||
if (isset($_SESSION['user']))
|
||||
return true;
|
||||
|
||||
$res = file_get_contents($fn);
|
||||
echo $res;
|
||||
return $res == '1';
|
||||
if (ryzom_get_param('user'))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Session method
|
||||
function ryzom_authenticate_with_session($name, $redirect) {
|
||||
global $_RYZOM_API_CONFIG;
|
||||
$fn = $_RYZOM_API_CONFIG['auth_script'].'?name='.$name;
|
||||
if (isset($_SESSION['user']))
|
||||
return true;
|
||||
|
||||
$res = file_get_contents($fn);
|
||||
return $res == '1';
|
||||
if (ryzom_get_param('user'))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -17,7 +17,23 @@
|
|||
*/
|
||||
|
||||
function ryzom_user_get_info($cid) {
|
||||
return Array();
|
||||
if (isset($_SESSION['user']))
|
||||
return $_SESSION['user'];
|
||||
|
||||
$user = unserialize(base64_decode(ryzom_get_param('user')));
|
||||
$_SESSION['user'] = $user;
|
||||
return $user;
|
||||
}
|
||||
|
||||
function ryzom_get_user_id($cid, $name, $creation_date) {
|
||||
if (isset($_SESSION['user']))
|
||||
return $_SESSION['user']['id'];
|
||||
|
||||
$user = unserialize(base64_decode(ryzom_get_param('user')));
|
||||
$_SESSION['user'] = $user;
|
||||
|
||||
return $user['id'];
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -5,7 +5,8 @@ function ryzom_app_authenticate(&$user, $ask_login=true, $welcome_message='') {
|
|||
$authserver = ryzom_get_param('authserver');
|
||||
$authkey = ryzom_get_param('authkey');
|
||||
$lang = ryzom_get_param('lang');
|
||||
|
||||
$cid = ryzom_get_param('cid', '');
|
||||
$is_ingame = false;
|
||||
// we have to set the $user['lang'] even for anonymous user or we cannot display the test in the right langage
|
||||
if($lang == '') {
|
||||
$l = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||
|
@ -14,15 +15,20 @@ function ryzom_app_authenticate(&$user, $ask_login=true, $welcome_message='') {
|
|||
else
|
||||
$lang = 'en';
|
||||
}
|
||||
$user['message'] = '';
|
||||
$user['lang'] = $lang;
|
||||
|
||||
if (RYZOM_IG || ryzom_get_param('ig')) {
|
||||
$user['ig'] = false;
|
||||
|
||||
if ((isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Ryzom')) || ryzom_get_param('ig')) {
|
||||
$user['ig'] = true;
|
||||
// Ingame
|
||||
$cid = ryzom_get_param('cid');
|
||||
if (!ryzom_authenticate_ingame($cid, $name, $authkey))
|
||||
$shardid = ryzom_get_param('shardid');
|
||||
if (!ryzom_authenticate_ingame($shardid, $cid, $name, $authkey))
|
||||
return false;
|
||||
$is_ingame = true;
|
||||
} else {
|
||||
// Outgame : Use session
|
||||
$error_message = '';
|
||||
if (!ryzom_authenticate_with_session($name, $cid, $error_message)) {
|
||||
if ($ask_login) {
|
||||
$c = '';
|
||||
|
@ -47,8 +53,12 @@ function ryzom_app_authenticate(&$user, $ask_login=true, $welcome_message='') {
|
|||
// get user informations
|
||||
$user = ryzom_user_get_info($cid);
|
||||
$user['lang'] = $_SESSION['lang'];
|
||||
|
||||
$user['id'] = ryzom_get_user_id($cid, $user['char_name'], $user['creation_date']);
|
||||
if (isset($user['creation_date']))
|
||||
$user['id'] = ryzom_get_user_id($cid, $user['char_name'], $user['creation_date']);
|
||||
if ($is_ingame && $user['last_played_date'] != '0')
|
||||
$user['ig'] = true;
|
||||
else
|
||||
$user['ig'] = false;
|
||||
unset($user['last_played_date']);
|
||||
unset($user['creation_date']);
|
||||
return true;
|
||||
|
|
|
@ -33,7 +33,7 @@ class ryLogger {
|
|||
function getLogs() {
|
||||
$ret = '';
|
||||
if ($this->logs && $this->enable)
|
||||
$ret = "<b>Debug</b>\n".implode("\n", $this->logs);
|
||||
$ret = "<b>Debug</b>\n\n".implode("\n", $this->logs);
|
||||
$this->logs = array();
|
||||
return $ret;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function ryzom_app_render($title, $content, $bgcolor='', $javascript=array(), $homeLink=false) {
|
||||
function ryzom_app_render($title, $content, $ig=false, $bgcolor='', $javascript=array(), $homeLink=false) {
|
||||
$c = '';
|
||||
// Render header
|
||||
$title_prefix = '';
|
||||
|
@ -25,38 +25,35 @@ function ryzom_app_render($title, $content, $bgcolor='', $javascript=array(), $h
|
|||
}
|
||||
|
||||
if (!$bgcolor)
|
||||
$bgcolor = '#000000'.(RYZOM_IG?'00':'');
|
||||
$bgcolor = '#000000'.($ig?'00':'');
|
||||
|
||||
$c .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
|
||||
$c .= '<html>
|
||||
<head>'."\n";
|
||||
$c .= ' <title>'.$title_prefix.(translation_exists($title)?_t($title):$title).'</title>'."\n";
|
||||
$c .= ' <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8" />'."\n";
|
||||
|
||||
if (!RYZOM_IG) {
|
||||
if (!$ig) {
|
||||
$c .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
|
||||
$c .= '<html>
|
||||
<head>'."\n";
|
||||
$c .= ' <title>'.$title_prefix.(translation_exists($title)?_t($title):$title).'</title>'."\n";
|
||||
$c .= ' <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8" />'."\n";
|
||||
$c .= ryzom_render_header();
|
||||
$c .= ryzom_render_header_www();
|
||||
}
|
||||
$events = ON_IPHONE ? 'onorientationchange="updateOrientation();" ' : '';
|
||||
$c .= ' </head>'."\n";
|
||||
$c .= ' <body '.$events.'bgcolor="'.$bgcolor.'">'."\n";
|
||||
// Javascript
|
||||
$js_code = '';
|
||||
foreach ($javascript as $js)
|
||||
$js_code .= '<script type="text/javascript" src="'.$js.'"></script>';
|
||||
$c .= $js_code;
|
||||
|
||||
$events = ON_IPHONE ? 'onorientationchange="updateOrientation();" ' : '';
|
||||
|
||||
$c .= ' </head>'."\n";
|
||||
|
||||
$c .= ' <body '.$events.'bgcolor="'.$bgcolor.'">'."\n";
|
||||
|
||||
// Javascript
|
||||
$js_code = '';
|
||||
foreach ($javascript as $js)
|
||||
$js_code .= '<script type="text/javascript" src="'.$js.'"></script>';
|
||||
$c .= $js_code;
|
||||
|
||||
if (RYZOM_IG)
|
||||
$c .= $content;
|
||||
else{
|
||||
$c .= ryzom_render_www(ryzom_render_window($title, $content, $homeLink));
|
||||
$c .= '</body></html>';
|
||||
} else {
|
||||
$c .= '<html><body>';
|
||||
$c .= $content;
|
||||
$debug = ryLogger::getInstance()->getLogs();
|
||||
if ($debug)
|
||||
$c .= '<table width="100%"><tr bgcolor="#002200"><td>'.$debug.'</td></tr></table>';
|
||||
$c .= '</body></html>';
|
||||
}
|
||||
|
||||
$c .= '</body></html>';
|
||||
return $c;
|
||||
}
|
||||
|
||||
|
@ -140,7 +137,7 @@ function ryzom_render_window_begin($title, $homeLink=false) {
|
|||
return '
|
||||
<div class="ryzom-ui ryzom-ui-header">
|
||||
<div class="ryzom-ui-tl"><div class="ryzom-ui-tr">
|
||||
<div class="ryzom-ui-t">'.$title_prefix.(translation_exists($title)?_t($title):$title).$homeLink.'</div>
|
||||
<div class="ryzom-ui-t">'.(translation_exists($title)?_t($title):$title).$homeLink.'</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ryzom-ui-l"><div class="ryzom-ui-r"><div class="ryzom-ui-m">
|
||||
|
|
|
@ -25,12 +25,6 @@ if (!defined('ON_IPHONE')) {
|
|||
else
|
||||
define('ON_IPHONE', false);
|
||||
}
|
||||
if (!defined('RYZOM_IG')) {
|
||||
if (isset($_SERVER['HTTP_USER_AGENT']))
|
||||
define('RYZOM_IG', strpos($_SERVER['HTTP_USER_AGENT'], 'Ryzom'));
|
||||
else
|
||||
define('RYZOM_IG', false);
|
||||
}
|
||||
|
||||
$includes = array('auth', 'config', 'utils', 'user');
|
||||
|
||||
|
|
|
@ -23,8 +23,15 @@ function ryzom_authenticate_with_serverkey($cid, $name, $authserver, $authkey) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function ryzom_authenticate_ingame($cid, $name, $authkey) {
|
||||
return file_get_contents(RYAPI_AUTH_SCRIPT) == '1';
|
||||
function ryzom_authenticate_ingame($shardid, $cid, $name, $authkey) {
|
||||
$db = new ServerDatabase(RYAPI_NELDB_HOST, RYAPI_NELDB_LOGIN, RYAPI_NELDB_PASS, RYAPI_NELDB_RING);
|
||||
$uid = intval($cid / 16);
|
||||
$sql = "SELECT cookie FROM ring_users WHERE user_id = $uid";
|
||||
$row = $db->query_single_row($sql);
|
||||
|
||||
$rawkey = $shardid.$name.$cid.'\''.trim($row['cookie']).'\'';
|
||||
$md5rawkey = md5($rawkey);
|
||||
return $authkey == $md5rawkey;
|
||||
}
|
||||
|
||||
// take the character name and the account password and check if it's valid
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
define('RYAPI_SHARDID', '101');
|
||||
define('RYAPI_WEBDB_HOST', 'localhost');
|
||||
define('RYAPI_WEBDB_LOGIN', 'localhost');
|
||||
define('RYAPI_WEBDB_PASS', 'localhost');
|
||||
|
|
|
@ -29,6 +29,6 @@ else
|
|||
// Content
|
||||
$c = _t('access', $num_access['num_access']).'<br/>';
|
||||
|
||||
echo ryzom_app_render(APP_NAME, $c);
|
||||
echo ryzom_app_render(APP_NAME, $c, $user['ig']);
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
include_once('config.php');
|
||||
|
||||
include_once('lang.php');
|
||||
|
||||
// List of apps
|
||||
|
@ -9,7 +8,6 @@ $apps = array(
|
|||
'app_test',
|
||||
);
|
||||
|
||||
|
||||
$c = '';
|
||||
|
||||
// Ask to authenticate user (using ingame or session method) and fill $user with all information
|
||||
|
@ -17,7 +15,7 @@ $logged = ryzom_app_authenticate($user, false);
|
|||
if ($logged) {
|
||||
$c .= '<h1>'._t('welcome', $user['char_name']).'</h1>';
|
||||
} else {
|
||||
if (!RYZOM_IG) {
|
||||
if (!$user['ig']) {
|
||||
if ($user['message'])
|
||||
$c .= '<div style="text-align: center"><strong style="color: #FF5555">'._t($user['message']).'</strong></div><br />';
|
||||
$c .= ryzom_render_login_form(ryzom_get_param('name'));
|
||||
|
@ -28,8 +26,11 @@ foreach ($apps as $app) {
|
|||
$c .= '<a href="'.RYAPP_URL.'/'.$app.'/index.php"><img src="'.RYAPP_URL.'/'.$app.'/favicon.png" />'._t($app).'</a><br />';
|
||||
}
|
||||
|
||||
if($logged) $c .= '<br /><a href="'.RYAPP_URL.'/index.php?action=logout">'._t('logout').'</a>';
|
||||
if ($logged && !$user['ig'])
|
||||
$c .= '<br /><a href="'.RYAPP_URL.'/index.php?action=logout">'._t('logout').'</a>';
|
||||
|
||||
echo ryzom_app_render('Ryzom', $c);
|
||||
// Print GET values on debug view
|
||||
p($_GET);
|
||||
echo ryzom_app_render('Ryzom', $c, $user['ig']);
|
||||
|
||||
?>
|
Loading…
Reference in a new issue