Source for file sl_send_object_linker.php
Documentation is available at sl_send_object_linker.php
* Sloodle object distribution linker script.
* Can be called by scripts to request in-world distribution of objects.
* @package sloodledistrib
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @contributor Edmund Edgar
* @contributor Peter R. Bloomfield
// This script should only be accessed by a browser (a script linker version can be found at "sl_send_object_linker.php")
// There are two modes: query and sendobject.
// The following parameters are required:
// sloodlepwd = prim password for authenticating the request
// sloodlecmd = indicates what action should be carried out (can be 'query' or 'sendobject')
// The following parameters are required if 'sloodlecmd' is set to 'sendobject':
// sloodleuuid = UUID of avatar to whom to send an object (NOTE: avatar does NOT need to be in the Sloodle database to use this!)
// sloodleavname = name of avatar to whom to send an object (NOTE: avatar DOES need to be in the Sloodle database to use this!)
// sloodleobject = name of the object to send
// In 'query' mode, this script will return a list of the names of all objects available for distribution.
// Success status code is 1. Each object name will be on its own line following the status line, e.g.:
// Sloodle Toolbar v1.2 (customizable)
// Sloodle Toolbar v1.2 (sloodle.org)
// NOTE: if not objects are available, then success code 1 is still returned, but no objects are listed in the data lines.
// In 'sendobject' mode, this script will return status code 1 if successful.
// There will be a single data line containing the name of the sent object.
// The status line will contain the UUID of the avatar to whom the object was sent.
// If the requested object is not listed in the database, then -812 is returned.
// If the distribution channel cannot be found, then status code -103 is returned.
// If the object distribution fails (e.g. the XML-RPC could not connect) then -105 is returned.
// If the 'sloodlecmd' value is not recognised, then -811 is returned.
require_once('../config.php');
require_once(SLOODLE_DIRROOT.
'/sl_debug.php');
require_once(SLOODLE_DIRROOT.
'/lib/sl_lsllib.php');
// Construct the LSL handler, and process the basic request data
$lsl->request->process_request_data();
// Ensure the request is authenticated
$lsl->request->authenticate_request();
// Fetch other additional parameters
$sloodlecmd =
$lsl->request->required_param('sloodlecmd', PARAM_RAW);
$sloodleobject =
optional_param('sloodleobject', NULL, PARAM_RAW);
// Make sure the command is recognised
if ($sloodlecmd !=
'query' &&
$sloodlecmd !=
'sendobject') {
$lsl->response->quick_output(-
811, "DISTRIB", "Parameter 'sloodlecmd' gave unrecognised script mode: '$sloodlecmd'", FALSE);
// Fetch the key for the XMLRPC channel
if (($distribchannel ==
NULL) ||
($distribchannel ==
'') ||
($distribchannel ==
FALSE)) {
$lsl->response->quick_output(-
103, "DISTRIB", "XML-RPC distribution channel not found in database.", FALSE);
// Fetch the list of objects
// No objects available - check which mode we're in to determine our response
if ($sloodlecmd ==
'query') {
$lsl->response->quick_output(1, "DISTRIB", "", FALSE);
$lsl->response->quick_output(-
812, "DISTRIB", "No objects available for distribution.", FALSE);
sort($distribobjects, SORT_STRING);
// What command was specified?
$lsl->response->set_status_code(1);
$lsl->response->set_status_descriptor("DISTRIB");
// Go through each distribution object, and add it as a data line
foreach($distribobjects as $obj) {
$lsl->response->add_data_line($obj);
// Send an object to the specified user
// Was the UUID ommitted?
if ($lsl->request->get_avatar_uuid() ==
NULL) {
// Yes - make sure the avatar name was specified
if ($lsl->request->get_avatar_name() ==
NULL) {
$lsl->response->quick_output(-
311, "USER_AUTH", "Neither the avatar name or UUID were specified.", FALSE);
// The request object would have found the matching UUID when asked to process data. The user is obviously not in the database.
$lsl->response->quick_output(-
321, "USER_AUTH", "Failed to find named avatar in Moodle database.", FALSE);
// Make sure the object was specified
$lsl->request->required_param('sloodleobject', PARAM_RAW);
// Make sure it was found in the object list
if (array_search($sloodleobject, $distribobjects) ===
FALSE) {
$lsl->response->quick_output(-
812, "DISTRIB", "Requested object not available for distribution.", FALSE);
// Construct our XML-RPC data message
$response->set_status_code(1);
$response->set_status_descriptor('OK');
$response->add_data_line(array('SENDOBJECT', $lsl->request->get_avatar_uuid(), $sloodleobject));
// Render it to a string so we can send it
$response->render_to_string($str);
$str =
str_replace("\n", "\\n", $str); // Ugly hack to stop the newline character disappearing before it reaches SL
$lsl->response->set_status_code(1);
$lsl->response->set_status_descriptor("DISTRIB");
$lsl->response->add_data_line($sloodleobject);
$lsl->response->set_status_code(-
105);
$lsl->response->set_status_descriptor("DISTRIB");
$lsl->response->add_data_line("XML-RPC distribution failed.");
$lsl->response->render_to_output();
Documentation generated on Tue, 04 Mar 2008 15:08:54 +0000 by phpDocumentor 1.4.0