aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs1954
1 files changed, 1327 insertions, 627 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 83aa245..a8c1a8f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -45,6 +45,7 @@ using OpenSim.Framework;
45using OpenSim.Framework.Console; 45using OpenSim.Framework.Console;
46using OpenSim.Region.Framework.Interfaces; 46using OpenSim.Region.Framework.Interfaces;
47using OpenSim.Region.Framework.Scenes; 47using OpenSim.Region.Framework.Scenes;
48using OpenSim.Region.Framework.Scenes.Scripting;
48using OpenSim.Region.ScriptEngine.Shared; 49using OpenSim.Region.ScriptEngine.Shared;
49using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 50using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
50using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 51using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
@@ -138,8 +139,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
138 internal TaskInventoryItem m_item; 139 internal TaskInventoryItem m_item;
139 internal bool m_OSFunctionsEnabled = false; 140 internal bool m_OSFunctionsEnabled = false;
140 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 141 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
142 internal bool m_debuggerSafe = false;
141 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 143 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
142
143 protected IUrlModule m_UrlModule = null; 144 protected IUrlModule m_UrlModule = null;
144 145
145 public void Initialize( 146 public void Initialize(
@@ -148,6 +149,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
148 m_ScriptEngine = scriptEngine; 149 m_ScriptEngine = scriptEngine;
149 m_host = host; 150 m_host = host;
150 m_item = item; 151 m_item = item;
152 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
151 153
152 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 154 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
153 155
@@ -187,7 +189,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
187 default: 189 default:
188 break; 190 break;
189 } 191 }
190 } 192 }
191 193
192 public override Object InitializeLifetimeService() 194 public override Object InitializeLifetimeService()
193 { 195 {
@@ -209,7 +211,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
209 211
210 internal void OSSLError(string msg) 212 internal void OSSLError(string msg)
211 { 213 {
212 OSSLShoutError("OSSL Runtime Error: " + msg); 214 if (m_debuggerSafe)
215 OSSLShoutError(msg);
216 else
217 {
218 throw new ScriptException("OSSL Runtime Error: " + msg);
219 }
213 } 220 }
214 221
215 /// <summary> 222 /// <summary>
@@ -244,28 +251,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
244 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); 251 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
245 } 252 }
246 253
247 // Returns of the function is allowed. Throws a script exception if not allowed. 254 // Returns if OSSL is enabled. Throws a script exception if OSSL is not allowed..
248 public bool CheckThreatLevel(ThreatLevel level, string function) 255 // for safe funtions always active
256 public void CheckThreatLevel()
249 { 257 {
250 if (!m_OSFunctionsEnabled) 258 if (!m_OSFunctionsEnabled)
251 { 259 throw new ScriptException(String.Format("{0} permission denied. All OS functions are disabled."));
252 OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); 260 }
253 return false; 261
254 } 262 // Returns if 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 throw new ScriptException(String.Format("{0} permission denied. All OS functions are disabled.", function));
255 267
256 string reasonWhyNot = CheckThreatLevelTest(level, function); 268 string reasonWhyNot = CheckThreatLevelTest(level, function);
257 if (!String.IsNullOrEmpty(reasonWhyNot)) 269 if (!String.IsNullOrEmpty(reasonWhyNot))
258 { 270 throw new ScriptException(reasonWhyNot);
259 OSSLError(reasonWhyNot);
260 return false;
261 }
262 return true;
263 } 271 }
264 272
265 // Check to see if function is allowed. Returns an empty string if function permitted 273 // Check to see if function is allowed. Returns an empty string if function permitted
266 // or a string explaining why this function can't be used. 274 // or a string explaining why this function can't be used.
267 private string CheckThreatLevelTest(ThreatLevel level, string function) 275 private string CheckThreatLevelTest(ThreatLevel level, string function)
268 { 276 {
277 // Grid gods can do anything they damn well please.
278 if (World.Permissions.IsGridGod(m_item.OwnerID))
279 return String.Empty;
280 else
281 {
282 // So can active gods.
283 ScenePresence sp = World.GetScenePresence(m_item.OwnerID);
284 if (sp != null && !sp.IsDeleted && sp.IsGod)
285 return String.Empty;
286 }
287
269 if (!m_FunctionPerms.ContainsKey(function)) 288 if (!m_FunctionPerms.ContainsKey(function))
270 { 289 {
271 FunctionPerms perms = new FunctionPerms(); 290 FunctionPerms perms = new FunctionPerms();
@@ -299,7 +318,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
299 foreach (string id in ids) 318 foreach (string id in ids)
300 { 319 {
301 string current = id.Trim(); 320 string current = id.Trim();
302 if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER") 321 if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER" || current.ToUpper() == "ACTIVE_GOD" || current.ToUpper() == "GRID_GOD" || current.ToUpper() == "GOD")
303 { 322 {
304 if (!perms.AllowedOwnerClasses.Contains(current)) 323 if (!perms.AllowedOwnerClasses.Contains(current))
305 perms.AllowedOwnerClasses.Add(current.ToUpper()); 324 perms.AllowedOwnerClasses.Add(current.ToUpper());
@@ -404,6 +423,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
404 } 423 }
405 } 424 }
406 425
426
427 //Only grid gods may use the function
428 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("GRID_GOD"))
429 {
430 if (World.Permissions.IsGridGod(ownerID))
431 {
432 return String.Empty;
433 }
434 }
435
436 //Any god may use the function
437 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("GOD"))
438 {
439 if (World.Permissions.IsAdministrator(ownerID))
440 {
441 return String.Empty;
442 }
443 }
444
445 //Only active gods may use the function
446 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ACTIVE_GOD"))
447 {
448 ScenePresence sp = World.GetScenePresence(ownerID);
449 if (sp != null && !sp.IsDeleted && sp.IsGod)
450 {
451 return String.Empty;
452 }
453 }
454
407 if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID)) 455 if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
408 return( 456 return(
409 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.", 457 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.",
@@ -425,16 +473,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
425 OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement)); 473 OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
426 } 474 }
427 475
476//// protected void ScriptSleep(int delay)
477//// {
478//// delay = (int)((float)delay * m_ScriptDelayFactor);
479//// if (delay == 0)
480//// return;
481//// System.Threading.Thread.Sleep(delay);
482//// }
483
428 public LSL_Integer osSetTerrainHeight(int x, int y, double val) 484 public LSL_Integer osSetTerrainHeight(int x, int y, double val)
429 { 485 {
430 if (!CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight")) return 0; 486 CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
431 487
432 return SetTerrainHeight(x, y, val); 488 return SetTerrainHeight(x, y, val);
433 } 489 }
434 490
435 public LSL_Integer osTerrainSetHeight(int x, int y, double val) 491 public LSL_Integer osTerrainSetHeight(int x, int y, double val)
436 { 492 {
437 if (!CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight")) return 0; 493 CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
438 OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); 494 OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
439 495
440 return SetTerrainHeight(x, y, val); 496 return SetTerrainHeight(x, y, val);
@@ -442,8 +498,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
442 498
443 private LSL_Integer SetTerrainHeight(int x, int y, double val) 499 private LSL_Integer SetTerrainHeight(int x, int y, double val)
444 { 500 {
445 m_host.AddScriptLPS(1);
446
447 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0) 501 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
448 OSSLError("osSetTerrainHeight: Coordinate out of bounds"); 502 OSSLError("osSetTerrainHeight: Coordinate out of bounds");
449 503
@@ -471,7 +525,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
471 525
472 private LSL_Float GetTerrainHeight(int x, int y) 526 private LSL_Float GetTerrainHeight(int x, int y)
473 { 527 {
474 m_host.AddScriptLPS(1);
475 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0) 528 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
476 OSSLError("osGetTerrainHeight: Coordinate out of bounds"); 529 OSSLError("osGetTerrainHeight: Coordinate out of bounds");
477 530
@@ -480,8 +533,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
480 533
481 public void osTerrainFlush() 534 public void osTerrainFlush()
482 { 535 {
483 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush")) return; 536 CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
484 m_host.AddScriptLPS(1);
485 537
486 ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>(); 538 ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
487 if (terrainModule != null) terrainModule.TaintTerrain(); 539 if (terrainModule != null) terrainModule.TaintTerrain();
@@ -495,31 +547,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
495 // The underlying functionality is fixed, since the security 547 // The underlying functionality is fixed, since the security
496 // as such is sound 548 // as such is sound
497 // 549 //
498 if (!CheckThreatLevel(ThreatLevel.High, "osRegionRestart")) return 0; 550 CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
499 551
500 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>(); 552 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
501 m_host.AddScriptLPS(1);
502 if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null)) 553 if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
503 { 554 {
504 if (seconds < 15) 555 if (seconds < 15)
505 { 556 {
506 restartModule.AbortRestart("Restart aborted"); 557 restartModule.AbortRestart("Region restart has been aborted\n");
507 return 1; 558 return 1;
508 } 559 }
509 560
510 List<int> times = new List<int>(); 561 RegionRestart(seconds, String.Empty);
511 while (seconds > 0) 562 return 1;
563 }
564 else
565 {
566 return 0;
567 }
568 }
569
570 public int osRegionRestart(double seconds, string msg)
571 {
572 CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
573
574 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
575 if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
576 {
577 if (seconds < 15)
512 { 578 {
513 times.Add((int)seconds); 579 restartModule.AbortRestart("Region restart has been aborted\n");
514 if (seconds > 300) 580 return 1;
515 seconds -= 120;
516 else if (seconds > 30)
517 seconds -= 30;
518 else
519 seconds -= 15;
520 } 581 }
521 582
522 restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true); 583 RegionRestart(seconds, msg);
523 return 1; 584 return 1;
524 } 585 }
525 else 586 else
@@ -528,15 +589,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
528 } 589 }
529 } 590 }
530 591
592 private void RegionRestart(double seconds, string msg)
593 {
594 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
595
596 List<int> times = new List<int>();
597 while (seconds > 0)
598 {
599 times.Add((int)seconds);
600 if (seconds > 300)
601 seconds -= 120;
602 else if (seconds > 120)
603 seconds -= 60;
604 else if (seconds > 60)
605 seconds -= 30;
606 else
607 seconds -= 15;
608 }
609
610 if (msg == String.Empty)
611 restartModule.ScheduleRestart(UUID.Zero, "Region: " + World.RegionInfo.RegionName + " is about to restart.\n\nIf you stay here you will be logged out.\n\n\nTime remaining: {0}.\n", times.ToArray(), true);
612
613 else
614 restartModule.ScheduleRestart(UUID.Zero, msg + "\n\nTime remaining: {0}.\n", times.ToArray(), true);
615 }
616
531 public void osRegionNotice(string msg) 617 public void osRegionNotice(string msg)
532 { 618 {
533 // This implementation provides absolutely no security 619 // This implementation provides absolutely no security
534 // It's high griefing potential makes this classification 620 // It's high griefing potential makes this classification
535 // necessary 621 // necessary
536 // 622 //
537 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice")) return; 623 CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
538
539 m_host.AddScriptLPS(1);
540 624
541 IDialogModule dm = World.RequestModuleInterface<IDialogModule>(); 625 IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
542 626
@@ -549,9 +633,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
549 // This function has no security. It can be used to destroy 633 // This function has no security. It can be used to destroy
550 // arbitrary builds the user would normally have no rights to 634 // arbitrary builds the user would normally have no rights to
551 // 635 //
552 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot")) return; 636 CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
553 637
554 m_host.AddScriptLPS(1);
555 if (World.Entities.ContainsKey(target)) 638 if (World.Entities.ContainsKey(target))
556 { 639 {
557 EntityBase entity; 640 EntityBase entity;
@@ -572,13 +655,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
572 public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams, 655 public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
573 int timer) 656 int timer)
574 { 657 {
575 m_host.AddScriptLPS(1);
576 if (dynamicID == String.Empty) 658 if (dynamicID == String.Empty)
577 { 659 {
578 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 660 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
579 UUID createdTexture = 661 UUID createdTexture =
580 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url, 662 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
581 extraParams, timer); 663 extraParams);
582 return createdTexture.ToString(); 664 return createdTexture.ToString();
583 } 665 }
584 else 666 else
@@ -592,13 +674,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
592 public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams, 674 public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
593 int timer, int alpha) 675 int timer, int alpha)
594 { 676 {
595 m_host.AddScriptLPS(1);
596 if (dynamicID == String.Empty) 677 if (dynamicID == String.Empty)
597 { 678 {
598 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 679 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
599 UUID createdTexture = 680 UUID createdTexture =
600 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url, 681 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
601 extraParams, timer, true, (byte) alpha); 682 extraParams, true, (byte) alpha);
602 return createdTexture.ToString(); 683 return createdTexture.ToString();
603 } 684 }
604 else 685 else
@@ -612,13 +693,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
612 public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams, 693 public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
613 bool blend, int disp, int timer, int alpha, int face) 694 bool blend, int disp, int timer, int alpha, int face)
614 { 695 {
615 m_host.AddScriptLPS(1);
616 if (dynamicID == String.Empty) 696 if (dynamicID == String.Empty)
617 { 697 {
618 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 698 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
619 UUID createdTexture = 699 UUID createdTexture =
620 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url, 700 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
621 extraParams, timer, blend, disp, (byte) alpha, face); 701 extraParams, blend, disp, (byte) alpha, face);
622 return createdTexture.ToString(); 702 return createdTexture.ToString();
623 } 703 }
624 else 704 else
@@ -632,7 +712,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
632 public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams, 712 public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
633 int timer) 713 int timer)
634 { 714 {
635 m_host.AddScriptLPS(1); 715 return osSetDynamicTextureDataFace(dynamicID, contentType, data, extraParams, timer, -1);
716 }
717
718 public string osSetDynamicTextureDataFace(string dynamicID, string contentType, string data, string extraParams,
719 int timer, int face)
720 {
636 if (dynamicID == String.Empty) 721 if (dynamicID == String.Empty)
637 { 722 {
638 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 723 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -644,7 +729,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
644 } 729 }
645 UUID createdTexture = 730 UUID createdTexture =
646 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data, 731 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
647 extraParams, timer); 732 extraParams, false, 3, 255, face);
733
648 return createdTexture.ToString(); 734 return createdTexture.ToString();
649 } 735 }
650 } 736 }
@@ -659,7 +745,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
659 public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams, 745 public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
660 int timer, int alpha) 746 int timer, int alpha)
661 { 747 {
662 m_host.AddScriptLPS(1);
663 if (dynamicID == String.Empty) 748 if (dynamicID == String.Empty)
664 { 749 {
665 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 750 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -671,7 +756,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
671 } 756 }
672 UUID createdTexture = 757 UUID createdTexture =
673 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data, 758 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
674 extraParams, timer, true, (byte) alpha); 759 extraParams, true, (byte) alpha);
675 return createdTexture.ToString(); 760 return createdTexture.ToString();
676 } 761 }
677 } 762 }
@@ -686,7 +771,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
686 public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams, 771 public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
687 bool blend, int disp, int timer, int alpha, int face) 772 bool blend, int disp, int timer, int alpha, int face)
688 { 773 {
689 m_host.AddScriptLPS(1);
690 if (dynamicID == String.Empty) 774 if (dynamicID == String.Empty)
691 { 775 {
692 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 776 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -698,7 +782,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
698 } 782 }
699 UUID createdTexture = 783 UUID createdTexture =
700 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data, 784 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
701 extraParams, timer, blend, disp, (byte) alpha, face); 785 extraParams, blend, disp, (byte) alpha, face);
702 return createdTexture.ToString(); 786 return createdTexture.ToString();
703 } 787 }
704 } 788 }
@@ -712,9 +796,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
712 796
713 public bool osConsoleCommand(string command) 797 public bool osConsoleCommand(string command)
714 { 798 {
715 if (!CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand")) return false; 799 CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
716
717 m_host.AddScriptLPS(1);
718 800
719 // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions 801 // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
720 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 802 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
@@ -728,123 +810,163 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
728 810
729 public void osSetPrimFloatOnWater(int floatYN) 811 public void osSetPrimFloatOnWater(int floatYN)
730 { 812 {
731 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater")) return; 813 CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
732
733 m_host.AddScriptLPS(1);
734 814
735 m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN); 815 m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
736 } 816 }
737 817
818 private bool checkAllowAgentTPbyLandOwner(UUID agentId, Vector3 pos)
819 {
820 UUID hostOwner = m_host.OwnerID;
821
822 if(hostOwner == agentId)
823 return true;
824
825 if (m_item.PermsGranter == agentId)
826 {
827 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
828 return true;
829 }
830
831 ILandObject land = World.LandChannel.GetLandObject(pos);
832 if(land == null)
833 return true;
834
835 LandData landdata = land.LandData;
836 if(landdata == null)
837 return true;
838
839 if(landdata.OwnerID == hostOwner)
840 return true;
841
842 EstateSettings es = World.RegionInfo.EstateSettings;
843 if(es != null && es.IsEstateManagerOrOwner(hostOwner))
844 return true;
845
846 if(!landdata.IsGroupOwned)
847 return false;
848
849 UUID landGroup = landdata.GroupID;
850 if(landGroup == UUID.Zero)
851 return false;
852
853 if(landGroup == m_host.GroupID)
854 return true;
855
856 return false;
857 }
858
738 // Teleport functions 859 // Teleport functions
739 public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 860 public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
740 { 861 {
741 // High because there is no security check. High griefer potential 862 // High because there is no security check. High griefer potential
742 // 863 //
743 if (!CheckThreatLevel(ThreatLevel.High, "osTeleportAgent")) return; 864 CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
744 865
745 TeleportAgent(agent, regionName, position, lookat, false); 866 TeleportAgent(agent, regionName, position, lookat);
746 } 867 }
747 868
748 private void TeleportAgent(string agent, string regionName, 869 private void TeleportAgent(string agent, string regionName,
749 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) 870 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
750 { 871 {
751 m_host.AddScriptLPS(1); 872 if(String.IsNullOrEmpty(regionName))
752 UUID agentId = new UUID(); 873 regionName = World.RegionInfo.RegionName;
874
875 UUID agentId;
753 if (UUID.TryParse(agent, out agentId)) 876 if (UUID.TryParse(agent, out agentId))
754 { 877 {
755 ScenePresence presence = World.GetScenePresence(agentId); 878 ScenePresence presence = World.GetScenePresence(agentId);
756 if (presence != null) 879 if (presence == null || presence.IsDeleted || presence.IsInTransit)
757 { 880 return;
758 // For osTeleportAgent, agent must be over owners land to avoid abuse 881
759 // For osTeleportOwner, this restriction isn't necessary 882 Vector3 pos = presence.AbsolutePosition;
760 883 if(!checkAllowAgentTPbyLandOwner(agentId, pos))
761 // commented out because its redundant and uneeded please remove eventually. 884 return;
762 // if (relaxRestrictions ||
763 // m_host.OwnerID
764 // == World.LandChannel.GetLandObject(
765 // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
766 // {
767
768 // We will launch the teleport on a new thread so that when the script threads are terminated
769 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
770 Util.FireAndForget(
771 o => World.RequestTeleportLocation(
772 presence.ControllingClient, regionName, position,
773 lookat, (uint)TPFlags.ViaLocation),
774 null, "OSSL_Api.TeleportAgentByRegionCoords");
775 // }
776 885
886 if(regionName == World.RegionInfo.RegionName)
887 {
888 // should be faster than going to threadpool
889 World.RequestTeleportLocation(presence.ControllingClient, regionName, position,
890 lookat, (uint)(TPFlags.ViaLocation | TPFlags.ViaScript));
891 }
892 else
893 {
894 // We will launch the teleport on a new thread so that when the script threads are terminated
895 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
896 Util.FireAndForget(
897 o => World.RequestTeleportLocation(
898 presence.ControllingClient, regionName, position,
899 lookat, (uint)(TPFlags.ViaLocation | TPFlags.ViaScript)),
900 null, "OSSL_Api.TeleportAgentByRegionCoords");
777 } 901 }
778 } 902 }
779 } 903 }
780 904
781 public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 905 public void osTeleportAgent(string agent, int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
782 { 906 {
783 // High because there is no security check. High griefer potential 907 // High because there is no security check. High griefer potential
784 // 908 //
785 if (!CheckThreatLevel(ThreatLevel.High, "osTeleportAgent")) return; 909 CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
786 910
787 TeleportAgent(agent, regionX, regionY, position, lookat, false); 911 TeleportAgent(agent, regionGridX, regionGridY, position, lookat);
788 } 912 }
789 913
790 private void TeleportAgent(string agent, int regionX, int regionY, 914 private void TeleportAgent(string agent, int regionGridX, int regionGridY,
791 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) 915 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
792 { 916 {
793 // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize)); 917 ulong regionHandle = Util.RegionGridLocToHandle((uint)regionGridX, (uint)regionGridY);
794 ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
795 918
796 m_host.AddScriptLPS(1); 919 UUID agentId;
797 UUID agentId = new UUID();
798 if (UUID.TryParse(agent, out agentId)) 920 if (UUID.TryParse(agent, out agentId))
799 { 921 {
800 ScenePresence presence = World.GetScenePresence(agentId); 922 ScenePresence presence = World.GetScenePresence(agentId);
801 if (presence != null) 923 if (presence == null || presence.IsDeleted || presence.IsInTransit)
802 { 924 return;
803 // For osTeleportAgent, agent must be over owners land to avoid abuse
804 // For osTeleportOwner, this restriction isn't necessary
805
806 // commented out because its redundant and uneeded please remove eventually.
807 // if (relaxRestrictions ||
808 // m_host.OwnerID
809 // == World.LandChannel.GetLandObject(
810 // presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
811 // {
812
813 // We will launch the teleport on a new thread so that when the script threads are terminated
814 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
815 Util.FireAndForget(
816 o => World.RequestTeleportLocation(
817 presence.ControllingClient, regionHandle,
818 position, lookat, (uint)TPFlags.ViaLocation),
819 null, "OSSL_Api.TeleportAgentByRegionName");
820 // }
821 925
822 } 926 Vector3 pos = presence.AbsolutePosition;
927 if(!checkAllowAgentTPbyLandOwner(agentId, pos))
928 return;
929
930 Util.FireAndForget(
931 o => World.RequestTeleportLocation(
932 presence.ControllingClient, regionHandle,
933 position, lookat, (uint)(TPFlags.ViaLocation | TPFlags.ViaScript)),
934 null, "OSSL_Api.TeleportAgentByRegionName");
823 } 935 }
824 } 936 }
825 937
826 public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 938 public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
827 { 939 {
828 // High because there is no security check. High griefer potential 940 UUID agentId;
829 // 941 if (UUID.TryParse(agent, out agentId))
830 if (!CheckThreatLevel(ThreatLevel.High, "osTeleportAgent")) return; 942 {
943 ScenePresence presence = World.GetScenePresence(agentId);
944 if (presence == null || presence.IsDeleted || presence.IsInTransit)
945 return;
946
947 Vector3 pos = presence.AbsolutePosition;
948 if(!checkAllowAgentTPbyLandOwner(agentId, pos))
949 return;
831 950
832 osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat); 951 World.RequestTeleportLocation(presence.ControllingClient, World.RegionInfo.RegionName, position,
952 lookat, (uint)(TPFlags.ViaLocation | TPFlags.ViaScript));
953 }
833 } 954 }
834 955
835 public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 956 public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
836 { 957 {
837 TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat, true); 958 // Threat level None because this is what can already be done with the World Map in the viewer
959 TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat);
838 } 960 }
839 961
840 public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 962 public void osTeleportOwner(int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
841 { 963 {
842 osTeleportOwner(World.RegionInfo.RegionName, position, lookat); 964 TeleportAgent(m_host.OwnerID.ToString(), regionGridX, regionGridY, position, lookat);
843 } 965 }
844 966
845 public void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 967 public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
846 { 968 {
847 TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true); 969 osTeleportAgent(m_host.OwnerID.ToString(), position, lookat);
848 } 970 }
849 971
850 ///<summary> 972 ///<summary>
@@ -856,9 +978,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
856 /// <param name="avatar"></param> 978 /// <param name="avatar"></param>
857 public void osForceOtherSit(string avatar) 979 public void osForceOtherSit(string avatar)
858 { 980 {
859 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit")) return; 981 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
860
861 m_host.AddScriptLPS(1);
862 982
863 ForceSit(avatar, m_host.UUID); 983 ForceSit(avatar, m_host.UUID);
864 } 984 }
@@ -871,9 +991,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
871 /// <param name="target"></param> 991 /// <param name="target"></param>
872 public void osForceOtherSit(string avatar, string target) 992 public void osForceOtherSit(string avatar, string target)
873 { 993 {
874 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit")) return; 994 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
875
876 m_host.AddScriptLPS(1);
877 995
878 UUID targetID = new UUID(target); 996 UUID targetID = new UUID(target);
879 997
@@ -882,7 +1000,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
882 1000
883 public void ForceSit(string avatar, UUID targetID) 1001 public void ForceSit(string avatar, UUID targetID)
884 { 1002 {
885 UUID agentID; 1003 UUID agentID;
886 1004
887 if (!UUID.TryParse(avatar, out agentID)) 1005 if (!UUID.TryParse(avatar, out agentID))
888 return; 1006 return;
@@ -900,21 +1018,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
900 part.SitTargetPosition); 1018 part.SitTargetPosition);
901 } 1019 }
902 1020
903 // Functions that get information from the agent itself. 1021 // Get a list of all the avatars/agents in the region
904 // 1022 public LSL_List osGetAgents()
905 // osGetAgentIP - this is used to determine the IP address of 1023 {
906 //the client. This is needed to help configure other in world 1024 // threat level is None as we could get this information with an
907 //resources based on the IP address of the clients connected. 1025 // in-world script as well, just not as efficient
908 //I think High is a good risk level for this, as it is an 1026 LSL_List result = new LSL_List();
909 //information leak. 1027 World.ForEachRootScenePresence(delegate(ScenePresence sp)
910 // Severe is even better coz privacy is important. 1028 {
1029 result.Add(new LSL_String(sp.Name));
1030 });
1031 return result;
1032 }
1033
911 public string osGetAgentIP(string agent) 1034 public string osGetAgentIP(string agent)
912 { 1035 {
913 if (!CheckThreatLevel(ThreatLevel.Severe, "osGetAgentIP")) return ""; 1036 CheckThreatLevel(ThreatLevel.Severe, "osGetAgentIP");
1037 if(!(World.Permissions.IsGod(m_host.OwnerID))) // user god always needed
1038 return "";
914 1039
915 UUID avatarID = (UUID)agent; 1040 UUID avatarID = (UUID)agent;
916 1041
917 m_host.AddScriptLPS(1);
918 if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence) 1042 if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
919 { 1043 {
920 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 1044 ScenePresence target = (ScenePresence)World.Entities[avatarID];
@@ -925,61 +1049,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
925 return ""; 1049 return "";
926 } 1050 }
927 1051
928 // Get a list of all the avatars/agents in the region
929 public LSL_List osGetAgents()
930 {
931 m_host.AddScriptLPS(1);
932
933 LSL_List result = new LSL_List();
934 World.ForEachRootScenePresence(delegate(ScenePresence sp)
935 {
936 result.Add(new LSL_String(sp.Name));
937 });
938 return result;
939 }
940
941 // Adam's super super custom animation functions 1052 // Adam's super super custom animation functions
942 public void osAvatarPlayAnimation(string avatar, string animation) 1053 public void osAvatarPlayAnimation(string avatar, string animation)
943 { 1054 {
944 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation")) return; 1055 CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
945 1056
946 AvatarPlayAnimation(avatar, animation); 1057 AvatarPlayAnimation(avatar, animation);
947 } 1058 }
948 1059
949 private void AvatarPlayAnimation(string avatar, string animation) 1060 private void AvatarPlayAnimation(string avatar, string animation)
950 { 1061 {
951 UUID avatarID = (UUID)avatar; 1062 UUID avatarID;
1063 if(!UUID.TryParse(avatar, out avatarID))
1064 return;
1065
1066 ScenePresence target = World.GetScenePresence(avatarID);
1067 if (target == null)
1068 return;
952 1069
953 m_host.AddScriptLPS(1); 1070 UUID animID = UUID.Zero;
954 if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence) 1071 m_host.TaskInventory.LockItemsForRead(true);
1072 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
955 { 1073 {
956 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 1074 if (inv.Value.Type == (int)AssetType.Animation)
957 if (target != null)
958 { 1075 {
959 UUID animID=UUID.Zero; 1076 if (inv.Value.Name == animation)
960 lock (m_host.TaskInventory) 1077 {
961 { 1078 animID = inv.Value.AssetID;
962 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 1079 break;
963 { 1080 }
964 if (inv.Value.Name == animation)
965 {
966 if (inv.Value.Type == (int)AssetType.Animation)
967 animID = inv.Value.AssetID;
968 continue;
969 }
970 }
971 }
972 if (animID == UUID.Zero)
973 target.Animator.AddAnimation(animation, m_host.UUID);
974 else
975 target.Animator.AddAnimation(animID, m_host.UUID);
976 } 1081 }
977 } 1082 }
1083 m_host.TaskInventory.LockItemsForRead(false);
1084
1085 if (animID == UUID.Zero)
1086 target.Animator.AddAnimation(animation, m_host.UUID);
1087 else
1088 target.Animator.AddAnimation(animID, m_host.UUID);
978 } 1089 }
979 1090
980 public void osAvatarStopAnimation(string avatar, string animation) 1091 public void osAvatarStopAnimation(string avatar, string animation)
981 { 1092 {
982 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation")) return; 1093 CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
983 1094
984 AvatarStopAnimation(avatar, animation); 1095 AvatarStopAnimation(avatar, animation);
985 } 1096 }
@@ -988,8 +1099,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
988 { 1099 {
989 UUID avatarID = (UUID)avatar; 1100 UUID avatarID = (UUID)avatar;
990 1101
991 m_host.AddScriptLPS(1);
992
993 // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common 1102 // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
994 // method (though see that doesn't do the is animation check, which is probably a bug) and have both 1103 // method (though see that doesn't do the is animation check, which is probably a bug) and have both
995 // these functions call that common code. However, this does mean navigating the brain-dead requirement 1104 // these functions call that common code. However, this does mean navigating the brain-dead requirement
@@ -1010,6 +1119,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1010 animID = UUID.Zero; 1119 animID = UUID.Zero;
1011 } 1120 }
1012 1121
1122
1013 if (animID == UUID.Zero) 1123 if (animID == UUID.Zero)
1014 target.Animator.RemoveAnimation(animation); 1124 target.Animator.RemoveAnimation(animation);
1015 else 1125 else
@@ -1019,59 +1129,81 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1019 } 1129 }
1020 1130
1021 //Texture draw functions 1131 //Texture draw functions
1132
1133 public string osDrawResetTransform(string drawList)
1134 {
1135 drawList += "ResetTransf;";
1136 return drawList;
1137 }
1138
1139 public string osDrawRotationTransform(string drawList, LSL_Float x)
1140 {
1141 drawList += "RotTransf " + x + ";";
1142 return drawList;
1143 }
1144
1145 public string osDrawScaleTransform(string drawList, LSL_Float x, LSL_Float y)
1146 {
1147 drawList += "ScaleTransf " + x + "," + y + ";";
1148 return drawList;
1149 }
1150
1151 public string osDrawTranslationTransform(string drawList, LSL_Float x, LSL_Float y)
1152 {
1153 drawList += "TransTransf " + x + "," + y + ";";
1154 return drawList;
1155 }
1156
1022 public string osMovePen(string drawList, int x, int y) 1157 public string osMovePen(string drawList, int x, int y)
1023 { 1158 {
1024 m_host.AddScriptLPS(1);
1025 drawList += "MoveTo " + x + "," + y + ";"; 1159 drawList += "MoveTo " + x + "," + y + ";";
1026 return drawList; 1160 return drawList;
1027 } 1161 }
1028 1162
1029 public string osDrawLine(string drawList, int startX, int startY, int endX, int endY) 1163 public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
1030 { 1164 {
1031 m_host.AddScriptLPS(1);
1032 drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; "; 1165 drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
1033 return drawList; 1166 return drawList;
1034 } 1167 }
1035 1168
1036 public string osDrawLine(string drawList, int endX, int endY) 1169 public string osDrawLine(string drawList, int endX, int endY)
1037 { 1170 {
1038 m_host.AddScriptLPS(1);
1039 drawList += "LineTo " + endX + "," + endY + "; "; 1171 drawList += "LineTo " + endX + "," + endY + "; ";
1040 return drawList; 1172 return drawList;
1041 } 1173 }
1042 1174
1043 public string osDrawText(string drawList, string text) 1175 public string osDrawText(string drawList, string text)
1044 { 1176 {
1045 m_host.AddScriptLPS(1);
1046 drawList += "Text " + text + "; "; 1177 drawList += "Text " + text + "; ";
1047 return drawList; 1178 return drawList;
1048 } 1179 }
1049 1180
1050 public string osDrawEllipse(string drawList, int width, int height) 1181 public string osDrawEllipse(string drawList, int width, int height)
1051 { 1182 {
1052 m_host.AddScriptLPS(1);
1053 drawList += "Ellipse " + width + "," + height + "; "; 1183 drawList += "Ellipse " + width + "," + height + "; ";
1054 return drawList; 1184 return drawList;
1055 } 1185 }
1056 1186
1187 public string osDrawFilledEllipse(string drawList, int width, int height)
1188 {
1189 drawList += "FillEllipse " + width + "," + height + "; ";
1190 return drawList;
1191 }
1192
1057 public string osDrawRectangle(string drawList, int width, int height) 1193 public string osDrawRectangle(string drawList, int width, int height)
1058 { 1194 {
1059 m_host.AddScriptLPS(1);
1060 drawList += "Rectangle " + width + "," + height + "; "; 1195 drawList += "Rectangle " + width + "," + height + "; ";
1061 return drawList; 1196 return drawList;
1062 } 1197 }
1063 1198
1064 public string osDrawFilledRectangle(string drawList, int width, int height) 1199 public string osDrawFilledRectangle(string drawList, int width, int height)
1065 { 1200 {
1066 m_host.AddScriptLPS(1);
1067 drawList += "FillRectangle " + width + "," + height + "; "; 1201 drawList += "FillRectangle " + width + "," + height + "; ";
1068 return drawList; 1202 return drawList;
1069 } 1203 }
1070 1204
1071 public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y) 1205 public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
1072 { 1206 {
1073 m_host.AddScriptLPS(1);
1074
1075 if (x.Length != y.Length || x.Length < 3) 1207 if (x.Length != y.Length || x.Length < 3)
1076 { 1208 {
1077 return ""; 1209 return "";
@@ -1087,8 +1219,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1087 1219
1088 public string osDrawPolygon(string drawList, LSL_List x, LSL_List y) 1220 public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
1089 { 1221 {
1090 m_host.AddScriptLPS(1);
1091
1092 if (x.Length != y.Length || x.Length < 3) 1222 if (x.Length != y.Length || x.Length < 3)
1093 { 1223 {
1094 return ""; 1224 return "";
@@ -1104,28 +1234,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1104 1234
1105 public string osSetFontSize(string drawList, int fontSize) 1235 public string osSetFontSize(string drawList, int fontSize)
1106 { 1236 {
1107 m_host.AddScriptLPS(1);
1108 drawList += "FontSize "+ fontSize +"; "; 1237 drawList += "FontSize "+ fontSize +"; ";
1109 return drawList; 1238 return drawList;
1110 } 1239 }
1111 1240
1112 public string osSetFontName(string drawList, string fontName) 1241 public string osSetFontName(string drawList, string fontName)
1113 { 1242 {
1114 m_host.AddScriptLPS(1);
1115 drawList += "FontName "+ fontName +"; "; 1243 drawList += "FontName "+ fontName +"; ";
1116 return drawList; 1244 return drawList;
1117 } 1245 }
1118 1246
1119 public string osSetPenSize(string drawList, int penSize) 1247 public string osSetPenSize(string drawList, int penSize)
1120 { 1248 {
1121 m_host.AddScriptLPS(1);
1122 drawList += "PenSize " + penSize + "; "; 1249 drawList += "PenSize " + penSize + "; ";
1123 return drawList; 1250 return drawList;
1124 } 1251 }
1125 1252
1126 public string osSetPenColor(string drawList, string color) 1253 public string osSetPenColor(string drawList, string color)
1127 { 1254 {
1128 m_host.AddScriptLPS(1);
1129 drawList += "PenColor " + color + "; "; 1255 drawList += "PenColor " + color + "; ";
1130 return drawList; 1256 return drawList;
1131 } 1257 }
@@ -1135,29 +1261,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1135 { 1261 {
1136 OSSLDeprecated("osSetPenColour", "osSetPenColor"); 1262 OSSLDeprecated("osSetPenColour", "osSetPenColor");
1137 1263
1138 m_host.AddScriptLPS(1);
1139 drawList += "PenColour " + colour + "; "; 1264 drawList += "PenColour " + colour + "; ";
1140 return drawList; 1265 return drawList;
1141 } 1266 }
1142 1267
1143 public string osSetPenCap(string drawList, string direction, string type) 1268 public string osSetPenCap(string drawList, string direction, string type)
1144 { 1269 {
1145 m_host.AddScriptLPS(1);
1146 drawList += "PenCap " + direction + "," + type + "; "; 1270 drawList += "PenCap " + direction + "," + type + "; ";
1147 return drawList; 1271 return drawList;
1148 } 1272 }
1149 1273
1150 public string osDrawImage(string drawList, int width, int height, string imageUrl) 1274 public string osDrawImage(string drawList, int width, int height, string imageUrl)
1151 { 1275 {
1152 m_host.AddScriptLPS(1);
1153 drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ; 1276 drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
1154 return drawList; 1277 return drawList;
1155 } 1278 }
1156 1279
1157 public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize) 1280 public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
1158 { 1281 {
1159 m_host.AddScriptLPS(1);
1160
1161 LSL_Vector vec = new LSL_Vector(0,0,0); 1282 LSL_Vector vec = new LSL_Vector(0,0,0);
1162 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 1283 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
1163 if (textureManager != null) 1284 if (textureManager != null)
@@ -1178,17 +1299,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 // It was probably added as a crutch or debugging aid, and 1299 // It was probably added as a crutch or debugging aid, and
1179 // should be removed 1300 // should be removed
1180 // 1301 //
1181 if (!CheckThreatLevel(ThreatLevel.High, "osSetStateEvents")) return; 1302 CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
1182 m_host.AddScriptLPS(1);
1183 1303
1184 m_host.SetScriptEvents(m_item.ItemID, events); 1304 m_host.SetScriptEvents(m_item.ItemID, events);
1185 } 1305 }
1186 1306
1187 public void osSetRegionWaterHeight(double height) 1307 public void osSetRegionWaterHeight(double height)
1188 { 1308 {
1189 if (!CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight")) return; 1309 CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
1190
1191 m_host.AddScriptLPS(1);
1192 1310
1193 World.EventManager.TriggerRequestChangeWaterHeight((float)height); 1311 World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1194 } 1312 }
@@ -1201,9 +1319,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1201 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param> 1319 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
1202 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour) 1320 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
1203 { 1321 {
1204 if (!CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings")) return; 1322 CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings");
1205
1206 m_host.AddScriptLPS(1);
1207 1323
1208 while (sunHour > 24.0) 1324 while (sunHour > 24.0)
1209 sunHour -= 24.0; 1325 sunHour -= 24.0;
@@ -1226,9 +1342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1226 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param> 1342 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
1227 public void osSetEstateSunSettings(bool sunFixed, double sunHour) 1343 public void osSetEstateSunSettings(bool sunFixed, double sunHour)
1228 { 1344 {
1229 if (!CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings")) return; 1345 CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings");
1230
1231 m_host.AddScriptLPS(1);
1232 1346
1233 while (sunHour > 24.0) 1347 while (sunHour > 24.0)
1234 sunHour -= 24.0; 1348 sunHour -= 24.0;
@@ -1250,8 +1364,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1250 /// <returns></returns> 1364 /// <returns></returns>
1251 public double osGetCurrentSunHour() 1365 public double osGetCurrentSunHour()
1252 { 1366 {
1253 m_host.AddScriptLPS(1);
1254
1255 // Must adjust for the fact that Region Sun Settings are still LL offset 1367 // Must adjust for the fact that Region Sun Settings are still LL offset
1256 double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6; 1368 double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
1257 1369
@@ -1278,8 +1390,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1278 1390
1279 private double GetSunParam(string param) 1391 private double GetSunParam(string param)
1280 { 1392 {
1281 m_host.AddScriptLPS(1);
1282
1283 double value = 0.0; 1393 double value = 0.0;
1284 1394
1285 ISunModule module = World.RequestModuleInterface<ISunModule>(); 1395 ISunModule module = World.RequestModuleInterface<ISunModule>();
@@ -1293,21 +1403,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1293 1403
1294 public void osSunSetParam(string param, double value) 1404 public void osSunSetParam(string param, double value)
1295 { 1405 {
1296//// if (!CheckThreatLevel(ThreatLevel.None, "osSunSetParam")) return; 1406 CheckThreatLevel(ThreatLevel.Nuisance, "osSunSetParam");
1297 OSSLDeprecated("osSunSetParam", "osSetSunParam"); 1407 OSSLDeprecated("osSunSetParam", "osSetSunParam");
1298 SetSunParam(param, value); 1408 SetSunParam(param, value);
1299 } 1409 }
1300 1410
1301 public void osSetSunParam(string param, double value) 1411 public void osSetSunParam(string param, double value)
1302 { 1412 {
1303//// if (!CheckThreatLevel(ThreatLevel.None, "osSetSunParam")) return; 1413 CheckThreatLevel(ThreatLevel.Nuisance, "osSetSunParam");
1304 SetSunParam(param, value); 1414 SetSunParam(param, value);
1305 } 1415 }
1306 1416
1307 private void SetSunParam(string param, double value) 1417 private void SetSunParam(string param, double value)
1308 { 1418 {
1309 m_host.AddScriptLPS(1);
1310
1311 ISunModule module = World.RequestModuleInterface<ISunModule>(); 1419 ISunModule module = World.RequestModuleInterface<ISunModule>();
1312 if (module != null) 1420 if (module != null)
1313 { 1421 {
@@ -1317,8 +1425,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1317 1425
1318 public string osWindActiveModelPluginName() 1426 public string osWindActiveModelPluginName()
1319 { 1427 {
1320 m_host.AddScriptLPS(1);
1321
1322 IWindModule module = World.RequestModuleInterface<IWindModule>(); 1428 IWindModule module = World.RequestModuleInterface<IWindModule>();
1323 if (module != null) 1429 if (module != null)
1324 { 1430 {
@@ -1330,8 +1436,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1330 1436
1331 public void osSetWindParam(string plugin, string param, LSL_Float value) 1437 public void osSetWindParam(string plugin, string param, LSL_Float value)
1332 { 1438 {
1333 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam")) return; 1439 CheckThreatLevel(ThreatLevel.Nuisance, "osSetWindParam");
1334 m_host.AddScriptLPS(1);
1335 1440
1336 IWindModule module = World.RequestModuleInterface<IWindModule>(); 1441 IWindModule module = World.RequestModuleInterface<IWindModule>();
1337 if (module != null) 1442 if (module != null)
@@ -1346,8 +1451,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1346 1451
1347 public LSL_Float osGetWindParam(string plugin, string param) 1452 public LSL_Float osGetWindParam(string plugin, string param)
1348 { 1453 {
1349 m_host.AddScriptLPS(1);
1350
1351 IWindModule module = World.RequestModuleInterface<IWindModule>(); 1454 IWindModule module = World.RequestModuleInterface<IWindModule>();
1352 if (module != null) 1455 if (module != null)
1353 { 1456 {
@@ -1360,8 +1463,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1360 // Routines for creating and managing parcels programmatically 1463 // Routines for creating and managing parcels programmatically
1361 public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2) 1464 public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
1362 { 1465 {
1363 if (!CheckThreatLevel(ThreatLevel.High, "osParcelJoin")) return; 1466 CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
1364 m_host.AddScriptLPS(1);
1365 1467
1366 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x); 1468 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
1367 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y); 1469 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
@@ -1373,8 +1475,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1373 1475
1374 public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2) 1476 public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
1375 { 1477 {
1376 if (!CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide")) return; 1478 CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
1377 m_host.AddScriptLPS(1);
1378 1479
1379 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x); 1480 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
1380 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y); 1481 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
@@ -1387,7 +1488,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1387 public void osParcelSetDetails(LSL_Vector pos, LSL_List rules) 1488 public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
1388 { 1489 {
1389 const string functionName = "osParcelSetDetails"; 1490 const string functionName = "osParcelSetDetails";
1390 if (!CheckThreatLevel(ThreatLevel.High, functionName)) return; 1491 CheckThreatLevel(ThreatLevel.High, functionName);
1391 OSSLDeprecated(functionName, "osSetParcelDetails"); 1492 OSSLDeprecated(functionName, "osSetParcelDetails");
1392 SetParcelDetails(pos, rules, functionName); 1493 SetParcelDetails(pos, rules, functionName);
1393 } 1494 }
@@ -1395,14 +1496,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1395 public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) 1496 public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
1396 { 1497 {
1397 const string functionName = "osSetParcelDetails"; 1498 const string functionName = "osSetParcelDetails";
1398 if (!CheckThreatLevel(ThreatLevel.High, functionName)) return; 1499 CheckThreatLevel(ThreatLevel.High, functionName);
1399 SetParcelDetails(pos, rules, functionName); 1500 SetParcelDetails(pos, rules, functionName);
1400 } 1501 }
1401 1502
1402 private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) 1503 private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
1403 { 1504 {
1404 m_host.AddScriptLPS(1);
1405
1406 // Get a reference to the land data and make sure the owner of the script 1505 // Get a reference to the land data and make sure the owner of the script
1407 // can modify it 1506 // can modify it
1408 1507
@@ -1413,15 +1512,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1413 return; 1512 return;
1414 } 1513 }
1415 1514
1416 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions)) 1515 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions, false))
1417 { 1516 {
1418 OSSLShoutError("You do not have permission to modify the parcel"); 1517 OSSLShoutError("script owner does not have permission to modify the parcel");
1419 return; 1518 return;
1420 } 1519 }
1421 1520
1422 // Create a new land data object we can modify 1521 // Create a new land data object we can modify
1423 LandData newLand = startLandObject.LandData.Copy(); 1522 LandData newLand = startLandObject.LandData.Copy();
1424 UUID uuid; 1523 UUID uuid;
1524 EstateSettings es = World.RegionInfo.EstateSettings;
1525
1526 bool changed = false;
1527 bool changedSeeAvs = false;
1528 bool changedoverlay = false;
1529 bool changedneedupdate = false;
1425 1530
1426 // Process the rules, not sure what the impact would be of changing owner or group 1531 // Process the rules, not sure what the impact would be of changing owner or group
1427 for (int idx = 0; idx < rules.Length;) 1532 for (int idx = 0; idx < rules.Length;)
@@ -1431,35 +1536,151 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1431 switch (code) 1536 switch (code)
1432 { 1537 {
1433 case ScriptBaseClass.PARCEL_DETAILS_NAME: 1538 case ScriptBaseClass.PARCEL_DETAILS_NAME:
1434 newLand.Name = arg; 1539 if(newLand.Name != arg)
1540 {
1541 newLand.Name = arg;
1542 changed = true;
1543 }
1435 break; 1544 break;
1436 1545
1437 case ScriptBaseClass.PARCEL_DETAILS_DESC: 1546 case ScriptBaseClass.PARCEL_DETAILS_DESC:
1438 newLand.Description = arg; 1547 if(newLand.Description != arg)
1548 {
1549 newLand.Description = arg;
1550 changed = true;
1551 }
1439 break; 1552 break;
1440 1553
1441 case ScriptBaseClass.PARCEL_DETAILS_OWNER: 1554 case ScriptBaseClass.PARCEL_DETAILS_OWNER:
1442 if (!CheckThreatLevel(ThreatLevel.VeryHigh, functionName)) return; 1555 if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
1443 if (UUID.TryParse(arg, out uuid)) 1556 {
1444 newLand.OwnerID = uuid; 1557 OSSLError("script owner does not have permission to modify the parcel owner");
1558 }
1559 else
1560 {
1561 if (UUID.TryParse(arg, out uuid))
1562 {
1563 if(newLand.OwnerID != uuid)
1564 {
1565 changed = true;
1566 newLand.OwnerID = uuid;
1567 newLand.GroupID = UUID.Zero;
1568 }
1569 }
1570 }
1445 break; 1571 break;
1446 1572
1447 case ScriptBaseClass.PARCEL_DETAILS_GROUP: 1573 case ScriptBaseClass.PARCEL_DETAILS_GROUP:
1448 if (!CheckThreatLevel(ThreatLevel.VeryHigh, functionName)) return; 1574 if(m_host.OwnerID == newLand.OwnerID || es == null || es.IsEstateManagerOrOwner(m_host.OwnerID))
1449 if (UUID.TryParse(arg, out uuid)) 1575 {
1450 newLand.GroupID = uuid; 1576 if (UUID.TryParse(arg, out uuid))
1577 {
1578 if(newLand.GroupID != uuid)
1579 {
1580 if(uuid == UUID.Zero)
1581 {
1582 changed = true;
1583 newLand.GroupID = uuid;
1584 }
1585 else
1586 {
1587 IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
1588 GroupMembershipData member = null;
1589 if (groupsModule != null)
1590 member = groupsModule.GetMembershipData(uuid, newLand.OwnerID);
1591 if (member == null)
1592 OSSLError(string.Format("land owner is not member of the new group for parcel"));
1593 else
1594 {
1595 changed = true;
1596 newLand.GroupID = uuid;
1597 }
1598 }
1599 }
1600 }
1601 }
1602 else
1603 {
1604 OSSLError("script owner does not have permission to modify the parcel group");
1605 }
1451 break; 1606 break;
1452 1607
1453 case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE: 1608 case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
1454 if (!CheckThreatLevel(ThreatLevel.VeryHigh, functionName)) return; 1609 if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
1455 newLand.ClaimDate = Convert.ToInt32(arg); 1610 {
1456 if (newLand.ClaimDate == 0) 1611 OSSLError("script owner does not have permission to modify the parcel CLAIM DATE");
1457 newLand.ClaimDate = Util.UnixTimeSinceEpoch(); 1612 }
1613 else
1614 {
1615 int date = Convert.ToInt32(arg);
1616 if (date == 0)
1617 date = Util.UnixTimeSinceEpoch();
1618 if(newLand.ClaimDate != date)
1619 {
1620 changed = true;
1621 newLand.ClaimDate = date;
1622 }
1623 }
1624 break;
1625
1626 case ScriptBaseClass.PARCEL_DETAILS_SEE_AVATARS:
1627 bool newavs = (Convert.ToInt32(arg) != 0);
1628 if(newLand.SeeAVs != newavs)
1629 {
1630 changed = true;
1631 changedSeeAvs = true;
1632 changedoverlay = true;
1633 changedneedupdate = true;
1634 newLand.SeeAVs = newavs;
1635 }
1458 break; 1636 break;
1459 }
1460 }
1461 1637
1462 World.LandChannel.UpdateLandObject(newLand.LocalID,newLand); 1638 case ScriptBaseClass.PARCEL_DETAILS_ANY_AVATAR_SOUNDS:
1639 bool newavsounds = (Convert.ToInt32(arg) != 0);
1640 if(newLand.AnyAVSounds != newavsounds)
1641 {
1642 changed = true;
1643 newLand.AnyAVSounds = newavsounds;
1644 }
1645 break;
1646
1647 case ScriptBaseClass.PARCEL_DETAILS_GROUP_SOUNDS:
1648 bool newgrpsounds = (Convert.ToInt32(arg) != 0);
1649 if(newLand.GroupAVSounds != newgrpsounds)
1650 {
1651 changed = true;
1652 newLand.GroupAVSounds = newgrpsounds;
1653 }
1654 break;
1655 }
1656 }
1657 if(changed)
1658 {
1659 World.LandChannel.UpdateLandObject(newLand.LocalID, newLand);
1660
1661 if(changedneedupdate)
1662 {
1663 UUID parcelID= newLand.GlobalID;
1664 World.ForEachRootScenePresence(delegate (ScenePresence avatar)
1665 {
1666 if (avatar == null || avatar.IsDeleted || avatar.IsInTransit)
1667 return;
1668
1669 if(changedSeeAvs && avatar.currentParcelUUID == parcelID )
1670 avatar.currentParcelUUID = parcelID; // force parcel flags review
1671
1672 if(avatar.ControllingClient == null)
1673 return;
1674
1675 // this will be needed for some things like damage etc
1676// if(avatar.currentParcelUUID == parcelID)
1677// startLandObject.SendLandUpdateToClient(avatar.ControllingClient);
1678
1679 if(changedoverlay && !avatar.IsNPC)
1680 World.LandChannel.SendParcelsOverlay(avatar.ControllingClient);
1681 });
1682 }
1683 }
1463 } 1684 }
1464 1685
1465 public double osList2Double(LSL_Types.list src, int index) 1686 public double osList2Double(LSL_Types.list src, int index)
@@ -1469,7 +1690,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1469 // is not allowed to contain any. 1690 // is not allowed to contain any.
1470 // This really should be removed. 1691 // This really should be removed.
1471 // 1692 //
1472 m_host.AddScriptLPS(1);
1473 if (index < 0) 1693 if (index < 0)
1474 { 1694 {
1475 index = src.Length + index; 1695 index = src.Length + index;
@@ -1485,9 +1705,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1485 { 1705 {
1486 // What actually is the difference to the LL function? 1706 // What actually is the difference to the LL function?
1487 // 1707 //
1488 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL")) return; 1708 CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
1489
1490 m_host.AddScriptLPS(1);
1491 1709
1492 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 1710 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
1493 1711
@@ -1501,9 +1719,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1501 { 1719 {
1502 // What actually is the difference to the LL function? 1720 // What actually is the difference to the LL function?
1503 // 1721 //
1504 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress")) return; 1722 CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
1505
1506 m_host.AddScriptLPS(1);
1507 1723
1508 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 1724 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
1509 1725
@@ -1529,9 +1745,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1529 // that trigger engine-specific failures. 1745 // that trigger engine-specific failures.
1530 // Besides, public grid users aren't supposed to know. 1746 // Besides, public grid users aren't supposed to know.
1531 // 1747 //
1532 // On the other hand, what other script engines are there? 1748 // And yet, they get to choose the engine in their scripts. Pfffft
1533 // 1749// CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
1534 m_host.AddScriptLPS(1);
1535 1750
1536 int scriptEngineNameIndex = 0; 1751 int scriptEngineNameIndex = 0;
1537 1752
@@ -1557,7 +1772,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1557 1772
1558 public LSL_Integer osCheckODE() 1773 public LSL_Integer osCheckODE()
1559 { 1774 {
1560 m_host.AddScriptLPS(1);
1561 LSL_Integer ret = 0; // false 1775 LSL_Integer ret = 0; // false
1562 if (m_ScriptEngine.World.PhysicsScene != null) 1776 if (m_ScriptEngine.World.PhysicsScene != null)
1563 { 1777 {
@@ -1580,22 +1794,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1580 // about the physics engine, this function returns an empty string if 1794 // about the physics engine, this function returns an empty string if
1581 // the user does not have permission to see it. This as opposed to 1795 // the user does not have permission to see it. This as opposed to
1582 // throwing an exception. 1796 // throwing an exception.
1583 m_host.AddScriptLPS(1); 1797
1584 string ret = String.Empty; 1798 string ret = String.Empty;
1799// if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
1800 {
1801 if (m_ScriptEngine.World.PhysicsScene != null)
1802 {
1803 ret = m_ScriptEngine.World.PhysicsScene.EngineType;
1804 // An old physics engine might have an uninitialized engine type
1805 if (ret == null)
1806 ret = "unknown";
1807 }
1808 }
1809
1810 return ret;
1811 }
1812
1813 public string osGetPhysicsEngineName()
1814 {
1815 CheckThreatLevel();
1816
1817 string ret = "NoEngine";
1585 if (m_ScriptEngine.World.PhysicsScene != null) 1818 if (m_ScriptEngine.World.PhysicsScene != null)
1586 { 1819 {
1587 ret = m_ScriptEngine.World.PhysicsScene.EngineType; 1820 ret = m_ScriptEngine.World.PhysicsScene.EngineName;
1588 // An old physics engine might have an uninitialized engine type 1821 // An old physics engine might have an uninitialized engine type
1589 if (ret == null) 1822 if (ret == null)
1590 ret = "unknown"; 1823 ret = "UnknownEngine";
1591 } 1824 }
1592
1593 return ret; 1825 return ret;
1594 } 1826 }
1595 1827
1596 public string osGetSimulatorVersion() 1828 public string osGetSimulatorVersion()
1597 { 1829 {
1598 m_host.AddScriptLPS(1); 1830 // High because it can be used to target attacks to known weaknesses
1831 // This would allow a new class of griefer scripts that don't even
1832 // require their user to know what they are doing (see script
1833 // kiddie)
1834 //
1835 // Or they could check in the About window. Pfffft
1836// CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
1599 1837
1600 return m_ScriptEngine.World.GetSimulatorVersion(); 1838 return m_ScriptEngine.World.GetSimulatorVersion();
1601 } 1839 }
@@ -1639,8 +1877,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1639 1877
1640 public Object osParseJSONNew(string JSON) 1878 public Object osParseJSONNew(string JSON)
1641 { 1879 {
1642 m_host.AddScriptLPS(1);
1643
1644 try 1880 try
1645 { 1881 {
1646 OSD decoded = OSDParser.DeserializeJson(JSON); 1882 OSD decoded = OSDParser.DeserializeJson(JSON);
@@ -1648,15 +1884,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1648 } 1884 }
1649 catch(Exception e) 1885 catch(Exception e)
1650 { 1886 {
1651 OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message); 1887 OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
1652 return null; 1888 return null;
1653 } 1889 }
1654 } 1890 }
1655 1891
1656 public Hashtable osParseJSON(string JSON) 1892 public Hashtable osParseJSON(string JSON)
1657 { 1893 {
1658 m_host.AddScriptLPS(1);
1659
1660 Object decoded = osParseJSONNew(JSON); 1894 Object decoded = osParseJSONNew(JSON);
1661 1895
1662 if ( decoded is Hashtable ) { 1896 if ( decoded is Hashtable ) {
@@ -1686,8 +1920,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1686 /// <param name="message"></param> 1920 /// <param name="message"></param>
1687 public void osMessageObject(LSL_Key objectUUID, string message) 1921 public void osMessageObject(LSL_Key objectUUID, string message)
1688 { 1922 {
1689 m_host.AddScriptLPS(1);
1690
1691 UUID objUUID; 1923 UUID objUUID;
1692 if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead. 1924 if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
1693 { 1925 {
@@ -1715,6 +1947,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1715 "dataserver", resobj, new DetectParams[0])); 1947 "dataserver", resobj, new DetectParams[0]));
1716 } 1948 }
1717 1949
1950
1951 /// <summary>
1952 /// Similar to llDie but given an object UUID
1953 /// </summary>
1954 /// <param name="objectUUID"></param>
1955
1956 public void osDie(LSL_Key objectUUID)
1957 {
1958// CheckThreatLevel(ThreatLevel.VeryHigh, "osDie");
1959 // if this is restricted to objects rezzed by this host level can be reduced
1960
1961// CheckThreatLevel(ThreatLevel.Low, "osDie");
1962
1963 UUID objUUID;
1964 if (!UUID.TryParse(objectUUID, out objUUID))
1965 {
1966 OSSLShoutError("osDie() cannot delete objects with invalid UUIDs");
1967 return;
1968 }
1969
1970 // harakiri check
1971 if(objUUID == UUID.Zero)
1972 {
1973 if (!m_host.ParentGroup.IsAttachment)
1974 throw new SelfDeleteException();
1975 return;
1976 }
1977
1978 SceneObjectGroup sceneOG = World.GetSceneObjectGroup(objUUID);
1979
1980 if (sceneOG == null || sceneOG.IsDeleted)
1981 return;
1982
1983 if(sceneOG.IsAttachment)
1984 return;
1985
1986 if (sceneOG.OwnerID != m_host.OwnerID)
1987 return;
1988
1989 // harakiri check
1990 if(sceneOG.UUID == m_host.ParentGroup.UUID)
1991 throw new SelfDeleteException();
1992
1993 // restrict to objects rezzed by host
1994 if(sceneOG.RezzerID == m_host.ParentGroup.UUID)
1995 World.DeleteSceneObject(sceneOG, false);
1996 }
1997
1718 /// <summary> 1998 /// <summary>
1719 /// Write a notecard directly to the prim's inventory. 1999 /// Write a notecard directly to the prim's inventory.
1720 /// </summary> 2000 /// </summary>
@@ -1727,7 +2007,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1727 /// <param name="contents">The contents of the notecard.</param> 2007 /// <param name="contents">The contents of the notecard.</param>
1728 public void osMakeNotecard(string notecardName, LSL_Types.list contents) 2008 public void osMakeNotecard(string notecardName, LSL_Types.list contents)
1729 { 2009 {
1730 m_host.AddScriptLPS(1); 2010// CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
1731 2011
1732 StringBuilder notecardData = new StringBuilder(); 2012 StringBuilder notecardData = new StringBuilder();
1733 2013
@@ -1778,8 +2058,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1778 taskItem.ResetIDs(m_host.UUID); 2058 taskItem.ResetIDs(m_host.UUID);
1779 taskItem.ParentID = m_host.UUID; 2059 taskItem.ParentID = m_host.UUID;
1780 taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch(); 2060 taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
1781 taskItem.Name = asset.Name; 2061 taskItem.Name = name;
1782 taskItem.Description = asset.Description; 2062 taskItem.Description = description;
1783 taskItem.Type = (int)AssetType.Notecard; 2063 taskItem.Type = (int)AssetType.Notecard;
1784 taskItem.InvType = (int)InventoryType.Notecard; 2064 taskItem.InvType = (int)InventoryType.Notecard;
1785 taskItem.OwnerID = m_host.OwnerID; 2065 taskItem.OwnerID = m_host.OwnerID;
@@ -1799,6 +2079,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1799 m_host.Inventory.AddInventoryItemExclusive(taskItem, false); 2079 m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
1800 else 2080 else
1801 m_host.Inventory.AddInventoryItem(taskItem, false); 2081 m_host.Inventory.AddInventoryItem(taskItem, false);
2082 m_host.ParentGroup.InvalidateDeepEffectivePerms();
1802 2083
1803 return taskItem; 2084 return taskItem;
1804 } 2085 }
@@ -1843,15 +2124,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1843 { 2124 {
1844 UUID assetID = UUID.Zero; 2125 UUID assetID = UUID.Zero;
1845 2126
1846 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 2127 bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
2128
2129 if (!notecardNameIsUUID)
1847 { 2130 {
1848 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 2131 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1849 {
1850 if (item.Type == 7 && item.Name == notecardNameOrUuid)
1851 {
1852 assetID = item.AssetID;
1853 }
1854 }
1855 } 2132 }
1856 2133
1857 if (assetID == UUID.Zero) 2134 if (assetID == UUID.Zero)
@@ -1862,13 +2139,43 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1862 AssetBase a = World.AssetService.Get(assetID.ToString()); 2139 AssetBase a = World.AssetService.Get(assetID.ToString());
1863 2140
1864 if (a == null) 2141 if (a == null)
1865 return UUID.Zero; 2142 {
2143 // Whoops, it's still possible here that the notecard name was properly
2144 // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
2145 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
2146 if (assetID == UUID.Zero)
2147 return UUID.Zero;
2148
2149 if (!NotecardCache.IsCached(assetID))
2150 {
2151 a = World.AssetService.Get(assetID.ToString());
2152
2153 if (a == null)
2154 {
2155 return UUID.Zero;
2156 }
2157 }
2158 }
1866 2159
1867 NotecardCache.Cache(assetID, a.Data); 2160 NotecardCache.Cache(assetID, a.Data);
1868 }; 2161 };
1869 2162
1870 return assetID; 2163 return assetID;
1871 } 2164 }
2165 protected UUID SearchTaskInventoryForAssetId(string name)
2166 {
2167 UUID assetId = UUID.Zero;
2168 m_host.TaskInventory.LockItemsForRead(true);
2169 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
2170 {
2171 if (item.Type == 7 && item.Name == name)
2172 {
2173 assetId = item.AssetID;
2174 }
2175 }
2176 m_host.TaskInventory.LockItemsForRead(false);
2177 return assetId;
2178 }
1872 2179
1873 /// <summary> 2180 /// <summary>
1874 /// Directly get an entire notecard at once. 2181 /// Directly get an entire notecard at once.
@@ -1885,7 +2192,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1885 /// <returns>Notecard line</returns> 2192 /// <returns>Notecard line</returns>
1886 public string osGetNotecardLine(string name, int line) 2193 public string osGetNotecardLine(string name, int line)
1887 { 2194 {
1888 m_host.AddScriptLPS(1); 2195// CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
1889 2196
1890 UUID assetID = CacheNotecard(name); 2197 UUID assetID = CacheNotecard(name);
1891 2198
@@ -1912,7 +2219,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1912 /// <returns>Notecard text</returns> 2219 /// <returns>Notecard text</returns>
1913 public string osGetNotecard(string name) 2220 public string osGetNotecard(string name)
1914 { 2221 {
1915 m_host.AddScriptLPS(1); 2222// CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
1916 2223
1917 string text = LoadNotecard(name); 2224 string text = LoadNotecard(name);
1918 2225
@@ -1941,7 +2248,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1941 /// <returns></returns> 2248 /// <returns></returns>
1942 public int osGetNumberOfNotecardLines(string name) 2249 public int osGetNumberOfNotecardLines(string name)
1943 { 2250 {
1944 m_host.AddScriptLPS(1); 2251// CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
1945 2252
1946 UUID assetID = CacheNotecard(name); 2253 UUID assetID = CacheNotecard(name);
1947 2254
@@ -1956,8 +2263,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1956 2263
1957 public string osAvatarName2Key(string firstname, string lastname) 2264 public string osAvatarName2Key(string firstname, string lastname)
1958 { 2265 {
1959 if (!CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key")) return string.Empty; 2266 CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
1960 m_host.AddScriptLPS(1);
1961 2267
1962 IUserManagement userManager = World.RequestModuleInterface<IUserManagement>(); 2268 IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
1963 if (userManager == null) 2269 if (userManager == null)
@@ -2008,8 +2314,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2008 2314
2009 public string osKey2Name(string id) 2315 public string osKey2Name(string id)
2010 { 2316 {
2011 m_host.AddScriptLPS(1);
2012
2013 UUID key = new UUID(); 2317 UUID key = new UUID();
2014 2318
2015 if (UUID.TryParse(id, out key)) 2319 if (UUID.TryParse(id, out key))
@@ -2117,8 +2421,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2117 /// <returns></returns> 2421 /// <returns></returns>
2118 public string osGetGridNick() 2422 public string osGetGridNick()
2119 { 2423 {
2120//// if (!CheckThreatLevel(ThreatLevel.None, "osGetGridNick")) return ""; 2424// CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
2121 m_host.AddScriptLPS(1);
2122 2425
2123 string nick = String.Empty; 2426 string nick = String.Empty;
2124 IConfigSource config = m_ScriptEngine.ConfigSource; 2427 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2134,8 +2437,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2134 2437
2135 public string osGetGridName() 2438 public string osGetGridName()
2136 { 2439 {
2137//// if (!CheckThreatLevel(ThreatLevel.None, "osGetGridName")) return ""; 2440// CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
2138 m_host.AddScriptLPS(1);
2139 2441
2140 string name = String.Empty; 2442 string name = String.Empty;
2141 IConfigSource config = m_ScriptEngine.ConfigSource; 2443 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2151,8 +2453,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2151 2453
2152 public string osGetGridLoginURI() 2454 public string osGetGridLoginURI()
2153 { 2455 {
2154 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI")) return ""; 2456// CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
2155 m_host.AddScriptLPS(1);
2156 2457
2157 string loginURI = String.Empty; 2458 string loginURI = String.Empty;
2158 IConfigSource config = m_ScriptEngine.ConfigSource; 2459 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2168,11 +2469,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2168 2469
2169 public string osGetGridHomeURI() 2470 public string osGetGridHomeURI()
2170 { 2471 {
2171 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI")) return ""; 2472// CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
2172 m_host.AddScriptLPS(1);
2173 2473
2174 IConfigSource config = m_ScriptEngine.ConfigSource; 2474 IConfigSource config = m_ScriptEngine.ConfigSource;
2175 string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI", 2475 string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
2176 new string[] { "Startup", "Hypergrid" }, String.Empty); 2476 new string[] { "Startup", "Hypergrid" }, String.Empty);
2177 2477
2178 if (!string.IsNullOrEmpty(HomeURI)) 2478 if (!string.IsNullOrEmpty(HomeURI))
@@ -2190,8 +2490,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2190 2490
2191 public string osGetGridGatekeeperURI() 2491 public string osGetGridGatekeeperURI()
2192 { 2492 {
2193 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI")) return ""; 2493 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
2194 m_host.AddScriptLPS(1);
2195 2494
2196 IConfigSource config = m_ScriptEngine.ConfigSource; 2495 IConfigSource config = m_ScriptEngine.ConfigSource;
2197 string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", 2496 string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
@@ -2201,16 +2500,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2201 return gatekeeperURI; 2500 return gatekeeperURI;
2202 2501
2203 // Legacy. Remove soon! 2502 // Legacy. Remove soon!
2204 if (config.Configs["GridService"] != null) 2503//// if (config.Configs["GridService"] != null)
2205 gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI); 2504//// gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI);
2206 2505
2207 return gatekeeperURI; 2506 return gatekeeperURI;
2208 } 2507 }
2209 2508
2210 public string osGetGridCustom(string key) 2509 public string osGetGridCustom(string key)
2211 { 2510 {
2212 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom")) return String.Empty; 2511// CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
2213 m_host.AddScriptLPS(1);
2214 2512
2215 string retval = String.Empty; 2513 string retval = String.Empty;
2216 IConfigSource config = m_ScriptEngine.ConfigSource; 2514 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2226,8 +2524,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2226 2524
2227 public string osGetAvatarHomeURI(string uuid) 2525 public string osGetAvatarHomeURI(string uuid)
2228 { 2526 {
2229 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetAvatarHomeURI")) return ""; 2527// CheckThreatLevel(ThreatLevel.Low, "osGetAvatarHomeURI");
2230 m_host.AddScriptLPS(1);
2231 2528
2232 IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>(); 2529 IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>();
2233 string returnValue = ""; 2530 string returnValue = "";
@@ -2259,15 +2556,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2259 2556
2260 public LSL_String osFormatString(string str, LSL_List strings) 2557 public LSL_String osFormatString(string str, LSL_List strings)
2261 { 2558 {
2262 m_host.AddScriptLPS(1);
2263
2264 return String.Format(str, strings.Data); 2559 return String.Format(str, strings.Data);
2265 } 2560 }
2266 2561
2267 public LSL_List osMatchString(string src, string pattern, int start) 2562 public LSL_List osMatchString(string src, string pattern, int start)
2268 { 2563 {
2269 m_host.AddScriptLPS(1);
2270
2271 LSL_List result = new LSL_List(); 2564 LSL_List result = new LSL_List();
2272 2565
2273 // Normalize indices (if negative). 2566 // Normalize indices (if negative).
@@ -2307,8 +2600,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2307 2600
2308 public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start) 2601 public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
2309 { 2602 {
2310 m_host.AddScriptLPS(1);
2311
2312 // Normalize indices (if negative). 2603 // Normalize indices (if negative).
2313 // After normlaization they may still be 2604 // After normlaization they may still be
2314 // negative, but that is now relative to 2605 // negative, but that is now relative to
@@ -2331,25 +2622,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2331 2622
2332 public string osLoadedCreationDate() 2623 public string osLoadedCreationDate()
2333 { 2624 {
2334 if (!CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate")) return "";
2335 m_host.AddScriptLPS(1);
2336
2337 return World.RegionInfo.RegionSettings.LoadedCreationDate; 2625 return World.RegionInfo.RegionSettings.LoadedCreationDate;
2338 } 2626 }
2339 2627
2340 public string osLoadedCreationTime() 2628 public string osLoadedCreationTime()
2341 { 2629 {
2342 if (!CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime")) return "";
2343 m_host.AddScriptLPS(1);
2344
2345 return World.RegionInfo.RegionSettings.LoadedCreationTime; 2630 return World.RegionInfo.RegionSettings.LoadedCreationTime;
2346 } 2631 }
2347 2632
2348 public string osLoadedCreationID() 2633 public string osLoadedCreationID()
2349 { 2634 {
2350 if (!CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID")) return "";
2351 m_host.AddScriptLPS(1);
2352
2353 return World.RegionInfo.RegionSettings.LoadedCreationID; 2635 return World.RegionInfo.RegionSettings.LoadedCreationID;
2354 } 2636 }
2355 2637
@@ -2368,8 +2650,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2368 /// <returns></returns> 2650 /// <returns></returns>
2369 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) 2651 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
2370 { 2652 {
2371 if (!CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams")) return new LSL_List(); 2653 CheckThreatLevel(ThreatLevel.VeryLow, "osGetLinkPrimitiveParams");
2372 m_host.AddScriptLPS(1); 2654
2373 InitLSL(); 2655 InitLSL();
2374 // One needs to cast m_LSL_Api because we're using functions not 2656 // One needs to cast m_LSL_Api because we're using functions not
2375 // on the ILSL_Api interface. 2657 // on the ILSL_Api interface.
@@ -2396,9 +2678,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2396 2678
2397 public void osForceCreateLink(string target, int parent) 2679 public void osForceCreateLink(string target, int parent)
2398 { 2680 {
2399 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink")) return; 2681 CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink");
2400
2401 m_host.AddScriptLPS(1);
2402 2682
2403 InitLSL(); 2683 InitLSL();
2404 ((LSL_Api)m_LSL_Api).CreateLink(target, parent); 2684 ((LSL_Api)m_LSL_Api).CreateLink(target, parent);
@@ -2406,9 +2686,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2406 2686
2407 public void osForceBreakLink(int linknum) 2687 public void osForceBreakLink(int linknum)
2408 { 2688 {
2409 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink")) return; 2689 CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink");
2410
2411 m_host.AddScriptLPS(1);
2412 2690
2413 InitLSL(); 2691 InitLSL();
2414 ((LSL_Api)m_LSL_Api).BreakLink(linknum); 2692 ((LSL_Api)m_LSL_Api).BreakLink(linknum);
@@ -2416,9 +2694,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2416 2694
2417 public void osForceBreakAllLinks() 2695 public void osForceBreakAllLinks()
2418 { 2696 {
2419 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks")) return; 2697 CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks");
2420
2421 m_host.AddScriptLPS(1);
2422 2698
2423 InitLSL(); 2699 InitLSL();
2424 ((LSL_Api)m_LSL_Api).BreakAllLinks(); 2700 ((LSL_Api)m_LSL_Api).BreakAllLinks();
@@ -2426,8 +2702,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2426 2702
2427 public LSL_Integer osIsNpc(LSL_Key npc) 2703 public LSL_Integer osIsNpc(LSL_Key npc)
2428 { 2704 {
2429 m_host.AddScriptLPS(1);
2430
2431 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2705 INPCModule module = World.RequestModuleInterface<INPCModule>();
2432 if (module != null) 2706 if (module != null)
2433 { 2707 {
@@ -2442,31 +2716,99 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2442 2716
2443 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) 2717 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
2444 { 2718 {
2445 if (!CheckThreatLevel(ThreatLevel.High, "osNpcCreate")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 2719 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2446 m_host.AddScriptLPS(1); 2720
2721 // have to get the npc module also here to set the default Not Owned
2722 INPCModule module = World.RequestModuleInterface<INPCModule>();
2723 if(module == null)
2724 return new LSL_Key(UUID.Zero.ToString());
2725
2726 bool owned = (module.NPCOptionFlags & NPCOptionsFlags.AllowNotOwned) == 0;
2447 2727
2448 return NpcCreate(firstname, lastname, position, notecard, false, false); 2728 return NpcCreate(firstname, lastname, position, notecard, owned, false, false);
2449 } 2729 }
2450 2730
2451 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) 2731 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
2452 { 2732 {
2453 if (!CheckThreatLevel(ThreatLevel.High, "osNpcCreate")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 2733 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2454 m_host.AddScriptLPS(1);
2455 2734
2456 return NpcCreate( 2735 return NpcCreate(
2457 firstname, lastname, position, notecard, 2736 firstname, lastname, position, notecard,
2458 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, 2737 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
2459 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); 2738 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0,
2739 (options & ScriptBaseClass.OS_NPC_OBJECT_GROUP) != 0);
2460 } 2740 }
2461 2741
2462 private LSL_Key NpcCreate( 2742 private LSL_Key NpcCreate(
2463 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) 2743 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent, bool hostGroupID)
2464 { 2744 {
2745 if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
2746 {
2747 OSSLError("no permission to rez NPC at requested location");
2748 return new LSL_Key(UUID.Zero.ToString());
2749 }
2750
2465 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2751 INPCModule module = World.RequestModuleInterface<INPCModule>();
2466 if (module != null) 2752 if(module == null)
2753 {
2754 OSSLError("NPC module not enabled");
2755 return new LSL_Key(UUID.Zero.ToString());
2756 }
2757
2758 string groupTitle = String.Empty;
2759 UUID groupID = UUID.Zero;
2760
2761 AvatarAppearance appearance = null;
2762
2763 // check creation options
2764 NPCOptionsFlags createFlags = module.NPCOptionFlags;
2765
2766 if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
2767 {
2768 OSSLError("Not owned NPCs disabled");
2769 owned = true; // we should get here...
2770 }
2771
2772 if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
2773 {
2774 OSSLError("NPC allow sense as Avatar disabled");
2775 senseAsAgent = false;
2776 }
2777
2778 if(hostGroupID && m_host.GroupID != UUID.Zero)
2467 { 2779 {
2468 AvatarAppearance appearance = null; 2780 IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
2781 if (groupsModule != null)
2782 {
2783 GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
2784 if (member == null)
2785 {
2786 OSSLError(string.Format("osNpcCreate: the object owner is not member of the object group"));
2787 return new LSL_Key(UUID.Zero.ToString());
2788 }
2789
2790 groupID = m_host.GroupID;
2791
2792 if((createFlags & NPCOptionsFlags.NoNPCGroup) != 0)
2793 {
2794 GroupRecord grprec = groupsModule.GetGroupRecord(m_host.GroupID);
2795 if(grprec != null && grprec.GroupName != "")
2796 groupTitle = grprec.GroupName;
2797 }
2798 }
2799 }
2800
2801 if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
2802 {
2803 if (firstname != String.Empty || lastname != String.Empty)
2804 {
2805 if (firstname != "Shown outfit:")
2806 groupTitle = "- NPC -";
2807 }
2808 }
2469 2809
2810 if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
2811 {
2470 UUID id; 2812 UUID id;
2471 if (UUID.TryParse(notecard, out id)) 2813 if (UUID.TryParse(notecard, out id))
2472 { 2814 {
@@ -2474,38 +2816,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2474 if (clonePresence != null) 2816 if (clonePresence != null)
2475 appearance = clonePresence.Appearance; 2817 appearance = clonePresence.Appearance;
2476 } 2818 }
2819 }
2477 2820
2478 if (appearance == null) 2821 if (appearance == null)
2479 { 2822 {
2480 string appearanceSerialized = LoadNotecard(notecard); 2823 string appearanceSerialized = LoadNotecard(notecard);
2481 2824
2482 if (appearanceSerialized != null) 2825 if (appearanceSerialized != null)
2826 {
2827 try
2483 { 2828 {
2484 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); 2829 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2485 appearance = new AvatarAppearance(); 2830 appearance = new AvatarAppearance();
2486 appearance.Unpack(appearanceOsd); 2831 appearance.Unpack(appearanceOsd);
2487 } 2832 }
2488 else 2833 catch
2489 { 2834 {
2490 OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); 2835 OSSLError(string.Format("osNpcCreate: Error processing notcard '{0}'", notecard));
2836 return new LSL_Key(UUID.Zero.ToString());
2491 } 2837 }
2492 } 2838 }
2839 else
2840 {
2841 OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
2842 }
2843 }
2493 2844
2494 UUID ownerID = UUID.Zero; 2845 UUID ownerID = UUID.Zero;
2495 if (owned) 2846 if (owned)
2496 ownerID = m_host.OwnerID; 2847 ownerID = m_host.OwnerID;
2497 UUID x = module.CreateNPC(firstname, 2848 UUID x = module.CreateNPC(firstname,
2498 lastname, 2849 lastname,
2499 position, 2850 position,
2500 ownerID, 2851 UUID.Random(),
2501 senseAsAgent, 2852 ownerID,
2502 World, 2853 groupTitle,
2503 appearance); 2854 groupID,
2855 senseAsAgent,
2856 World,
2857 appearance);
2504 2858
2505 return new LSL_Key(x.ToString()); 2859 ScenePresence sp;
2860 if (World.TryGetScenePresence(x, out sp))
2861 {
2862 sp.SendAvatarDataToAllAgents();
2506 } 2863 }
2507 2864 return new LSL_Key(x.ToString());
2508 return new LSL_Key(UUID.Zero.ToString());
2509 } 2865 }
2510 2866
2511 /// <summary> 2867 /// <summary>
@@ -2516,9 +2872,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2516 /// <returns>The asset ID of the notecard saved.</returns> 2872 /// <returns>The asset ID of the notecard saved.</returns>
2517 public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard) 2873 public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
2518 { 2874 {
2519 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance")) return new LSL_Key(ScriptBaseClass.NULL_KEY);
2520 m_host.AddScriptLPS(1);
2521
2522 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 2875 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2523 2876
2524 if (npcModule != null) 2877 if (npcModule != null)
@@ -2538,9 +2891,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2538 2891
2539 public void osNpcLoadAppearance(LSL_Key npc, string notecard) 2892 public void osNpcLoadAppearance(LSL_Key npc, string notecard)
2540 { 2893 {
2541 if (!CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance")) return;
2542 m_host.AddScriptLPS(1);
2543
2544 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 2894 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2545 2895
2546 if (npcModule != null) 2896 if (npcModule != null)
@@ -2570,8 +2920,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2570 2920
2571 public LSL_Key osNpcGetOwner(LSL_Key npc) 2921 public LSL_Key osNpcGetOwner(LSL_Key npc)
2572 { 2922 {
2573 m_host.AddScriptLPS(1);
2574
2575 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 2923 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2576 if (npcModule != null) 2924 if (npcModule != null)
2577 { 2925 {
@@ -2591,8 +2939,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2591 2939
2592 public LSL_Vector osNpcGetPos(LSL_Key npc) 2940 public LSL_Vector osNpcGetPos(LSL_Key npc)
2593 { 2941 {
2594 m_host.AddScriptLPS(1);
2595
2596 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 2942 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2597 if (npcModule != null) 2943 if (npcModule != null)
2598 { 2944 {
@@ -2614,9 +2960,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2614 2960
2615 public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos) 2961 public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
2616 { 2962 {
2617 if (!CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo")) return;
2618 m_host.AddScriptLPS(1);
2619
2620 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2963 INPCModule module = World.RequestModuleInterface<INPCModule>();
2621 if (module != null) 2964 if (module != null)
2622 { 2965 {
@@ -2633,9 +2976,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2633 2976
2634 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options) 2977 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
2635 { 2978 {
2636 if (!CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget")) return;
2637 m_host.AddScriptLPS(1);
2638
2639 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2979 INPCModule module = World.RequestModuleInterface<INPCModule>();
2640 if (module != null) 2980 if (module != null)
2641 { 2981 {
@@ -2658,8 +2998,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2658 2998
2659 public LSL_Rotation osNpcGetRot(LSL_Key npc) 2999 public LSL_Rotation osNpcGetRot(LSL_Key npc)
2660 { 3000 {
2661 m_host.AddScriptLPS(1);
2662
2663 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3001 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2664 if (npcModule != null) 3002 if (npcModule != null)
2665 { 3003 {
@@ -2681,9 +3019,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2681 3019
2682 public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) 3020 public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
2683 { 3021 {
2684 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSetRot")) return;
2685 m_host.AddScriptLPS(1);
2686
2687 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3022 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2688 if (npcModule != null) 3023 if (npcModule != null)
2689 { 3024 {
@@ -2703,9 +3038,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2703 3038
2704 public void osNpcStopMoveToTarget(LSL_Key npc) 3039 public void osNpcStopMoveToTarget(LSL_Key npc)
2705 { 3040 {
2706 if (!CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget")) return;
2707 m_host.AddScriptLPS(1);
2708
2709 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3041 INPCModule module = World.RequestModuleInterface<INPCModule>();
2710 if (module != null) 3042 if (module != null)
2711 { 3043 {
@@ -2718,6 +3050,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2718 } 3050 }
2719 } 3051 }
2720 3052
3053 public void osNpcSetProfileAbout(LSL_Key npc, string about)
3054 {
3055 INPCModule module = World.RequestModuleInterface<INPCModule>();
3056 if (module != null)
3057 {
3058 UUID npcId = new UUID(npc.m_string);
3059
3060 if (!module.CheckPermissions(npcId, m_host.OwnerID))
3061 return;
3062
3063 ScenePresence sp = World.GetScenePresence(npcId);
3064 if (sp != null)
3065 ((INPC)(sp.ControllingClient)).profileAbout = about;
3066 }
3067 }
3068
3069 public void osNpcSetProfileImage(LSL_Key npc, string image)
3070 {
3071 INPCModule module = World.RequestModuleInterface<INPCModule>();
3072 if (module != null)
3073 {
3074 UUID npcId = new UUID(npc.m_string);
3075
3076 if (!module.CheckPermissions(npcId, m_host.OwnerID))
3077 return;
3078
3079 UUID ImageID = new UUID();
3080
3081 ImageID = ScriptUtils.GetAssetIdFromItemName(m_host, image, (int)AssetType.Texture);
3082
3083 if (ImageID == null || ImageID == UUID.Zero)
3084 {
3085 if (!UUID.TryParse(image, out ImageID))
3086 return;
3087 }
3088
3089 ScenePresence sp = World.GetScenePresence(npcId);
3090 if (sp != null)
3091 ((INPC)(sp.ControllingClient)).profileImage = ImageID;
3092 }
3093 }
3094
2721 public void osNpcSay(LSL_Key npc, string message) 3095 public void osNpcSay(LSL_Key npc, string message)
2722 { 3096 {
2723 osNpcSay(npc, 0, message); 3097 osNpcSay(npc, 0, message);
@@ -2725,9 +3099,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2725 3099
2726 public void osNpcSay(LSL_Key npc, int channel, string message) 3100 public void osNpcSay(LSL_Key npc, int channel, string message)
2727 { 3101 {
2728 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSay")) return;
2729 m_host.AddScriptLPS(1);
2730
2731 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3102 INPCModule module = World.RequestModuleInterface<INPCModule>();
2732 if (module != null) 3103 if (module != null)
2733 { 3104 {
@@ -2742,9 +3113,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2742 3113
2743 public void osNpcShout(LSL_Key npc, int channel, string message) 3114 public void osNpcShout(LSL_Key npc, int channel, string message)
2744 { 3115 {
2745 if (!CheckThreatLevel(ThreatLevel.High, "osNpcShout")) return;
2746 m_host.AddScriptLPS(1);
2747
2748 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3116 INPCModule module = World.RequestModuleInterface<INPCModule>();
2749 if (module != null) 3117 if (module != null)
2750 { 3118 {
@@ -2759,9 +3127,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2759 3127
2760 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 3128 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
2761 { 3129 {
2762 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSit")) return;
2763 m_host.AddScriptLPS(1);
2764
2765 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3130 INPCModule module = World.RequestModuleInterface<INPCModule>();
2766 if (module != null) 3131 if (module != null)
2767 { 3132 {
@@ -2776,9 +3141,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2776 3141
2777 public void osNpcStand(LSL_Key npc) 3142 public void osNpcStand(LSL_Key npc)
2778 { 3143 {
2779 if (!CheckThreatLevel(ThreatLevel.High, "osNpcStand")) return;
2780 m_host.AddScriptLPS(1);
2781
2782 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3144 INPCModule module = World.RequestModuleInterface<INPCModule>();
2783 if (module != null) 3145 if (module != null)
2784 { 3146 {
@@ -2793,26 +3155,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2793 3155
2794 public void osNpcRemove(LSL_Key npc) 3156 public void osNpcRemove(LSL_Key npc)
2795 { 3157 {
2796 if (!CheckThreatLevel(ThreatLevel.High, "osNpcRemove")) return; 3158 try
2797 m_host.AddScriptLPS(1);
2798
2799 INPCModule module = World.RequestModuleInterface<INPCModule>();
2800 if (module != null)
2801 { 3159 {
2802 UUID npcId = new UUID(npc.m_string); 3160 INPCModule module = World.RequestModuleInterface<INPCModule>();
3161 if (module != null)
3162 {
3163 UUID npcId = new UUID(npc.m_string);
2803 3164
2804 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 3165 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2805 return; 3166 return;
2806 3167
2807 module.DeleteNPC(npcId, World); 3168 module.DeleteNPC(npcId, World);
3169 }
2808 } 3170 }
3171 catch { }
2809 } 3172 }
2810 3173
2811 public void osNpcPlayAnimation(LSL_Key npc, string animation) 3174 public void osNpcPlayAnimation(LSL_Key npc, string animation)
2812 { 3175 {
2813 if (!CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation")) return;
2814 m_host.AddScriptLPS(1);
2815
2816 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3176 INPCModule module = World.RequestModuleInterface<INPCModule>();
2817 if (module != null) 3177 if (module != null)
2818 { 3178 {
@@ -2825,9 +3185,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2825 3185
2826 public void osNpcStopAnimation(LSL_Key npc, string animation) 3186 public void osNpcStopAnimation(LSL_Key npc, string animation)
2827 { 3187 {
2828 if (!CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation")) return;
2829 m_host.AddScriptLPS(1);
2830
2831 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3188 INPCModule module = World.RequestModuleInterface<INPCModule>();
2832 if (module != null) 3189 if (module != null)
2833 { 3190 {
@@ -2840,9 +3197,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2840 3197
2841 public void osNpcWhisper(LSL_Key npc, int channel, string message) 3198 public void osNpcWhisper(LSL_Key npc, int channel, string message)
2842 { 3199 {
2843 if (!CheckThreatLevel(ThreatLevel.High, "osNpcWhisper")) return;
2844 m_host.AddScriptLPS(1);
2845
2846 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3200 INPCModule module = World.RequestModuleInterface<INPCModule>();
2847 if (module != null) 3201 if (module != null)
2848 { 3202 {
@@ -2857,9 +3211,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2857 3211
2858 public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num) 3212 public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
2859 { 3213 {
2860 if (!CheckThreatLevel(ThreatLevel.High, "osNpcTouch")) return;
2861 m_host.AddScriptLPS(1);
2862
2863 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3214 INPCModule module = World.RequestModuleInterface<INPCModule>();
2864 int linkNum = link_num.value; 3215 int linkNum = link_num.value;
2865 if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS)) 3216 if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
@@ -2902,16 +3253,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2902 /// <returns>The asset ID of the notecard saved.</returns> 3253 /// <returns>The asset ID of the notecard saved.</returns>
2903 public LSL_Key osOwnerSaveAppearance(string notecard) 3254 public LSL_Key osOwnerSaveAppearance(string notecard)
2904 { 3255 {
2905 if (!CheckThreatLevel(ThreatLevel.Moderate, "osOwnerSaveAppearance")) return new LSL_Key(ScriptBaseClass.NULL_KEY);
2906 m_host.AddScriptLPS(1);
2907
2908 return SaveAppearanceToNotecard(m_host.OwnerID, notecard); 3256 return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
2909 } 3257 }
2910 3258
2911 public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard) 3259 public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
2912 { 3260 {
2913 if (!CheckThreatLevel(ThreatLevel.High, "osAgentSaveAppearance")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 3261 CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
2914 m_host.AddScriptLPS(1);
2915 3262
2916 return SaveAppearanceToNotecard(avatarId, notecard); 3263 return SaveAppearanceToNotecard(avatarId, notecard);
2917 } 3264 }
@@ -2923,7 +3270,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2923 if (appearanceModule != null) 3270 if (appearanceModule != null)
2924 { 3271 {
2925 appearanceModule.SaveBakedTextures(sp.UUID); 3272 appearanceModule.SaveBakedTextures(sp.UUID);
2926 OSDMap appearancePacked = sp.Appearance.Pack(); 3273 EntityTransferContext ctx = new EntityTransferContext();
3274 OSDMap appearancePacked = sp.Appearance.Pack(ctx);
2927 3275
2928 TaskInventoryItem item 3276 TaskInventoryItem item
2929 = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true); 3277 = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
@@ -2962,8 +3310,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2962 /// <returns>"male" or "female" or "unknown"</returns> 3310 /// <returns>"male" or "female" or "unknown"</returns>
2963 public LSL_String osGetGender(LSL_Key rawAvatarId) 3311 public LSL_String osGetGender(LSL_Key rawAvatarId)
2964 { 3312 {
2965 m_host.AddScriptLPS(1);
2966
2967 UUID avatarId; 3313 UUID avatarId;
2968 if (!UUID.TryParse(rawAvatarId, out avatarId)) 3314 if (!UUID.TryParse(rawAvatarId, out avatarId))
2969 return new LSL_String("unknown"); 3315 return new LSL_String("unknown");
@@ -3005,8 +3351,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3005 /// <returns></returns> 3351 /// <returns></returns>
3006 public LSL_Key osGetMapTexture() 3352 public LSL_Key osGetMapTexture()
3007 { 3353 {
3008 m_host.AddScriptLPS(1);
3009
3010 return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString(); 3354 return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
3011 } 3355 }
3012 3356
@@ -3017,8 +3361,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3017 /// <returns></returns> 3361 /// <returns></returns>
3018 public LSL_Key osGetRegionMapTexture(string regionName) 3362 public LSL_Key osGetRegionMapTexture(string regionName)
3019 { 3363 {
3020 m_host.AddScriptLPS(1);
3021
3022 Scene scene = m_ScriptEngine.World; 3364 Scene scene = m_ScriptEngine.World;
3023 UUID key = UUID.Zero; 3365 UUID key = UUID.Zero;
3024 GridRegion region; 3366 GridRegion region;
@@ -3045,7 +3387,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3045 /// <returns>List of floats</returns> 3387 /// <returns>List of floats</returns>
3046 public LSL_List osGetRegionStats() 3388 public LSL_List osGetRegionStats()
3047 { 3389 {
3048 m_host.AddScriptLPS(1); 3390 CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
3391
3049 LSL_List ret = new LSL_List(); 3392 LSL_List ret = new LSL_List();
3050 float[] stats = World.StatsReporter.LastReportedSimStats; 3393 float[] stats = World.StatsReporter.LastReportedSimStats;
3051 3394
@@ -3058,32 +3401,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3058 3401
3059 public LSL_Vector osGetRegionSize() 3402 public LSL_Vector osGetRegionSize()
3060 { 3403 {
3061 m_host.AddScriptLPS(1); 3404 Scene scene = m_ScriptEngine.World;
3062 3405 RegionInfo reg = World.RegionInfo;
3063 bool isMegaregion; 3406// GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
3064 IRegionCombinerModule rcMod = World.RequestModuleInterface<IRegionCombinerModule>(); 3407// return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeY, (float)Constants.RegionHeight);
3065 if (rcMod != null) 3408 return new LSL_Vector((float)reg.RegionSizeX, (float)reg.RegionSizeY, 0.0f);
3066 isMegaregion = rcMod.IsRootForMegaregion(World.RegionInfo.RegionID);
3067 else
3068 isMegaregion = false;
3069
3070 if (isMegaregion)
3071 {
3072 Vector2 size = rcMod.GetSizeOfMegaregion(World.RegionInfo.RegionID);
3073 return new LSL_Vector(size.X, size.Y, Constants.RegionHeight);
3074 }
3075 else
3076 {
3077 Scene scene = m_ScriptEngine.World;
3078 GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
3079 return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeX, Constants.RegionHeight);
3080 }
3081 } 3409 }
3082 3410
3083 public int osGetSimulatorMemory() 3411 public int osGetSimulatorMemory()
3084 { 3412 {
3085 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory")) return 0; 3413 CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
3086 m_host.AddScriptLPS(1); 3414
3087 long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; 3415 long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
3088 3416
3089 if (pws > Int32.MaxValue) 3417 if (pws > Int32.MaxValue)
@@ -3094,10 +3422,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3094 return (int)pws; 3422 return (int)pws;
3095 } 3423 }
3096 3424
3425 public int osGetSimulatorMemoryKB()
3426 {
3427 CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemoryKB");
3428
3429 long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
3430
3431 if((pws & 0x3FFL) != 0)
3432 pws += 0x400L;
3433 pws >>= 10;
3434
3435 if (pws > Int32.MaxValue)
3436 return Int32.MaxValue;
3437
3438 return (int)pws;
3439 }
3440
3097 public void osSetSpeed(string UUID, LSL_Float SpeedModifier) 3441 public void osSetSpeed(string UUID, LSL_Float SpeedModifier)
3098 { 3442 {
3099 if (!CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed")) return; 3443 CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
3100 m_host.AddScriptLPS(1); 3444
3101 ScenePresence avatar = World.GetScenePresence(new UUID(UUID)); 3445 ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
3102 3446
3103 if (avatar != null) 3447 if (avatar != null)
@@ -3106,8 +3450,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3106 3450
3107 public void osKickAvatar(string FirstName, string SurName, string alert) 3451 public void osKickAvatar(string FirstName, string SurName, string alert)
3108 { 3452 {
3109 if (!CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar")) return; 3453 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
3110 m_host.AddScriptLPS(1);
3111 3454
3112 World.ForEachRootScenePresence(delegate(ScenePresence sp) 3455 World.ForEachRootScenePresence(delegate(ScenePresence sp)
3113 { 3456 {
@@ -3125,23 +3468,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3125 3468
3126 public LSL_Float osGetHealth(string avatar) 3469 public LSL_Float osGetHealth(string avatar)
3127 { 3470 {
3128 m_host.AddScriptLPS(1);
3129
3130 LSL_Float health = new LSL_Float(-1); 3471 LSL_Float health = new LSL_Float(-1);
3131 ScenePresence presence = World.GetScenePresence(new UUID(avatar)); 3472 ScenePresence presence = World.GetScenePresence(new UUID(avatar));
3132 if (presence != null) health = presence.Health; 3473 if (presence != null)
3474 health = presence.Health;
3133 return health; 3475 return health;
3134 } 3476 }
3135 3477
3136 public void osCauseDamage(string avatar, double damage) 3478 public void osCauseDamage(string avatar, double damage)
3137 { 3479 {
3138 if (!CheckThreatLevel(ThreatLevel.High, "osCauseDamage")) return; 3480 CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
3139 m_host.AddScriptLPS(1);
3140 3481
3141 UUID avatarId = new UUID(avatar); 3482 UUID avatarId = new UUID(avatar);
3142 Vector3 pos = m_host.GetWorldPosition(); 3483 Vector3 pos = m_host.GetWorldPosition();
3143 3484
3144 ScenePresence presence = World.GetScenePresence(avatarId); 3485 ScenePresence presence = World.GetScenePresence(avatarId);
3145 if (presence != null) 3486 if (presence != null)
3146 { 3487 {
3147 LandData land = World.GetLandData(pos); 3488 LandData land = World.GetLandData(pos);
@@ -3163,13 +3504,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3163 3504
3164 public void osCauseHealing(string avatar, double healing) 3505 public void osCauseHealing(string avatar, double healing)
3165 { 3506 {
3166 if (!CheckThreatLevel(ThreatLevel.High, "osCauseHealing")) return; 3507 CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
3167 m_host.AddScriptLPS(1);
3168 3508
3169 UUID avatarId = new UUID(avatar); 3509 UUID avatarId = new UUID(avatar);
3170 ScenePresence presence = World.GetScenePresence(avatarId); 3510 ScenePresence presence = World.GetScenePresence(avatarId);
3171 3511
3172 if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition())) 3512 if (presence != null)
3173 { 3513 {
3174 float health = presence.Health; 3514 float health = presence.Health;
3175 health += (float)healing; 3515 health += (float)healing;
@@ -3181,31 +3521,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3181 } 3521 }
3182 } 3522 }
3183 3523
3524 public void osSetHealth(string avatar, double health)
3525 {
3526 CheckThreatLevel(ThreatLevel.High, "osSetHealth");
3527
3528 UUID avatarId = new UUID(avatar);
3529 ScenePresence presence = World.GetScenePresence(avatarId);
3530
3531 if (presence != null)
3532 {
3533 if (health > 100.0)
3534 health = 100.0;
3535 else if (health < 1.0)
3536 health = 1.0;
3537
3538 presence.setHealthWithUpdate((float)health);
3539 }
3540 }
3541
3542 public void osSetHealRate(string avatar, double healrate)
3543 {
3544 CheckThreatLevel(ThreatLevel.High, "osSetHealRate");
3545
3546 UUID avatarId = new UUID(avatar);
3547 ScenePresence presence = World.GetScenePresence(avatarId);
3548
3549 if (presence != null)
3550 presence.HealRate = (float)healrate;
3551 }
3552
3553 public LSL_Float osGetHealRate(string avatar)
3554 {
3555 LSL_Float rate = new LSL_Float(0);
3556 ScenePresence presence = World.GetScenePresence(new UUID(avatar));
3557 if (presence != null)
3558 rate = presence.HealRate;
3559 return rate;
3560 }
3561
3184 public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules) 3562 public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
3185 { 3563 {
3186 if (!CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams")) return new LSL_List(); 3564 CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
3187 m_host.AddScriptLPS(1);
3188 InitLSL();
3189 3565
3566 InitLSL();
3190 return m_LSL_Api.GetPrimitiveParamsEx(prim, rules); 3567 return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
3191 } 3568 }
3192 3569
3193 public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules) 3570 public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
3194 { 3571 {
3195 if (!CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams")) return; 3572 CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimitiveParams");
3196 m_host.AddScriptLPS(1);
3197 InitLSL();
3198 3573
3574 InitLSL();
3199 m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams"); 3575 m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
3200 } 3576 }
3201 3577
3202 /// <summary> 3578 /// <summary>
3203 /// Set parameters for light projection in host prim 3579 /// Set parameters for light projection in host prim
3204 /// </summary> 3580 /// </summary>
3205 public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb) 3581 public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
3206 { 3582 {
3207 if (!CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams")) return;
3208
3209 osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb); 3583 osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
3210 } 3584 }
3211 3585
@@ -3214,8 +3588,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3214 /// </summary> 3588 /// </summary>
3215 public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb) 3589 public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
3216 { 3590 {
3217 if (!CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams")) return; 3591 CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
3218 m_host.AddScriptLPS(1);
3219 3592
3220 SceneObjectPart obj = null; 3593 SceneObjectPart obj = null;
3221 if (prim == UUID.Zero.ToString()) 3594 if (prim == UUID.Zero.ToString())
@@ -3245,12 +3618,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3245 /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns> 3618 /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
3246 public LSL_List osGetAvatarList() 3619 public LSL_List osGetAvatarList()
3247 { 3620 {
3248 m_host.AddScriptLPS(1); 3621 LSL_List result = new LSL_List();
3622 World.ForEachRootScenePresence(delegate (ScenePresence avatar)
3623 {
3624 if (avatar != null && !avatar.IsDeleted && avatar.UUID != m_host.OwnerID )
3625 {
3626 result.Add(new LSL_String(avatar.UUID.ToString()));
3627 result.Add(new LSL_Vector(avatar.AbsolutePosition));
3628 result.Add(new LSL_String(avatar.Name));
3629 }
3630 });
3631
3632 return result;
3633 }
3249 3634
3635 public LSL_List osGetNPCList()
3636 {
3250 LSL_List result = new LSL_List(); 3637 LSL_List result = new LSL_List();
3251 World.ForEachRootScenePresence(delegate (ScenePresence avatar) 3638 World.ForEachRootScenePresence(delegate (ScenePresence avatar)
3252 { 3639 {
3253 if (avatar != null && avatar.UUID != m_host.OwnerID) 3640 // npcs are not childagents but that is now.
3641 if (avatar != null && avatar.IsNPC && !avatar.IsDeleted && !avatar.IsChildAgent && !avatar.IsInTransit)
3254 { 3642 {
3255 result.Add(new LSL_String(avatar.UUID.ToString())); 3643 result.Add(new LSL_String(avatar.UUID.ToString()));
3256 result.Add(new LSL_Vector(avatar.AbsolutePosition)); 3644 result.Add(new LSL_Vector(avatar.AbsolutePosition));
@@ -3268,8 +3656,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3268 /// <returns></returns> 3656 /// <returns></returns>
3269 public LSL_String osUnixTimeToTimestamp(long time) 3657 public LSL_String osUnixTimeToTimestamp(long time)
3270 { 3658 {
3271 m_host.AddScriptLPS(1);
3272
3273 long baseTicks = 621355968000000000; 3659 long baseTicks = 621355968000000000;
3274 long tickResolution = 10000000; 3660 long tickResolution = 10000000;
3275 long epochTicks = (time * tickResolution) + baseTicks; 3661 long epochTicks = (time * tickResolution) + baseTicks;
@@ -3282,11 +3668,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3282 /// Get the description from an inventory item 3668 /// Get the description from an inventory item
3283 /// </summary> 3669 /// </summary>
3284 /// <param name="inventoryName"></param> 3670 /// <param name="inventoryName"></param>
3285 /// <returns>Item description</returns> 3671 /// <returns>Item description</returns>
3286 public LSL_String osGetInventoryDesc(string item) 3672 public LSL_String osGetInventoryDesc(string item)
3287 { 3673 {
3288 m_host.AddScriptLPS(1);
3289
3290 lock (m_host.TaskInventory) 3674 lock (m_host.TaskInventory)
3291 { 3675 {
3292 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3676 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
@@ -3308,8 +3692,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3308 /// <returns></returns> 3692 /// <returns></returns>
3309 public LSL_Integer osInviteToGroup(LSL_Key agentId) 3693 public LSL_Integer osInviteToGroup(LSL_Key agentId)
3310 { 3694 {
3311 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup")) return ScriptBaseClass.FALSE; 3695 CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
3312 m_host.AddScriptLPS(1);
3313 3696
3314 UUID agent = new UUID(agentId); 3697 UUID agent = new UUID(agentId);
3315 3698
@@ -3343,8 +3726,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3343 /// <returns></returns> 3726 /// <returns></returns>
3344 public LSL_Integer osEjectFromGroup(LSL_Key agentId) 3727 public LSL_Integer osEjectFromGroup(LSL_Key agentId)
3345 { 3728 {
3346 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup")) return ScriptBaseClass.FALSE; 3729 CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
3347 m_host.AddScriptLPS(1);
3348 3730
3349 UUID agent = new UUID(agentId); 3731 UUID agent = new UUID(agentId);
3350 3732
@@ -3378,9 +3760,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3378 /// <returns></returns> 3760 /// <returns></returns>
3379 public void osSetTerrainTexture(int level, LSL_Key texture) 3761 public void osSetTerrainTexture(int level, LSL_Key texture)
3380 { 3762 {
3381 if (!CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture")) return; 3763 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3382 3764
3383 m_host.AddScriptLPS(1);
3384 //Check to make sure that the script's owner is the estate manager/master 3765 //Check to make sure that the script's owner is the estate manager/master
3385 //World.Permissions.GenericEstatePermission( 3766 //World.Permissions.GenericEstatePermission(
3386 if (World.Permissions.IsGod(m_host.OwnerID)) 3767 if (World.Permissions.IsGod(m_host.OwnerID))
@@ -3408,9 +3789,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3408 /// <returns></returns> 3789 /// <returns></returns>
3409 public void osSetTerrainTextureHeight(int corner, double low, double high) 3790 public void osSetTerrainTextureHeight(int corner, double low, double high)
3410 { 3791 {
3411 if (!CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight")) return; 3792 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3412 3793
3413 m_host.AddScriptLPS(1);
3414 //Check to make sure that the script's owner is the estate manager/master 3794 //Check to make sure that the script's owner is the estate manager/master
3415 //World.Permissions.GenericEstatePermission( 3795 //World.Permissions.GenericEstatePermission(
3416 if (World.Permissions.IsGod(m_host.OwnerID)) 3796 if (World.Permissions.IsGod(m_host.OwnerID))
@@ -3429,9 +3809,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3429 3809
3430 public void osForceAttachToAvatar(int attachmentPoint) 3810 public void osForceAttachToAvatar(int attachmentPoint)
3431 { 3811 {
3432 if (!CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar")) return; 3812 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3433
3434 m_host.AddScriptLPS(1);
3435 3813
3436 InitLSL(); 3814 InitLSL();
3437 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint); 3815 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
@@ -3439,18 +3817,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3439 3817
3440 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint) 3818 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
3441 { 3819 {
3442 if (!CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory")) return; 3820 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
3443
3444 m_host.AddScriptLPS(1);
3445 3821
3446 ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint); 3822 ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
3447 } 3823 }
3448 3824
3449 public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint) 3825 public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
3450 { 3826 {
3451 if (!CheckThreatLevel(ThreatLevel.Severe, "osForceAttachToOtherAvatarFromInventory")) return; 3827 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory");
3452
3453 m_host.AddScriptLPS(1);
3454 3828
3455 UUID avatarId; 3829 UUID avatarId;
3456 3830
@@ -3480,7 +3854,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3480 if (item.InvType != (int)InventoryType.Object) 3854 if (item.InvType != (int)InventoryType.Object)
3481 { 3855 {
3482 // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set 3856 // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
3483 // up the api reference. 3857 // up the api reference.
3484 if (m_LSL_Api != null) 3858 if (m_LSL_Api != null)
3485 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName)); 3859 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
3486 3860
@@ -3509,9 +3883,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3509 3883
3510 public void osForceDetachFromAvatar() 3884 public void osForceDetachFromAvatar()
3511 { 3885 {
3512 if (!CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar")) return; 3886 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceDetachFromAvatar");
3513
3514 m_host.AddScriptLPS(1);
3515 3887
3516 InitLSL(); 3888 InitLSL();
3517 ((LSL_Api)m_LSL_Api).DetachFromAvatar(); 3889 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
@@ -3519,9 +3891,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3519 3891
3520 public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints) 3892 public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
3521 { 3893 {
3522 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments")) return new LSL_List(); 3894 CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
3523
3524 m_host.AddScriptLPS(1);
3525 3895
3526 UUID targetUUID; 3896 UUID targetUUID;
3527 ScenePresence target; 3897 ScenePresence target;
@@ -3555,15 +3925,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3555 3925
3556 public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options) 3926 public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
3557 { 3927 {
3558 if (!CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments")) return; 3928 CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
3559 m_host.AddScriptLPS(1);
3560 3929
3561 UUID targetUUID; 3930 UUID targetUUID;
3931 if(!UUID.TryParse(avatar.ToString(), out targetUUID))
3932 return;
3933
3934 if(targetUUID == UUID.Zero)
3935 return;
3936
3562 ScenePresence target; 3937 ScenePresence target;
3938 if(!World.TryGetScenePresence(targetUUID, out target))
3939 return;
3563 3940
3564 if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target)) 3941 if(target.IsDeleted || target.IsInTransit)
3942 return;
3943
3944 List<int> aps = new List<int>();
3945 if(attachmentPoints.Length != 0)
3565 { 3946 {
3566 List<int> aps = new List<int>();
3567 foreach (object point in attachmentPoints.Data) 3947 foreach (object point in attachmentPoints.Data)
3568 { 3948 {
3569 int ipoint; 3949 int ipoint;
@@ -3572,115 +3952,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3572 aps.Add(ipoint); 3952 aps.Add(ipoint);
3573 } 3953 }
3574 } 3954 }
3955 // parsing failed
3956 if(aps.Count != attachmentPoints.Length)
3957 return;
3958 }
3575 3959
3576 List<SceneObjectGroup> attachments = new List<SceneObjectGroup>(); 3960 List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
3577
3578 bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
3579 bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
3580 3961
3581 if (msgAll && invertPoints) 3962 bool msgAll;
3582 { 3963 bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
3583 return;
3584 }
3585 else if (msgAll || invertPoints)
3586 {
3587 attachments = target.GetAttachments();
3588 }
3589 else
3590 {
3591 foreach (int point in aps)
3592 {
3593 if (point > 0)
3594 {
3595 attachments.AddRange(target.GetAttachments((uint)point));
3596 }
3597 }
3598 }
3599 3964
3600 // if we have no attachments at this point, exit now 3965 if(aps.Count == 0)
3601 if (attachments.Count == 0) 3966 {
3602 { 3967 if(!invertPoints)
3603 return; 3968 return;
3604 } 3969 msgAll = true;
3970 invertPoints = false;
3971 }
3972 else
3973 msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
3605 3974
3606 List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>(); 3975 if (msgAll && invertPoints)
3976 return;
3607 3977
3608 if (invertPoints) 3978 if (msgAll || invertPoints)
3979 {
3980 attachments = target.GetAttachments();
3981 }
3982 else
3983 {
3984 foreach (int point in aps)
3609 { 3985 {
3610 foreach (SceneObjectGroup attachment in attachments) 3986 if (point > 0)
3611 { 3987 {
3612 if (aps.Contains((int)attachment.AttachmentPoint)) 3988 attachments.AddRange(target.GetAttachments((uint)point));
3613 {
3614 ignoreThese.Add(attachment);
3615 }
3616 } 3989 }
3617 } 3990 }
3991 }
3618 3992
3619 foreach (SceneObjectGroup attachment in ignoreThese) 3993 // if we have no attachments at this point, exit now
3620 { 3994 if (attachments.Count == 0)
3621 attachments.Remove(attachment); 3995 {
3622 } 3996 return;
3623 ignoreThese.Clear(); 3997 }
3624 3998
3625 // if inverting removed all attachments to check, exit now 3999 bool optionObjCreator = (options &
3626 if (attachments.Count < 1) 4000 ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0;
3627 { 4001 bool optionScriptCreator = (options &
3628 return; 4002 ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0;
3629 }
3630 4003
3631 if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0) 4004 UUID hostCreatorID = m_host.CreatorID;
3632 { 4005 UUID itemCreatorID = m_item.CreatorID;
3633 foreach (SceneObjectGroup attachment in attachments)
3634 {
3635 if (attachment.RootPart.CreatorID != m_host.CreatorID)
3636 {
3637 ignoreThese.Add(attachment);
3638 }
3639 }
3640 4006
3641 foreach (SceneObjectGroup attachment in ignoreThese) 4007 foreach (SceneObjectGroup sog in attachments)
3642 { 4008 {
3643 attachments.Remove(attachment); 4009 if(sog.IsDeleted || sog.inTransit)
3644 } 4010 continue;
3645 ignoreThese.Clear();
3646
3647 // if filtering by same object creator removed all
3648 // attachments to check, exit now
3649 if (attachments.Count == 0)
3650 {
3651 return;
3652 }
3653 }
3654 4011
3655 if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0) 4012 if (invertPoints && aps.Contains((int)sog.AttachmentPoint))
3656 { 4013 continue;
3657 foreach (SceneObjectGroup attachment in attachments)
3658 {
3659 if (attachment.RootPart.CreatorID != m_item.CreatorID)
3660 {
3661 ignoreThese.Add(attachment);
3662 }
3663 }
3664 4014
3665 foreach (SceneObjectGroup attachment in ignoreThese) 4015 UUID CreatorID = sog.RootPart.CreatorID;
3666 { 4016 if (optionObjCreator && CreatorID != hostCreatorID)
3667 attachments.Remove(attachment); 4017 continue;
3668 }
3669 ignoreThese.Clear();
3670 4018
3671 // if filtering by object creator must match originating 4019 if (optionScriptCreator && CreatorID != itemCreatorID)
3672 // script creator removed all attachments to check, 4020 continue;
3673 // exit now
3674 if (attachments.Count == 0)
3675 {
3676 return;
3677 }
3678 }
3679 4021
3680 foreach (SceneObjectGroup attachment in attachments) 4022 SceneObjectPart[] parts = sog.Parts;
3681 { 4023 foreach(SceneObjectPart p in parts)
3682 MessageObject(attachment.RootPart.UUID, message); 4024 MessageObject(p.UUID, message);
3683 }
3684 } 4025 }
3685 } 4026 }
3686 4027
@@ -3693,8 +4034,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3693 /// <returns>1 if thing is a valid UUID, 0 otherwise</returns> 4034 /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
3694 public LSL_Integer osIsUUID(string thing) 4035 public LSL_Integer osIsUUID(string thing)
3695 { 4036 {
3696 m_host.AddScriptLPS(1);
3697
3698 UUID test; 4037 UUID test;
3699 return UUID.TryParse(thing, out test) ? 1 : 0; 4038 return UUID.TryParse(thing, out test) ? 1 : 0;
3700 } 4039 }
@@ -3707,8 +4046,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3707 /// <returns></returns> 4046 /// <returns></returns>
3708 public LSL_Float osMin(double a, double b) 4047 public LSL_Float osMin(double a, double b)
3709 { 4048 {
3710 m_host.AddScriptLPS(1);
3711
3712 return Math.Min(a, b); 4049 return Math.Min(a, b);
3713 } 4050 }
3714 4051
@@ -3720,16 +4057,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3720 /// <returns></returns> 4057 /// <returns></returns>
3721 public LSL_Float osMax(double a, double b) 4058 public LSL_Float osMax(double a, double b)
3722 { 4059 {
3723 m_host.AddScriptLPS(1);
3724
3725 return Math.Max(a, b); 4060 return Math.Max(a, b);
3726 } 4061 }
3727 4062
3728 public LSL_Key osGetRezzingObject() 4063 public LSL_Key osGetRezzingObject()
3729 { 4064 {
3730 m_host.AddScriptLPS(1); 4065 UUID rezID = m_host.ParentGroup.RezzerID;
3731 4066 if(rezID == UUID.Zero || m_host.ParentGroup.Scene.GetScenePresence(rezID) != null)
3732 return new LSL_Key(m_host.ParentGroup.FromPartID.ToString()); 4067 return new LSL_Key(UUID.Zero.ToString());
4068 return new LSL_Key(rezID.ToString());
3733 } 4069 }
3734 4070
3735 /// <summary> 4071 /// <summary>
@@ -3738,7 +4074,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3738 /// <returns></returns> 4074 /// <returns></returns>
3739 public void osSetContentType(LSL_Key id, string type) 4075 public void osSetContentType(LSL_Key id, string type)
3740 { 4076 {
3741 if (!CheckThreatLevel(ThreatLevel.High, "osSetContentType")) return; 4077 CheckThreatLevel(ThreatLevel.High, "osSetContentType");
3742 4078
3743 if (m_UrlModule != null) 4079 if (m_UrlModule != null)
3744 m_UrlModule.HttpContentType(new UUID(id),type); 4080 m_UrlModule.HttpContentType(new UUID(id),type);
@@ -3750,7 +4086,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3750 /// <returns>boolean indicating whether an error was shouted.</returns> 4086 /// <returns>boolean indicating whether an error was shouted.</returns>
3751 protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix) 4087 protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
3752 { 4088 {
3753 m_host.AddScriptLPS(1);
3754 bool fail = false; 4089 bool fail = false;
3755 if (m_item.PermsGranter != m_host.OwnerID) 4090 if (m_item.PermsGranter != m_host.OwnerID)
3756 { 4091 {
@@ -3800,39 +4135,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3800 4135
3801 public void osDropAttachment() 4136 public void osDropAttachment()
3802 { 4137 {
3803 if (!CheckThreatLevel(ThreatLevel.Low, "osDropAttachment")) return; 4138 CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
3804 m_host.AddScriptLPS(1);
3805 4139
3806 DropAttachment(true); 4140 DropAttachment(true);
3807 } 4141 }
3808 4142
3809 public void osForceDropAttachment() 4143 public void osForceDropAttachment()
3810 { 4144 {
3811 if (!CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment")) return; 4145 CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
3812 m_host.AddScriptLPS(1);
3813 4146
3814 DropAttachment(false); 4147 DropAttachment(false);
3815 } 4148 }
3816 4149
3817 public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) 4150 public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
3818 { 4151 {
3819 if (!CheckThreatLevel(ThreatLevel.Low, "osDropAttachmentAt")) return; 4152 CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
3820 m_host.AddScriptLPS(1);
3821 4153
3822 DropAttachmentAt(true, pos, rot); 4154 DropAttachmentAt(true, pos, rot);
3823 } 4155 }
3824 4156
3825 public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) 4157 public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
3826 { 4158 {
3827 if (!CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt")) return; 4159 CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
3828 m_host.AddScriptLPS(1);
3829 4160
3830 DropAttachmentAt(false, pos, rot); 4161 DropAttachmentAt(false, pos, rot);
3831 } 4162 }
3832 4163
3833 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) 4164 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
3834 { 4165 {
3835 m_host.AddScriptLPS(1);
3836 UUID keyID; 4166 UUID keyID;
3837 UUID.TryParse(ID, out keyID); 4167 UUID.TryParse(ID, out keyID);
3838 4168
@@ -3879,7 +4209,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3879 4209
3880 public LSL_Integer osRegexIsMatch(string input, string pattern) 4210 public LSL_Integer osRegexIsMatch(string input, string pattern)
3881 { 4211 {
3882 m_host.AddScriptLPS(1);
3883 try 4212 try
3884 { 4213 {
3885 return Regex.IsMatch(input, pattern) ? 1 : 0; 4214 return Regex.IsMatch(input, pattern) ? 1 : 0;
@@ -3890,5 +4219,376 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3890 return 0; 4219 return 0;
3891 } 4220 }
3892 } 4221 }
4222
4223 public LSL_String osRequestURL(LSL_List options)
4224 {
4225 CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
4226
4227 Hashtable opts = new Hashtable();
4228 for (int i = 0 ; i < options.Length ; i++)
4229 {
4230 object opt = options.Data[i];
4231 if (opt.ToString() == "allowXss")
4232 opts["allowXss"] = true;
4233 }
4234
4235 if (m_UrlModule != null)
4236 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4237 return UUID.Zero.ToString();
4238 }
4239
4240 public LSL_String osRequestSecureURL(LSL_List options)
4241 {
4242 CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
4243
4244 Hashtable opts = new Hashtable();
4245 for (int i = 0 ; i < options.Length ; i++)
4246 {
4247 object opt = options.Data[i];
4248 if (opt.ToString() == "allowXss")
4249 opts["allowXss"] = true;
4250 }
4251
4252 if (m_UrlModule != null)
4253 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4254 return UUID.Zero.ToString();
4255 }
4256
4257 public void osCollisionSound(string impact_sound, double impact_volume)
4258 {
4259 if(impact_sound == "")
4260 {
4261 m_host.CollisionSoundVolume = (float)impact_volume;
4262 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
4263 if(impact_volume == 0.0)
4264 m_host.CollisionSoundType = -1; // disable all sounds
4265 else if(impact_volume == 1.0f)
4266 m_host.CollisionSoundType = 0; // full return to default sounds
4267 else
4268 m_host.CollisionSoundType = 2; // default sounds with volume
4269 m_host.aggregateScriptEvents();
4270 return;
4271 }
4272 // TODO: Parameter check logic required.
4273 UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
4274 if(soundId != UUID.Zero)
4275 {
4276 m_host.CollisionSound = soundId;
4277 m_host.CollisionSoundVolume = (float)impact_volume;
4278 m_host.CollisionSoundType = 1;
4279 }
4280 else
4281 m_host.CollisionSoundType = -1;
4282
4283 m_host.aggregateScriptEvents();
4284 }
4285
4286 // still not very usefull, detector is lost on rez, restarts, etc
4287 public void osVolumeDetect(int detect)
4288 {
4289 CheckThreatLevel();
4290
4291 if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted || m_host.ParentGroup.IsAttachment)
4292 return;
4293
4294 m_host.ScriptSetVolumeDetect(detect != 0);
4295 }
4296
4297 /// <summary>
4298 /// Get inertial data
4299 /// </summary>
4300 /// <remarks>
4301 /// </remarks>
4302 /// <returns>
4303 /// a LSL list with contents:
4304 /// LSL_Float mass, the total mass of a linkset
4305 /// LSL_Vector CenterOfMass, center mass relative to root prim
4306 /// LSL_Vector Inertia, elements of diagonal of inertia Ixx,Iyy,Izz divided by total mass
4307 /// LSL_Vector aux, elements of upper triagle of inertia Ixy (= Iyx), Ixz (= Izx), Iyz(= Izy) divided by total mass
4308 /// </returns>
4309 public LSL_List osGetInertiaData()
4310 {
4311 LSL_List result = new LSL_List();
4312 float TotalMass;
4313 Vector3 CenterOfMass;
4314 Vector3 Inertia;
4315 Vector4 aux;
4316
4317 SceneObjectGroup sog = m_host.ParentGroup;
4318 if(sog== null || sog.IsDeleted)
4319 return result;
4320
4321 sog.GetInertiaData(out TotalMass, out CenterOfMass, out Inertia, out aux );
4322 if(TotalMass > 0)
4323 {
4324 float t = 1.0f/TotalMass;
4325 Inertia.X *= t;
4326 Inertia.Y *= t;
4327 Inertia.Z *= t;
4328
4329 aux.X *= t;
4330 aux.Y *= t;
4331 aux.Z *= t;
4332 }
4333
4334 result.Add(new LSL_Float(TotalMass));
4335 result.Add(new LSL_Vector(CenterOfMass.X, CenterOfMass.Y, CenterOfMass.Z));
4336 result.Add(new LSL_Vector(Inertia.X, Inertia.Y, Inertia.Z));
4337 result.Add(new LSL_Vector(aux.X, aux.Y, aux.Z));
4338 return result;
4339 }
4340
4341 /// <summary>
4342 /// set inertial data
4343 /// replaces the automatic calculation of mass, center of mass and inertia
4344 ///
4345 /// </summary>
4346 /// <param name="Mass">total mass of linkset</param>
4347 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4348 /// <param name="principalInertiaScaled">moment of inertia relative to principal axis and center of mass,Ixx, Iyy, Izz divided by mass</param>
4349 /// <param name="lslrot">rotation of the inertia, relative to local axis</param>
4350 /// <remarks>
4351 /// the inertia argument is is inertia divided by mass, so corresponds only to the geometric distribution of mass and both can be changed independently.
4352 /// </remarks>
4353
4354 public void osSetInertia(LSL_Float mass, LSL_Vector centerOfMass, LSL_Vector principalInertiaScaled, LSL_Rotation lslrot)
4355 {
4356 SceneObjectGroup sog = m_host.ParentGroup;
4357 if(sog== null || sog.IsDeleted)
4358 return;
4359
4360 if(mass < 0 || principalInertiaScaled.x < 0 || principalInertiaScaled.y < 0 || principalInertiaScaled.z < 0)
4361 return;
4362
4363 // need more checks
4364
4365 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4366 Vector3 Inertia;
4367 float m = (float)mass;
4368
4369 Inertia.X = m * (float)principalInertiaScaled.x;
4370 Inertia.Y = m * (float)principalInertiaScaled.y;
4371 Inertia.Z = m * (float)principalInertiaScaled.z;
4372
4373 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.y, (float)lslrot.s);
4374 rot.Normalize();
4375
4376 sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
4377 }
4378
4379 /// <summary>
4380 /// set inertial data as a sphere
4381 /// replaces the automatic calculation of mass, center of mass and inertia
4382 ///
4383 /// </summary>
4384 /// <param name="Mass">total mass of linkset</param>
4385 /// <param name="boxsize">size of the Box</param>
4386 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4387 /// <param name="lslrot">rotation of the box, and so inertia, relative to local axis</param>
4388 /// <remarks>
4389 /// </remarks>
4390 public void osSetInertiaAsBox(LSL_Float mass, LSL_Vector boxSize, LSL_Vector centerOfMass, LSL_Rotation lslrot)
4391 {
4392 SceneObjectGroup sog = m_host.ParentGroup;
4393 if(sog== null || sog.IsDeleted)
4394 return;
4395
4396 if(mass < 0)
4397 return;
4398
4399 // need more checks
4400
4401 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4402 Vector3 Inertia;
4403 float lx = (float)boxSize.x;
4404 float ly = (float)boxSize.y;
4405 float lz = (float)boxSize.z;
4406 float m = (float)mass;
4407 float t = m / 12.0f;
4408
4409 Inertia.X = t * (ly*ly + lz*lz);
4410 Inertia.Y = t * (lx*lx + lz*lz);
4411 Inertia.Z = t * (lx*lx + ly*ly);
4412
4413 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
4414 rot.Normalize();
4415
4416 sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
4417 }
4418
4419 /// <summary>
4420 /// set inertial data as a sphere
4421 /// replaces the automatic calculation of mass, center of mass and inertia
4422 ///
4423 /// </summary>
4424 /// <param name="Mass">total mass of linkset</param>
4425 /// <param name="radius">radius of the sphere</param>
4426 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4427 /// <remarks>
4428 /// </remarks>
4429 public void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, LSL_Vector centerOfMass)
4430 {
4431 SceneObjectGroup sog = m_host.ParentGroup;
4432 if(sog== null || sog.IsDeleted)
4433 return;
4434
4435 if(mass < 0)
4436 return;
4437
4438 // need more checks
4439
4440 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4441 Vector3 Inertia;
4442 float r = (float)radius;
4443 float m = (float)mass;
4444 float t = 0.4f * m * r * r;
4445
4446 Inertia.X = t;
4447 Inertia.Y = t;
4448 Inertia.Z = t;
4449
4450 sog.SetInertiaData(m, CenterOfMass, Inertia, new Vector4(0f, 0f, 0f,1.0f));
4451 }
4452
4453 /// <summary>
4454 /// set inertial data as a cylinder
4455 /// replaces the automatic calculation of mass, center of mass and inertia
4456 ///
4457 /// </summary>
4458 /// <param name="Mass">total mass of linkset</param>
4459 /// <param name="radius">radius of the cylinder</param>
4460 /// <param name="lenght">lenght of the cylinder</param>
4461 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4462 /// <param name="lslrot">rotation of the cylinder, and so inertia, relative to local axis</param>
4463 /// <remarks>
4464 /// cylinder axis aligned with Z axis. For other orientations provide the rotation.
4465 /// </remarks>
4466 public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, LSL_Vector centerOfMass, LSL_Rotation lslrot)
4467 {
4468 SceneObjectGroup sog = m_host.ParentGroup;
4469 if(sog== null || sog.IsDeleted)
4470 return;
4471
4472 if(mass < 0)
4473 return;
4474
4475 // need more checks
4476
4477 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4478 Vector3 Inertia;
4479 float m = (float)mass;
4480 float r = (float)radius;
4481 r *= r;
4482 Inertia.Z = 0.5f * m * r;
4483 float t = (float)lenght;
4484 t *= t;
4485 t += 3.0f * r;
4486 t *= 8.333333e-2f * m;
4487
4488 Inertia.X = t;
4489 Inertia.Y = t;
4490
4491 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
4492 rot.Normalize();
4493
4494 sog.SetInertiaData(m, CenterOfMass, Inertia, rot);
4495 }
4496
4497 /// <summary>
4498 /// removes inertial data manual override
4499 /// default automatic calculation is used again
4500 ///
4501 /// </summary>
4502 public void osClearInertia()
4503 {
4504 SceneObjectGroup sog = m_host.ParentGroup;
4505 if(sog== null || sog.IsDeleted)
4506 return;
4507
4508 sog.SetInertiaData(-1, Vector3.Zero, Vector3.Zero, Vector4.Zero );
4509 }
4510
4511 private bool checkAllowObjectTPbyLandOwner(Vector3 pos)
4512 {
4513 ILandObject land = World.LandChannel.GetLandObject(pos);
4514 if(land == null)
4515 return true;
4516
4517 LandData landdata = land.LandData;
4518 if(landdata == null)
4519 return true;
4520
4521 UUID hostOwner = m_host.OwnerID;
4522 if(landdata.OwnerID == hostOwner)
4523 return true;
4524
4525 EstateSettings es = World.RegionInfo.EstateSettings;
4526 if(es != null && es.IsEstateManagerOrOwner(hostOwner))
4527 return true;
4528
4529 if(!landdata.IsGroupOwned)
4530 return false;
4531
4532 UUID landGroup = landdata.GroupID;
4533 if(landGroup == UUID.Zero)
4534 return false;
4535
4536 if(landGroup == m_host.GroupID)
4537 return true;
4538
4539 return false;
4540 }
4541
4542 /// <summary>
4543 /// teleports a object (full linkset)
4544 /// </summary>
4545 /// <param name="objectUUID">the id of the linkset to teleport</param>
4546 /// <param name="targetPos">target position</param>
4547 /// <param name="rotation"> a rotation to apply</param>
4548 /// <param name="flags">several flags/param>
4549 /// <remarks>
4550 /// only does teleport local to region
4551 /// if object has scripts, owner must have rights to run scripts on target location
4552 /// object owner must have rights to enter ojects on target location
4553 /// target location parcel must have enought free prims capacity for the linkset prims
4554 /// all avatars siting on the object must have access to target location
4555 /// has a cool down time. retries before expire reset it
4556 /// fail conditions are silent ignored
4557 /// </remarks>
4558 public LSL_Integer osTeleportObject(LSL_Key objectUUID, LSL_Vector targetPos, LSL_Rotation rotation, LSL_Integer flags)
4559 {
4560 CheckThreatLevel(ThreatLevel.Severe, "osTeleportObject");
4561
4562 UUID objUUID;
4563 if (!UUID.TryParse(objectUUID, out objUUID))
4564 {
4565 OSSLShoutError("osTeleportObject() invalid object Key");
4566 return -1;
4567 }
4568
4569 SceneObjectGroup sog = World.GetSceneObjectGroup(objUUID);
4570 if(sog== null || sog.IsDeleted || sog.inTransit)
4571 return -1;
4572
4573 if(sog.OwnerID != m_host.OwnerID)
4574 {
4575 Vector3 pos = sog.AbsolutePosition;
4576 if(!checkAllowObjectTPbyLandOwner(pos))
4577 return -1;
4578 }
4579
4580 UUID myid = m_host.ParentGroup.UUID;
4581
4582 return sog.TeleportObject(myid, targetPos, rotation, flags);
4583 // a delay here may break vehicles
4584 }
4585
4586 public LSL_Integer osGetLinkNumber(LSL_String name)
4587 {
4588 SceneObjectGroup sog = m_host.ParentGroup;
4589 if(sog== null || sog.IsDeleted)
4590 return -1;
4591 return sog.GetLinkNumber(name);
4592 }
3893 } 4593 }
3894} 4594}