OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
OSSL_Api.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Reflection;
33 using System.Runtime.Remoting.Lifetime;
34 using System.Text;
35 using System.Net;
36 using System.Threading;
37 using System.Xml;
38 using log4net;
39 using OpenMetaverse;
40 using OpenMetaverse.StructuredData;
41 using Nini.Config;
42 using OpenSim;
43 using OpenSim.Framework;
44 
45 using OpenSim.Framework.Console;
46 using OpenSim.Region.Framework.Interfaces;
47 using OpenSim.Region.Framework.Scenes;
48 using OpenSim.Region.ScriptEngine.Shared;
49 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
50 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
51 using OpenSim.Region.ScriptEngine.Interfaces;
52 using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
54 using OpenSim.Services.Interfaces;
56 using System.Text.RegularExpressions;
57 
66 using OpenSim.Services.Connectors.Hypergrid;
67 
68 namespace OpenSim.Region.ScriptEngine.Shared.Api
69 {
71  //
72  // Level description
73  //
74  // None - Function is no threat at all. It doesn't constitute
75  // an threat to either users or the system and has no
76  // known side effects
77  //
78  // Nuisance - Abuse of this command can cause a nuisance to the
79  // region operator, such as log message spew
80  //
81  // VeryLow - Extreme levels ob abuse of this function can cause
82  // impaired functioning of the region, or very gullible
83  // users can be tricked into experiencing harmless effects
84  //
85  // Low - Intentional abuse can cause crashes or malfunction
86  // under certain circumstances, which can easily be rectified,
87  // or certain users can be tricked into certain situations
88  // in an avoidable manner.
89  //
90  // Moderate - Intentional abuse can cause denial of service and crashes
91  // with potential of data or state loss, or trusting users
92  // can be tricked into embarrassing or uncomfortable
93  // situationsa.
94  //
95  // High - Casual abuse can cause impaired functionality or temporary
96  // denial of service conditions. Intentional abuse can easily
97  // cause crashes with potential data loss, or can be used to
98  // trick experienced and cautious users into unwanted situations,
99  // or changes global data permanently and without undo ability
100  // Malicious scripting can allow theft of content
101  //
102  // VeryHigh - Even normal use may, depending on the number of instances,
103  // or frequency of use, result in severe service impairment
104  // or crash with loss of data, or can be used to cause
105  // unwanted or harmful effects on users without giving the
106  // user a means to avoid it.
107  //
108  // Severe - Even casual use is a danger to region stability, or function
109  // allows console or OS command execution, or function allows
110  // taking money without consent, or allows deletion or
111  // modification of user data, or allows the compromise of
112  // sensitive data by design.
113 
115  {
116  public List<UUID> AllowedCreators;
117  public List<UUID> AllowedOwners;
118  public List<string> AllowedOwnerClasses;
119 
120  public FunctionPerms()
121  {
122  AllowedCreators = new List<UUID>();
123  AllowedOwners = new List<UUID>();
124  AllowedOwnerClasses = new List<string>();
125  }
126  }
127 
128  [Serializable]
129  public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
130  {
131  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
132 
133  public const string GridInfoServiceConfigSectionName = "GridInfoService";
134 
135  internal IScriptEngine m_ScriptEngine;
136  internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
137  internal SceneObjectPart m_host;
138  internal TaskInventoryItem m_item;
139  internal bool m_OSFunctionsEnabled = false;
140  internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
141  internal float m_ScriptDelayFactor = 1.0f;
142  internal float m_ScriptDistanceFactor = 1.0f;
143  internal bool m_debuggerSafe = false;
144  internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
145  protected IUrlModule m_UrlModule = null;
146 
147  public void Initialize(
148  IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
149  {
150  m_ScriptEngine = scriptEngine;
151  m_host = host;
152  m_item = item;
153  m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
154 
155  m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
156 
157  if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
158  {
159  m_OSFunctionsEnabled = true;
160  // m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED");
161  }
162 
163  m_ScriptDelayFactor =
164  m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
165  m_ScriptDistanceFactor =
166  m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
167 
168  string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow");
169  switch (risk)
170  {
171  case "NoAccess":
172  m_MaxThreatLevel = ThreatLevel.NoAccess;
173  break;
174  case "None":
175  m_MaxThreatLevel = ThreatLevel.None;
176  break;
177  case "VeryLow":
178  m_MaxThreatLevel = ThreatLevel.VeryLow;
179  break;
180  case "Low":
181  m_MaxThreatLevel = ThreatLevel.Low;
182  break;
183  case "Moderate":
184  m_MaxThreatLevel = ThreatLevel.Moderate;
185  break;
186  case "High":
187  m_MaxThreatLevel = ThreatLevel.High;
188  break;
189  case "VeryHigh":
190  m_MaxThreatLevel = ThreatLevel.VeryHigh;
191  break;
192  case "Severe":
193  m_MaxThreatLevel = ThreatLevel.Severe;
194  break;
195  default:
196  break;
197  }
198  }
199 
201  {
202  ILease lease = (ILease)base.InitializeLifetimeService();
203 
204  if (lease.CurrentState == LeaseState.Initial)
205  {
206  lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
207 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
208 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
209  }
210  return lease;
211  }
212 
213  public Scene World
214  {
215  get { return m_ScriptEngine.World; }
216  }
217 
218  internal void OSSLError(string msg)
219  {
220  if (m_debuggerSafe)
221  {
222  OSSLShoutError(msg);
223  }
224  else
225  {
226  throw new ScriptException("OSSL Runtime Error: " + msg);
227  }
228  }
229 
238  private void InitLSL()
239  {
240  if (m_LSL_Api != null)
241  return;
242 
243  m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
244  }
245 
246  //
247  //Dumps an error message on the debug console.
248  //
249 
250  internal void OSSLShoutError(string message)
251  {
252  if (message.Length > 1023)
253  message = message.Substring(0, 1023);
254 
255  World.SimChat(Utils.StringToBytes(message),
256  ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
257 
258  IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
259  wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
260  }
261 
262  // Returns of the function is allowed. Throws a script exception if not allowed.
263  public void CheckThreatLevel(ThreatLevel level, string function)
264  {
265  if (!m_OSFunctionsEnabled)
266  OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
267 
268  string reasonWhyNot = CheckThreatLevelTest(level, function);
269  if (!String.IsNullOrEmpty(reasonWhyNot))
270  {
271  OSSLError(reasonWhyNot);
272  }
273  }
274 
275  // Check to see if function is allowed. Returns an empty string if function permitted
276  // or a string explaining why this function can't be used.
277  private string CheckThreatLevelTest(ThreatLevel level, string function)
278  {
279  if (!m_FunctionPerms.ContainsKey(function))
280  {
281  FunctionPerms perms = new FunctionPerms();
282  m_FunctionPerms[function] = perms;
283 
284  string ownerPerm = m_ScriptEngine.Config.GetString("Allow_" + function, "");
285  string creatorPerm = m_ScriptEngine.Config.GetString("Creators_" + function, "");
286  if (ownerPerm == "" && creatorPerm == "")
287  {
288  // Default behavior
289  perms.AllowedOwners = null;
290  perms.AllowedCreators = null;
291  perms.AllowedOwnerClasses = null;
292  }
293  else
294  {
295  bool allowed;
296 
297  if (bool.TryParse(ownerPerm, out allowed))
298  {
299  // Boolean given
300  if (allowed)
301  {
302  // Allow globally
303  perms.AllowedOwners.Add(UUID.Zero);
304  }
305  }
306  else
307  {
308  string[] ids = ownerPerm.Split(new char[] {','});
309  foreach (string id in ids)
310  {
311  string current = id.Trim();
312  if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER")
313  {
314  if (!perms.AllowedOwnerClasses.Contains(current))
315  perms.AllowedOwnerClasses.Add(current.ToUpper());
316  }
317  else
318  {
319  UUID uuid;
320 
321  if (UUID.TryParse(current, out uuid))
322  {
323  if (uuid != UUID.Zero)
324  perms.AllowedOwners.Add(uuid);
325  }
326  }
327  }
328 
329  ids = creatorPerm.Split(new char[] {','});
330  foreach (string id in ids)
331  {
332  string current = id.Trim();
333  UUID uuid;
334 
335  if (UUID.TryParse(current, out uuid))
336  {
337  if (uuid != UUID.Zero)
338  perms.AllowedCreators.Add(uuid);
339  }
340  }
341  }
342  }
343  }
344 
345  // If the list is null, then the value was true / undefined
346  // Threat level governs permissions in this case
347  //
348  // If the list is non-null, then it is a list of UUIDs allowed
349  // to use that particular function. False causes an empty
350  // list and therefore means "no one"
351  //
352  // To allow use by anyone, the list contains UUID.Zero
353  //
354  if (m_FunctionPerms[function].AllowedOwners == null)
355  {
356  // Allow / disallow by threat level
357  if (level > m_MaxThreatLevel)
358  return
359  String.Format(
360  "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
361  function, m_MaxThreatLevel, level);
362  }
363  else
364  {
365  if (!m_FunctionPerms[function].AllowedOwners.Contains(UUID.Zero))
366  {
367  // Not anyone. Do detailed checks
368  if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID))
369  {
370  // prim owner is in the list of allowed owners
371  return String.Empty;
372  }
373 
374  UUID ownerID = m_item.OwnerID;
375 
376  //OSSL only may be used if object is in the same group as the parcel
377  if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER"))
378  {
379  ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
380 
381  if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
382  {
383  return String.Empty;
384  }
385  }
386 
387  //Only Parcelowners may use the function
388  if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_OWNER"))
389  {
390  ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
391 
392  if (land.LandData.OwnerID == ownerID)
393  {
394  return String.Empty;
395  }
396  }
397 
398  //Only Estate Managers may use the function
399  if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER"))
400  {
401  //Only Estate Managers may use the function
402  if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
403  {
404  return String.Empty;
405  }
406  }
407 
408  //Only regionowners may use the function
409  if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_OWNER"))
410  {
411  if (World.RegionInfo.EstateSettings.EstateOwner == ownerID)
412  {
413  return String.Empty;
414  }
415  }
416 
417  if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
418  return(
419  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.",
420  function));
421 
422  if (m_item.CreatorID != ownerID)
423  {
424  if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
425  return String.Format("{0} permission denied. Script permissions error.", function);
426 
427  }
428  }
429  }
430  return String.Empty;
431  }
432 
433  internal void OSSLDeprecated(string function, string replacement)
434  {
435  OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
436  }
437 
438  protected void ScriptSleep(int delay)
439  {
440  delay = (int)((float)delay * m_ScriptDelayFactor);
441  if (delay == 0)
442  return;
443  System.Threading.Thread.Sleep(delay);
444  }
445 
446  public LSL_Integer osSetTerrainHeight(int x, int y, double val)
447  {
448  CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
449 
450  return SetTerrainHeight(x, y, val);
451  }
452 
453  public LSL_Integer osTerrainSetHeight(int x, int y, double val)
454  {
455  CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
456  OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
457 
458  return SetTerrainHeight(x, y, val);
459  }
460 
461  private LSL_Integer SetTerrainHeight(int x, int y, double val)
462  {
463  m_host.AddScriptLPS(1);
464 
465  if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
466  OSSLError("osSetTerrainHeight: Coordinate out of bounds");
467 
468  if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
469  {
470  World.Heightmap[x, y] = val;
471  return 1;
472  }
473  else
474  {
475  return 0;
476  }
477  }
478 
479  public LSL_Float osGetTerrainHeight(int x, int y)
480  {
481  CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight");
482  return GetTerrainHeight(x, y);
483  }
484 
485  public LSL_Float osTerrainGetHeight(int x, int y)
486  {
487  CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
488  OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
489  return GetTerrainHeight(x, y);
490  }
491 
492  private LSL_Float GetTerrainHeight(int x, int y)
493  {
494  m_host.AddScriptLPS(1);
495  if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
496  OSSLError("osGetTerrainHeight: Coordinate out of bounds");
497 
498  return World.Heightmap[x, y];
499  }
500 
501  public void osTerrainFlush()
502  {
503  CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
504  m_host.AddScriptLPS(1);
505 
506  ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
507  if (terrainModule != null) terrainModule.TaintTerrain();
508  }
509 
510  public int osRegionRestart(double seconds)
511  {
512  // This is High here because region restart is not reliable
513  // it may result in the region staying down or becoming
514  // unstable. This should be changed to Low or VeryLow once
515  // The underlying functionality is fixed, since the security
516  // as such is sound
517  //
518  CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
519 
520  IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
521  m_host.AddScriptLPS(1);
522  if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
523  {
524  if (seconds < 15)
525  {
526  restartModule.AbortRestart("Restart aborted");
527  return 1;
528  }
529 
530  List<int> times = new List<int>();
531  while (seconds > 0)
532  {
533  times.Add((int)seconds);
534  if (seconds > 300)
535  seconds -= 120;
536  else if (seconds > 30)
537  seconds -= 30;
538  else
539  seconds -= 15;
540  }
541 
542  restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true);
543  return 1;
544  }
545  else
546  {
547  return 0;
548  }
549  }
550 
551  public void osRegionNotice(string msg)
552  {
553  // This implementation provides absolutely no security
554  // It's high griefing potential makes this classification
555  // necessary
556  //
557  CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
558 
559  m_host.AddScriptLPS(1);
560 
561  IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
562 
563  if (dm != null)
564  dm.SendGeneralAlert(msg);
565  }
566 
567  public void osSetRot(UUID target, Quaternion rotation)
568  {
569  // This function has no security. It can be used to destroy
570  // arbitrary builds the user would normally have no rights to
571  //
572  CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
573 
574  m_host.AddScriptLPS(1);
575  if (World.Entities.ContainsKey(target))
576  {
577  EntityBase entity;
578  if (World.Entities.TryGetValue(target, out entity))
579  {
580  if (entity is SceneObjectGroup)
581  ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation);
582  else if (entity is ScenePresence)
583  ((ScenePresence)entity).Rotation = rotation;
584  }
585  }
586  else
587  {
588  OSSLError("osSetRot: Invalid target");
589  }
590  }
591 
592  public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
593  int timer)
594  {
595  // This may be upgraded depending on the griefing or DOS
596  // potential, or guarded with a delay
597  //
598  CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
599 
600  m_host.AddScriptLPS(1);
601  if (dynamicID == String.Empty)
602  {
603  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
604  UUID createdTexture =
605  textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
606  extraParams, timer);
607  return createdTexture.ToString();
608  }
609  else
610  {
611  //TODO update existing dynamic textures
612  }
613 
614  return UUID.Zero.ToString();
615  }
616 
617  public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
618  int timer, int alpha)
619  {
620  CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
621 
622  m_host.AddScriptLPS(1);
623  if (dynamicID == String.Empty)
624  {
625  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
626  UUID createdTexture =
627  textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
628  extraParams, timer, true, (byte) alpha);
629  return createdTexture.ToString();
630  }
631  else
632  {
633  //TODO update existing dynamic textures
634  }
635 
636  return UUID.Zero.ToString();
637  }
638 
639  public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
640  bool blend, int disp, int timer, int alpha, int face)
641  {
642  CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
643 
644  m_host.AddScriptLPS(1);
645  if (dynamicID == String.Empty)
646  {
647  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
648  UUID createdTexture =
649  textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
650  extraParams, timer, blend, disp, (byte) alpha, face);
651  return createdTexture.ToString();
652  }
653  else
654  {
655  //TODO update existing dynamic textures
656  }
657 
658  return UUID.Zero.ToString();
659  }
660 
661  public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
662  int timer)
663  {
664  CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
665 
666  m_host.AddScriptLPS(1);
667  if (dynamicID == String.Empty)
668  {
669  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
670  if (textureManager != null)
671  {
672  if (extraParams == String.Empty)
673  {
674  extraParams = "256";
675  }
676  UUID createdTexture =
677  textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
678  extraParams, timer);
679  return createdTexture.ToString();
680  }
681  }
682  else
683  {
684  //TODO update existing dynamic textures
685  }
686 
687  return UUID.Zero.ToString();
688  }
689 
690  public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
691  int timer, int alpha)
692  {
693  CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
694 
695  m_host.AddScriptLPS(1);
696  if (dynamicID == String.Empty)
697  {
698  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
699  if (textureManager != null)
700  {
701  if (extraParams == String.Empty)
702  {
703  extraParams = "256";
704  }
705  UUID createdTexture =
706  textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
707  extraParams, timer, true, (byte) alpha);
708  return createdTexture.ToString();
709  }
710  }
711  else
712  {
713  //TODO update existing dynamic textures
714  }
715 
716  return UUID.Zero.ToString();
717  }
718 
719  public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
720  bool blend, int disp, int timer, int alpha, int face)
721  {
722  CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace");
723 
724  m_host.AddScriptLPS(1);
725  if (dynamicID == String.Empty)
726  {
727  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
728  if (textureManager != null)
729  {
730  if (extraParams == String.Empty)
731  {
732  extraParams = "256";
733  }
734  UUID createdTexture =
735  textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
736  extraParams, timer, blend, disp, (byte) alpha, face);
737  return createdTexture.ToString();
738  }
739  }
740  else
741  {
742  //TODO update existing dynamic textures
743  }
744 
745  return UUID.Zero.ToString();
746  }
747 
748  public bool osConsoleCommand(string command)
749  {
750  CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
751 
752  m_host.AddScriptLPS(1);
753 
754  // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
755  if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
756  {
757  MainConsole.Instance.RunCommand(command);
758  return true;
759  }
760 
761  return false;
762  }
763 
764  public void osSetPrimFloatOnWater(int floatYN)
765  {
766  CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
767 
768  m_host.AddScriptLPS(1);
769 
770  m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
771  }
772 
773  // Teleport functions
774  public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
775  {
776  // High because there is no security check. High griefer potential
777  //
778  CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
779 
780  TeleportAgent(agent, regionName, position, lookat, false);
781  }
782 
783  private void TeleportAgent(string agent, string regionName,
784  LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
785  {
786  m_host.AddScriptLPS(1);
787  UUID agentId = new UUID();
788  if (UUID.TryParse(agent, out agentId))
789  {
790  ScenePresence presence = World.GetScenePresence(agentId);
791  if (presence != null)
792  {
793  // For osTeleportAgent, agent must be over owners land to avoid abuse
794  // For osTeleportOwner, this restriction isn't necessary
795 
796  // commented out because its redundant and uneeded please remove eventually.
797  // if (relaxRestrictions ||
798  // m_host.OwnerID
799  // == World.LandChannel.GetLandObject(
800  // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
801  // {
802 
803  // We will launch the teleport on a new thread so that when the script threads are terminated
804  // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
805  Util.FireAndForget(
806  o => World.RequestTeleportLocation(
807  presence.ControllingClient, regionName, position,
808  lookat, (uint)TPFlags.ViaLocation),
809  null, "OSSL_Api.TeleportAgentByRegionCoords");
810 
811  ScriptSleep(5000);
812 
813  // }
814 
815  }
816  }
817  }
818 
819  public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
820  {
821  // High because there is no security check. High griefer potential
822  //
823  CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
824 
825  TeleportAgent(agent, regionX, regionY, position, lookat, false);
826  }
827 
828  private void TeleportAgent(string agent, int regionX, int regionY,
829  LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions)
830  {
831  ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
832 
833  m_host.AddScriptLPS(1);
834  UUID agentId = new UUID();
835  if (UUID.TryParse(agent, out agentId))
836  {
837  ScenePresence presence = World.GetScenePresence(agentId);
838  if (presence != null)
839  {
840  // For osTeleportAgent, agent must be over owners land to avoid abuse
841  // For osTeleportOwner, this restriction isn't necessary
842 
843  // commented out because its redundant and uneeded please remove eventually.
844  // if (relaxRestrictions ||
845  // m_host.OwnerID
846  // == World.LandChannel.GetLandObject(
847  // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
848  // {
849 
850  // We will launch the teleport on a new thread so that when the script threads are terminated
851  // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
852  Util.FireAndForget(
853  o => World.RequestTeleportLocation(
854  presence.ControllingClient, regionHandle,
855  position, lookat, (uint)TPFlags.ViaLocation),
856  null, "OSSL_Api.TeleportAgentByRegionName");
857 
858  ScriptSleep(5000);
859 
860  // }
861 
862  }
863  }
864  }
865 
866  public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
867  {
868  osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
869  }
870 
871  public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
872  {
873  // Threat level None because this is what can already be done with the World Map in the viewer
874  CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
875 
876  TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat, true);
877  }
878 
879  public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
880  {
881  osTeleportOwner(World.RegionInfo.RegionName, position, lookat);
882  }
883 
884  public void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
885  {
886  CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
887 
888  TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true);
889  }
890 
898  public void osForceOtherSit(string avatar)
899  {
900  CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
901 
902  m_host.AddScriptLPS(1);
903 
904  ForceSit(avatar, m_host.UUID);
905  }
906 
913  public void osForceOtherSit(string avatar, string target)
914  {
915  CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
916 
917  m_host.AddScriptLPS(1);
918 
919  UUID targetID = new UUID(target);
920 
921  ForceSit(avatar, targetID);
922  }
923 
924  public void ForceSit(string avatar, UUID targetID)
925  {
926  UUID agentID;
927 
928  if (!UUID.TryParse(avatar, out agentID))
929  return;
930 
931  ScenePresence presence = World.GetScenePresence(agentID);
932 
933  SceneObjectPart part = World.GetSceneObjectPart(targetID);
934 
935  if (presence != null &&
936  part != null &&
937  part.SitTargetAvatar == UUID.Zero)
938  presence.HandleAgentRequestSit(presence.ControllingClient,
939  agentID,
940  targetID,
941  part.SitTargetPosition);
942  }
943 
944  // Functions that get information from the agent itself.
945  //
946  // osGetAgentIP - this is used to determine the IP address of
947  //the client. This is needed to help configure other in world
948  //resources based on the IP address of the clients connected.
949  //I think High is a good risk level for this, as it is an
950  //information leak.
951  public string osGetAgentIP(string agent)
952  {
953  CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
954 
955  UUID avatarID = (UUID)agent;
956 
957  m_host.AddScriptLPS(1);
958  if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
959  {
960  ScenePresence target = (ScenePresence)World.Entities[avatarID];
961  return target.ControllingClient.RemoteEndPoint.Address.ToString();
962  }
963 
964  // fall through case, just return nothing
965  return "";
966  }
967 
968  // Get a list of all the avatars/agents in the region
970  {
971  // threat level is None as we could get this information with an
972  // in-world script as well, just not as efficient
973  CheckThreatLevel(ThreatLevel.None, "osGetAgents");
974  m_host.AddScriptLPS(1);
975 
976  LSL_List result = new LSL_List();
977  World.ForEachRootScenePresence(delegate(ScenePresence sp)
978  {
979  result.Add(new LSL_String(sp.Name));
980  });
981  return result;
982  }
983 
984  // Adam's super super custom animation functions
985  public void osAvatarPlayAnimation(string avatar, string animation)
986  {
987  CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
988 
989  AvatarPlayAnimation(avatar, animation);
990  }
991 
992  private void AvatarPlayAnimation(string avatar, string animation)
993  {
994  m_host.AddScriptLPS(1);
995 
996  UUID avatarID;
997  if(!UUID.TryParse(avatar, out avatarID))
998  return;
999 
1000  if(!World.Entities.ContainsKey(avatarID))
1001  return;
1002 
1003  ScenePresence target = null;
1004  if ((World.Entities[avatarID] is ScenePresence))
1005  target = (ScenePresence)World.Entities[avatarID];
1006 
1007  if (target == null)
1008  return;
1009 
1010  UUID animID = UUID.Zero;
1011  m_host.TaskInventory.LockItemsForRead(true);
1012  foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
1013  {
1014  if (inv.Value.Type == (int)AssetType.Animation)
1015  {
1016  if (inv.Value.Name == animation)
1017  {
1018  animID = inv.Value.AssetID;
1019  break;
1020  }
1021  }
1022  }
1023  m_host.TaskInventory.LockItemsForRead(false);
1024 
1025  if (animID == UUID.Zero)
1026  target.Animator.AddAnimation(animation, m_host.UUID);
1027  else
1028  target.Animator.AddAnimation(animID, m_host.UUID);
1029  }
1030 
1031  public void osAvatarStopAnimation(string avatar, string animation)
1032  {
1033  CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
1034 
1035  AvatarStopAnimation(avatar, animation);
1036  }
1037 
1038  private void AvatarStopAnimation(string avatar, string animation)
1039  {
1040  UUID avatarID = (UUID)avatar;
1041 
1042  m_host.AddScriptLPS(1);
1043 
1044  // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
1045  // method (though see that doesn't do the is animation check, which is probably a bug) and have both
1046  // these functions call that common code. However, this does mean navigating the brain-dead requirement
1047  // of calling InitLSL()
1048  if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
1049  {
1050  ScenePresence target = (ScenePresence)World.Entities[avatarID];
1051  if (target != null)
1052  {
1053  UUID animID;
1054 
1055  if (!UUID.TryParse(animation, out animID))
1056  {
1057  TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
1058  if (item != null && item.Type == (int)AssetType.Animation)
1059  animID = item.AssetID;
1060  else
1061  animID = UUID.Zero;
1062  }
1063 
1064 
1065  if (animID == UUID.Zero)
1066  target.Animator.RemoveAnimation(animation);
1067  else
1068  target.Animator.RemoveAnimation(animID, true);
1069  }
1070  }
1071  }
1072 
1073  //Texture draw functions
1074  public string osMovePen(string drawList, int x, int y)
1075  {
1076  CheckThreatLevel(ThreatLevel.None, "osMovePen");
1077 
1078  m_host.AddScriptLPS(1);
1079  drawList += "MoveTo " + x + "," + y + ";";
1080  return drawList;
1081  }
1082 
1083  public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
1084  {
1085  CheckThreatLevel(ThreatLevel.None, "osDrawLine");
1086 
1087  m_host.AddScriptLPS(1);
1088  drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
1089  return drawList;
1090  }
1091 
1092  public string osDrawLine(string drawList, int endX, int endY)
1093  {
1094  CheckThreatLevel(ThreatLevel.None, "osDrawLine");
1095 
1096  m_host.AddScriptLPS(1);
1097  drawList += "LineTo " + endX + "," + endY + "; ";
1098  return drawList;
1099  }
1100 
1101  public string osDrawText(string drawList, string text)
1102  {
1103  CheckThreatLevel(ThreatLevel.None, "osDrawText");
1104 
1105  m_host.AddScriptLPS(1);
1106  drawList += "Text " + text + "; ";
1107  return drawList;
1108  }
1109 
1110  public string osDrawEllipse(string drawList, int width, int height)
1111  {
1112  CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
1113 
1114  m_host.AddScriptLPS(1);
1115  drawList += "Ellipse " + width + "," + height + "; ";
1116  return drawList;
1117  }
1118 
1119  public string osDrawRectangle(string drawList, int width, int height)
1120  {
1121  CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
1122 
1123  m_host.AddScriptLPS(1);
1124  drawList += "Rectangle " + width + "," + height + "; ";
1125  return drawList;
1126  }
1127 
1128  public string osDrawFilledRectangle(string drawList, int width, int height)
1129  {
1130  CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
1131 
1132  m_host.AddScriptLPS(1);
1133  drawList += "FillRectangle " + width + "," + height + "; ";
1134  return drawList;
1135  }
1136 
1137  public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
1138  {
1139  CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
1140 
1141  m_host.AddScriptLPS(1);
1142 
1143  if (x.Length != y.Length || x.Length < 3)
1144  {
1145  return "";
1146  }
1147  drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
1148  for (int i = 1; i < x.Length; i++)
1149  {
1150  drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
1151  }
1152  drawList += "; ";
1153  return drawList;
1154  }
1155 
1156  public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
1157  {
1158  CheckThreatLevel(ThreatLevel.None, "osDrawPolygon");
1159 
1160  m_host.AddScriptLPS(1);
1161 
1162  if (x.Length != y.Length || x.Length < 3)
1163  {
1164  return "";
1165  }
1166  drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
1167  for (int i = 1; i < x.Length; i++)
1168  {
1169  drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
1170  }
1171  drawList += "; ";
1172  return drawList;
1173  }
1174 
1175  public string osSetFontSize(string drawList, int fontSize)
1176  {
1177  CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
1178 
1179  m_host.AddScriptLPS(1);
1180  drawList += "FontSize "+ fontSize +"; ";
1181  return drawList;
1182  }
1183 
1184  public string osSetFontName(string drawList, string fontName)
1185  {
1186  CheckThreatLevel(ThreatLevel.None, "osSetFontName");
1187 
1188  m_host.AddScriptLPS(1);
1189  drawList += "FontName "+ fontName +"; ";
1190  return drawList;
1191  }
1192 
1193  public string osSetPenSize(string drawList, int penSize)
1194  {
1195  CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
1196 
1197  m_host.AddScriptLPS(1);
1198  drawList += "PenSize " + penSize + "; ";
1199  return drawList;
1200  }
1201 
1202  public string osSetPenColor(string drawList, string color)
1203  {
1204  CheckThreatLevel(ThreatLevel.None, "osSetPenColor");
1205 
1206  m_host.AddScriptLPS(1);
1207  drawList += "PenColor " + color + "; ";
1208  return drawList;
1209  }
1210 
1211  // Deprecated
1212  public string osSetPenColour(string drawList, string colour)
1213  {
1214  CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
1215  OSSLDeprecated("osSetPenColour", "osSetPenColor");
1216 
1217  m_host.AddScriptLPS(1);
1218  drawList += "PenColour " + colour + "; ";
1219  return drawList;
1220  }
1221 
1222  public string osSetPenCap(string drawList, string direction, string type)
1223  {
1224  CheckThreatLevel(ThreatLevel.None, "osSetPenCap");
1225 
1226  m_host.AddScriptLPS(1);
1227  drawList += "PenCap " + direction + "," + type + "; ";
1228  return drawList;
1229  }
1230 
1231  public string osDrawImage(string drawList, int width, int height, string imageUrl)
1232  {
1233  CheckThreatLevel(ThreatLevel.None, "osDrawImage");
1234 
1235  m_host.AddScriptLPS(1);
1236  drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
1237  return drawList;
1238  }
1239 
1240  public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
1241  {
1242  CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
1243  m_host.AddScriptLPS(1);
1244 
1245  LSL_Vector vec = new LSL_Vector(0,0,0);
1246  IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
1247  if (textureManager != null)
1248  {
1249  double xSize, ySize;
1250  textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
1251  out xSize, out ySize);
1252  vec.x = xSize;
1253  vec.y = ySize;
1254  }
1255  return vec;
1256  }
1257 
1258  public void osSetStateEvents(int events)
1259  {
1260  // This function is a hack. There is no reason for it's existence
1261  // anymore, since state events now work properly.
1262  // It was probably added as a crutch or debugging aid, and
1263  // should be removed
1264  //
1265  CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
1266  m_host.AddScriptLPS(1);
1267 
1268  m_host.SetScriptEvents(m_item.ItemID, events);
1269  }
1270 
1271  public void osSetRegionWaterHeight(double height)
1272  {
1273  CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
1274 
1275  m_host.AddScriptLPS(1);
1276 
1277  World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1278  }
1279 
1286  public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
1287  {
1288  CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
1289 
1290  m_host.AddScriptLPS(1);
1291 
1292  while (sunHour > 24.0)
1293  sunHour -= 24.0;
1294 
1295  while (sunHour < 0)
1296  sunHour += 24.0;
1297 
1298  World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
1299  World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
1300  World.RegionInfo.RegionSettings.FixedSun = sunFixed;
1301  World.RegionInfo.RegionSettings.Save();
1302 
1303  World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
1304  }
1305 
1311  public void osSetEstateSunSettings(bool sunFixed, double sunHour)
1312  {
1313  CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
1314 
1315  m_host.AddScriptLPS(1);
1316 
1317  while (sunHour > 24.0)
1318  sunHour -= 24.0;
1319 
1320  while (sunHour < 0)
1321  sunHour += 24.0;
1322 
1323  World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
1324  World.RegionInfo.EstateSettings.SunPosition = sunHour;
1325  World.RegionInfo.EstateSettings.FixedSun = sunFixed;
1326  World.EstateDataService.StoreEstateSettings(World.RegionInfo.EstateSettings);
1327 
1328  World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle);
1329  }
1330 
1335  public double osGetCurrentSunHour()
1336  {
1337  CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
1338 
1339  m_host.AddScriptLPS(1);
1340 
1341  // Must adjust for the fact that Region Sun Settings are still LL offset
1342  double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
1343 
1344  // See if the sun module has registered itself, if so it's authoritative
1345  ISunModule module = World.RequestModuleInterface<ISunModule>();
1346  if (module != null)
1347  {
1348  sunHour = module.GetCurrentSunHour();
1349  }
1350 
1351  return sunHour;
1352  }
1353 
1354  public double osSunGetParam(string param)
1355  {
1356  CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
1357  OSSLDeprecated("osSunGetParam", "osGetSunParam");
1358  return GetSunParam(param);
1359  }
1360 
1361  public double osGetSunParam(string param)
1362  {
1363  CheckThreatLevel(ThreatLevel.None, "osGetSunParam");
1364  return GetSunParam(param);
1365  }
1366 
1367  private double GetSunParam(string param)
1368  {
1369  m_host.AddScriptLPS(1);
1370 
1371  double value = 0.0;
1372 
1373  ISunModule module = World.RequestModuleInterface<ISunModule>();
1374  if (module != null)
1375  {
1376  value = module.GetSunParameter(param);
1377  }
1378 
1379  return value;
1380  }
1381 
1382  public void osSunSetParam(string param, double value)
1383  {
1384  CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
1385  OSSLDeprecated("osSunSetParam", "osSetSunParam");
1386  SetSunParam(param, value);
1387  }
1388 
1389  public void osSetSunParam(string param, double value)
1390  {
1391  CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
1392  SetSunParam(param, value);
1393  }
1394 
1395  private void SetSunParam(string param, double value)
1396  {
1397  m_host.AddScriptLPS(1);
1398 
1399  ISunModule module = World.RequestModuleInterface<ISunModule>();
1400  if (module != null)
1401  {
1402  module.SetSunParameter(param, value);
1403  }
1404  }
1405 
1407  {
1408  CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
1409  m_host.AddScriptLPS(1);
1410 
1411  IWindModule module = World.RequestModuleInterface<IWindModule>();
1412  if (module != null)
1413  {
1414  return module.WindActiveModelPluginName;
1415  }
1416 
1417  return String.Empty;
1418  }
1419 
1420  public void osSetWindParam(string plugin, string param, LSL_Float value)
1421  {
1422  CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
1423  m_host.AddScriptLPS(1);
1424 
1425  IWindModule module = World.RequestModuleInterface<IWindModule>();
1426  if (module != null)
1427  {
1428  try
1429  {
1430  module.WindParamSet(plugin, param, (float)value);
1431  }
1432  catch (Exception) { }
1433  }
1434  }
1435 
1436  public LSL_Float osGetWindParam(string plugin, string param)
1437  {
1438  CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
1439  m_host.AddScriptLPS(1);
1440 
1441  IWindModule module = World.RequestModuleInterface<IWindModule>();
1442  if (module != null)
1443  {
1444  return module.WindParamGet(plugin, param);
1445  }
1446 
1447  return 0.0f;
1448  }
1449 
1450  // Routines for creating and managing parcels programmatically
1451  public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
1452  {
1453  CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
1454  m_host.AddScriptLPS(1);
1455 
1456  int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
1457  int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
1458  int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
1459  int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
1460 
1461  World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
1462  }
1463 
1464  public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
1465  {
1466  CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
1467  m_host.AddScriptLPS(1);
1468 
1469  int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
1470  int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
1471  int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
1472  int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
1473 
1474  World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
1475  }
1476 
1477  public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
1478  {
1479  const string functionName = "osParcelSetDetails";
1480  CheckThreatLevel(ThreatLevel.High, functionName);
1481  OSSLDeprecated(functionName, "osSetParcelDetails");
1482  SetParcelDetails(pos, rules, functionName);
1483  }
1484 
1485  public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
1486  {
1487  const string functionName = "osSetParcelDetails";
1488  CheckThreatLevel(ThreatLevel.High, functionName);
1489  SetParcelDetails(pos, rules, functionName);
1490  }
1491 
1492  private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
1493  {
1494  m_host.AddScriptLPS(1);
1495 
1496  // Get a reference to the land data and make sure the owner of the script
1497  // can modify it
1498 
1499  ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
1500  if (startLandObject == null)
1501  {
1502  OSSLShoutError("There is no land at that location");
1503  return;
1504  }
1505 
1506  if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions, false))
1507  {
1508  OSSLShoutError("You do not have permission to modify the parcel");
1509  return;
1510  }
1511 
1512  // Create a new land data object we can modify
1513  LandData newLand = startLandObject.LandData.Copy();
1514  UUID uuid;
1515 
1516  // Process the rules, not sure what the impact would be of changing owner or group
1517  for (int idx = 0; idx < rules.Length;)
1518  {
1519  int code = rules.GetLSLIntegerItem(idx++);
1520  string arg = rules.GetLSLStringItem(idx++);
1521  switch (code)
1522  {
1523  case ScriptBaseClass.PARCEL_DETAILS_NAME:
1524  newLand.Name = arg;
1525  break;
1526 
1527  case ScriptBaseClass.PARCEL_DETAILS_DESC:
1528  newLand.Description = arg;
1529  break;
1530 
1531  case ScriptBaseClass.PARCEL_DETAILS_OWNER:
1532  CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
1533  if (UUID.TryParse(arg, out uuid))
1534  newLand.OwnerID = uuid;
1535  break;
1536 
1538  CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
1539  if (UUID.TryParse(arg, out uuid))
1540  newLand.GroupID = uuid;
1541  break;
1542 
1544  CheckThreatLevel(ThreatLevel.VeryHigh, functionName);
1545  newLand.ClaimDate = Convert.ToInt32(arg);
1546  if (newLand.ClaimDate == 0)
1547  newLand.ClaimDate = Util.UnixTimeSinceEpoch();
1548  break;
1549  }
1550  }
1551 
1552  World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
1553  }
1554 
1555  public double osList2Double(LSL_Types.list src, int index)
1556  {
1557  // There is really no double type in OSSL. C# and other
1558  // have one, but the current implementation of LSL_Types.list
1559  // is not allowed to contain any.
1560  // This really should be removed.
1561  //
1562  CheckThreatLevel(ThreatLevel.None, "osList2Double");
1563 
1564  m_host.AddScriptLPS(1);
1565  if (index < 0)
1566  {
1567  index = src.Length + index;
1568  }
1569  if (index >= src.Length)
1570  {
1571  return 0.0;
1572  }
1573  return Convert.ToDouble(src.Data[index]);
1574  }
1575 
1576  public void osSetParcelMediaURL(string url)
1577  {
1578  // What actually is the difference to the LL function?
1579  //
1580  CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
1581 
1582  m_host.AddScriptLPS(1);
1583 
1584  ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
1585 
1586  if (land.LandData.OwnerID != m_host.OwnerID)
1587  return;
1588 
1589  land.SetMediaUrl(url);
1590  }
1591 
1592  public void osSetParcelSIPAddress(string SIPAddress)
1593  {
1594  // What actually is the difference to the LL function?
1595  //
1596  CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
1597 
1598  m_host.AddScriptLPS(1);
1599 
1600  ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
1601 
1602  if (land.LandData.OwnerID != m_host.OwnerID)
1603  {
1604  OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
1605  return;
1606  }
1607 
1608  // get the voice module
1609  IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
1610 
1611  if (voiceModule != null)
1612  voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
1613  else
1614  OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
1615  }
1616 
1617  public string osGetScriptEngineName()
1618  {
1619  // This gets a "high" because knowing the engine may be used
1620  // to exploit engine-specific bugs or induce usage patterns
1621  // that trigger engine-specific failures.
1622  // Besides, public grid users aren't supposed to know.
1623  //
1624  CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
1625 
1626  m_host.AddScriptLPS(1);
1627 
1628  int scriptEngineNameIndex = 0;
1629 
1630  if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
1631  {
1632  // parse off the "ScriptEngine."
1633  scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
1634  scriptEngineNameIndex++; // get past delimiter
1635 
1636  int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
1637 
1638  // create char array then a string that is only the script engine name
1639  Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
1640  String scriptEngineName = new String(scriptEngineNameCharArray);
1641 
1642  return scriptEngineName;
1643  }
1644  else
1645  {
1646  return String.Empty;
1647  }
1648  }
1649 
1651  {
1652  m_host.AddScriptLPS(1);
1653  LSL_Integer ret = 0; // false
1654  if (m_ScriptEngine.World.PhysicsScene != null)
1655  {
1656  string physEngine = m_ScriptEngine.World.PhysicsScene.EngineType;
1657  if (physEngine == "OpenDynamicsEngine")
1658  {
1659  ret = 1; // true
1660  }
1661  }
1662  return ret;
1663  }
1664 
1665  public string osGetPhysicsEngineType()
1666  {
1667  // High because it can be used to target attacks to known weaknesses
1668  // This would allow a new class of griefer scripts that don't even
1669  // require their user to know what they are doing (see script
1670  // kiddie)
1671  // Because it would be nice if scripts didn't blow up if the information
1672  // about the physics engine, this function returns an empty string if
1673  // the user does not have permission to see it. This as opposed to
1674  // throwing an exception.
1675  m_host.AddScriptLPS(1);
1676  string ret = String.Empty;
1677  if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
1678  {
1679  if (m_ScriptEngine.World.PhysicsScene != null)
1680  {
1681  ret = m_ScriptEngine.World.PhysicsScene.EngineType;
1682  // An old physics engine might have an uninitialized engine type
1683  if (ret == null)
1684  ret = "unknown";
1685  }
1686  }
1687 
1688  return ret;
1689  }
1690 
1691  public string osGetSimulatorVersion()
1692  {
1693  // High because it can be used to target attacks to known weaknesses
1694  // This would allow a new class of griefer scripts that don't even
1695  // require their user to know what they are doing (see script
1696  // kiddie)
1697  //
1698  CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
1699  m_host.AddScriptLPS(1);
1700 
1701  return m_ScriptEngine.World.GetSimulatorVersion();
1702  }
1703 
1704  private Hashtable osdToHashtable(OSDMap map)
1705  {
1706  Hashtable result = new Hashtable();
1707  foreach (KeyValuePair<string, OSD> item in map) {
1708  result.Add(item.Key, osdToObject(item.Value));
1709  }
1710  return result;
1711  }
1712 
1713  private ArrayList osdToArray(OSDArray list)
1714  {
1715  ArrayList result = new ArrayList();
1716  foreach ( OSD item in list ) {
1717  result.Add(osdToObject(item));
1718  }
1719  return result;
1720  }
1721 
1722  private Object osdToObject(OSD decoded)
1723  {
1724  if ( decoded is OSDString ) {
1725  return (string) decoded.AsString();
1726  } else if ( decoded is OSDInteger ) {
1727  return (int) decoded.AsInteger();
1728  } else if ( decoded is OSDReal ) {
1729  return (float) decoded.AsReal();
1730  } else if ( decoded is OSDBoolean ) {
1731  return (bool) decoded.AsBoolean();
1732  } else if ( decoded is OSDMap ) {
1733  return osdToHashtable((OSDMap) decoded);
1734  } else if ( decoded is OSDArray ) {
1735  return osdToArray((OSDArray) decoded);
1736  } else {
1737  return null;
1738  }
1739  }
1740 
1741  public Object osParseJSONNew(string JSON)
1742  {
1743  CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
1744 
1745  m_host.AddScriptLPS(1);
1746 
1747  try
1748  {
1749  OSD decoded = OSDParser.DeserializeJson(JSON);
1750  return osdToObject(decoded);
1751  }
1752  catch(Exception e)
1753  {
1754  OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
1755  return null;
1756  }
1757  }
1758 
1759  public Hashtable osParseJSON(string JSON)
1760  {
1761  CheckThreatLevel(ThreatLevel.None, "osParseJSON");
1762 
1763  m_host.AddScriptLPS(1);
1764 
1765  Object decoded = osParseJSONNew(JSON);
1766 
1767  if ( decoded is Hashtable ) {
1768  return (Hashtable) decoded;
1769  } else if ( decoded is ArrayList ) {
1770  ArrayList decoded_list = (ArrayList) decoded;
1771  Hashtable fakearray = new Hashtable();
1772  int i = 0;
1773  for ( i = 0; i < decoded_list.Count ; i++ ) {
1774  fakearray.Add(i, decoded_list[i]);
1775  }
1776  return fakearray;
1777  } else {
1778  OSSLError("osParseJSON: unable to parse JSON string " + JSON);
1779  return null;
1780  }
1781  }
1782 
1792  public void osMessageObject(LSL_Key objectUUID, string message)
1793  {
1794  CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
1795  m_host.AddScriptLPS(1);
1796 
1797  UUID objUUID;
1798  if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
1799  {
1800  OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs");
1801  return;
1802  }
1803 
1804  MessageObject(objUUID, message);
1805  }
1806 
1807  private void MessageObject(UUID objUUID, string message)
1808  {
1809  object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
1810 
1811  SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
1812 
1813  if (sceneOP == null) // prior to patching, PostObjectEvent() would cause a throw exception to be shouted instead.
1814  {
1815  OSSLShoutError("osMessageObject() cannot send message to " + objUUID.ToString() + ", object was not found in scene.");
1816  return;
1817  }
1818 
1819  m_ScriptEngine.PostObjectEvent(
1820  sceneOP.LocalId, new EventParams(
1821  "dataserver", resobj, new DetectParams[0]));
1822  }
1823 
1834  public void osMakeNotecard(string notecardName, LSL_Types.list contents)
1835  {
1836  CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
1837  m_host.AddScriptLPS(1);
1838 
1839  StringBuilder notecardData = new StringBuilder();
1840 
1841  for (int i = 0; i < contents.Length; i++)
1842  notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
1843 
1844  SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
1845  }
1846 
1858  protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
1859  {
1860  // Create new asset
1861  AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
1862  asset.Description = description;
1863  byte[] a;
1864  byte[] b;
1865  byte[] c;
1866 
1867  b = Util.UTF8.GetBytes(data);
1868 
1869  a = Util.UTF8.GetBytes(
1870  "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + b.Length.ToString() + "\n");
1871 
1872  c = Util.UTF8.GetBytes("}");
1873 
1874  byte[] d = new byte[a.Length + b.Length + c.Length];
1875  Buffer.BlockCopy(a, 0, d, 0, a.Length);
1876  Buffer.BlockCopy(b, 0, d, a.Length, b.Length);
1877  Buffer.BlockCopy(c, 0, d, a.Length + b.Length, c.Length);
1878 
1879  asset.Data = d;
1880  World.AssetService.Store(asset);
1881 
1882  // Create Task Entry
1883  TaskInventoryItem taskItem = new TaskInventoryItem();
1884 
1885  taskItem.ResetIDs(m_host.UUID);
1886  taskItem.ParentID = m_host.UUID;
1887  taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
1888  taskItem.Name = asset.Name;
1889  taskItem.Description = asset.Description;
1890  taskItem.Type = (int)AssetType.Notecard;
1891  taskItem.InvType = (int)InventoryType.Notecard;
1892  taskItem.OwnerID = m_host.OwnerID;
1893  taskItem.CreatorID = m_host.OwnerID;
1894  taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1895  taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
1896  taskItem.EveryonePermissions = 0;
1897  taskItem.NextPermissions = (uint)PermissionMask.All;
1898  taskItem.GroupID = m_host.GroupID;
1899  taskItem.GroupPermissions = 0;
1900  taskItem.Flags = 0;
1901  taskItem.PermsGranter = UUID.Zero;
1902  taskItem.PermsMask = 0;
1903  taskItem.AssetID = asset.FullID;
1904 
1905  if (forceSameName)
1906  m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
1907  else
1908  m_host.Inventory.AddInventoryItem(taskItem, false);
1909 
1910  return taskItem;
1911  }
1912 
1918  protected string LoadNotecard(string notecardNameOrUuid)
1919  {
1920  UUID assetID = CacheNotecard(notecardNameOrUuid);
1921 
1922  if (assetID != UUID.Zero)
1923  {
1924  StringBuilder notecardData = new StringBuilder();
1925 
1926  for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1927  {
1928  string line = NotecardCache.GetLine(assetID, count) + "\n";
1929 
1930  // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
1931 
1932  notecardData.Append(line);
1933  }
1934 
1935  return notecardData.ToString();
1936  }
1937 
1938  return null;
1939  }
1940 
1949  protected UUID CacheNotecard(string notecardNameOrUuid)
1950  {
1951  UUID assetID = UUID.Zero;
1952 
1953  bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
1954 
1955  if (!notecardNameIsUUID)
1956  {
1957  assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1958  }
1959 
1960  if (assetID == UUID.Zero)
1961  return UUID.Zero;
1962 
1963  if (!NotecardCache.IsCached(assetID))
1964  {
1965  AssetBase a = World.AssetService.Get(assetID.ToString());
1966 
1967  if (a == null)
1968  {
1969  // Whoops, it's still possible here that the notecard name was properly
1970  // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
1971  assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1972  if (assetID == UUID.Zero)
1973  return UUID.Zero;
1974 
1975  if (!NotecardCache.IsCached(assetID))
1976  {
1977  a = World.AssetService.Get(assetID.ToString());
1978 
1979  if (a == null)
1980  {
1981  return UUID.Zero;
1982  }
1983  }
1984  }
1985 
1986  NotecardCache.Cache(assetID, a.Data);
1987  };
1988 
1989  return assetID;
1990  }
1991  protected UUID SearchTaskInventoryForAssetId(string name)
1992  {
1993  UUID assetId = UUID.Zero;
1994  m_host.TaskInventory.LockItemsForRead(true);
1995  foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1996  {
1997  if (item.Type == 7 && item.Name == name)
1998  {
1999  assetId = item.AssetID;
2000  }
2001  }
2002  m_host.TaskInventory.LockItemsForRead(false);
2003  return assetId;
2004  }
2005 
2019  public string osGetNotecardLine(string name, int line)
2020  {
2021  CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
2022  m_host.AddScriptLPS(1);
2023 
2024  UUID assetID = CacheNotecard(name);
2025 
2026  if (assetID == UUID.Zero)
2027  {
2028  OSSLShoutError("Notecard '" + name + "' could not be found.");
2029  return "ERROR!";
2030  }
2031 
2032  return NotecardCache.GetLine(assetID, line);
2033  }
2034 
2047  public string osGetNotecard(string name)
2048  {
2049  CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
2050  m_host.AddScriptLPS(1);
2051 
2052  string text = LoadNotecard(name);
2053 
2054  if (text == null)
2055  {
2056  OSSLShoutError("Notecard '" + name + "' could not be found.");
2057  return "ERROR!";
2058  }
2059  else
2060  {
2061  return text;
2062  }
2063  }
2064 
2077  public int osGetNumberOfNotecardLines(string name)
2078  {
2079  CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
2080  m_host.AddScriptLPS(1);
2081 
2082  UUID assetID = CacheNotecard(name);
2083 
2084  if (assetID == UUID.Zero)
2085  {
2086  OSSLShoutError("Notecard '" + name + "' could not be found.");
2087  return -1;
2088  }
2089 
2090  return NotecardCache.GetLines(assetID);
2091  }
2092 
2093  public string osAvatarName2Key(string firstname, string lastname)
2094  {
2095  CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
2096  m_host.AddScriptLPS(1);
2097 
2098  IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
2099  if (userManager == null)
2100  {
2101  OSSLShoutError("osAvatarName2Key: UserManagement module not available");
2102  return string.Empty;
2103  }
2104 
2105  // Check if the user is already cached
2106 
2107  UUID userID = userManager.GetUserIdByName(firstname, lastname);
2108  if (userID != UUID.Zero)
2109  return userID.ToString();
2110 
2111  // Query for the user
2112 
2113  String realFirstName; String realLastName; String serverURI;
2114  if (Util.ParseForeignAvatarName(firstname, lastname, out realFirstName, out realLastName, out serverURI))
2115  {
2116  try
2117  {
2118  UserAgentServiceConnector userConnection = new UserAgentServiceConnector(serverURI, true);
2119 
2120  if (userConnection != null)
2121  {
2122  userID = userConnection.GetUUID(realFirstName, realLastName);
2123  if (userID != UUID.Zero)
2124  {
2125  userManager.AddUser(userID, realFirstName, realLastName, serverURI);
2126  return userID.ToString();
2127  }
2128  }
2129  }
2130  catch (Exception /*e*/)
2131  {
2132  // m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid ", e);
2133  }
2134  }
2135  else
2136  {
2137  UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
2138  if (account != null)
2139  return account.PrincipalID.ToString();
2140  }
2141 
2142  return UUID.Zero.ToString();
2143  }
2144 
2145  public string osKey2Name(string id)
2146  {
2147  CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
2148  m_host.AddScriptLPS(1);
2149 
2150  UUID key = new UUID();
2151 
2152  if (UUID.TryParse(id, out key))
2153  {
2154  UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
2155  if (account != null)
2156  return account.Name;
2157 
2158  if (m_ScriptEngine.World.GridUserService != null)
2159  {
2160  GridUserInfo uInfo = m_ScriptEngine.World.GridUserService.GetGridUserInfo(key.ToString());
2161 
2162  if (uInfo != null)
2163  {
2164  UUID userUUID; String gridURL; String firstName; String lastName; String tmp;
2165 
2166  if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out userUUID, out gridURL, out firstName, out lastName, out tmp))
2167  {
2168  string grid = new Uri(gridURL).Authority;
2169  return firstName + "." + lastName + " @" + grid;
2170  }
2171  }
2172  }
2173  }
2174 
2175  return "";
2176  }
2177 
2178  private enum InfoType
2179  {
2180  Nick,
2181  Name,
2182  Login,
2183  Home,
2184  Custom
2185  };
2186 
2187  private string GridUserInfo(InfoType type)
2188  {
2189  return GridUserInfo(type, "");
2190  }
2191 
2192  private string GridUserInfo(InfoType type, string key)
2193  {
2194  string retval = String.Empty;
2195  IConfigSource config = m_ScriptEngine.ConfigSource;
2196  string url = null;
2197 
2198  IConfig gridInfoConfig = config.Configs["GridInfo"];
2199 
2200  if (gridInfoConfig != null)
2201  url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
2202 
2203  if (String.IsNullOrEmpty(url))
2204  return "Configuration Error!";
2205 
2206  string verb ="/json_grid_info";
2207  OSDMap json = new OSDMap();
2208 
2209  OSDMap info = WebUtil.GetFromService(String.Format("{0}{1}",url,verb), 3000);
2210 
2211  if (info["Success"] != true)
2212  return "Get GridInfo Failed!";
2213 
2214  json = (OSDMap)OSDParser.DeserializeJson(info["_RawResult"].AsString());
2215 
2216  switch (type)
2217  {
2218  case InfoType.Nick:
2219  retval = json["gridnick"];
2220  break;
2221 
2222  case InfoType.Name:
2223  retval = json["gridname"];
2224  break;
2225 
2226  case InfoType.Login:
2227  retval = json["login"];
2228  break;
2229 
2230  case InfoType.Home:
2231  retval = json["home"];
2232  break;
2233 
2234  case InfoType.Custom:
2235  retval = json[key];
2236  break;
2237 
2238  default:
2239  retval = "error";
2240  break;
2241  }
2242 
2243  return retval;
2244  }
2245 
2255  public string osGetGridNick()
2256  {
2257  CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
2258  m_host.AddScriptLPS(1);
2259 
2260  string nick = String.Empty;
2261  IConfigSource config = m_ScriptEngine.ConfigSource;
2262 
2263  if (config.Configs[GridInfoServiceConfigSectionName] != null)
2264  nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
2265 
2266  if (String.IsNullOrEmpty(nick))
2267  nick = GridUserInfo(InfoType.Nick);
2268 
2269  return nick;
2270  }
2271 
2272  public string osGetGridName()
2273  {
2274  CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
2275  m_host.AddScriptLPS(1);
2276 
2277  string name = String.Empty;
2278  IConfigSource config = m_ScriptEngine.ConfigSource;
2279 
2280  if (config.Configs[GridInfoServiceConfigSectionName] != null)
2281  name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
2282 
2283  if (String.IsNullOrEmpty(name))
2284  name = GridUserInfo(InfoType.Name);
2285 
2286  return name;
2287  }
2288 
2289  public string osGetGridLoginURI()
2290  {
2291  CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
2292  m_host.AddScriptLPS(1);
2293 
2294  string loginURI = String.Empty;
2295  IConfigSource config = m_ScriptEngine.ConfigSource;
2296 
2297  if (config.Configs[GridInfoServiceConfigSectionName] != null)
2298  loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
2299 
2300  if (String.IsNullOrEmpty(loginURI))
2301  loginURI = GridUserInfo(InfoType.Login);
2302 
2303  return loginURI;
2304  }
2305 
2306  public string osGetGridHomeURI()
2307  {
2308  CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
2309  m_host.AddScriptLPS(1);
2310 
2311  IConfigSource config = m_ScriptEngine.ConfigSource;
2312  string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
2313  new string[] { "Startup", "Hypergrid" }, String.Empty);
2314 
2315  if (!string.IsNullOrEmpty(HomeURI))
2316  return HomeURI;
2317 
2318  // Legacy. Remove soon!
2319  if (config.Configs["LoginService"] != null)
2320  HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI);
2321 
2322  if (String.IsNullOrEmpty(HomeURI))
2323  HomeURI = GridUserInfo(InfoType.Home);
2324 
2325  return HomeURI;
2326  }
2327 
2328  public string osGetGridGatekeeperURI()
2329  {
2330  CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
2331  m_host.AddScriptLPS(1);
2332 
2333  IConfigSource config = m_ScriptEngine.ConfigSource;
2334  string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
2335  new string[] { "Startup", "Hypergrid" }, String.Empty);
2336 
2337  if (!string.IsNullOrEmpty(gatekeeperURI))
2338  return gatekeeperURI;
2339 
2340  // Legacy. Remove soon!
2341  if (config.Configs["GridService"] != null)
2342  gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI);
2343 
2344  return gatekeeperURI;
2345  }
2346 
2347  public string osGetGridCustom(string key)
2348  {
2349  CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
2350  m_host.AddScriptLPS(1);
2351 
2352  string retval = String.Empty;
2353  IConfigSource config = m_ScriptEngine.ConfigSource;
2354 
2355  if (config.Configs[GridInfoServiceConfigSectionName] != null)
2356  retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
2357 
2358  if (String.IsNullOrEmpty(retval))
2359  retval = GridUserInfo(InfoType.Custom, key);
2360 
2361  return retval;
2362  }
2363 
2364  public string osGetAvatarHomeURI(string uuid)
2365  {
2366  CheckThreatLevel(ThreatLevel.Low, "osGetAvatarHomeURI");
2367  m_host.AddScriptLPS(1);
2368 
2369  IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>();
2370  string returnValue = "";
2371 
2372  if (userManager != null)
2373  {
2374  returnValue = userManager.GetUserServerURL(new UUID(uuid), "HomeURI");
2375  }
2376 
2377  if (returnValue == "")
2378  {
2379  IConfigSource config = m_ScriptEngine.ConfigSource;
2380  returnValue = Util.GetConfigVarFromSections<string>(config, "HomeURI",
2381  new string[] { "Startup", "Hypergrid" }, String.Empty);
2382 
2383  if (!string.IsNullOrEmpty(returnValue))
2384  return returnValue;
2385 
2386  // Legacy. Remove soon!
2387  if (config.Configs["LoginService"] != null)
2388  returnValue = config.Configs["LoginService"].GetString("SRV_HomeURI", returnValue);
2389 
2390  if (String.IsNullOrEmpty(returnValue))
2391  returnValue = GridUserInfo(InfoType.Home);
2392  }
2393 
2394  return returnValue;
2395  }
2396 
2397  public LSL_String osFormatString(string str, LSL_List strings)
2398  {
2399  CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
2400  m_host.AddScriptLPS(1);
2401 
2402  return String.Format(str, strings.Data);
2403  }
2404 
2405  public LSL_List osMatchString(string src, string pattern, int start)
2406  {
2407  CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
2408  m_host.AddScriptLPS(1);
2409 
2410  LSL_List result = new LSL_List();
2411 
2412  // Normalize indices (if negative).
2413  // After normlaization they may still be
2414  // negative, but that is now relative to
2415  // the start, rather than the end, of the
2416  // sequence.
2417  if (start < 0)
2418  {
2419  start = src.Length + start;
2420  }
2421 
2422  if (start < 0 || start >= src.Length)
2423  {
2424  return result; // empty list
2425  }
2426 
2427  // Find matches beginning at start position
2428  Regex matcher = new Regex(pattern);
2429  Match match = matcher.Match(src, start);
2430  while (match.Success)
2431  {
2432  foreach (System.Text.RegularExpressions.Group g in match.Groups)
2433  {
2434  if (g.Success)
2435  {
2436  result.Add(new LSL_String(g.Value));
2437  result.Add(new LSL_Integer(g.Index));
2438  }
2439  }
2440 
2441  match = match.NextMatch();
2442  }
2443 
2444  return result;
2445  }
2446 
2447  public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
2448  {
2449  CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
2450  m_host.AddScriptLPS(1);
2451 
2452  // Normalize indices (if negative).
2453  // After normlaization they may still be
2454  // negative, but that is now relative to
2455  // the start, rather than the end, of the
2456  // sequence.
2457  if (start < 0)
2458  {
2459  start = src.Length + start;
2460  }
2461 
2462  if (start < 0 || start >= src.Length)
2463  {
2464  return src;
2465  }
2466 
2467  // Find matches beginning at start position
2468  Regex matcher = new Regex(pattern);
2469  return matcher.Replace(src,replace,count,start);
2470  }
2471 
2472  public string osLoadedCreationDate()
2473  {
2474  CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
2475  m_host.AddScriptLPS(1);
2476 
2477  return World.RegionInfo.RegionSettings.LoadedCreationDate;
2478  }
2479 
2480  public string osLoadedCreationTime()
2481  {
2482  CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
2483  m_host.AddScriptLPS(1);
2484 
2485  return World.RegionInfo.RegionSettings.LoadedCreationTime;
2486  }
2487 
2488  public string osLoadedCreationID()
2489  {
2490  CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
2491  m_host.AddScriptLPS(1);
2492 
2493  return World.RegionInfo.RegionSettings.LoadedCreationID;
2494  }
2495 
2509  public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
2510  {
2511  CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
2512  m_host.AddScriptLPS(1);
2513  InitLSL();
2514  // One needs to cast m_LSL_Api because we're using functions not
2515  // on the ILSL_Api interface.
2516  LSL_Api LSL_Api = (LSL_Api)m_LSL_Api;
2517  LSL_List retVal = new LSL_List();
2518  LSL_List remaining = new LSL_List();
2519  List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber);
2520  foreach (SceneObjectPart part in parts)
2521  {
2522  remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
2523  }
2524 
2525  while (remaining.Length > 2)
2526  {
2527  linknumber = remaining.GetLSLIntegerItem(0);
2528  rules = remaining.GetSublist(1, -1);
2529  parts = LSL_Api.GetLinkParts(linknumber);
2530 
2531  foreach (SceneObjectPart part in parts)
2532  remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
2533  }
2534  return retVal;
2535  }
2536 
2537  public void osForceCreateLink(string target, int parent)
2538  {
2539  CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink");
2540 
2541  m_host.AddScriptLPS(1);
2542 
2543  InitLSL();
2544  ((LSL_Api)m_LSL_Api).CreateLink(target, parent);
2545  }
2546 
2547  public void osForceBreakLink(int linknum)
2548  {
2549  CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink");
2550 
2551  m_host.AddScriptLPS(1);
2552 
2553  InitLSL();
2554  ((LSL_Api)m_LSL_Api).BreakLink(linknum);
2555  }
2556 
2557  public void osForceBreakAllLinks()
2558  {
2559  CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks");
2560 
2561  m_host.AddScriptLPS(1);
2562 
2563  InitLSL();
2564  ((LSL_Api)m_LSL_Api).BreakAllLinks();
2565  }
2566 
2568  {
2569  CheckThreatLevel(ThreatLevel.None, "osIsNpc");
2570  m_host.AddScriptLPS(1);
2571 
2572  INPCModule module = World.RequestModuleInterface<INPCModule>();
2573  if (module != null)
2574  {
2575  UUID npcId;
2576  if (UUID.TryParse(npc.m_string, out npcId))
2577  if (module.IsNPC(npcId, World))
2578  return ScriptBaseClass.TRUE;
2579  }
2580 
2581  return ScriptBaseClass.FALSE;
2582  }
2583 
2584  public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
2585  {
2586  CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2587  m_host.AddScriptLPS(1);
2588 
2589  // have to get the npc module also here to set the default Not Owned
2590  INPCModule module = World.RequestModuleInterface<INPCModule>();
2591  if(module == null)
2592  return new LSL_Key(UUID.Zero.ToString());
2593 
2594  bool owned = (module.NPCOptionFlags & NPCOptionsFlags.AllowNotOwned) == 0;
2595 
2596  return NpcCreate(firstname, lastname, position, notecard, owned, false, false);
2597  }
2598 
2599  public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
2600  {
2601  CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2602  m_host.AddScriptLPS(1);
2603 
2604  return NpcCreate(
2605  firstname, lastname, position, notecard,
2606  (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
2607  (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0,
2608  (options & ScriptBaseClass.OS_NPC_OBJECT_GROUP) != 0);
2609  }
2610 
2611  private LSL_Key NpcCreate(
2612  string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent, bool hostGroupID)
2613  {
2614 
2615  if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
2616  return new LSL_Key(UUID.Zero.ToString());
2617 
2618  INPCModule module = World.RequestModuleInterface<INPCModule>();
2619  if(module == null)
2620  new LSL_Key(UUID.Zero.ToString());
2621 
2622  string groupTitle = String.Empty;
2623  UUID groupID = UUID.Zero;
2624 
2625  AvatarAppearance appearance = null;
2626 
2627  // check creation options
2628  NPCOptionsFlags createFlags = module.NPCOptionFlags;
2629 
2630  if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
2631  {
2632  OSSLError("Not owned NPCs disabled");
2633  owned = true; // we should get here...
2634  }
2635 
2636  if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
2637  {
2638  OSSLError("NPC allow sense as Avatar disabled");
2639  senseAsAgent = false;
2640  }
2641 
2642  if(hostGroupID && m_host.GroupID != UUID.Zero)
2643  {
2644  IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
2645  if (groupsModule != null)
2646  {
2647  GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
2648  if (member == null)
2649  {
2650  OSSLError(string.Format("osNpcCreate: the object owner is not member of the object group"));
2651  return new LSL_Key(UUID.Zero.ToString());
2652  }
2653 
2654  groupID = m_host.GroupID;
2655 
2656  if((createFlags & NPCOptionsFlags.NoNPCGroup) != 0)
2657  {
2658  GroupRecord grprec = groupsModule.GetGroupRecord(m_host.GroupID);
2659  if(grprec != null && grprec.GroupName != "")
2660  groupTitle = grprec.GroupName;
2661  }
2662  }
2663  }
2664 
2665  if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
2666  {
2667  if (firstname != String.Empty || lastname != String.Empty)
2668  {
2669  if (firstname != "Shown outfit:")
2670  groupTitle = "- NPC -";
2671  }
2672  }
2673 
2674  if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
2675  {
2676  UUID id;
2677  if (UUID.TryParse(notecard, out id))
2678  {
2679  ScenePresence clonePresence = World.GetScenePresence(id);
2680  if (clonePresence != null)
2681  appearance = clonePresence.Appearance;
2682  }
2683  }
2684 
2685  if (appearance == null)
2686  {
2687  string appearanceSerialized = LoadNotecard(notecard);
2688 
2689  if (appearanceSerialized != null)
2690  {
2691  try
2692  {
2693  OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2694  appearance = new AvatarAppearance();
2695  appearance.Unpack(appearanceOsd);
2696  }
2697  catch
2698  {
2699  OSSLError(string.Format("osNpcCreate: Error processing notcard '{0}'", notecard));
2700  return new LSL_Key(UUID.Zero.ToString());
2701  }
2702  }
2703  else
2704  {
2705  OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
2706  }
2707  }
2708 
2709  UUID ownerID = UUID.Zero;
2710  if (owned)
2711  ownerID = m_host.OwnerID;
2712  UUID x = module.CreateNPC(firstname,
2713  lastname,
2714  position,
2715  ownerID,
2716  senseAsAgent,
2717  World,
2718  appearance);
2719 
2720  ScenePresence sp;
2721  if (World.TryGetScenePresence(x, out sp))
2722  {
2723  sp.Grouptitle = groupTitle;
2724  ((INPC)(sp.ControllingClient)).ActiveGroupId = groupID;
2725 
2726  sp.SendAvatarDataToAllAgents();
2727  }
2728  return new LSL_Key(x.ToString());
2729  }
2730 
2737  public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
2738  {
2739  CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
2740  m_host.AddScriptLPS(1);
2741 
2742  INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2743 
2744  if (npcModule != null)
2745  {
2746  UUID npcId;
2747  if (!UUID.TryParse(npc.m_string, out npcId))
2748  return new LSL_Key(UUID.Zero.ToString());
2749 
2750  if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2751  return new LSL_Key(UUID.Zero.ToString());
2752 
2753  return SaveAppearanceToNotecard(npcId, notecard);
2754  }
2755 
2756  return new LSL_Key(UUID.Zero.ToString());
2757  }
2758 
2759  public void osNpcLoadAppearance(LSL_Key npc, string notecard)
2760  {
2761  CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
2762  m_host.AddScriptLPS(1);
2763 
2764  INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2765 
2766  if (npcModule != null)
2767  {
2768  UUID npcId;
2769  if (!UUID.TryParse(npc.m_string, out npcId))
2770  return;
2771 
2772  if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2773  return;
2774 
2775  string appearanceSerialized = LoadNotecard(notecard);
2776 
2777  if (appearanceSerialized == null)
2778  OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
2779 
2780  OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2781 // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
2782 // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
2783 // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
2784  AvatarAppearance appearance = new AvatarAppearance();
2785  appearance.Unpack(appearanceOsd);
2786 
2787  npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
2788  }
2789  }
2790 
2792  {
2793  CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
2794  m_host.AddScriptLPS(1);
2795 
2796  INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2797  if (npcModule != null)
2798  {
2799  UUID npcId;
2800  if (UUID.TryParse(npc.m_string, out npcId))
2801  {
2802  UUID owner = npcModule.GetOwner(npcId);
2803  if (owner != UUID.Zero)
2804  return new LSL_Key(owner.ToString());
2805  else
2806  return npc;
2807  }
2808  }
2809 
2810  return new LSL_Key(UUID.Zero.ToString());
2811  }
2812 
2814  {
2815  CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
2816  m_host.AddScriptLPS(1);
2817 
2818  INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2819  if (npcModule != null)
2820  {
2821  UUID npcId;
2822  if (!UUID.TryParse(npc.m_string, out npcId))
2823  return new LSL_Vector(0, 0, 0);
2824 
2825  if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2826  return new LSL_Vector(0, 0, 0);
2827 
2828  ScenePresence sp = World.GetScenePresence(npcId);
2829 
2830  if (sp != null)
2831  return new LSL_Vector(sp.AbsolutePosition);
2832  }
2833 
2834  return Vector3.Zero;
2835  }
2836 
2837  public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
2838  {
2839  CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
2840  m_host.AddScriptLPS(1);
2841 
2842  INPCModule module = World.RequestModuleInterface<INPCModule>();
2843  if (module != null)
2844  {
2845  UUID npcId;
2846  if (!UUID.TryParse(npc.m_string, out npcId))
2847  return;
2848 
2849  if (!module.CheckPermissions(npcId, m_host.OwnerID))
2850  return;
2851 
2852  module.MoveToTarget(npcId, World, pos, false, true, false);
2853  }
2854  }
2855 
2856  public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
2857  {
2858  CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
2859  m_host.AddScriptLPS(1);
2860 
2861  INPCModule module = World.RequestModuleInterface<INPCModule>();
2862  if (module != null)
2863  {
2864  UUID npcId;
2865  if (!UUID.TryParse(npc.m_string, out npcId))
2866  return;
2867 
2868  if (!module.CheckPermissions(npcId, m_host.OwnerID))
2869  return;
2870 
2871  module.MoveToTarget(
2872  new UUID(npc.m_string),
2873  World,
2874  target,
2875  (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2876  (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
2877  (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
2878  }
2879  }
2880 
2882  {
2883  CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
2884  m_host.AddScriptLPS(1);
2885 
2886  INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2887  if (npcModule != null)
2888  {
2889  UUID npcId;
2890  if (!UUID.TryParse(npc.m_string, out npcId))
2891  return new LSL_Rotation(Quaternion.Identity);
2892 
2893  if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2894  return new LSL_Rotation(Quaternion.Identity);
2895 
2896  ScenePresence sp = World.GetScenePresence(npcId);
2897 
2898  if (sp != null)
2899  return new LSL_Rotation(sp.GetWorldRotation());
2900  }
2901 
2902  return Quaternion.Identity;
2903  }
2904 
2906  {
2907  CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
2908  m_host.AddScriptLPS(1);
2909 
2910  INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2911  if (npcModule != null)
2912  {
2913  UUID npcId;
2914  if (!UUID.TryParse(npc.m_string, out npcId))
2915  return;
2916 
2917  if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2918  return;
2919 
2920  ScenePresence sp = World.GetScenePresence(npcId);
2921 
2922  if (sp != null)
2923  sp.Rotation = rotation;
2924  }
2925  }
2926 
2928  {
2929  CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
2930  m_host.AddScriptLPS(1);
2931 
2932  INPCModule module = World.RequestModuleInterface<INPCModule>();
2933  if (module != null)
2934  {
2935  UUID npcId = new UUID(npc.m_string);
2936 
2937  if (!module.CheckPermissions(npcId, m_host.OwnerID))
2938  return;
2939 
2940  module.StopMoveToTarget(npcId, World);
2941  }
2942  }
2943 
2944  public void osNpcSay(LSL_Key npc, string message)
2945  {
2946  osNpcSay(npc, 0, message);
2947  }
2948 
2949  public void osNpcSay(LSL_Key npc, int channel, string message)
2950  {
2951  CheckThreatLevel(ThreatLevel.High, "osNpcSay");
2952  m_host.AddScriptLPS(1);
2953 
2954  INPCModule module = World.RequestModuleInterface<INPCModule>();
2955  if (module != null)
2956  {
2957  UUID npcId = new UUID(npc.m_string);
2958 
2959  if (!module.CheckPermissions(npcId, m_host.OwnerID))
2960  return;
2961 
2962  module.Say(npcId, World, message, channel);
2963  }
2964  }
2965 
2966  public void osNpcShout(LSL_Key npc, int channel, string message)
2967  {
2968  CheckThreatLevel(ThreatLevel.High, "osNpcShout");
2969  m_host.AddScriptLPS(1);
2970 
2971  INPCModule module = World.RequestModuleInterface<INPCModule>();
2972  if (module != null)
2973  {
2974  UUID npcId = new UUID(npc.m_string);
2975 
2976  if (!module.CheckPermissions(npcId, m_host.OwnerID))
2977  return;
2978 
2979  module.Shout(npcId, World, message, channel);
2980  }
2981  }
2982 
2983  public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
2984  {
2985  CheckThreatLevel(ThreatLevel.High, "osNpcSit");
2986  m_host.AddScriptLPS(1);
2987 
2988  INPCModule module = World.RequestModuleInterface<INPCModule>();
2989  if (module != null)
2990  {
2991  UUID npcId = new UUID(npc.m_string);
2992 
2993  if (!module.CheckPermissions(npcId, m_host.OwnerID))
2994  return;
2995 
2996  module.Sit(npcId, new UUID(target.m_string), World);
2997  }
2998  }
2999 
3000  public void osNpcStand(LSL_Key npc)
3001  {
3002  CheckThreatLevel(ThreatLevel.High, "osNpcStand");
3003  m_host.AddScriptLPS(1);
3004 
3005  INPCModule module = World.RequestModuleInterface<INPCModule>();
3006  if (module != null)
3007  {
3008  UUID npcId = new UUID(npc.m_string);
3009 
3010  if (!module.CheckPermissions(npcId, m_host.OwnerID))
3011  return;
3012 
3013  module.Stand(npcId, World);
3014  }
3015  }
3016 
3017  public void osNpcRemove(LSL_Key npc)
3018  {
3019  CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
3020  m_host.AddScriptLPS(1);
3021 
3022  try
3023  {
3024  INPCModule module = World.RequestModuleInterface<INPCModule>();
3025  if (module != null)
3026  {
3027  UUID npcId = new UUID(npc.m_string);
3028 
3029  if (!module.CheckPermissions(npcId, m_host.OwnerID))
3030  return;
3031 
3032  module.DeleteNPC(npcId, World);
3033  }
3034  }
3035  catch { }
3036  }
3037 
3038  public void osNpcPlayAnimation(LSL_Key npc, string animation)
3039  {
3040  CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
3041  m_host.AddScriptLPS(1);
3042 
3043  INPCModule module = World.RequestModuleInterface<INPCModule>();
3044  if (module != null)
3045  {
3046  UUID npcID = new UUID(npc.m_string);
3047 
3048  if (module.CheckPermissions(npcID, m_host.OwnerID))
3049  AvatarPlayAnimation(npcID.ToString(), animation);
3050  }
3051  }
3052 
3053  public void osNpcStopAnimation(LSL_Key npc, string animation)
3054  {
3055  CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
3056  m_host.AddScriptLPS(1);
3057 
3058  INPCModule module = World.RequestModuleInterface<INPCModule>();
3059  if (module != null)
3060  {
3061  UUID npcID = new UUID(npc.m_string);
3062 
3063  if (module.CheckPermissions(npcID, m_host.OwnerID))
3064  AvatarStopAnimation(npcID.ToString(), animation);
3065  }
3066  }
3067 
3068  public void osNpcWhisper(LSL_Key npc, int channel, string message)
3069  {
3070  CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
3071  m_host.AddScriptLPS(1);
3072 
3073  INPCModule module = World.RequestModuleInterface<INPCModule>();
3074  if (module != null)
3075  {
3076  UUID npcId = new UUID(npc.m_string);
3077 
3078  if (!module.CheckPermissions(npcId, m_host.OwnerID))
3079  return;
3080 
3081  module.Whisper(npcId, World, message, channel);
3082  }
3083  }
3084 
3085  public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
3086  {
3087  CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
3088  m_host.AddScriptLPS(1);
3089 
3090  INPCModule module = World.RequestModuleInterface<INPCModule>();
3091  int linkNum = link_num.value;
3092  if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
3093  {
3094  UUID npcId;
3095  if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
3096  return;
3097 
3098  SceneObjectPart part = null;
3099  UUID objectId;
3100  if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
3101  part = World.GetSceneObjectPart(objectId);
3102 
3103  if (part == null)
3104  return;
3105 
3106  if (linkNum != ScriptBaseClass.LINK_THIS)
3107  {
3108  if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
3109  { // 0 and 1 are treated as root, find the root if the current part isnt it
3110  if (!part.IsRoot)
3111  part = part.ParentGroup.RootPart;
3112  }
3113  else
3114  { // Find the prim with the given link number if not found then fail silently
3115  part = part.ParentGroup.GetLinkNumPart(linkNum);
3116  if (part == null)
3117  return;
3118  }
3119  }
3120 
3121  module.Touch(npcId, part.UUID);
3122  }
3123  }
3124 
3130  public LSL_Key osOwnerSaveAppearance(string notecard)
3131  {
3132  CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
3133  m_host.AddScriptLPS(1);
3134 
3135  return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
3136  }
3137 
3138  public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
3139  {
3140  CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
3141  m_host.AddScriptLPS(1);
3142 
3143  return SaveAppearanceToNotecard(avatarId, notecard);
3144  }
3145 
3146  protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
3147  {
3148  IAvatarFactoryModule appearanceModule = World.RequestModuleInterface<IAvatarFactoryModule>();
3149 
3150  if (appearanceModule != null)
3151  {
3152  appearanceModule.SaveBakedTextures(sp.UUID);
3154  OSDMap appearancePacked = sp.Appearance.Pack(ctx);
3155 
3156  TaskInventoryItem item
3157  = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
3158 
3159  return new LSL_Key(item.AssetID.ToString());
3160  }
3161  else
3162  {
3163  return new LSL_Key(UUID.Zero.ToString());
3164  }
3165  }
3166 
3167  protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
3168  {
3169  ScenePresence sp = World.GetScenePresence(avatarId);
3170 
3171  if (sp == null || sp.IsChildAgent)
3172  return new LSL_Key(UUID.Zero.ToString());
3173 
3174  return SaveAppearanceToNotecard(sp, notecard);
3175  }
3176 
3177  protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
3178  {
3179  UUID avatarId;
3180  if (!UUID.TryParse(rawAvatarId, out avatarId))
3181  return new LSL_Key(UUID.Zero.ToString());
3182 
3183  return SaveAppearanceToNotecard(avatarId, notecard);
3184  }
3185 
3191  public LSL_String osGetGender(LSL_Key rawAvatarId)
3192  {
3193  CheckThreatLevel(ThreatLevel.None, "osGetGender");
3194  m_host.AddScriptLPS(1);
3195 
3196  UUID avatarId;
3197  if (!UUID.TryParse(rawAvatarId, out avatarId))
3198  return new LSL_String("unknown");
3199 
3200  ScenePresence sp = World.GetScenePresence(avatarId);
3201 
3202  if (sp == null || sp.IsChildAgent || sp.Appearance == null || sp.Appearance.VisualParams == null)
3203  return new LSL_String("unknown");
3204 
3205  // find the index of "shape" parameter "male"
3206  int vpShapeMaleIndex = 0;
3207  bool indexFound = false;
3208  VisualParam param = new VisualParam();
3209  foreach(var vpEntry in VisualParams.Params)
3210  {
3211  param = vpEntry.Value;
3212  if (param.Name == "male" && param.Wearable == "shape")
3213  {
3214  indexFound = true;
3215  break;
3216  }
3217 
3218  if (param.Group == 0)
3219  vpShapeMaleIndex++;
3220  }
3221 
3222  if (!indexFound)
3223  return new LSL_String("unknown");
3224 
3225  float vpShapeMale = Utils.ByteToFloat(sp.Appearance.VisualParams[vpShapeMaleIndex], param.MinValue, param.MaxValue);
3226 
3227  bool isMale = vpShapeMale > 0.5f;
3228  return new LSL_String(isMale ? "male" : "female");
3229  }
3230 
3236  {
3237  CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
3238  m_host.AddScriptLPS(1);
3239 
3240  return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
3241  }
3242 
3248  public LSL_Key osGetRegionMapTexture(string regionName)
3249  {
3250  CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
3251  m_host.AddScriptLPS(1);
3252 
3253  Scene scene = m_ScriptEngine.World;
3254  UUID key = UUID.Zero;
3255  GridRegion region;
3256 
3257  //If string is a key, use it. Otherwise, try to locate region by name.
3258  if (UUID.TryParse(regionName, out key))
3259  region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
3260  else
3261  region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
3262 
3263  // If region was found, return the regions map texture key.
3264  if (region != null)
3265  key = region.TerrainImage;
3266 
3267  ScriptSleep(1000);
3268 
3269  return key.ToString();
3270  }
3271 
3280  {
3281  CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
3282  m_host.AddScriptLPS(1);
3283  LSL_List ret = new LSL_List();
3284  float[] stats = World.StatsReporter.LastReportedSimStats;
3285 
3286  for (int i = 0; i < 21; i++)
3287  {
3288  ret.Add(new LSL_Float(stats[i]));
3289  }
3290  return ret;
3291  }
3292 
3294  {
3295  CheckThreatLevel(ThreatLevel.None, "osGetRegionSize");
3296  m_host.AddScriptLPS(1);
3297 
3298  bool isMegaregion;
3299  IRegionCombinerModule rcMod = World.RequestModuleInterface<IRegionCombinerModule>();
3300  if (rcMod != null)
3301  isMegaregion = rcMod.IsRootForMegaregion(World.RegionInfo.RegionID);
3302  else
3303  isMegaregion = false;
3304 
3305  if (isMegaregion)
3306  {
3307  Vector2 size = rcMod.GetSizeOfMegaregion(World.RegionInfo.RegionID);
3308  return new LSL_Vector(size.X, size.Y, Constants.RegionHeight);
3309  }
3310  else
3311  {
3312  Scene scene = m_ScriptEngine.World;
3313  GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
3314  return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeY, (float)Constants.RegionHeight);
3315  }
3316  }
3317 
3319  {
3320  CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
3321  m_host.AddScriptLPS(1);
3322  long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
3323 
3324  if (pws > Int32.MaxValue)
3325  return Int32.MaxValue;
3326  if (pws < 0)
3327  return 0;
3328 
3329  return (int)pws;
3330  }
3331 
3332  public void osSetSpeed(string UUID, LSL_Float SpeedModifier)
3333  {
3334  CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
3335  m_host.AddScriptLPS(1);
3336  ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
3337 
3338  if (avatar != null)
3339  avatar.SpeedModifier = (float)SpeedModifier;
3340  }
3341 
3342  public void osKickAvatar(string FirstName, string SurName, string alert)
3343  {
3344  CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
3345  m_host.AddScriptLPS(1);
3346 
3347  World.ForEachRootScenePresence(delegate(ScenePresence sp)
3348  {
3349  if (sp.Firstname == FirstName && sp.Lastname == SurName)
3350  {
3351  // kick client...
3352  if (alert != null)
3353  sp.ControllingClient.Kick(alert);
3354 
3355  // ...and close on our side
3356  sp.Scene.CloseAgent(sp.UUID, false);
3357  }
3358  });
3359  }
3360 
3361  public LSL_Float osGetHealth(string avatar)
3362  {
3363  CheckThreatLevel(ThreatLevel.None, "osGetHealth");
3364  m_host.AddScriptLPS(1);
3365 
3366  LSL_Float health = new LSL_Float(-1);
3367  ScenePresence presence = World.GetScenePresence(new UUID(avatar));
3368  if (presence != null) health = presence.Health;
3369  return health;
3370  }
3371 
3372  public void osCauseDamage(string avatar, double damage)
3373  {
3374  CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
3375  m_host.AddScriptLPS(1);
3376 
3377  UUID avatarId = new UUID(avatar);
3378  Vector3 pos = m_host.GetWorldPosition();
3379 
3380  ScenePresence presence = World.GetScenePresence(avatarId);
3381  if (presence != null)
3382  {
3383  LandData land = World.GetLandData(pos);
3384  if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
3385  {
3386  float health = presence.Health;
3387  health -= (float)damage;
3388  presence.setHealthWithUpdate(health);
3389  if (health <= 0)
3390  {
3391  float healthliveagain = 100;
3392  presence.ControllingClient.SendAgentAlertMessage("You died!", true);
3393  presence.setHealthWithUpdate(healthliveagain);
3394  presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
3395  }
3396  }
3397  }
3398  }
3399 
3400  public void osCauseHealing(string avatar, double healing)
3401  {
3402  CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
3403  m_host.AddScriptLPS(1);
3404 
3405  UUID avatarId = new UUID(avatar);
3406  ScenePresence presence = World.GetScenePresence(avatarId);
3407 
3408  if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition()))
3409  {
3410  float health = presence.Health;
3411  health += (float)healing;
3412 
3413  if (health >= 100)
3414  health = 100;
3415 
3416  presence.setHealthWithUpdate(health);
3417  }
3418  }
3419 
3421  {
3422  CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
3423  m_host.AddScriptLPS(1);
3424  InitLSL();
3425 
3426  return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
3427  }
3428 
3429  public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
3430  {
3431  CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams");
3432  m_host.AddScriptLPS(1);
3433  InitLSL();
3434 
3435  m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
3436  }
3437 
3441  public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
3442  {
3443  CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
3444 
3445  osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
3446  }
3447 
3451  public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
3452  {
3453  CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
3454  m_host.AddScriptLPS(1);
3455 
3456  SceneObjectPart obj = null;
3457  if (prim == UUID.Zero.ToString())
3458  {
3459  obj = m_host;
3460  }
3461  else
3462  {
3463  obj = World.GetSceneObjectPart(new UUID(prim));
3464  if (obj == null)
3465  return;
3466  }
3467 
3468  obj.Shape.ProjectionEntry = projection;
3469  obj.Shape.ProjectionTextureUUID = new UUID(texture);
3470  obj.Shape.ProjectionFOV = (float)fov;
3471  obj.Shape.ProjectionFocus = (float)focus;
3472  obj.Shape.ProjectionAmbiance = (float)amb;
3473 
3474  obj.ParentGroup.HasGroupChanged = true;
3475  obj.ScheduleFullUpdate();
3476  }
3477 
3483  {
3484  CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
3485  m_host.AddScriptLPS(1);
3486 
3487  LSL_List result = new LSL_List();
3488  World.ForEachRootScenePresence(delegate (ScenePresence avatar)
3489  {
3490  if (avatar != null && avatar.UUID != m_host.OwnerID)
3491  {
3492  result.Add(new LSL_String(avatar.UUID.ToString()));
3493  result.Add(new LSL_Vector(avatar.AbsolutePosition));
3494  result.Add(new LSL_String(avatar.Name));
3495  }
3496  });
3497 
3498  return result;
3499  }
3500 
3507  {
3508  CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
3509  m_host.AddScriptLPS(1);
3510 
3511  long baseTicks = 621355968000000000;
3512  long tickResolution = 10000000;
3513  long epochTicks = (time * tickResolution) + baseTicks;
3514  DateTime date = new DateTime(epochTicks);
3515 
3516  return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
3517  }
3518 
3524  public LSL_String osGetInventoryDesc(string item)
3525  {
3526  m_host.AddScriptLPS(1);
3527 
3528  lock (m_host.TaskInventory)
3529  {
3530  foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3531  {
3532  if (inv.Value.Name == item)
3533  {
3534  return inv.Value.Description.ToString();
3535  }
3536  }
3537  }
3538 
3539  return String.Empty;
3540  }
3541 
3548  {
3549  CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
3550  m_host.AddScriptLPS(1);
3551 
3552  UUID agent = new UUID(agentId);
3553 
3554  // groups module is required
3555  IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
3556  if (groupsModule == null) return ScriptBaseClass.FALSE;
3557 
3558  // object has to be set to a group, but not group owned
3559  if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
3560 
3561  // object owner has to be in that group and required permissions
3562  GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
3563  if (member == null || (member.GroupPowers & (ulong)GroupPowers.Invite) == 0) return ScriptBaseClass.FALSE;
3564 
3565  // check if agent is in that group already
3566  //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
3567  //if (member != null) return ScriptBaseClass.FALSE;
3568 
3569  // invited agent has to be present in this scene
3570  if (World.GetScenePresence(agent) == null) return ScriptBaseClass.FALSE;
3571 
3572  groupsModule.InviteGroup(null, m_host.OwnerID, m_host.GroupID, agent, UUID.Zero);
3573 
3574  return ScriptBaseClass.TRUE;
3575  }
3576 
3583  {
3584  CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
3585  m_host.AddScriptLPS(1);
3586 
3587  UUID agent = new UUID(agentId);
3588 
3589  // groups module is required
3590  IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
3591  if (groupsModule == null) return ScriptBaseClass.FALSE;
3592 
3593  // object has to be set to a group, but not group owned
3594  if (m_host.GroupID == UUID.Zero || m_host.GroupID == m_host.OwnerID) return ScriptBaseClass.FALSE;
3595 
3596  // object owner has to be in that group and required permissions
3597  GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
3598  if (member == null || (member.GroupPowers & (ulong)GroupPowers.Eject) == 0) return ScriptBaseClass.FALSE;
3599 
3600  // agent has to be in that group
3601  //member = groupsModule.GetMembershipData(agent, m_host.GroupID, agent);
3602  //if (member == null) return ScriptBaseClass.FALSE;
3603 
3604  // ejectee can be offline
3605 
3606  groupsModule.EjectGroupMember(null, m_host.OwnerID, m_host.GroupID, agent);
3607 
3608  return ScriptBaseClass.TRUE;
3609  }
3610 
3617  public void osSetTerrainTexture(int level, LSL_Key texture)
3618  {
3619  CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3620 
3621  m_host.AddScriptLPS(1);
3622  //Check to make sure that the script's owner is the estate manager/master
3623  //World.Permissions.GenericEstatePermission(
3624  if (World.Permissions.IsGod(m_host.OwnerID))
3625  {
3626  if (level < 0 || level > 3)
3627  return;
3628 
3629  UUID textureID = new UUID();
3630  if (!UUID.TryParse(texture, out textureID))
3631  return;
3632 
3633  // estate module is required
3634  IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3635  if (estate != null)
3636  estate.setEstateTerrainBaseTexture(level, textureID);
3637  }
3638  }
3639 
3647  public void osSetTerrainTextureHeight(int corner, double low, double high)
3648  {
3649  CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3650 
3651  m_host.AddScriptLPS(1);
3652  //Check to make sure that the script's owner is the estate manager/master
3653  //World.Permissions.GenericEstatePermission(
3654  if (World.Permissions.IsGod(m_host.OwnerID))
3655  {
3656  if (corner < 0 || corner > 3)
3657  return;
3658 
3659  // estate module is required
3660  IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3661  if (estate != null)
3662  estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
3663  }
3664  }
3665 
3666  #region Attachment commands
3667 
3668  public void osForceAttachToAvatar(int attachmentPoint)
3669  {
3670  CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3671 
3672  m_host.AddScriptLPS(1);
3673 
3674  InitLSL();
3675  ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
3676  }
3677 
3678  public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
3679  {
3680  CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
3681 
3682  m_host.AddScriptLPS(1);
3683 
3684  ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
3685  }
3686 
3687  public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
3688  {
3689  CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory");
3690 
3691  m_host.AddScriptLPS(1);
3692 
3693  UUID avatarId;
3694 
3695  if (!UUID.TryParse(rawAvatarId, out avatarId))
3696  return;
3697 
3698  ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
3699  }
3700 
3701  public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
3702  {
3703  IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3704 
3705  if (attachmentsModule == null)
3706  return;
3707 
3708  InitLSL();
3709 
3710  TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
3711 
3712  if (item == null)
3713  {
3714  ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Could not find object '{0}'", itemName));
3715  throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
3716  }
3717 
3718  if (item.InvType != (int)InventoryType.Object)
3719  {
3720  // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
3721  // up the api reference.
3722  if (m_LSL_Api != null)
3723  ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
3724 
3725  throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
3726  }
3727 
3728  ScenePresence sp = World.GetScenePresence(avatarId);
3729 
3730  if (sp == null)
3731  return;
3732 
3733  string message;
3734  InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out message);
3735 
3736  if (newItem == null)
3737  {
3738  m_log.ErrorFormat(
3739  "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}",
3740  itemName, m_host.Name, attachmentPoint, World.Name, message);
3741  ((LSL_Api)m_LSL_Api).llSay(0, message);
3742  return;
3743  }
3744 
3745  attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
3746  }
3747 
3749  {
3750  CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3751 
3752  m_host.AddScriptLPS(1);
3753 
3754  InitLSL();
3755  ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3756  }
3757 
3758  public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
3759  {
3760  CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
3761 
3762  m_host.AddScriptLPS(1);
3763 
3764  UUID targetUUID;
3765  ScenePresence target;
3766  LSL_List resp = new LSL_List();
3767 
3768  if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
3769  {
3770  foreach (object point in attachmentPoints.Data)
3771  {
3772  LSL_Integer ipoint = new LSL_Integer(
3773  (point is LSL_Integer || point is int || point is uint) ?
3774  (int)point :
3775  0
3776  );
3777  resp.Add(ipoint);
3778  if (ipoint == 0)
3779  {
3780  // indicates zero attachments
3781  resp.Add(new LSL_Integer(0));
3782  }
3783  else
3784  {
3785  // gets the number of attachments on the attachment point
3786  resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
3787  }
3788  }
3789  }
3790 
3791  return resp;
3792  }
3793 
3794  public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
3795  {
3796  CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
3797  m_host.AddScriptLPS(1);
3798 
3799  UUID targetUUID;
3800  ScenePresence target;
3801 
3802  if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
3803  {
3804  List<int> aps = new List<int>();
3805  foreach (object point in attachmentPoints.Data)
3806  {
3807  int ipoint;
3808  if (int.TryParse(point.ToString(), out ipoint))
3809  {
3810  aps.Add(ipoint);
3811  }
3812  }
3813 
3814  List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
3815 
3816  bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
3817  bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
3818 
3819  if (msgAll && invertPoints)
3820  {
3821  return;
3822  }
3823  else if (msgAll || invertPoints)
3824  {
3825  attachments = target.GetAttachments();
3826  }
3827  else
3828  {
3829  foreach (int point in aps)
3830  {
3831  if (point > 0)
3832  {
3833  attachments.AddRange(target.GetAttachments((uint)point));
3834  }
3835  }
3836  }
3837 
3838  // if we have no attachments at this point, exit now
3839  if (attachments.Count == 0)
3840  {
3841  return;
3842  }
3843 
3844  List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>();
3845 
3846  if (invertPoints)
3847  {
3848  foreach (SceneObjectGroup attachment in attachments)
3849  {
3850  if (aps.Contains((int)attachment.AttachmentPoint))
3851  {
3852  ignoreThese.Add(attachment);
3853  }
3854  }
3855  }
3856 
3857  foreach (SceneObjectGroup attachment in ignoreThese)
3858  {
3859  attachments.Remove(attachment);
3860  }
3861  ignoreThese.Clear();
3862 
3863  // if inverting removed all attachments to check, exit now
3864  if (attachments.Count < 1)
3865  {
3866  return;
3867  }
3868 
3869  if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0)
3870  {
3871  foreach (SceneObjectGroup attachment in attachments)
3872  {
3873  if (attachment.RootPart.CreatorID != m_host.CreatorID)
3874  {
3875  ignoreThese.Add(attachment);
3876  }
3877  }
3878 
3879  foreach (SceneObjectGroup attachment in ignoreThese)
3880  {
3881  attachments.Remove(attachment);
3882  }
3883  ignoreThese.Clear();
3884 
3885  // if filtering by same object creator removed all
3886  // attachments to check, exit now
3887  if (attachments.Count == 0)
3888  {
3889  return;
3890  }
3891  }
3892 
3893  if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0)
3894  {
3895  foreach (SceneObjectGroup attachment in attachments)
3896  {
3897  if (attachment.RootPart.CreatorID != m_item.CreatorID)
3898  {
3899  ignoreThese.Add(attachment);
3900  }
3901  }
3902 
3903  foreach (SceneObjectGroup attachment in ignoreThese)
3904  {
3905  attachments.Remove(attachment);
3906  }
3907  ignoreThese.Clear();
3908 
3909  // if filtering by object creator must match originating
3910  // script creator removed all attachments to check,
3911  // exit now
3912  if (attachments.Count == 0)
3913  {
3914  return;
3915  }
3916  }
3917 
3918  foreach (SceneObjectGroup attachment in attachments)
3919  {
3920  MessageObject(attachment.RootPart.UUID, message);
3921  }
3922  }
3923  }
3924 
3925  #endregion
3926 
3932  public LSL_Integer osIsUUID(string thing)
3933  {
3934  CheckThreatLevel(ThreatLevel.None, "osIsUUID");
3935  m_host.AddScriptLPS(1);
3936 
3937  UUID test;
3938  return UUID.TryParse(thing, out test) ? 1 : 0;
3939  }
3940 
3947  public LSL_Float osMin(double a, double b)
3948  {
3949  CheckThreatLevel(ThreatLevel.None, "osMin");
3950  m_host.AddScriptLPS(1);
3951 
3952  return Math.Min(a, b);
3953  }
3954 
3961  public LSL_Float osMax(double a, double b)
3962  {
3963  CheckThreatLevel(ThreatLevel.None, "osMax");
3964  m_host.AddScriptLPS(1);
3965 
3966  return Math.Max(a, b);
3967  }
3968 
3970  {
3971  CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
3972  m_host.AddScriptLPS(1);
3973 
3974  return new LSL_Key(m_host.ParentGroup.FromPartID.ToString());
3975  }
3976 
3981  public void osSetContentType(LSL_Key id, string type)
3982  {
3983  CheckThreatLevel(ThreatLevel.High, "osSetContentType");
3984 
3985  if (m_UrlModule != null)
3986  m_UrlModule.HttpContentType(new UUID(id),type);
3987  }
3988 
3993  protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
3994  {
3995  m_host.AddScriptLPS(1);
3996  bool fail = false;
3997  if (m_item.PermsGranter != m_host.OwnerID)
3998  {
3999  fail = true;
4000  OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
4001  }
4002  else if ((m_item.PermsMask & perms) == 0)
4003  {
4004  fail = true;
4005  OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
4006  }
4007 
4008  return fail;
4009  }
4010 
4011  protected void DropAttachment(bool checkPerms)
4012  {
4013  if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
4014  {
4015  return;
4016  }
4017 
4018  IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
4019  ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
4020 
4021  if (attachmentsModule != null && sp != null)
4022  {
4023  attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
4024  }
4025  }
4026 
4027  protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
4028  {
4029  if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
4030  {
4031  return;
4032  }
4033 
4034  IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
4035  ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
4036 
4037  if (attachmentsModule != null && sp != null)
4038  {
4039  attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
4040  }
4041  }
4042 
4043  public void osDropAttachment()
4044  {
4045  CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
4046  m_host.AddScriptLPS(1);
4047 
4048  DropAttachment(true);
4049  }
4050 
4052  {
4053  CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
4054  m_host.AddScriptLPS(1);
4055 
4056  DropAttachment(false);
4057  }
4058 
4060  {
4061  CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
4062  m_host.AddScriptLPS(1);
4063 
4064  DropAttachmentAt(true, pos, rot);
4065  }
4066 
4068  {
4069  CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
4070  m_host.AddScriptLPS(1);
4071 
4072  DropAttachmentAt(false, pos, rot);
4073  }
4074 
4075  public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
4076  {
4077  CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
4078  m_host.AddScriptLPS(1);
4079  UUID keyID;
4080  UUID.TryParse(ID, out keyID);
4081 
4082  // if we want the name to be used as a regular expression, ensure it is valid first.
4083  if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
4084  {
4085  try
4086  {
4087  Regex.IsMatch("", name);
4088  }
4089  catch (Exception)
4090  {
4091  OSSLShoutError("Name regex is invalid.");
4092  return -1;
4093  }
4094  }
4095 
4096  // if we want the msg to be used as a regular expression, ensure it is valid first.
4098  {
4099  try
4100  {
4101  Regex.IsMatch("", msg);
4102  }
4103  catch (Exception)
4104  {
4105  OSSLShoutError("Message regex is invalid.");
4106  return -1;
4107  }
4108  }
4109 
4110  IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
4111  return (wComm == null) ? -1 : wComm.Listen(
4112  m_host.LocalId,
4113  m_item.ItemID,
4114  m_host.UUID,
4115  channelID,
4116  name,
4117  keyID,
4118  msg,
4119  regexBitfield
4120  );
4121  }
4122 
4123  public LSL_Integer osRegexIsMatch(string input, string pattern)
4124  {
4125  CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
4126  m_host.AddScriptLPS(1);
4127  try
4128  {
4129  return Regex.IsMatch(input, pattern) ? 1 : 0;
4130  }
4131  catch (Exception)
4132  {
4133  OSSLShoutError("Possible invalid regular expression detected.");
4134  return 0;
4135  }
4136  }
4137 
4139  {
4140  CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
4141  m_host.AddScriptLPS(1);
4142 
4143  Hashtable opts = new Hashtable();
4144  for (int i = 0 ; i < options.Length ; i++)
4145  {
4146  object opt = options.Data[i];
4147  if (opt.ToString() == "allowXss")
4148  opts["allowXss"] = true;
4149  }
4150 
4151  if (m_UrlModule != null)
4152  return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4153  return UUID.Zero.ToString();
4154  }
4155 
4157  {
4158  CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
4159  m_host.AddScriptLPS(1);
4160 
4161  Hashtable opts = new Hashtable();
4162  for (int i = 0 ; i < options.Length ; i++)
4163  {
4164  object opt = options.Data[i];
4165  if (opt.ToString() == "allowXss")
4166  opts["allowXss"] = true;
4167  }
4168 
4169  if (m_UrlModule != null)
4170  return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4171  return UUID.Zero.ToString();
4172  }
4173  }
4174 }
LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
Definition: OSSL_Api.cs:3138
void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
Definition: OSSL_Api.cs:1485
double osGetCurrentSunHour()
Return the current Sun Hour 0...24, with 0 being roughly sun-rise
Definition: OSSL_Api.cs:1335
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
Definition: CM_Api.cs:48
void osDropAttachment()
Attempts to drop an attachment to the ground
Definition: OSSL_Api.cs:4043
void osCauseDamage(string avatar, double damage)
Definition: OSSL_Api.cs:3372
LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
Definition: OSSL_Api.cs:3420
void osForceOtherSit(string avatar, string target)
Overload method of osForceOtherSit(string avatar) to allow a script NOT in the target prim to force a...
Definition: OSSL_Api.cs:913
LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
Returns a strided list of the specified attachment points and the number of attachments on those poin...
Definition: OSSL_Api.cs:3758
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
Definition: CM_Api.cs:51
void Initialize(IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
Initialize the API
Definition: OSSL_Api.cs:147
string osGetGridNick()
Get the nickname of this grid, as set in the [GridInfo] config section.
Definition: OSSL_Api.cs:2255
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_Key
Definition: OSSL_Api.cs:60
OpenMetaverse.StructuredData.OSDArray OSDArray
Contains all LSL ll-functions. This class will be in Default AppDomain.
Definition: LSL_Api.cs:95
void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
Definition: OSSL_Api.cs:4027
LSL_Key osGetMapTexture()
Get current region's map texture UUID
Definition: OSSL_Api.cs:3235
const int OS_LISTEN_REGEX_NAME
process name parameter as regex
OpenSim.Framework.Constants.TeleportFlags TeleportFlags
void osForceBreakLink(int linknum)
Identical to llBreakLink() but does not require permission from the owner.
Definition: OSSL_Api.cs:2547
void osNpcLoadAppearance(LSL_Key npc, string notecard)
Definition: OSSL_Api.cs:2759
void osSetRot(UUID target, Quaternion rotation)
Definition: OSSL_Api.cs:567
void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
Definition: OSSL_Api.cs:1464
void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
Sends a specified message to the specified avatar's attachments on the specified attachment points...
Definition: OSSL_Api.cs:3794
LSL_Integer osIsUUID(string thing)
Checks if thing is a UUID.
Definition: OSSL_Api.cs:3932
string osSetPenColour(string drawList, string colour)
Definition: OSSL_Api.cs:1212
void osNpcStopAnimation(LSL_Key npc, string animation)
Definition: OSSL_Api.cs:3053
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_Key
Definition: CM_Api.cs:50
void osSetEstateSunSettings(bool sunFixed, double sunHour)
Changes the Estate Sun Settings, then Triggers a Sun Update
Definition: OSSL_Api.cs:1311
ThreatLevel
To permit region owners to enable the extended scripting functionality of OSSL, without allowing mali...
Definition: IOSSL_Api.cs:51
string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams, bool blend, int disp, int timer, int alpha, int face)
Definition: OSSL_Api.cs:719
void osForceCreateLink(string target, int parent)
Identical to llCreateLink() but does not require permission from the owner.
Definition: OSSL_Api.cs:2537
void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
Attempts to drop an attachment at the specified coordinates while bypassing the script permissions ...
Definition: OSSL_Api.cs:4067
int ClaimDate
Date that the current owner purchased or claimed the parcel
Definition: LandData.cs:297
LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
Definition: OSSL_Api.cs:2599
void osSetWindParam(string plugin, string param, LSL_Float value)
Definition: OSSL_Api.cs:1420
void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
Set parameters for light projection with uuid of target prim
Definition: OSSL_Api.cs:3451
LSL_String osGetGender(LSL_Key rawAvatarId)
Get the gender as specified in avatar appearance for a given avatar key
Definition: OSSL_Api.cs:3191
void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
Attach an inventory item in the object containing this script to any avatar in the region without ask...
Definition: OSSL_Api.cs:3687
Contains the Avatar's Appearance and methods to manipulate the appearance.
LSL_String osFormatString(string str, LSL_List strings)
Definition: OSSL_Api.cs:2397
string osGetNotecardLine(string name, int line)
Directly get an entire notecard at once.
Definition: OSSL_Api.cs:2019
string osDrawImage(string drawList, int width, int height, string imageUrl)
Definition: OSSL_Api.cs:1231
string osAvatarName2Key(string firstname, string lastname)
Definition: OSSL_Api.cs:2093
LSL_Integer osSetTerrainHeight(int x, int y, double val)
Definition: OSSL_Api.cs:446
void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
Definition: OSSL_Api.cs:1451
OpenMetaverse.StructuredData.OSDMap OSDMap
TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
Save a notecard to prim inventory.
Definition: OSSL_Api.cs:1858
void osMakeNotecard(string notecardName, LSL_Types.list contents)
Write a notecard directly to the prim's inventory.
Definition: OSSL_Api.cs:1834
LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
Save the current appearance of the NPC permanently to the named notecard.
Definition: OSSL_Api.cs:2737
UUID CacheNotecard(string notecardNameOrUuid)
Cache a notecard's contents.
Definition: OSSL_Api.cs:1949
void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
Definition: OSSL_Api.cs:819
string LoadNotecard(string notecardNameOrUuid)
Load the notecard data found at the given prim inventory item name or asset uuid. ...
Definition: OSSL_Api.cs:1918
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
Attach an inventory item in the object containing this script to the avatar that owns it without aski...
Definition: OSSL_Api.cs:3678
void osSetParcelSIPAddress(string SIPAddress)
Definition: OSSL_Api.cs:1592
bool CheckPermissions(UUID npcID, UUID callerID)
Check if the caller has permission to manipulate the given NPC.
void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
Definition: OSSL_Api.cs:774
Represents an item in a task inventory
LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
Definition: OSSL_Api.cs:1240
void osSetSpeed(string UUID, LSL_Float SpeedModifier)
Definition: OSSL_Api.cs:3332
void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
Definition: OSSL_Api.cs:2905
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
Definition: OSSL_Api.cs:58
void osAvatarPlayAnimation(string avatar, string animation)
Definition: OSSL_Api.cs:985
const int OS_LISTEN_REGEX_MESSAGE
process message parameter as regex
LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
Get the primitive parameters of a linked prim.
Definition: OSSL_Api.cs:2509
void osNpcSay(LSL_Key npc, int channel, string message)
Definition: OSSL_Api.cs:2949
void ForceSit(string avatar, UUID targetID)
Definition: OSSL_Api.cs:924
void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
Definition: OSSL_Api.cs:2856
Temporary interface. More methods to come at some point to make NPCs more object oriented rather than...
Definition: INPCModule.cs:50
string osDrawEllipse(string drawList, int width, int height)
Definition: OSSL_Api.cs:1110
Records user information specific to a grid but which is not part of a user's account.
void osForceDropAttachment()
Attempts to drop an attachment to the ground while bypassing the script permissions ...
Definition: OSSL_Api.cs:4051
double osList2Double(LSL_Types.list src, int index)
Definition: OSSL_Api.cs:1555
LSL_Integer osTerrainSetHeight(int x, int y, double val)
Definition: OSSL_Api.cs:453
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
Definition: OSSL_Api.cs:61
LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
Definition: OSSL_Api.cs:3146
void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
Definition: OSSL_Api.cs:3085
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
Definition: ICM_Api.cs:31
void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
Definition: OSSL_Api.cs:866
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 LSL_Vector
Definition: OSSL_Api.cs:64
string osSetPenColor(string drawList, string color)
Definition: OSSL_Api.cs:1202
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 LSL_Vector
Definition: CM_Api.cs:54
void osKickAvatar(string FirstName, string SurName, string alert)
Definition: OSSL_Api.cs:3342
string osDrawLine(string drawList, int endX, int endY)
Definition: OSSL_Api.cs:1092
void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
Definition: OSSL_Api.cs:879
void osSetTerrainTextureHeight(int corner, double low, double high)
Sets terrain heights of estate
Definition: OSSL_Api.cs:3647
LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
Definition: OSSL_Api.cs:3177
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
void osForceBreakAllLinks()
Identical to llBreakAllLinks() but does not require permission from the owner.
Definition: OSSL_Api.cs:2557
LSL_String osUnixTimeToTimestamp(long time)
Convert a unix time to a llGetTimestamp() like string
Definition: OSSL_Api.cs:3506
An interface for a script API module to communicate with the engine it's running under ...
LSL_Integer osIsNpc(LSL_Key npc)
Check if the given key is an npc
Definition: OSSL_Api.cs:2567
LSL_Float osGetTerrainHeight(int x, int y)
Definition: OSSL_Api.cs:479
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion LSL_Rotation
Definition: OSSL_Api.cs:62
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
Definition: OSSL_Api.cs:63
string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams, int timer)
Definition: OSSL_Api.cs:592
const int OS_ATTACH_MSG_OBJECT_CREATOR
Instructs osMessageAttachments to only send the message to attachments with a CreatorID that matches ...
OpenSim.Framework.Constants.TeleportFlags TPFlags
Definition: Scene.cs:52
string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
Definition: OSSL_Api.cs:1083
LSL_String osGetInventoryDesc(string item)
Get the description from an inventory item
Definition: OSSL_Api.cs:3524
void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
Definition: OSSL_Api.cs:1477
int osGetNumberOfNotecardLines(string name)
Get the number of lines in the given notecard.
Definition: OSSL_Api.cs:2077
void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
Definition: OSSL_Api.cs:2837
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion rotation
Definition: ICM_Api.cs:32
UUID GroupID
Unique ID of the Group that owns
Definition: LandData.cs:342
string osSetPenCap(string drawList, string direction, string type)
Definition: OSSL_Api.cs:1222
void osMessageObject(LSL_Key objectUUID, string message)
Send a message to to object identified by the given UUID
Definition: OSSL_Api.cs:1792
string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams, int timer)
Definition: OSSL_Api.cs:661
string osDrawRectangle(string drawList, int width, int height)
Definition: OSSL_Api.cs:1119
override Vector3 AbsolutePosition
Position of this avatar relative to the region the avatar is in
uint AttachmentPoint
Attachment point of this scene object to an avatar.
void osCauseHealing(string avatar, double healing)
Definition: OSSL_Api.cs:3400
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Definition: CM_Api.cs:49
Inventory Item - contains all the properties associated with an individual inventory piece...
LSL_Float osMax(double a, double b)
Wraps to Math.max()
Definition: OSSL_Api.cs:3961
LSL_Key osOwnerSaveAppearance(string notecard)
Save the current appearance of the script owner permanently to the named notecard.
Definition: OSSL_Api.cs:3130
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion LSL_Rotation
Definition: CM_Api.cs:52
void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
Definition: OSSL_Api.cs:3701
Details of a Parcel of land
Definition: LandData.cs:47
LSL_Key osGetRegionMapTexture(string regionName)
Get a region's map texture UUID by region UUID or name.
Definition: OSSL_Api.cs:3248
void osNpcPlayAnimation(LSL_Key npc, string animation)
Definition: OSSL_Api.cs:3038
void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
Definition: OSSL_Api.cs:884
string osGetNotecard(string name)
Get an entire notecard at once.
Definition: OSSL_Api.cs:2047
LSL_Float osGetWindParam(string plugin, string param)
Definition: OSSL_Api.cs:1436
void osNpcWhisper(LSL_Key npc, int channel, string message)
Definition: OSSL_Api.cs:3068
OpenMetaverse.StructuredData.OSD OSD
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
Identical to llListen except for a bitfield which indicates which string parameters should be parsed ...
Definition: OSSL_Api.cs:4075
LSL_Integer osInviteToGroup(LSL_Key agentId)
Invite user to the group this object is set to
Definition: OSSL_Api.cs:3547
void osNpcShout(LSL_Key npc, int channel, string message)
Definition: OSSL_Api.cs:2966
string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams, bool blend, int disp, int timer, int alpha, int face)
Definition: OSSL_Api.cs:639
string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
Definition: OSSL_Api.cs:1156
LSL_Key osNpcGetOwner(LSL_Key npc)
Get the owner of the NPC
Definition: OSSL_Api.cs:2791
LSL_String osRequestURL(LSL_List options)
Definition: OSSL_Api.cs:4138
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Definition: OSSL_Api.cs:59
LSL_Integer osRegexIsMatch(string input, string pattern)
Wraps to bool Regex.IsMatch(string input, string pattern)
Definition: OSSL_Api.cs:4123
Interactive OpenSim region server
Definition: OpenSim.cs:55
LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
Definition: OSSL_Api.cs:3167
const int OS_ATTACH_MSG_SCRIPT_CREATOR
Instructs osMessageAttachments to only send the message to attachments with a CreatorID that matches ...
void osSetSunParam(string param, double value)
Definition: OSSL_Api.cs:1389
OpenSim.Framework.Animation Animation
void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID GroupID, UUID InviteeID, UUID RoleID)
string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams, int timer, int alpha)
Definition: OSSL_Api.cs:690
void osForceAttachToAvatar(int attachmentPoint)
Attach the object containing this script to the avatar that owns it without asking for PERMISSION_ATT...
Definition: OSSL_Api.cs:3668
string osMovePen(string drawList, int x, int y)
Definition: OSSL_Api.cs:1074
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSLInteger
Definition: CM_Constants.cs:31
LSL_Key osGetRezzingObject()
Get the key of the object that rezzed this object.
Definition: OSSL_Api.cs:3969
LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
Definition: OSSL_Api.cs:2584
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
Definition: CM_Api.cs:53
uint Flags
Parcel settings. Access flags, Fly, NoPush, Voice, Scripts allowed, etc. ParcelFlags ...
Definition: LandData.cs:402
void osAvatarStopAnimation(string avatar, string animation)
Definition: OSSL_Api.cs:1031
UUID FullID
Asset UUID
Definition: AssetBase.cs:168
void CheckThreatLevel(ThreatLevel level, string function)
Definition: OSSL_Api.cs:263
string osSetFontName(string drawList, string fontName)
Definition: OSSL_Api.cs:1184
LSL_List osGetAvatarList()
Like osGetAgents but returns enough info for a radar
Definition: OSSL_Api.cs:3482
Quaternion GetWorldRotation()
Gets the world rotation of this presence.
void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
Definition: OSSL_Api.cs:3429
string osSetFontSize(string drawList, int fontSize)
Definition: OSSL_Api.cs:1175
void osSetContentType(LSL_Key id, string type)
Sets the response type for an HTTP request/response
Definition: OSSL_Api.cs:3981
string osDrawText(string drawList, string text)
Definition: OSSL_Api.cs:1101
OpenSim.Services.Interfaces.GridRegion GridRegion
Definition: OSSL_Api.cs:55
void osNpcSay(LSL_Key npc, string message)
Definition: OSSL_Api.cs:2944
bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
Definition: OSSL_Api.cs:3993
virtual string Name
The name of this entity
Definition: EntityBase.cs:65
Holds all the data required to execute a scripting event.
Definition: Helpers.cs:281
LSL_List osMatchString(string src, string pattern, int start)
Definition: OSSL_Api.cs:2405
LSL_Float osTerrainGetHeight(int x, int y)
Definition: OSSL_Api.cs:485
void osSetTerrainTexture(int level, LSL_Key texture)
Sets terrain estate texture
Definition: OSSL_Api.cs:3617
This maintains the relationship between a UUID and a user name.
void osSunSetParam(string param, double value)
Definition: OSSL_Api.cs:1382
void osForceDetachFromAvatar()
Detach the object containing this script from the avatar it is attached to without checking for PERMI...
Definition: OSSL_Api.cs:3748
LSL_String osRequestSecureURL(LSL_List options)
Definition: OSSL_Api.cs:4156
void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
Changes the Region Sun Settings, then Triggers a Sun Update
Definition: OSSL_Api.cs:1286
string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams, int timer, int alpha)
Definition: OSSL_Api.cs:617
void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
Set parameters for light projection in host prim
Definition: OSSL_Api.cs:3441
void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
Attempts to drop an attachment at the specified coordinates.
Definition: OSSL_Api.cs:4059
void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
Definition: OSSL_Api.cs:871
LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
Definition: OSSL_Api.cs:2447
OpenSim.Framework.PermissionMask PermissionMask
Definition: OSSL_Api.cs:65
LSL_Float osMin(double a, double b)
Wraps to Math.Min()
Definition: OSSL_Api.cs:3947
string osDrawFilledRectangle(string drawList, int width, int height)
Definition: OSSL_Api.cs:1128
LSL_Integer osEjectFromGroup(LSL_Key agentId)
Eject user from the group this object is set to
Definition: OSSL_Api.cs:3582
string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
Definition: OSSL_Api.cs:1137
string osSetPenSize(string drawList, int penSize)
Definition: OSSL_Api.cs:1193
void osNpcSit(LSL_Key npc, LSL_Key target, int options)
Definition: OSSL_Api.cs:2983
UUID OwnerID
Owner Avatar or Group of the parcel. Naturally, all land masses must be owned by someone ...
Definition: LandData.cs:551