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 ;
2016-08-27 15:38:29 +00:00
using OpenSim.Region.Framework.Scenes.Scripting ;
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 ;
2013-03-26 03:40:06 +00:00
using PermissionMask = OpenSim . Framework . PermissionMask ;
2015-08-04 06:56:37 +00:00
using OpenSim.Services.Connectors.Hypergrid ;
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
{
2012-07-04 23:05:06 +00:00
private static readonly ILog m_log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2011-08-09 02:51:34 +00:00
2012-05-07 18:05:21 +00:00
public const string GridInfoServiceConfigSectionName = "GridInfoService" ;
2008-11-08 02:24:34 +00:00
internal IScriptEngine m_ScriptEngine ;
2018-09-13 11:32:55 +00:00
internal LSL_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 ;
2012-05-08 21:58:34 +00:00
internal TaskInventoryItem m_item ;
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 ;
2017-01-05 19:07:37 +00:00
internal Dictionary < string , FunctionPerms > m_FunctionPerms = new Dictionary < string , FunctionPerms > ( ) ;
2012-08-29 21:56:51 +00:00
protected IUrlModule m_UrlModule = null ;
2018-04-08 23:15:45 +00:00
protected ISoundModule m_SoundModule = null ;
2018-02-02 03:50:43 +00:00
internal IConfig m_osslconfig ;
2012-08-29 21:56:51 +00:00
2013-01-16 02:07:43 +00:00
public void Initialize (
2015-08-17 19:46:30 +00:00
IScriptEngine scriptEngine , SceneObjectPart host , TaskInventoryItem item )
2008-05-30 12:27:06 +00:00
{
2013-01-16 02:07:43 +00:00
m_ScriptEngine = scriptEngine ;
m_host = host ;
m_item = item ;
2018-02-02 03:50:43 +00:00
m_osslconfig = m_ScriptEngine . ConfigSource . Configs [ "OSSL" ] ;
if ( m_osslconfig = = null )
m_osslconfig = m_ScriptEngine . Config ;
2012-08-29 21:56:51 +00:00
m_UrlModule = m_ScriptEngine . World . RequestModuleInterface < IUrlModule > ( ) ;
2018-04-08 23:15:45 +00:00
m_SoundModule = m_ScriptEngine . World . RequestModuleInterface < ISoundModule > ( ) ;
2018-02-02 03:50:43 +00:00
if ( m_osslconfig . GetBoolean ( "AllowOSFunctions" , false ) )
2015-04-14 14:17:54 +00:00
{
2008-09-15 15:25:48 +00:00
m_OSFunctionsEnabled = true ;
2015-04-14 18:30:14 +00:00
// m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED");
2015-04-14 14:17:54 +00:00
}
2008-09-15 15:25:48 +00:00
m_ScriptDelayFactor =
m_ScriptEngine . Config . GetFloat ( "ScriptDelayFactor" , 1.0f ) ;
m_ScriptDistanceFactor =
m_ScriptEngine . Config . GetFloat ( "ScriptDistanceLimitFactor" , 1.0f ) ;
2018-02-02 03:50:43 +00:00
string risk = m_osslconfig . GetString ( "OSFunctionThreatLevel" , "VeryLow" ) ;
2008-09-15 15:25:48 +00:00
switch ( risk )
{
2012-01-06 17:37:22 +00:00
case "NoAccess" :
m_MaxThreatLevel = ThreatLevel . NoAccess ;
break ;
2008-09-15 15:25:48 +00:00
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 ;
}
2015-09-30 01:45:11 +00:00
}
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 )
{
2018-11-26 18:35:45 +00:00
throw new ScriptException ( "OSSL Runtime Error: " + msg ) ;
2008-09-15 15:25:48 +00:00
}
2012-04-23 23:03:57 +00:00
/// <summary>
/// Initialize the LSL interface.
/// </summary>
/// <remarks>
/// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
/// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
/// ScriptInstance.
/// </remarks>
2009-08-07 18:50:47 +00:00
private void InitLSL ( )
{
if ( m_LSL_Api ! = null )
return ;
2018-09-13 11:32:55 +00:00
m_LSL_Api = ( LSL_Api ) m_ScriptEngine . GetApi ( m_item . ItemID , "LSL" ) ;
2009-08-07 18:50:47 +00:00
}
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 ) ,
2018-10-20 14:38:50 +00:00
ChatTypeEnum . Shout , ScriptBaseClass . DEBUG_CHANNEL , m_host . ParentGroup . RootPart . AbsolutePosition , m_host . Name , m_host . UUID , false ) ;
2009-04-27 12:05:49 +00:00
IWorldComm wComm = m_ScriptEngine . World . RequestModuleInterface < IWorldComm > ( ) ;
2018-10-20 14:35:04 +00:00
if ( wComm ! = null )
wComm . DeliverMessage ( ChatTypeEnum . Shout , ScriptBaseClass . DEBUG_CHANNEL , m_host . Name , m_host . UUID , message ) ;
2009-04-27 12:05:49 +00:00
}
2017-04-05 14:11:19 +00:00
// Returns if OSSL is enabled. Throws a script exception if OSSL is not allowed..
2017-10-26 15:26:49 +00:00
// for safe funtions always active
2017-04-05 14:11:19 +00:00
public void CheckThreatLevel ( )
{
2017-06-30 21:39:19 +00:00
m_host . AddScriptLPS ( 1 ) ;
2017-04-05 14:11:19 +00:00
if ( ! m_OSFunctionsEnabled )
2018-01-14 00:47:12 +00:00
OSSLError ( "permission denied. All OS functions are disabled." ) ; // throws
2017-04-05 14:11:19 +00:00
}
// Returns if the function is allowed. Throws a script exception if not allowed.
2008-10-03 06:15:23 +00:00
public void CheckThreatLevel ( ThreatLevel level , string function )
2008-09-15 15:25:48 +00:00
{
2017-06-30 21:39:19 +00:00
m_host . AddScriptLPS ( 1 ) ;
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
2013-01-11 01:03:19 +00:00
string reasonWhyNot = CheckThreatLevelTest ( level , function ) ;
if ( ! String . IsNullOrEmpty ( reasonWhyNot ) )
{
OSSLError ( reasonWhyNot ) ;
}
}
// Check to see if function is allowed. Returns an empty string if function permitted
// or a string explaining why this function can't be used.
private string CheckThreatLevelTest ( ThreatLevel level , string function )
{
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 ;
2018-02-02 03:50:43 +00:00
string ownerPerm = m_osslconfig . GetString ( "Allow_" + function , "" ) ;
string creatorPerm = m_osslconfig . GetString ( "Creators_" + function , "" ) ;
2010-05-30 13:46:54 +00:00
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 ( ) ;
2017-01-07 23:12:51 +00:00
if ( current . ToUpper ( ) = = "PARCEL_GROUP_MEMBER" | | current . ToUpper ( ) = = "PARCEL_OWNER" | | current . ToUpper ( ) = = "ESTATE_MANAGER" | | current . ToUpper ( ) = = "ESTATE_OWNER" | | current . ToUpper ( ) = = "ACTIVE_GOD" | | current . ToUpper ( ) = = "GRID_GOD" | | current . ToUpper ( ) = = "GOD" )
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 )
2013-01-11 01:03:19 +00:00
return
2008-11-21 17:28:57 +00:00
String . Format (
"{0} permission denied. Allowed threat level is {1} but function threat level is {2}." ,
2013-01-11 01:03:19 +00:00
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
2013-01-11 01:03:19 +00:00
return String . Empty ;
2010-05-30 13:46:54 +00:00
}
2012-05-08 21:58:34 +00:00
UUID ownerID = m_item . OwnerID ;
2011-10-26 13:03:10 +00:00
2012-04-23 16:18:28 +00:00
//OSSL only may be used if object is in the same group as the parcel
2011-10-26 13:03:10 +00:00
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "PARCEL_GROUP_MEMBER" ) )
{
2013-03-14 23:09:59 +00:00
ILandObject land = World . LandChannel . GetLandObject ( m_host . AbsolutePosition ) ;
2011-10-26 13:03:10 +00:00
2012-05-08 21:58:34 +00:00
if ( land . LandData . GroupID = = m_item . GroupID & & land . LandData . GroupID ! = UUID . Zero )
2011-10-26 13:03:10 +00:00
{
2013-01-11 01:03:19 +00:00
return String . Empty ;
2011-10-26 13:03:10 +00:00
}
}
//Only Parcelowners may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "PARCEL_OWNER" ) )
{
2013-03-14 23:09:59 +00:00
ILandObject land = World . LandChannel . GetLandObject ( m_host . AbsolutePosition ) ;
2011-10-26 13:03:10 +00:00
if ( land . LandData . OwnerID = = ownerID )
{
2013-01-11 01:03:19 +00:00
return String . Empty ;
2011-10-26 13:03:10 +00:00
}
}
//Only Estate Managers may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "ESTATE_MANAGER" ) )
{
//Only Estate Managers may use the function
2012-04-17 00:25:41 +00:00
if ( World . RegionInfo . EstateSettings . IsEstateManagerOrOwner ( ownerID ) & & World . RegionInfo . EstateSettings . EstateOwner ! = ownerID )
2011-10-26 13:03:10 +00:00
{
2013-01-11 01:03:19 +00:00
return String . Empty ;
2011-10-26 13:03:10 +00:00
}
}
//Only regionowners may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "ESTATE_OWNER" ) )
{
if ( World . RegionInfo . EstateSettings . EstateOwner = = ownerID )
{
2013-01-11 01:03:19 +00:00
return String . Empty ;
2011-10-26 13:03:10 +00:00
}
}
2017-01-07 21:44:01 +00:00
//Only grid gods may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "GRID_GOD" ) )
2016-12-21 14:35:34 +00:00
{
2017-01-07 21:44:01 +00:00
if ( World . Permissions . IsGridGod ( ownerID ) )
2016-12-21 14:35:34 +00:00
{
return String . Empty ;
}
}
2017-01-07 23:12:51 +00:00
//Any god may use the function
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "GOD" ) )
{
if ( World . Permissions . IsAdministrator ( ownerID ) )
{
return String . Empty ;
}
}
2017-01-07 21:44:01 +00:00
//Only active gods may use the function
2017-01-07 22:51:56 +00:00
if ( m_FunctionPerms [ function ] . AllowedOwnerClasses . Contains ( "ACTIVE_GOD" ) )
2016-12-23 19:48:03 +00:00
{
2017-01-07 21:44:01 +00:00
ScenePresence sp = World . GetScenePresence ( ownerID ) ;
if ( sp ! = null & & ! sp . IsDeleted & & sp . IsGod )
2016-12-23 19:48:03 +00:00
{
2017-01-07 23:36:07 +00:00
return String . Empty ;
2016-12-23 19:48:03 +00:00
}
}
2012-05-08 21:58:34 +00:00
if ( ! m_FunctionPerms [ function ] . AllowedCreators . Contains ( m_item . CreatorID ) )
2013-01-11 01:03:19 +00:00
return (
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 ) ) ;
2012-05-08 21:58:34 +00:00
if ( m_item . CreatorID ! = ownerID )
2010-05-30 11:46:05 +00:00
{
2012-05-08 21:58:34 +00:00
if ( ( m_item . CurrentPermissions & ( uint ) PermissionMask . Modify ) ! = 0 )
2013-01-11 01:03:19 +00:00
return String . Format ( "{0} permission denied. Script permissions error." , function ) ;
2010-05-30 11:46:05 +00:00
}
2008-11-17 04:23:03 +00:00
}
2008-09-15 23:50:07 +00:00
}
2013-01-11 01:03:19 +00:00
return String . Empty ;
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 )
{
2018-09-04 21:19:30 +00:00
delay = ( int ) ( delay * m_ScriptDelayFactor ) ;
if ( delay < 10 )
2008-09-15 14:32:02 +00:00
return ;
2018-09-04 21:19:30 +00:00
if ( m_item ! = null )
m_ScriptEngine . SleepScript ( m_item . ItemID , delay ) ;
else
Thread . Sleep ( delay ) ;
2008-09-15 14:32:02 +00:00
}
2010-12-10 21:13:05 +00:00
public LSL_Integer osSetTerrainHeight ( int x , int y , double val )
{
CheckThreatLevel ( ThreatLevel . High , "osSetTerrainHeight" ) ;
2012-01-27 23:24:49 +00:00
2010-12-10 21:13:05 +00:00
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" ) ;
2012-01-27 23:24:49 +00:00
2010-12-10 21:13:05 +00:00
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 )
{
2013-11-09 04:53:37 +00:00
if ( x > ( World . RegionInfo . RegionSizeX - 1 ) | | x < 0 | | y > ( World . RegionInfo . RegionSizeY - 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 )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2010-12-10 21:13:05 +00:00
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
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
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 )
{
2013-11-09 04:53:37 +00:00
if ( x > ( World . RegionInfo . RegionSizeX - 1 ) | | x < 0 | | y > ( World . RegionInfo . RegionSizeY - 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 > ( ) ;
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 )
{
2016-05-29 23:25:06 +00:00
restartModule . AbortRestart ( "Region restart has been aborted\n" ) ;
2010-11-25 03:16:52 +00:00
return 1 ;
}
2016-05-29 23:25:06 +00:00
RegionRestart ( seconds , String . Empty ) ;
return 1 ;
}
else
{
return 0 ;
}
}
public int osRegionRestart ( double seconds , string msg )
{
CheckThreatLevel ( ThreatLevel . High , "osRegionRestart" ) ;
IRestartModule restartModule = World . RequestModuleInterface < IRestartModule > ( ) ;
if ( World . Permissions . CanIssueEstateCommand ( m_host . OwnerID , false ) & & ( restartModule ! = null ) )
{
if ( seconds < 15 )
2010-11-25 03:16:52 +00:00
{
2016-05-29 23:25:06 +00:00
restartModule . AbortRestart ( "Region restart has been aborted\n" ) ;
return 1 ;
2010-11-25 03:16:52 +00:00
}
2016-05-29 23:25:06 +00:00
RegionRestart ( seconds , msg ) ;
2008-05-30 12:27:06 +00:00
return 1 ;
}
else
{
return 0 ;
}
}
2016-05-29 23:25:06 +00:00
private void RegionRestart ( double seconds , string msg )
{
IRestartModule restartModule = World . RequestModuleInterface < IRestartModule > ( ) ;
List < int > times = new List < int > ( ) ;
while ( seconds > 0 )
{
times . Add ( ( int ) seconds ) ;
if ( seconds > 300 )
seconds - = 120 ;
else if ( seconds > 120 )
seconds - = 60 ;
else if ( seconds > 60 )
seconds - = 30 ;
else
seconds - = 15 ;
}
if ( msg = = String . Empty )
2016-05-30 17:04:19 +00:00
restartModule . ScheduleRestart ( UUID . Zero , "Region: " + World . RegionInfo . RegionName + " is about to restart.\n\nIf you stay here you will be logged out.\n\n\nTime remaining: {0}.\n" , times . ToArray ( ) , true ) ;
2016-05-29 23:25:06 +00:00
else
2016-05-30 17:04:19 +00:00
restartModule . ScheduleRestart ( UUID . Zero , msg + "\n\nTime remaining: {0}.\n" , times . ToArray ( ) , true ) ;
2016-05-29 23:25:06 +00:00
}
2008-05-30 12:27:06 +00:00
public void osRegionNotice ( string msg )
{
2018-08-27 19:36:45 +00:00
CheckThreatLevel ( ThreatLevel . High , "osRegionNotice" ) ;
2008-09-15 15:25:48 +00:00
2009-01-07 20:29:09 +00:00
IDialogModule dm = World . RequestModuleInterface < IDialogModule > ( ) ;
2018-08-27 19:36:45 +00:00
if ( dm = = null )
return ;
if ( ! World . Permissions . CanIssueEstateCommand ( m_host . OwnerID , false ) )
return ;
dm . SendGeneralAlert ( msg + "\n" ) ;
}
2018-08-30 13:51:07 +00:00
public void osRegionNotice ( LSL_Key agentID , string msg )
2018-08-27 19:36:45 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osRegionNotice" ) ;
2018-08-30 13:51:07 +00:00
if ( ! World . Permissions . CanIssueEstateCommand ( m_host . OwnerID , false ) )
2018-08-27 19:36:45 +00:00
return ;
2018-08-30 13:51:07 +00:00
IDialogModule dm = World . RequestModuleInterface < IDialogModule > ( ) ;
if ( dm = = null )
2018-08-27 19:36:45 +00:00
return ;
2018-08-30 19:09:12 +00:00
UUID avatarID ;
if ( ! UUID . TryParse ( agentID , out avatarID ) )
2018-08-27 19:36:45 +00:00
return ;
2018-08-30 19:09:12 +00:00
ScenePresence sp = null ;
if ( ! World . TryGetScenePresence ( avatarID , out sp ) )
2018-08-27 19:36:45 +00:00
return ;
2018-08-30 19:09:12 +00:00
if ( sp = = null | | sp . IsChildAgent | | sp . IsDeleted | | sp . IsInTransit | | sp . IsNPC )
2018-08-27 19:36:45 +00:00
return ;
2009-02-04 00:01:36 +00:00
2018-08-27 19:36:45 +00:00
dm . SendAlertToUser ( sp . ControllingClient , msg + "\n" , false ) ;
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
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 )
2011-10-28 23:39:01 +00:00
( ( SceneObjectGroup ) entity ) . UpdateGroupRotationR ( rotation ) ;
2009-11-05 00:08:10 +00:00
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
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 ,
2017-06-24 08:24:56 +00:00
extraParams ) ;
2008-05-30 12:27:06 +00:00
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
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 ,
2017-06-24 08:24:56 +00:00
extraParams , true , ( byte ) alpha ) ;
2008-05-30 12:27:06 +00:00
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" ) ;
if ( dynamicID = = String . Empty )
{
IDynamicTextureManager textureManager = World . RequestModuleInterface < IDynamicTextureManager > ( ) ;
UUID createdTexture =
textureManager . AddDynamicTextureURL ( World . RegionInfo . RegionID , m_host . UUID , contentType , url ,
2017-06-24 08:24:56 +00:00
extraParams , 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 )
2017-06-24 03:23:13 +00:00
{
return osSetDynamicTextureDataFace ( dynamicID , contentType , data , extraParams , timer , - 1 ) ;
}
public string osSetDynamicTextureDataFace ( string dynamicID , string contentType , string data , string extraParams ,
int timer , int face )
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureData" ) ;
2008-05-30 12:27:06 +00:00
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 ,
2017-06-24 08:24:56 +00:00
extraParams , false , 3 , 255 , face ) ;
2017-06-24 03:23:13 +00:00
2008-05-30 12:27:06 +00:00
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
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 ,
2017-06-24 08:24:56 +00:00
extraParams , true , ( byte ) alpha ) ;
2008-05-30 12:27:06 +00:00
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
{
2017-06-24 08:24:56 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osSetDynamicTextureDataBlendFace" ) ;
2009-05-22 16:22:49 +00:00
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 ,
2017-06-24 08:24:56 +00:00
extraParams , 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" ) ;
2012-04-23 16:18:28 +00:00
// For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
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 ;
}
2012-04-23 16:18:28 +00:00
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" ) ;
2011-09-01 01:09:41 +00:00
m_host . ParentGroup . RootPart . SetFloatOnWater ( floatYN ) ;
2008-05-30 12:27:06 +00:00
}
2017-06-26 01:49:20 +00:00
private bool checkAllowAgentTPbyLandOwner ( UUID agentId , Vector3 pos )
{
2017-06-26 17:26:45 +00:00
UUID hostOwner = m_host . OwnerID ;
if ( hostOwner = = agentId )
return true ;
2017-06-26 01:49:20 +00:00
if ( m_item . PermsGranter = = agentId )
{
if ( ( m_item . PermsMask & ScriptBaseClass . PERMISSION_TELEPORT ) ! = 0 )
return true ;
}
ILandObject land = World . LandChannel . GetLandObject ( pos ) ;
if ( land = = null )
return true ;
LandData landdata = land . LandData ;
if ( landdata = = null )
return true ;
if ( landdata . OwnerID = = hostOwner )
return true ;
2017-06-26 18:40:20 +00:00
EstateSettings es = World . RegionInfo . EstateSettings ;
if ( es ! = null & & es . IsEstateManagerOrOwner ( hostOwner ) )
2017-06-26 01:49:20 +00:00
return true ;
if ( ! landdata . IsGroupOwned )
return false ;
UUID landGroup = landdata . GroupID ;
if ( landGroup = = UUID . Zero )
return false ;
if ( landGroup = = m_host . GroupID )
return true ;
return false ;
}
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
/ /
2012-01-15 01:36:46 +00:00
CheckThreatLevel ( ThreatLevel . Severe , "osTeleportAgent" ) ;
2008-09-15 15:25:48 +00:00
2017-06-26 17:26:45 +00:00
TeleportAgent ( agent , regionName , position , lookat ) ;
2010-11-15 18:52:39 +00:00
}
2011-01-21 18:55:35 +00:00
private void TeleportAgent ( string agent , string regionName ,
2017-06-26 17:26:45 +00:00
LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
2010-11-15 18:52:39 +00:00
{
2017-06-26 01:49:20 +00:00
if ( String . IsNullOrEmpty ( regionName ) )
regionName = World . RegionInfo . RegionName ;
2017-06-25 23:18:46 +00:00
UUID agentId ;
2008-09-15 14:32:02 +00:00
if ( UUID . TryParse ( agent , out agentId ) )
{
ScenePresence presence = World . GetScenePresence ( agentId ) ;
2017-06-25 23:18:46 +00:00
if ( presence = = null | | presence . IsDeleted | | presence . IsInTransit )
return ;
2012-01-15 01:36:46 +00:00
2017-06-26 01:49:20 +00:00
Vector3 pos = presence . AbsolutePosition ;
2017-06-26 17:26:45 +00:00
if ( ! checkAllowAgentTPbyLandOwner ( agentId , pos ) )
2017-06-26 01:49:20 +00:00
{
ScriptSleep ( 500 ) ;
return ;
}
2017-06-25 23:18:46 +00:00
if ( regionName = = World . RegionInfo . RegionName )
{
// should be faster than going to threadpool
World . RequestTeleportLocation ( presence . ControllingClient , regionName , position ,
lookat , ( uint ) TPFlags . ViaLocation ) ;
ScriptSleep ( 500 ) ;
}
else
{
// 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 , position ,
lookat , ( uint ) TPFlags . ViaLocation ) ,
null , "OSSL_Api.TeleportAgentByRegionCoords" ) ;
ScriptSleep ( 5000 ) ;
2008-09-15 14:32:02 +00:00
}
}
}
2016-07-31 00:56:44 +00:00
public void osTeleportAgent ( string agent , int regionGridX , int regionGridY , 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
/ /
2012-01-15 01:36:46 +00:00
CheckThreatLevel ( ThreatLevel . Severe , "osTeleportAgent" ) ;
2009-02-01 17:41:33 +00:00
2017-06-26 17:26:45 +00:00
TeleportAgent ( agent , regionGridX , regionGridY , position , lookat ) ;
2010-11-15 18:52:39 +00:00
}
2016-07-31 00:56:44 +00:00
private void TeleportAgent ( string agent , int regionGridX , int regionGridY ,
2017-06-26 17:26:45 +00:00
LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
2010-11-15 18:52:39 +00:00
{
2016-07-31 00:56:44 +00:00
ulong regionHandle = Util . RegionGridLocToHandle ( ( uint ) regionGridX , ( uint ) regionGridY ) ;
2009-02-01 17:41:33 +00:00
2017-06-25 23:18:46 +00:00
UUID agentId ;
2009-02-01 17:41:33 +00:00
if ( UUID . TryParse ( agent , out agentId ) )
{
ScenePresence presence = World . GetScenePresence ( agentId ) ;
2017-06-25 23:18:46 +00:00
if ( presence = = null | | presence . IsDeleted | | presence . IsInTransit )
return ;
2011-09-07 22:55:41 +00:00
2017-06-26 01:49:20 +00:00
Vector3 pos = presence . AbsolutePosition ;
2017-06-26 17:26:45 +00:00
if ( ! checkAllowAgentTPbyLandOwner ( agentId , pos ) )
2017-06-26 01:49:20 +00:00
{
ScriptSleep ( 500 ) ;
return ;
}
2017-06-25 23:18:46 +00:00
Util . FireAndForget (
o = > World . RequestTeleportLocation (
presence . ControllingClient , regionHandle ,
position , lookat , ( uint ) TPFlags . ViaLocation ) ,
null , "OSSL_Api.TeleportAgentByRegionName" ) ;
2012-01-15 01:36:46 +00:00
2017-06-25 23:18:46 +00:00
ScriptSleep ( 5000 ) ;
2009-02-01 17:41:33 +00:00
}
}
2008-09-15 14:32:02 +00:00
public void osTeleportAgent ( string agent , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
2017-06-26 01:49:20 +00:00
{
2017-06-25 23:18:46 +00:00
UUID agentId ;
if ( UUID . TryParse ( agent , out agentId ) )
{
ScenePresence presence = World . GetScenePresence ( agentId ) ;
if ( presence = = null | | presence . IsDeleted | | presence . IsInTransit )
return ;
2017-06-26 01:49:20 +00:00
Vector3 pos = presence . AbsolutePosition ;
2017-06-26 17:26:45 +00:00
if ( ! checkAllowAgentTPbyLandOwner ( agentId , pos ) )
2017-06-26 01:49:20 +00:00
{
ScriptSleep ( 500 ) ;
return ;
}
2017-06-25 23:18:46 +00:00
World . RequestTeleportLocation ( presence . ControllingClient , World . RegionInfo . RegionName , position ,
lookat , ( uint ) TPFlags . ViaLocation ) ;
ScriptSleep ( 500 ) ;
}
2008-09-15 14:32:02 +00:00
}
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" ) ;
2017-06-26 17:26:45 +00:00
TeleportAgent ( m_host . OwnerID . ToString ( ) , regionName , position , lookat ) ;
2010-11-15 18:52:39 +00:00
}
2016-07-31 00:56:44 +00:00
public void osTeleportOwner ( int regionGridX , int regionGridY , LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
2010-11-15 18:52:39 +00:00
{
CheckThreatLevel ( ThreatLevel . None , "osTeleportOwner" ) ;
2017-06-26 17:26:45 +00:00
TeleportAgent ( m_host . OwnerID . ToString ( ) , regionGridX , regionGridY , position , lookat ) ;
2017-06-26 01:49:20 +00:00
}
public void osTeleportOwner ( LSL_Types . Vector3 position , LSL_Types . Vector3 lookat )
{
2017-06-30 21:39:19 +00:00
CheckThreatLevel ( ThreatLevel . None , "osTeleportOwner" ) ;
2017-06-26 17:26:45 +00:00
osTeleportAgent ( m_host . OwnerID . ToString ( ) , position , lookat ) ;
2010-11-15 18:52:39 +00:00
}
2014-10-10 23:10:49 +00:00
2014-10-09 13:46:17 +00:00
///<summary>
/// Allows a script IN the target prim to force an avatar to sit on it using normal methods
/// as if called by the client.
/// Silent fail if agent (or target if overloaded) not found.
/// Does work if passed key (or keys if overloaded).
/// </summary>
/// <param name="avatar"></param>
2014-10-10 23:14:35 +00:00
public void osForceOtherSit ( string avatar )
2014-10-09 13:46:17 +00:00
{
2014-10-10 23:14:35 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osForceOtherSit" ) ;
2014-10-09 13:46:17 +00:00
ForceSit ( avatar , m_host . UUID ) ;
}
2014-10-10 23:10:49 +00:00
2014-10-09 13:46:17 +00:00
/// <summary>
2014-10-10 23:14:35 +00:00
/// Overload method of osForceOtherSit(string avatar) to allow a script NOT in the target prim to force
2014-10-09 13:46:17 +00:00
/// an avatar to sit on the target prim using normal methods as if called by the client.
/// </summary>
/// <param name="avatar"></param>
/// <param name="target"></param>
2014-10-10 23:14:35 +00:00
public void osForceOtherSit ( string avatar , string target )
2014-10-09 13:46:17 +00:00
{
2014-10-10 23:14:35 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osForceOtherSit" ) ;
2014-10-09 13:46:17 +00:00
UUID targetID = new UUID ( target ) ;
2017-01-05 19:07:37 +00:00
ForceSit ( avatar , targetID ) ;
2014-10-09 13:46:17 +00:00
}
public void ForceSit ( string avatar , UUID targetID )
{
2017-01-05 19:07:37 +00:00
UUID agentID ;
2014-10-09 13:46:17 +00:00
if ( ! UUID . TryParse ( avatar , out agentID ) )
return ;
ScenePresence presence = World . GetScenePresence ( agentID ) ;
SceneObjectPart part = World . GetSceneObjectPart ( targetID ) ;
if ( presence ! = null & &
part ! = null & &
part . SitTargetAvatar = = UUID . Zero )
presence . HandleAgentRequestSit ( presence . ControllingClient ,
agentID ,
targetID ,
part . SitTargetPosition ) ;
}
2017-10-26 15:26:49 +00:00
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-11-04 00:53:51 +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
2017-06-28 01:19:27 +00:00
public string osGetAgentIP ( string agent )
{
2017-10-26 15:26:49 +00:00
CheckThreatLevel ( ThreatLevel . Severe , "osGetAgentIP" ) ;
2017-06-30 21:04:56 +00:00
if ( ! ( World . Permissions . IsGod ( m_host . OwnerID ) ) ) // user god always needed
2017-06-28 01:19:27 +00:00
return "" ;
UUID avatarID = ( UUID ) agent ;
if ( World . Entities . ContainsKey ( ( UUID ) agent ) & & World . Entities [ avatarID ] is ScenePresence )
{
ScenePresence target = ( ScenePresence ) World . Entities [ avatarID ] ;
return target . ControllingClient . RemoteEndPoint . Address . ToString ( ) ;
}
// fall through case, just return nothing
return "" ;
}
2017-06-30 21:04:56 +00:00
2008-05-30 12:27:06 +00:00
// Adam's super super custom animation functions
2018-11-26 16:45:04 +00:00
public void osAvatarPlayAnimation ( LSL_Key avatar , string animation )
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osAvatarPlayAnimation" ) ;
2015-12-25 10:43:51 +00:00
UUID avatarID ;
if ( ! UUID . TryParse ( avatar , out avatarID ) )
return ;
2017-06-30 21:04:56 +00:00
ScenePresence target = World . GetScenePresence ( avatarID ) ;
2015-12-25 10:43:51 +00:00
if ( target = = null )
return ;
UUID animID = UUID . Zero ;
m_host . TaskInventory . LockItemsForRead ( true ) ;
foreach ( KeyValuePair < UUID , TaskInventoryItem > inv in m_host . TaskInventory )
2008-05-30 12:27:06 +00:00
{
2015-12-25 10:43:51 +00:00
if ( inv . Value . Type = = ( int ) AssetType . Animation )
2009-03-15 19:45:42 +00:00
{
2015-12-25 10:43:51 +00:00
if ( inv . Value . Name = = animation )
{
animID = inv . Value . AssetID ;
break ;
}
2009-03-15 19:45:42 +00:00
}
2008-05-30 12:27:06 +00:00
}
2015-12-25 10:43:51 +00:00
m_host . TaskInventory . LockItemsForRead ( false ) ;
if ( animID = = UUID . Zero )
target . Animator . AddAnimation ( animation , m_host . UUID ) ;
else
target . Animator . AddAnimation ( animID , m_host . UUID ) ;
2008-05-30 12:27:06 +00:00
}
2018-11-26 16:45:04 +00:00
public void osAvatarStopAnimation ( LSL_Key avatar , string animation )
2008-05-30 12:27:06 +00:00
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osAvatarStopAnimation" ) ;
2018-11-26 16:45:04 +00:00
UUID avatarID ;
if ( ! UUID . TryParse ( avatar , out avatarID ) )
return ;
2012-01-06 22:59:08 +00:00
2018-11-26 16:45:04 +00:00
ScenePresence target = World . GetScenePresence ( avatarID ) ;
if ( target = = null )
return ;
2008-09-26 17:25:22 +00:00
2018-11-26 16:45:04 +00:00
UUID animID ;
if ( ! UUID . TryParse ( animation , out animID ) )
2008-05-30 12:27:06 +00:00
{
2018-11-26 16:45:04 +00:00
TaskInventoryItem item = m_host . Inventory . GetInventoryItem ( animation ) ;
if ( item ! = null & & item . Type = = ( int ) AssetType . Animation )
animID = item . AssetID ;
else
animID = UUID . Zero ;
2008-05-30 12:27:06 +00:00
}
2018-11-26 16:45:04 +00:00
if ( animID = = UUID . Zero )
target . Animator . RemoveAnimation ( animation ) ;
else
target . Animator . RemoveAnimation ( animID , true ) ;
2008-05-30 12:27:06 +00:00
}
//Texture draw functions
2017-06-24 22:04:37 +00:00
2017-06-25 01:26:36 +00:00
public string osDrawResetTransform ( string drawList )
2017-06-24 22:04:37 +00:00
{
CheckThreatLevel ( ) ;
2017-06-30 21:39:19 +00:00
2017-06-25 01:26:36 +00:00
drawList + = "ResetTransf;" ;
2017-06-24 22:04:37 +00:00
return drawList ;
}
public string osDrawRotationTransform ( string drawList , LSL_Float x )
{
CheckThreatLevel ( ) ;
2017-06-30 21:39:19 +00:00
2017-06-24 22:04:37 +00:00
drawList + = "RotTransf " + x + ";" ;
return drawList ;
}
2017-06-25 01:26:36 +00:00
public string osDrawScaleTransform ( string drawList , LSL_Float x , LSL_Float y )
2017-06-24 22:04:37 +00:00
{
CheckThreatLevel ( ) ;
2017-06-25 01:26:36 +00:00
drawList + = "ScaleTransf " + x + "," + y + ";" ;
return drawList ;
}
public string osDrawTranslationTransform ( string drawList , LSL_Float x , LSL_Float y )
{
CheckThreatLevel ( ) ;
drawList + = "TransTransf " + x + "," + y + ";" ;
2017-06-24 22:04:37 +00:00
return drawList ;
}
2008-05-30 12:27:06 +00:00
public string osMovePen ( string drawList , int x , int y )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
drawList + = "MoveTo " + x + "," + y + ";" ;
return drawList ;
}
public string osDrawLine ( string drawList , int startX , int startY , int endX , int endY )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
drawList + = "MoveTo " + startX + "," + startY + "; LineTo " + endX + "," + endY + "; " ;
return drawList ;
}
public string osDrawLine ( string drawList , int endX , int endY )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
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
drawList + = "Text " + text + "; " ;
return drawList ;
}
public string osDrawEllipse ( string drawList , int width , int height )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
drawList + = "Ellipse " + width + "," + height + "; " ;
return drawList ;
}
2017-06-24 02:21:23 +00:00
public string osDrawFilledEllipse ( string drawList , int width , int height )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2017-06-24 02:21:23 +00:00
drawList + = "FillEllipse " + width + "," + height + "; " ;
return drawList ;
}
2008-05-30 12:27:06 +00:00
public string osDrawRectangle ( string drawList , int width , int height )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
drawList + = "Rectangle " + width + "," + height + "; " ;
return drawList ;
}
public string osDrawFilledRectangle ( string drawList , int width , int height )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
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 )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2009-08-22 00:12:22 +00:00
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 )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2009-08-28 20:48:03 +00:00
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 )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
drawList + = "FontSize " + fontSize + "; " ;
return drawList ;
}
2009-08-31 07:28:56 +00:00
public string osSetFontName ( string drawList , string fontName )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2009-08-31 07:28:56 +00:00
drawList + = "FontName " + fontName + "; " ;
return drawList ;
}
2008-05-30 12:27:06 +00:00
public string osSetPenSize ( string drawList , int penSize )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
2008-05-30 12:27:06 +00:00
drawList + = "PenSize " + penSize + "; " ;
return drawList ;
}
2010-12-10 21:13:05 +00:00
public string osSetPenColor ( string drawList , string color )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2017-01-05 19:07:37 +00:00
2010-12-10 21:13:05 +00:00
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 )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
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
drawList + = "PenColour " + colour + "; " ;
return drawList ;
}
2009-08-25 13:32:45 +00:00
public string osSetPenCap ( string drawList , string direction , string type )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2009-08-25 13:32:45 +00:00
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 )
{
2017-06-24 22:04:37 +00:00
CheckThreatLevel ( ) ;
2008-09-15 15:25:48 +00:00
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 )
{
2017-06-30 21:04:56 +00:00
CheckThreatLevel ( ) ;
2009-02-18 12:56:36 +00:00
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" ) ;
2012-05-08 21:58:34 +00:00
m_host . SetScriptEvents ( m_item . ItemID , events ) ;
2008-05-30 12:27:06 +00:00
}
public void osSetRegionWaterHeight ( double height )
{
2008-09-15 15:25:48 +00:00
CheckThreatLevel ( ThreatLevel . High , "osSetRegionWaterHeight" ) ;
2012-04-13 21:32:33 +00:00
World . EventManager . TriggerRequestChangeWaterHeight ( ( float ) height ) ;
2008-05-30 12:27:06 +00:00
}
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 )
{
2012-04-13 21:32:33 +00:00
CheckThreatLevel ( ThreatLevel . High , "osSetRegionSunSettings" ) ;
2009-03-13 23:45:02 +00:00
2012-04-13 21:32:33 +00:00
while ( sunHour > 24.0 )
sunHour - = 24.0 ;
2009-04-19 13:34:28 +00:00
2012-04-13 21:32:33 +00:00
while ( sunHour < 0 )
sunHour + = 24.0 ;
2009-03-20 22:42:21 +00:00
2012-04-13 21:32:33 +00:00
World . RegionInfo . RegionSettings . UseEstateSun = useEstateSun ;
2012-12-25 08:47:45 +00:00
World . RegionInfo . RegionSettings . SunPosition = sunHour + 6 ; // LL Region Sun Hour is 6 to 30
World . RegionInfo . RegionSettings . FixedSun = sunFixed ;
2012-04-13 21:32:33 +00:00
World . RegionInfo . RegionSettings . Save ( ) ;
2009-03-13 23:45:02 +00:00
2012-12-25 08:47:45 +00:00
World . EventManager . TriggerEstateToolsSunUpdate ( World . RegionInfo . RegionHandle ) ;
2009-03-13 23:45:02 +00:00
}
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 )
{
2012-04-13 21:32:33 +00:00
CheckThreatLevel ( ThreatLevel . High , "osSetEstateSunSettings" ) ;
2009-03-20 22:42:21 +00:00
2012-04-13 21:32:33 +00:00
while ( sunHour > 24.0 )
sunHour - = 24.0 ;
2009-03-20 22:42:21 +00:00
2012-04-13 21:32:33 +00:00
while ( sunHour < 0 )
sunHour + = 24.0 ;
2009-03-20 22:42:21 +00:00
2012-04-13 21:32:33 +00:00
World . RegionInfo . EstateSettings . UseGlobalTime = ! sunFixed ;
World . RegionInfo . EstateSettings . SunPosition = sunHour ;
World . RegionInfo . EstateSettings . FixedSun = sunFixed ;
2014-06-01 17:06:26 +00:00
World . EstateDataService . StoreEstateSettings ( World . RegionInfo . EstateSettings ) ;
2012-04-13 21:32:33 +00:00
2012-12-25 08:47:45 +00:00
World . EventManager . TriggerEstateToolsSunUpdate ( World . RegionInfo . RegionHandle ) ;
2009-03-20 22:42:21 +00:00
}
/// <summary>
/// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
/// </summary>
/// <returns></returns>
public double osGetCurrentSunHour ( )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2009-03-20 22:42:21 +00:00
// 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 )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2010-12-10 21:13:05 +00:00
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
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
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" ) ;
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
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
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" ) ;
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" ) ;
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
// 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 ;
}
2014-04-26 18:32:27 +00:00
if ( ! World . Permissions . CanEditParcelProperties ( m_host . OwnerID , startLandObject , GroupPowers . LandOptions , false ) )
2010-04-29 18:57:30 +00:00
{
2017-07-12 00:44:34 +00:00
OSSLShoutError ( "script owner does not have permission to modify the parcel" ) ;
2010-04-29 18:57:30 +00:00
return ;
}
// Create a new land data object we can modify
LandData newLand = startLandObject . LandData . Copy ( ) ;
UUID uuid ;
2017-07-12 00:44:34 +00:00
EstateSettings es = World . RegionInfo . EstateSettings ;
bool changed = false ;
2017-07-12 02:47:34 +00:00
bool changedSeeAvs = false ;
2017-07-12 06:27:21 +00:00
bool changedoverlay = false ;
bool changedneedupdate = false ;
2010-04-29 18:57:30 +00:00
// 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 :
2017-07-12 00:44:34 +00:00
if ( newLand . Name ! = arg )
{
newLand . Name = arg ;
changed = true ;
}
2011-10-08 05:38:04 +00:00
break ;
case ScriptBaseClass . PARCEL_DETAILS_DESC :
2017-07-12 00:44:34 +00:00
if ( newLand . Description ! = arg )
{
newLand . Description = arg ;
changed = true ;
}
2011-10-08 05:38:04 +00:00
break ;
case ScriptBaseClass . PARCEL_DETAILS_OWNER :
2017-07-12 00:44:34 +00:00
if ( es ! = null & & ! es . IsEstateManagerOrOwner ( m_host . OwnerID ) )
{
2018-11-25 23:10:44 +00:00
OSSLShoutError ( "script owner does not have permission to modify the parcel owner" ) ;
2017-07-12 00:44:34 +00:00
}
else
{
if ( UUID . TryParse ( arg , out uuid ) )
2017-10-26 15:26:49 +00:00
{
2017-07-12 00:44:34 +00:00
if ( newLand . OwnerID ! = uuid )
{
changed = true ;
newLand . OwnerID = uuid ;
newLand . GroupID = UUID . Zero ;
}
}
}
2011-10-08 05:38:04 +00:00
break ;
case ScriptBaseClass . PARCEL_DETAILS_GROUP :
2017-07-12 00:44:34 +00:00
if ( m_host . OwnerID = = newLand . OwnerID | | es = = null | | es . IsEstateManagerOrOwner ( m_host . OwnerID ) )
{
if ( UUID . TryParse ( arg , out uuid ) )
{
if ( newLand . GroupID ! = uuid )
{
2017-07-12 00:52:01 +00:00
if ( uuid = = UUID . Zero )
2017-07-12 00:44:34 +00:00
{
changed = true ;
newLand . GroupID = uuid ;
}
2017-07-12 00:52:01 +00:00
else
{
IGroupsModule groupsModule = m_ScriptEngine . World . RequestModuleInterface < IGroupsModule > ( ) ;
GroupMembershipData member = null ;
if ( groupsModule ! = null )
member = groupsModule . GetMembershipData ( uuid , newLand . OwnerID ) ;
if ( member = = null )
2018-11-25 23:10:44 +00:00
OSSLShoutError ( string . Format ( "land owner is not member of the new group for parcel" ) ) ;
2017-07-12 00:52:01 +00:00
else
{
changed = true ;
newLand . GroupID = uuid ;
}
}
2017-07-12 00:44:34 +00:00
}
}
}
else
{
2018-11-25 23:10:44 +00:00
OSSLShoutError ( "script owner does not have permission to modify the parcel group" ) ;
2017-07-12 00:44:34 +00:00
}
2011-10-08 05:38:04 +00:00
break ;
case ScriptBaseClass . PARCEL_DETAILS_CLAIMDATE :
2017-07-12 00:44:34 +00:00
if ( es ! = null & & ! es . IsEstateManagerOrOwner ( m_host . OwnerID ) )
{
2018-11-25 23:10:44 +00:00
OSSLShoutError ( "script owner does not have permission to modify the parcel CLAIM DATE" ) ;
2017-07-12 00:44:34 +00:00
}
else
{
int date = Convert . ToInt32 ( arg ) ;
if ( date = = 0 )
date = Util . UnixTimeSinceEpoch ( ) ;
if ( newLand . ClaimDate ! = date )
{
changed = true ;
newLand . ClaimDate = date ;
}
}
2011-10-08 05:38:04 +00:00
break ;
2010-04-29 18:57:30 +00:00
2017-07-12 00:44:34 +00:00
case ScriptBaseClass . PARCEL_DETAILS_SEE_AVATARS :
bool newavs = ( Convert . ToInt32 ( arg ) ! = 0 ) ;
if ( newLand . SeeAVs ! = newavs )
{
changed = true ;
2017-07-12 02:47:34 +00:00
changedSeeAvs = true ;
2017-07-12 06:27:21 +00:00
changedoverlay = true ;
changedneedupdate = true ;
2017-07-12 00:44:34 +00:00
newLand . SeeAVs = newavs ;
}
break ;
case ScriptBaseClass . PARCEL_DETAILS_ANY_AVATAR_SOUNDS :
bool newavsounds = ( Convert . ToInt32 ( arg ) ! = 0 ) ;
if ( newLand . AnyAVSounds ! = newavsounds )
{
changed = true ;
newLand . AnyAVSounds = newavsounds ;
}
break ;
case ScriptBaseClass . PARCEL_DETAILS_GROUP_SOUNDS :
bool newgrpsounds = ( Convert . ToInt32 ( arg ) ! = 0 ) ;
if ( newLand . GroupAVSounds ! = newgrpsounds )
{
changed = true ;
newLand . GroupAVSounds = newgrpsounds ;
}
break ;
}
}
if ( changed )
2017-07-12 02:47:34 +00:00
{
2017-07-12 06:27:21 +00:00
World . LandChannel . UpdateLandObject ( newLand . LocalID , newLand ) ;
2017-07-12 02:47:34 +00:00
2017-07-12 06:27:21 +00:00
if ( changedneedupdate )
2017-07-12 02:47:34 +00:00
{
UUID parcelID = newLand . GlobalID ;
2017-07-12 06:27:21 +00:00
World . ForEachRootScenePresence ( delegate ( ScenePresence avatar )
2017-07-12 02:47:34 +00:00
{
2017-07-12 06:27:21 +00:00
if ( avatar = = null | | avatar . IsDeleted | | avatar . IsInTransit )
return ;
if ( changedSeeAvs & & avatar . currentParcelUUID = = parcelID )
2017-07-12 02:47:34 +00:00
avatar . currentParcelUUID = parcelID ; // force parcel flags review
2017-10-26 15:26:49 +00:00
2017-07-12 06:27:21 +00:00
if ( avatar . ControllingClient = = null )
return ;
// this will be needed for some things like damage etc
// if(avatar.currentParcelUUID == parcelID)
// startLandObject.SendLandUpdateToClient(avatar.ControllingClient);
if ( changedoverlay & & ! avatar . IsNPC )
World . LandChannel . SendParcelsOverlay ( avatar . ControllingClient ) ;
2017-07-12 02:47:34 +00:00
} ) ;
}
}
2010-04-29 18:57:30 +00:00
}
2009-03-13 23:45:02 +00:00
2008-05-30 12:27:06 +00:00
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" ) ;
2013-03-14 23:09:59 +00:00
ILandObject land = World . LandChannel . GetLandObject ( m_host . AbsolutePosition ) ;
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
2013-03-14 23:09:59 +00:00
ILandObject land = World . LandChannel . GetLandObject ( m_host . AbsolutePosition ) ;
2009-09-18 13:11:38 +00:00
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
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
2015-04-13 02:30:55 +00:00
public LSL_Integer osCheckODE ( )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2015-04-13 02:30:55 +00:00
LSL_Integer ret = 0 ; // false
if ( m_ScriptEngine . World . PhysicsScene ! = null )
{
string physEngine = m_ScriptEngine . World . PhysicsScene . EngineType ;
if ( physEngine = = "OpenDynamicsEngine" )
{
ret = 1 ; // true
}
}
return ret ;
}
2013-01-11 01:03:19 +00:00
public string osGetPhysicsEngineType ( )
{
// 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)
// Because it would be nice if scripts didn't blow up if the information
// about the physics engine, this function returns an empty string if
// the user does not have permission to see it. This as opposed to
// throwing an exception.
2017-06-30 21:39:19 +00:00
2013-01-11 01:03:19 +00:00
m_host . AddScriptLPS ( 1 ) ;
string ret = String . Empty ;
if ( String . IsNullOrEmpty ( CheckThreatLevelTest ( ThreatLevel . High , "osGetPhysicsEngineType" ) ) )
{
if ( m_ScriptEngine . World . PhysicsScene ! = null )
{
ret = m_ScriptEngine . World . PhysicsScene . EngineType ;
// An old physics engine might have an uninitialized engine type
if ( ret = = null )
ret = "unknown" ;
}
}
return ret ;
}
2016-07-04 07:29:26 +00:00
public string osGetPhysicsEngineName ( )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2016-07-04 07:29:26 +00:00
string ret = "NoEngine" ;
if ( m_ScriptEngine . World . PhysicsScene ! = null )
{
ret = m_ScriptEngine . World . PhysicsScene . EngineName ;
// An old physics engine might have an uninitialized engine type
if ( ret = = null )
ret = "UnknownEngine" ;
}
return ret ;
}
2017-04-05 14:11:19 +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" ) ;
2012-01-27 23:24:49 +00:00
2008-10-05 14:15:39 +00:00
return m_ScriptEngine . World . GetSimulatorVersion ( ) ;
}
2008-07-09 12:02:01 +00:00
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" ) ;
2009-02-04 00:01:36 +00:00
2012-07-16 13:47:03 +00:00
UUID objUUID ;
if ( ! UUID . TryParse ( objectUUID , out objUUID ) ) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
{
OSSLShoutError ( "osMessageObject() cannot send messages to objects with invalid UUIDs" ) ;
return ;
}
2012-09-01 01:43:04 +00:00
MessageObject ( objUUID , message ) ;
}
private void MessageObject ( UUID objUUID , string message )
{
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
2012-07-16 13:47:03 +00:00
SceneObjectPart sceneOP = World . GetSceneObjectPart ( objUUID ) ;
if ( sceneOP = = null ) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
{
OSSLShoutError ( "osMessageObject() cannot send message to " + objUUID . ToString ( ) + ", object was not found in scene." ) ;
return ;
}
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
2016-05-21 22:57:30 +00:00
/// <summary>
/// Similar to llDie but given an object UUID
/// </summary>
/// <param name="objectUUID"></param>
public void osDie ( LSL_Key objectUUID )
{
2016-12-14 16:08:25 +00:00
// CheckThreatLevel(ThreatLevel.VeryHigh, "osDie");
// if this is restricted to objects rezzed by this host level can be reduced
2017-01-05 19:07:37 +00:00
2016-12-14 16:08:25 +00:00
CheckThreatLevel ( ThreatLevel . Low , "osDie" ) ;
2016-05-21 22:57:30 +00:00
UUID objUUID ;
2016-12-14 16:08:25 +00:00
if ( ! UUID . TryParse ( objectUUID , out objUUID ) )
2016-05-21 22:57:30 +00:00
{
OSSLShoutError ( "osDie() cannot delete objects with invalid UUIDs" ) ;
return ;
}
2018-09-13 11:32:55 +00:00
InitLSL ( ) ;
2016-12-14 16:08:25 +00:00
// harakiri check
if ( objUUID = = UUID . Zero )
2016-12-14 16:31:39 +00:00
{
if ( ! m_host . ParentGroup . IsAttachment )
2018-09-13 11:32:55 +00:00
m_LSL_Api . llDie ( ) ;
2016-12-14 16:31:39 +00:00
return ;
}
2016-05-21 22:57:30 +00:00
SceneObjectGroup sceneOG = World . GetSceneObjectGroup ( objUUID ) ;
2016-12-14 16:08:25 +00:00
if ( sceneOG = = null | | sceneOG . IsDeleted )
return ;
if ( sceneOG . IsAttachment )
2016-05-21 22:57:30 +00:00
return ;
if ( sceneOG . OwnerID ! = m_host . OwnerID )
return ;
2017-01-05 19:07:37 +00:00
2016-12-14 16:08:25 +00:00
// harakiri check
if ( sceneOG . UUID = = m_host . ParentGroup . UUID )
2018-09-13 11:32:55 +00:00
{
m_LSL_Api . llDie ( ) ;
return ;
}
2016-05-21 22:57:30 +00:00
2016-12-14 16:08:25 +00:00
// restrict to objects rezzed by host
if ( sceneOG . RezzerID = = m_host . ParentGroup . UUID )
World . DeleteSceneObject ( sceneOG , false ) ;
2016-05-21 22:57:30 +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" ) ;
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 ;
2015-03-02 20:01:29 +00:00
byte [ ] a ;
byte [ ] b ;
byte [ ] c ;
2008-11-06 14:37:41 +00:00
2015-03-02 20:01:29 +00:00
b = Util . UTF8 . GetBytes ( data ) ;
2008-11-06 14:37:41 +00:00
2015-03-02 20:01:29 +00:00
a = Util . UTF8 . GetBytes (
"Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + b . Length . ToString ( ) + "\n" ) ;
c = Util . UTF8 . GetBytes ( "}" ) ;
byte [ ] d = new byte [ a . Length + b . Length + c . Length ] ;
Buffer . BlockCopy ( a , 0 , d , 0 , a . Length ) ;
Buffer . BlockCopy ( b , 0 , d , a . Length , b . Length ) ;
Buffer . BlockCopy ( c , 0 , d , a . Length + b . Length , c . Length ) ;
asset . Data = d ;
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 ( ) ;
2016-11-24 20:53:04 +00:00
taskItem . Name = name ;
taskItem . Description = 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 ;
2013-03-26 03:40:06 +00:00
taskItem . BasePermissions = ( uint ) PermissionMask . All | ( uint ) PermissionMask . Export ;
taskItem . CurrentPermissions = ( uint ) PermissionMask . All | ( uint ) PermissionMask . Export ;
2008-11-06 14:37:41 +00:00
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 ) ;
2017-05-04 11:08:10 +00:00
m_host . ParentGroup . InvalidateDeepEffectivePerms ( ) ;
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 ) ;
2012-10-25 00:07:06 +00:00
if ( assetID ! = UUID . Zero )
2011-08-09 02:51:34 +00:00
{
2012-10-25 00:07:06 +00:00
StringBuilder notecardData = new StringBuilder ( ) ;
2017-01-05 19:07:37 +00:00
2012-10-25 00:07:06 +00:00
for ( int count = 0 ; count < NotecardCache . GetLines ( assetID ) ; count + + )
{
string line = NotecardCache . GetLine ( assetID , count ) + "\n" ;
2017-01-05 19:07:37 +00:00
2012-10-25 00:07:06 +00:00
// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
2017-01-05 19:07:37 +00:00
2012-10-25 00:07:06 +00:00
notecardData . Append ( line ) ;
}
2017-01-05 19:07:37 +00:00
2012-10-25 00:07:06 +00:00
return notecardData . ToString ( ) ;
2011-08-09 02:51:34 +00:00
}
2011-08-08 23:12:41 +00:00
2012-10-25 00:07:06 +00:00
return null ;
2011-08-08 23:12:41 +00:00
}
/// <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 ;
2013-01-21 22:30:38 +00:00
bool notecardNameIsUUID = UUID . TryParse ( notecardNameOrUuid , out assetID ) ;
if ( ! notecardNameIsUUID )
2011-08-08 23:12:41 +00:00
{
2013-01-21 22:30:38 +00:00
assetID = SearchTaskInventoryForAssetId ( notecardNameOrUuid ) ;
2011-08-08 23:12:41 +00:00
}
if ( assetID = = UUID . Zero )
return UUID . Zero ;
if ( ! NotecardCache . IsCached ( assetID ) )
{
AssetBase a = World . AssetService . Get ( assetID . ToString ( ) ) ;
if ( a = = null )
2013-01-21 22:30:38 +00:00
{
2017-01-05 19:07:37 +00:00
// Whoops, it's still possible here that the notecard name was properly
2013-01-21 22:30:38 +00:00
// formatted like a UUID but isn't an asset UUID so lets look it up by name after all
assetID = SearchTaskInventoryForAssetId ( notecardNameOrUuid ) ;
if ( assetID = = UUID . Zero )
return UUID . Zero ;
if ( ! NotecardCache . IsCached ( assetID ) )
{
a = World . AssetService . Get ( assetID . ToString ( ) ) ;
if ( a = = null )
{
return UUID . Zero ;
}
}
}
2011-08-08 23:12:41 +00:00
2015-03-03 23:17:24 +00:00
NotecardCache . Cache ( assetID , a . Data ) ;
2011-08-08 23:12:41 +00:00
} ;
return assetID ;
2008-11-06 14:37:41 +00:00
}
2013-01-21 22:30:38 +00:00
protected UUID SearchTaskInventoryForAssetId ( string name )
{
UUID assetId = UUID . Zero ;
m_host . TaskInventory . LockItemsForRead ( true ) ;
foreach ( TaskInventoryItem item in m_host . TaskInventory . Values )
{
if ( item . Type = = 7 & & item . Name = = name )
{
assetId = item . AssetID ;
}
}
m_host . TaskInventory . LockItemsForRead ( false ) ;
return assetId ;
}
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" ) ;
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
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" ) ;
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" ) ;
2015-08-07 08:34:52 +00:00
IUserManagement userManager = World . RequestModuleInterface < IUserManagement > ( ) ;
if ( userManager = = null )
2009-04-09 15:04:02 +00:00
{
2015-08-07 08:34:52 +00:00
OSSLShoutError ( "osAvatarName2Key: UserManagement module not available" ) ;
return string . Empty ;
}
2018-10-20 13:10:56 +00:00
// Check local grid
2015-08-07 08:34:52 +00:00
UUID userID = userManager . GetUserIdByName ( firstname , lastname ) ;
if ( userID ! = UUID . Zero )
return userID . ToString ( ) ;
2015-08-04 06:56:37 +00:00
2018-10-20 13:10:56 +00:00
// HG ?
string realFirstName ;
string realLastName ;
string serverURI ;
2015-08-07 08:34:52 +00:00
if ( Util . ParseForeignAvatarName ( firstname , lastname , out realFirstName , out realLastName , out serverURI ) )
{
2015-08-04 06:56:37 +00:00
try
{
UserAgentServiceConnector userConnection = new UserAgentServiceConnector ( serverURI , true ) ;
if ( userConnection ! = null )
{
2015-08-07 08:34:52 +00:00
userID = userConnection . GetUUID ( realFirstName , realLastName ) ;
if ( userID ! = UUID . Zero )
2015-08-04 06:56:37 +00:00
{
2015-08-07 08:34:52 +00:00
userManager . AddUser ( userID , realFirstName , realLastName , serverURI ) ;
return userID . ToString ( ) ;
2015-08-04 06:56:37 +00:00
}
}
}
2015-08-07 08:34:52 +00:00
catch ( Exception /*e*/ )
2015-08-04 06:56:37 +00:00
{
2015-08-07 08:34:52 +00:00
// m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid ", e);
2015-08-04 06:56:37 +00:00
}
2009-04-19 13:34:28 +00:00
}
2015-08-04 06:56:37 +00:00
return UUID . Zero . ToString ( ) ;
2009-04-09 15:04:02 +00:00
}
public string osKey2Name ( string id )
{
CheckThreatLevel ( ThreatLevel . Low , "osKey2Name" ) ;
2012-01-27 23:24:49 +00:00
2009-04-09 15:04:02 +00:00
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 ) ;
2015-07-31 20:16:38 +00:00
if ( account ! = null )
2010-01-10 18:40:07 +00:00
return account . Name ;
2015-07-31 20:16:38 +00:00
if ( m_ScriptEngine . World . GridUserService ! = null )
{
GridUserInfo uInfo = m_ScriptEngine . World . GridUserService . GetGridUserInfo ( key . ToString ( ) ) ;
if ( uInfo ! = null )
{
UUID userUUID ; String gridURL ; String firstName ; String lastName ; String tmp ;
if ( Util . ParseUniversalUserIdentifier ( uInfo . UserID , out userUUID , out gridURL , out firstName , out lastName , out tmp ) )
{
string grid = new Uri ( gridURL ) . Authority ;
return firstName + "." + lastName + " @" + grid ;
}
}
2009-04-09 15:04:02 +00:00
}
2009-04-19 13:34:28 +00:00
}
2017-01-05 19:07:37 +00:00
2015-07-31 20:16:38 +00:00
return "" ;
2009-04-09 15:04:02 +00:00
}
2012-01-18 03:07:40 +00:00
private enum InfoType
{
Nick ,
Name ,
2012-01-18 03:38:36 +00:00
Login ,
2012-01-19 19:21:12 +00:00
Home ,
2012-01-18 03:38:36 +00:00
Custom
2012-01-18 03:07:40 +00:00
} ;
private string GridUserInfo ( InfoType type )
2012-01-18 03:38:36 +00:00
{
return GridUserInfo ( type , "" ) ;
}
private string GridUserInfo ( InfoType type , string key )
2012-01-18 03:07:40 +00:00
{
string retval = String . Empty ;
IConfigSource config = m_ScriptEngine . ConfigSource ;
2012-06-13 03:05:02 +00:00
string url = null ;
IConfig gridInfoConfig = config . Configs [ "GridInfo" ] ;
if ( gridInfoConfig ! = null )
url = gridInfoConfig . GetString ( "GridInfoURI" , String . Empty ) ;
2012-01-18 03:07:40 +00:00
if ( String . IsNullOrEmpty ( url ) )
return "Configuration Error!" ;
string verb = "/json_grid_info" ;
OSDMap json = new OSDMap ( ) ;
OSDMap info = WebUtil . GetFromService ( String . Format ( "{0}{1}" , url , verb ) , 3000 ) ;
if ( info [ "Success" ] ! = true )
return "Get GridInfo Failed!" ;
json = ( OSDMap ) OSDParser . DeserializeJson ( info [ "_RawResult" ] . AsString ( ) ) ;
switch ( type )
{
case InfoType . Nick :
retval = json [ "gridnick" ] ;
break ;
case InfoType . Name :
retval = json [ "gridname" ] ;
break ;
case InfoType . Login :
retval = json [ "login" ] ;
break ;
2012-01-19 19:21:12 +00:00
case InfoType . Home :
retval = json [ "home" ] ;
break ;
2012-01-18 03:38:36 +00:00
case InfoType . Custom :
retval = json [ key ] ;
break ;
2012-01-18 03:07:40 +00:00
default :
retval = "error" ;
break ;
}
return retval ;
}
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" ) ;
2012-01-18 03:07:40 +00:00
string nick = String . Empty ;
2009-12-15 15:42:51 +00:00
IConfigSource config = m_ScriptEngine . ConfigSource ;
2012-01-18 03:07:40 +00:00
2012-05-07 18:05:21 +00:00
if ( config . Configs [ GridInfoServiceConfigSectionName ] ! = null )
nick = config . Configs [ GridInfoServiceConfigSectionName ] . GetString ( "gridnick" , nick ) ;
2012-01-18 03:07:40 +00:00
if ( String . IsNullOrEmpty ( nick ) )
nick = GridUserInfo ( InfoType . Nick ) ;
2009-02-16 01:22:37 +00:00
return nick ;
}
public string osGetGridName ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridName" ) ;
2012-01-18 03:07:40 +00:00
string name = String . Empty ;
2009-12-15 15:42:51 +00:00
IConfigSource config = m_ScriptEngine . ConfigSource ;
2012-01-18 03:07:40 +00:00
2012-05-07 18:05:21 +00:00
if ( config . Configs [ GridInfoServiceConfigSectionName ] ! = null )
name = config . Configs [ GridInfoServiceConfigSectionName ] . GetString ( "gridname" , name ) ;
2012-01-18 03:07:40 +00:00
if ( String . IsNullOrEmpty ( name ) )
name = GridUserInfo ( InfoType . Name ) ;
2009-02-16 01:22:37 +00:00
return name ;
}
public string osGetGridLoginURI ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridLoginURI" ) ;
2012-01-18 03:07:40 +00:00
string loginURI = String . Empty ;
2009-12-15 15:42:51 +00:00
IConfigSource config = m_ScriptEngine . ConfigSource ;
2012-01-18 03:07:40 +00:00
2012-05-07 18:05:21 +00:00
if ( config . Configs [ GridInfoServiceConfigSectionName ] ! = null )
loginURI = config . Configs [ GridInfoServiceConfigSectionName ] . GetString ( "login" , loginURI ) ;
2012-01-18 03:07:40 +00:00
if ( String . IsNullOrEmpty ( loginURI ) )
loginURI = GridUserInfo ( InfoType . Login ) ;
2009-02-16 01:22:37 +00:00
return loginURI ;
}
2009-02-16 01:58:26 +00:00
2012-01-19 19:21:12 +00:00
public string osGetGridHomeURI ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridHomeURI" ) ;
IConfigSource config = m_ScriptEngine . ConfigSource ;
2017-01-05 19:07:37 +00:00
string HomeURI = Util . GetConfigVarFromSections < string > ( config , "HomeURI" ,
2013-02-28 04:59:16 +00:00
new string [ ] { "Startup" , "Hypergrid" } , String . Empty ) ;
2012-01-19 19:21:12 +00:00
2013-02-22 01:26:19 +00:00
if ( ! string . IsNullOrEmpty ( HomeURI ) )
return HomeURI ;
// Legacy. Remove soon!
2012-01-19 19:21:12 +00:00
if ( config . Configs [ "LoginService" ] ! = null )
HomeURI = config . Configs [ "LoginService" ] . GetString ( "SRV_HomeURI" , HomeURI ) ;
if ( String . IsNullOrEmpty ( HomeURI ) )
HomeURI = GridUserInfo ( InfoType . Home ) ;
return HomeURI ;
}
2012-03-11 03:51:28 +00:00
public string osGetGridGatekeeperURI ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridGatekeeperURI" ) ;
IConfigSource config = m_ScriptEngine . ConfigSource ;
2013-02-28 04:59:16 +00:00
string gatekeeperURI = Util . GetConfigVarFromSections < string > ( config , "GatekeeperURI" ,
new string [ ] { "Startup" , "Hypergrid" } , String . Empty ) ;
2013-02-22 01:26:19 +00:00
if ( ! string . IsNullOrEmpty ( gatekeeperURI ) )
return gatekeeperURI ;
2012-03-11 03:51:28 +00:00
2013-02-22 01:26:19 +00:00
// Legacy. Remove soon!
2012-03-11 03:51:28 +00:00
if ( config . Configs [ "GridService" ] ! = null )
gatekeeperURI = config . Configs [ "GridService" ] . GetString ( "Gatekeeper" , gatekeeperURI ) ;
return gatekeeperURI ;
}
2012-01-18 03:38:36 +00:00
public string osGetGridCustom ( string key )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetGridCustom" ) ;
string retval = String . Empty ;
IConfigSource config = m_ScriptEngine . ConfigSource ;
2012-05-07 18:05:21 +00:00
if ( config . Configs [ GridInfoServiceConfigSectionName ] ! = null )
retval = config . Configs [ GridInfoServiceConfigSectionName ] . GetString ( key , retval ) ;
2012-01-18 03:38:36 +00:00
if ( String . IsNullOrEmpty ( retval ) )
retval = GridUserInfo ( InfoType . Custom , key ) ;
return retval ;
2015-08-04 07:00:24 +00:00
}
public string osGetAvatarHomeURI ( string uuid )
{
CheckThreatLevel ( ThreatLevel . Low , "osGetAvatarHomeURI" ) ;
IUserManagement userManager = m_ScriptEngine . World . RequestModuleInterface < IUserManagement > ( ) ;
string returnValue = "" ;
if ( userManager ! = null )
{
returnValue = userManager . GetUserServerURL ( new UUID ( uuid ) , "HomeURI" ) ;
}
if ( returnValue = = "" )
{
IConfigSource config = m_ScriptEngine . ConfigSource ;
returnValue = Util . GetConfigVarFromSections < string > ( config , "HomeURI" ,
new string [ ] { "Startup" , "Hypergrid" } , String . Empty ) ;
if ( ! string . IsNullOrEmpty ( returnValue ) )
return returnValue ;
// Legacy. Remove soon!
if ( config . Configs [ "LoginService" ] ! = null )
returnValue = config . Configs [ "LoginService" ] . GetString ( "SRV_HomeURI" , returnValue ) ;
if ( String . IsNullOrEmpty ( returnValue ) )
returnValue = GridUserInfo ( InfoType . Home ) ;
}
return returnValue ;
2012-01-18 03:38:36 +00:00
}
2009-02-16 01:58:26 +00:00
public LSL_String osFormatString ( string str , LSL_List strings )
{
2012-07-05 20:10:59 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osFormatString" ) ;
2009-02-16 01:58:26 +00:00
return String . Format ( str , strings . Data ) ;
}
public LSL_List osMatchString ( string src , string pattern , int start )
{
2012-07-05 20:10:59 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osMatchString" ) ;
2009-02-16 01:58:26 +00:00
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
2012-03-01 22:49:49 +00:00
public LSL_String osReplaceString ( string src , string pattern , string replace , int count , int start )
{
2012-07-05 20:10:59 +00:00
CheckThreatLevel ( ThreatLevel . VeryLow , "osReplaceString" ) ;
2012-03-01 22:49:49 +00:00
// 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 src ;
}
// Find matches beginning at start position
Regex matcher = new Regex ( pattern ) ;
return matcher . Replace ( src , replace , count , start ) ;
}
2009-06-03 12:48:04 +00:00
public string osLoadedCreationDate ( )
{
CheckThreatLevel ( ThreatLevel . Low , "osLoadedCreationDate" ) ;
return World . RegionInfo . RegionSettings . LoadedCreationDate ;
}
public string osLoadedCreationTime ( )
{
CheckThreatLevel ( ThreatLevel . Low , "osLoadedCreationTime" ) ;
return World . RegionInfo . RegionSettings . LoadedCreationTime ;
}
public string osLoadedCreationID ( )
{
CheckThreatLevel ( ThreatLevel . Low , "osLoadedCreationID" ) ;
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" ) ;
2017-06-30 21:39:19 +00:00
2009-08-07 20:51:03 +00:00
InitLSL ( ) ;
2012-08-24 16:25:37 +00:00
// One needs to cast m_LSL_Api because we're using functions not
// on the ILSL_Api interface.
2009-08-07 20:51:03 +00:00
LSL_List retVal = new LSL_List ( ) ;
2015-08-19 21:18:40 +00:00
LSL_List remaining = new LSL_List ( ) ;
2018-09-13 11:32:55 +00:00
List < SceneObjectPart > parts = m_LSL_Api . GetLinkParts ( linknumber ) ;
2009-08-07 20:51:03 +00:00
foreach ( SceneObjectPart part in parts )
{
2018-09-13 11:32:55 +00:00
remaining = m_LSL_Api . GetPrimParams ( part , rules , ref retVal ) ;
2012-08-24 16:44:39 +00:00
}
2018-12-19 04:01:52 +00:00
while ( remaining . Length > 1 )
2012-08-24 16:44:39 +00:00
{
linknumber = remaining . GetLSLIntegerItem ( 0 ) ;
2018-09-13 11:32:55 +00:00
parts = m_LSL_Api . GetLinkParts ( linknumber ) ;
2018-12-19 04:01:52 +00:00
if ( parts . Count = = 0 )
break ;
2012-08-24 16:44:39 +00:00
2018-12-19 04:01:52 +00:00
rules = remaining . GetSublist ( 1 , - 1 ) ;
2012-08-24 16:44:39 +00:00
foreach ( SceneObjectPart part in parts )
2018-09-13 11:32:55 +00:00
remaining = m_LSL_Api . GetPrimParams ( part , rules , ref retVal ) ;
2009-08-07 20:51:03 +00:00
}
return retVal ;
}
2009-06-03 12:48:04 +00:00
2014-03-12 23:05:16 +00:00
public void osForceCreateLink ( string target , int parent )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osForceCreateLink" ) ;
InitLSL ( ) ;
2018-09-13 11:32:55 +00:00
m_LSL_Api . CreateLink ( target , parent ) ;
2014-03-12 23:05:16 +00:00
}
public void osForceBreakLink ( int linknum )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osForceBreakLink" ) ;
InitLSL ( ) ;
2018-09-13 11:32:55 +00:00
m_LSL_Api . BreakLink ( linknum ) ;
2014-03-12 23:05:16 +00:00
}
2014-03-13 00:04:20 +00:00
public void osForceBreakAllLinks ( )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osForceBreakAllLinks" ) ;
InitLSL ( ) ;
2018-09-13 11:32:55 +00:00
m_LSL_Api . BreakAllLinks ( ) ;
2014-03-13 00:04:20 +00:00
}
2012-01-27 23:17:13 +00:00
public LSL_Integer osIsNpc ( LSL_Key npc )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2012-01-27 23:17:13 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
UUID npcId ;
if ( UUID . TryParse ( npc . m_string , out npcId ) )
if ( module . IsNPC ( npcId , World ) )
return ScriptBaseClass . TRUE ;
}
return ScriptBaseClass . FALSE ;
}
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
{
2012-01-07 06:07:48 +00:00
CheckThreatLevel ( ThreatLevel . High , "osNpcCreate" ) ;
2017-01-05 19:07:37 +00:00
2015-09-30 01:45:11 +00:00
// have to get the npc module also here to set the default Not Owned
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module = = null )
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2017-01-05 19:07:37 +00:00
2015-09-30 01:45:11 +00:00
bool owned = ( module . NPCOptionFlags & NPCOptionsFlags . AllowNotOwned ) = = 0 ;
2012-01-27 23:24:49 +00:00
2016-01-01 23:41:25 +00:00
return NpcCreate ( firstname , lastname , position , notecard , owned , false , false ) ;
2012-01-06 22:35:06 +00:00
}
2009-08-21 01:14:55 +00:00
2012-01-12 19:37:30 +00:00
public LSL_Key osNpcCreate ( string firstname , string lastname , LSL_Vector position , string notecard , int options )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcCreate" ) ;
2012-01-27 23:24:49 +00:00
2012-01-28 00:00:12 +00:00
return NpcCreate (
firstname , lastname , position , notecard ,
( options & ScriptBaseClass . OS_NPC_NOT_OWNED ) = = 0 ,
2016-01-01 23:41:25 +00:00
( options & ScriptBaseClass . OS_NPC_SENSE_AS_AGENT ) ! = 0 ,
( options & ScriptBaseClass . OS_NPC_OBJECT_GROUP ) ! = 0 ) ;
2012-01-12 19:37:30 +00:00
}
2012-01-28 00:00:12 +00:00
private LSL_Key NpcCreate (
2016-01-01 23:41:25 +00:00
string firstname , string lastname , LSL_Vector position , string notecard , bool owned , bool senseAsAgent , bool hostGroupID )
2012-01-06 22:35:06 +00:00
{
2012-03-05 21:22:28 +00:00
if ( ! World . Permissions . CanRezObject ( 1 , m_host . OwnerID , new Vector3 ( ( float ) position . x , ( float ) position . y , ( float ) position . z ) ) )
2016-09-22 21:08:21 +00:00
{
OSSLError ( "no permission to rez NPC at requested location" ) ;
2012-03-05 21:22:28 +00:00
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2016-09-22 21:08:21 +00:00
}
2012-03-05 21:22:28 +00:00
2009-08-21 01:14:55 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
2016-01-01 23:41:25 +00:00
if ( module = = null )
2016-09-22 21:08:21 +00:00
{
OSSLError ( "NPC module not enabled" ) ;
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
2016-01-01 23:41:25 +00:00
string groupTitle = String . Empty ;
UUID groupID = UUID . Zero ;
AvatarAppearance appearance = null ;
// check creation options
NPCOptionsFlags createFlags = module . NPCOptionFlags ;
if ( ( createFlags & NPCOptionsFlags . AllowNotOwned ) = = 0 & & ! owned )
2009-08-21 01:14:55 +00:00
{
2016-01-01 23:41:25 +00:00
OSSLError ( "Not owned NPCs disabled" ) ;
owned = true ; // we should get here...
}
2011-08-11 23:14:06 +00:00
2016-01-01 23:41:25 +00:00
if ( ( createFlags & NPCOptionsFlags . AllowSenseAsAvatar ) = = 0 & & senseAsAgent )
{
OSSLError ( "NPC allow sense as Avatar disabled" ) ;
senseAsAgent = false ;
}
2015-09-30 01:45:11 +00:00
2016-01-01 23:41:25 +00:00
if ( hostGroupID & & m_host . GroupID ! = UUID . Zero )
{
IGroupsModule groupsModule = m_ScriptEngine . World . RequestModuleInterface < IGroupsModule > ( ) ;
if ( groupsModule ! = null )
2015-09-30 01:45:11 +00:00
{
2016-01-01 23:41:25 +00:00
GroupMembershipData member = groupsModule . GetMembershipData ( m_host . GroupID , m_host . OwnerID ) ;
if ( member = = null )
{
OSSLError ( string . Format ( "osNpcCreate: the object owner is not member of the object group" ) ) ;
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
2015-09-30 01:45:11 +00:00
2016-01-01 23:41:25 +00:00
groupID = m_host . GroupID ;
if ( ( createFlags & NPCOptionsFlags . NoNPCGroup ) ! = 0 )
{
GroupRecord grprec = groupsModule . GetGroupRecord ( m_host . GroupID ) ;
if ( grprec ! = null & & grprec . GroupName ! = "" )
groupTitle = grprec . GroupName ;
}
2015-09-30 01:45:11 +00:00
}
2016-01-01 23:41:25 +00:00
}
2015-09-30 01:45:11 +00:00
2016-01-01 23:41:25 +00:00
if ( ( createFlags & NPCOptionsFlags . NoNPCGroup ) = = 0 )
{
if ( firstname ! = String . Empty | | lastname ! = String . Empty )
2015-09-30 01:45:11 +00:00
{
2016-01-01 23:41:25 +00:00
if ( firstname ! = "Shown outfit:" )
groupTitle = "- NPC -" ;
2015-09-30 01:45:11 +00:00
}
2016-01-01 23:41:25 +00:00
}
2017-01-05 19:07:37 +00:00
2016-01-01 23:41:25 +00:00
if ( ( createFlags & NPCOptionsFlags . AllowCloneOtherAvatars ) ! = 0 )
{
UUID id ;
if ( UUID . TryParse ( notecard , out id ) )
2015-09-30 01:45:11 +00:00
{
2016-01-01 23:41:25 +00:00
ScenePresence clonePresence = World . GetScenePresence ( id ) ;
if ( clonePresence ! = null )
appearance = clonePresence . Appearance ;
2015-09-29 21:15:56 +00:00
}
2016-01-01 23:41:25 +00:00
}
2011-08-11 23:14:06 +00:00
2016-01-01 23:41:25 +00:00
if ( appearance = = null )
{
2018-10-20 14:25:28 +00:00
if ( ! string . IsNullOrWhiteSpace ( notecard ) )
2016-01-01 23:41:25 +00:00
{
2018-10-20 14:25:28 +00:00
string appearanceSerialized = LoadNotecard ( notecard ) ;
if ( appearanceSerialized = = null )
{
OSSLError ( string . Format ( "osNpcCreate: Notecard '{0}' not found." , notecard ) ) ;
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
2016-01-01 23:41:25 +00:00
try
2011-08-11 23:14:06 +00:00
{
2016-01-01 23:41:25 +00:00
OSDMap appearanceOsd = ( OSDMap ) OSDParser . DeserializeLLSDXml ( appearanceSerialized ) ;
appearance = new AvatarAppearance ( ) ;
appearance . Unpack ( appearanceOsd ) ;
2011-08-11 23:14:06 +00:00
}
2016-01-01 23:41:25 +00:00
catch
2012-10-25 02:02:00 +00:00
{
2018-10-20 14:25:28 +00:00
OSSLError ( string . Format ( "osNpcCreate: Error processing notecard '{0}'" , notecard ) ) ;
2016-01-01 23:41:25 +00:00
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
2012-10-25 02:02:00 +00:00
}
2011-08-11 23:14:06 +00:00
}
2009-08-21 01:14:55 +00:00
}
2011-08-09 02:51:34 +00:00
2016-01-01 23:41:25 +00:00
UUID ownerID = UUID . Zero ;
if ( owned )
ownerID = m_host . OwnerID ;
UUID x = module . CreateNPC ( firstname ,
lastname ,
position ,
2016-06-28 17:14:30 +00:00
UUID . Random ( ) ,
2016-01-01 23:41:25 +00:00
ownerID ,
2016-06-28 17:14:30 +00:00
groupTitle ,
groupID ,
2016-01-01 23:41:25 +00:00
senseAsAgent ,
World ,
appearance ) ;
ScenePresence sp ;
if ( World . TryGetScenePresence ( x , out sp ) )
{
sp . SendAvatarDataToAllAgents ( ) ;
}
return new LSL_Key ( x . ToString ( ) ) ;
2009-08-21 01:14:55 +00:00
}
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
2012-01-12 18:14:19 +00:00
if ( ! npcModule . CheckPermissions ( npcId , m_host . OwnerID ) )
2012-01-06 22:35:06 +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 ;
2012-01-12 19:06:46 +00:00
if ( ! npcModule . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
2011-08-12 01:46:44 +00:00
string appearanceSerialized = LoadNotecard ( notecard ) ;
2012-10-25 00:07:06 +00:00
if ( appearanceSerialized = = null )
2012-10-25 02:02:00 +00:00
OSSLError ( string . Format ( "osNpcCreate: Notecard reference '{0}' not found." , 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
}
}
2012-01-27 23:05:48 +00:00
public LSL_Key osNpcGetOwner ( LSL_Key npc )
{
CheckThreatLevel ( ThreatLevel . None , "osNpcGetOwner" ) ;
INPCModule npcModule = World . RequestModuleInterface < INPCModule > ( ) ;
if ( npcModule ! = null )
{
UUID npcId ;
if ( UUID . TryParse ( npc . m_string , out npcId ) )
{
UUID owner = npcModule . GetOwner ( npcId ) ;
if ( owner ! = UUID . Zero )
return new LSL_Key ( owner . ToString ( ) ) ;
else
return npc ;
}
}
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
}
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 ) ;
2012-01-12 19:06:46 +00:00
if ( ! npcModule . CheckPermissions ( npcId , m_host . OwnerID ) )
2011-08-11 22:36:22 +00:00
return new LSL_Vector ( 0 , 0 , 0 ) ;
2012-08-14 20:44:06 +00:00
ScenePresence sp = World . GetScenePresence ( npcId ) ;
if ( sp ! = null )
2013-03-14 23:12:58 +00:00
return new LSL_Vector ( sp . AbsolutePosition ) ;
2011-08-11 22:36:22 +00:00
}
2013-03-14 23:12:58 +00:00
return Vector3 . Zero ;
2011-08-11 22:36:22 +00:00
}
2012-08-18 00:17:01 +00:00
public void osNpcMoveTo ( LSL_Key npc , LSL_Vector pos )
2009-08-21 01:14:55 +00:00
{
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 ;
2012-01-12 19:06:46 +00:00
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
2017-01-05 19:07:37 +00:00
2012-05-07 07:08:56 +00:00
module . MoveToTarget ( npcId , World , pos , false , true , false ) ;
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 ;
2012-01-12 19:06:46 +00:00
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
2011-08-10 22:56:19 +00:00
module . MoveToTarget (
new UUID ( npc . m_string ) ,
World ,
2012-08-18 00:17:01 +00:00
target ,
2011-08-11 01:19:13 +00:00
( options & ScriptBaseClass . OS_NPC_NO_FLY ) ! = 0 ,
2012-05-07 06:54:50 +00:00
( options & ScriptBaseClass . OS_NPC_LAND_AT_TARGET ) ! = 0 ,
( options & ScriptBaseClass . OS_NPC_RUNNING ) ! = 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 ) )
2013-03-14 21:46:29 +00:00
return new LSL_Rotation ( Quaternion . Identity ) ;
2011-08-11 22:28:14 +00:00
2012-01-12 19:06:46 +00:00
if ( ! npcModule . CheckPermissions ( npcId , m_host . OwnerID ) )
2013-03-14 21:46:29 +00:00
return new LSL_Rotation ( Quaternion . Identity ) ;
2011-08-11 22:28:14 +00:00
ScenePresence sp = World . GetScenePresence ( npcId ) ;
2012-08-14 20:44:06 +00:00
if ( sp ! = null )
2013-03-14 21:46:29 +00:00
return new LSL_Rotation ( sp . GetWorldRotation ( ) ) ;
2011-08-11 22:28:14 +00:00
}
2013-03-14 23:12:58 +00:00
return Quaternion . Identity ;
2011-08-11 22:28:14 +00:00
}
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 ;
2012-01-12 19:06:46 +00:00
if ( ! npcModule . CheckPermissions ( npcId , m_host . OwnerID ) )
2011-08-11 22:28:14 +00:00
return ;
ScenePresence sp = World . GetScenePresence ( npcId ) ;
2012-08-14 20:44:06 +00:00
if ( sp ! = null )
2012-08-18 14:18:31 +00:00
sp . Rotation = rotation ;
2011-08-11 22:28:14 +00:00
}
}
2011-08-12 00:32:49 +00:00
public void osNpcStopMoveToTarget ( LSL_Key npc )
2011-08-09 23:26:38 +00:00
{
2012-04-13 21:52:24 +00:00
CheckThreatLevel ( ThreatLevel . High , "osNpcStopMoveToTarget" ) ;
2011-08-09 23:26:38 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
2012-01-12 19:06:46 +00:00
{
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
module . StopMoveToTarget ( npcId , World ) ;
}
2011-08-09 23:26:38 +00:00
}
2016-12-06 17:05:02 +00:00
public void osNpcSetProfileAbout ( LSL_Key npc , string about )
{
2016-12-14 01:31:16 +00:00
CheckThreatLevel ( ThreatLevel . Low , "osNpcSetProfileAbout" ) ;
2016-12-06 17:05:02 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
ScenePresence sp = World . GetScenePresence ( npcId ) ;
if ( sp ! = null )
( ( INPC ) ( sp . ControllingClient ) ) . profileAbout = about ;
}
}
2016-12-14 00:14:23 +00:00
public void osNpcSetProfileImage ( LSL_Key npc , string image )
{
2016-12-14 01:00:48 +00:00
CheckThreatLevel ( ThreatLevel . Low , "osNpcSetProfileImage" ) ;
2016-12-14 00:14:23 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
UUID ImageID = new UUID ( ) ;
ImageID = ScriptUtils . GetAssetIdFromItemName ( m_host , image , ( int ) AssetType . Texture ) ;
if ( ImageID = = null | | ImageID = = UUID . Zero )
{
if ( ! UUID . TryParse ( image , out ImageID ) )
return ;
}
ScenePresence sp = World . GetScenePresence ( npcId ) ;
if ( sp ! = null )
( ( INPC ) ( sp . ControllingClient ) ) . profileImage = ImageID ;
}
}
2009-08-21 01:14:55 +00:00
public void osNpcSay ( LSL_Key npc , string message )
2012-04-24 20:54:13 +00:00
{
osNpcSay ( npc , 0 , message ) ;
}
public void osNpcSay ( LSL_Key npc , int channel , string message )
2009-08-21 01:14:55 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osNpcSay" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
2012-01-12 19:06:46 +00:00
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
2012-04-24 20:54:13 +00:00
module . Say ( npcId , World , message , channel ) ;
}
}
2018-12-11 18:23:26 +00:00
public void osNpcSayTo ( LSL_Key npc , LSL_Key target , int channel , string msg )
2018-12-11 05:52:36 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osNpcSayTo" ) ;
2012-04-24 20:54:13 +00:00
2018-12-11 05:52:36 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
2018-12-11 18:23:26 +00:00
if ( module = = null )
return ;
UUID npcId ;
if ( ! UUID . TryParse ( npc . m_string , out npcId ) )
return ;
2018-12-11 05:52:36 +00:00
UUID TargetID ;
2018-12-11 18:23:26 +00:00
if ( ! UUID . TryParse ( target . m_string , out TargetID ) )
return ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
ScenePresence NPCpresence = World . GetScenePresence ( npcId ) ;
if ( NPCpresence = = null | | NPCpresence . IsDeleted | | ! NPCpresence . IsNPC )
return ;
Vector3 npcPOS = NPCpresence . AbsolutePosition ;
string npcNAME = NPCpresence . Name ;
IWorldComm wComm = m_ScriptEngine . World . RequestModuleInterface < IWorldComm > ( ) ;
2018-12-11 05:52:36 +00:00
if ( wComm ! = null )
wComm . DeliverMessageTo ( TargetID , channel , npcPOS , npcNAME , npcId , msg ) ;
}
2018-12-11 18:23:26 +00:00
2012-04-24 20:54:13 +00:00
public void osNpcShout ( LSL_Key npc , int channel , string message )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcShout" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
module . Shout ( npcId , World , message , channel ) ;
2009-08-21 01:14:55 +00:00
}
}
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 )
{
2012-01-12 19:06:46 +00:00
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
module . Sit ( npcId , new UUID ( target . m_string ) , World ) ;
2011-10-17 00:42:31 +00:00
}
}
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 )
{
2012-01-12 19:06:46 +00:00
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
module . Stand ( npcId , World ) ;
2011-10-17 00:56:25 +00:00
}
}
2009-08-21 01:14:55 +00:00
public void osNpcRemove ( LSL_Key npc )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcRemove" ) ;
2015-09-29 21:15:56 +00:00
try
{
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
2012-02-06 21:26:25 +00:00
{
2015-09-29 21:15:56 +00:00
UUID npcId = new UUID ( npc . m_string ) ;
2012-01-12 19:06:46 +00:00
2015-09-29 21:15:56 +00:00
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
2012-01-12 19:06:46 +00:00
2017-01-05 19:07:37 +00:00
module . DeleteNPC ( npcId , World ) ;
2012-02-08 12:04:23 +00:00
}
2015-09-29 21:15:56 +00:00
}
catch { }
2009-08-21 01:14:55 +00:00
}
2011-08-09 21:05:47 +00:00
2012-01-06 22:59:08 +00:00
public void osNpcPlayAnimation ( LSL_Key npc , string animation )
{
2012-01-07 11:29:59 +00:00
CheckThreatLevel ( ThreatLevel . High , "osNpcPlayAnimation" ) ;
2012-01-06 22:59:08 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
2018-11-26 16:45:04 +00:00
if ( module = = null )
return ;
UUID npcID ;
if ( ! UUID . TryParse ( npc . m_string , out npcID ) )
return ;
ScenePresence target = World . GetScenePresence ( npcID ) ;
if ( target = = null | | ! target . IsNPC )
return ;
2012-01-12 19:06:46 +00:00
2018-11-26 16:45:04 +00:00
if ( ! module . CheckPermissions ( npcID , m_host . OwnerID ) )
return ;
UUID animID = UUID . Zero ;
m_host . TaskInventory . LockItemsForRead ( true ) ;
foreach ( KeyValuePair < UUID , TaskInventoryItem > inv in m_host . TaskInventory )
{
if ( inv . Value . Type = = ( int ) AssetType . Animation )
{
if ( inv . Value . Name = = animation )
{
animID = inv . Value . AssetID ;
break ;
}
}
2012-01-06 22:59:08 +00:00
}
2018-11-26 16:45:04 +00:00
m_host . TaskInventory . LockItemsForRead ( false ) ;
if ( animID = = UUID . Zero )
target . Animator . AddAnimation ( animation , m_host . UUID ) ;
else
target . Animator . AddAnimation ( animID , m_host . UUID ) ;
2012-01-06 22:59:08 +00:00
}
public void osNpcStopAnimation ( LSL_Key npc , string animation )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcStopAnimation" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
2018-11-26 16:45:04 +00:00
if ( module = = null )
return ;
UUID npcID ;
if ( ! UUID . TryParse ( npc . m_string , out npcID ) )
return ;
ScenePresence target = World . GetScenePresence ( npcID ) ;
if ( target = = null | | ! target . IsNPC )
return ;
2012-01-12 19:06:46 +00:00
2018-11-26 16:45:04 +00:00
if ( ! module . CheckPermissions ( npcID , m_host . OwnerID ) )
return ;
UUID animID ;
if ( ! UUID . TryParse ( animation , out animID ) )
{
TaskInventoryItem item = m_host . Inventory . GetInventoryItem ( animation ) ;
if ( item ! = null & & item . Type = = ( int ) AssetType . Animation )
animID = item . AssetID ;
else
animID = UUID . Zero ;
2012-01-06 22:59:08 +00:00
}
2018-11-26 16:45:04 +00:00
if ( animID = = UUID . Zero )
target . Animator . RemoveAnimation ( animation ) ;
else
target . Animator . RemoveAnimation ( animID , true ) ;
2012-01-06 22:59:08 +00:00
}
2012-04-24 20:54:13 +00:00
public void osNpcWhisper ( LSL_Key npc , int channel , string message )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcWhisper" ) ;
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
if ( module ! = null )
{
UUID npcId = new UUID ( npc . m_string ) ;
if ( ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
module . Whisper ( npcId , World , message , channel ) ;
}
}
2012-07-03 10:10:09 +00:00
public void osNpcTouch ( LSL_Key npcLSL_Key , LSL_Key object_key , LSL_Integer link_num )
{
CheckThreatLevel ( ThreatLevel . High , "osNpcTouch" ) ;
2017-01-05 19:07:37 +00:00
2012-07-03 10:10:09 +00:00
INPCModule module = World . RequestModuleInterface < INPCModule > ( ) ;
int linkNum = link_num . value ;
if ( module ! = null | | ( linkNum < 0 & & linkNum ! = ScriptBaseClass . LINK_THIS ) )
{
UUID npcId ;
if ( ! UUID . TryParse ( npcLSL_Key , out npcId ) | | ! module . CheckPermissions ( npcId , m_host . OwnerID ) )
return ;
2012-08-14 20:44:06 +00:00
2012-07-03 10:10:09 +00:00
SceneObjectPart part = null ;
UUID objectId ;
if ( UUID . TryParse ( LSL_String . ToString ( object_key ) , out objectId ) )
part = World . GetSceneObjectPart ( objectId ) ;
2012-08-14 20:44:06 +00:00
2012-07-03 10:10:09 +00:00
if ( part = = null )
return ;
2012-08-14 20:44:06 +00:00
2012-07-03 10:10:09 +00:00
if ( linkNum ! = ScriptBaseClass . LINK_THIS )
{
if ( linkNum = = 0 | | linkNum = = ScriptBaseClass . LINK_ROOT )
{ // 0 and 1 are treated as root, find the root if the current part isnt it
if ( ! part . IsRoot )
part = part . ParentGroup . RootPart ;
}
else
{ // Find the prim with the given link number if not found then fail silently
part = part . ParentGroup . GetLinkNumPart ( linkNum ) ;
if ( part = = null )
return ;
}
}
2012-08-14 20:44:06 +00:00
2012-07-03 10:10:09 +00:00
module . Touch ( npcId , part . UUID ) ;
}
}
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 ) ;
2015-11-01 18:37:14 +00:00
EntityTransferContext ctx = new EntityTransferContext ( ) ;
OSDMap appearancePacked = sp . Appearance . Pack ( ctx ) ;
2011-08-09 21:05:47 +00:00
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
}
2015-05-30 06:02:12 +00:00
/// <summary>
/// Get the gender as specified in avatar appearance for a given avatar key
/// </summary>
/// <param name="rawAvatarId"></param>
/// <returns>"male" or "female" or "unknown"</returns>
public LSL_String osGetGender ( LSL_Key rawAvatarId )
{
CheckThreatLevel ( ThreatLevel . None , "osGetGender" ) ;
UUID avatarId ;
if ( ! UUID . TryParse ( rawAvatarId , out avatarId ) )
return new LSL_String ( "unknown" ) ;
ScenePresence sp = World . GetScenePresence ( avatarId ) ;
if ( sp = = null | | sp . IsChildAgent | | sp . Appearance = = null | | sp . Appearance . VisualParams = = null )
return new LSL_String ( "unknown" ) ;
// find the index of "shape" parameter "male"
int vpShapeMaleIndex = 0 ;
bool indexFound = false ;
VisualParam param = new VisualParam ( ) ;
foreach ( var vpEntry in VisualParams . Params )
{
param = vpEntry . Value ;
if ( param . Name = = "male" & & param . Wearable = = "shape" )
{
indexFound = true ;
break ;
}
if ( param . Group = = 0 )
vpShapeMaleIndex + + ;
}
if ( ! indexFound )
return new LSL_String ( "unknown" ) ;
float vpShapeMale = Utils . ByteToFloat ( sp . Appearance . VisualParams [ vpShapeMaleIndex ] , param . MinValue , param . MaxValue ) ;
bool isMale = vpShapeMale > 0.5f ;
return new LSL_String ( isMale ? "male" : "female" ) ;
}
2017-01-05 19:07:37 +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 ( )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2012-01-27 23:24:49 +00:00
2009-11-12 19:42:35 +00:00
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" ) ;
2012-01-27 23:24:49 +00:00
2009-11-12 19:42:35 +00:00
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 ( ) ;
}
2017-01-05 19:07:37 +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" ) ;
2017-06-30 21:39:19 +00:00
2009-11-22 23:10:46 +00:00
LSL_List ret = new LSL_List ( ) ;
2011-10-10 21:23:42 +00:00
float [ ] stats = World . StatsReporter . LastReportedSimStats ;
2017-01-05 19:07:37 +00:00
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
2014-01-15 15:38:09 +00:00
public LSL_Vector osGetRegionSize ( )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2014-01-15 15:38:09 +00:00
2016-07-27 23:34:16 +00:00
Scene scene = m_ScriptEngine . World ;
2016-11-26 03:57:33 +00:00
RegionInfo reg = World . RegionInfo ;
// GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
// return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeY, (float)Constants.RegionHeight);
return new LSL_Vector ( ( float ) reg . RegionSizeX , ( float ) reg . RegionSizeY , 0.0f ) ;
2014-01-15 15:38:09 +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" ) ;
2017-06-30 21:39:19 +00:00
2009-12-12 16:04:16 +00:00
long pws = System . Diagnostics . Process . GetCurrentProcess ( ) . WorkingSet64 ;
if ( pws > Int32 . MaxValue )
return Int32 . MaxValue ;
if ( pws < 0 )
return 0 ;
return ( int ) pws ;
}
2017-01-05 19:07:37 +00:00
2017-10-15 13:46:21 +00:00
public int osGetSimulatorMemoryKB ( )
{
2017-10-26 17:29:14 +00:00
CheckThreatLevel ( ThreatLevel . Moderate , "osGetSimulatorMemoryKB" ) ;
2017-10-15 13:46:21 +00:00
long pws = System . Diagnostics . Process . GetCurrentProcess ( ) . WorkingSet64 ;
if ( ( pws & 0x3FFL ) ! = 0 )
pws + = 0x400L ;
pws > > = 10 ;
if ( pws > Int32 . MaxValue )
return Int32 . MaxValue ;
return ( int ) pws ;
}
2018-09-29 20:40:52 +00:00
public void osSetSpeed ( string ID , LSL_Float SpeedModifier )
2010-01-03 21:10:45 +00:00
{
CheckThreatLevel ( ThreatLevel . Moderate , "osSetSpeed" ) ;
2017-06-30 21:39:19 +00:00
2018-09-29 20:40:52 +00:00
UUID avid ;
if ( ! UUID . TryParse ( ID , out avid ) )
return ;
2012-02-24 04:08:59 +00:00
2018-09-29 20:40:52 +00:00
ScenePresence avatar = World . GetScenePresence ( avid ) ;
2012-02-24 04:08:59 +00:00
if ( avatar ! = null )
avatar . SpeedModifier = ( float ) SpeedModifier ;
2010-01-03 21:10:45 +00:00
}
2018-09-29 20:40:52 +00:00
2018-09-28 08:45:33 +00:00
public void osSetOwnerSpeed ( LSL_Float SpeedModifier )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osSetOwnerSpeed" ) ;
2017-01-05 19:07:37 +00:00
2018-09-29 20:40:52 +00:00
if ( SpeedModifier > 4 )
SpeedModifier = 4 ;
ScenePresence avatar = World . GetScenePresence ( m_host . OwnerID ) ;
2018-09-28 08:45:33 +00:00
if ( avatar ! = null )
avatar . SpeedModifier = ( float ) SpeedModifier ;
}
2018-09-29 20:40:52 +00:00
2012-08-20 19:24:54 +00:00
public void osKickAvatar ( string FirstName , string SurName , string alert )
2010-01-03 21:10:45 +00:00
{
CheckThreatLevel ( ThreatLevel . Severe , "osKickAvatar" ) ;
2012-01-27 23:24:49 +00:00
2019-02-20 02:06:25 +00:00
World . ForEachRootScenePresence ( delegate ( ScenePresence sp )
2010-01-03 21:10:45 +00:00
{
2012-04-23 16:18:28 +00:00
if ( sp . Firstname = = FirstName & & sp . Lastname = = SurName )
2010-01-03 21:10:45 +00:00
{
2012-04-23 16:18:28 +00:00
// kick client...
if ( alert ! = null )
sp . ControllingClient . Kick ( alert ) ;
2010-01-03 21:10:45 +00:00
2012-04-23 16:18:28 +00:00
// ...and close on our side
2013-09-27 18:14:21 +00:00
sp . Scene . CloseAgent ( sp . UUID , false ) ;
2012-04-23 16:18:28 +00:00
}
} ) ;
2010-01-03 21:10:45 +00:00
}
2012-08-09 17:03:26 +00:00
2019-02-20 02:06:25 +00:00
public void osKickAvatar ( LSL_Key agentKey , string alert )
{
CheckThreatLevel ( ThreatLevel . Severe , "osKickAvatar" ) ;
UUID id ;
if ( ! UUID . TryParse ( agentKey , out id ) | | id = = UUID . Zero )
return ;
ScenePresence sp = World . GetScenePresence ( id ) ;
if ( sp = = null )
return ;
// kick client...
if ( alert ! = null )
sp . ControllingClient . Kick ( alert ) ;
// ...and close on our side
sp . Scene . CloseAgent ( id , false ) ;
}
public LSL_Float osGetHealth ( LSL_Key agentKey )
2012-08-09 17:03:26 +00:00
{
CheckThreatLevel ( ThreatLevel . None , "osGetHealth" ) ;
LSL_Float health = new LSL_Float ( - 1 ) ;
2019-02-20 02:06:25 +00:00
UUID id ;
if ( ! UUID . TryParse ( agentKey , out id ) | | id = = UUID . Zero )
return health ;
ScenePresence presence = World . GetScenePresence ( id ) ;
2017-01-21 06:37:29 +00:00
if ( presence ! = null )
health = presence . Health ;
2012-08-09 17:03:26 +00:00
return health ;
}
2017-01-05 19:07:37 +00:00
2019-02-20 02:06:25 +00:00
public void osCauseDamage ( LSL_Key avatar , LSL_Float damage )
2009-12-31 04:21:24 +00:00
{
2010-01-03 21:10:45 +00:00
CheckThreatLevel ( ThreatLevel . High , "osCauseDamage" ) ;
2018-09-29 20:40:52 +00:00
UUID avatarId ;
if ( ! UUID . TryParse ( avatar , out avatarId ) )
return ;
2010-01-03 21:10:45 +00:00
2017-01-05 19:07:37 +00:00
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
2018-09-29 20:40:52 +00:00
if ( presence = = null )
return ;
Vector3 pos = m_host . GetWorldPosition ( ) ;
LandData land = World . GetLandData ( pos ) ;
if ( ( land . Flags & ( uint ) ParcelFlags . AllowDamage ) = = ( uint ) ParcelFlags . AllowDamage )
2010-01-03 21:10:45 +00:00
{
2018-09-29 20:40:52 +00:00
float health = presence . Health ;
health - = ( float ) damage ;
presence . setHealthWithUpdate ( health ) ;
if ( health < = 0 )
2010-01-03 21:10:45 +00:00
{
2018-09-29 20:40:52 +00:00
float healthliveagain = 100 ;
presence . ControllingClient . SendAgentAlertMessage ( "You died!" , true ) ;
presence . setHealthWithUpdate ( healthliveagain ) ;
presence . Scene . TeleportClientHome ( presence . UUID , presence . ControllingClient ) ;
2010-01-03 21:10:45 +00:00
}
}
2009-12-31 04:21:24 +00:00
}
2017-01-05 19:07:37 +00:00
2019-02-20 02:06:25 +00:00
public void osCauseHealing ( LSL_Key avatar , LSL_Float healing )
2009-12-31 04:21:24 +00:00
{
2010-01-03 21:10:45 +00:00
CheckThreatLevel ( ThreatLevel . High , "osCauseHealing" ) ;
2018-09-29 20:40:52 +00:00
UUID avatarId ;
if ( ! UUID . TryParse ( avatar , out avatarId ) )
return ;
2010-01-03 21:10:45 +00:00
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
2018-09-29 20:40:52 +00:00
if ( presence = = null )
return ;
2013-03-14 23:16:39 +00:00
2018-09-29 20:40:52 +00:00
float health = presence . Health ;
health + = ( float ) healing ;
2013-03-14 23:16:39 +00:00
2018-09-29 20:40:52 +00:00
if ( health > = 100 )
health = 100 ;
2013-03-14 23:16:39 +00:00
2018-09-29 20:40:52 +00:00
presence . setHealthWithUpdate ( health ) ;
2009-12-31 04:21:24 +00:00
}
2010-06-01 23:01:56 +00:00
2019-02-20 02:06:25 +00:00
public void osSetHealth ( LSL_Key avatar , LSL_Float health )
2016-07-24 15:31:29 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osSetHealth" ) ;
UUID avatarId = new UUID ( avatar ) ;
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
2017-01-21 06:37:29 +00:00
if ( presence ! = null )
2016-07-24 15:31:29 +00:00
{
if ( health > 100.0 )
health = 100.0 ;
else if ( health < 1.0 )
health = 1.0 ;
presence . setHealthWithUpdate ( ( float ) health ) ;
}
}
2019-02-20 02:06:25 +00:00
public void osSetHealRate ( LSL_Key avatar , LSL_Float healrate )
2016-07-25 01:05:53 +00:00
{
CheckThreatLevel ( ThreatLevel . High , "osSetHealRate" ) ;
2018-09-29 20:40:52 +00:00
UUID avatarId ;
if ( ! UUID . TryParse ( avatar , out avatarId ) )
return ;
2016-07-25 01:05:53 +00:00
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
2018-09-29 20:40:52 +00:00
if ( presence = = null )
return ;
2016-07-25 01:05:53 +00:00
2018-09-29 20:40:52 +00:00
presence . HealRate = ( float ) healrate ;
2016-07-25 01:05:53 +00:00
}
2019-02-20 02:06:25 +00:00
public LSL_Float osGetHealRate ( LSL_Key avatar )
2016-07-25 01:05:53 +00:00
{
CheckThreatLevel ( ThreatLevel . None , "osGetHealRate" ) ;
LSL_Float rate = new LSL_Float ( 0 ) ;
2018-09-29 20:40:52 +00:00
UUID avatarId ;
if ( ! UUID . TryParse ( avatar , out avatarId ) )
return rate ;
ScenePresence presence = World . GetScenePresence ( avatarId ) ;
2016-07-25 01:05:53 +00:00
if ( presence ! = null )
rate = presence . HealRate ;
return rate ;
}
2010-06-01 23:01:56 +00:00
public LSL_List osGetPrimitiveParams ( LSL_Key prim , LSL_List rules )
{
CheckThreatLevel ( ThreatLevel . High , "osGetPrimitiveParams" ) ;
2017-01-05 19:07:37 +00:00
2017-06-30 21:39:19 +00:00
InitLSL ( ) ;
2012-08-24 15:35:59 +00:00
return m_LSL_Api . GetPrimitiveParamsEx ( prim , rules ) ;
2010-06-01 23:01:56 +00:00
}
public void osSetPrimitiveParams ( LSL_Key prim , LSL_List rules )
{
2011-06-24 10:40:21 +00:00
CheckThreatLevel ( ThreatLevel . High , "osSetPrimitiveParams" ) ;
2017-01-05 19:07:37 +00:00
2017-06-30 21:39:19 +00:00
InitLSL ( ) ;
2012-08-28 02:21:04 +00:00
m_LSL_Api . SetPrimitiveParamsEx ( prim , rules , "osSetPrimitiveParams" ) ;
2010-06-01 23:01:56 +00:00
}
2017-01-05 19:07:37 +00:00
2010-10-17 05:47:07 +00:00
/// <summary>
2017-01-05 19:07:37 +00:00
/// Set parameters for light projection in host prim
2010-10-17 05:47:07 +00:00
/// </summary>
public void osSetProjectionParams ( bool projection , LSL_Key texture , double fov , double focus , double amb )
{
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" ) ;
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-11-04 00:53:51 +00:00
World . ForEachRootScenePresence ( delegate ( ScenePresence avatar )
2010-06-11 15:04:54 +00:00
{
2017-06-26 19:55:44 +00:00
if ( avatar ! = null & & ! avatar . IsDeleted & & avatar . UUID ! = m_host . OwnerID )
2010-06-11 15:04:54 +00:00
{
2011-10-27 08:25:12 +00:00
result . Add ( new LSL_String ( avatar . UUID . ToString ( ) ) ) ;
2013-03-14 23:19:18 +00:00
result . Add ( new LSL_Vector ( avatar . AbsolutePosition ) ) ;
2011-10-27 08:25:12 +00:00
result . Add ( new LSL_String ( avatar . Name ) ) ;
2010-06-11 15:04:54 +00:00
}
} ) ;
2011-08-08 23:12:41 +00:00
2017-06-26 19:42:49 +00:00
return result ;
}
public LSL_List osGetNPCList ( )
{
CheckThreatLevel ( ThreatLevel . None , "osGetNPCList" ) ;
LSL_List result = new LSL_List ( ) ;
World . ForEachRootScenePresence ( delegate ( ScenePresence avatar )
{
2017-06-26 19:51:16 +00:00
// npcs are not childagents but that is now.
2017-06-26 19:55:44 +00:00
if ( avatar ! = null & & avatar . IsNPC & & ! avatar . IsDeleted & & ! avatar . IsChildAgent & & ! avatar . IsInTransit )
2017-06-26 19:42:49 +00:00
{
result . Add ( new LSL_String ( avatar . UUID . ToString ( ) ) ) ;
result . Add ( new LSL_Vector ( avatar . AbsolutePosition ) ) ;
result . Add ( new LSL_String ( avatar . Name ) ) ;
}
} ) ;
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>
2018-07-27 13:20:59 +00:00
public LSL_String osUnixTimeToTimestamp ( LSL_Integer time )
2010-11-17 01:45:47 +00:00
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osUnixTimeToTimestamp" ) ;
2012-01-27 23:24:49 +00:00
2010-11-17 01:45:47 +00:00
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" ) ;
}
2012-03-17 04:02:23 +00:00
2012-03-27 20:30:02 +00:00
/// <summary>
/// Invite user to the group this object is set to
/// </summary>
/// <param name="agentId"></param>
/// <returns></returns>
public LSL_Integer osInviteToGroup ( LSL_Key agentId )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osInviteToGroup" ) ;
UUID agent = new UUID ( agentId ) ;
// groups module is required
IGroupsModule groupsModule = m_ScriptEngine . World . RequestModuleInterface < IGroupsModule > ( ) ;
if ( groupsModule = = null ) return ScriptBaseClass . FALSE ;
// object has to be set to a group, but not group owned
if ( m_host . GroupID = = UUID . Zero | | m_host . GroupID = = m_host . OwnerID ) return ScriptBaseClass . FALSE ;
// object owner has to be in that group and required permissions
GroupMembershipData member = groupsModule . GetMembershipData ( m_host . GroupID , m_host . OwnerID ) ;
if ( member = = null | | ( member . GroupPowers & ( ulong ) GroupPowers . Invite ) = = 0 ) return ScriptBaseClass . FALSE ;
// check if agent is in that group already
//member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
//if (member != null) return ScriptBaseClass.FALSE;
// invited agent has to be present in this scene
if ( World . GetScenePresence ( agent ) = = null ) return ScriptBaseClass . FALSE ;
groupsModule . InviteGroup ( null , m_host . OwnerID , m_host . GroupID , agent , UUID . Zero ) ;
return ScriptBaseClass . TRUE ;
}
/// <summary>
/// Eject user from the group this object is set to
/// </summary>
/// <param name="agentId"></param>
/// <returns></returns>
public LSL_Integer osEjectFromGroup ( LSL_Key agentId )
{
CheckThreatLevel ( ThreatLevel . VeryLow , "osEjectFromGroup" ) ;
UUID agent = new UUID ( agentId ) ;
// groups module is required
IGroupsModule groupsModule = m_ScriptEngine . World . RequestModuleInterface < IGroupsModule > ( ) ;
if ( groupsModule = = null ) return ScriptBaseClass . FALSE ;
// object has to be set to a group, but not group owned
if ( m_host . GroupID = = UUID . Zero | | m_host . GroupID = = m_host . OwnerID ) return ScriptBaseClass . FALSE ;
// object owner has to be in that group and required permissions
GroupMembershipData member = groupsModule . GetMembershipData ( m_host . GroupID , m_host . OwnerID ) ;
if ( member = = null | | ( member . GroupPowers & ( ulong ) GroupPowers . Eject ) = = 0 ) return ScriptBaseClass . FALSE ;
// agent has to be in that group
//member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
//if (member == null) return ScriptBaseClass.FALSE;
// ejectee can be offline
groupsModule . EjectGroupMember ( null , m_host . OwnerID , m_host . GroupID , agent ) ;
return ScriptBaseClass . TRUE ;
}
2012-04-10 19:49:43 +00:00
/// <summary>
/// Sets terrain estate texture
/// </summary>
/// <param name="level"></param>
/// <param name="texture"></param>
/// <returns></returns>
public void osSetTerrainTexture ( int level , LSL_Key texture )
{
CheckThreatLevel ( ThreatLevel . High , "osSetTerrainTexture" ) ;
//Check to make sure that the script's owner is the estate manager/master
//World.Permissions.GenericEstatePermission(
if ( World . Permissions . IsGod ( m_host . OwnerID ) )
{
if ( level < 0 | | level > 3 )
return ;
UUID textureID = new UUID ( ) ;
if ( ! UUID . TryParse ( texture , out textureID ) )
return ;
// estate module is required
IEstateModule estate = World . RequestModuleInterface < IEstateModule > ( ) ;
if ( estate ! = null )
estate . setEstateTerrainBaseTexture ( level , textureID ) ;
}
}
/// <summary>
/// Sets terrain heights of estate
/// </summary>
/// <param name="corner"></param>
/// <param name="low"></param>
/// <param name="high"></param>
/// <returns></returns>
public void osSetTerrainTextureHeight ( int corner , double low , double high )
{
CheckThreatLevel ( ThreatLevel . High , "osSetTerrainTextureHeight" ) ;
//Check to make sure that the script's owner is the estate manager/master
//World.Permissions.GenericEstatePermission(
if ( World . Permissions . IsGod ( m_host . OwnerID ) )
{
if ( corner < 0 | | corner > 3 )
return ;
// estate module is required
IEstateModule estate = World . RequestModuleInterface < IEstateModule > ( ) ;
if ( estate ! = null )
estate . setEstateTerrainTextureHeights ( corner , ( float ) low , ( float ) high ) ;
}
}
2012-04-23 23:03:57 +00:00
2012-09-01 01:45:07 +00:00
#region Attachment commands
2012-04-23 23:03:57 +00:00
public void osForceAttachToAvatar ( int attachmentPoint )
{
CheckThreatLevel ( ThreatLevel . High , "osForceAttachToAvatar" ) ;
InitLSL ( ) ;
2018-09-13 11:32:55 +00:00
m_LSL_Api . AttachToAvatar ( attachmentPoint ) ;
2012-04-23 23:03:57 +00:00
}
2012-07-04 23:05:06 +00:00
public void osForceAttachToAvatarFromInventory ( string itemName , int attachmentPoint )
{
CheckThreatLevel ( ThreatLevel . High , "osForceAttachToAvatarFromInventory" ) ;
2012-07-09 22:08:41 +00:00
ForceAttachToAvatarFromInventory ( m_host . OwnerID , itemName , attachmentPoint ) ;
}
public void osForceAttachToOtherAvatarFromInventory ( string rawAvatarId , string itemName , int attachmentPoint )
{
2014-10-08 22:35:25 +00:00
CheckThreatLevel ( ThreatLevel . VeryHigh , "osForceAttachToOtherAvatarFromInventory" ) ;
2012-07-09 22:08:41 +00:00
UUID avatarId ;
if ( ! UUID . TryParse ( rawAvatarId , out avatarId ) )
return ;
ForceAttachToAvatarFromInventory ( avatarId , itemName , attachmentPoint ) ;
}
public void ForceAttachToAvatarFromInventory ( UUID avatarId , string itemName , int attachmentPoint )
{
2012-07-04 23:05:06 +00:00
IAttachmentsModule attachmentsModule = m_ScriptEngine . World . AttachmentsModule ;
if ( attachmentsModule = = null )
return ;
InitLSL ( ) ;
TaskInventoryItem item = m_host . Inventory . GetInventoryItem ( itemName ) ;
if ( item = = null )
{
2018-09-13 11:32:55 +00:00
m_LSL_Api . llSay ( 0 , string . Format ( "Could not find object '{0}'" , itemName ) ) ;
2012-07-04 23:05:06 +00:00
throw new Exception ( String . Format ( "The inventory item '{0}' could not be found" , itemName ) ) ;
}
if ( item . InvType ! = ( int ) InventoryType . Object )
{
// FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
2017-01-05 19:07:37 +00:00
// up the api reference.
2012-07-04 23:05:06 +00:00
if ( m_LSL_Api ! = null )
2018-09-13 11:32:55 +00:00
m_LSL_Api . llSay ( 0 , string . Format ( "Unable to attach, item '{0}' is not an object." , itemName ) ) ;
2012-07-04 23:05:06 +00:00
throw new Exception ( String . Format ( "The inventory item '{0}' is not an object" , itemName ) ) ;
}
2012-07-09 22:08:41 +00:00
ScenePresence sp = World . GetScenePresence ( avatarId ) ;
2012-07-04 23:05:06 +00:00
if ( sp = = null )
return ;
2014-05-05 12:59:24 +00:00
string message ;
InventoryItemBase newItem = World . MoveTaskInventoryItem ( sp . UUID , UUID . Zero , m_host , item . ItemID , out message ) ;
2012-07-04 23:05:06 +00:00
if ( newItem = = null )
{
m_log . ErrorFormat (
2014-05-05 12:59:24 +00:00
"[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}" ,
itemName , m_host . Name , attachmentPoint , World . Name , message ) ;
2018-09-13 11:32:55 +00:00
m_LSL_Api . llSay ( 0 , message ) ;
2012-07-04 23:05:06 +00:00
return ;
}
attachmentsModule . RezSingleAttachmentFromInventory ( sp , newItem . ID , ( uint ) attachmentPoint ) ;
}
2012-04-23 23:03:57 +00:00
public void osForceDetachFromAvatar ( )
{
CheckThreatLevel ( ThreatLevel . High , "osForceDetachFromAvatar" ) ;
InitLSL ( ) ;
2018-09-13 11:32:55 +00:00
m_LSL_Api . DetachFromAvatar ( ) ;
2012-04-23 23:03:57 +00:00
}
2012-07-20 17:25:50 +00:00
2012-09-01 01:39:49 +00:00
public LSL_List osGetNumberOfAttachments ( LSL_Key avatar , LSL_List attachmentPoints )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osGetNumberOfAttachments" ) ;
UUID targetUUID ;
ScenePresence target ;
LSL_List resp = new LSL_List ( ) ;
if ( attachmentPoints . Length > = 1 & & UUID . TryParse ( avatar . ToString ( ) , out targetUUID ) & & World . TryGetScenePresence ( targetUUID , out target ) )
{
foreach ( object point in attachmentPoints . Data )
{
LSL_Integer ipoint = new LSL_Integer (
( point is LSL_Integer | | point is int | | point is uint ) ?
( int ) point :
0
) ;
resp . Add ( ipoint ) ;
if ( ipoint = = 0 )
{
// indicates zero attachments
resp . Add ( new LSL_Integer ( 0 ) ) ;
}
else
{
// gets the number of attachments on the attachment point
resp . Add ( new LSL_Integer ( target . GetAttachments ( ( uint ) ipoint ) . Count ) ) ;
}
}
}
return resp ;
}
2012-09-01 01:44:11 +00:00
public void osMessageAttachments ( LSL_Key avatar , string message , LSL_List attachmentPoints , int options )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osMessageAttachments" ) ;
UUID targetUUID ;
2016-09-22 16:05:05 +00:00
if ( ! UUID . TryParse ( avatar . ToString ( ) , out targetUUID ) )
return ;
2017-01-05 19:07:37 +00:00
2016-09-22 16:05:05 +00:00
if ( targetUUID = = UUID . Zero )
return ;
2017-01-05 19:07:37 +00:00
2012-09-01 01:44:11 +00:00
ScenePresence target ;
2016-09-22 16:05:05 +00:00
if ( ! World . TryGetScenePresence ( targetUUID , out target ) )
return ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
if ( target . IsDeleted | | target . IsInTransit )
return ;
List < int > aps = new List < int > ( ) ;
if ( attachmentPoints . Length ! = 0 )
2012-09-01 01:44:11 +00:00
{
foreach ( object point in attachmentPoints . Data )
{
int ipoint ;
if ( int . TryParse ( point . ToString ( ) , out ipoint ) )
{
aps . Add ( ipoint ) ;
}
}
2016-09-22 16:05:05 +00:00
// parsing failed
if ( aps . Count ! = attachmentPoints . Length )
return ;
}
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
List < SceneObjectGroup > attachments = new List < SceneObjectGroup > ( ) ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
bool msgAll ;
bool invertPoints = ( options & ScriptBaseClass . OS_ATTACH_MSG_INVERT_POINTS ) ! = 0 ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
if ( aps . Count = = 0 )
{
if ( ! invertPoints )
2012-09-01 01:44:11 +00:00
return ;
2016-09-22 16:05:05 +00:00
msgAll = true ;
invertPoints = false ;
}
else
msgAll = aps . Contains ( ScriptBaseClass . OS_ATTACH_MSG_ALL ) ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
if ( msgAll & & invertPoints )
return ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
if ( msgAll | | invertPoints )
{
attachments = target . GetAttachments ( ) ;
}
else
{
foreach ( int point in aps )
2012-09-01 01:44:11 +00:00
{
2016-09-22 16:05:05 +00:00
if ( point > 0 )
2012-09-01 01:44:11 +00:00
{
2016-09-22 16:05:05 +00:00
attachments . AddRange ( target . GetAttachments ( ( uint ) point ) ) ;
2012-09-01 01:44:11 +00:00
}
}
2016-09-22 16:05:05 +00:00
}
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
// if we have no attachments at this point, exit now
if ( attachments . Count = = 0 )
{
return ;
}
2012-09-01 01:44:11 +00:00
2017-01-05 19:07:37 +00:00
bool optionObjCreator = ( options &
2016-09-22 16:05:05 +00:00
ScriptBaseClass . OS_ATTACH_MSG_OBJECT_CREATOR ) ! = 0 ;
bool optionScriptCreator = ( options &
ScriptBaseClass . OS_ATTACH_MSG_SCRIPT_CREATOR ) ! = 0 ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
UUID hostCreatorID = m_host . CreatorID ;
UUID itemCreatorID = m_item . CreatorID ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
foreach ( SceneObjectGroup sog in attachments )
{
if ( sog . IsDeleted | | sog . inTransit )
continue ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
if ( invertPoints & & aps . Contains ( ( int ) sog . AttachmentPoint ) )
continue ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
UUID CreatorID = sog . RootPart . CreatorID ;
if ( optionObjCreator & & CreatorID ! = hostCreatorID )
continue ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
if ( optionScriptCreator & & CreatorID ! = itemCreatorID )
continue ;
2012-09-01 01:44:11 +00:00
2016-09-22 16:05:05 +00:00
SceneObjectPart [ ] parts = sog . Parts ;
foreach ( SceneObjectPart p in parts )
MessageObject ( p . UUID , message ) ;
2012-09-01 01:44:11 +00:00
}
}
2012-09-01 01:39:49 +00:00
# endregion
2012-07-20 17:25:50 +00:00
/// <summary>
/// Checks if thing is a UUID.
/// </summary>
/// <param name="thing"></param>
/// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
public LSL_Integer osIsUUID ( string thing )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2012-07-20 17:25:50 +00:00
UUID test ;
return UUID . TryParse ( thing , out test ) ? 1 : 0 ;
}
2012-07-27 09:49:47 +00:00
/// <summary>
/// Wraps to Math.Min()
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public LSL_Float osMin ( double a , double b )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2012-07-27 09:49:47 +00:00
return Math . Min ( a , b ) ;
}
/// <summary>
/// Wraps to Math.max()
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public LSL_Float osMax ( double a , double b )
{
2017-06-26 19:28:16 +00:00
CheckThreatLevel ( ) ;
2012-07-27 09:49:47 +00:00
return Math . Max ( a , b ) ;
}
2012-08-02 10:19:33 +00:00
public LSL_Key osGetRezzingObject ( )
{
CheckThreatLevel ( ThreatLevel . None , "osGetRezzingObject" ) ;
2017-06-30 21:39:19 +00:00
2016-12-04 17:56:47 +00:00
UUID rezID = m_host . ParentGroup . RezzerID ;
if ( rezID = = UUID . Zero | | m_host . ParentGroup . Scene . GetScenePresence ( rezID ) ! = null )
return new LSL_Key ( UUID . Zero . ToString ( ) ) ;
return new LSL_Key ( rezID . ToString ( ) ) ;
2012-08-02 10:19:33 +00:00
}
2012-08-01 09:28:58 +00:00
2012-08-29 21:56:51 +00:00
/// <summary>
/// Sets the response type for an HTTP request/response
/// </summary>
/// <returns></returns>
public void osSetContentType ( LSL_Key id , string type )
{
2018-12-11 14:55:32 +00:00
CheckThreatLevel ( ThreatLevel . Severe , "osSetContentType" ) ;
2012-10-10 00:39:47 +00:00
2012-08-29 21:56:51 +00:00
if ( m_UrlModule ! = null )
m_UrlModule . HttpContentType ( new UUID ( id ) , type ) ;
}
2012-10-10 00:39:47 +00:00
2012-08-01 09:28:58 +00:00
/// Shout an error if the object owner did not grant the script the specified permissions.
/// </summary>
/// <param name="perms"></param>
/// <returns>boolean indicating whether an error was shouted.</returns>
protected bool ShoutErrorOnLackingOwnerPerms ( int perms , string errorPrefix )
2012-07-31 13:45:23 +00:00
{
2012-08-01 09:28:58 +00:00
bool fail = false ;
if ( m_item . PermsGranter ! = m_host . OwnerID )
{
fail = true ;
OSSLShoutError ( string . Format ( "{0}. Permissions not granted to owner." , errorPrefix ) ) ;
}
else if ( ( m_item . PermsMask & perms ) = = 0 )
{
fail = true ;
OSSLShoutError ( string . Format ( "{0}. Permissions not granted." , errorPrefix ) ) ;
}
return fail ;
}
protected void DropAttachment ( bool checkPerms )
{
if ( checkPerms & & ShoutErrorOnLackingOwnerPerms ( ScriptBaseClass . PERMISSION_ATTACH , "Cannot drop attachment" ) )
{
return ;
}
2012-07-31 13:45:23 +00:00
IAttachmentsModule attachmentsModule = m_ScriptEngine . World . AttachmentsModule ;
ScenePresence sp = attachmentsModule = = null ? null : m_host . ParentGroup . Scene . GetScenePresence ( m_host . ParentGroup . OwnerID ) ;
if ( attachmentsModule ! = null & & sp ! = null )
{
attachmentsModule . DetachSingleAttachmentToGround ( sp , m_host . ParentGroup . LocalId ) ;
}
}
2012-09-30 11:27:53 +00:00
protected void DropAttachmentAt ( bool checkPerms , LSL_Vector pos , LSL_Rotation rot )
2012-07-31 13:45:23 +00:00
{
2012-08-01 09:28:58 +00:00
if ( checkPerms & & ShoutErrorOnLackingOwnerPerms ( ScriptBaseClass . PERMISSION_ATTACH , "Cannot drop attachment" ) )
{
return ;
}
2012-07-31 13:45:23 +00:00
IAttachmentsModule attachmentsModule = m_ScriptEngine . World . AttachmentsModule ;
ScenePresence sp = attachmentsModule = = null ? null : m_host . ParentGroup . Scene . GetScenePresence ( m_host . ParentGroup . OwnerID ) ;
if ( attachmentsModule ! = null & & sp ! = null )
{
2012-08-20 09:19:39 +00:00
attachmentsModule . DetachSingleAttachmentToGround ( sp , m_host . ParentGroup . LocalId , pos , rot ) ;
2012-07-31 13:45:23 +00:00
}
}
2012-08-01 09:28:58 +00:00
public void osDropAttachment ( )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osDropAttachment" ) ;
DropAttachment ( true ) ;
}
public void osForceDropAttachment ( )
{
CheckThreatLevel ( ThreatLevel . High , "osForceDropAttachment" ) ;
DropAttachment ( false ) ;
}
public void osDropAttachmentAt ( LSL_Vector pos , LSL_Rotation rot )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osDropAttachmentAt" ) ;
2012-09-30 11:27:53 +00:00
DropAttachmentAt ( true , pos , rot ) ;
2012-08-01 09:28:58 +00:00
}
public void osForceDropAttachmentAt ( LSL_Vector pos , LSL_Rotation rot )
{
CheckThreatLevel ( ThreatLevel . High , "osForceDropAttachmentAt" ) ;
2012-09-30 11:27:53 +00:00
DropAttachmentAt ( false , pos , rot ) ;
2012-08-01 09:28:58 +00:00
}
2012-10-23 14:42:16 +00:00
public LSL_Integer osListenRegex ( int channelID , string name , string ID , string msg , int regexBitfield )
{
CheckThreatLevel ( ThreatLevel . Low , "osListenRegex" ) ;
2017-06-30 21:39:19 +00:00
2012-10-23 14:42:16 +00:00
UUID keyID ;
UUID . TryParse ( ID , out keyID ) ;
// if we want the name to be used as a regular expression, ensure it is valid first.
if ( ( regexBitfield & ScriptBaseClass . OS_LISTEN_REGEX_NAME ) = = ScriptBaseClass . OS_LISTEN_REGEX_NAME )
{
try
{
Regex . IsMatch ( "" , name ) ;
}
catch ( Exception )
{
OSSLShoutError ( "Name regex is invalid." ) ;
return - 1 ;
}
}
// if we want the msg to be used as a regular expression, ensure it is valid first.
if ( ( regexBitfield & ScriptBaseClass . OS_LISTEN_REGEX_MESSAGE ) = = ScriptBaseClass . OS_LISTEN_REGEX_MESSAGE )
{
try
{
Regex . IsMatch ( "" , msg ) ;
}
catch ( Exception )
{
OSSLShoutError ( "Message regex is invalid." ) ;
return - 1 ;
}
}
IWorldComm wComm = m_ScriptEngine . World . RequestModuleInterface < IWorldComm > ( ) ;
return ( wComm = = null ) ? - 1 : wComm . Listen (
m_host . LocalId ,
m_item . ItemID ,
m_host . UUID ,
channelID ,
name ,
keyID ,
msg ,
regexBitfield
) ;
}
public LSL_Integer osRegexIsMatch ( string input , string pattern )
{
CheckThreatLevel ( ThreatLevel . Low , "osRegexIsMatch" ) ;
2017-06-30 21:39:19 +00:00
2012-10-23 14:42:16 +00:00
try
{
return Regex . IsMatch ( input , pattern ) ? 1 : 0 ;
}
catch ( Exception )
{
OSSLShoutError ( "Possible invalid regular expression detected." ) ;
return 0 ;
}
}
2016-03-16 19:04:52 +00:00
public LSL_String osRequestURL ( LSL_List options )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osRequestSecureURL" ) ;
2017-01-05 19:07:37 +00:00
2016-03-16 19:04:52 +00:00
Hashtable opts = new Hashtable ( ) ;
for ( int i = 0 ; i < options . Length ; i + + )
{
object opt = options . Data [ i ] ;
if ( opt . ToString ( ) = = "allowXss" )
opts [ "allowXss" ] = true ;
}
if ( m_UrlModule ! = null )
return m_UrlModule . RequestURL ( m_ScriptEngine . ScriptModule , m_host , m_item . ItemID , opts ) . ToString ( ) ;
return UUID . Zero . ToString ( ) ;
}
public LSL_String osRequestSecureURL ( LSL_List options )
{
CheckThreatLevel ( ThreatLevel . Moderate , "osRequestSecureURL" ) ;
2017-01-05 19:07:37 +00:00
2016-03-16 19:04:52 +00:00
Hashtable opts = new Hashtable ( ) ;
for ( int i = 0 ; i < options . Length ; i + + )
{
object opt = options . Data [ i ] ;
if ( opt . ToString ( ) = = "allowXss" )
opts [ "allowXss" ] = true ;
}
if ( m_UrlModule ! = null )
return m_UrlModule . RequestSecureURL ( m_ScriptEngine . ScriptModule , m_host , m_item . ItemID , opts ) . ToString ( ) ;
return UUID . Zero . ToString ( ) ;
}
2016-08-27 15:38:29 +00:00
public void osCollisionSound ( string impact_sound , double impact_volume )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2016-08-27 15:38:29 +00:00
if ( impact_sound = = "" )
{
m_host . CollisionSoundVolume = ( float ) impact_volume ;
m_host . CollisionSound = m_host . invalidCollisionSoundUUID ;
if ( impact_volume = = 0.0 )
m_host . CollisionSoundType = - 1 ; // disable all sounds
else if ( impact_volume = = 1.0f )
m_host . CollisionSoundType = 0 ; // full return to default sounds
else
m_host . CollisionSoundType = 2 ; // default sounds with volume
2017-01-05 19:07:37 +00:00
m_host . aggregateScriptEvents ( ) ;
2016-08-27 15:38:29 +00:00
return ;
}
// TODO: Parameter check logic required.
UUID soundId = ScriptUtils . GetAssetIdFromKeyOrItemName ( m_host , impact_sound , AssetType . Sound ) ;
if ( soundId ! = UUID . Zero )
{
m_host . CollisionSound = soundId ;
m_host . CollisionSoundVolume = ( float ) impact_volume ;
m_host . CollisionSoundType = 1 ;
}
else
m_host . CollisionSoundType = - 1 ;
2016-08-28 07:45:09 +00:00
2017-01-05 19:07:37 +00:00
m_host . aggregateScriptEvents ( ) ;
2016-08-27 15:38:29 +00:00
}
2016-08-27 18:25:47 +00:00
// still not very usefull, detector is lost on rez, restarts, etc
public void osVolumeDetect ( int detect )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2016-08-27 18:25:47 +00:00
if ( m_host . ParentGroup = = null | | m_host . ParentGroup . IsDeleted | | m_host . ParentGroup . IsAttachment )
return ;
m_host . ScriptSetVolumeDetect ( detect ! = 0 ) ;
}
2017-03-31 19:55:48 +00:00
/// <summary>
/// Get inertial data
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>
/// a LSL list with contents:
/// LSL_Float mass, the total mass of a linkset
/// LSL_Vector CenterOfMass, center mass relative to root prim
/// LSL_Vector Inertia, elements of diagonal of inertia Ixx,Iyy,Izz divided by total mass
/// LSL_Vector aux, elements of upper triagle of inertia Ixy (= Iyx), Ixz (= Izx), Iyz(= Izy) divided by total mass
2017-10-26 15:26:49 +00:00
/// </returns>
2017-03-31 19:55:48 +00:00
public LSL_List osGetInertiaData ( )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-04-03 16:19:28 +00:00
2017-03-31 19:55:48 +00:00
LSL_List result = new LSL_List ( ) ;
float TotalMass ;
Vector3 CenterOfMass ;
Vector3 Inertia ;
Vector4 aux ;
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
2017-10-26 15:26:49 +00:00
return result ;
2017-03-31 19:55:48 +00:00
sog . GetInertiaData ( out TotalMass , out CenterOfMass , out Inertia , out aux ) ;
if ( TotalMass > 0 )
{
float t = 1.0f / TotalMass ;
Inertia . X * = t ;
Inertia . Y * = t ;
Inertia . Z * = t ;
aux . X * = t ;
aux . Y * = t ;
aux . Z * = t ;
}
result . Add ( new LSL_Float ( TotalMass ) ) ;
result . Add ( new LSL_Vector ( CenterOfMass . X , CenterOfMass . Y , CenterOfMass . Z ) ) ;
result . Add ( new LSL_Vector ( Inertia . X , Inertia . Y , Inertia . Z ) ) ;
result . Add ( new LSL_Vector ( aux . X , aux . Y , aux . Z ) ) ;
return result ;
}
/// <summary>
/// set inertial data
/// replaces the automatic calculation of mass, center of mass and inertia
2017-10-26 15:26:49 +00:00
///
2017-03-31 19:55:48 +00:00
/// </summary>
/// <param name="Mass">total mass of linkset</param>
/// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
/// <param name="principalInertiaScaled">moment of inertia relative to principal axis and center of mass,Ixx, Iyy, Izz divided by mass</param>
/// <param name="lslrot">rotation of the inertia, relative to local axis</param>
/// <remarks>
/// the inertia argument is is inertia divided by mass, so corresponds only to the geometric distribution of mass and both can be changed independently.
/// </remarks>
public void osSetInertia ( LSL_Float mass , LSL_Vector centerOfMass , LSL_Vector principalInertiaScaled , LSL_Rotation lslrot )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-03-31 19:55:48 +00:00
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
return ;
if ( mass < 0 | | principalInertiaScaled . x < 0 | | principalInertiaScaled . y < 0 | | principalInertiaScaled . z < 0 )
return ;
// need more checks
Vector3 CenterOfMass = new Vector3 ( ( float ) centerOfMass . x , ( float ) centerOfMass . y , ( float ) centerOfMass . z ) ;
2017-10-26 15:26:49 +00:00
Vector3 Inertia ;
2017-03-31 19:55:48 +00:00
float m = ( float ) mass ;
Inertia . X = m * ( float ) principalInertiaScaled . x ;
Inertia . Y = m * ( float ) principalInertiaScaled . y ;
Inertia . Z = m * ( float ) principalInertiaScaled . z ;
Vector4 rot = new Vector4 ( ( float ) lslrot . x , ( float ) lslrot . y , ( float ) lslrot . y , ( float ) lslrot . s ) ;
rot . Normalize ( ) ;
sog . SetInertiaData ( m , CenterOfMass , Inertia , rot ) ;
}
/// <summary>
/// set inertial data as a sphere
/// replaces the automatic calculation of mass, center of mass and inertia
2017-10-26 15:26:49 +00:00
///
2017-03-31 19:55:48 +00:00
/// </summary>
/// <param name="Mass">total mass of linkset</param>
/// <param name="boxsize">size of the Box</param>
/// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
/// <param name="lslrot">rotation of the box, and so inertia, relative to local axis</param>
/// <remarks>
/// </remarks>
public void osSetInertiaAsBox ( LSL_Float mass , LSL_Vector boxSize , LSL_Vector centerOfMass , LSL_Rotation lslrot )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-04-03 16:19:28 +00:00
2017-03-31 19:55:48 +00:00
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
return ;
if ( mass < 0 )
return ;
// need more checks
Vector3 CenterOfMass = new Vector3 ( ( float ) centerOfMass . x , ( float ) centerOfMass . y , ( float ) centerOfMass . z ) ;
2017-10-26 15:26:49 +00:00
Vector3 Inertia ;
2017-03-31 19:55:48 +00:00
float lx = ( float ) boxSize . x ;
float ly = ( float ) boxSize . y ;
float lz = ( float ) boxSize . z ;
float m = ( float ) mass ;
float t = m / 12.0f ;
Inertia . X = t * ( ly * ly + lz * lz ) ;
Inertia . Y = t * ( lx * lx + lz * lz ) ;
Inertia . Z = t * ( lx * lx + ly * ly ) ;
Vector4 rot = new Vector4 ( ( float ) lslrot . x , ( float ) lslrot . y , ( float ) lslrot . z , ( float ) lslrot . s ) ;
rot . Normalize ( ) ;
sog . SetInertiaData ( m , CenterOfMass , Inertia , rot ) ;
}
/// <summary>
/// set inertial data as a sphere
/// replaces the automatic calculation of mass, center of mass and inertia
2017-10-26 15:26:49 +00:00
///
2017-03-31 19:55:48 +00:00
/// </summary>
/// <param name="Mass">total mass of linkset</param>
/// <param name="radius">radius of the sphere</param>
/// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
/// <remarks>
/// </remarks>
public void osSetInertiaAsSphere ( LSL_Float mass , LSL_Float radius , LSL_Vector centerOfMass )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-03-31 19:55:48 +00:00
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
return ;
if ( mass < 0 )
return ;
// need more checks
2017-10-26 15:26:49 +00:00
2017-03-31 19:55:48 +00:00
Vector3 CenterOfMass = new Vector3 ( ( float ) centerOfMass . x , ( float ) centerOfMass . y , ( float ) centerOfMass . z ) ;
2017-10-26 15:26:49 +00:00
Vector3 Inertia ;
2017-03-31 19:55:48 +00:00
float r = ( float ) radius ;
float m = ( float ) mass ;
float t = 0.4f * m * r * r ;
Inertia . X = t ;
Inertia . Y = t ;
Inertia . Z = t ;
sog . SetInertiaData ( m , CenterOfMass , Inertia , new Vector4 ( 0f , 0f , 0f , 1.0f ) ) ;
}
/// <summary>
/// set inertial data as a cylinder
/// replaces the automatic calculation of mass, center of mass and inertia
2017-10-26 15:26:49 +00:00
///
2017-03-31 19:55:48 +00:00
/// </summary>
/// <param name="Mass">total mass of linkset</param>
/// <param name="radius">radius of the cylinder</param>
/// <param name="lenght">lenght of the cylinder</param>
/// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
/// <param name="lslrot">rotation of the cylinder, and so inertia, relative to local axis</param>
/// <remarks>
/// cylinder axis aligned with Z axis. For other orientations provide the rotation.
/// </remarks>
public void osSetInertiaAsCylinder ( LSL_Float mass , LSL_Float radius , LSL_Float lenght , LSL_Vector centerOfMass , LSL_Rotation lslrot )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-03-31 19:55:48 +00:00
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
return ;
if ( mass < 0 )
return ;
// need more checks
2017-10-26 15:26:49 +00:00
2017-03-31 19:55:48 +00:00
Vector3 CenterOfMass = new Vector3 ( ( float ) centerOfMass . x , ( float ) centerOfMass . y , ( float ) centerOfMass . z ) ;
2017-10-26 15:26:49 +00:00
Vector3 Inertia ;
2017-03-31 19:55:48 +00:00
float m = ( float ) mass ;
float r = ( float ) radius ;
r * = r ;
Inertia . Z = 0.5f * m * r ;
float t = ( float ) lenght ;
t * = t ;
t + = 3.0f * r ;
t * = 8.333333e-2f * m ;
Inertia . X = t ;
Inertia . Y = t ;
Vector4 rot = new Vector4 ( ( float ) lslrot . x , ( float ) lslrot . y , ( float ) lslrot . z , ( float ) lslrot . s ) ;
rot . Normalize ( ) ;
sog . SetInertiaData ( m , CenterOfMass , Inertia , rot ) ;
}
/// <summary>
/// removes inertial data manual override
/// default automatic calculation is used again
2017-10-26 15:26:49 +00:00
///
2017-03-31 19:55:48 +00:00
/// </summary>
public void osClearInertia ( )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-03-31 19:55:48 +00:00
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
return ;
sog . SetInertiaData ( - 1 , Vector3 . Zero , Vector3 . Zero , Vector4 . Zero ) ;
}
2017-04-03 16:19:28 +00:00
2017-06-26 18:40:20 +00:00
private bool checkAllowObjectTPbyLandOwner ( Vector3 pos )
{
ILandObject land = World . LandChannel . GetLandObject ( pos ) ;
if ( land = = null )
return true ;
LandData landdata = land . LandData ;
if ( landdata = = null )
return true ;
UUID hostOwner = m_host . OwnerID ;
if ( landdata . OwnerID = = hostOwner )
return true ;
EstateSettings es = World . RegionInfo . EstateSettings ;
if ( es ! = null & & es . IsEstateManagerOrOwner ( hostOwner ) )
return true ;
if ( ! landdata . IsGroupOwned )
return false ;
UUID landGroup = landdata . GroupID ;
if ( landGroup = = UUID . Zero )
return false ;
if ( landGroup = = m_host . GroupID )
return true ;
return false ;
}
2017-04-03 16:19:28 +00:00
/// <summary>
/// teleports a object (full linkset)
/// </summary>
/// <param name="objectUUID">the id of the linkset to teleport</param>
/// <param name="targetPos">target position</param>
/// <param name="rotation"> a rotation to apply</param>
2017-04-04 13:34:25 +00:00
/// <param name="flags">several flags/param>
2017-04-03 16:19:28 +00:00
/// <remarks>
/// only does teleport local to region
2017-04-04 13:34:25 +00:00
/// if object has scripts, owner must have rights to run scripts on target location
2017-04-03 16:19:28 +00:00
/// object owner must have rights to enter ojects on target location
/// target location parcel must have enought free prims capacity for the linkset prims
/// all avatars siting on the object must have access to target location
/// has a cool down time. retries before expire reset it
/// fail conditions are silent ignored
/// </remarks>
2017-04-15 09:46:18 +00:00
public LSL_Integer osTeleportObject ( LSL_Key objectUUID , LSL_Vector targetPos , LSL_Rotation rotation , LSL_Integer flags )
2017-04-03 16:19:28 +00:00
{
2017-04-05 00:15:44 +00:00
CheckThreatLevel ( ThreatLevel . Severe , "osTeleportObject" ) ;
2017-04-03 16:19:28 +00:00
UUID objUUID ;
if ( ! UUID . TryParse ( objectUUID , out objUUID ) )
{
2017-04-05 00:15:44 +00:00
OSSLShoutError ( "osTeleportObject() invalid object Key" ) ;
2017-04-15 09:46:18 +00:00
return - 1 ;
2017-04-03 16:19:28 +00:00
}
SceneObjectGroup sog = World . GetSceneObjectGroup ( objUUID ) ;
2017-06-26 18:40:20 +00:00
if ( sog = = null | | sog . IsDeleted | | sog . inTransit )
2017-04-15 09:46:18 +00:00
return - 1 ;
2017-04-03 16:19:28 +00:00
2017-06-26 18:40:20 +00:00
if ( sog . OwnerID ! = m_host . OwnerID )
{
Vector3 pos = sog . AbsolutePosition ;
if ( ! checkAllowObjectTPbyLandOwner ( pos ) )
return - 1 ;
}
2017-04-03 16:19:28 +00:00
UUID myid = m_host . ParentGroup . UUID ;
2017-04-15 09:46:18 +00:00
return sog . TeleportObject ( myid , targetPos , rotation , flags ) ;
2017-04-03 16:19:28 +00:00
// a delay here may break vehicles
}
2017-04-04 18:27:45 +00:00
public LSL_Integer osGetLinkNumber ( LSL_String name )
{
2017-04-05 14:11:19 +00:00
CheckThreatLevel ( ) ;
2017-04-04 18:27:45 +00:00
SceneObjectGroup sog = m_host . ParentGroup ;
if ( sog = = null | | sog . IsDeleted )
return - 1 ;
return sog . GetLinkNumber ( name ) ;
}
2018-04-03 22:00:37 +00:00
// rounds to the nearest number with provided number of decimal places
public LSL_Float osRound ( LSL_Float value , LSL_Integer ndigits )
{
if ( ndigits < = 0 )
return Math . Round ( value , MidpointRounding . AwayFromZero ) ;
if ( ndigits > 15 )
ndigits = 15 ;
return Math . Round ( value , ndigits , MidpointRounding . AwayFromZero ) ;
}
public LSL_Float osVecMagSquare ( LSL_Vector a )
{
return LSL_Vector . MagSquare ( a ) ;
}
public LSL_Float osVecDistSquare ( LSL_Vector a , LSL_Vector b )
{
return LSL_Vector . MagSquare ( a - b ) ;
}
2018-04-04 00:25:49 +00:00
// returns the angle between 2 vectors 0 to pi
2018-04-03 22:00:37 +00:00
public LSL_Float osAngleBetween ( LSL_Vector a , LSL_Vector b )
{
double dot = LSL_Vector . Dot ( a , b ) ;
2018-04-04 00:25:49 +00:00
double mcross = LSL_Vector . Mag ( LSL_Vector . Cross ( a , b ) ) ;
2018-04-03 22:00:37 +00:00
return Math . Atan2 ( mcross , dot ) ;
}
2018-04-08 23:15:45 +00:00
public void osAdjustSoundVolume ( LSL_Integer linknum , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
sop . AdjustSoundGain ( volume ) ;
}
public void osSetSoundRadius ( LSL_Integer linknum , LSL_Float radius )
{
m_host . AddScriptLPS ( 1 ) ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
sop . SoundRadius = radius ;
2018-04-08 23:15:45 +00:00
}
public void osPlaySound ( LSL_Integer linknum , LSL_String sound , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
// send the sound, once, to all clients in range
2018-04-10 20:45:11 +00:00
m_SoundModule . SendSound ( sop . UUID , soundID , volume , false , 0 , false , false ) ;
2018-04-08 23:15:45 +00:00
}
public void osLoopSound ( LSL_Integer linknum , LSL_String sound , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
2018-04-10 20:45:11 +00:00
m_SoundModule . LoopSound ( sop . UUID , soundID , volume , false , false ) ;
2018-04-08 23:15:45 +00:00
}
public void osLoopSoundMaster ( LSL_Integer linknum , LSL_String sound , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
2018-11-14 19:02:00 +00:00
if ( m_SoundModule = = null )
return ;
2018-04-08 23:15:45 +00:00
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
2018-04-10 20:45:11 +00:00
m_SoundModule . LoopSound ( sop . UUID , soundID , volume , true , false ) ;
2018-04-08 23:15:45 +00:00
}
public void osLoopSoundSlave ( LSL_Integer linknum , LSL_String sound , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
2018-04-10 20:45:11 +00:00
m_SoundModule . LoopSound ( sop . UUID , soundID , volume , false , true ) ;
2018-04-08 23:15:45 +00:00
}
public void osPlaySoundSlave ( LSL_Integer linknum , LSL_String sound , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
// send the sound, once, to all clients in range
2018-04-10 20:45:11 +00:00
m_SoundModule . SendSound ( sop . UUID , soundID , volume , false , 0 , true , false ) ;
2018-04-08 23:15:45 +00:00
}
public void osTriggerSound ( LSL_Integer linknum , LSL_String sound , LSL_Float volume )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
// send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
2018-04-10 20:45:11 +00:00
m_SoundModule . SendSound ( sop . UUID , soundID , volume , true , 0 , false , false ) ;
2018-04-08 23:15:45 +00:00
}
2018-04-10 02:58:54 +00:00
public void osTriggerSoundLimited ( LSL_Integer linknum , LSL_String sound , LSL_Float volume ,
LSL_Vector top_north_east , LSL_Vector bottom_south_west )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-10 02:58:54 +00:00
return ;
m_SoundModule . TriggerSoundLimited ( sop . UUID , soundID , volume ,
bottom_south_west , top_north_east ) ;
}
2018-04-08 23:15:45 +00:00
public void osStopSound ( LSL_Integer linknum )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
m_SoundModule . StopSound ( sop . UUID ) ;
}
public void osPreloadSound ( LSL_Integer linknum , LSL_String sound )
{
m_host . AddScriptLPS ( 1 ) ;
if ( m_SoundModule = = null )
return ;
SceneObjectPart sop = GetSingleLinkPart ( linknum ) ;
if ( sop = = null )
return ;
2018-11-14 19:02:00 +00:00
UUID soundID = ScriptUtils . GetAssetIdFromKeyOrItemName ( sop , m_host , sound , AssetType . Sound ) ;
if ( soundID = = UUID . Zero )
2018-04-08 23:15:45 +00:00
return ;
2018-04-10 20:45:11 +00:00
m_SoundModule . PreloadSound ( sop . UUID , soundID ) ;
2018-04-08 23:15:45 +00:00
ScriptSleep ( 1000 ) ;
}
// get only one part
private SceneObjectPart GetSingleLinkPart ( int linkType )
{
if ( m_host . ParentGroup = = null | | m_host . ParentGroup . IsDeleted )
return null ;
switch ( linkType )
{
case ScriptBaseClass . LINK_SET :
case ScriptBaseClass . LINK_ALL_OTHERS :
case ScriptBaseClass . LINK_ALL_CHILDREN :
return null ;
case 0 :
case ScriptBaseClass . LINK_ROOT :
return m_host . ParentGroup . RootPart ;
case ScriptBaseClass . LINK_THIS :
return m_host ;
default :
if ( linkType < 0 )
return null ;
return m_host . ParentGroup . GetLinkNumPart ( linkType ) ;
}
}
2018-11-15 20:29:12 +00:00
// funtions to retrieve user country
// adaptation cm* counter parts from Avination Careminster extensions API
// included in Avination code contribution
// for now users country can only be set directly on DB
public LSL_String osDetectedCountry ( LSL_Integer number )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ThreatLevel . Moderate , "osDetectedCountry" ) ;
if ( World . UserAccountService = = null )
return String . Empty ;
DetectParams detectedParams = m_ScriptEngine . GetDetectParams ( m_item . ItemID , number ) ;
if ( detectedParams = = null )
return String . Empty ;
UUID key = detectedParams . Key ;
if ( key = = UUID . Zero )
return String . Empty ;
UserAccount account = World . UserAccountService . GetUserAccount ( World . RegionInfo . ScopeID , key ) ;
return account . UserCountry ;
}
public LSL_String osGetAgentCountry ( LSL_Key id )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ThreatLevel . Moderate , "osGetAgentCountry" ) ;
if ( World . UserAccountService = = null )
return String . Empty ;
UUID key ;
if ( ! UUID . TryParse ( id , out key ) )
return String . Empty ;
if ( key = = UUID . Zero )
return String . Empty ;
//if owner is not god, target must be in region, or nearby regions
if ( ! World . Permissions . IsGod ( m_host . OwnerID ) )
{
ScenePresence sp = World . GetScenePresence ( key ) ;
if ( sp = = null )
return String . Empty ;
}
UserAccount account = World . UserAccountService . GetUserAccount ( World . RegionInfo . ScopeID , key ) ;
return account . UserCountry ;
}
2018-11-18 22:40:59 +00:00
public LSL_String osStringSubString ( LSL_String src , LSL_Integer offset )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return "" ;
if ( offset > = src . Length )
return "" ;
if ( offset < = 0 )
return src ;
return ( ( string ) src ) . Substring ( offset ) ;
}
public LSL_String osStringSubString ( LSL_String src , LSL_Integer offset , LSL_Integer length )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return "" ;
if ( length < = 0 | | offset > = src . Length )
return "" ;
if ( offset < = 0 )
{
if ( length = = src . Length )
return src ;
offset = 0 ;
}
if ( length > src . Length - offset )
length = src . Length - offset ;
return ( ( string ) src ) . Substring ( offset , length ) ;
}
public LSL_Integer osStringStartsWith ( LSL_String src , LSL_String value , LSL_Integer ignorecase )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return 0 ;
if ( string . IsNullOrEmpty ( value ) )
return 0 ;
bool ign = ( ignorecase ! = 0 ) ;
return ( ( string ) src ) . StartsWith ( value , ignorecase , Culture . GetDefaultCurrentCulture ( ) ) ? 1 : 0 ;
}
public LSL_Integer osStringEndsWith ( LSL_String src , LSL_String value , LSL_Integer ignorecase )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return 0 ;
if ( string . IsNullOrEmpty ( value ) )
return 0 ;
bool ign = ( ignorecase ! = 0 ) ;
return ( ( string ) src ) . EndsWith ( value , ign , Culture . GetDefaultCurrentCulture ( ) ) ? 1 : 0 ;
}
public LSL_Integer osStringIndexOf ( LSL_String src , LSL_String value , LSL_Integer ignorecase )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return - 1 ;
if ( string . IsNullOrEmpty ( value ) )
return - 1 ;
if ( ignorecase = = 0 )
return ( ( string ) src ) . IndexOf ( value , StringComparison . CurrentCulture ) ;
return ( ( string ) src ) . IndexOf ( value , StringComparison . CurrentCultureIgnoreCase ) ;
}
public LSL_Integer osStringIndexOf ( LSL_String src , LSL_String value ,
LSL_Integer offset , LSL_Integer count , LSL_Integer ignorecase )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return - 1 ;
if ( string . IsNullOrEmpty ( value ) )
return - 1 ;
if ( offset > = src . Length )
return - 1 ;
else if ( offset < 0 )
offset = 0 ;
if ( count < = 0 )
count = src . Length - offset ;
else if ( count > src . Length - offset )
count = src . Length - offset ;
if ( ignorecase = = 0 )
return ( ( string ) src ) . IndexOf ( value , offset , count , StringComparison . CurrentCulture ) ;
return ( ( string ) src ) . IndexOf ( value , offset , count , StringComparison . CurrentCultureIgnoreCase ) ;
}
public LSL_Integer osStringLastIndexOf ( LSL_String src , LSL_String value , LSL_Integer ignorecase )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return - 1 ;
if ( string . IsNullOrEmpty ( value ) )
return - 1 ;
if ( ignorecase = = 0 )
return ( ( string ) src ) . LastIndexOf ( value , StringComparison . CurrentCulture ) ;
return ( ( string ) src ) . LastIndexOf ( value , StringComparison . CurrentCultureIgnoreCase ) ;
}
public LSL_Integer osStringLastIndexOf ( LSL_String src , LSL_String value ,
LSL_Integer offset , LSL_Integer count , LSL_Integer ignorecase )
{
m_host . AddScriptLPS ( 1 ) ;
CheckThreatLevel ( ) ;
if ( string . IsNullOrEmpty ( src ) )
return - 1 ;
if ( string . IsNullOrEmpty ( value ) )
return - 1 ;
if ( offset > = src . Length )
return - 1 ;
if ( offset < 0 )
offset = 0 ;
if ( count < = 0 )
count = src . Length - offset ;
else if ( count > src . Length - offset )
count = src . Length - offset ;
if ( ignorecase = = 0 )
return ( ( string ) src ) . LastIndexOf ( value , offset , count , StringComparison . CurrentCulture ) ;
return ( ( string ) src ) . LastIndexOf ( value , offset , count , StringComparison . CurrentCultureIgnoreCase ) ;
}
public LSL_String osStringRemove ( LSL_String src , LSL_Integer offset , LSL_Integer count )
{
if ( string . IsNullOrEmpty ( src ) )
return "" ;
if ( offset > = src . Length )
return "" ;
if ( offset < 0 )
offset = 0 ;
if ( count < = 0 )
count = src . Length - offset ;
else if ( count > src . Length - offset )
count = src . Length - offset ;
if ( count > = src . Length )
return "" ;
return ( ( string ) src ) . Remove ( offset , count ) ;
}
public LSL_String osStringReplace ( LSL_String src , LSL_String oldvalue , LSL_String newvalue )
{
if ( string . IsNullOrEmpty ( src ) )
return "" ;
if ( string . IsNullOrEmpty ( oldvalue ) )
return "" ;
if ( string . IsNullOrEmpty ( newvalue ) )
newvalue = null ;
return ( ( string ) src ) . Replace ( oldvalue , newvalue ) ;
}
2018-11-20 18:12:18 +00:00
public LSL_Integer osApproxEquals ( LSL_Float a , LSL_Float b )
{
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
return 1 ;
}
public LSL_Integer osApproxEquals ( LSL_Float a , LSL_Float b , LSL_Float margin )
{
double e = Math . Abs ( margin ) ;
if ( a > b + e | | a < b - e )
return 0 ;
return 1 ;
}
public LSL_Integer osApproxEquals ( LSL_Vector va , LSL_Vector vb )
{
double a = va . x ;
double b = vb . x ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
a = va . y ;
b = vb . y ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
a = va . z ;
b = vb . z ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
return 1 ;
}
public LSL_Integer osApproxEquals ( LSL_Vector va , LSL_Vector vb , LSL_Float margin )
{
double e = Math . Abs ( margin ) ;
double a = va . x ;
double b = vb . x ;
if ( a > b + e | | a < b - e )
return 0 ;
a = va . y ;
b = vb . y ;
if ( a > b + e | | a < b - e )
return 0 ;
a = va . z ;
b = vb . z ;
if ( a > b + e | | a < b - e )
return 0 ;
return 1 ;
}
public LSL_Integer osApproxEquals ( LSL_Rotation ra , LSL_Rotation rb )
{
double a = ra . x ;
double b = rb . x ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
a = ra . y ;
b = rb . y ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
a = ra . z ;
b = rb . z ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
a = ra . s ;
b = rb . s ;
if ( a > b + 1.0e-6 | | a < b - 1.0e-6 )
return 0 ;
return 1 ;
}
public LSL_Integer osApproxEquals ( LSL_Rotation ra , LSL_Rotation rb , LSL_Float margin )
{
double e = Math . Abs ( margin ) ;
double a = ra . x ;
double b = rb . x ;
if ( a > b + e | | a < b - e )
return 0 ;
a = ra . y ;
b = rb . y ;
if ( a > b + e | | a < b - e )
return 0 ;
a = ra . z ;
b = rb . z ;
if ( a > b + e | | a < b - e )
return 0 ;
a = ra . s ;
b = rb . s ;
if ( a > b + e | | a < b - e )
return 0 ;
return 1 ;
}
2019-02-21 23:11:03 +00:00
public LSL_Key osGetInventoryLastOwner ( LSL_String itemNameorid )
2019-02-21 21:56:27 +00:00
{
m_host . AddScriptLPS ( 1 ) ;
TaskInventoryItem item = null ;
UUID itemID ;
if ( UUID . TryParse ( itemNameorid , out itemID ) )
item = m_host . Inventory . GetInventoryItem ( itemID ) ;
else
item = m_host . Inventory . GetInventoryItem ( itemNameorid ) ;
if ( item = = null )
return UUID . Zero . ToString ( ) ;
UUID id = item . LastOwnerID ;
if ( id = = UUID . Zero )
id = item . OwnerID ;
return id . ToString ( ) ;
}
2019-02-21 23:11:03 +00:00
public LSL_String osGetInventoryName ( LSL_Key itemId )
{
m_host . AddScriptLPS ( 1 ) ;
TaskInventoryItem item = null ;
UUID itemID ;
if ( UUID . TryParse ( itemId , out itemID ) )
item = m_host . Inventory . GetInventoryItem ( itemID ) ;
if ( item = = null )
return String . Empty ;
return item . Name ;
}
2019-02-22 22:28:47 +00:00
public LSL_String osGetInventoryDesc ( LSL_String itemNameorid )
2019-02-21 23:11:03 +00:00
{
m_host . AddScriptLPS ( 1 ) ;
TaskInventoryItem item = null ;
UUID itemID ;
if ( UUID . TryParse ( itemNameorid , out itemID ) )
item = m_host . Inventory . GetInventoryItem ( itemID ) ;
else
item = m_host . Inventory . GetInventoryItem ( itemNameorid ) ;
if ( item = = null )
return String . Empty ;
return item . Description ;
}
2019-02-21 23:41:49 +00:00
public LSL_Key osGetLastChangedEventKey ( )
{
m_host . AddScriptLPS ( 1 ) ;
DetectParams detectedParams = m_ScriptEngine . GetDetectParams ( m_item . ItemID , 0 ) ;
if ( detectedParams = = null )
return String . Empty ;
return detectedParams . Key . ToString ( ) ;
}
2012-07-31 13:45:23 +00:00
}
2018-11-18 22:40:59 +00:00
}