code modified to accept request through Rest and sending achievments in response
This commit is contained in:
parent
771070ab19
commit
1b5a6ec066
1 changed files with 139 additions and 91 deletions
|
@ -9,38 +9,12 @@ require_once('../config.php');
|
||||||
include_once( '../lang.php' );
|
include_once( '../lang.php' );
|
||||||
include_once( 'lang.php' );
|
include_once( 'lang.php' );
|
||||||
require_once( 'conf.php' );
|
require_once( 'conf.php' );
|
||||||
|
|
||||||
// Ask to authenticate user (using ingame or session method) and fill $user with all information
|
|
||||||
ryzom_app_authenticate($user, true);
|
|
||||||
|
|
||||||
#echo var_export($user,true);
|
|
||||||
|
|
||||||
#$user['id'] = $user['char_id'];
|
|
||||||
#$user['name'] = $user['char_name'];
|
|
||||||
|
|
||||||
/*$user = array();
|
|
||||||
$user['cid'] = 1;
|
|
||||||
$user['lang'] = 'en';
|
|
||||||
$user['name'] = 'Talvela';
|
|
||||||
$user['race'] = "r_matis";
|
|
||||||
$user['civilization'] = "c_neutral";
|
|
||||||
$user['cult'] = "c_neutral";
|
|
||||||
$user['ig'] = ($_REQUEST['ig']==1);
|
|
||||||
#$user['ig'] = true;*/
|
|
||||||
|
|
||||||
require_once( "class/RyzomUser_class.php" );
|
require_once( "class/RyzomUser_class.php" );
|
||||||
$_USER = new RyzomUser($user);
|
|
||||||
|
|
||||||
if($_USER->isIG()) {
|
|
||||||
require_once("include/ach_render_ig.php");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
require_once("include/ach_render_web.php");
|
|
||||||
}
|
|
||||||
require_once( "include/ach_render_common.php" );
|
require_once( "include/ach_render_common.php" );
|
||||||
|
|
||||||
require_once( "class/DLL_class.php" );
|
require_once( "class/DLL_class.php" );
|
||||||
#require_once("class/InDev_trait.php");
|
// require_once("class/InDev_trait.php");
|
||||||
require_once( "class/Node_abstract.php" );
|
require_once( "class/Node_abstract.php" );
|
||||||
require_once( "class/AVLTree_class.php" );
|
require_once( "class/AVLTree_class.php" );
|
||||||
require_once( "class/Parentum_abstract.php" );
|
require_once( "class/Parentum_abstract.php" );
|
||||||
|
@ -57,48 +31,122 @@ require_once("class/AchAchievement_class.php");
|
||||||
require_once( "class/AchTask_class.php" );
|
require_once( "class/AchTask_class.php" );
|
||||||
require_once( "class/AchObjective_class.php" );
|
require_once( "class/AchObjective_class.php" );
|
||||||
|
|
||||||
#require_once("fb/facebook.php");
|
|
||||||
|
|
||||||
// Update user acces on Db
|
// Update user acces on Db
|
||||||
#$DBc = ryDB::getInstance(APP_NAME."_test");
|
// $DBc = ryDB::getInstance(APP_NAME."_test");
|
||||||
$DBc = ryDB :: getInstance( APP_NAME );
|
$DBc = ryDB :: getInstance( APP_NAME );
|
||||||
|
|
||||||
|
|
||||||
|
// if getting request using REST
|
||||||
|
if ( isset( $_GET['search'] ) && isset( $_GET['format'] ) )
|
||||||
|
{
|
||||||
|
// if the format is json
|
||||||
|
if ( $_GET['format'] == 'json' )
|
||||||
|
{
|
||||||
|
// getting the headers when the request is sent
|
||||||
|
$header = getallheaders();
|
||||||
|
|
||||||
|
// this block is to get the posted data
|
||||||
|
$fp = fopen( 'php://input', 'r' );
|
||||||
|
$rawData = stream_get_contents( $fp );
|
||||||
|
$userd = json_decode( $rawData, true );
|
||||||
|
|
||||||
|
// authenticate the user using data we get from server
|
||||||
|
appAuthenticateRest( $user, $userd );
|
||||||
|
|
||||||
|
// create a ryzom user object whose achievements we have to send in response
|
||||||
|
$_USER = new RyzomUser( $user );
|
||||||
|
|
||||||
|
require_once( "include/ach_render_web.php" );
|
||||||
|
$c .= ach_render();
|
||||||
|
$response = $c;
|
||||||
|
// sending the response
|
||||||
|
echo( $response );
|
||||||
|
exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo 'Invalid response';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Ask to authenticate user (using ingame or session method) and fill $user with all information
|
||||||
|
ryzom_app_authenticate( $user, true );
|
||||||
|
|
||||||
|
|
||||||
|
// echo var_export($user,true);
|
||||||
|
// $user['id'] = $user['char_id'];
|
||||||
|
// $user['name'] = $user['char_name'];
|
||||||
|
/**
|
||||||
|
* $user = array();
|
||||||
|
* $user['cid'] = 1;
|
||||||
|
* $user['lang'] = 'en';
|
||||||
|
* $user['name'] = 'Talvela';
|
||||||
|
* $user['race'] = "r_matis";
|
||||||
|
* $user['civilization'] = "c_neutral";
|
||||||
|
* $user['cult'] = "c_neutral";
|
||||||
|
* $user['ig'] = ($_REQUEST['ig']==1);
|
||||||
|
* #$user['ig'] = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
$_USER = new RyzomUser( $user );
|
||||||
|
|
||||||
|
|
||||||
|
if ( $_USER -> isIG() ) {
|
||||||
|
require_once( "include/ach_render_ig.php" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
require_once( "include/ach_render_web.php" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// require_once("fb/facebook.php");
|
||||||
|
|
||||||
$c = "";
|
$c = "";
|
||||||
if ( !$_USER -> isIG() ) {
|
if ( !$_USER -> isIG() ) {
|
||||||
/*$facebook = new Facebook(array(
|
/**
|
||||||
'appId' => $_CONF['fb_id'],
|
* $facebook = new Facebook(array(
|
||||||
'secret' => $_CONF['fb_secret'],
|
* 'appId' => $_CONF['fb_id'],
|
||||||
'cookie' => true
|
* 'secret' => $_CONF['fb_secret'],
|
||||||
));
|
* 'cookie' => true
|
||||||
|
* ));
|
||||||
#code taken from facebook tutorial
|
*
|
||||||
|
* #code taken from facebook tutorial
|
||||||
// Get the url to redirect for login to facebook
|
*
|
||||||
// and request permission to write on the user's wall.
|
* // Get the url to redirect for login to facebook
|
||||||
$login_url = $facebook->getLoginUrl(
|
* // and request permission to write on the user's wall.
|
||||||
array('scope' => 'publish_stream')
|
* $login_url = $facebook->getLoginUrl(
|
||||||
);
|
* array('scope' => 'publish_stream')
|
||||||
|
* );
|
||||||
// If not authenticated, redirect to the facebook login dialog.
|
*
|
||||||
// The $login_url will take care of redirecting back to us
|
* // If not authenticated, redirect to the facebook login dialog.
|
||||||
// after successful login.
|
* // The $login_url will take care of redirecting back to us
|
||||||
if (! $facebook->getUser()) {
|
* // after successful login.
|
||||||
$c .= '<script type="text/javascript">
|
* if (! $facebook->getUser()) {
|
||||||
top.location.href = "'.$login_url.'";
|
* $c .= '<script type="text/javascript">
|
||||||
</script>;';
|
* top.location.href = "'.$login_url.'";
|
||||||
}
|
* </script>;';
|
||||||
else {
|
* }
|
||||||
$DBc->sqlQuery("INSERT INTO ach_fb_token (aft_player,aft_token,aft_date,aft_allow) VALUES ('".$_USER->getID()."','".$DBc->sqlEscape($facebook->getAccessToken())."','".time()."','1') ON DUPLICATE KEY UPDATE aft_token='".$DBc->sqlEscape($facebook->getAccessToken())."', aft_date='".time()."'");
|
* else {
|
||||||
}*/
|
* $DBc->sqlQuery("INSERT INTO ach_fb_token (aft_player,aft_token,aft_date,aft_allow) VALUES ('".$_USER->getID()."','".$DBc->sqlEscape($facebook->getAccessToken())."','".time()."','1') ON DUPLICATE KEY UPDATE aft_token='".$DBc->sqlEscape($facebook->getAccessToken())."', aft_date='".time()."'");
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$_USER -> isIG && $_CONF['enable_webig'] == false ) {
|
if ( !$_USER -> isIG && $_CONF['enable_webig'] == false ) {
|
||||||
$c .= ach_render_forbidden( false );
|
$c .= ach_render_forbidden( false );
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif ( $_USER -> isIG && $_CONF['enable_offgame'] == false ) {
|
elseif ( $_USER -> isIG && $_CONF['enable_offgame'] == false ) {
|
||||||
$c .= ach_render_forbidden( true );
|
$c .= ach_render_forbidden( true );
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$c .= ach_render();
|
$c .= ach_render();
|
||||||
|
|
Loading…
Reference in a new issue