Talk:ConciergeModule

From OpenSimulator

Revision as of 02:48, 19 April 2013 by Gwyneth Llewelyn (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PHP script to use the Concierge Service

The OpenSim team has included a Python script to test the Concierge Service.

Here is something very simple done in PHP to accomplish pretty much the same: it writes to a log file what avatars are in a region (and its UUIDs) when someone teleports in or out. If the region is left empty, this will also say so.

Notice the nasty trick to capture raw POST data (or else, you won't get any XML). The SimpleXML module is required, but it should be built-in on pretty much every PHP installation.

<?php
	define("LOG_FILENAME", "broker.log");	// define log file

// get raw POST data (needed for XML)

	$post_data = file_get_contents('php://input');

	$avatars = simplexml_load_string($post_data);	// convert to SimpleXMLObject

	// DEBUG: make sure we're actually getting something!
	// error_log(sprintf("%s Region %s (%s) [DEBUG] - post data: %s\n", date("c"), 
				$_REQUEST['region'], $_REQUEST['UUID'], print_r($post_data, TRUE)), 3, LOG_FILENAME);

	// check first if we actually got nicely parsed XML
	if ($avatars) {
		if ($avatars['count'] != 0) {	// attribute "count" should give us how many avatars we have
			foreach ($avatars as $avatar) {	// parse name and UUID; each comes as attribute 
				error_log(sprintf("%s Region %s (%s) - %s (%s)\n", date("c"), 
					$_REQUEST['region'], $_REQUEST['UUID'], $avatar['name'], $avatar['uuid']), 3, LOG_FILENAME);
			}
		}
		else { // this means that no more avatars are left on this region
			error_log(sprintf("%s Region %s (%s) - No avatars left"), date("c"), 
					$_REQUEST['region'], $_REQUEST['UUID']);
		}
	}	
	else {	// error parsing XML
		error_log(sprintf("%s Region %s (%s) - Error parsing XML"), date("c"), 
					$_REQUEST['region'], $_REQUEST['UUID']);
		header('HTTP/1.0 400 Bad Request');
		echo "<error>No valid XML found - got: '" . print_r($post_data, TRUE) . "'</error>"; 
		return false;
	}
	
	echo "<success/>"; // allegedly this is what we have to pass back to OpenSim
				
	return true; // who knows if this is useful or not
?>

Gwyneth Llewelyn 10:48, 19 April 2013 (UTC)

Personal tools
General
About This Wiki