User:SignpostMarv Martin/PHP/lsl fu.php

From Second Life Wiki
Jump to navigation Jump to search

For an actually readable and color-coded version of the code below, click here

<?php
class lsl_processor
{
// this class is a part of SignpostMarv Martin's "UHU" codebase.
// All code is my own eccentricity, except for a slightly modified version of VeloxSeverine's $_POST fixer
	public static $headers;
	public static $llHTTPRequestPayload;
	public static $get;
	public static $post;
	public static $fixedPOST;
	function lsl_processor()
	{
		if(EXPLICIT_FIX_POST)
		{
			$_POST = lsl_processor::fix_post();
		}
		self::$headers = self::parse_llHTTPRequest_headers();
		self::$llHTTPRequestPayload = self::$get + lsl_processor::$post;
	}
	function parse_llHTTPRequest_headers()
	{
		$position_array = explode(', ',substr($_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION'],1,-1));
		$rotation_array = explode(', ',substr($_SERVER['HTTP_X_SECONDLIFE_LOCAL_ROTATION'],1,-1));
		$velocity_array = explode(', ',substr($_SERVER['HTTP_X_SECONDLIFE_LOCAL_VELOCITY'],1,-1));
		$position_of_left_bracket = strrpos($_SERVER['HTTP_X_SECONDLIFE_REGION'],'(');
		$region_name = trim(substr($_SERVER['HTTP_X_SECONDLIFE_REGION'],0,$position_of_left_bracket));
		list($global_x,$global_y) = explode(',',trim(substr($_SERVER['HTTP_X_SECONDLIFE_REGION'],$position_of_left_bracket + 1,-1)));
		$region_array = array($region_name,(integer)$global_x,(integer)$global_y);
		$headers = array('Accept'=>$_SERVER['HTTP_ACCEPT'],
			'User-Agent'=>$_SERVER['HTTP_USER_AGENT'],
			'X-SecondLife-Shard'=>$_SERVER['HTTP_X_SECONDLIFE_SHARD'],
			'X-SecondLife-Object-Name'=>$_SERVER['HTTP_X_SECONDLIFE_OBJECT_NAME'],
			'X-SecondLife-Object-Key'=>$_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY'],
			'X-SecondLife-Region'=>$_SERVER['HTTP_X_SECONDLIFE_REGION'],
			'X-SecondLife-Region-Array'=> $region_array,
			'X-SecondLife-Local-Position'=>array(	'x'=>(float)$position_array[0],
													'y'=>(float)$position_array[1],
													'z'=>(float)$position_array[2]),
			'X-SecondLife-Local-Rotation'=>array(	'x'=>(float)$rotation_array[0],
													'y'=>(float)$rotation_array[1],
													'z'=>(float)$rotation_array[2],
													'w'=>(float)$rotation_array[3]),
			'X-SecondLife-Local-Velocity'=>array(	'x'=>(float)$velocity_array[0],
													'y'=>(float)$velocity_array[1],
													'z'=>(float)$velocity_array[2]),
			'X-SecondLife-Owner-Name'=>$_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME'],
			'X-SecondLife-Owner-Key'=>$_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY']
		);
		if(!strstr($headers['X-SecondLife-Owner-Name'],' ') && $_POST['X-SecondLife-Owner-Name'])
		{
			$headers['X-SecondLife-Owner-Name'] == $_POST['X-SecondLife-Owner-Name'];
		}
		if(is_array($headers))
		{
			return $headers;
		}
		else
		{
			return FALSE;
		}
	}
	function fix_post()
	{
// Code by VeloxSeverine
//  http://lslwiki.net/lslwiki/wakka.php?wakka=llHTTPRequest&show_comments=1#comment
		$p_data = implode('', file('php://input'));
		$p_data = explode('&', $p_data);
		$fixedPOST = array();
		foreach ($p_data as $p_val)
		{
			$d_parts = explode('=', $p_val);
			$fixedPOST[$d_parts[0]] = urldecode($d_parts[1]);
		}
		return $fixedPOST;
	}
	function process_agent_info($agent_info)
	{			
		$always_run = (bool)($agent_info & AGENT_ALWAYS_RUN);
		$attachments = (bool)($agent_info & AGENT_ATTACHMENTS);
		$away = (bool)($agent_info & AGENT_AWAY);
		$busy = (bool)($agent_info & AGENT_BUSY);
		$crouching = (bool)($agent_info & AGENT_CROUCHING);
		$flying = (bool)($agent_info & AGENT_FLYING);
		$in_air = (bool)($agent_info & AGENT_IN_AIR);
		$mouselook = (bool)($agent_info & AGENT_MOUSELOOK);
		$on_object = (bool)($agent_info & AGENT_ON_OBJECT);
		$scripted = (bool)($agent_info & AGENT_SCRIPTED);
		$sitting = (bool)($agent_info & AGENT_SITTING);
		$typing = (bool)($agent_info & AGENT_TYPING);
		$walking = (bool)($agent_info & AGENT_WALKING);
		
		$info = array(	'always run'=>$always_run,
						'attachments'=>$attachments,
						'away'=>$away,
						'busy'=>$busy,
						'crouching'=>$crouching,
						'flying'=>$flying,
						'in air'=>$in_air,
						'mouselook'=>$mouselook,
						'on object'=>$on_object,
						'scripted'=>$scripted,
						'sitting'=>$sitting,
						'typing'=>$typing,
						'walking'=>$walking);
		foreach($info as $key => $val)
		{
			if($val == '')
			{
				$info[$key] = 0;
			}
		}
		return $info;
	}
}
?>