Talk:ConciergeModule

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(PHP script to use the Concierge Service)
 
m (PHP script to use the Concierge Service: - changed the status error code to bad request)
 
(One intermediate revision by one user not shown)
Line 11: Line 11:
 
define("LOG_FILENAME", "broker.log"); // define log file
 
define("LOG_FILENAME", "broker.log"); // define log file
  
$post_data = file_get_contents("php://input"); // get raw POST data (needed for XML)
+
// get raw POST data (needed for XML)
 +
 
 +
$post_data = file_get_contents('php://input');
 +
 
 
$avatars = simplexml_load_string($post_data); // convert to SimpleXMLObject
 
$avatars = simplexml_load_string($post_data); // convert to SimpleXMLObject
  
 
// DEBUG: make sure we're actually getting something!
 
// DEBUG: make sure we're actually getting something!
 
// error_log(sprintf("%s Region %s (%s) [DEBUG] - post data: %s\n", date("c"),  
 
// 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);
+
$_REQUEST['region'], $_REQUEST['UUID'], print_r($post_data, TRUE)), 3, LOG_FILENAME);
  
 
// check first if we actually got nicely parsed XML
 
// check first if we actually got nicely parsed XML
Line 34: Line 37:
 
error_log(sprintf("%s Region %s (%s) - Error parsing XML"), date("c"),  
 
error_log(sprintf("%s Region %s (%s) - Error parsing XML"), date("c"),  
 
$_REQUEST['region'], $_REQUEST['UUID']);
 
$_REQUEST['region'], $_REQUEST['UUID']);
echo "<error>No valid XML found</error>";  
+
header('HTTP/1.0 400 Bad Request');
 +
echo "<error>No valid XML found - got: '" . print_r($post_data, TRUE) . "'</error>";  
 
return false;
 
return false;
 
}
 
}
Line 43: Line 47:
 
?>
 
?>
 
</pre>
 
</pre>
 +
 +
[[User:Gwyneth Llewelyn|Gwyneth Llewelyn]] 10:48, 19 April 2013 (UTC)

Latest revision as of 03:48, 19 April 2013

[edit] 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