Hi.
Posting this so maybe it helps others out. it's pretty basic.
<?php
//SL Class.9
//This class can pull info from SL headers.
//Currently for http_req
//TODO: Add Email header parsing when I have a few free mins... If someone else wants to, go ahead.
//I don't rely on SLEmail as much anymore, so it isn't a priority
//Find any bugs? Ways to make it better? Please share :)
//Max Case - July 8, 2006
class secondlife {
var $UserAgent;
var $UserAgentVersion;
var $Shard; //Production or Testing?
var $HostNumber;
var $Region;
var $LocalPos;
var $LocalRot;
var $LocalVel;
var $ObjectKey;
var $ObjectName;
var $OwnerKey;
var $OwnerName;
// Class constructor
function secondlife() {
}
// Returns class name
function GetClassName() {
return 'secondlife';
}
//This take in $_SERVER for args at the moment.
//Loads up all the vars.
function ParseHeaders($headers) {
foreach( $headers as $key => $value )
{
//Loop though values
if($key == "HTTP_USER_AGENT" ) //HTTP_USER_AGENT is Second Life LSL/1.10.0(32) (http://secondlife.com)
{
$this->SetUserAgent($value);
$this->SetUserAgentVersion($value);
}
else if($key == "HTTP_VIA")//HTTP_VIA is 1.1 sim480.agni.lindenlab.com:3128 (squid/2.5.STABLE9)
{
$this->SetHostNumber($value);
}
else if( strpos($key,"HTTP_X_SECONDLIFE_") !== false )
{
$temp = explode("HTTP_X_SECONDLIFE_", $key);
$headerinfo = $temp[1];
if($headerinfo == "LOCAL_POSITION")
{//Parse out ( ) in SetLocalPos
$this->SetLocalPos($value);
}
else if($headerinfo == "LOCAL_ROTATION")
{
$this->SetLocalRot($value);
}
else if($headerinfo == "LOCAL_VELOCITY")
{
$this->SetLocalVel($value);
}
else if($headerinfo == "OBJECT_KEY")
{
$this->SetObjectKey($value);
}
else if($headerinfo == "OBJECT_NAME")
{
$this->SetObjectName($value);
}
else if($headerinfo == "OWNER_KEY")
{
$this->SetOwnerKey($value);
}
else if($headerinfo == "OWNER_NAME")
{
$this->SetOwnerName($value);
}
else if($headerinfo == "REGION")
{
$this->SetRegion($value);
}
else if($headerinfo == "SHARD")
{
$this->SetShard($value);
}
}
}
}
function GetAll() {
return compact(
$this->UserAgent,
$this->UserAgentVersion,
$this->Shard, //Production or Testing?
$this->HostNumber,
$this->Region,
$this->RegionCorners,
$this->LocalPos,
$this->LocalRot,
$this->LocalVel,
$this->ObjectKey,
$this->ObjectName,
$this->OwnerKey,
$this->OwnerName
); //compact it all into array, return it
}
function GetUserAgent() {
return $this->UserAgent;
}
function GetUserAgentVersion() {
return $this->UserAgentVersion;
}
function GetShard() {
return $this->Shard;
}
function GetHostNumber() {
return $this->HostNumber;
}
function GetRegion() {
return $this->Region;
}
function GetLocalPos() {
return $this->LocalPos;
}
function GetLocalRot() {
return $this->LocalRot;
}
function GetLocalVel() {
return $this->LocalVel;
}
function GetObjectKey() {
return $this->ObjectKey;
}
function GetObjectName() {
return $this->ObjectName;
}
function GetOwnerKey() {
return $this->OwnerKey;
}
function GetOwnerName() {
return $this->OwnerName;
}
function SetUserAgent($UserAgent) {
$this->UserAgent = $UserAgent;
}
//Sets to 0 if Not SL
//Use that as indicator of SL or not sl?
//good for one script which can handle browser req's, or SL req's
function SetUserAgentVersion($UserAgentVersion)
{
if( strpos($UserAgentVersion,"Second Life") !== false )
{
if (preg_match("/LSL\/(.*)/", $UserAgentVersion, $matches))
{
$temp = explode("(", $matches[1]);
$ua_version = $temp[0];
}
$this->UserAgentVersion = $ua_version;
}
else
{
$this->UserAgentVersion = 0;
}
}
function SetShard($Shard) {
$this->Shard = $Shard;
}
function SetHostNumber($HostNumber)
{
if (preg_match("/sim(.*)/", $HostNumber, $matches))
{ //grab region_sim
$temp = explode(".", $matches[1]);
$region_sim_number = $temp[0];
}
$this->HostNumber = $region_sim_number;
}
function SetRegion($Region)
{
$foo = explode(' (', $Region, 2);
//explode region, and create world corner coords.
$temp = $this->burst_coords($this->remove_brackets( $foo[1] ));
$reg_corners = array();
$reg_corners['x'] = $temp[0];
$reg_corners['y'] = $temp[1];
$this->RegionCorners = $reg_corners;
$this->Region = $foo[0];
}
function SetLocalPos($LocalPos)
{
$temp = $this->burst_coords($this->remove_brackets( $LocalPos ));
$position = array();
$position['x'] = $temp[0];
$position['y'] = $temp[1];
$position['z'] = $temp[2];
$this->LocalPos = $position;
}
function SetLocalRot($LocalRot)
{ //returns x,y,z,w
$temp = $this->burst_coords($this->remove_brackets( $LocalRot ));
$rotation = array();
$rotation['x'] = $temp[0];
$rotation['y'] = $temp[1];
$rotation['z'] = $temp[2];
$rotation['w'] = $temp[3];
$this->LocalRot = $rotation;
}
function SetLocalVel($LocalVel)
{
$temp = $this->burst_coords($this->remove_brackets( $LocalVel ));
$velocity = array();
$velocity['x'] = $temp[0];
$velocity['y'] = $temp[1];
$velocity['z'] = $temp[2];
$this->LocalVel = $velocity;
}
function SetObjectKey($ObjectKey) {
$this->ObjectKey = $ObjectKey;
}
function SetObjectName($ObjectName) {
$this->ObjectName = $ObjectName;
}
function SetOwnerKey($OwnerKey) {
$this->OwnerKey = $OwnerKey;
}
function SetOwnerName($OwnerName) {
$this->OwnerName = $OwnerName;
}
//Little utility / string cleaner functions.
//This removes brackets, and spaces :>
function remove_brackets($foo)
{
return trim($foo, " ())");
}
function burst_coords($foo) //CSV ", "
{
return explode( ", ", $foo);
}
}
/* EXAMPLE */
/*
$testheader = array(
"HTTP_USER_AGENT"=>"Second Life LSL/1.10.0(32) (http://secondlife.com)",
"HTTP_VIA"=>"1.1 sim400.agni.lindenlab.com:3128 (squid/2.5.STABLE9)",
"HTTP_X_SECONDLIFE_LOCAL_POSITION"=>"(34.408112, 159.722198, 68.476143)",
"HTTP_X_SECONDLIFE_LOCAL_ROTATION"=>"(0.000000, 0.000000, 0.000000, 1.000000)",
"HTTP_X_SECONDLIFE_LOCAL_VELOCITY"=>"(0.000000, 0.000000, 0.000000)",
"HTTP_X_SECONDLIFE_OBJECT_KEY"=>"4d97ef9f-3e36-efe7-ffd5-c210a973ec1b",
"HTTP_X_SECONDLIFE_OBJECT_NAME"=>"Flagpole .5",
"HTTP_X_SECONDLIFE_OWNER_KEY"=>"6d869ee0-e19e-4afa-8431-b85705198a0c",
"HTTP_X_SECONDLIFE_OWNER_NAME"=>"Max Case",
"HTTP_X_SECONDLIFE_REGION"=>"Yoyo slsls (254720, 258048)",
"HTTP_X_SECONDLIFE_SHARD"=>"Production"
);
$sl = new secondlife; //Make the object
$sl->ParseHeaders($testheader);
print_r($sl->GetAll());
*/
?>