2008-05-30 12:27:06 +00:00
/ *
* Copyright ( c ) Contributors , http : //opensimulator.org/
* See CONTRIBUTORS . TXT for a full list of copyright holders .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
2009-06-01 06:37:14 +00:00
* * Neither the name of the OpenSimulator Project nor the
2008-05-30 12:27:06 +00:00
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ` ` AS IS ' ' AND ANY
* EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
* LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
2009-01-23 17:07:37 +00:00
2008-05-30 12:27:06 +00:00
using System ;
2008-09-18 16:53:26 +00:00
using System.Collections ;
2008-09-15 15:36:51 +00:00
using System.Collections.Generic ;
2011-08-09 02:51:34 +00:00
using System.IO ;
using System.Reflection ;
2008-07-11 17:52:39 +00:00
using System.Runtime.Remoting.Lifetime ;
2008-11-06 09:12:14 +00:00
using System.Text ;
2009-02-26 22:37:02 +00:00
using System.Net ;
2009-08-21 05:12:50 +00:00
using System.Threading ;
2011-08-09 02:51:34 +00:00
using System.Xml ;
using log4net ;
2008-09-06 07:52:41 +00:00
using OpenMetaverse ;
2011-08-09 02:51:34 +00:00
using OpenMetaverse.StructuredData ;
2008-05-30 12:27:06 +00:00
using Nini.Config ;
2008-10-03 01:30:22 +00:00
using OpenSim ;
2008-11-04 20:48:35 +00:00
using OpenSim.Framework ;
2010-01-11 15:51:33 +00:00
2008-05-30 12:27:06 +00:00
using OpenSim.Framework.Console ;
2009-02-06 16:55:34 +00:00
using OpenSim.Region.Framework.Interfaces ;
using OpenSim.Region.Framework.Scenes ;
2009-02-04 00:01:36 +00:00
using OpenSim.Region.ScriptEngine.Shared ;
using OpenSim.Region.ScriptEngine.Shared.Api.Plugins ;
2008-06-24 21:09:49 +00:00
using OpenSim.Region.ScriptEngine.Shared.ScriptBase ;
using OpenSim.Region.ScriptEngine.Interfaces ;
using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces ;
2008-09-15 14:32:02 +00:00
using TPFlags = OpenSim . Framework . Constants . TeleportFlags ;
2009-09-26 14:48:21 +00:00
using OpenSim.Services.Interfaces ;
using GridRegion = OpenSim . Services . Interfaces . GridRegion ;
2009-02-16 01:58:26 +00:00
using System.Text.RegularExpressions ;
2008-05-30 12:27:06 +00:00
2008-11-04 20:48:35 +00:00
using LSL_Float = OpenSim . Region . ScriptEngine . Shared . LSL_Types . LSLFloat ;
using LSL_Integer = OpenSim . Region . ScriptEngine . Shared . LSL_Types . LSLInteger ;
using LSL_Key = OpenSim . Region . ScriptEngine . Shared . LSL_Types . LSLString ;
using LSL_List = OpenSim . Region . ScriptEngine . Shared . LSL_Types . list ;
using LSL_Rotation = OpenSim . Region . ScriptEngine . Shared . LSL_Types . Quaternion ;
using LSL_String = OpenSim . Region . ScriptEngine . Shared . LSL_Types . LSLString ;
using LSL_Vector = OpenSim . Region . ScriptEngine . Shared . LSL_Types . Vector3 ;
2008-10-03 01:30:22 +00:00
2008-06-24 21:09:49 +00:00
namespace OpenSim.Region.ScriptEngine.Shared.Api
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
//////////////////////////////////////////////////////////////
/ /
// Level description
/ /
// None - Function is no threat at all. It doesn't constitute
// an threat to either users or the system and has no
// known side effects
/ /
// Nuisance - Abuse of this command can cause a nuisance to the
// region operator, such as log message spew
/ /
// VeryLow - Extreme levels ob abuse of this function can cause
// impaired functioning of the region, or very gullible
// users can be tricked into experiencing harmless effects
/ /
// Low - Intentional abuse can cause crashes or malfunction
// under certain circumstances, which can easily be rectified,
// or certain users can be tricked into certain situations
// in an avoidable manner.
/ /
// Moderate - Intentional abuse can cause denial of service and crashes
// with potential of data or state loss, or trusting users
// can be tricked into embarrassing or uncomfortable
// situationsa.
/ /
// High - Casual abuse can cause impaired functionality or temporary
// denial of service conditions. Intentional abuse can easily
// cause crashes with potential data loss, or can be used to
// trick experienced and cautious users into unwanted situations,
// or changes global data permanently and without undo ability
2009-08-07 23:53:34 +00:00
// Malicious scripting can allow theft of content
2008-09-15 15:25:48 +00:00
/ /
// VeryHigh - Even normal use may, depending on the number of instances,
// or frequency of use, result in severe service impairment
// or crash with loss of data, or can be used to cause
// unwanted or harmful effects on users without giving the
// user a means to avoid it.
/ /
// Severe - Even casual use is a danger to region stability, or function
// allows console or OS command execution, or function allows
// taking money without consent, or allows deletion or
// modification of user data, or allows the compromise of
// sensitive data by design.
2010-05-30 13:46:54 +00:00
class FunctionPerms
{
public List < UUID > AllowedCreators ;
public List < UUID > AllowedOwners ;
2011-10-26 13:03:10 +00:00
public List < string > AllowedOwnerClasses ;
2010-05-30 13:46:54 +00:00
public FunctionPerms ( )
{
AllowedCreators = new List < UUID > ( ) ;
AllowedOwners = new List < UUID > ( ) ;
2011-10-26 13:03:10 +00:00
AllowedOwnerClasses = new List < string > ( ) ;
2010-05-30 13:46:54 +00:00
}
}
2008-05-30 12:27:06 +00:00
[Serializable]
2008-06-24 21:09:49 +00:00
public class OSSL_Api : MarshalByRefObject , IOSSL_Api , IScriptApi
2008-05-30 12:27:06 +00:00
{
2011-08-09 02:51:34 +00:00
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
2008-11-08 02:24:34 +00:00
internal IScriptEngine m_ScriptEngine ;
2009-08-07 18:50:47 +00:00
internal ILSL_Api m_LSL_Api = null ; // get a reference to the LSL API so we can call methods housed there
2008-05-30 12:27:06 +00:00
internal SceneObjectPart m_host ;
internal uint m_localID ;
2008-09-06 07:52:41 +00:00
internal UUID m_itemID ;
2008-09-15 15:25:48 +00:00
internal bool m_OSFunctionsEnabled = false ;
internal ThreatLevel m_MaxThreatLevel = ThreatLevel . VeryLow ;
2008-09-15 14:32:02 +00:00
internal float m_ScriptDelayFactor = 1.0f ;
internal float m_ScriptDistanceFactor = 1.0f ;
2010-05-30 13:46:54 +00:00
internal Dictionary < string , FunctionPerms > m_FunctionPerms = new Dictionary < string , FunctionPerms > ( ) ;
2008-05-30 12:27:06 +00:00
2008-11-08 02:24:34 +00:00
public void Initialize ( IScriptEngine ScriptEngine , SceneObjectPart host , uint localID , UUID itemID )
2008-05-30 12:27:06 +00:00
{
2008-06-24 21:09:49 +00:00
m_ScriptEngine = ScriptEngine ;
2008-05-30 12:27:06 +00:00
m_host = host ;
m_localID = localID ;
m_itemID = itemID ;
2009-02-04 00:01:36 +00:00
2008-09-15 15:25:48 +00:00
if ( m_ScriptEngine . Config . GetBoolean ( "AllowOSFunctions" , false ) )
m_OSFunctionsEnabled = true ;
m_ScriptDelayFactor =
m_ScriptEngine . Config . GetFloat ( "ScriptDelayFactor" , 1.0f ) ;
m_ScriptDistanceFactor =
m_ScriptEngine . Config . GetFloat ( "ScriptDistanceLimitFactor" , 1.0f ) ;
string risk = m_ScriptEngine . Config . GetString ( "OSFunctionThreatLevel" , "VeryLow" ) ;
switch ( risk )
{
case "None" :
m_MaxThreatLevel = ThreatLevel . None ;
break ;
case "VeryLow" :
m_MaxThreatLevel = ThreatLevel . VeryLow ;
break ;
case "Low" :
m_MaxThreatLevel = ThreatLevel . Low ;
break ;
case "Moderate" :
m_MaxThreatLevel = ThreatLevel . Moderate ;
break ;
case "High" :
m_MaxThreatLevel = ThreatLevel . High ;
break ;
case "VeryHigh" :
m_MaxThreatLevel = ThreatLevel . VeryHigh ;
break ;
case "Severe" :
m_MaxThreatLevel = ThreatLevel . Severe ;
break ;
default :
break ;
}
2008-05-30 12:27:06 +00:00
}
2008-07-11 17:52:39 +00:00
public override Object InitializeLifetimeService ( )
{
ILease lease = ( ILease ) base . InitializeLifetimeService ( ) ;
if ( lease . CurrentState = = LeaseState . Initial )
{
2009-08-14 13:18:56 +00:00
lease . InitialLeaseTime = TimeSpan . FromMinutes ( 0 ) ;
// lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
// lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
2008-07-11 17:52:39 +00:00
}
return lease ;
}
2008-05-30 12:27:06 +00:00
2008-09-15 15:25:48 +00:00
public Scene World
{
get { return m_ScriptEngine . World ; }
}
internal void OSSLError ( string msg )
{
throw new Exception ( "OSSL Runtime Error: " + msg ) ;
}
2009-08-07 18:50:47 +00:00
private void InitLSL ( )
{
if ( m_LSL_Api ! = null )
return ;
m_LSL_Api = ( ILSL_Api ) m_ScriptEngine . GetApi ( m_itemID , "LSL" ) ;
}
2009-04-27 12:05:49 +00:00
/ /
//Dumps an error message on the debug console.
/ /
2009-11-12 19:42:35 +00:00
internal void OSSLShoutError ( string message )
2009-04-27 12:05:49 +00:00
{
if ( message . Length > 1023 )
message = message . Substring ( 0 , 1023 ) ;
World . SimChat ( Utils . StringToBytes ( message ) ,
ChatTypeEnum . Shout , ScriptBaseClass . DEBUG_CHANNEL , m_host . ParentGroup . RootPart . AbsolutePosition , m_host . Name , m_host . UUID , true ) ;
IWorldComm wComm = m_ScriptEngine . World . RequestModuleInterface < IWorldComm > ( ) ;
wComm . DeliverMessage ( ChatTypeEnum . Shout , ScriptBaseClass . DEBUG_CHANNEL , m_host . Name , m_host . UUID , message ) ;
}
2008-10-03 06:15:23 +00:00
public void CheckThreatLevel ( ThreatLevel level , string function )
2008-09-15 15:25:48 +00:00
{
2008-09-15 22:52:23 +00:00
if ( ! m_OSFunctionsEnabled )
2008-11-21 17:28:57 +00:00
OSSLError ( String . Format ( "{0} permission denied. All OS functions are disabled." , function ) ) ; // throws
2008-09-15 22:52:23 +00:00
2008-09-15 15:36:51 +00:00
if ( ! m_FunctionPerms . ContainsKey ( function ) )
{
2010-05-30 13:46:54 +00:00
FunctionPerms perms = new FunctionPerms ( ) ;
m_FunctionPerms [ function ] = perms ;
string ownerPerm = m_ScriptEngine . Config . GetString ( "Allow_" + function , "" ) ;
string creatorPerm = m_ScriptEngine . Config . GetString ( "Creators_" + function , "" ) ;
if ( ownerPerm = = "" & & creatorPerm = = "" )
2008-09-15 23:50:07 +00:00
{
2010-05-30 13:46:54 +00:00
// Default behavior
perms . AllowedOwners = null ;
perms . AllowedCreators = null ;
2011-10-26 13:03:10 +00:00
perms . AllowedOwnerClasses = null ;
2008-09-15 23:50:07 +00:00
}
else
{
2008-11-17 04:23:03 +00:00
bool allowed ;
2008-09-15 23:50:07 +00:00
2010-05-30 13:46:54 +00:00
if ( bool . TryParse ( ownerPerm , out allowed ) )
2008-11-17 04:23:03 +00:00
{
// Boolean given
if ( allowed )
{
2010-05-30 13:46:54 +00:00
// Allow globally
perms . AllowedOwners . Add ( UUID . Zero ) ;
2008-11-17 04:23:03 +00:00
}
}
else
2008-09-15 23:50:07 +00:00
{
2010-05-30 13:46:54 +00:00
string [ ] ids = ownerPerm . Split ( new char [ ] { ',' } ) ;
foreach ( string id in ids )
{
string current = id . Trim ( ) ;
2011-10-26 13:03:10 +00:00
if ( current . ToUpper ( ) = = "PARCEL_GROUP_MEMBER" | | current . ToUpper ( ) = = "PARCEL_OWNER" | | current . ToUpper ( ) = = "ESTATE_MANAGER" | | current . ToUpper ( ) = = "ESTATE_OWNER" )
2010-05-30 13:46:54 +00:00
{
2011-10-26 13:03:10 +00:00
if ( ! perms . AllowedOwnerClasses . Contains ( current ) )
perms . AllowedOwnerClasses . Add ( current . ToUpper ( ) ) ;
}
else
{
UUID uuid ;
if ( UUID . TryParse ( current , out uuid ) )
{
if ( uuid ! = UUID . Zero )
perms . AllowedOwners . Add ( uuid ) ;
}
2010-05-30 13:46:54 +00:00
}
}
ids = creatorPerm . Split ( new char [ ] { ',' } ) ;
2008-11-17 04:23:03 +00:00
foreach ( string id in ids )
2008-09-15 23:50:07 +00:00
{
2008-11-17 04:23:03 +00:00
string current = id . Trim ( ) ;
UUID uuid ;
if ( UUID . TryParse ( current , out uuid ) )
{
2008-11-17 04:34:19 +00:00
if ( uuid ! = UUID . Zero )
2010-05-30 13:46:54 +00:00
perms . AllowedCreators . Add ( uuid ) ;
2008-11-17 04:23:03 +00:00
}
2008-09-15 23:50:07 +00:00
}
}
}
2008-09-15 15:36:51 +00:00
}
2008-09-15 23:50:07 +00:00
// If the list is null, then the value was true / undefined
// Threat level governs permissions in this case
/ /
// If the list is non-null, then it is a list of UUIDs allowed
// to use that particular function. False causes an empty
// list and therefore means "no one"
/ /
2008-11-17 04:23:03 +00:00
// To allow use by anyone, the list contains UUID.Zero
/ /
2010-05-30 13:46:54 +00:00
if ( m_FunctionPerms [ function ] . AllowedOwners = = null )
2008-09-15 23:50:07 +00:00
{
2010-05-30 13:46:54 +00:00
// Allow / disallow by threat level
2008-09-15 23:50:07 +00:00
if ( level > m_MaxThreatLevel )
2008-11-21 17:28:57 +00:00
OSSLError (
String . Format (
"{0} permission denied. Allowed threat level is {1} but function threat level is {2}." ,
function , m_MaxThreatLevel , level ) ) ;
2008-09-15 23:50:07 +00:00
}
else
{
2010-05-30 13:46:54 +00:00
if ( ! m_FunctionPerms [ function ] . AllowedOwners . Contains ( UUID . Zero ) )
2008-11-17 04:23:03 +00:00
{
2010-05-30 13:46:54 +00:00
// Not anyone. Do detailed checks
if ( m_FunctionPerms [ function ] . AllowedOwners . Contains ( m_host . OwnerID ) )
{
// prim owner is in the list of allowed owners
return ;
}
2010-05-30 11:46:05 +00:00
TaskInventoryItem ti = m_host . Inventory . GetInventoryItem ( m_itemID ) ;
if ( ti = = null )
{
OSSLError (
String . Format ( "{0} permission error. Can't find script in prim inventory." ,
function ) ) ;
}
2011-10-26 13:03:10 +00:00
UUID ownerID = ti . OwnerID ;
//OSSL only may be used if objet is in the same group as the parcel
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "PARCEL_GROUP_MEMBER" ) )
{
ILandObject land = World . LandChannel . GetLandObject ( m_host . AbsolutePosition . X , m_host . AbsolutePosition . Y ) ;
if ( land . LandData . GroupID = = ti . GroupID & & land . LandData . GroupID ! = UUID . Zero )
{
return ;
}
}
//Only Parcelowners may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "PARCEL_OWNER" ) )
{
ILandObject land = World . LandChannel . GetLandObject ( m_host . AbsolutePosition . X , m_host . AbsolutePosition . Y ) ;
if ( land . LandData . OwnerID = = ownerID )
{
return ;
}
}
//Only Estate Managers may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "ESTATE_MANAGER" ) )
{
//Only Estate Managers may use the function
if ( World . RegionInfo . EstateSettings . IsEstateManager ( ownerID ) & & World . RegionInfo . EstateSettings . EstateOwner ! = ownerID )
{
return ;
}
}
//Only regionowners may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "ESTATE_OWNER" ) )
{
if ( World . RegionInfo . EstateSettings . EstateOwner = = ownerID )
{
return ;
}
}
2010-05-30 13:46:54 +00:00
if ( ! m_FunctionPerms [ function ] . AllowedCreators . Contains ( ti . CreatorID ) )
2008-11-21 17:28:57 +00:00
OSSLError (
2010-05-30 13:46:54 +00:00
String . Format ( "{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission." ,
2008-11-21 17:28:57 +00:00
function ) ) ;
2011-10-26 13:03:10 +00:00
if ( ti . CreatorID ! = ownerID )
2010-05-30 11:46:05 +00:00
{
if ( ( ti . CurrentPermissions & ( uint ) PermissionMask . Modify ) ! = 0 )
OSSLError (
String . Format ( "{0} permission denied. Script permissions error." ,
function ) ) ;
}
2008-11-17 04:23:03 +00:00
}
2008-09-15 23:50:07 +00:00
}
2008-09-15 15:25:48 +00:00
}
2010-12-10 21:13:05 +00:00
internal void OSSLDeprecated ( string function , string replacement )
{
OSSLShoutError ( string . Format ( "Use of function {0} is deprecated. Use {1} instead." , function , replacement ) ) ;
}
2008-09-15 14:32:02 +00:00
protected void ScriptSleep ( int delay )
{
delay = ( int ) ( ( float ) delay * m_ScriptDelayFactor ) ;
if ( delay = = 0 )
return ;
System . Threading . Thread . Sleep ( delay ) ;
}
2010-12-10 21:13:05 +00:00
public LSL_Integer osSetTerrainHeight ( int x , int y , double val )
{
CheckThreatLevel ( ThreatLevel . High , "osSetTerrainHeight" ) ;
return SetTerrainHeight ( x , y , val ) ;
}
2011-08-08 22:22:47 +00:00
2009-04-19 13:34:28 +00:00
public LSL_Integer osTerrainSetHeight ( int x , int y , double val )
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . High , "osTerrainSetHeight" ) ;
2010-12-10 21:13:05 +00:00
OSSLDeprecated ( "osTerrainSetHeight" , "osSetTerrainHeight" ) ;
return SetTerrainHeight ( x , y , val ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
private LSL_Integer SetTerrainHeight ( int x , int y , double val )
{
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2009-08-08 00:31:48 +00:00
if ( x > ( ( int ) Constants . RegionSize - 1 ) | | x < 0 | | y > ( ( int ) Constants . RegionSize - 1 ) | | y < 0 )
2010-12-10 21:13:05 +00:00
OSSLError ( "osSetTerrainHeight: Coordinate out of bounds" ) ;
2008-05-30 12:27:06 +00:00
2008-11-21 22:14:57 +00:00
if ( World . Permissions . CanTerraformLand ( m_host . OwnerID , new Vector3 ( x , y , 0 ) ) )
2008-05-30 12:27:06 +00:00
{
World . Heightmap [ x , y ] = val ;
return 1 ;
}
else
{
return 0 ;
}
}
2010-12-10 21:13:05 +00:00
public LSL_Float osGetTerrainHeight ( int x , int y )
{
CheckThreatLevel ( ThreatLevel . None , "osGetTerrainHeight" ) ;
return GetTerrainHeight ( x , y ) ;
}
2011-08-08 22:22:47 +00:00
2009-04-19 13:34:28 +00:00
public LSL_Float osTerrainGetHeight ( int x , int y )
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osTerrainGetHeight" ) ;
2010-12-10 21:13:05 +00:00
OSSLDeprecated ( "osTerrainGetHeight" , "osGetTerrainHeight" ) ;
return GetTerrainHeight ( x , y ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
private LSL_Float GetTerrainHeight ( int x , int y )
{
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2009-08-08 00:31:48 +00:00
if ( x > ( ( int ) Constants . RegionSize - 1 ) | | x < 0 | | y > ( ( int ) Constants . RegionSize - 1 ) | | y < 0 )
2010-12-10 21:13:05 +00:00
OSSLError ( "osGetTerrainHeight: Coordinate out of bounds" ) ;
2008-05-30 12:27:06 +00:00
return World . Heightmap [ x , y ] ;
}
2009-04-19 13:34:28 +00:00
public void osTerrainFlush ( )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osTerrainFlush" ) ;
ITerrainModule terrainModule = World . RequestModuleInterface < ITerrainModule > ( ) ;
if ( terrainModule ! = null ) terrainModule . TaintTerrain ( ) ;
}
2008-05-30 12:27:06 +00:00
public int osRegionRestart ( double seconds )
{
2008-09-15 15:25:48 +00:00
// This is High here because region restart is not reliable
// it may result in the region staying down or becoming
// unstable. This should be changed to Low or VeryLow once
// The underlying functionality is fixed, since the security
// as such is sound
/ /
CheckThreatLevel ( ThreatLevel . High , "osRegionRestart" ) ;
2008-05-30 12:27:06 +00:00
2010-11-25 03:16:52 +00:00
IRestartModule restartModule = World . RequestModuleInterface < IRestartModule > ( ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2010-11-25 03:16:52 +00:00
if ( World . Permissions . CanIssueEstateCommand ( m_host . OwnerID , false ) & & ( restartModule ! = null ) )
2008-05-30 12:27:06 +00:00
{
2010-11-25 03:16:52 +00:00
if ( seconds < 15 )
{
restartModule . AbortRestart ( "Restart aborted" ) ;
return 1 ;
}
List < int > times = new List < int > ( ) ;
while ( seconds > 0 )
{
times . Add ( ( int ) seconds ) ;
if ( seconds > 300 )
seconds - = 120 ;
else if ( seconds > 30 )
seconds - = 30 ;
else
seconds - = 15 ;
}
restartModule . ScheduleRestart ( UUID . Zero , "Region will restart in {0}" , times . ToArray ( ) , true ) ;
2008-05-30 12:27:06 +00:00
return 1 ;
}
else
{
return 0 ;
}
}
public void osRegionNotice ( string msg )
{
2008-09-15 15:25:48 +00:00
// This implementation provides absolutely no security
// It's high griefing potential makes this classification
// necessary
/ /
CheckThreatLevel ( ThreatLevel . VeryHigh , "osRegionNotice" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2009-02-04 00:01:36 +00:00
2009-01-07 20:29:09 +00:00
IDialogModule dm = World . RequestModuleInterface < IDialogModule > ( ) ;
2009-02-04 00:01:36 +00:00
2009-01-07 20:29:09 +00:00
if ( dm ! = null )
dm . SendGeneralAlert ( msg ) ;
2008-05-30 12:27:06 +00:00
}
2008-09-06 07:52:41 +00:00
public void osSetRot ( UUID target , Quaternion rotation )
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
// This function has no security. It can be used to destroy
// arbitrary builds the user would normally have no rights to
/ /
CheckThreatLevel ( ThreatLevel . VeryHigh , "osSetRot" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( World . Entities . ContainsKey ( target ) )
{
2009-11-05 00:08:10 +00:00
EntityBase entity ;
if ( World . Entities . TryGetValue ( target , out entity ) )
{
if ( entity is SceneObjectGroup )
( ( SceneObjectGroup ) entity ) . Rotation = rotation ;
else if ( entity is ScenePresence )
( ( ScenePresence ) entity ) . Rotation = rotation ;
}
2008-05-30 12:27:06 +00:00
}
else
{
OSSLError ( "osSetRot: Invalid target" ) ;
}
}
public string osSetDynamicTextureURL ( string dynamicID , string contentType , string url , string extraParams ,
int timer )
{
2008-09-15 15:25:48 +00:00
// This may be upgraded depending on the griefing or DOS
// potential, or guarded with a delay
/ /
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureURL" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
2008-09-06 07:52:41 +00:00
UUID createdTexture =
2008-05-30 12:27:06 +00:00
textureManager . AddDynamicTextureURL ( World . RegionInfo . RegionID , m_host . UUID , contentType , url ,
extraParams , timer ) ;
return createdTexture . ToString ( ) ;
}
else
{
//TODO update existing dynamic textures
}
2008-09-06 07:52:41 +00:00
return UUID . Zero . ToString ( ) ;
2008-05-30 12:27:06 +00:00
}
public string osSetDynamicTextureURLBlend ( string dynamicID , string contentType , string url , string extraParams ,
int timer , int alpha )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureURLBlend" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
2008-09-06 07:52:41 +00:00
UUID createdTexture =
2008-05-30 12:27:06 +00:00
textureManager . AddDynamicTextureURL ( World . RegionInfo . RegionID , m_host . UUID , contentType , url ,
extraParams , timer , true , ( byte ) alpha ) ;
return createdTexture . ToString ( ) ;
}
else
{
//TODO update existing dynamic textures
}
2008-09-06 07:52:41 +00:00
return UUID . Zero . ToString ( ) ;
2008-05-30 12:27:06 +00:00
}
2009-05-22 16:22:49 +00:00
public string osSetDynamicTextureURLBlendFace ( string dynamicID , string contentType , string url , string extraParams ,
2009-06-09 06:39:27 +00:00
bool blend , int disp , int timer , int alpha , int face )
2009-05-22 16:22:49 +00:00
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureURLBlendFace" ) ;
m_host . AddScriptLPS ( 1 ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
UUID createdTexture =
textureManager . AddDynamicTextureURL ( World . RegionInfo . RegionID , m_host . UUID , contentType , url ,
2009-06-09 06:39:27 +00:00
extraParams , timer , blend , disp , ( byte ) alpha , face ) ;
2009-05-22 16:22:49 +00:00
return createdTexture . ToString ( ) ;
}
else
{
//TODO update existing dynamic textures
}
return UUID . Zero . ToString ( ) ;
}
2008-05-30 12:27:06 +00:00
public string osSetDynamicTextureData ( string dynamicID , string contentType , string data , string extraParams ,
int timer )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureData" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
if ( textureManager ! = null )
{
2008-09-10 05:17:28 +00:00
if ( extraParams = = String . Empty )
{
extraParams = "256" ;
}
2008-09-06 07:52:41 +00:00
UUID createdTexture =
2008-05-30 12:27:06 +00:00
textureManager . AddDynamicTextureData ( World . RegionInfo . RegionID , m_host . UUID , contentType , data ,
extraParams , timer ) ;
return createdTexture . ToString ( ) ;
}
}
else
{
//TODO update existing dynamic textures
}
2008-09-06 07:52:41 +00:00
return UUID . Zero . ToString ( ) ;
2008-05-30 12:27:06 +00:00
}
public string osSetDynamicTextureDataBlend ( string dynamicID , string contentType , string data , string extraParams ,
int timer , int alpha )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureDataBlend" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
if ( textureManager ! = null )
{
2008-09-10 05:17:28 +00:00
if ( extraParams = = String . Empty )
{
extraParams = "256" ;
}
2008-09-06 07:52:41 +00:00
UUID createdTexture =
2008-05-30 12:27:06 +00:00
textureManager . AddDynamicTextureData ( World . RegionInfo . RegionID , m_host . UUID , contentType , data ,
extraParams , timer , true , ( byte ) alpha ) ;
return createdTexture . ToString ( ) ;
}
}
else
{
//TODO update existing dynamic textures
}
2008-09-06 07:52:41 +00:00
return UUID . Zero . ToString ( ) ;
2008-05-30 12:27:06 +00:00
}
2009-05-22 16:22:49 +00:00
public string osSetDynamicTextureDataBlendFace ( string dynamicID , string contentType , string data , string extraParams ,
2009-06-09 06:39:27 +00:00
bool blend , int disp , int timer , int alpha , int face )
2009-05-22 16:22:49 +00:00
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureDataBlendFace" ) ;
m_host . AddScriptLPS ( 1 ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
if ( textureManager ! = null )
{
if ( extraParams = = String . Empty )
{
extraParams = "256" ;
}
UUID createdTexture =
textureManager . AddDynamicTextureData ( World . RegionInfo . RegionID , m_host . UUID , contentType , data ,
2009-06-09 06:39:27 +00:00
extraParams , timer , blend , disp , ( byte ) alpha , face ) ;
2009-05-22 16:22:49 +00:00
return createdTexture . ToString ( ) ;
}
}
else
{
//TODO update existing dynamic textures
}
return UUID . Zero . ToString ( ) ;
}
2008-05-30 12:27:06 +00:00
public bool osConsoleCommand ( string command )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . Severe , "osConsoleCommand" ) ;
2008-09-15 22:52:23 +00:00
m_host . AddScriptLPS ( 1 ) ;
2008-11-21 22:14:57 +00:00
if ( World . Permissions . CanRunConsoleCommand ( m_host . OwnerID ) )
2008-09-15 15:25:48 +00:00
{
MainConsole . Instance . RunCommand ( command ) ;
return true ;
}
2008-05-30 12:27:06 +00:00
return false ;
}
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
public void osSetPrimFloatOnWater ( int floatYN )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetPrimFloatOnWater" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2011-09-01 00:22:28 +00:00
2011-09-01 01:09:41 +00:00
m_host . ParentGroup . RootPart . SetFloatOnWater ( floatYN ) ;
2008-05-30 12:27:06 +00:00
}
2008-09-15 14:32:02 +00:00
// Teleport functions
public void osTeleportAgent ( string agent , string regionName , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
{
2008-09-15 15:25:48 +00:00
// High because there is no security check. High griefer potential
/ /
CheckThreatLevel ( ThreatLevel . High , "osTeleportAgent" ) ;
2011-01-21 18:55:35 +00:00
TeleportAgent ( agent , regionName , position , lookat , false ) ;
2010-11-15 18:52:39 +00:00
}
2011-01-21 18:55:35 +00:00
private void TeleportAgent ( string agent , string regionName ,
LSL_Types . Vector3 position , LSL_Types . Vector3 lookat , bool relaxRestrictions )
2010-11-15 18:52:39 +00:00
{
2008-09-15 14:32:02 +00:00
m_host . AddScriptLPS ( 1 ) ;
UUID agentId = new UUID ( ) ;
if ( UUID . TryParse ( agent , out agentId ) )
{
ScenePresence presence = World . GetScenePresence ( agentId ) ;
if ( presence ! = null )
{
2011-01-21 19:00:04 +00:00
// For osTeleportAgent, agent must be over owners land to avoid abuse
// For osTeleportOwner, this restriction isn't necessary
2011-01-21 18:55:35 +00:00
if ( relaxRestrictions | |
m_host . OwnerID
2009-03-06 20:44:31 +00:00
= = World . LandChannel . GetLandObject (
2009-10-02 09:10:52 +00:00
presence . AbsolutePosition . X , presence . AbsolutePosition . Y ) . LandData . OwnerID )
2008-09-15 14:32:02 +00:00
{
2011-09-07 22:55:41 +00:00
// We will launch the teleport on a new thread so that when the script threads are terminated
// before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
Util . FireAndForget (
o = > World . RequestTeleportLocation ( presence . ControllingClient , regionName ,
new Vector3 ( ( float ) position . x , ( float ) position . y , ( float ) position . z ) ,
new Vector3 ( ( float ) lookat . x , ( float ) lookat . y , ( float ) lookat . z ) , ( uint ) TPFlags . ViaLocation ) ) ;
2009-04-19 13:34:28 +00:00
2008-09-15 15:25:48 +00:00
ScriptSleep ( 5000 ) ;
2008-09-15 14:32:02 +00:00
}
}
}
}
2009-11-25 17:01:41 +00:00
public void osTeleportAgent ( string agent , int regionX , int regionY , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
2009-02-01 17:41:33 +00:00
{
// High because there is no security check. High griefer potential
/ /
CheckThreatLevel ( ThreatLevel . High , "osTeleportAgent" ) ;
2011-01-21 18:55:35 +00:00
TeleportAgent ( agent , regionX , regionY , position , lookat , false ) ;
2010-11-15 18:52:39 +00:00
}
2011-01-21 18:55:35 +00:00
private void TeleportAgent ( string agent , int regionX , int regionY ,
LSL_Types . Vector3 position , LSL_Types . Vector3 lookat , bool relaxRestrictions )
2010-11-15 18:52:39 +00:00
{
2009-11-25 17:01:41 +00:00
ulong regionHandle = Util . UIntsToLong ( ( ( uint ) regionX * ( uint ) Constants . RegionSize ) , ( ( uint ) regionY * ( uint ) Constants . RegionSize ) ) ;
2009-02-01 17:41:33 +00:00
m_host . AddScriptLPS ( 1 ) ;
UUID agentId = new UUID ( ) ;
if ( UUID . TryParse ( agent , out agentId ) )
{
ScenePresence presence = World . GetScenePresence ( agentId ) ;
if ( presence ! = null )
{
2011-01-21 18:55:35 +00:00
// For osTeleportAgent, agent must be over owners land to avoid abuse
// For osTeleportOwner, this restriction isn't necessary
if ( relaxRestrictions | |
m_host . OwnerID
2009-03-06 20:44:31 +00:00
= = World . LandChannel . GetLandObject (
2009-10-02 09:10:52 +00:00
presence . AbsolutePosition . X , presence . AbsolutePosition . Y ) . LandData . OwnerID )
2009-02-01 17:41:33 +00:00
{
2011-09-07 22:55:41 +00:00
// We will launch the teleport on a new thread so that when the script threads are terminated
// before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
Util . FireAndForget (
o = > World . RequestTeleportLocation ( presence . ControllingClient , regionHandle ,
new Vector3 ( ( float ) position . x , ( float ) position . y , ( float ) position . z ) ,
new Vector3 ( ( float ) lookat . x , ( float ) lookat . y , ( float ) lookat . z ) , ( uint ) TPFlags . ViaLocation ) ) ;
2009-02-01 17:41:33 +00:00
ScriptSleep ( 5000 ) ;
}
}
}
}
2008-09-15 14:32:02 +00:00
public void osTeleportAgent ( string agent , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
{
osTeleportAgent ( agent , World . RegionInfo . RegionName , position , lookat ) ;
}
2010-11-15 18:52:39 +00:00
public void osTeleportOwner ( string regionName , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
{
// Threat level None because this is what can already be done with the World Map in the viewer
CheckThreatLevel ( ThreatLevel . None , "osTeleportOwner" ) ;
2011-01-21 18:55:35 +00:00
TeleportAgent ( m_host . OwnerID . ToString ( ) , regionName , position , lookat , true ) ;
2010-11-15 18:52:39 +00:00
}
public void osTeleportOwner ( LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
{
osTeleportOwner ( World . RegionInfo . RegionName , position , lookat ) ;
}
public void osTeleportOwner ( int regionX , int regionY , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
{
CheckThreatLevel ( ThreatLevel . None , "osTeleportOwner" ) ;
2011-01-21 18:55:35 +00:00
TeleportAgent ( m_host . OwnerID . ToString ( ) , regionX , regionY , position , lookat , true ) ;
2010-11-15 18:52:39 +00:00
}
2009-02-26 22:37:02 +00:00
// Functions that get information from the agent itself.
/ /
// osGetAgentIP - this is used to determine the IP address of
//the client. This is needed to help configure other in world
//resources based on the IP address of the clients connected.
//I think High is a good risk level for this, as it is an
//information leak.
public string osGetAgentIP ( string agent )
{
CheckThreatLevel ( ThreatLevel . High , "osGetAgentIP" ) ;
UUID avatarID = ( UUID ) agent ;
m_host . AddScriptLPS ( 1 ) ;
if ( World . Entities . ContainsKey ( ( UUID ) agent ) & & World . Entities [ avatarID ] is ScenePresence )
{
ScenePresence target = ( ScenePresence ) World . Entities [ avatarID ] ;
2009-07-01 15:47:52 +00:00
EndPoint ep = target . ControllingClient . GetClientEP ( ) ;
2009-04-19 13:34:28 +00:00
if ( ep is IPEndPoint )
2009-02-26 22:37:02 +00:00
{
IPEndPoint ip = ( IPEndPoint ) ep ;
return ip . Address . ToString ( ) ;
}
}
// fall through case, just return nothing
return "" ;
}
2009-03-26 12:08:18 +00:00
// Get a list of all the avatars/agents in the region
public LSL_List osGetAgents ( )
{
// threat level is None as we could get this information with an
// in-world script as well, just not as efficient
CheckThreatLevel ( ThreatLevel . None , "osGetAgents" ) ;
LSL_List result = new LSL_List ( ) ;
2011-10-27 08:25:12 +00:00
World . ForEachRootScenePresence ( delegate ( ScenePresence sp )
2009-03-26 12:08:18 +00:00
{
2011-10-27 08:25:12 +00:00
result . Add ( new LSL_String ( sp . Name ) ) ;
2010-03-19 12:51:16 +00:00
} ) ;
2009-03-26 12:08:18 +00:00
return result ;
2009-04-19 13:34:28 +00:00
}
2009-03-26 12:08:18 +00:00
2008-05-30 12:27:06 +00:00
// Adam's super super custom animation functions
public void osAvatarPlayAnimation ( string avatar , string animation )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osAvatarPlayAnimation" ) ;
2008-09-26 17:25:22 +00:00
UUID avatarID = ( UUID ) avatar ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2008-09-26 17:25:22 +00:00
if ( World . Entities . ContainsKey ( ( UUID ) avatar ) & & World . Entities [ avatarID ] is ScenePresence )
2008-05-30 12:27:06 +00:00
{
2008-09-26 17:25:22 +00:00
ScenePresence target = ( ScenePresence ) World . Entities [ avatarID ] ;
2009-03-15 19:45:42 +00:00
if ( target ! = null )
{
2009-03-26 12:08:18 +00:00
UUID animID = UUID . Zero ;
2009-03-15 19:45:42 +00:00
lock ( m_host . TaskInventory )
{
foreach ( KeyValuePair < UUID , TaskInventoryItem > inv in m_host . TaskInventory )
{
if ( inv . Value . Name = = animation )
{
if ( inv . Value . Type = = ( int ) AssetType . Animation )
animID = inv . Value . AssetID ;
continue ;
}
}
}
if ( animID = = UUID . Zero )
2009-11-17 15:05:40 +00:00
target . Animator . AddAnimation ( animation , m_host . UUID ) ;
2009-03-15 19:45:42 +00:00
else
2009-11-17 15:05:40 +00:00
target . Animator . AddAnimation ( animID , m_host . UUID ) ;
2009-03-15 19:45:42 +00:00
}
2008-05-30 12:27:06 +00:00
}
}
public void osAvatarStopAnimation ( string avatar , string animation )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osAvatarStopAnimation" ) ;
2008-09-26 17:25:22 +00:00
UUID avatarID = ( UUID ) avatar ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2008-09-26 17:25:22 +00:00
if ( World . Entities . ContainsKey ( avatarID ) & & World . Entities [ avatarID ] is ScenePresence )
2008-05-30 12:27:06 +00:00
{
2008-09-26 17:25:22 +00:00
ScenePresence target = ( ScenePresence ) World . Entities [ avatarID ] ;
2009-03-26 12:08:18 +00:00
if ( target ! = null )
{
2011-08-11 00:56:42 +00:00
UUID animID = UUID . Zero ;
2009-03-15 19:45:42 +00:00
lock ( m_host . TaskInventory )
{
foreach ( KeyValuePair < UUID , TaskInventoryItem > inv in m_host . TaskInventory )
{
if ( inv . Value . Name = = animation )
{
if ( inv . Value . Type = = ( int ) AssetType . Animation )
animID = inv . Value . AssetID ;
continue ;
}
}
}
2009-11-17 15:05:40 +00:00
2009-03-15 19:45:42 +00:00
if ( animID = = UUID . Zero )
2009-11-17 15:05:40 +00:00
target . Animator . RemoveAnimation ( animation ) ;
2009-03-15 19:45:42 +00:00
else
2009-11-17 15:05:40 +00:00
target . Animator . RemoveAnimation ( animID ) ;
2009-03-26 12:08:18 +00:00
}
2008-05-30 12:27:06 +00:00
}
}
//Texture draw functions
public string osMovePen ( string drawList , int x , int y )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osMovePen" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "MoveTo " + x + "," + y + ";" ;
return drawList ;
}
public string osDrawLine ( string drawList , int startX , int startY , int endX , int endY )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawLine" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "MoveTo " + startX + "," + startY + "; LineTo " + endX + "," + endY + "; " ;
return drawList ;
}
public string osDrawLine ( string drawList , int endX , int endY )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawLine" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "LineTo " + endX + "," + endY + "; " ;
return drawList ;
}
public string osDrawText ( string drawList , string text )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawText" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "Text " + text + "; " ;
return drawList ;
}
public string osDrawEllipse ( string drawList , int width , int height )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawEllipse" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "Ellipse " + width + "," + height + "; " ;
return drawList ;
}
public string osDrawRectangle ( string drawList , int width , int height )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawRectangle" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "Rectangle " + width + "," + height + "; " ;
return drawList ;
}
public string osDrawFilledRectangle ( string drawList , int width , int height )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawFilledRectangle" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "FillRectangle " + width + "," + height + "; " ;
return drawList ;
}
2009-08-22 00:12:22 +00:00
public string osDrawFilledPolygon ( string drawList , LSL_List x , LSL_List y )
{
CheckThreatLevel ( ThreatLevel . None , "osDrawFilledPolygon" ) ;
m_host . AddScriptLPS ( 1 ) ;
if ( x . Length ! = y . Length | | x . Length < 3 )
{
return "" ;
}
drawList + = "FillPolygon " + x . GetLSLStringItem ( 0 ) + "," + y . GetLSLStringItem ( 0 ) ;
for ( int i = 1 ; i < x . Length ; i + + )
{
drawList + = "," + x . GetLSLStringItem ( i ) + "," + y . GetLSLStringItem ( i ) ;
}
drawList + = "; " ;
return drawList ;
}
2009-08-28 20:48:03 +00:00
public string osDrawPolygon ( string drawList , LSL_List x , LSL_List y )
{
2011-06-24 10:40:21 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawPolygon" ) ;
2009-08-28 20:48:03 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( x . Length ! = y . Length | | x . Length < 3 )
{
return "" ;
}
drawList + = "Polygon " + x . GetLSLStringItem ( 0 ) + "," + y . GetLSLStringItem ( 0 ) ;
for ( int i = 1 ; i < x . Length ; i + + )
{
drawList + = "," + x . GetLSLStringItem ( i ) + "," + y . GetLSLStringItem ( i ) ;
}
drawList + = "; " ;
return drawList ;
}
2008-05-30 12:27:06 +00:00
public string osSetFontSize ( string drawList , int fontSize )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osSetFontSize" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "FontSize " + fontSize + "; " ;
return drawList ;
}
2009-08-31 07:28:56 +00:00
public string osSetFontName ( string drawList , string fontName )
{
CheckThreatLevel ( ThreatLevel . None , "osSetFontName" ) ;
m_host . AddScriptLPS ( 1 ) ;
drawList + = "FontName " + fontName + "; " ;
return drawList ;
}
2008-05-30 12:27:06 +00:00
public string osSetPenSize ( string drawList , int penSize )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osSetPenSize" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "PenSize " + penSize + "; " ;
return drawList ;
}
2010-12-10 21:13:05 +00:00
public string osSetPenColor ( string drawList , string color )
{
CheckThreatLevel ( ThreatLevel . None , "osSetPenColor" ) ;
m_host . AddScriptLPS ( 1 ) ;
drawList + = "PenColor " + color + "; " ;
return drawList ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
// Deprecated
2008-05-30 12:27:06 +00:00
public string osSetPenColour ( string drawList , string colour )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osSetPenColour" ) ;
2010-12-10 21:13:05 +00:00
OSSLDeprecated ( "osSetPenColour" , "osSetPenColor" ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "PenColour " + colour + "; " ;
return drawList ;
}
2009-08-25 13:32:45 +00:00
public string osSetPenCap ( string drawList , string direction , string type )
{
2010-12-10 21:13:05 +00:00
CheckThreatLevel ( ThreatLevel . None , "osSetPenCap" ) ;
2009-08-25 13:32:45 +00:00
m_host . AddScriptLPS ( 1 ) ;
drawList + = "PenCap " + direction + "," + type + "; " ;
return drawList ;
}
2008-05-30 12:27:06 +00:00
public string osDrawImage ( string drawList , int width , int height , string imageUrl )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . None , "osDrawImage" ) ;
m_host . AddScriptLPS ( 1 ) ;
drawList + = "Image " + width + "," + height + "," + imageUrl + "; " ;
return drawList ;
2008-05-30 12:27:06 +00:00
}
2009-02-18 12:56:36 +00:00
public LSL_Vector osGetDrawStringSize ( string contentType , string text , string fontName , int fontSize )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osGetDrawStringSize" ) ;
m_host . AddScriptLPS ( 1 ) ;
LSL_Vector vec = new LSL_Vector ( 0 , 0 , 0 ) ;
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
2009-04-19 13:34:28 +00:00
if ( textureManager ! = null )
2009-02-18 12:56:36 +00:00
{
double xSize , ySize ;
textureManager . GetDrawStringSize ( contentType , text , fontName , fontSize ,
out xSize , out ySize ) ;
vec . x = xSize ;
vec . y = ySize ;
}
return vec ;
}
2008-05-30 12:27:06 +00:00
public void osSetStateEvents ( int events )
{
2008-09-15 15:25:48 +00:00
// This function is a hack. There is no reason for it's existence
// anymore, since state events now work properly.
// It was probably added as a crutch or debugging aid, and
// should be removed
/ /
CheckThreatLevel ( ThreatLevel . High , "osSetStateEvents" ) ;
2008-05-30 12:27:06 +00:00
m_host . SetScriptEvents ( m_itemID , events ) ;
}
public void osSetRegionWaterHeight ( double height )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . High , "osSetRegionWaterHeight" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
//Check to make sure that the script's owner is the estate manager/master
//World.Permissions.GenericEstatePermission(
2008-11-21 22:14:57 +00:00
if ( World . Permissions . IsGod ( m_host . OwnerID ) )
2008-05-30 12:27:06 +00:00
{
World . EventManager . TriggerRequestChangeWaterHeight ( ( float ) height ) ;
}
}
2009-03-13 23:45:02 +00:00
/// <summary>
/// Changes the Region Sun Settings, then Triggers a Sun Update
/// </summary>
/// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
/// <param name="sunFixed">True to keep the sun stationary</param>
/// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
public void osSetRegionSunSettings ( bool useEstateSun , bool sunFixed , double sunHour )
{
CheckThreatLevel ( ThreatLevel . Nuisance , "osSetRegionSunSettings" ) ;
m_host . AddScriptLPS ( 1 ) ;
//Check to make sure that the script's owner is the estate manager/master
//World.Permissions.GenericEstatePermission(
if ( World . Permissions . IsGod ( m_host . OwnerID ) )
{
2009-03-20 22:42:21 +00:00
while ( sunHour > 24.0 )
sunHour - = 24.0 ;
while ( sunHour < 0 )
sunHour + = 24.0 ;
2009-04-19 13:34:28 +00:00
2009-03-20 22:42:21 +00:00
2009-03-13 23:45:02 +00:00
World . RegionInfo . RegionSettings . UseEstateSun = useEstateSun ;
World . RegionInfo . RegionSettings . SunPosition = sunHour + 6 ; // LL Region Sun Hour is 6 to 30
World . RegionInfo . RegionSettings . FixedSun = sunFixed ;
World . RegionInfo . RegionSettings . Save ( ) ;
World . EventManager . TriggerEstateToolsSunUpdate ( World . RegionInfo . RegionHandle , sunFixed , useEstateSun , ( float ) sunHour ) ;
}
}
2009-03-20 22:42:21 +00:00
/// <summary>
/// Changes the Estate Sun Settings, then Triggers a Sun Update
/// </summary>
/// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
/// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
public void osSetEstateSunSettings ( bool sunFixed , double sunHour )
{
CheckThreatLevel ( ThreatLevel . Nuisance , "osSetEstateSunSettings" ) ;
m_host . AddScriptLPS ( 1 ) ;
//Check to make sure that the script's owner is the estate manager/master
//World.Permissions.GenericEstatePermission(
if ( World . Permissions . IsGod ( m_host . OwnerID ) )
{
while ( sunHour > 24.0 )
sunHour - = 24.0 ;
while ( sunHour < 0 )
sunHour + = 24.0 ;
World . RegionInfo . EstateSettings . UseGlobalTime = ! sunFixed ;
World . RegionInfo . EstateSettings . SunPosition = sunHour ;
World . RegionInfo . EstateSettings . FixedSun = sunFixed ;
World . RegionInfo . EstateSettings . Save ( ) ;
World . EventManager . TriggerEstateToolsSunUpdate ( World . RegionInfo . RegionHandle , sunFixed , World . RegionInfo . RegionSettings . UseEstateSun , ( float ) sunHour ) ;
}
}
/// <summary>
/// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
/// </summary>
/// <returns></returns>
public double osGetCurrentSunHour ( )
{
CheckThreatLevel ( ThreatLevel . None , "osGetCurrentSunHour" ) ;
m_host . AddScriptLPS ( 1 ) ;
// Must adjust for the fact that Region Sun Settings are still LL offset
double sunHour = World . RegionInfo . RegionSettings . SunPosition - 6 ;
// See if the sun module has registered itself, if so it's authoritative
ISunModule module = World . RequestModuleInterface < ISunModule > ( ) ;
if ( module ! = null )
{
sunHour = module . GetCurrentSunHour ( ) ;
}
return sunHour ;
}
public double osSunGetParam ( string param )
{
CheckThreatLevel ( ThreatLevel . None , "osSunGetParam" ) ;
2010-12-10 21:13:05 +00:00
OSSLDeprecated ( "osSunGetParam" , "osGetSunParam" ) ;
return GetSunParam ( param ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
public double osGetSunParam ( string param )
{
CheckThreatLevel ( ThreatLevel . None , "osGetSunParam" ) ;
return GetSunParam ( param ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
private double GetSunParam ( string param )
{
2009-03-20 22:42:21 +00:00
m_host . AddScriptLPS ( 1 ) ;
double value = 0.0 ;
ISunModule module = World . RequestModuleInterface < ISunModule > ( ) ;
if ( module ! = null )
{
value = module . GetSunParameter ( param ) ;
}
return value ;
}
public void osSunSetParam ( string param , double value )
{
CheckThreatLevel ( ThreatLevel . None , "osSunSetParam" ) ;
2010-12-10 21:13:05 +00:00
OSSLDeprecated ( "osSunSetParam" , "osSetSunParam" ) ;
SetSunParam ( param , value ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
public void osSetSunParam ( string param , double value )
{
CheckThreatLevel ( ThreatLevel . None , "osSetSunParam" ) ;
SetSunParam ( param , value ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-10 21:13:05 +00:00
private void SetSunParam ( string param , double value )
{
2009-03-20 22:42:21 +00:00
m_host . AddScriptLPS ( 1 ) ;
ISunModule module = World . RequestModuleInterface < ISunModule > ( ) ;
if ( module ! = null )
{
module . SetSunParameter ( param , value ) ;
}
}
2009-03-31 02:33:19 +00:00
public string osWindActiveModelPluginName ( )
{
CheckThreatLevel ( ThreatLevel . None , "osWindActiveModelPluginName" ) ;
m_host . AddScriptLPS ( 1 ) ;
IWindModule module = World . RequestModuleInterface < IWindModule > ( ) ;
if ( module ! = null )
{
return module . WindActiveModelPluginName ;
}
return String . Empty ;
}
2011-06-27 10:30:42 +00:00
public void osSetWindParam ( string plugin , string param , LSL_Float value )
2009-03-31 02:33:19 +00:00
{
2010-12-10 21:13:05 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetWindParam" ) ;
2009-03-31 02:33:19 +00:00
m_host . AddScriptLPS ( 1 ) ;
IWindModule module = World . RequestModuleInterface < IWindModule > ( ) ;
if ( module ! = null )
{
try
{
2011-06-27 10:30:42 +00:00
module . WindParamSet ( plugin , param , ( float ) value ) ;
2009-03-31 02:33:19 +00:00
}
catch ( Exception ) { }
}
}
2011-06-27 10:30:42 +00:00
public LSL_Float osGetWindParam ( string plugin , string param )
2009-03-31 02:33:19 +00:00
{
2010-12-10 21:13:05 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osGetWindParam" ) ;
2009-03-31 02:33:19 +00:00
m_host . AddScriptLPS ( 1 ) ;
IWindModule module = World . RequestModuleInterface < IWindModule > ( ) ;
if ( module ! = null )
{
return module . WindParamGet ( plugin , param ) ;
}
return 0.0f ;
}
2010-04-29 18:57:30 +00:00
// Routines for creating and managing parcels programmatically
public void osParcelJoin ( LSL_Vector pos1 , LSL_Vector pos2 )
{
CheckThreatLevel ( ThreatLevel . High , "osParcelJoin" ) ;
m_host . AddScriptLPS ( 1 ) ;
int startx = ( int ) ( pos1 . x < pos2 . x ? pos1 . x : pos2 . x ) ;
int starty = ( int ) ( pos1 . y < pos2 . y ? pos1 . y : pos2 . y ) ;
int endx = ( int ) ( pos1 . x > pos2 . x ? pos1 . x : pos2 . x ) ;
int endy = ( int ) ( pos1 . y > pos2 . y ? pos1 . y : pos2 . y ) ;
World . LandChannel . Join ( startx , starty , endx , endy , m_host . OwnerID ) ;
}
2010-09-12 17:43:49 +00:00
2010-04-29 18:57:30 +00:00
public void osParcelSubdivide ( LSL_Vector pos1 , LSL_Vector pos2 )
{
CheckThreatLevel ( ThreatLevel . High , "osParcelSubdivide" ) ;
m_host . AddScriptLPS ( 1 ) ;
int startx = ( int ) ( pos1 . x < pos2 . x ? pos1 . x : pos2 . x ) ;
int starty = ( int ) ( pos1 . y < pos2 . y ? pos1 . y : pos2 . y ) ;
int endx = ( int ) ( pos1 . x > pos2 . x ? pos1 . x : pos2 . x ) ;
int endy = ( int ) ( pos1 . y > pos2 . y ? pos1 . y : pos2 . y ) ;
2009-03-13 23:45:02 +00:00
2010-04-29 18:57:30 +00:00
World . LandChannel . Subdivide ( startx , starty , endx , endy , m_host . OwnerID ) ;
}
public void osParcelSetDetails ( LSL_Vector pos , LSL_List rules )
{
2010-12-11 10:41:45 +00:00
const string functionName = "osParcelSetDetails" ;
CheckThreatLevel ( ThreatLevel . High , functionName ) ;
OSSLDeprecated ( functionName , "osSetParcelDetails" ) ;
SetParcelDetails ( pos , rules , functionName ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-11 10:41:45 +00:00
public void osSetParcelDetails ( LSL_Vector pos , LSL_List rules )
{
const string functionName = "osSetParcelDetails" ;
CheckThreatLevel ( ThreatLevel . High , functionName ) ;
SetParcelDetails ( pos , rules , functionName ) ;
}
2011-08-08 22:22:47 +00:00
2010-12-11 10:41:45 +00:00
private void SetParcelDetails ( LSL_Vector pos , LSL_List rules , string functionName )
{
2010-04-29 18:57:30 +00:00
m_host . AddScriptLPS ( 1 ) ;
// Get a reference to the land data and make sure the owner of the script
// can modify it
ILandObject startLandObject = World . LandChannel . GetLandObject ( ( int ) pos . x , ( int ) pos . y ) ;
2010-09-12 17:43:49 +00:00
if ( startLandObject = = null )
2010-04-29 18:57:30 +00:00
{
OSSLShoutError ( "There is no land at that location" ) ;
return ;
}
2010-12-13 20:35:56 +00:00
if ( ! World . Permissions . CanEditParcelProperties ( m_host . OwnerID , startLandObject , GroupPowers . LandOptions ) )
2010-04-29 18:57:30 +00:00
{
OSSLShoutError ( "You do not have permission to modify the parcel" ) ;
return ;
}
// Create a new land data object we can modify
LandData newLand = startLandObject . LandData . Copy ( ) ;
UUID uuid ;
// Process the rules, not sure what the impact would be of changing owner or group
2010-09-12 17:43:49 +00:00
for ( int idx = 0 ; idx < rules . Length ; )
2010-04-29 18:57:30 +00:00
{
int code = rules . GetLSLIntegerItem ( idx + + ) ;
string arg = rules . GetLSLStringItem ( idx + + ) ;
switch ( code )
{
2011-10-08 05:38:04 +00:00
case ScriptBaseClass . PARCEL_DETAILS_NAME :
newLand . Name = arg ;
break ;
case ScriptBaseClass . PARCEL_DETAILS_DESC :
newLand . Description = arg ;
break ;
case ScriptBaseClass . PARCEL_DETAILS_OWNER :
CheckThreatLevel ( ThreatLevel . VeryHigh , functionName ) ;
if ( UUID . TryParse ( arg , out uuid ) )
newLand . OwnerID = uuid ;
break ;
case ScriptBaseClass . PARCEL_DETAILS_GROUP :
CheckThreatLevel ( ThreatLevel . VeryHigh , functionName ) ;
if ( UUID . TryParse ( arg , out uuid ) )
newLand . GroupID = uuid ;
break ;
case ScriptBaseClass . PARCEL_DETAILS_CLAIMDATE :
CheckThreatLevel ( ThreatLevel . VeryHigh , functionName ) ;
newLand . ClaimDate = Convert . ToInt32 ( arg ) ;
if ( newLand . ClaimDate = = 0 )
newLand . ClaimDate = Util . UnixTimeSinceEpoch ( ) ;
break ;
}
}
2010-04-29 18:57:30 +00:00
World . LandChannel . UpdateLandObject ( newLand . LocalID , newLand ) ;
}
2009-03-13 23:45:02 +00:00
2008-05-30 12:27:06 +00:00
public double osList2Double ( LSL_Types . list src , int index )
{
2008-09-15 15:25:48 +00:00
// There is really no double type in OSSL. C# and other
// have one, but the current implementation of LSL_Types.list
// is not allowed to contain any.
// This really should be removed.
/ /
CheckThreatLevel ( ThreatLevel . None , "osList2Double" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
if ( index < 0 )
{
index = src . Length + index ;
}
if ( index > = src . Length )
{
return 0.0 ;
}
return Convert . ToDouble ( src . Data [ index ] ) ;
}
public void osSetParcelMediaURL ( string url )
{
2008-09-15 15:25:48 +00:00
// What actually is the difference to the LL function?
/ /
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetParcelMediaURL" ) ;
2008-05-30 12:27:06 +00:00
m_host . AddScriptLPS ( 1 ) ;
2009-04-19 13:34:28 +00:00
ILandObject land
2009-03-06 20:44:31 +00:00
= World . LandChannel . GetLandObject ( m_host . AbsolutePosition . X , m_host . AbsolutePosition . Y ) ;
2008-05-30 12:27:06 +00:00
2009-10-15 23:35:27 +00:00
if ( land . LandData . OwnerID ! = m_host . OwnerID )
2008-05-30 12:27:06 +00:00
return ;
2009-03-06 20:44:31 +00:00
land . SetMediaUrl ( url ) ;
2008-05-30 12:27:06 +00:00
}
2009-11-12 19:42:35 +00:00
2009-09-18 13:11:38 +00:00
public void osSetParcelSIPAddress ( string SIPAddress )
{
// What actually is the difference to the LL function?
/ /
2011-06-24 10:40:21 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetParcelSIPAddress" ) ;
2009-09-18 13:11:38 +00:00
m_host . AddScriptLPS ( 1 ) ;
2009-11-12 19:42:35 +00:00
2009-09-18 13:11:38 +00:00
ILandObject land
= World . LandChannel . GetLandObject ( m_host . AbsolutePosition . X , m_host . AbsolutePosition . Y ) ;
2009-10-15 23:35:27 +00:00
if ( land . LandData . OwnerID ! = m_host . OwnerID )
2009-09-18 13:11:38 +00:00
{
OSSLError ( "osSetParcelSIPAddress: Sorry, you need to own the land to use this function" ) ;
return ;
}
2009-11-12 19:42:35 +00:00
2009-09-18 13:11:38 +00:00
// get the voice module
IVoiceModule voiceModule = World . RequestModuleInterface < IVoiceModule > ( ) ;
2009-11-12 19:42:35 +00:00
if ( voiceModule ! = null )
2009-10-02 09:10:52 +00:00
voiceModule . setLandSIPAddress ( SIPAddress , land . LandData . GlobalID ) ;
2009-09-18 13:11:38 +00:00
else
OSSLError ( "osSetParcelSIPAddress: No voice module enabled for this land" ) ;
}
2008-05-30 12:27:06 +00:00
2008-07-01 07:16:02 +00:00
public string osGetScriptEngineName ( )
{
2008-09-15 15:25:48 +00:00
// This gets a "high" because knowing the engine may be used
// to exploit engine-specific bugs or induce usage patterns
// that trigger engine-specific failures.
// Besides, public grid users aren't supposed to know.
/ /
CheckThreatLevel ( ThreatLevel . High , "osGetScriptEngineName" ) ;
2008-07-01 07:16:02 +00:00
m_host . AddScriptLPS ( 1 ) ;
int scriptEngineNameIndex = 0 ;
if ( ! String . IsNullOrEmpty ( m_ScriptEngine . ScriptEngineName ) )
{
// parse off the "ScriptEngine."
scriptEngineNameIndex = m_ScriptEngine . ScriptEngineName . IndexOf ( "." , scriptEngineNameIndex ) ;
scriptEngineNameIndex + + ; // get past delimiter
int scriptEngineNameLength = m_ScriptEngine . ScriptEngineName . Length - scriptEngineNameIndex ;
// create char array then a string that is only the script engine name
Char [ ] scriptEngineNameCharArray = m_ScriptEngine . ScriptEngineName . ToCharArray ( scriptEngineNameIndex , scriptEngineNameLength ) ;
String scriptEngineName = new String ( scriptEngineNameCharArray ) ;
return scriptEngineName ;
}
else
{
return String . Empty ;
}
}
2009-02-04 00:01:36 +00:00
2008-10-05 14:15:39 +00:00
public string osGetSimulatorVersion ( )
{
2008-10-03 01:30:22 +00:00
// High because it can be used to target attacks to known weaknesses
// This would allow a new class of griefer scripts that don't even
// require their user to know what they are doing (see script
// kiddie)
/ /
2008-10-05 14:15:39 +00:00
CheckThreatLevel ( ThreatLevel . High , "osGetSimulatorVersion" ) ;
m_host . AddScriptLPS ( 1 ) ;
return m_ScriptEngine . World . GetSimulatorVersion ( ) ;
}
2008-07-09 12:02:01 +00:00
2008-09-18 16:53:26 +00:00
public Hashtable osParseJSON ( string JSON )
{
CheckThreatLevel ( ThreatLevel . None , "osParseJSON" ) ;
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
m_host . AddScriptLPS ( 1 ) ;
// see http://www.json.org/ for more details on JSON
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
string currentKey = null ;
2008-09-18 16:53:26 +00:00
Stack objectStack = new Stack ( ) ; // objects in JSON can be nested so we need to keep a track of this
Hashtable jsondata = new Hashtable ( ) ; // the hashtable to be returned
2009-03-26 12:08:18 +00:00
int i = 0 ;
2008-09-18 16:53:26 +00:00
try
{
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
// iterate through the serialised stream of tokens and store at the right depth in the hashtable
// the top level hashtable may contain more nested hashtables within it each containing an objects representation
2009-03-26 12:08:18 +00:00
for ( i = 0 ; i < JSON . Length ; i + + )
2008-09-18 16:53:26 +00:00
{
2009-02-04 00:01:36 +00:00
2009-02-22 20:52:55 +00:00
// m_log.Debug(""+JSON[i]);
2008-09-21 02:41:22 +00:00
switch ( JSON [ i ] )
2008-09-18 16:53:26 +00:00
{
case '{' :
// create hashtable and add it to the stack or array if we are populating one, we can have a lot of nested objects in JSON
2009-02-04 00:01:36 +00:00
Hashtable currentObject = new Hashtable ( ) ;
2009-03-26 12:08:18 +00:00
if ( objectStack . Count = = 0 ) // the stack should only be empty for the first outer object
2008-09-18 16:53:26 +00:00
{
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
objectStack . Push ( jsondata ) ;
}
2009-03-26 12:08:18 +00:00
else if ( objectStack . Peek ( ) . ToString ( ) = = "System.Collections.ArrayList" )
2008-09-18 16:53:26 +00:00
{
// add it to the parent array
( ( ArrayList ) objectStack . Peek ( ) ) . Add ( currentObject ) ;
objectStack . Push ( currentObject ) ;
}
else
2009-02-04 00:01:36 +00:00
{
2008-09-18 16:53:26 +00:00
// add it to the parent hashtable
( ( Hashtable ) objectStack . Peek ( ) ) . Add ( currentKey , currentObject ) ;
objectStack . Push ( currentObject ) ;
2009-02-04 00:01:36 +00:00
}
2008-09-18 16:53:26 +00:00
// clear the key
2009-03-26 12:08:18 +00:00
currentKey = null ;
break ;
2008-09-18 16:53:26 +00:00
case '}' :
// pop the hashtable off the stack
objectStack . Pop ( ) ;
2009-03-26 12:08:18 +00:00
break ;
2008-09-18 16:53:26 +00:00
case '"' : // string boundary
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
string tokenValue = "" ;
2008-09-18 16:53:26 +00:00
i + + ; // move to next char
2009-02-04 00:01:36 +00:00
2008-09-29 17:47:17 +00:00
// just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
2009-03-26 12:08:18 +00:00
while ( JSON [ i ] ! = '"' )
2008-09-18 16:53:26 +00:00
{
2009-03-26 12:08:18 +00:00
tokenValue + = JSON [ i ] ;
2009-02-04 00:01:36 +00:00
2008-09-29 17:47:17 +00:00
// handle escaped double quotes \"
2009-03-26 12:08:18 +00:00
if ( JSON [ i ] = = '\\' & & JSON [ i + 1 ] = = '"' )
2009-02-04 00:01:36 +00:00
{
2009-03-26 12:08:18 +00:00
tokenValue + = JSON [ i + 1 ] ;
2009-02-04 00:01:36 +00:00
i + + ;
}
2008-09-29 17:47:17 +00:00
i + + ;
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
}
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
// ok we've got a string, if we've got an array on the top of the stack then we store it
2009-03-26 12:08:18 +00:00
if ( objectStack . Peek ( ) . ToString ( ) = = "System.Collections.ArrayList" )
2008-09-18 16:53:26 +00:00
{
( ( ArrayList ) objectStack . Peek ( ) ) . Add ( tokenValue ) ;
}
2009-03-26 12:08:18 +00:00
else if ( currentKey = = null ) // no key stored and its not an array this must be a key so store it
2008-09-18 16:53:26 +00:00
{
currentKey = tokenValue ;
}
2009-02-04 00:01:36 +00:00
else
2008-09-18 16:53:26 +00:00
{
// we have a key so lets store this value
( ( Hashtable ) objectStack . Peek ( ) ) . Add ( currentKey , tokenValue ) ;
// now lets clear the key, we're done with it and moving on
2009-03-26 12:08:18 +00:00
currentKey = null ;
2008-09-18 16:53:26 +00:00
}
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
break ;
2008-09-18 16:53:26 +00:00
case ':' : // key : value separator
2009-03-26 12:08:18 +00:00
// just ignore
break ;
2008-09-18 16:53:26 +00:00
case ' ' : // spaces
2009-03-26 12:08:18 +00:00
// just ignore
break ;
2008-09-18 16:53:26 +00:00
case '[' : // array start
2009-02-04 00:01:36 +00:00
ArrayList currentArray = new ArrayList ( ) ;
2009-03-26 12:08:18 +00:00
if ( objectStack . Peek ( ) . ToString ( ) = = "System.Collections.ArrayList" )
2009-02-04 00:01:36 +00:00
{
2008-09-18 16:53:26 +00:00
( ( ArrayList ) objectStack . Peek ( ) ) . Add ( currentArray ) ;
}
2009-02-04 00:01:36 +00:00
else
{
2008-09-18 16:53:26 +00:00
( ( Hashtable ) objectStack . Peek ( ) ) . Add ( currentKey , currentArray ) ;
// clear the key
2009-03-26 12:08:18 +00:00
currentKey = null ;
2008-09-18 16:53:26 +00:00
}
objectStack . Push ( currentArray ) ;
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
break ;
2008-09-18 16:53:26 +00:00
case ',' : // seperator
// just ignore
2009-03-26 12:08:18 +00:00
break ;
2008-09-18 16:53:26 +00:00
case ']' : //Array end
// pop the array off the stack
objectStack . Pop ( ) ;
2009-03-26 12:08:18 +00:00
break ;
2008-09-18 16:53:26 +00:00
case 't' : // we've found a character start not in quotes, it must be a boolean true
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
if ( objectStack . Peek ( ) . ToString ( ) = = "System.Collections.ArrayList" )
2008-09-18 16:53:26 +00:00
{
( ( ArrayList ) objectStack . Peek ( ) ) . Add ( true ) ;
}
else
2009-02-04 00:01:36 +00:00
{
2008-09-18 16:53:26 +00:00
( ( Hashtable ) objectStack . Peek ( ) ) . Add ( currentKey , true ) ;
2009-03-26 12:08:18 +00:00
currentKey = null ;
2008-09-18 16:53:26 +00:00
}
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
//advance the counter to the letter 'e'
2009-03-26 12:08:18 +00:00
i = i + 3 ;
break ;
2008-09-18 16:53:26 +00:00
case 'f' : // we've found a character start not in quotes, it must be a boolean false
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
if ( objectStack . Peek ( ) . ToString ( ) = = "System.Collections.ArrayList" )
2009-02-04 00:01:36 +00:00
{
2008-09-18 16:53:26 +00:00
( ( ArrayList ) objectStack . Peek ( ) ) . Add ( false ) ;
}
else
{
( ( Hashtable ) objectStack . Peek ( ) ) . Add ( currentKey , false ) ;
2009-03-26 12:08:18 +00:00
currentKey = null ;
2008-09-18 16:53:26 +00:00
}
//advance the counter to the letter 'e'
2009-03-26 12:08:18 +00:00
i = i + 4 ;
break ;
2008-09-29 17:47:17 +00:00
case '\n' : // carriage return
// just ignore
2009-03-26 12:08:18 +00:00
break ;
2008-09-29 17:47:17 +00:00
case '\r' : // carriage return
// just ignore
2009-03-26 12:08:18 +00:00
break ;
2008-09-18 16:53:26 +00:00
default :
// ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
// but for now we'll just do them as strings
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
string numberValue = "" ;
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
// just loop through until the next known marker quote mark storing the string
2008-09-21 02:41:22 +00:00
while ( JSON [ i ] ! = '"' & & JSON [ i ] ! = ',' & & JSON [ i ] ! = ']' & & JSON [ i ] ! = '}' & & JSON [ i ] ! = ' ' )
2008-09-18 16:53:26 +00:00
{
2009-03-26 12:08:18 +00:00
numberValue + = "" + JSON [ i + + ] ;
2008-09-18 16:53:26 +00:00
}
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
i - - ; // we want to process this caracter that marked the end of this string in the main loop
2009-02-04 00:01:36 +00:00
2008-09-18 16:53:26 +00:00
// ok we've got a string, if we've got an array on the top of the stack then we store it
2009-03-26 12:08:18 +00:00
if ( objectStack . Peek ( ) . ToString ( ) = = "System.Collections.ArrayList" )
2008-09-18 16:53:26 +00:00
{
( ( ArrayList ) objectStack . Peek ( ) ) . Add ( numberValue ) ;
}
2009-02-04 00:01:36 +00:00
else
2008-09-18 16:53:26 +00:00
{
// we have a key so lets store this value
( ( Hashtable ) objectStack . Peek ( ) ) . Add ( currentKey , numberValue ) ;
// now lets clear the key, we're done with it and moving on
2009-03-26 12:08:18 +00:00
currentKey = null ;
2008-09-18 16:53:26 +00:00
}
2009-02-04 00:01:36 +00:00
2009-03-26 12:08:18 +00:00
break ;
2009-02-04 00:01:36 +00:00
}
}
2008-09-18 16:53:26 +00:00
}
catch ( Exception )
{
2008-09-29 17:47:17 +00:00
OSSLError ( "osParseJSON: The JSON string is not valid " + JSON ) ;
2008-09-18 16:53:26 +00:00
}
2009-02-04 00:01:36 +00:00
return jsondata ;
}
2011-08-08 22:22:47 +00:00
/// <summary>
/// Send a message to to object identified by the given UUID
/// </summary>
/// <remarks>
/// A script in the object must implement the dataserver function
/// the dataserver function is passed the ID of the calling function and a string message
/// </remarks>
/// <param name="objectUUID"></param>
/// <param name="message"></param>
2008-11-05 15:15:41 +00:00
public void osMessageObject ( LSL_Key objectUUID , string message )
{
CheckThreatLevel ( ThreatLevel . Low , "osMessageObject" ) ;
m_host . AddScriptLPS ( 1 ) ;
2009-02-04 00:01:36 +00:00
2008-11-05 15:15:41 +00:00
object [ ] resobj = new object [ ] { new LSL_Types . LSLString ( m_host . UUID . ToString ( ) ) , new LSL_Types . LSLString ( message ) } ;
2009-02-04 00:01:36 +00:00
2008-11-05 15:15:41 +00:00
SceneObjectPart sceneOP = World . GetSceneObjectPart ( new UUID ( objectUUID ) ) ;
2009-02-04 00:01:36 +00:00
2008-11-05 15:15:41 +00:00
m_ScriptEngine . PostObjectEvent (
sceneOP . LocalId , new EventParams (
"dataserver" , resobj , new DetectParams [ 0 ] ) ) ;
}
2008-11-06 09:12:14 +00:00
2011-08-08 22:22:47 +00:00
/// <summary>
/// Write a notecard directly to the prim's inventory.
/// </summary>
/// <remarks>
/// This needs ThreatLevel high. It is an excellent griefer tool,
/// In a loop, it can cause asset bloat and DOS levels of asset
/// writes.
/// </remarks>
/// <param name="notecardName">The name of the notecard to write.</param>
/// <param name="contents">The contents of the notecard.</param>
2008-11-06 14:37:41 +00:00
public void osMakeNotecard ( string notecardName , LSL_Types . list contents )
{
CheckThreatLevel ( ThreatLevel . High , "osMakeNotecard" ) ;
m_host . AddScriptLPS ( 1 ) ;
2011-08-08 22:22:47 +00:00
StringBuilder notecardData = new StringBuilder ( ) ;
for ( int i = 0 ; i < contents . Length ; i + + )
notecardData . Append ( ( string ) ( contents . GetLSLStringItem ( i ) + "\n" ) ) ;
2011-08-09 02:51:34 +00:00
SaveNotecard ( notecardName , "Script generated notecard" , notecardData . ToString ( ) , false ) ;
2011-08-08 22:22:47 +00:00
}
2011-08-08 23:12:41 +00:00
/// <summary>
/// Save a notecard to prim inventory.
/// </summary>
2011-08-09 02:51:34 +00:00
/// <param name="name"></param>
/// <param name="description">Description of notecard</param>
2011-08-08 23:12:41 +00:00
/// <param name="notecardData"></param>
2011-08-09 02:51:34 +00:00
/// <param name="forceSameName">
/// If true, then if an item exists with the same name, it is replaced.
/// If false, then a new item is created witha slightly different name (e.g. name 1)
/// </param>
2011-08-08 23:12:41 +00:00
/// <returns>Prim inventory item created.</returns>
2011-08-09 02:51:34 +00:00
protected TaskInventoryItem SaveNotecard ( string name , string description , string data , bool forceSameName )
2011-08-08 22:22:47 +00:00
{
2008-11-06 14:37:41 +00:00
// Create new asset
2011-08-09 02:51:34 +00:00
AssetBase asset = new AssetBase ( UUID . Random ( ) , name , ( sbyte ) AssetType . Notecard , m_host . OwnerID . ToString ( ) ) ;
asset . Description = description ;
2008-11-06 14:37:41 +00:00
2011-08-09 02:51:34 +00:00
int textLength = data . Length ;
data
= "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
+ textLength . ToString ( ) + "\n" + data + "}\n" ;
2008-11-06 14:37:41 +00:00
2011-08-09 02:51:34 +00:00
asset . Data = Util . UTF8 . GetBytes ( data ) ;
2009-05-15 05:00:25 +00:00
World . AssetService . Store ( asset ) ;
2008-11-06 14:37:41 +00:00
// Create Task Entry
2011-08-08 22:22:47 +00:00
TaskInventoryItem taskItem = new TaskInventoryItem ( ) ;
2008-11-06 14:37:41 +00:00
taskItem . ResetIDs ( m_host . UUID ) ;
taskItem . ParentID = m_host . UUID ;
taskItem . CreationDate = ( uint ) Util . UnixTimeSinceEpoch ( ) ;
2009-02-17 01:36:44 +00:00
taskItem . Name = asset . Name ;
taskItem . Description = asset . Description ;
2009-05-09 21:11:12 +00:00
taskItem . Type = ( int ) AssetType . Notecard ;
taskItem . InvType = ( int ) InventoryType . Notecard ;
2008-11-06 14:37:41 +00:00
taskItem . OwnerID = m_host . OwnerID ;
taskItem . CreatorID = m_host . OwnerID ;
taskItem . BasePermissions = ( uint ) PermissionMask . All ;
taskItem . CurrentPermissions = ( uint ) PermissionMask . All ;
taskItem . EveryonePermissions = 0 ;
taskItem . NextPermissions = ( uint ) PermissionMask . All ;
taskItem . GroupID = m_host . GroupID ;
taskItem . GroupPermissions = 0 ;
taskItem . Flags = 0 ;
taskItem . PermsGranter = UUID . Zero ;
taskItem . PermsMask = 0 ;
2009-02-17 01:36:44 +00:00
taskItem . AssetID = asset . FullID ;
2008-11-06 14:37:41 +00:00
2011-08-09 02:51:34 +00:00
if ( forceSameName )
m_host . Inventory . AddInventoryItemExclusive ( taskItem , false ) ;
else
m_host . Inventory . AddInventoryItem ( taskItem , false ) ;
2011-08-08 23:12:41 +00:00
return taskItem ;
}
/// <summary>
/// Load the notecard data found at the given prim inventory item name or asset uuid.
/// </summary>
/// <param name="notecardNameOrUuid"></param>
/// <returns>The text loaded. Null if no notecard was found.</returns>
protected string LoadNotecard ( string notecardNameOrUuid )
{
UUID assetID = CacheNotecard ( notecardNameOrUuid ) ;
StringBuilder notecardData = new StringBuilder ( ) ;
for ( int count = 0 ; count < NotecardCache . GetLines ( assetID ) ; count + + )
2011-08-09 02:51:34 +00:00
{
string line = NotecardCache . GetLine ( assetID , count ) + "\n" ;
// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
notecardData . Append ( line ) ;
}
2011-08-08 23:12:41 +00:00
return notecardData . ToString ( ) ;
}
/// <summary>
/// Cache a notecard's contents.
/// </summary>
/// <param name="notecardNameOrUuid"></param>
/// <returns>
/// The asset id of the notecard, which is used for retrieving the cached data.
/// UUID.Zero if no asset could be found.
/// </returns>
protected UUID CacheNotecard ( string notecardNameOrUuid )
{
UUID assetID = UUID . Zero ;
if ( ! UUID . TryParse ( notecardNameOrUuid , out assetID ) )
{
foreach ( TaskInventoryItem item in m_host . TaskInventory . Values )
{
if ( item . Type = = 7 & & item . Name = = notecardNameOrUuid )
{
assetID = item . AssetID ;
}
}
}
if ( assetID = = UUID . Zero )
return UUID . Zero ;
if ( ! NotecardCache . IsCached ( assetID ) )
{
AssetBase a = World . AssetService . Get ( assetID . ToString ( ) ) ;
if ( a = = null )
return UUID . Zero ;
System . Text . UTF8Encoding enc = new System . Text . UTF8Encoding ( ) ;
string data = enc . GetString ( a . Data ) ;
NotecardCache . Cache ( assetID , data ) ;
} ;
return assetID ;
2008-11-06 14:37:41 +00:00
}
2009-02-16 01:22:37 +00:00
2011-08-08 22:22:47 +00:00
/// <summary>
/// Directly get an entire notecard at once.
/// </summary>
/// <remarks>
/// Instead of using the LSL Dataserver event to pull notecard data
/// this will simply read the entire notecard and return its data as a string.
///
/// Warning - due to the synchronous method this function uses to fetch assets, its use
/// may be dangerous and unreliable while running in grid mode.
/// </remarks>
/// <param name="name">Name of the notecard or its asset id</param>
/// <param name="line">The line number to read. The first line is line 0</param>
/// <returns>Notecard line</returns>
2009-04-27 14:16:01 +00:00
public string osGetNotecardLine ( string name , int line )
{
CheckThreatLevel ( ThreatLevel . VeryHigh , "osGetNotecardLine" ) ;
m_host . AddScriptLPS ( 1 ) ;
2011-08-08 23:12:41 +00:00
UUID assetID = CacheNotecard ( name ) ;
2009-04-27 14:16:01 +00:00
if ( assetID = = UUID . Zero )
{
OSSLShoutError ( "Notecard '" + name + "' could not be found." ) ;
return "ERROR!" ;
}
2011-08-09 02:51:34 +00:00
return NotecardCache . GetLine ( assetID , line ) ;
2009-04-27 14:16:01 +00:00
}
2011-08-08 22:22:47 +00:00
/// <summary>
/// Get an entire notecard at once.
/// </summary>
/// <remarks>
/// Instead of using the LSL Dataserver event to pull notecard data line by line,
/// this will simply read the entire notecard and return its data as a string.
///
/// Warning - due to the synchronous method this function uses to fetch assets, its use
/// may be dangerous and unreliable while running in grid mode.
/// </remarks>
/// <param name="name">Name of the notecard or its asset id</param>
/// <returns>Notecard text</returns>
2009-04-27 14:16:01 +00:00
public string osGetNotecard ( string name )
2009-04-27 12:05:49 +00:00
{
2009-04-27 14:16:01 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osGetNotecard" ) ;
2009-04-27 12:05:49 +00:00
m_host . AddScriptLPS ( 1 ) ;
2011-08-08 23:12:41 +00:00
string text = LoadNotecard ( name ) ;
2009-04-27 14:16:01 +00:00
2011-08-08 23:12:41 +00:00
if ( text = = null )
2009-04-27 14:16:01 +00:00
{
OSSLShoutError ( "Notecard '" + name + "' could not be found." ) ;
return "ERROR!" ;
}
2011-08-08 23:12:41 +00:00
else
2009-04-27 14:16:01 +00:00
{
2011-08-08 23:12:41 +00:00
return text ;
2009-04-27 12:05:49 +00:00
}
}
2011-08-08 22:22:47 +00:00
/// <summary>
/// Get the number of lines in the given notecard.
/// </summary>
/// <remarks>
/// Instead of using the LSL Dataserver event to pull notecard data,
/// this will simply read the number of note card lines and return this data as an integer.
///
/// Warning - due to the synchronous method this function uses to fetch assets, its use
/// may be dangerous and unreliable while running in grid mode.
/// </remarks>
/// <param name="name">Name of the notecard or its asset id</param>
/// <returns></returns>
2009-04-27 12:05:49 +00:00
public int osGetNumberOfNotecardLines ( string name )
{
CheckThreatLevel ( ThreatLevel . VeryHigh , "osGetNumberOfNotecardLines" ) ;
m_host . AddScriptLPS ( 1 ) ;
2011-08-08 23:12:41 +00:00
UUID assetID = CacheNotecard ( name ) ;
2009-04-27 12:05:49 +00:00
2009-04-27 14:16:01 +00:00
if ( assetID = = UUID . Zero )
{
OSSLShoutError ( "Notecard '" + name + "' could not be found." ) ;
return - 1 ;
}
return NotecardCache . GetLines ( assetID ) ;
}
2009-04-27 12:05:49 +00:00
2009-04-09 15:04:02 +00:00
public string osAvatarName2Key ( string firstname , string lastname )
{
CheckThreatLevel ( ThreatLevel . Low , "osAvatarName2Key" ) ;
2010-01-10 18:40:07 +00:00
UserAccount account = World . UserAccountService . GetUserAccount ( World . RegionInfo . ScopeID , firstname , lastname ) ;
if ( null = = account )
2009-04-09 15:04:02 +00:00
{
return UUID . Zero . ToString ( ) ;
2009-04-19 13:34:28 +00:00
}
else
2009-04-09 15:04:02 +00:00
{
2010-01-10 18:40:07 +00:00
return account . PrincipalID . ToString ( ) ;
2009-04-09 15:04:02 +00:00
}
}
public string osKey2Name ( string id )
{
CheckThreatLevel ( ThreatLevel . Low , "osKey2Name" ) ;
UUID key = new UUID ( ) ;
if ( UUID . TryParse ( id , out key ) )
{
2010-01-10 18:40:07 +00:00
UserAccount account = World . UserAccountService . GetUserAccount ( World . RegionInfo . ScopeID , key ) ;
if ( null = = account )
2009-04-09 15:04:02 +00:00
{
return "" ;
2009-04-19 13:34:28 +00:00
}
else
2009-04-09 15:04:02 +00:00
{
2010-01-10 18:40:07 +00:00
return account . Name ;
2009-04-09 15:04:02 +00:00
}
2009-04-19 13:34:28 +00:00
}
2009-04-09 15:04:02 +00:00
else
{
return "" ;
}
}
2011-08-08 22:22:47 +00:00
/// <summary>
/// Get the nickname of this grid, as set in the [GridInfo] config section.
/// </summary>
/// <remarks>
2009-02-16 01:22:37 +00:00
/// Threat level is Moderate because intentional abuse, for instance
/// scripts that are written to be malicious only on one grid,
/// for instance in a HG scenario, are a distinct possibility.
2011-08-08 22:22:47 +00:00
/// </remarks>
/// <returns></returns>
2009-02-16 01:22:37 +00:00
public string osGetGridNick ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridNick" ) ;
m_host . AddScriptLPS ( 1 ) ;
string nick = "hippogrid" ;
2009-12-15 15:42:51 +00:00
IConfigSource config = m_ScriptEngine . ConfigSource ;
2009-02-16 01:22:37 +00:00
if ( config . Configs [ "GridInfo" ] ! = null )
nick = config . Configs [ "GridInfo" ] . GetString ( "gridnick" , nick ) ;
return nick ;
}
public string osGetGridName ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridName" ) ;
m_host . AddScriptLPS ( 1 ) ;
string name = "the lost continent of hippo" ;
2009-12-15 15:42:51 +00:00
IConfigSource config = m_ScriptEngine . ConfigSource ;
2009-02-16 01:22:37 +00:00
if ( config . Configs [ "GridInfo" ] ! = null )
name = config . Configs [ "GridInfo" ] . GetString ( "gridname" , name ) ;
return name ;
}
public string osGetGridLoginURI ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridLoginURI" ) ;
m_host . AddScriptLPS ( 1 ) ;
string loginURI = "http://127.0.0.1:9000/" ;
2009-12-15 15:42:51 +00:00
IConfigSource config = m_ScriptEngine . ConfigSource ;
2009-02-16 01:22:37 +00:00
if ( config . Configs [ "GridInfo" ] ! = null )
loginURI = config . Configs [ "GridInfo" ] . GetString ( "login" , loginURI ) ;
return loginURI ;
}
2009-02-16 01:58:26 +00:00
public LSL_String osFormatString ( string str , LSL_List strings )
{
CheckThreatLevel ( ThreatLevel . Low , "osFormatString" ) ;
m_host . AddScriptLPS ( 1 ) ;
return String . Format ( str , strings . Data ) ;
}
public LSL_List osMatchString ( string src , string pattern , int start )
{
CheckThreatLevel ( ThreatLevel . High , "osMatchString" ) ;
m_host . AddScriptLPS ( 1 ) ;
LSL_List result = new LSL_List ( ) ;
// Normalize indices (if negative).
// After normlaization they may still be
// negative, but that is now relative to
// the start, rather than the end, of the
// sequence.
if ( start < 0 )
{
start = src . Length + start ;
}
if ( start < 0 | | start > = src . Length )
{
return result ; // empty list
}
2009-04-19 13:34:28 +00:00
2009-02-16 01:58:26 +00:00
// Find matches beginning at start position
Regex matcher = new Regex ( pattern ) ;
Match match = matcher . Match ( src , start ) ;
2011-07-09 00:24:30 +00:00
while ( match . Success )
2009-02-16 01:58:26 +00:00
{
foreach ( System . Text . RegularExpressions . Group g in match . Groups )
{
2009-04-19 13:34:28 +00:00
if ( g . Success )
2009-02-16 01:58:26 +00:00
{
2011-07-04 13:45:21 +00:00
result . Add ( new LSL_String ( g . Value ) ) ;
result . Add ( new LSL_Integer ( g . Index ) ) ;
2009-02-16 01:58:26 +00:00
}
}
2011-07-09 00:24:30 +00:00
match = match . NextMatch ( ) ;
2009-02-16 01:58:26 +00:00
}
return result ;
}
2009-06-03 12:48:04 +00:00
public string osLoadedCreationDate ( )
{
CheckThreatLevel ( ThreatLevel . Low , "osLoadedCreationDate" ) ;
m_host . AddScriptLPS ( 1 ) ;
return World . RegionInfo . RegionSettings . LoadedCreationDate ;
}
public string osLoadedCreationTime ( )
{
CheckThreatLevel ( ThreatLevel . Low , "osLoadedCreationTime" ) ;
m_host . AddScriptLPS ( 1 ) ;
return World . RegionInfo . RegionSettings . LoadedCreationTime ;
}
public string osLoadedCreationID ( )
{
CheckThreatLevel ( ThreatLevel . Low , "osLoadedCreationID" ) ;
m_host . AddScriptLPS ( 1 ) ;
return World . RegionInfo . RegionSettings . LoadedCreationID ;
}
2009-11-12 19:42:35 +00:00
2011-08-08 22:22:47 +00:00
/// <summary>
/// Get the primitive parameters of a linked prim.
/// </summary>
/// <remarks>
/// Threat level is 'Low' because certain users could possibly be tricked into
/// dropping an unverified script into one of their own objects, which could
/// then gather the physical construction details of the object and transmit it
/// to an unscrupulous third party, thus permitting unauthorized duplication of
/// the object's form.
/// </remarks>
/// <param name="linknumber"></param>
/// <param name="rules"></param>
/// <returns></returns>
2009-08-08 15:43:13 +00:00
public LSL_List osGetLinkPrimitiveParams ( int linknumber , LSL_List rules )
2009-08-07 20:51:03 +00:00
{
2009-08-08 15:43:13 +00:00
CheckThreatLevel ( ThreatLevel . High , "osGetLinkPrimitiveParams" ) ;
m_host . AddScriptLPS ( 1 ) ;
2009-08-07 20:51:03 +00:00
InitLSL ( ) ;
LSL_List retVal = new LSL_List ( ) ;
2009-08-08 15:43:13 +00:00
List < SceneObjectPart > parts = ( ( LSL_Api ) m_LSL_Api ) . GetLinkParts ( linknumber ) ;
2009-08-07 20:51:03 +00:00
foreach ( SceneObjectPart part in parts )
{
2009-08-08 15:43:13 +00:00
retVal + = ( ( LSL_Api ) m_LSL_Api ) . GetLinkPrimitiveParams ( part , rules ) ;
2009-08-07 20:51:03 +00:00
}
return retVal ;
}
2009-06-03 12:48:04 +00:00
2011-08-12 01:46:44 +00:00
public LSL_Key osNpcCreate ( string firstname , string lastname , LSL_Vector position , string notecard )
2009-08-21 01:14:55 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osNpcCreate" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
2011-08-11 23:14:06 +00:00
AvatarAppearance appearance = null ;
2011-08-12 01:46:44 +00:00
UUID id ;
if ( UUID . TryParse ( notecard , out id ) )
2011-08-11 23:14:06 +00:00
{
2011-08-12 01:46:44 +00:00
ScenePresence clonePresence = World . GetScenePresence ( id ) ;
2011-08-11 23:14:06 +00:00
if ( clonePresence ! = null )
appearance = clonePresence . Appearance ;
}
if ( appearance = = null )
{
2011-08-12 01:46:44 +00:00
string appearanceSerialized = LoadNotecard ( notecard ) ;
2011-08-11 23:14:06 +00:00
if ( appearanceSerialized ! = null )
{
OSDMap appearanceOsd = ( OSDMap ) OSDParser . DeserializeLLSDXml ( appearanceSerialized ) ;
appearance = new AvatarAppearance ( ) ;
appearance . Unpack ( appearanceOsd ) ;
}
}
if ( appearance = = null )
2011-08-11 20:43:26 +00:00
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2009-08-21 01:14:55 +00:00
UUID x = module . CreateNPC ( firstname ,
lastname ,
new Vector3 ( ( float ) position . x , ( float ) position . y , ( float ) position . z ) ,
World ,
2011-08-11 23:14:06 +00:00
appearance ) ;
2009-08-21 01:14:55 +00:00
return new LSL_Key ( x . ToString ( ) ) ;
}
2011-08-09 02:51:34 +00:00
2009-08-21 01:14:55 +00:00
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
2011-08-09 21:05:47 +00:00
/// <summary>
/// Save the current appearance of the NPC permanently to the named notecard.
/// </summary>
/// <param name="avatar"></param>
2011-08-12 01:46:44 +00:00
/// <param name="notecard">The name of the notecard to which to save the appearance.</param>
2011-08-09 21:05:47 +00:00
/// <returns>The asset ID of the notecard saved.</returns>
2011-08-12 01:46:44 +00:00
public LSL_Key osNpcSaveAppearance ( LSL_Key npc , string notecard )
2011-08-09 02:51:34 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osNpcSaveAppearance" ) ;
INPCModule npcModule = World . RequestModuleInterface < INPCModule > ( ) ;
2011-08-09 21:05:47 +00:00
if ( npcModule ! = null )
2011-08-09 02:51:34 +00:00
{
2011-08-11 21:26:47 +00:00
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2011-08-09 02:51:34 +00:00
2011-08-11 01:19:13 +00:00
if ( ! npcModule . IsNPC ( npcId , m_host . ParentGroup . Scene ) )
2011-08-09 02:51:34 +00:00
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2011-08-12 01:46:44 +00:00
return SaveAppearanceToNotecard ( npcId , notecard ) ;
2011-08-09 02:51:34 +00:00
}
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
2011-08-12 01:46:44 +00:00
public void osNpcLoadAppearance ( LSL_Key npc , string notecard )
2011-08-09 02:51:34 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osNpcLoadAppearance" ) ;
INPCModule npcModule = World . RequestModuleInterface < INPCModule > ( ) ;
if ( npcModule ! = null )
{
2011-08-11 22:28:14 +00:00
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
2011-08-09 02:51:34 +00:00
return ;
2011-08-12 01:46:44 +00:00
string appearanceSerialized = LoadNotecard ( notecard ) ;
2011-08-09 02:51:34 +00:00
OSDMap appearanceOsd = ( OSDMap ) OSDParser . DeserializeLLSDXml ( appearanceSerialized ) ;
// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
// Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
AvatarAppearance appearance = new AvatarAppearance ( ) ;
appearance . Unpack ( appearanceOsd ) ;
2011-08-11 01:19:13 +00:00
npcModule . SetNPCAppearance ( npcId , appearance , m_host . ParentGroup . Scene ) ;
2011-08-09 02:51:34 +00:00
}
}
2011-08-11 22:36:22 +00:00
public LSL_Vector osNpcGetPos ( LSL_Key npc )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcGetPos" ) ;
INPCModule npcModule = World . RequestModuleInterface < INPCModule > ( ) ;
if ( npcModule ! = null )
{
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return new LSL_Vector ( 0 , 0 , 0 ) ;
if ( ! npcModule . IsNPC ( npcId , m_host . ParentGroup . Scene ) )
return new LSL_Vector ( 0 , 0 , 0 ) ;
Vector3 pos = World . GetScenePresence ( npcId ) . AbsolutePosition ;
return new LSL_Vector ( pos . X , pos . Y , pos . Z ) ;
}
return new LSL_Vector ( 0 , 0 , 0 ) ;
}
2009-08-21 01:14:55 +00:00
public void osNpcMoveTo ( LSL_Key npc , LSL_Vector position )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcMoveTo" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
2011-08-11 22:28:14 +00:00
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return ;
2009-08-21 01:14:55 +00:00
Vector3 pos = new Vector3 ( ( float ) position . x , ( float ) position . y , ( float ) position . z ) ;
2011-08-11 22:28:14 +00:00
module . MoveToTarget ( npcId , World , pos , false , true ) ;
2011-08-10 00:47:37 +00:00
}
}
2011-08-12 00:52:12 +00:00
public void osNpcMoveToTarget ( LSL_Key npc , LSL_Vector target , int options )
2011-08-10 00:47:37 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osNpcMoveToTarget" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
2011-08-11 22:28:14 +00:00
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return ;
2011-08-12 00:52:12 +00:00
Vector3 pos = new Vector3 ( ( float ) target . x , ( float ) target . y , ( float ) target . z ) ;
2011-08-10 22:56:19 +00:00
module . MoveToTarget (
new UUID ( npc . m_string ) ,
World ,
pos ,
2011-08-11 01:19:13 +00:00
( options & ScriptBaseClass . OS_NPC_NO_FLY ) ! = 0 ,
( options & ScriptBaseClass . OS_NPC_LAND_AT_TARGET ) ! = 0 ) ;
2009-08-21 01:14:55 +00:00
}
}
2011-08-11 22:28:14 +00:00
public LSL_Rotation osNpcGetRot ( LSL_Key npc )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcGetRot" ) ;
INPCModule npcModule = World . RequestModuleInterface < INPCModule > ( ) ;
if ( npcModule ! = null )
{
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return new LSL_Rotation ( Quaternion . Identity . X , Quaternion . Identity . Y , Quaternion . Identity . Z , Quaternion . Identity . W ) ;
if ( ! npcModule . IsNPC ( npcId , m_host . ParentGroup . Scene ) )
return new LSL_Rotation ( Quaternion . Identity . X , Quaternion . Identity . Y , Quaternion . Identity . Z , Quaternion . Identity . W ) ;
ScenePresence sp = World . GetScenePresence ( npcId ) ;
Quaternion rot = sp . Rotation ;
return new LSL_Rotation ( rot . X , rot . Y , rot . Z , rot . W ) ;
}
return new LSL_Rotation ( Quaternion . Identity . X , Quaternion . Identity . Y , Quaternion . Identity . Z , Quaternion . Identity . W ) ;
}
public void osNpcSetRot ( LSL_Key npc , LSL_Rotation rotation )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcSetRot" ) ;
INPCModule npcModule = World . RequestModuleInterface < INPCModule > ( ) ;
if ( npcModule ! = null )
{
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return ;
if ( ! npcModule . IsNPC ( npcId , m_host . ParentGroup . Scene ) )
return ;
ScenePresence sp = World . GetScenePresence ( npcId ) ;
sp . Rotation = LSL_Api . Rot2Quaternion ( rotation ) ;
}
}
2011-08-12 00:32:49 +00:00
public void osNpcStopMoveToTarget ( LSL_Key npc )
2011-08-09 23:26:38 +00:00
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osNpcStopMoveTo" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
module . StopMoveToTarget ( new UUID ( npc . m_string ) , World ) ;
}
2009-08-21 01:14:55 +00:00
public void osNpcSay ( LSL_Key npc , string message )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcSay" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
module . Say ( new UUID ( npc . m_string ) , World , message ) ;
}
}
2011-10-17 00:42:31 +00:00
public void osNpcSit ( LSL_Key npc , LSL_Key target , int options )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcSit" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
module . Sit ( new UUID ( npc . m_string ) , new UUID ( target . m_string ) , World ) ;
}
}
2011-10-17 00:56:25 +00:00
public void osNpcStand ( LSL_Key npc )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcStand" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
module . Stand ( new UUID ( npc . m_string ) , World ) ;
}
}
2009-08-21 01:14:55 +00:00
public void osNpcRemove ( LSL_Key npc )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcRemove" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
module . DeleteNPC ( new UUID ( npc . m_string ) , World ) ;
}
}
2011-08-09 21:05:47 +00:00
/// <summary>
/// Save the current appearance of the script owner permanently to the named notecard.
/// </summary>
2011-08-12 01:46:44 +00:00
/// <param name="notecard">The name of the notecard to which to save the appearance.</param>
2011-08-09 21:05:47 +00:00
/// <returns>The asset ID of the notecard saved.</returns>
2011-08-12 01:46:44 +00:00
public LSL_Key osOwnerSaveAppearance ( string notecard )
2011-08-09 21:05:47 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osOwnerSaveAppearance" ) ;
2011-08-12 01:46:44 +00:00
return SaveAppearanceToNotecard ( m_host . OwnerID , notecard ) ;
2011-08-09 21:05:47 +00:00
}
2011-08-12 01:46:44 +00:00
public LSL_Key osAgentSaveAppearance ( LSL_Key avatarId , string notecard )
2011-08-11 21:26:47 +00:00
{
CheckThreatLevel ( ThreatLevel . VeryHigh , "osAgentSaveAppearance" ) ;
2011-08-12 01:46:44 +00:00
return SaveAppearanceToNotecard ( avatarId , notecard ) ;
2011-08-11 21:26:47 +00:00
}
2011-08-12 01:46:44 +00:00
protected LSL_Key SaveAppearanceToNotecard ( ScenePresence sp , string notecard )
2011-08-09 21:05:47 +00:00
{
2011-10-19 21:41:44 +00:00
IAvatarFactoryModule appearanceModule = World . RequestModuleInterface < IAvatarFactoryModule > ( ) ;
2011-08-09 21:05:47 +00:00
if ( appearanceModule ! = null )
{
2011-08-11 21:26:47 +00:00
appearanceModule . SaveBakedTextures ( sp . UUID ) ;
2011-08-09 21:05:47 +00:00
OSDMap appearancePacked = sp . Appearance . Pack ( ) ;
TaskInventoryItem item
2011-08-12 01:46:44 +00:00
= SaveNotecard ( notecard , "Avatar Appearance" , Util . GetFormattedXml ( appearancePacked as OSD ) , true ) ;
2011-08-09 21:05:47 +00:00
return new LSL_Key ( item . AssetID . ToString ( ) ) ;
}
else
{
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
}
2011-08-11 21:26:47 +00:00
2011-08-12 01:46:44 +00:00
protected LSL_Key SaveAppearanceToNotecard ( UUID avatarId , string notecard )
2011-08-11 21:26:47 +00:00
{
ScenePresence sp = World . GetScenePresence ( avatarId ) ;
if ( sp = = null | | sp . IsChildAgent )
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2011-08-12 01:46:44 +00:00
return SaveAppearanceToNotecard ( sp , notecard ) ;
2011-08-11 21:26:47 +00:00
}
2011-08-12 01:46:44 +00:00
protected LSL_Key SaveAppearanceToNotecard ( LSL_Key rawAvatarId , string notecard )
2011-08-11 21:26:47 +00:00
{
UUID avatarId ;
if ( ! UUID . TryParse ( rawAvatarId , out avatarId ) )
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2011-08-12 01:46:44 +00:00
return SaveAppearanceToNotecard ( avatarId , notecard ) ;
2011-08-11 21:26:47 +00:00
}
2009-11-12 19:42:35 +00:00
/// <summary>
/// Get current region's map texture UUID
/// </summary>
/// <returns></returns>
public LSL_Key osGetMapTexture ( )
{
CheckThreatLevel ( ThreatLevel . None , "osGetMapTexture" ) ;
return m_ScriptEngine . World . RegionInfo . RegionSettings . TerrainImageID . ToString ( ) ;
}
/// <summary>
/// Get a region's map texture UUID by region UUID or name.
/// </summary>
/// <param name="regionName"></param>
/// <returns></returns>
public LSL_Key osGetRegionMapTexture ( string regionName )
{
CheckThreatLevel ( ThreatLevel . High , "osGetRegionMapTexture" ) ;
Scene scene = m_ScriptEngine . World ;
UUID key = UUID . Zero ;
GridRegion region ;
//If string is a key, use it. Otherwise, try to locate region by name.
if ( UUID . TryParse ( regionName , out key ) )
region = scene . GridService . GetRegionByUUID ( UUID . Zero , key ) ;
else
region = scene . GridService . GetRegionByName ( UUID . Zero , regionName ) ;
// If region was found, return the regions map texture key.
if ( region ! = null )
key = region . TerrainImage ;
ScriptSleep ( 1000 ) ;
return key . ToString ( ) ;
}
2010-01-03 21:10:45 +00:00
2009-11-23 16:53:37 +00:00
/// <summary>
/// Return information regarding various simulator statistics (sim fps, physics fps, time
/// dilation, total number of prims, total number of active scripts, script lps, various
/// timing data, packets in/out, etc. Basically much the information that's shown in the
/// client's Statistics Bar (Ctrl-Shift-1)
/// </summary>
/// <returns>List of floats</returns>
2010-01-03 21:10:45 +00:00
public LSL_List osGetRegionStats ( )
{
2009-11-23 16:53:37 +00:00
CheckThreatLevel ( ThreatLevel . Moderate , "osGetRegionStats" ) ;
2009-11-22 23:10:46 +00:00
m_host . AddScriptLPS ( 1 ) ;
LSL_List ret = new LSL_List ( ) ;
2011-10-10 21:23:42 +00:00
float [ ] stats = World . StatsReporter . LastReportedSimStats ;
2010-01-03 21:10:45 +00:00
for ( int i = 0 ; i < 21 ; i + + )
{
ret . Add ( new LSL_Float ( stats [ i ] ) ) ;
}
return ret ;
}
2009-11-22 23:10:46 +00:00
2009-12-12 16:04:16 +00:00
public int osGetSimulatorMemory ( )
{
2009-12-12 16:49:22 +00:00
CheckThreatLevel ( ThreatLevel . Moderate , "osGetSimulatorMemory" ) ;
2009-12-12 16:04:16 +00:00
m_host . AddScriptLPS ( 1 ) ;
long pws = System . Diagnostics . Process . GetCurrentProcess ( ) . WorkingSet64 ;
if ( pws > Int32 . MaxValue )
return Int32 . MaxValue ;
if ( pws < 0 )
return 0 ;
return ( int ) pws ;
}
2010-01-11 15:00:16 +00:00
2011-06-28 13:21:53 +00:00
public void osSetSpeed ( string UUID , LSL_Float SpeedModifier )
2010-01-03 21:10:45 +00:00
{
CheckThreatLevel ( ThreatLevel . Moderate , "osSetSpeed" ) ;
2009-12-31 04:21:24 +00:00
m_host . AddScriptLPS ( 1 ) ;
2010-01-03 21:10:45 +00:00
ScenePresence avatar = World . GetScenePresence ( new UUID ( UUID ) ) ;
2011-06-28 13:21:53 +00:00
avatar . SpeedModifier = ( float ) SpeedModifier ;
2010-01-03 21:10:45 +00:00
}
2010-01-11 15:00:16 +00:00
2009-12-31 04:21:24 +00:00
public void osKickAvatar ( string FirstName , string SurName , string alert )
2010-01-03 21:10:45 +00:00
{
CheckThreatLevel ( ThreatLevel . Severe , "osKickAvatar" ) ;
if ( World . Permissions . CanRunConsoleCommand ( m_host . OwnerID ) )
{
2011-10-27 08:25:12 +00:00
World . ForEachRootScenePresence ( delegate ( ScenePresence sp )
2010-01-03 21:10:45 +00:00
{
2011-10-27 08:25:12 +00:00
if ( sp . Firstname = = FirstName & & sp . Lastname = = SurName )
2010-01-03 21:10:45 +00:00
{
// kick client...
if ( alert ! = null )
2010-03-19 12:51:16 +00:00
sp . ControllingClient . Kick ( alert ) ;
2010-01-03 21:10:45 +00:00
// ...and close on our side
2010-03-19 12:51:16 +00:00
sp . Scene . IncomingCloseAgent ( sp . UUID ) ;
2010-01-03 21:10:45 +00:00
}
2010-03-19 12:51:16 +00:00
} ) ;
2010-01-03 21:10:45 +00:00
}
}
2010-01-11 15:00:16 +00:00
2009-12-31 04:21:24 +00:00
public void osCauseDamage ( string avatar , double damage )
{
2010-01-03 21:10:45 +00:00
CheckThreatLevel ( ThreatLevel . High , "osCauseDamage" ) ;
m_host . AddScriptLPS ( 1 ) ;
UUID avatarId = new UUID ( avatar ) ;
Vector3 pos = m_host . GetWorldPosition ( ) ;
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
if ( presence ! = null )
{
LandData land = World . GetLandData ( ( float ) pos . X , ( float ) pos . Y ) ;
if ( ( land . Flags & ( uint ) ParcelFlags . AllowDamage ) = = ( uint ) ParcelFlags . AllowDamage )
{
float health = presence . Health ;
health - = ( float ) damage ;
presence . setHealthWithUpdate ( health ) ;
if ( health < = 0 )
{
float healthliveagain = 100 ;
presence . ControllingClient . SendAgentAlertMessage ( "You died!" , true ) ;
presence . setHealthWithUpdate ( healthliveagain ) ;
presence . Scene . TeleportClientHome ( presence . UUID , presence . ControllingClient ) ;
}
}
}
2009-12-31 04:21:24 +00:00
}
2010-01-11 15:00:16 +00:00
2009-12-31 04:21:24 +00:00
public void osCauseHealing ( string avatar , double healing )
{
2010-01-03 21:10:45 +00:00
CheckThreatLevel ( ThreatLevel . High , "osCauseHealing" ) ;
m_host . AddScriptLPS ( 1 ) ;
UUID avatarId = new UUID ( avatar ) ;
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
Vector3 pos = m_host . GetWorldPosition ( ) ;
bool result = World . ScriptDanger ( m_host . LocalId , new Vector3 ( ( float ) pos . X , ( float ) pos . Y , ( float ) pos . Z ) ) ;
if ( result )
{
if ( presence ! = null )
{
float health = presence . Health ;
health + = ( float ) healing ;
if ( health > = 100 )
{
health = 100 ;
}
presence . setHealthWithUpdate ( health ) ;
}
}
2009-12-31 04:21:24 +00:00
}
2010-06-01 23:01:56 +00:00
public LSL_List osGetPrimitiveParams ( LSL_Key prim , LSL_List rules )
{
CheckThreatLevel ( ThreatLevel . High , "osGetPrimitiveParams" ) ;
m_host . AddScriptLPS ( 1 ) ;
2011-06-25 02:13:55 +00:00
InitLSL ( ) ;
2010-06-01 23:01:56 +00:00
return m_LSL_Api . GetLinkPrimitiveParamsEx ( prim , rules ) ;
}
public void osSetPrimitiveParams ( LSL_Key prim , LSL_List rules )
{
2011-06-24 10:40:21 +00:00
CheckThreatLevel ( ThreatLevel . High , "osSetPrimitiveParams" ) ;
2010-06-01 23:01:56 +00:00
m_host . AddScriptLPS ( 1 ) ;
2011-06-25 02:13:55 +00:00
InitLSL ( ) ;
2010-06-01 23:01:56 +00:00
m_LSL_Api . SetPrimitiveParamsEx ( prim , rules ) ;
}
2010-10-17 05:47:07 +00:00
/// <summary>
/// Set parameters for light projection in host prim
/// </summary>
public void osSetProjectionParams ( bool projection , LSL_Key texture , double fov , double focus , double amb )
{
CheckThreatLevel ( ThreatLevel . High , "osSetProjectionParams" ) ;
osSetProjectionParams ( UUID . Zero . ToString ( ) , projection , texture , fov , focus , amb ) ;
}
/// <summary>
/// Set parameters for light projection with uuid of target prim
/// </summary>
public void osSetProjectionParams ( LSL_Key prim , bool projection , LSL_Key texture , double fov , double focus , double amb )
{
CheckThreatLevel ( ThreatLevel . High , "osSetProjectionParams" ) ;
m_host . AddScriptLPS ( 1 ) ;
SceneObjectPart obj = null ;
if ( prim = = UUID . Zero . ToString ( ) )
{
obj = m_host ;
}
else
{
obj = World . GetSceneObjectPart ( new UUID ( prim ) ) ;
if ( obj = = null )
return ;
}
obj . Shape . ProjectionEntry = projection ;
obj . Shape . ProjectionTextureUUID = new UUID ( texture ) ;
obj . Shape . ProjectionFOV = ( float ) fov ;
obj . Shape . ProjectionFocus = ( float ) focus ;
obj . Shape . ProjectionAmbiance = ( float ) amb ;
obj . ParentGroup . HasGroupChanged = true ;
obj . ScheduleFullUpdate ( ) ;
}
2010-06-11 15:04:54 +00:00
/// <summary>
/// Like osGetAgents but returns enough info for a radar
/// </summary>
/// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
public LSL_List osGetAvatarList ( )
{
CheckThreatLevel ( ThreatLevel . None , "osGetAvatarList" ) ;
LSL_List result = new LSL_List ( ) ;
2011-10-27 08:25:12 +00:00
World . ForEachRootScenePresence ( delegate ( ScenePresence avatar )
2010-06-11 15:04:54 +00:00
{
if ( avatar ! = null & & avatar . UUID ! = m_host . OwnerID )
{
2011-10-27 08:25:12 +00:00
result . Add ( new LSL_String ( avatar . UUID . ToString ( ) ) ) ;
OpenMetaverse . Vector3 ap = avatar . AbsolutePosition ;
result . Add ( new LSL_Vector ( ap . X , ap . Y , ap . Z ) ) ;
result . Add ( new LSL_String ( avatar . Name ) ) ;
2010-06-11 15:04:54 +00:00
}
} ) ;
2011-08-08 23:12:41 +00:00
2010-06-11 15:04:54 +00:00
return result ;
}
2010-11-17 01:45:47 +00:00
/// <summary>
/// Convert a unix time to a llGetTimestamp() like string
/// </summary>
/// <param name="unixTime"></param>
/// <returns></returns>
public LSL_String osUnixTimeToTimestamp ( long time )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osUnixTimeToTimestamp" ) ;
long baseTicks = 621355968000000000 ;
long tickResolution = 10000000 ;
long epochTicks = ( time * tickResolution ) + baseTicks ;
DateTime date = new DateTime ( epochTicks ) ;
return date . ToString ( "yyyy-MM-ddTHH:mm:ss.fffffffZ" ) ;
}
2008-05-30 12:27:06 +00:00
}
2011-08-08 22:22:47 +00:00
}