From d583b2cd8e87b52fd0cd1b554f4f681819f6cf90 Mon Sep 17 00:00:00 2001
From: Quitta
Date: Sat, 7 Sep 2013 04:12:47 +0200
Subject: [PATCH] Ingame version works now too more or less
--HG--
branch : quitta-gsoc-2013
---
.../ryzommanage/autoload/webusers.php | 24 +---
.../drupal_module/ryzommanage/config.php | 7 +-
.../drupal_module/ryzommanage/func/login.php | 36 +++++
.../ryzommanage/inc/dashboard.php | 2 +
.../drupal_module/ryzommanage/inc/login.php | 21 +++
.../drupal_module/ryzommanage/inc/logout.php | 6 +
.../ryzommanage/inc/show_ticket_info.php | 4 +-
.../ryzommanage/ryzommanage.module | 132 ++++++++++++++++--
.../ryzommanage/templates/show_ticket.tpl | 2 +-
.../templates/show_ticket_info.tpl | 32 ++---
.../ryzom_ams/www/html/inc/dashboard.php | 3 +-
11 files changed, 216 insertions(+), 53 deletions(-)
create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/func/login.php
create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/login.php
create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/logout.php
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php
index 73d0b79a0..779414de3 100644
--- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php
@@ -57,17 +57,11 @@ class WebUsers extends Users{
* @return string Info: Returns true or false if a login match is found in the web db
*/
public function checkLoginMatch($username,$password){
- $dbw = new DBLayer("web");
- $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username));
- $row = $statement->fetch();
-
- $salt = substr($row['Password'],0,2);
- $hashed_input_pass = crypt($password, $salt);
- if($hashed_input_pass == $row['Password']){
- return $row;
- }else{
- return "fail";
- }
+ if(!user_authenticate($username, $password)){
+ return 'fail';
+ }else{
+ return db_query("SELECT * FROM {users} WHERE name = :name", array(':name' => $username))->fetchAssoc();
+ }
}
//returns te id for a given username
@@ -132,13 +126,7 @@ class WebUsers extends Users{
}
public function getLanguage(){
- $dbw = new DBLayer("web");
- if(! isset($this->language) || $this->language == ""){
- $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
- $row = $statement->fetch();
- $this->set($row);
- }
- return $this->language;
+ return $DEFAULT_LANGUAGE;
}
public function isLoggedIn(){
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php
index ad9a05462..7723032f8 100644
--- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/config.php
@@ -73,7 +73,11 @@ $AMS_LIB = dirname( __FILE__ ) . '/ams_lib';
$AMS_TRANS = $AMS_LIB . '/translations';
$AMS_CACHEDIR = $AMS_LIB . '/cache';
$SITEBASE = dirname( __FILE__ );
-$WEBPATH ='http://localhost:40917/drupal/sites/all/modules/ryzommanage/' ;
+$BASE_WEBPATH = 'http://localhost:40917/drupal';
+$IMAGELOC_WEBPATH = $BASE_WEBPATH. '/sites/all/modules/ryzommanage/' ;
+$WEBPATH = $BASE_WEBPATH .'/ams';
+$INGAME_WEBPATH = $BASE_WEBPATH . '/ingame';
+$CONFIG_PATH = dirname( __FILE__ );
//defines the default language
$DEFAULT_LANGUAGE = 'en';
@@ -88,3 +92,4 @@ $TIME_FORMAT = "m-d-Y H:i:s";
$INGAME_LAYOUT = "basic";
+
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/func/login.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/func/login.php
new file mode 100644
index 000000000..2731de130
--- /dev/null
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/func/login.php
@@ -0,0 +1,36 @@
+getLanguage();
+
+ //go back to the index page.
+ header( 'Location: '. $INGAME_WEBPATH );
+ exit;
+ }else{
+ //handle login failure
+ $result = Array();
+ $result['login_error'] = 'TRUE';
+ $result['no_visible_elements'] = 'TRUE';
+ helpers :: loadtemplate( 'login', $result);
+ exit;
+ }
+
+
+ }catch (PDOException $e) {
+ //go to error page or something, because can't access website db
+ print_r($e);
+ exit;
+ }
+
+}
\ No newline at end of file
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/dashboard.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/dashboard.php
index 6d0ef5faf..74475dcd1 100644
--- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/dashboard.php
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/dashboard.php
@@ -15,6 +15,8 @@ function dashboard(){
$result['newestTicketId'] = $ticket->getTId();
$result['newestTicketTitle'] = $ticket->getTitle();
$result['newestTicketAuthor'] = Ticket_User::get_username_from_id($ticket->getAuthor());
+ global $INGAME_WEBPATH;
+ $result['ingame_webpath'] = $INGAME_WEBPATH;
return $result;
}else{
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/login.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/login.php
new file mode 100644
index 000000000..fca774ddc
--- /dev/null
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/inc/login.php
@@ -0,0 +1,21 @@
+getHT();
$result['nel3d'] = $ticket_info->getNel3D();
$result['user_id'] = $ticket_info->getUser_Id();
- global $WEBPATH;
- $result['WEBPATH'] = $WEBPATH;
+ global $IMAGELOC_WEBPATH;
+ $result['IMAGELOC_WEBPATH'] = $IMAGELOC_WEBPATH;
if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
$result['isMod'] = "TRUE";
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module
index 04bdefb14..7249aded2 100644
--- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module
@@ -22,10 +22,15 @@ global $cfg;
global $TICKET_LOGGING;
global $TIME_FORMAT;
global $TICKET_MAILING_SUPPORT;
+global $IMAGELOC_WEBPATH;
global $WEBPATH;
+global $INGAME_WEBPATH;
+global $BASE_WEBPATH;
+global $INGAME_LAYOUT;
require 'ams_lib/libinclude.php';
spl_autoload_register('__autoload');
+
require 'config.php';
/*
@@ -132,6 +137,15 @@ function ryzommanage_menu()
'type' => MENU_NORMAL_ITEM
);
+ $items['ingame'] = array(
+ 'title' => 'Ingame AMS',
+ 'page callback' => '_collect_ingame_ams',
+ 'page arguments' => array(1, 2),
+ 'access callback' => 'user_access',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK
+ );
+
//main menu item
$items['admin/config/ryzommanage'] = array(
'title' => 'Ryzom Server Integration',
@@ -256,7 +270,7 @@ function ryzommanage_block_view($delta = '')
function _ams_handler()
{
-
+ global $BASE_WEBPATH;
//Decide what page to load
if ( ! isset( $_GET["page"]) ){
if(isset($_SESSION['user'])){
@@ -267,7 +281,7 @@ function _ams_handler()
}
}else{
//default page
- header("Location: user/login");
+ header("Location: ".$BASE_WEBPATH."/user/login");
exit;
}
}else{
@@ -333,11 +347,99 @@ function _collect_register($nids, $collection)
return_client_httpdata();
} else {
//redirect to registration page
- header("Location: user/register");
+ header("Location: ".$BASE_WEBPATH. "/user/register");
}
}
+
+/**
+ *
+ * Function _collect_register
+ *
+ * @takes
+ * @return Nothing
+ *
+ * Info: Determins what to send back to client, if the client is ryzom core then send the http data if its a browser send to /
+ *
+ */
+function _collect_ingame_ams($nids, $collection)
+{
+ //if not using ryzom core client show registration page
+ if (Helpers::check_if_game_client(true)) {
+ _return_ingame_httpdata();
+ } else {
+ //redirect to registration page
+ global $WEBPATH;
+ header("Location: ". $WEBPATH);
+ }
+}
+
+
+function _return_ingame_httpdata(){
+
+ //Decide what page to load
+ if ( ! isset( $_GET["page"]) ){
+ if(isset($_SESSION['user'])){
+ if(Ticket_User::isMod(unserialize($_SESSION['ticket_user']))){
+ $page = 'dashboard';
+ }else{
+ $page = 'show_user';
+ }
+ }else{
+ //default page
+ $page = 'login';
+ }
+ }else{
+ $page = $_GET["page"];
+ }
+
+ //perform an action in case one is specified
+ //else check if a php page is included in the inc folder, else just set page to the get param
+ global $SITEBASE;
+ if ( isset( $_POST["function"] ) ){
+ $filename = $SITEBASE.'/func/' . $_POST["function"] . '.php';
+ if(is_file($filename)){
+ require($filename);
+ $return = $_POST["function"]();
+ }
+ }else{
+
+ $filename = $SITEBASE.'/inc/' . $page . '.php';
+ if(is_file($filename)){
+ require_once($filename);
+ $return = $page();
+ }
+ }
+
+ //add username to the return array in case logged in.
+ if(isset($_SESSION['user'])){
+ $return['username'] = $_SESSION['user'];
+ }
+
+ //Set permission
+ if(isset($_SESSION['ticket_user'])){
+ $return['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
+ }else{
+ //default permission
+ $return['permission'] = 0;
+ }
+
+ //hide sidebar + topbar in case of login/register
+ if($page == 'login' || $page == 'register' || $page == 'logout'){
+ $return['no_visible_elements'] = 'TRUE';
+ }else{
+ $return['no_visible_elements'] = 'FALSE';
+ }
+
+ //handle error page
+ if($page == 'error'){
+ $return['permission'] = 0;
+ $return['no_visible_elements'] = 'FALSE';
+ }
+
+ helpers :: loadTemplate( $page , $return );
+}
/**
*
* Function _collect_register
@@ -350,6 +452,8 @@ function _collect_register($nids, $collection)
*/
function _collect_login($nids, $collection)
{
+ global $WEBPATH;
+ global $BASE_WEBPATH;
$result = Helpers::check_login_ingame();
if ($result != "FALSE") {
//handle successful ingame login
@@ -364,10 +468,10 @@ function _collect_login($nids, $collection)
$user->timezone = $account->timezone;
user_login_finalize();
}
- header( 'Location: ams' );
+ header( 'Location: '.$WEBPATH );
} else {
//redirect to registration page
- header("Location: user/login");
+ header("Location: ".$BASE_WEBPATH."/user/login");
}
}
@@ -550,21 +654,23 @@ function login_form($login_form)
function top_bar()
{
global $user;
+ global $WEBPATH;
+ global $BASE_WEBPATH;
$userId = $user->uid;
if (user_is_logged_in()) {
// Logged in user
//check permission, if user
if(ticket_user::isMod(unserialize($_SESSION['ticket_user']))){
- return "";
+ return "";
}else{
- return "";
+ return "";
}
} else {
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket.tpl b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket.tpl
index c9d8c854b..5a4963795 100644
--- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket.tpl
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket.tpl
@@ -119,7 +119,7 @@
{if $reply.permission eq '1'}
{if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if}
{else if $reply.permission gt '1'}
- {if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if}
+ {if isset($isMod) and $isMod eq "TRUE"} {$reply.author}{else} {$reply.author} {/if}
{/if}
{if $reply.hidden eq 1}{/if}{$reply.replyContent}{if $reply.hidden eq 1}{/if}
diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl
index 6437c3f23..04384009e 100644
--- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl
+++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/templates/show_ticket_info.tpl
@@ -16,61 +16,61 @@
Ingame related |
- Shard ID: {$shard_id} |
+ Shard ID: {$shard_id} |
- User_Id: {$user_id} |
+ User_Id: {$user_id} |
- User Position: {$user_position} |
+ User Position: {$user_position} |
- View Position: {$view_position} |
+ View Position: {$view_position} |
- Client_Version: {$client_version} |
+ Client_Version: {$client_version} |
- Patch_Version: {$patch_version} |
+ Patch_Version: {$patch_version} |
- Server_Tick: {$server_tick} |
+ Server_Tick: {$server_tick} |
Hardware & Software related |
- Memory: {$memory} |
+ Memory: {$memory} |
- Processor: {$processor} |
+ Processor: {$processor} |
- Cpu_Id: {$cpu_id} |
+ Cpu_Id: {$cpu_id} |
- Cpu_Mask: {$cpu_mask} |
+ Cpu_Mask: {$cpu_mask} |
- HT: {$ht} |
+ HT: {$ht} |
- OS: {$os} |
+ OS: {$os} |
- NeL3D: {$nel3d} |
+ NeL3D: {$nel3d} |
Network related |
- Connect_State: {$connect_state} |
+ Connect_State: {$connect_state} |
- Local_Address: {$local_address} |
+ Local_Address: {$local_address} |
diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/dashboard.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/dashboard.php
index 752156c6c..980da3cb1 100644
--- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/dashboard.php
+++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/dashboard.php
@@ -1,8 +1,7 @@