aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs2053
1 files changed, 1481 insertions, 572 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..6e28fe0 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,10 @@ 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 float m_ScriptDelayFactor = 1.0f;
143 internal float m_ScriptDistanceFactor = 1.0f;
144 internal bool m_debuggerSafe = false;
141 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 145 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
142
143 protected IUrlModule m_UrlModule = null; 146 protected IUrlModule m_UrlModule = null;
144 147
145 public void Initialize( 148 public void Initialize(
@@ -148,6 +151,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
148 m_ScriptEngine = scriptEngine; 151 m_ScriptEngine = scriptEngine;
149 m_host = host; 152 m_host = host;
150 m_item = item; 153 m_item = item;
154 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
151 155
152 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 156 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
153 157
@@ -157,6 +161,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
157 // m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED"); 161 // m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED");
158 } 162 }
159 163
164 m_ScriptDelayFactor =
165 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
166 m_ScriptDistanceFactor =
167 m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
168
160 string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow"); 169 string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow");
161 switch (risk) 170 switch (risk)
162 { 171 {
@@ -187,7 +196,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
187 default: 196 default:
188 break; 197 break;
189 } 198 }
190 } 199 }
191 200
192 public override Object InitializeLifetimeService() 201 public override Object InitializeLifetimeService()
193 { 202 {
@@ -209,7 +218,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
209 218
210 internal void OSSLError(string msg) 219 internal void OSSLError(string msg)
211 { 220 {
212 OSSLShoutError("OSSL Runtime Error: " + msg); 221 if (m_debuggerSafe)
222 {
223 OSSLShoutError(msg);
224 }
225 else
226 {
227 throw new ScriptException("OSSL Runtime Error: " + msg);
228 }
213 } 229 }
214 230
215 /// <summary> 231 /// <summary>
@@ -244,22 +260,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
244 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); 260 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
245 } 261 }
246 262
247 // Returns of the function is allowed. Throws a script exception if not allowed. 263 // Returns if OSSL is enabled. Throws a script exception if OSSL is not allowed..
248 public bool CheckThreatLevel(ThreatLevel level, string function) 264 // for safe funtions always active
265 public void CheckThreatLevel()
249 { 266 {
267 m_host.AddScriptLPS(1);
250 if (!m_OSFunctionsEnabled) 268 if (!m_OSFunctionsEnabled)
251 { 269 OSSLError(String.Format("{0} permission denied. All OS functions are disabled.")); // throws
252 OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); 270 }
253 return false; 271
254 } 272 // Returns if the function is allowed. Throws a script exception if not allowed.
273 public void CheckThreatLevel(ThreatLevel level, string function)
274 {
275 m_host.AddScriptLPS(1);
276 if (!m_OSFunctionsEnabled)
277 OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
255 278
256 string reasonWhyNot = CheckThreatLevelTest(level, function); 279 string reasonWhyNot = CheckThreatLevelTest(level, function);
257 if (!String.IsNullOrEmpty(reasonWhyNot)) 280 if (!String.IsNullOrEmpty(reasonWhyNot))
258 { 281 {
259 OSSLError(reasonWhyNot); 282 OSSLError(reasonWhyNot);
260 return false;
261 } 283 }
262 return true;
263 } 284 }
264 285
265 // Check to see if function is allowed. Returns an empty string if function permitted 286 // Check to see if function is allowed. Returns an empty string if function permitted
@@ -299,7 +320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
299 foreach (string id in ids) 320 foreach (string id in ids)
300 { 321 {
301 string current = id.Trim(); 322 string current = id.Trim();
302 if (current.ToUpper() == "PARCEL_GROUP_MEMBER" || current.ToUpper() == "PARCEL_OWNER" || current.ToUpper() == "ESTATE_MANAGER" || current.ToUpper() == "ESTATE_OWNER") 323 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 { 324 {
304 if (!perms.AllowedOwnerClasses.Contains(current)) 325 if (!perms.AllowedOwnerClasses.Contains(current))
305 perms.AllowedOwnerClasses.Add(current.ToUpper()); 326 perms.AllowedOwnerClasses.Add(current.ToUpper());
@@ -404,6 +425,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
404 } 425 }
405 } 426 }
406 427
428
429 //Only grid gods may use the function
430 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("GRID_GOD"))
431 {
432 if (World.Permissions.IsGridGod(ownerID))
433 {
434 return String.Empty;
435 }
436 }
437
438 //Any god may use the function
439 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("GOD"))
440 {
441 if (World.Permissions.IsAdministrator(ownerID))
442 {
443 return String.Empty;
444 }
445 }
446
447 //Only active gods may use the function
448 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ACTIVE_GOD"))
449 {
450 ScenePresence sp = World.GetScenePresence(ownerID);
451 if (sp != null && !sp.IsDeleted && sp.IsGod)
452 {
453 return String.Empty;
454 }
455 }
456
407 if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID)) 457 if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
408 return( 458 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.", 459 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 +475,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
425 OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement)); 475 OSSLShoutError(string.Format("Use of function {0} is deprecated. Use {1} instead.", function, replacement));
426 } 476 }
427 477
478 protected void ScriptSleep(int delay)
479 {
480 delay = (int)((float)delay * m_ScriptDelayFactor);
481 if (delay == 0)
482 return;
483 System.Threading.Thread.Sleep(delay);
484 }
485
428 public LSL_Integer osSetTerrainHeight(int x, int y, double val) 486 public LSL_Integer osSetTerrainHeight(int x, int y, double val)
429 { 487 {
430 if (!CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight")) return 0; 488 CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
431 489
432 return SetTerrainHeight(x, y, val); 490 return SetTerrainHeight(x, y, val);
433 } 491 }
434 492
435 public LSL_Integer osTerrainSetHeight(int x, int y, double val) 493 public LSL_Integer osTerrainSetHeight(int x, int y, double val)
436 { 494 {
437 if (!CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight")) return 0; 495 CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
438 OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); 496 OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
439 497
440 return SetTerrainHeight(x, y, val); 498 return SetTerrainHeight(x, y, val);
@@ -442,8 +500,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
442 500
443 private LSL_Integer SetTerrainHeight(int x, int y, double val) 501 private LSL_Integer SetTerrainHeight(int x, int y, double val)
444 { 502 {
445 m_host.AddScriptLPS(1);
446
447 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0) 503 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
448 OSSLError("osSetTerrainHeight: Coordinate out of bounds"); 504 OSSLError("osSetTerrainHeight: Coordinate out of bounds");
449 505
@@ -460,18 +516,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
460 516
461 public LSL_Float osGetTerrainHeight(int x, int y) 517 public LSL_Float osGetTerrainHeight(int x, int y)
462 { 518 {
519 CheckThreatLevel();
463 return GetTerrainHeight(x, y); 520 return GetTerrainHeight(x, y);
464 } 521 }
465 522
466 public LSL_Float osTerrainGetHeight(int x, int y) 523 public LSL_Float osTerrainGetHeight(int x, int y)
467 { 524 {
525 CheckThreatLevel();
468 OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight"); 526 OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
469 return GetTerrainHeight(x, y); 527 return GetTerrainHeight(x, y);
470 } 528 }
471 529
472 private LSL_Float GetTerrainHeight(int x, int y) 530 private LSL_Float GetTerrainHeight(int x, int y)
473 { 531 {
474 m_host.AddScriptLPS(1);
475 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0) 532 if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0)
476 OSSLError("osGetTerrainHeight: Coordinate out of bounds"); 533 OSSLError("osGetTerrainHeight: Coordinate out of bounds");
477 534
@@ -480,8 +537,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
480 537
481 public void osTerrainFlush() 538 public void osTerrainFlush()
482 { 539 {
483 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush")) return; 540 CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
484 m_host.AddScriptLPS(1);
485 541
486 ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>(); 542 ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
487 if (terrainModule != null) terrainModule.TaintTerrain(); 543 if (terrainModule != null) terrainModule.TaintTerrain();
@@ -495,31 +551,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
495 // The underlying functionality is fixed, since the security 551 // The underlying functionality is fixed, since the security
496 // as such is sound 552 // as such is sound
497 // 553 //
498 if (!CheckThreatLevel(ThreatLevel.High, "osRegionRestart")) return 0; 554 CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
499 555
500 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>(); 556 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
501 m_host.AddScriptLPS(1);
502 if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null)) 557 if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
503 { 558 {
504 if (seconds < 15) 559 if (seconds < 15)
505 { 560 {
506 restartModule.AbortRestart("Restart aborted"); 561 restartModule.AbortRestart("Region restart has been aborted\n");
507 return 1; 562 return 1;
508 } 563 }
509 564
510 List<int> times = new List<int>(); 565 RegionRestart(seconds, String.Empty);
511 while (seconds > 0) 566 return 1;
567 }
568 else
569 {
570 return 0;
571 }
572 }
573
574 public int osRegionRestart(double seconds, string msg)
575 {
576 CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
577
578 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
579 if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false) && (restartModule != null))
580 {
581 if (seconds < 15)
512 { 582 {
513 times.Add((int)seconds); 583 restartModule.AbortRestart("Region restart has been aborted\n");
514 if (seconds > 300) 584 return 1;
515 seconds -= 120;
516 else if (seconds > 30)
517 seconds -= 30;
518 else
519 seconds -= 15;
520 } 585 }
521 586
522 restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true); 587 RegionRestart(seconds, msg);
523 return 1; 588 return 1;
524 } 589 }
525 else 590 else
@@ -528,15 +593,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
528 } 593 }
529 } 594 }
530 595
596 private void RegionRestart(double seconds, string msg)
597 {
598 IRestartModule restartModule = World.RequestModuleInterface<IRestartModule>();
599
600 List<int> times = new List<int>();
601 while (seconds > 0)
602 {
603 times.Add((int)seconds);
604 if (seconds > 300)
605 seconds -= 120;
606 else if (seconds > 120)
607 seconds -= 60;
608 else if (seconds > 60)
609 seconds -= 30;
610 else
611 seconds -= 15;
612 }
613
614 if (msg == String.Empty)
615 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);
616
617 else
618 restartModule.ScheduleRestart(UUID.Zero, msg + "\n\nTime remaining: {0}.\n", times.ToArray(), true);
619 }
620
531 public void osRegionNotice(string msg) 621 public void osRegionNotice(string msg)
532 { 622 {
533 // This implementation provides absolutely no security 623 // This implementation provides absolutely no security
534 // It's high griefing potential makes this classification 624 // It's high griefing potential makes this classification
535 // necessary 625 // necessary
536 // 626 //
537 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice")) return; 627 CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
538
539 m_host.AddScriptLPS(1);
540 628
541 IDialogModule dm = World.RequestModuleInterface<IDialogModule>(); 629 IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
542 630
@@ -549,9 +637,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
549 // This function has no security. It can be used to destroy 637 // This function has no security. It can be used to destroy
550 // arbitrary builds the user would normally have no rights to 638 // arbitrary builds the user would normally have no rights to
551 // 639 //
552 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot")) return; 640 CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
553 641
554 m_host.AddScriptLPS(1);
555 if (World.Entities.ContainsKey(target)) 642 if (World.Entities.ContainsKey(target))
556 { 643 {
557 EntityBase entity; 644 EntityBase entity;
@@ -572,13 +659,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
572 public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams, 659 public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
573 int timer) 660 int timer)
574 { 661 {
575 m_host.AddScriptLPS(1); 662 // This may be upgraded depending on the griefing or DOS
663 // potential, or guarded with a delay
664 //
665 CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
666
576 if (dynamicID == String.Empty) 667 if (dynamicID == String.Empty)
577 { 668 {
578 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 669 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
579 UUID createdTexture = 670 UUID createdTexture =
580 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url, 671 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
581 extraParams, timer); 672 extraParams);
582 return createdTexture.ToString(); 673 return createdTexture.ToString();
583 } 674 }
584 else 675 else
@@ -592,13 +683,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
592 public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams, 683 public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
593 int timer, int alpha) 684 int timer, int alpha)
594 { 685 {
595 m_host.AddScriptLPS(1); 686 CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
687
596 if (dynamicID == String.Empty) 688 if (dynamicID == String.Empty)
597 { 689 {
598 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 690 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
599 UUID createdTexture = 691 UUID createdTexture =
600 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url, 692 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
601 extraParams, timer, true, (byte) alpha); 693 extraParams, true, (byte) alpha);
602 return createdTexture.ToString(); 694 return createdTexture.ToString();
603 } 695 }
604 else 696 else
@@ -612,13 +704,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
612 public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams, 704 public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
613 bool blend, int disp, int timer, int alpha, int face) 705 bool blend, int disp, int timer, int alpha, int face)
614 { 706 {
615 m_host.AddScriptLPS(1); 707 CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
708
616 if (dynamicID == String.Empty) 709 if (dynamicID == String.Empty)
617 { 710 {
618 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 711 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
619 UUID createdTexture = 712 UUID createdTexture =
620 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url, 713 textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
621 extraParams, timer, blend, disp, (byte) alpha, face); 714 extraParams, blend, disp, (byte) alpha, face);
622 return createdTexture.ToString(); 715 return createdTexture.ToString();
623 } 716 }
624 else 717 else
@@ -632,7 +725,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
632 public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams, 725 public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
633 int timer) 726 int timer)
634 { 727 {
635 m_host.AddScriptLPS(1); 728 return osSetDynamicTextureDataFace(dynamicID, contentType, data, extraParams, timer, -1);
729 }
730
731 public string osSetDynamicTextureDataFace(string dynamicID, string contentType, string data, string extraParams,
732 int timer, int face)
733 {
734 CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
735
636 if (dynamicID == String.Empty) 736 if (dynamicID == String.Empty)
637 { 737 {
638 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 738 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -644,7 +744,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
644 } 744 }
645 UUID createdTexture = 745 UUID createdTexture =
646 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data, 746 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
647 extraParams, timer); 747 extraParams, false, 3, 255, face);
748
648 return createdTexture.ToString(); 749 return createdTexture.ToString();
649 } 750 }
650 } 751 }
@@ -659,7 +760,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
659 public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams, 760 public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
660 int timer, int alpha) 761 int timer, int alpha)
661 { 762 {
662 m_host.AddScriptLPS(1); 763 CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
764
663 if (dynamicID == String.Empty) 765 if (dynamicID == String.Empty)
664 { 766 {
665 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 767 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -671,7 +773,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
671 } 773 }
672 UUID createdTexture = 774 UUID createdTexture =
673 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data, 775 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
674 extraParams, timer, true, (byte) alpha); 776 extraParams, true, (byte) alpha);
675 return createdTexture.ToString(); 777 return createdTexture.ToString();
676 } 778 }
677 } 779 }
@@ -686,7 +788,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
686 public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams, 788 public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
687 bool blend, int disp, int timer, int alpha, int face) 789 bool blend, int disp, int timer, int alpha, int face)
688 { 790 {
689 m_host.AddScriptLPS(1); 791 CheckThreatLevel(ThreatLevel.VeryLow , "osSetDynamicTextureDataBlendFace");
792
690 if (dynamicID == String.Empty) 793 if (dynamicID == String.Empty)
691 { 794 {
692 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 795 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -698,7 +801,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
698 } 801 }
699 UUID createdTexture = 802 UUID createdTexture =
700 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data, 803 textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
701 extraParams, timer, blend, disp, (byte) alpha, face); 804 extraParams, blend, disp, (byte) alpha, face);
702 return createdTexture.ToString(); 805 return createdTexture.ToString();
703 } 806 }
704 } 807 }
@@ -712,9 +815,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
712 815
713 public bool osConsoleCommand(string command) 816 public bool osConsoleCommand(string command)
714 { 817 {
715 if (!CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand")) return false; 818 CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
716
717 m_host.AddScriptLPS(1);
718 819
719 // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions 820 // 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)) 821 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
@@ -728,123 +829,183 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
728 829
729 public void osSetPrimFloatOnWater(int floatYN) 830 public void osSetPrimFloatOnWater(int floatYN)
730 { 831 {
731 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater")) return; 832 CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
732
733 m_host.AddScriptLPS(1);
734 833
735 m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN); 834 m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
736 } 835 }
737 836
837 private bool checkAllowAgentTPbyLandOwner(UUID agentId, Vector3 pos)
838 {
839 UUID hostOwner = m_host.OwnerID;
840
841 if(hostOwner == agentId)
842 return true;
843
844 if (m_item.PermsGranter == agentId)
845 {
846 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
847 return true;
848 }
849
850 ILandObject land = World.LandChannel.GetLandObject(pos);
851 if(land == null)
852 return true;
853
854 LandData landdata = land.LandData;
855 if(landdata == null)
856 return true;
857
858 if(landdata.OwnerID == hostOwner)
859 return true;
860
861 EstateSettings es = World.RegionInfo.EstateSettings;
862 if(es != null && es.IsEstateManagerOrOwner(hostOwner))
863 return true;
864
865 if(!landdata.IsGroupOwned)
866 return false;
867
868 UUID landGroup = landdata.GroupID;
869 if(landGroup == UUID.Zero)
870 return false;
871
872 if(landGroup == m_host.GroupID)
873 return true;
874
875 return false;
876 }
877
738 // Teleport functions 878 // Teleport functions
739 public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 879 public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
740 { 880 {
741 // High because there is no security check. High griefer potential 881 // High because there is no security check. High griefer potential
742 // 882 //
743 if (!CheckThreatLevel(ThreatLevel.High, "osTeleportAgent")) return; 883 CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
744 884
745 TeleportAgent(agent, regionName, position, lookat, false); 885 TeleportAgent(agent, regionName, position, lookat);
746 } 886 }
747 887
748 private void TeleportAgent(string agent, string regionName, 888 private void TeleportAgent(string agent, string regionName,
749 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) 889 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
750 { 890 {
751 m_host.AddScriptLPS(1); 891 if(String.IsNullOrEmpty(regionName))
752 UUID agentId = new UUID(); 892 regionName = World.RegionInfo.RegionName;
893
894 UUID agentId;
753 if (UUID.TryParse(agent, out agentId)) 895 if (UUID.TryParse(agent, out agentId))
754 { 896 {
755 ScenePresence presence = World.GetScenePresence(agentId); 897 ScenePresence presence = World.GetScenePresence(agentId);
756 if (presence != null) 898 if (presence == null || presence.IsDeleted || presence.IsInTransit)
899 return;
900
901 Vector3 pos = presence.AbsolutePosition;
902 if(!checkAllowAgentTPbyLandOwner(agentId, pos))
757 { 903 {
758 // For osTeleportAgent, agent must be over owners land to avoid abuse 904 ScriptSleep(500);
759 // For osTeleportOwner, this restriction isn't necessary 905 return;
760 906 }
761 // commented out because its redundant and uneeded please remove eventually.
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 907
908 if(regionName == World.RegionInfo.RegionName)
909 {
910 // should be faster than going to threadpool
911 World.RequestTeleportLocation(presence.ControllingClient, regionName, position,
912 lookat, (uint)TPFlags.ViaLocation);
913 ScriptSleep(500);
914 }
915 else
916 {
917 // We will launch the teleport on a new thread so that when the script threads are terminated
918 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
919 Util.FireAndForget(
920 o => World.RequestTeleportLocation(
921 presence.ControllingClient, regionName, position,
922 lookat, (uint)TPFlags.ViaLocation),
923 null, "OSSL_Api.TeleportAgentByRegionCoords");
924 ScriptSleep(5000);
777 } 925 }
778 } 926 }
779 } 927 }
780 928
781 public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 929 public void osTeleportAgent(string agent, int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
782 { 930 {
783 // High because there is no security check. High griefer potential 931 // High because there is no security check. High griefer potential
784 // 932 //
785 if (!CheckThreatLevel(ThreatLevel.High, "osTeleportAgent")) return; 933 CheckThreatLevel(ThreatLevel.Severe, "osTeleportAgent");
786 934
787 TeleportAgent(agent, regionX, regionY, position, lookat, false); 935 TeleportAgent(agent, regionGridX, regionGridY, position, lookat);
788 } 936 }
789 937
790 private void TeleportAgent(string agent, int regionX, int regionY, 938 private void TeleportAgent(string agent, int regionGridX, int regionGridY,
791 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) 939 LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
792 { 940 {
793 // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize)); 941 ulong regionHandle = Util.RegionGridLocToHandle((uint)regionGridX, (uint)regionGridY);
794 ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY);
795 942
796 m_host.AddScriptLPS(1); 943 UUID agentId;
797 UUID agentId = new UUID();
798 if (UUID.TryParse(agent, out agentId)) 944 if (UUID.TryParse(agent, out agentId))
799 { 945 {
800 ScenePresence presence = World.GetScenePresence(agentId); 946 ScenePresence presence = World.GetScenePresence(agentId);
801 if (presence != null) 947 if (presence == null || presence.IsDeleted || presence.IsInTransit)
802 { 948 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 949
950 Vector3 pos = presence.AbsolutePosition;
951 if(!checkAllowAgentTPbyLandOwner(agentId, pos))
952 {
953 ScriptSleep(500);
954 return;
822 } 955 }
956
957 Util.FireAndForget(
958 o => World.RequestTeleportLocation(
959 presence.ControllingClient, regionHandle,
960 position, lookat, (uint)TPFlags.ViaLocation),
961 null, "OSSL_Api.TeleportAgentByRegionName");
962
963 ScriptSleep(5000);
823 } 964 }
824 } 965 }
825 966
826 public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 967 public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
827 { 968 {
828 // High because there is no security check. High griefer potential 969 UUID agentId;
829 // 970 if (UUID.TryParse(agent, out agentId))
830 if (!CheckThreatLevel(ThreatLevel.High, "osTeleportAgent")) return; 971 {
972 ScenePresence presence = World.GetScenePresence(agentId);
973 if (presence == null || presence.IsDeleted || presence.IsInTransit)
974 return;
831 975
832 osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat); 976 Vector3 pos = presence.AbsolutePosition;
977 if(!checkAllowAgentTPbyLandOwner(agentId, pos))
978 {
979 ScriptSleep(500);
980 return;
981 }
982
983 World.RequestTeleportLocation(presence.ControllingClient, World.RegionInfo.RegionName, position,
984 lookat, (uint)TPFlags.ViaLocation);
985 ScriptSleep(500);
986 }
833 } 987 }
834 988
835 public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 989 public void osTeleportOwner(string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
836 { 990 {
837 TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat, true); 991 // Threat level None because this is what can already be done with the World Map in the viewer
992 CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
993
994 TeleportAgent(m_host.OwnerID.ToString(), regionName, position, lookat);
838 } 995 }
839 996
840 public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 997 public void osTeleportOwner(int regionGridX, int regionGridY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
841 { 998 {
842 osTeleportOwner(World.RegionInfo.RegionName, position, lookat); 999 CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
1000
1001 TeleportAgent(m_host.OwnerID.ToString(), regionGridX, regionGridY, position, lookat);
843 } 1002 }
844 1003
845 public void osTeleportOwner(int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) 1004 public void osTeleportOwner(LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
846 { 1005 {
847 TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true); 1006 CheckThreatLevel(ThreatLevel.None, "osTeleportOwner");
1007
1008 osTeleportAgent(m_host.OwnerID.ToString(), position, lookat);
848 } 1009 }
849 1010
850 ///<summary> 1011 ///<summary>
@@ -856,9 +1017,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
856 /// <param name="avatar"></param> 1017 /// <param name="avatar"></param>
857 public void osForceOtherSit(string avatar) 1018 public void osForceOtherSit(string avatar)
858 { 1019 {
859 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit")) return; 1020 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
860
861 m_host.AddScriptLPS(1);
862 1021
863 ForceSit(avatar, m_host.UUID); 1022 ForceSit(avatar, m_host.UUID);
864 } 1023 }
@@ -871,9 +1030,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
871 /// <param name="target"></param> 1030 /// <param name="target"></param>
872 public void osForceOtherSit(string avatar, string target) 1031 public void osForceOtherSit(string avatar, string target)
873 { 1032 {
874 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit")) return; 1033 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit");
875
876 m_host.AddScriptLPS(1);
877 1034
878 UUID targetID = new UUID(target); 1035 UUID targetID = new UUID(target);
879 1036
@@ -882,7 +1039,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
882 1039
883 public void ForceSit(string avatar, UUID targetID) 1040 public void ForceSit(string avatar, UUID targetID)
884 { 1041 {
885 UUID agentID; 1042 UUID agentID;
886 1043
887 if (!UUID.TryParse(avatar, out agentID)) 1044 if (!UUID.TryParse(avatar, out agentID))
888 return; 1045 return;
@@ -900,21 +1057,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
900 part.SitTargetPosition); 1057 part.SitTargetPosition);
901 } 1058 }
902 1059
903 // Functions that get information from the agent itself. 1060 // Get a list of all the avatars/agents in the region
904 // 1061 public LSL_List osGetAgents()
905 // osGetAgentIP - this is used to determine the IP address of 1062 {
906 //the client. This is needed to help configure other in world 1063 // threat level is None as we could get this information with an
907 //resources based on the IP address of the clients connected. 1064 // in-world script as well, just not as efficient
908 //I think High is a good risk level for this, as it is an 1065 CheckThreatLevel(ThreatLevel.None, "osGetAgents");
909 //information leak. 1066
910 // Severe is even better coz privacy is important. 1067 LSL_List result = new LSL_List();
1068 World.ForEachRootScenePresence(delegate(ScenePresence sp)
1069 {
1070 result.Add(new LSL_String(sp.Name));
1071 });
1072 return result;
1073 }
1074
911 public string osGetAgentIP(string agent) 1075 public string osGetAgentIP(string agent)
912 { 1076 {
913 if (!CheckThreatLevel(ThreatLevel.Severe, "osGetAgentIP")) return ""; 1077 CheckThreatLevel(ThreatLevel.Severe, "osGetAgentIP");
1078 if(!(World.Permissions.IsGod(m_host.OwnerID))) // user god always needed
1079 return "";
914 1080
915 UUID avatarID = (UUID)agent; 1081 UUID avatarID = (UUID)agent;
916 1082
917 m_host.AddScriptLPS(1);
918 if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence) 1083 if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
919 { 1084 {
920 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 1085 ScenePresence target = (ScenePresence)World.Entities[avatarID];
@@ -925,61 +1090,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
925 return ""; 1090 return "";
926 } 1091 }
927 1092
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 1093 // Adam's super super custom animation functions
942 public void osAvatarPlayAnimation(string avatar, string animation) 1094 public void osAvatarPlayAnimation(string avatar, string animation)
943 { 1095 {
944 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation")) return; 1096 CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
945 1097
946 AvatarPlayAnimation(avatar, animation); 1098 AvatarPlayAnimation(avatar, animation);
947 } 1099 }
948 1100
949 private void AvatarPlayAnimation(string avatar, string animation) 1101 private void AvatarPlayAnimation(string avatar, string animation)
950 { 1102 {
951 UUID avatarID = (UUID)avatar; 1103 UUID avatarID;
1104 if(!UUID.TryParse(avatar, out avatarID))
1105 return;
952 1106
953 m_host.AddScriptLPS(1); 1107 ScenePresence target = World.GetScenePresence(avatarID);
954 if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence) 1108 if (target == null)
1109 return;
1110
1111 UUID animID = UUID.Zero;
1112 m_host.TaskInventory.LockItemsForRead(true);
1113 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
955 { 1114 {
956 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 1115 if (inv.Value.Type == (int)AssetType.Animation)
957 if (target != null)
958 { 1116 {
959 UUID animID=UUID.Zero; 1117 if (inv.Value.Name == animation)
960 lock (m_host.TaskInventory) 1118 {
961 { 1119 animID = inv.Value.AssetID;
962 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 1120 break;
963 { 1121 }
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 } 1122 }
977 } 1123 }
1124 m_host.TaskInventory.LockItemsForRead(false);
1125
1126 if (animID == UUID.Zero)
1127 target.Animator.AddAnimation(animation, m_host.UUID);
1128 else
1129 target.Animator.AddAnimation(animID, m_host.UUID);
978 } 1130 }
979 1131
980 public void osAvatarStopAnimation(string avatar, string animation) 1132 public void osAvatarStopAnimation(string avatar, string animation)
981 { 1133 {
982 if (!CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation")) return; 1134 CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
983 1135
984 AvatarStopAnimation(avatar, animation); 1136 AvatarStopAnimation(avatar, animation);
985 } 1137 }
@@ -988,8 +1140,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
988 { 1140 {
989 UUID avatarID = (UUID)avatar; 1141 UUID avatarID = (UUID)avatar;
990 1142
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 1143 // 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 1144 // 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 1145 // these functions call that common code. However, this does mean navigating the brain-dead requirement
@@ -1010,6 +1160,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1010 animID = UUID.Zero; 1160 animID = UUID.Zero;
1011 } 1161 }
1012 1162
1163
1013 if (animID == UUID.Zero) 1164 if (animID == UUID.Zero)
1014 target.Animator.RemoveAnimation(animation); 1165 target.Animator.RemoveAnimation(animation);
1015 else 1166 else
@@ -1019,58 +1170,106 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1019 } 1170 }
1020 1171
1021 //Texture draw functions 1172 //Texture draw functions
1173
1174 public string osDrawResetTransform(string drawList)
1175 {
1176 CheckThreatLevel();
1177
1178 drawList += "ResetTransf;";
1179 return drawList;
1180 }
1181
1182 public string osDrawRotationTransform(string drawList, LSL_Float x)
1183 {
1184 CheckThreatLevel();
1185
1186 drawList += "RotTransf " + x + ";";
1187 return drawList;
1188 }
1189
1190 public string osDrawScaleTransform(string drawList, LSL_Float x, LSL_Float y)
1191 {
1192 CheckThreatLevel();
1193
1194 drawList += "ScaleTransf " + x + "," + y + ";";
1195 return drawList;
1196 }
1197
1198 public string osDrawTranslationTransform(string drawList, LSL_Float x, LSL_Float y)
1199 {
1200 CheckThreatLevel();
1201
1202 drawList += "TransTransf " + x + "," + y + ";";
1203 return drawList;
1204 }
1205
1022 public string osMovePen(string drawList, int x, int y) 1206 public string osMovePen(string drawList, int x, int y)
1023 { 1207 {
1024 m_host.AddScriptLPS(1); 1208 CheckThreatLevel();
1209
1025 drawList += "MoveTo " + x + "," + y + ";"; 1210 drawList += "MoveTo " + x + "," + y + ";";
1026 return drawList; 1211 return drawList;
1027 } 1212 }
1028 1213
1029 public string osDrawLine(string drawList, int startX, int startY, int endX, int endY) 1214 public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
1030 { 1215 {
1031 m_host.AddScriptLPS(1); 1216 CheckThreatLevel();
1217
1032 drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; "; 1218 drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
1033 return drawList; 1219 return drawList;
1034 } 1220 }
1035 1221
1036 public string osDrawLine(string drawList, int endX, int endY) 1222 public string osDrawLine(string drawList, int endX, int endY)
1037 { 1223 {
1038 m_host.AddScriptLPS(1); 1224 CheckThreatLevel();
1225
1039 drawList += "LineTo " + endX + "," + endY + "; "; 1226 drawList += "LineTo " + endX + "," + endY + "; ";
1040 return drawList; 1227 return drawList;
1041 } 1228 }
1042 1229
1043 public string osDrawText(string drawList, string text) 1230 public string osDrawText(string drawList, string text)
1044 { 1231 {
1045 m_host.AddScriptLPS(1); 1232 CheckThreatLevel(ThreatLevel.None, "osDrawText");
1233
1046 drawList += "Text " + text + "; "; 1234 drawList += "Text " + text + "; ";
1047 return drawList; 1235 return drawList;
1048 } 1236 }
1049 1237
1050 public string osDrawEllipse(string drawList, int width, int height) 1238 public string osDrawEllipse(string drawList, int width, int height)
1051 { 1239 {
1052 m_host.AddScriptLPS(1); 1240 CheckThreatLevel();
1241
1053 drawList += "Ellipse " + width + "," + height + "; "; 1242 drawList += "Ellipse " + width + "," + height + "; ";
1054 return drawList; 1243 return drawList;
1055 } 1244 }
1056 1245
1246 public string osDrawFilledEllipse(string drawList, int width, int height)
1247 {
1248 CheckThreatLevel();
1249
1250 drawList += "FillEllipse " + width + "," + height + "; ";
1251 return drawList;
1252 }
1253
1057 public string osDrawRectangle(string drawList, int width, int height) 1254 public string osDrawRectangle(string drawList, int width, int height)
1058 { 1255 {
1059 m_host.AddScriptLPS(1); 1256 CheckThreatLevel();
1257
1060 drawList += "Rectangle " + width + "," + height + "; "; 1258 drawList += "Rectangle " + width + "," + height + "; ";
1061 return drawList; 1259 return drawList;
1062 } 1260 }
1063 1261
1064 public string osDrawFilledRectangle(string drawList, int width, int height) 1262 public string osDrawFilledRectangle(string drawList, int width, int height)
1065 { 1263 {
1066 m_host.AddScriptLPS(1); 1264 CheckThreatLevel();
1265
1067 drawList += "FillRectangle " + width + "," + height + "; "; 1266 drawList += "FillRectangle " + width + "," + height + "; ";
1068 return drawList; 1267 return drawList;
1069 } 1268 }
1070 1269
1071 public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y) 1270 public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
1072 { 1271 {
1073 m_host.AddScriptLPS(1); 1272 CheckThreatLevel();
1074 1273
1075 if (x.Length != y.Length || x.Length < 3) 1274 if (x.Length != y.Length || x.Length < 3)
1076 { 1275 {
@@ -1087,7 +1286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1087 1286
1088 public string osDrawPolygon(string drawList, LSL_List x, LSL_List y) 1287 public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
1089 { 1288 {
1090 m_host.AddScriptLPS(1); 1289 CheckThreatLevel();
1091 1290
1092 if (x.Length != y.Length || x.Length < 3) 1291 if (x.Length != y.Length || x.Length < 3)
1093 { 1292 {
@@ -1104,28 +1303,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1104 1303
1105 public string osSetFontSize(string drawList, int fontSize) 1304 public string osSetFontSize(string drawList, int fontSize)
1106 { 1305 {
1107 m_host.AddScriptLPS(1); 1306 CheckThreatLevel();
1307
1108 drawList += "FontSize "+ fontSize +"; "; 1308 drawList += "FontSize "+ fontSize +"; ";
1109 return drawList; 1309 return drawList;
1110 } 1310 }
1111 1311
1112 public string osSetFontName(string drawList, string fontName) 1312 public string osSetFontName(string drawList, string fontName)
1113 { 1313 {
1114 m_host.AddScriptLPS(1); 1314 CheckThreatLevel();
1315
1115 drawList += "FontName "+ fontName +"; "; 1316 drawList += "FontName "+ fontName +"; ";
1116 return drawList; 1317 return drawList;
1117 } 1318 }
1118 1319
1119 public string osSetPenSize(string drawList, int penSize) 1320 public string osSetPenSize(string drawList, int penSize)
1120 { 1321 {
1121 m_host.AddScriptLPS(1); 1322 CheckThreatLevel();
1323
1122 drawList += "PenSize " + penSize + "; "; 1324 drawList += "PenSize " + penSize + "; ";
1123 return drawList; 1325 return drawList;
1124 } 1326 }
1125 1327
1126 public string osSetPenColor(string drawList, string color) 1328 public string osSetPenColor(string drawList, string color)
1127 { 1329 {
1128 m_host.AddScriptLPS(1); 1330 CheckThreatLevel();
1331
1129 drawList += "PenColor " + color + "; "; 1332 drawList += "PenColor " + color + "; ";
1130 return drawList; 1333 return drawList;
1131 } 1334 }
@@ -1133,30 +1336,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1133 // Deprecated 1336 // Deprecated
1134 public string osSetPenColour(string drawList, string colour) 1337 public string osSetPenColour(string drawList, string colour)
1135 { 1338 {
1339 CheckThreatLevel();
1136 OSSLDeprecated("osSetPenColour", "osSetPenColor"); 1340 OSSLDeprecated("osSetPenColour", "osSetPenColor");
1137 1341
1138 m_host.AddScriptLPS(1);
1139 drawList += "PenColour " + colour + "; "; 1342 drawList += "PenColour " + colour + "; ";
1140 return drawList; 1343 return drawList;
1141 } 1344 }
1142 1345
1143 public string osSetPenCap(string drawList, string direction, string type) 1346 public string osSetPenCap(string drawList, string direction, string type)
1144 { 1347 {
1145 m_host.AddScriptLPS(1); 1348 CheckThreatLevel();
1349
1146 drawList += "PenCap " + direction + "," + type + "; "; 1350 drawList += "PenCap " + direction + "," + type + "; ";
1147 return drawList; 1351 return drawList;
1148 } 1352 }
1149 1353
1150 public string osDrawImage(string drawList, int width, int height, string imageUrl) 1354 public string osDrawImage(string drawList, int width, int height, string imageUrl)
1151 { 1355 {
1152 m_host.AddScriptLPS(1); 1356 CheckThreatLevel();
1357
1153 drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ; 1358 drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
1154 return drawList; 1359 return drawList;
1155 } 1360 }
1156 1361
1157 public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize) 1362 public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
1158 { 1363 {
1159 m_host.AddScriptLPS(1); 1364 CheckThreatLevel();
1160 1365
1161 LSL_Vector vec = new LSL_Vector(0,0,0); 1366 LSL_Vector vec = new LSL_Vector(0,0,0);
1162 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>(); 1367 IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
@@ -1178,17 +1383,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 // It was probably added as a crutch or debugging aid, and 1383 // It was probably added as a crutch or debugging aid, and
1179 // should be removed 1384 // should be removed
1180 // 1385 //
1181 if (!CheckThreatLevel(ThreatLevel.High, "osSetStateEvents")) return; 1386 CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
1182 m_host.AddScriptLPS(1);
1183 1387
1184 m_host.SetScriptEvents(m_item.ItemID, events); 1388 m_host.SetScriptEvents(m_item.ItemID, events);
1185 } 1389 }
1186 1390
1187 public void osSetRegionWaterHeight(double height) 1391 public void osSetRegionWaterHeight(double height)
1188 { 1392 {
1189 if (!CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight")) return; 1393 CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
1190
1191 m_host.AddScriptLPS(1);
1192 1394
1193 World.EventManager.TriggerRequestChangeWaterHeight((float)height); 1395 World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1194 } 1396 }
@@ -1201,9 +1403,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> 1403 /// <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) 1404 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
1203 { 1405 {
1204 if (!CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings")) return; 1406 CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
1205
1206 m_host.AddScriptLPS(1);
1207 1407
1208 while (sunHour > 24.0) 1408 while (sunHour > 24.0)
1209 sunHour -= 24.0; 1409 sunHour -= 24.0;
@@ -1226,9 +1426,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> 1426 /// <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) 1427 public void osSetEstateSunSettings(bool sunFixed, double sunHour)
1228 { 1428 {
1229 if (!CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings")) return; 1429 CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
1230
1231 m_host.AddScriptLPS(1);
1232 1430
1233 while (sunHour > 24.0) 1431 while (sunHour > 24.0)
1234 sunHour -= 24.0; 1432 sunHour -= 24.0;
@@ -1250,7 +1448,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1250 /// <returns></returns> 1448 /// <returns></returns>
1251 public double osGetCurrentSunHour() 1449 public double osGetCurrentSunHour()
1252 { 1450 {
1253 m_host.AddScriptLPS(1); 1451 CheckThreatLevel();
1254 1452
1255 // Must adjust for the fact that Region Sun Settings are still LL offset 1453 // Must adjust for the fact that Region Sun Settings are still LL offset
1256 double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6; 1454 double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
@@ -1267,19 +1465,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1267 1465
1268 public double osSunGetParam(string param) 1466 public double osSunGetParam(string param)
1269 { 1467 {
1468 CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
1270 OSSLDeprecated("osSunGetParam", "osGetSunParam"); 1469 OSSLDeprecated("osSunGetParam", "osGetSunParam");
1271 return GetSunParam(param); 1470 return GetSunParam(param);
1272 } 1471 }
1273 1472
1274 public double osGetSunParam(string param) 1473 public double osGetSunParam(string param)
1275 { 1474 {
1475 CheckThreatLevel();
1276 return GetSunParam(param); 1476 return GetSunParam(param);
1277 } 1477 }
1278 1478
1279 private double GetSunParam(string param) 1479 private double GetSunParam(string param)
1280 { 1480 {
1281 m_host.AddScriptLPS(1);
1282
1283 double value = 0.0; 1481 double value = 0.0;
1284 1482
1285 ISunModule module = World.RequestModuleInterface<ISunModule>(); 1483 ISunModule module = World.RequestModuleInterface<ISunModule>();
@@ -1293,21 +1491,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1293 1491
1294 public void osSunSetParam(string param, double value) 1492 public void osSunSetParam(string param, double value)
1295 { 1493 {
1296//// if (!CheckThreatLevel(ThreatLevel.None, "osSunSetParam")) return; 1494 CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
1297 OSSLDeprecated("osSunSetParam", "osSetSunParam"); 1495 OSSLDeprecated("osSunSetParam", "osSetSunParam");
1298 SetSunParam(param, value); 1496 SetSunParam(param, value);
1299 } 1497 }
1300 1498
1301 public void osSetSunParam(string param, double value) 1499 public void osSetSunParam(string param, double value)
1302 { 1500 {
1303//// if (!CheckThreatLevel(ThreatLevel.None, "osSetSunParam")) return; 1501 CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
1304 SetSunParam(param, value); 1502 SetSunParam(param, value);
1305 } 1503 }
1306 1504
1307 private void SetSunParam(string param, double value) 1505 private void SetSunParam(string param, double value)
1308 { 1506 {
1309 m_host.AddScriptLPS(1);
1310
1311 ISunModule module = World.RequestModuleInterface<ISunModule>(); 1507 ISunModule module = World.RequestModuleInterface<ISunModule>();
1312 if (module != null) 1508 if (module != null)
1313 { 1509 {
@@ -1317,7 +1513,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1317 1513
1318 public string osWindActiveModelPluginName() 1514 public string osWindActiveModelPluginName()
1319 { 1515 {
1320 m_host.AddScriptLPS(1); 1516 CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
1321 1517
1322 IWindModule module = World.RequestModuleInterface<IWindModule>(); 1518 IWindModule module = World.RequestModuleInterface<IWindModule>();
1323 if (module != null) 1519 if (module != null)
@@ -1330,8 +1526,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1330 1526
1331 public void osSetWindParam(string plugin, string param, LSL_Float value) 1527 public void osSetWindParam(string plugin, string param, LSL_Float value)
1332 { 1528 {
1333 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam")) return; 1529 CheckThreatLevel(ThreatLevel.VeryLow, "osSetWindParam");
1334 m_host.AddScriptLPS(1);
1335 1530
1336 IWindModule module = World.RequestModuleInterface<IWindModule>(); 1531 IWindModule module = World.RequestModuleInterface<IWindModule>();
1337 if (module != null) 1532 if (module != null)
@@ -1346,7 +1541,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1346 1541
1347 public LSL_Float osGetWindParam(string plugin, string param) 1542 public LSL_Float osGetWindParam(string plugin, string param)
1348 { 1543 {
1349 m_host.AddScriptLPS(1); 1544 CheckThreatLevel(ThreatLevel.VeryLow, "osGetWindParam");
1350 1545
1351 IWindModule module = World.RequestModuleInterface<IWindModule>(); 1546 IWindModule module = World.RequestModuleInterface<IWindModule>();
1352 if (module != null) 1547 if (module != null)
@@ -1360,8 +1555,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1360 // Routines for creating and managing parcels programmatically 1555 // Routines for creating and managing parcels programmatically
1361 public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2) 1556 public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
1362 { 1557 {
1363 if (!CheckThreatLevel(ThreatLevel.High, "osParcelJoin")) return; 1558 CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
1364 m_host.AddScriptLPS(1);
1365 1559
1366 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x); 1560 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
1367 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y); 1561 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
@@ -1373,8 +1567,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1373 1567
1374 public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2) 1568 public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
1375 { 1569 {
1376 if (!CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide")) return; 1570 CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
1377 m_host.AddScriptLPS(1);
1378 1571
1379 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x); 1572 int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
1380 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y); 1573 int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
@@ -1387,7 +1580,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1387 public void osParcelSetDetails(LSL_Vector pos, LSL_List rules) 1580 public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
1388 { 1581 {
1389 const string functionName = "osParcelSetDetails"; 1582 const string functionName = "osParcelSetDetails";
1390 if (!CheckThreatLevel(ThreatLevel.High, functionName)) return; 1583 CheckThreatLevel(ThreatLevel.High, functionName);
1391 OSSLDeprecated(functionName, "osSetParcelDetails"); 1584 OSSLDeprecated(functionName, "osSetParcelDetails");
1392 SetParcelDetails(pos, rules, functionName); 1585 SetParcelDetails(pos, rules, functionName);
1393 } 1586 }
@@ -1395,14 +1588,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1395 public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) 1588 public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
1396 { 1589 {
1397 const string functionName = "osSetParcelDetails"; 1590 const string functionName = "osSetParcelDetails";
1398 if (!CheckThreatLevel(ThreatLevel.High, functionName)) return; 1591 CheckThreatLevel(ThreatLevel.High, functionName);
1399 SetParcelDetails(pos, rules, functionName); 1592 SetParcelDetails(pos, rules, functionName);
1400 } 1593 }
1401 1594
1402 private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) 1595 private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
1403 { 1596 {
1404 m_host.AddScriptLPS(1);
1405
1406 // Get a reference to the land data and make sure the owner of the script 1597 // Get a reference to the land data and make sure the owner of the script
1407 // can modify it 1598 // can modify it
1408 1599
@@ -1413,15 +1604,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1413 return; 1604 return;
1414 } 1605 }
1415 1606
1416 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions)) 1607 if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, startLandObject, GroupPowers.LandOptions, false))
1417 { 1608 {
1418 OSSLShoutError("You do not have permission to modify the parcel"); 1609 OSSLShoutError("script owner does not have permission to modify the parcel");
1419 return; 1610 return;
1420 } 1611 }
1421 1612
1422 // Create a new land data object we can modify 1613 // Create a new land data object we can modify
1423 LandData newLand = startLandObject.LandData.Copy(); 1614 LandData newLand = startLandObject.LandData.Copy();
1424 UUID uuid; 1615 UUID uuid;
1616 EstateSettings es = World.RegionInfo.EstateSettings;
1617
1618 bool changed = false;
1619 bool changedSeeAvs = false;
1620 bool changedoverlay = false;
1621 bool changedneedupdate = false;
1425 1622
1426 // Process the rules, not sure what the impact would be of changing owner or group 1623 // Process the rules, not sure what the impact would be of changing owner or group
1427 for (int idx = 0; idx < rules.Length;) 1624 for (int idx = 0; idx < rules.Length;)
@@ -1431,35 +1628,151 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1431 switch (code) 1628 switch (code)
1432 { 1629 {
1433 case ScriptBaseClass.PARCEL_DETAILS_NAME: 1630 case ScriptBaseClass.PARCEL_DETAILS_NAME:
1434 newLand.Name = arg; 1631 if(newLand.Name != arg)
1632 {
1633 newLand.Name = arg;
1634 changed = true;
1635 }
1435 break; 1636 break;
1436 1637
1437 case ScriptBaseClass.PARCEL_DETAILS_DESC: 1638 case ScriptBaseClass.PARCEL_DETAILS_DESC:
1438 newLand.Description = arg; 1639 if(newLand.Description != arg)
1640 {
1641 newLand.Description = arg;
1642 changed = true;
1643 }
1439 break; 1644 break;
1440 1645
1441 case ScriptBaseClass.PARCEL_DETAILS_OWNER: 1646 case ScriptBaseClass.PARCEL_DETAILS_OWNER:
1442 if (!CheckThreatLevel(ThreatLevel.VeryHigh, functionName)) return; 1647 if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
1443 if (UUID.TryParse(arg, out uuid)) 1648 {
1444 newLand.OwnerID = uuid; 1649 OSSLError("script owner does not have permission to modify the parcel owner");
1650 }
1651 else
1652 {
1653 if (UUID.TryParse(arg, out uuid))
1654 {
1655 if(newLand.OwnerID != uuid)
1656 {
1657 changed = true;
1658 newLand.OwnerID = uuid;
1659 newLand.GroupID = UUID.Zero;
1660 }
1661 }
1662 }
1445 break; 1663 break;
1446 1664
1447 case ScriptBaseClass.PARCEL_DETAILS_GROUP: 1665 case ScriptBaseClass.PARCEL_DETAILS_GROUP:
1448 if (!CheckThreatLevel(ThreatLevel.VeryHigh, functionName)) return; 1666 if(m_host.OwnerID == newLand.OwnerID || es == null || es.IsEstateManagerOrOwner(m_host.OwnerID))
1449 if (UUID.TryParse(arg, out uuid)) 1667 {
1450 newLand.GroupID = uuid; 1668 if (UUID.TryParse(arg, out uuid))
1669 {
1670 if(newLand.GroupID != uuid)
1671 {
1672 if(uuid == UUID.Zero)
1673 {
1674 changed = true;
1675 newLand.GroupID = uuid;
1676 }
1677 else
1678 {
1679 IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
1680 GroupMembershipData member = null;
1681 if (groupsModule != null)
1682 member = groupsModule.GetMembershipData(uuid, newLand.OwnerID);
1683 if (member == null)
1684 OSSLError(string.Format("land owner is not member of the new group for parcel"));
1685 else
1686 {
1687 changed = true;
1688 newLand.GroupID = uuid;
1689 }
1690 }
1691 }
1692 }
1693 }
1694 else
1695 {
1696 OSSLError("script owner does not have permission to modify the parcel group");
1697 }
1451 break; 1698 break;
1452 1699
1453 case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE: 1700 case ScriptBaseClass.PARCEL_DETAILS_CLAIMDATE:
1454 if (!CheckThreatLevel(ThreatLevel.VeryHigh, functionName)) return; 1701 if(es != null && !es.IsEstateManagerOrOwner(m_host.OwnerID))
1455 newLand.ClaimDate = Convert.ToInt32(arg); 1702 {
1456 if (newLand.ClaimDate == 0) 1703 OSSLError("script owner does not have permission to modify the parcel CLAIM DATE");
1457 newLand.ClaimDate = Util.UnixTimeSinceEpoch(); 1704 }
1705 else
1706 {
1707 int date = Convert.ToInt32(arg);
1708 if (date == 0)
1709 date = Util.UnixTimeSinceEpoch();
1710 if(newLand.ClaimDate != date)
1711 {
1712 changed = true;
1713 newLand.ClaimDate = date;
1714 }
1715 }
1458 break; 1716 break;
1459 }
1460 }
1461 1717
1462 World.LandChannel.UpdateLandObject(newLand.LocalID,newLand); 1718 case ScriptBaseClass.PARCEL_DETAILS_SEE_AVATARS:
1719 bool newavs = (Convert.ToInt32(arg) != 0);
1720 if(newLand.SeeAVs != newavs)
1721 {
1722 changed = true;
1723 changedSeeAvs = true;
1724 changedoverlay = true;
1725 changedneedupdate = true;
1726 newLand.SeeAVs = newavs;
1727 }
1728 break;
1729
1730 case ScriptBaseClass.PARCEL_DETAILS_ANY_AVATAR_SOUNDS:
1731 bool newavsounds = (Convert.ToInt32(arg) != 0);
1732 if(newLand.AnyAVSounds != newavsounds)
1733 {
1734 changed = true;
1735 newLand.AnyAVSounds = newavsounds;
1736 }
1737 break;
1738
1739 case ScriptBaseClass.PARCEL_DETAILS_GROUP_SOUNDS:
1740 bool newgrpsounds = (Convert.ToInt32(arg) != 0);
1741 if(newLand.GroupAVSounds != newgrpsounds)
1742 {
1743 changed = true;
1744 newLand.GroupAVSounds = newgrpsounds;
1745 }
1746 break;
1747 }
1748 }
1749 if(changed)
1750 {
1751 World.LandChannel.UpdateLandObject(newLand.LocalID, newLand);
1752
1753 if(changedneedupdate)
1754 {
1755 UUID parcelID= newLand.GlobalID;
1756 World.ForEachRootScenePresence(delegate (ScenePresence avatar)
1757 {
1758 if (avatar == null || avatar.IsDeleted || avatar.IsInTransit)
1759 return;
1760
1761 if(changedSeeAvs && avatar.currentParcelUUID == parcelID )
1762 avatar.currentParcelUUID = parcelID; // force parcel flags review
1763
1764 if(avatar.ControllingClient == null)
1765 return;
1766
1767 // this will be needed for some things like damage etc
1768// if(avatar.currentParcelUUID == parcelID)
1769// startLandObject.SendLandUpdateToClient(avatar.ControllingClient);
1770
1771 if(changedoverlay && !avatar.IsNPC)
1772 World.LandChannel.SendParcelsOverlay(avatar.ControllingClient);
1773 });
1774 }
1775 }
1463 } 1776 }
1464 1777
1465 public double osList2Double(LSL_Types.list src, int index) 1778 public double osList2Double(LSL_Types.list src, int index)
@@ -1469,7 +1782,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1469 // is not allowed to contain any. 1782 // is not allowed to contain any.
1470 // This really should be removed. 1783 // This really should be removed.
1471 // 1784 //
1472 m_host.AddScriptLPS(1); 1785 CheckThreatLevel();
1786
1473 if (index < 0) 1787 if (index < 0)
1474 { 1788 {
1475 index = src.Length + index; 1789 index = src.Length + index;
@@ -1485,9 +1799,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1485 { 1799 {
1486 // What actually is the difference to the LL function? 1800 // What actually is the difference to the LL function?
1487 // 1801 //
1488 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL")) return; 1802 CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
1489
1490 m_host.AddScriptLPS(1);
1491 1803
1492 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 1804 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
1493 1805
@@ -1501,9 +1813,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1501 { 1813 {
1502 // What actually is the difference to the LL function? 1814 // What actually is the difference to the LL function?
1503 // 1815 //
1504 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress")) return; 1816 CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelSIPAddress");
1505
1506 m_host.AddScriptLPS(1);
1507 1817
1508 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); 1818 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
1509 1819
@@ -1529,9 +1839,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1529 // that trigger engine-specific failures. 1839 // that trigger engine-specific failures.
1530 // Besides, public grid users aren't supposed to know. 1840 // Besides, public grid users aren't supposed to know.
1531 // 1841 //
1532 // On the other hand, what other script engines are there? 1842 CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
1533 //
1534 m_host.AddScriptLPS(1);
1535 1843
1536 int scriptEngineNameIndex = 0; 1844 int scriptEngineNameIndex = 0;
1537 1845
@@ -1557,7 +1865,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1557 1865
1558 public LSL_Integer osCheckODE() 1866 public LSL_Integer osCheckODE()
1559 { 1867 {
1560 m_host.AddScriptLPS(1); 1868 CheckThreatLevel();
1869
1561 LSL_Integer ret = 0; // false 1870 LSL_Integer ret = 0; // false
1562 if (m_ScriptEngine.World.PhysicsScene != null) 1871 if (m_ScriptEngine.World.PhysicsScene != null)
1563 { 1872 {
@@ -1580,22 +1889,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1580 // about the physics engine, this function returns an empty string if 1889 // 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 1890 // the user does not have permission to see it. This as opposed to
1582 // throwing an exception. 1891 // throwing an exception.
1892
1583 m_host.AddScriptLPS(1); 1893 m_host.AddScriptLPS(1);
1584 string ret = String.Empty; 1894 string ret = String.Empty;
1895 if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType")))
1896 {
1897 if (m_ScriptEngine.World.PhysicsScene != null)
1898 {
1899 ret = m_ScriptEngine.World.PhysicsScene.EngineType;
1900 // An old physics engine might have an uninitialized engine type
1901 if (ret == null)
1902 ret = "unknown";
1903 }
1904 }
1905
1906 return ret;
1907 }
1908
1909 public string osGetPhysicsEngineName()
1910 {
1911 CheckThreatLevel();
1912
1913 string ret = "NoEngine";
1585 if (m_ScriptEngine.World.PhysicsScene != null) 1914 if (m_ScriptEngine.World.PhysicsScene != null)
1586 { 1915 {
1587 ret = m_ScriptEngine.World.PhysicsScene.EngineType; 1916 ret = m_ScriptEngine.World.PhysicsScene.EngineName;
1588 // An old physics engine might have an uninitialized engine type 1917 // An old physics engine might have an uninitialized engine type
1589 if (ret == null) 1918 if (ret == null)
1590 ret = "unknown"; 1919 ret = "UnknownEngine";
1591 } 1920 }
1592
1593 return ret; 1921 return ret;
1594 } 1922 }
1595 1923
1596 public string osGetSimulatorVersion() 1924 public string osGetSimulatorVersion()
1597 { 1925 {
1598 m_host.AddScriptLPS(1); 1926 // High because it can be used to target attacks to known weaknesses
1927 // This would allow a new class of griefer scripts that don't even
1928 // require their user to know what they are doing (see script
1929 // kiddie)
1930 //
1931 CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
1599 1932
1600 return m_ScriptEngine.World.GetSimulatorVersion(); 1933 return m_ScriptEngine.World.GetSimulatorVersion();
1601 } 1934 }
@@ -1639,7 +1972,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1639 1972
1640 public Object osParseJSONNew(string JSON) 1973 public Object osParseJSONNew(string JSON)
1641 { 1974 {
1642 m_host.AddScriptLPS(1); 1975 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
1643 1976
1644 try 1977 try
1645 { 1978 {
@@ -1648,14 +1981,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1648 } 1981 }
1649 catch(Exception e) 1982 catch(Exception e)
1650 { 1983 {
1651 OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message); 1984 OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
1652 return null; 1985 return null;
1653 } 1986 }
1654 } 1987 }
1655 1988
1656 public Hashtable osParseJSON(string JSON) 1989 public Hashtable osParseJSON(string JSON)
1657 { 1990 {
1658 m_host.AddScriptLPS(1); 1991 CheckThreatLevel(ThreatLevel.None, "osParseJSON");
1659 1992
1660 Object decoded = osParseJSONNew(JSON); 1993 Object decoded = osParseJSONNew(JSON);
1661 1994
@@ -1686,7 +2019,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1686 /// <param name="message"></param> 2019 /// <param name="message"></param>
1687 public void osMessageObject(LSL_Key objectUUID, string message) 2020 public void osMessageObject(LSL_Key objectUUID, string message)
1688 { 2021 {
1689 m_host.AddScriptLPS(1); 2022 CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
1690 2023
1691 UUID objUUID; 2024 UUID objUUID;
1692 if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead. 2025 if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead.
@@ -1715,6 +2048,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1715 "dataserver", resobj, new DetectParams[0])); 2048 "dataserver", resobj, new DetectParams[0]));
1716 } 2049 }
1717 2050
2051
2052 /// <summary>
2053 /// Similar to llDie but given an object UUID
2054 /// </summary>
2055 /// <param name="objectUUID"></param>
2056
2057 public void osDie(LSL_Key objectUUID)
2058 {
2059// CheckThreatLevel(ThreatLevel.VeryHigh, "osDie");
2060 // if this is restricted to objects rezzed by this host level can be reduced
2061
2062 CheckThreatLevel(ThreatLevel.Low, "osDie");
2063
2064 UUID objUUID;
2065 if (!UUID.TryParse(objectUUID, out objUUID))
2066 {
2067 OSSLShoutError("osDie() cannot delete objects with invalid UUIDs");
2068 return;
2069 }
2070
2071 // harakiri check
2072 if(objUUID == UUID.Zero)
2073 {
2074 if (!m_host.ParentGroup.IsAttachment)
2075 throw new SelfDeleteException();
2076 return;
2077 }
2078
2079 SceneObjectGroup sceneOG = World.GetSceneObjectGroup(objUUID);
2080
2081 if (sceneOG == null || sceneOG.IsDeleted)
2082 return;
2083
2084 if(sceneOG.IsAttachment)
2085 return;
2086
2087 if (sceneOG.OwnerID != m_host.OwnerID)
2088 return;
2089
2090 // harakiri check
2091 if(sceneOG.UUID == m_host.ParentGroup.UUID)
2092 throw new SelfDeleteException();
2093
2094 // restrict to objects rezzed by host
2095 if(sceneOG.RezzerID == m_host.ParentGroup.UUID)
2096 World.DeleteSceneObject(sceneOG, false);
2097 }
2098
1718 /// <summary> 2099 /// <summary>
1719 /// Write a notecard directly to the prim's inventory. 2100 /// Write a notecard directly to the prim's inventory.
1720 /// </summary> 2101 /// </summary>
@@ -1727,7 +2108,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1727 /// <param name="contents">The contents of the notecard.</param> 2108 /// <param name="contents">The contents of the notecard.</param>
1728 public void osMakeNotecard(string notecardName, LSL_Types.list contents) 2109 public void osMakeNotecard(string notecardName, LSL_Types.list contents)
1729 { 2110 {
1730 m_host.AddScriptLPS(1); 2111 CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
1731 2112
1732 StringBuilder notecardData = new StringBuilder(); 2113 StringBuilder notecardData = new StringBuilder();
1733 2114
@@ -1778,8 +2159,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1778 taskItem.ResetIDs(m_host.UUID); 2159 taskItem.ResetIDs(m_host.UUID);
1779 taskItem.ParentID = m_host.UUID; 2160 taskItem.ParentID = m_host.UUID;
1780 taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch(); 2161 taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
1781 taskItem.Name = asset.Name; 2162 taskItem.Name = name;
1782 taskItem.Description = asset.Description; 2163 taskItem.Description = description;
1783 taskItem.Type = (int)AssetType.Notecard; 2164 taskItem.Type = (int)AssetType.Notecard;
1784 taskItem.InvType = (int)InventoryType.Notecard; 2165 taskItem.InvType = (int)InventoryType.Notecard;
1785 taskItem.OwnerID = m_host.OwnerID; 2166 taskItem.OwnerID = m_host.OwnerID;
@@ -1799,6 +2180,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1799 m_host.Inventory.AddInventoryItemExclusive(taskItem, false); 2180 m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
1800 else 2181 else
1801 m_host.Inventory.AddInventoryItem(taskItem, false); 2182 m_host.Inventory.AddInventoryItem(taskItem, false);
2183 m_host.ParentGroup.InvalidateDeepEffectivePerms();
1802 2184
1803 return taskItem; 2185 return taskItem;
1804 } 2186 }
@@ -1843,15 +2225,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1843 { 2225 {
1844 UUID assetID = UUID.Zero; 2226 UUID assetID = UUID.Zero;
1845 2227
1846 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 2228 bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
2229
2230 if (!notecardNameIsUUID)
1847 { 2231 {
1848 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 2232 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1849 {
1850 if (item.Type == 7 && item.Name == notecardNameOrUuid)
1851 {
1852 assetID = item.AssetID;
1853 }
1854 }
1855 } 2233 }
1856 2234
1857 if (assetID == UUID.Zero) 2235 if (assetID == UUID.Zero)
@@ -1862,13 +2240,43 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1862 AssetBase a = World.AssetService.Get(assetID.ToString()); 2240 AssetBase a = World.AssetService.Get(assetID.ToString());
1863 2241
1864 if (a == null) 2242 if (a == null)
1865 return UUID.Zero; 2243 {
2244 // Whoops, it's still possible here that the notecard name was properly
2245 // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
2246 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
2247 if (assetID == UUID.Zero)
2248 return UUID.Zero;
2249
2250 if (!NotecardCache.IsCached(assetID))
2251 {
2252 a = World.AssetService.Get(assetID.ToString());
2253
2254 if (a == null)
2255 {
2256 return UUID.Zero;
2257 }
2258 }
2259 }
1866 2260
1867 NotecardCache.Cache(assetID, a.Data); 2261 NotecardCache.Cache(assetID, a.Data);
1868 }; 2262 };
1869 2263
1870 return assetID; 2264 return assetID;
1871 } 2265 }
2266 protected UUID SearchTaskInventoryForAssetId(string name)
2267 {
2268 UUID assetId = UUID.Zero;
2269 m_host.TaskInventory.LockItemsForRead(true);
2270 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
2271 {
2272 if (item.Type == 7 && item.Name == name)
2273 {
2274 assetId = item.AssetID;
2275 }
2276 }
2277 m_host.TaskInventory.LockItemsForRead(false);
2278 return assetId;
2279 }
1872 2280
1873 /// <summary> 2281 /// <summary>
1874 /// Directly get an entire notecard at once. 2282 /// Directly get an entire notecard at once.
@@ -1885,7 +2293,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1885 /// <returns>Notecard line</returns> 2293 /// <returns>Notecard line</returns>
1886 public string osGetNotecardLine(string name, int line) 2294 public string osGetNotecardLine(string name, int line)
1887 { 2295 {
1888 m_host.AddScriptLPS(1); 2296 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
1889 2297
1890 UUID assetID = CacheNotecard(name); 2298 UUID assetID = CacheNotecard(name);
1891 2299
@@ -1912,7 +2320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1912 /// <returns>Notecard text</returns> 2320 /// <returns>Notecard text</returns>
1913 public string osGetNotecard(string name) 2321 public string osGetNotecard(string name)
1914 { 2322 {
1915 m_host.AddScriptLPS(1); 2323 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
1916 2324
1917 string text = LoadNotecard(name); 2325 string text = LoadNotecard(name);
1918 2326
@@ -1941,7 +2349,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1941 /// <returns></returns> 2349 /// <returns></returns>
1942 public int osGetNumberOfNotecardLines(string name) 2350 public int osGetNumberOfNotecardLines(string name)
1943 { 2351 {
1944 m_host.AddScriptLPS(1); 2352 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
1945 2353
1946 UUID assetID = CacheNotecard(name); 2354 UUID assetID = CacheNotecard(name);
1947 2355
@@ -1956,8 +2364,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1956 2364
1957 public string osAvatarName2Key(string firstname, string lastname) 2365 public string osAvatarName2Key(string firstname, string lastname)
1958 { 2366 {
1959 if (!CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key")) return string.Empty; 2367 CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
1960 m_host.AddScriptLPS(1);
1961 2368
1962 IUserManagement userManager = World.RequestModuleInterface<IUserManagement>(); 2369 IUserManagement userManager = World.RequestModuleInterface<IUserManagement>();
1963 if (userManager == null) 2370 if (userManager == null)
@@ -2008,7 +2415,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2008 2415
2009 public string osKey2Name(string id) 2416 public string osKey2Name(string id)
2010 { 2417 {
2011 m_host.AddScriptLPS(1); 2418 CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
2012 2419
2013 UUID key = new UUID(); 2420 UUID key = new UUID();
2014 2421
@@ -2117,8 +2524,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2117 /// <returns></returns> 2524 /// <returns></returns>
2118 public string osGetGridNick() 2525 public string osGetGridNick()
2119 { 2526 {
2120//// if (!CheckThreatLevel(ThreatLevel.None, "osGetGridNick")) return ""; 2527 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
2121 m_host.AddScriptLPS(1);
2122 2528
2123 string nick = String.Empty; 2529 string nick = String.Empty;
2124 IConfigSource config = m_ScriptEngine.ConfigSource; 2530 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2134,8 +2540,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2134 2540
2135 public string osGetGridName() 2541 public string osGetGridName()
2136 { 2542 {
2137//// if (!CheckThreatLevel(ThreatLevel.None, "osGetGridName")) return ""; 2543 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
2138 m_host.AddScriptLPS(1);
2139 2544
2140 string name = String.Empty; 2545 string name = String.Empty;
2141 IConfigSource config = m_ScriptEngine.ConfigSource; 2546 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2151,8 +2556,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2151 2556
2152 public string osGetGridLoginURI() 2557 public string osGetGridLoginURI()
2153 { 2558 {
2154 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI")) return ""; 2559 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
2155 m_host.AddScriptLPS(1);
2156 2560
2157 string loginURI = String.Empty; 2561 string loginURI = String.Empty;
2158 IConfigSource config = m_ScriptEngine.ConfigSource; 2562 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2168,11 +2572,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2168 2572
2169 public string osGetGridHomeURI() 2573 public string osGetGridHomeURI()
2170 { 2574 {
2171 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI")) return ""; 2575 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI");
2172 m_host.AddScriptLPS(1);
2173 2576
2174 IConfigSource config = m_ScriptEngine.ConfigSource; 2577 IConfigSource config = m_ScriptEngine.ConfigSource;
2175 string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI", 2578 string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
2176 new string[] { "Startup", "Hypergrid" }, String.Empty); 2579 new string[] { "Startup", "Hypergrid" }, String.Empty);
2177 2580
2178 if (!string.IsNullOrEmpty(HomeURI)) 2581 if (!string.IsNullOrEmpty(HomeURI))
@@ -2190,8 +2593,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2190 2593
2191 public string osGetGridGatekeeperURI() 2594 public string osGetGridGatekeeperURI()
2192 { 2595 {
2193 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI")) return ""; 2596 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI");
2194 m_host.AddScriptLPS(1);
2195 2597
2196 IConfigSource config = m_ScriptEngine.ConfigSource; 2598 IConfigSource config = m_ScriptEngine.ConfigSource;
2197 string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", 2599 string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
@@ -2209,8 +2611,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2209 2611
2210 public string osGetGridCustom(string key) 2612 public string osGetGridCustom(string key)
2211 { 2613 {
2212 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom")) return String.Empty; 2614 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridCustom");
2213 m_host.AddScriptLPS(1);
2214 2615
2215 string retval = String.Empty; 2616 string retval = String.Empty;
2216 IConfigSource config = m_ScriptEngine.ConfigSource; 2617 IConfigSource config = m_ScriptEngine.ConfigSource;
@@ -2226,8 +2627,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2226 2627
2227 public string osGetAvatarHomeURI(string uuid) 2628 public string osGetAvatarHomeURI(string uuid)
2228 { 2629 {
2229 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetAvatarHomeURI")) return ""; 2630 CheckThreatLevel(ThreatLevel.Low, "osGetAvatarHomeURI");
2230 m_host.AddScriptLPS(1);
2231 2631
2232 IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>(); 2632 IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>();
2233 string returnValue = ""; 2633 string returnValue = "";
@@ -2259,14 +2659,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2259 2659
2260 public LSL_String osFormatString(string str, LSL_List strings) 2660 public LSL_String osFormatString(string str, LSL_List strings)
2261 { 2661 {
2262 m_host.AddScriptLPS(1); 2662 CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
2263 2663
2264 return String.Format(str, strings.Data); 2664 return String.Format(str, strings.Data);
2265 } 2665 }
2266 2666
2267 public LSL_List osMatchString(string src, string pattern, int start) 2667 public LSL_List osMatchString(string src, string pattern, int start)
2268 { 2668 {
2269 m_host.AddScriptLPS(1); 2669 CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
2270 2670
2271 LSL_List result = new LSL_List(); 2671 LSL_List result = new LSL_List();
2272 2672
@@ -2307,7 +2707,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2307 2707
2308 public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start) 2708 public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
2309 { 2709 {
2310 m_host.AddScriptLPS(1); 2710 CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
2311 2711
2312 // Normalize indices (if negative). 2712 // Normalize indices (if negative).
2313 // After normlaization they may still be 2713 // After normlaization they may still be
@@ -2331,24 +2731,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2331 2731
2332 public string osLoadedCreationDate() 2732 public string osLoadedCreationDate()
2333 { 2733 {
2334 if (!CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate")) return ""; 2734 CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
2335 m_host.AddScriptLPS(1);
2336 2735
2337 return World.RegionInfo.RegionSettings.LoadedCreationDate; 2736 return World.RegionInfo.RegionSettings.LoadedCreationDate;
2338 } 2737 }
2339 2738
2340 public string osLoadedCreationTime() 2739 public string osLoadedCreationTime()
2341 { 2740 {
2342 if (!CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime")) return ""; 2741 CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
2343 m_host.AddScriptLPS(1);
2344 2742
2345 return World.RegionInfo.RegionSettings.LoadedCreationTime; 2743 return World.RegionInfo.RegionSettings.LoadedCreationTime;
2346 } 2744 }
2347 2745
2348 public string osLoadedCreationID() 2746 public string osLoadedCreationID()
2349 { 2747 {
2350 if (!CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID")) return ""; 2748 CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
2351 m_host.AddScriptLPS(1);
2352 2749
2353 return World.RegionInfo.RegionSettings.LoadedCreationID; 2750 return World.RegionInfo.RegionSettings.LoadedCreationID;
2354 } 2751 }
@@ -2368,8 +2765,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2368 /// <returns></returns> 2765 /// <returns></returns>
2369 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) 2766 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
2370 { 2767 {
2371 if (!CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams")) return new LSL_List(); 2768 CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
2372 m_host.AddScriptLPS(1); 2769
2373 InitLSL(); 2770 InitLSL();
2374 // One needs to cast m_LSL_Api because we're using functions not 2771 // One needs to cast m_LSL_Api because we're using functions not
2375 // on the ILSL_Api interface. 2772 // on the ILSL_Api interface.
@@ -2396,9 +2793,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2396 2793
2397 public void osForceCreateLink(string target, int parent) 2794 public void osForceCreateLink(string target, int parent)
2398 { 2795 {
2399 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink")) return; 2796 CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink");
2400
2401 m_host.AddScriptLPS(1);
2402 2797
2403 InitLSL(); 2798 InitLSL();
2404 ((LSL_Api)m_LSL_Api).CreateLink(target, parent); 2799 ((LSL_Api)m_LSL_Api).CreateLink(target, parent);
@@ -2406,9 +2801,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2406 2801
2407 public void osForceBreakLink(int linknum) 2802 public void osForceBreakLink(int linknum)
2408 { 2803 {
2409 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink")) return; 2804 CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink");
2410
2411 m_host.AddScriptLPS(1);
2412 2805
2413 InitLSL(); 2806 InitLSL();
2414 ((LSL_Api)m_LSL_Api).BreakLink(linknum); 2807 ((LSL_Api)m_LSL_Api).BreakLink(linknum);
@@ -2416,9 +2809,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2416 2809
2417 public void osForceBreakAllLinks() 2810 public void osForceBreakAllLinks()
2418 { 2811 {
2419 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks")) return; 2812 CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks");
2420
2421 m_host.AddScriptLPS(1);
2422 2813
2423 InitLSL(); 2814 InitLSL();
2424 ((LSL_Api)m_LSL_Api).BreakAllLinks(); 2815 ((LSL_Api)m_LSL_Api).BreakAllLinks();
@@ -2426,7 +2817,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2426 2817
2427 public LSL_Integer osIsNpc(LSL_Key npc) 2818 public LSL_Integer osIsNpc(LSL_Key npc)
2428 { 2819 {
2429 m_host.AddScriptLPS(1); 2820 CheckThreatLevel();
2430 2821
2431 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2822 INPCModule module = World.RequestModuleInterface<INPCModule>();
2432 if (module != null) 2823 if (module != null)
@@ -2442,31 +2833,99 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2442 2833
2443 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) 2834 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
2444 { 2835 {
2445 if (!CheckThreatLevel(ThreatLevel.High, "osNpcCreate")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 2836 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2446 m_host.AddScriptLPS(1); 2837
2838 // have to get the npc module also here to set the default Not Owned
2839 INPCModule module = World.RequestModuleInterface<INPCModule>();
2840 if(module == null)
2841 return new LSL_Key(UUID.Zero.ToString());
2842
2843 bool owned = (module.NPCOptionFlags & NPCOptionsFlags.AllowNotOwned) == 0;
2447 2844
2448 return NpcCreate(firstname, lastname, position, notecard, false, false); 2845 return NpcCreate(firstname, lastname, position, notecard, owned, false, false);
2449 } 2846 }
2450 2847
2451 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) 2848 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
2452 { 2849 {
2453 if (!CheckThreatLevel(ThreatLevel.High, "osNpcCreate")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 2850 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2454 m_host.AddScriptLPS(1);
2455 2851
2456 return NpcCreate( 2852 return NpcCreate(
2457 firstname, lastname, position, notecard, 2853 firstname, lastname, position, notecard,
2458 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, 2854 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
2459 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); 2855 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0,
2856 (options & ScriptBaseClass.OS_NPC_OBJECT_GROUP) != 0);
2460 } 2857 }
2461 2858
2462 private LSL_Key NpcCreate( 2859 private LSL_Key NpcCreate(
2463 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) 2860 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent, bool hostGroupID)
2464 { 2861 {
2862 if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
2863 {
2864 OSSLError("no permission to rez NPC at requested location");
2865 return new LSL_Key(UUID.Zero.ToString());
2866 }
2867
2465 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2868 INPCModule module = World.RequestModuleInterface<INPCModule>();
2466 if (module != null) 2869 if(module == null)
2870 {
2871 OSSLError("NPC module not enabled");
2872 return new LSL_Key(UUID.Zero.ToString());
2873 }
2874
2875 string groupTitle = String.Empty;
2876 UUID groupID = UUID.Zero;
2877
2878 AvatarAppearance appearance = null;
2879
2880 // check creation options
2881 NPCOptionsFlags createFlags = module.NPCOptionFlags;
2882
2883 if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
2884 {
2885 OSSLError("Not owned NPCs disabled");
2886 owned = true; // we should get here...
2887 }
2888
2889 if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
2467 { 2890 {
2468 AvatarAppearance appearance = null; 2891 OSSLError("NPC allow sense as Avatar disabled");
2892 senseAsAgent = false;
2893 }
2469 2894
2895 if(hostGroupID && m_host.GroupID != UUID.Zero)
2896 {
2897 IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
2898 if (groupsModule != null)
2899 {
2900 GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
2901 if (member == null)
2902 {
2903 OSSLError(string.Format("osNpcCreate: the object owner is not member of the object group"));
2904 return new LSL_Key(UUID.Zero.ToString());
2905 }
2906
2907 groupID = m_host.GroupID;
2908
2909 if((createFlags & NPCOptionsFlags.NoNPCGroup) != 0)
2910 {
2911 GroupRecord grprec = groupsModule.GetGroupRecord(m_host.GroupID);
2912 if(grprec != null && grprec.GroupName != "")
2913 groupTitle = grprec.GroupName;
2914 }
2915 }
2916 }
2917
2918 if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
2919 {
2920 if (firstname != String.Empty || lastname != String.Empty)
2921 {
2922 if (firstname != "Shown outfit:")
2923 groupTitle = "- NPC -";
2924 }
2925 }
2926
2927 if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
2928 {
2470 UUID id; 2929 UUID id;
2471 if (UUID.TryParse(notecard, out id)) 2930 if (UUID.TryParse(notecard, out id))
2472 { 2931 {
@@ -2474,38 +2933,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2474 if (clonePresence != null) 2933 if (clonePresence != null)
2475 appearance = clonePresence.Appearance; 2934 appearance = clonePresence.Appearance;
2476 } 2935 }
2936 }
2477 2937
2478 if (appearance == null) 2938 if (appearance == null)
2479 { 2939 {
2480 string appearanceSerialized = LoadNotecard(notecard); 2940 string appearanceSerialized = LoadNotecard(notecard);
2481 2941
2482 if (appearanceSerialized != null) 2942 if (appearanceSerialized != null)
2943 {
2944 try
2483 { 2945 {
2484 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); 2946 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2485 appearance = new AvatarAppearance(); 2947 appearance = new AvatarAppearance();
2486 appearance.Unpack(appearanceOsd); 2948 appearance.Unpack(appearanceOsd);
2487 } 2949 }
2488 else 2950 catch
2489 { 2951 {
2490 OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); 2952 OSSLError(string.Format("osNpcCreate: Error processing notcard '{0}'", notecard));
2953 return new LSL_Key(UUID.Zero.ToString());
2491 } 2954 }
2492 } 2955 }
2956 else
2957 {
2958 OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
2959 }
2960 }
2493 2961
2494 UUID ownerID = UUID.Zero; 2962 UUID ownerID = UUID.Zero;
2495 if (owned) 2963 if (owned)
2496 ownerID = m_host.OwnerID; 2964 ownerID = m_host.OwnerID;
2497 UUID x = module.CreateNPC(firstname, 2965 UUID x = module.CreateNPC(firstname,
2498 lastname, 2966 lastname,
2499 position, 2967 position,
2500 ownerID, 2968 UUID.Random(),
2501 senseAsAgent, 2969 ownerID,
2502 World, 2970 groupTitle,
2503 appearance); 2971 groupID,
2972 senseAsAgent,
2973 World,
2974 appearance);
2504 2975
2505 return new LSL_Key(x.ToString()); 2976 ScenePresence sp;
2977 if (World.TryGetScenePresence(x, out sp))
2978 {
2979 sp.SendAvatarDataToAllAgents();
2506 } 2980 }
2507 2981 return new LSL_Key(x.ToString());
2508 return new LSL_Key(UUID.Zero.ToString());
2509 } 2982 }
2510 2983
2511 /// <summary> 2984 /// <summary>
@@ -2516,8 +2989,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2516 /// <returns>The asset ID of the notecard saved.</returns> 2989 /// <returns>The asset ID of the notecard saved.</returns>
2517 public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard) 2990 public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
2518 { 2991 {
2519 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 2992 CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
2520 m_host.AddScriptLPS(1);
2521 2993
2522 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 2994 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2523 2995
@@ -2538,8 +3010,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2538 3010
2539 public void osNpcLoadAppearance(LSL_Key npc, string notecard) 3011 public void osNpcLoadAppearance(LSL_Key npc, string notecard)
2540 { 3012 {
2541 if (!CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance")) return; 3013 CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
2542 m_host.AddScriptLPS(1);
2543 3014
2544 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3015 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2545 3016
@@ -2570,7 +3041,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2570 3041
2571 public LSL_Key osNpcGetOwner(LSL_Key npc) 3042 public LSL_Key osNpcGetOwner(LSL_Key npc)
2572 { 3043 {
2573 m_host.AddScriptLPS(1); 3044 CheckThreatLevel(ThreatLevel.None, "osNpcGetOwner");
2574 3045
2575 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3046 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2576 if (npcModule != null) 3047 if (npcModule != null)
@@ -2591,7 +3062,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2591 3062
2592 public LSL_Vector osNpcGetPos(LSL_Key npc) 3063 public LSL_Vector osNpcGetPos(LSL_Key npc)
2593 { 3064 {
2594 m_host.AddScriptLPS(1); 3065 CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
2595 3066
2596 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3067 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2597 if (npcModule != null) 3068 if (npcModule != null)
@@ -2614,8 +3085,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2614 3085
2615 public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos) 3086 public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
2616 { 3087 {
2617 if (!CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo")) return; 3088 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
2618 m_host.AddScriptLPS(1);
2619 3089
2620 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3090 INPCModule module = World.RequestModuleInterface<INPCModule>();
2621 if (module != null) 3091 if (module != null)
@@ -2633,8 +3103,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2633 3103
2634 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options) 3104 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
2635 { 3105 {
2636 if (!CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget")) return; 3106 CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
2637 m_host.AddScriptLPS(1);
2638 3107
2639 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3108 INPCModule module = World.RequestModuleInterface<INPCModule>();
2640 if (module != null) 3109 if (module != null)
@@ -2658,7 +3127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2658 3127
2659 public LSL_Rotation osNpcGetRot(LSL_Key npc) 3128 public LSL_Rotation osNpcGetRot(LSL_Key npc)
2660 { 3129 {
2661 m_host.AddScriptLPS(1); 3130 CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
2662 3131
2663 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3132 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2664 if (npcModule != null) 3133 if (npcModule != null)
@@ -2681,8 +3150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2681 3150
2682 public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) 3151 public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
2683 { 3152 {
2684 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSetRot")) return; 3153 CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
2685 m_host.AddScriptLPS(1);
2686 3154
2687 INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); 3155 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2688 if (npcModule != null) 3156 if (npcModule != null)
@@ -2703,8 +3171,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2703 3171
2704 public void osNpcStopMoveToTarget(LSL_Key npc) 3172 public void osNpcStopMoveToTarget(LSL_Key npc)
2705 { 3173 {
2706 if (!CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget")) return; 3174 CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
2707 m_host.AddScriptLPS(1);
2708 3175
2709 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3176 INPCModule module = World.RequestModuleInterface<INPCModule>();
2710 if (module != null) 3177 if (module != null)
@@ -2718,6 +3185,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2718 } 3185 }
2719 } 3186 }
2720 3187
3188 public void osNpcSetProfileAbout(LSL_Key npc, string about)
3189 {
3190 CheckThreatLevel(ThreatLevel.Low, "osNpcSetProfileAbout");
3191
3192 INPCModule module = World.RequestModuleInterface<INPCModule>();
3193 if (module != null)
3194 {
3195 UUID npcId = new UUID(npc.m_string);
3196
3197 if (!module.CheckPermissions(npcId, m_host.OwnerID))
3198 return;
3199
3200 ScenePresence sp = World.GetScenePresence(npcId);
3201 if (sp != null)
3202 ((INPC)(sp.ControllingClient)).profileAbout = about;
3203 }
3204 }
3205
3206 public void osNpcSetProfileImage(LSL_Key npc, string image)
3207 {
3208 CheckThreatLevel(ThreatLevel.Low, "osNpcSetProfileImage");
3209
3210 INPCModule module = World.RequestModuleInterface<INPCModule>();
3211 if (module != null)
3212 {
3213 UUID npcId = new UUID(npc.m_string);
3214
3215 if (!module.CheckPermissions(npcId, m_host.OwnerID))
3216 return;
3217
3218 UUID ImageID = new UUID();
3219
3220 ImageID = ScriptUtils.GetAssetIdFromItemName(m_host, image, (int)AssetType.Texture);
3221
3222 if (ImageID == null || ImageID == UUID.Zero)
3223 {
3224 if (!UUID.TryParse(image, out ImageID))
3225 return;
3226 }
3227
3228 ScenePresence sp = World.GetScenePresence(npcId);
3229 if (sp != null)
3230 ((INPC)(sp.ControllingClient)).profileImage = ImageID;
3231 }
3232 }
3233
2721 public void osNpcSay(LSL_Key npc, string message) 3234 public void osNpcSay(LSL_Key npc, string message)
2722 { 3235 {
2723 osNpcSay(npc, 0, message); 3236 osNpcSay(npc, 0, message);
@@ -2725,8 +3238,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2725 3238
2726 public void osNpcSay(LSL_Key npc, int channel, string message) 3239 public void osNpcSay(LSL_Key npc, int channel, string message)
2727 { 3240 {
2728 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSay")) return; 3241 CheckThreatLevel(ThreatLevel.High, "osNpcSay");
2729 m_host.AddScriptLPS(1);
2730 3242
2731 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3243 INPCModule module = World.RequestModuleInterface<INPCModule>();
2732 if (module != null) 3244 if (module != null)
@@ -2742,8 +3254,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2742 3254
2743 public void osNpcShout(LSL_Key npc, int channel, string message) 3255 public void osNpcShout(LSL_Key npc, int channel, string message)
2744 { 3256 {
2745 if (!CheckThreatLevel(ThreatLevel.High, "osNpcShout")) return; 3257 CheckThreatLevel(ThreatLevel.High, "osNpcShout");
2746 m_host.AddScriptLPS(1);
2747 3258
2748 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3259 INPCModule module = World.RequestModuleInterface<INPCModule>();
2749 if (module != null) 3260 if (module != null)
@@ -2759,8 +3270,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2759 3270
2760 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 3271 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
2761 { 3272 {
2762 if (!CheckThreatLevel(ThreatLevel.High, "osNpcSit")) return; 3273 CheckThreatLevel(ThreatLevel.High, "osNpcSit");
2763 m_host.AddScriptLPS(1);
2764 3274
2765 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3275 INPCModule module = World.RequestModuleInterface<INPCModule>();
2766 if (module != null) 3276 if (module != null)
@@ -2776,8 +3286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2776 3286
2777 public void osNpcStand(LSL_Key npc) 3287 public void osNpcStand(LSL_Key npc)
2778 { 3288 {
2779 if (!CheckThreatLevel(ThreatLevel.High, "osNpcStand")) return; 3289 CheckThreatLevel(ThreatLevel.High, "osNpcStand");
2780 m_host.AddScriptLPS(1);
2781 3290
2782 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3291 INPCModule module = World.RequestModuleInterface<INPCModule>();
2783 if (module != null) 3292 if (module != null)
@@ -2793,25 +3302,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2793 3302
2794 public void osNpcRemove(LSL_Key npc) 3303 public void osNpcRemove(LSL_Key npc)
2795 { 3304 {
2796 if (!CheckThreatLevel(ThreatLevel.High, "osNpcRemove")) return; 3305 CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
2797 m_host.AddScriptLPS(1);
2798 3306
2799 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3307 try
2800 if (module != null)
2801 { 3308 {
2802 UUID npcId = new UUID(npc.m_string); 3309 INPCModule module = World.RequestModuleInterface<INPCModule>();
3310 if (module != null)
3311 {
3312 UUID npcId = new UUID(npc.m_string);
2803 3313
2804 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 3314 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2805 return; 3315 return;
2806 3316
2807 module.DeleteNPC(npcId, World); 3317 module.DeleteNPC(npcId, World);
3318 }
2808 } 3319 }
3320 catch { }
2809 } 3321 }
2810 3322
2811 public void osNpcPlayAnimation(LSL_Key npc, string animation) 3323 public void osNpcPlayAnimation(LSL_Key npc, string animation)
2812 { 3324 {
2813 if (!CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation")) return; 3325 CheckThreatLevel(ThreatLevel.High, "osNpcPlayAnimation");
2814 m_host.AddScriptLPS(1);
2815 3326
2816 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3327 INPCModule module = World.RequestModuleInterface<INPCModule>();
2817 if (module != null) 3328 if (module != null)
@@ -2825,8 +3336,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2825 3336
2826 public void osNpcStopAnimation(LSL_Key npc, string animation) 3337 public void osNpcStopAnimation(LSL_Key npc, string animation)
2827 { 3338 {
2828 if (!CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation")) return; 3339 CheckThreatLevel(ThreatLevel.High, "osNpcStopAnimation");
2829 m_host.AddScriptLPS(1);
2830 3340
2831 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3341 INPCModule module = World.RequestModuleInterface<INPCModule>();
2832 if (module != null) 3342 if (module != null)
@@ -2840,8 +3350,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2840 3350
2841 public void osNpcWhisper(LSL_Key npc, int channel, string message) 3351 public void osNpcWhisper(LSL_Key npc, int channel, string message)
2842 { 3352 {
2843 if (!CheckThreatLevel(ThreatLevel.High, "osNpcWhisper")) return; 3353 CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
2844 m_host.AddScriptLPS(1);
2845 3354
2846 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3355 INPCModule module = World.RequestModuleInterface<INPCModule>();
2847 if (module != null) 3356 if (module != null)
@@ -2857,8 +3366,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2857 3366
2858 public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num) 3367 public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
2859 { 3368 {
2860 if (!CheckThreatLevel(ThreatLevel.High, "osNpcTouch")) return; 3369 CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
2861 m_host.AddScriptLPS(1);
2862 3370
2863 INPCModule module = World.RequestModuleInterface<INPCModule>(); 3371 INPCModule module = World.RequestModuleInterface<INPCModule>();
2864 int linkNum = link_num.value; 3372 int linkNum = link_num.value;
@@ -2902,16 +3410,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2902 /// <returns>The asset ID of the notecard saved.</returns> 3410 /// <returns>The asset ID of the notecard saved.</returns>
2903 public LSL_Key osOwnerSaveAppearance(string notecard) 3411 public LSL_Key osOwnerSaveAppearance(string notecard)
2904 { 3412 {
2905 if (!CheckThreatLevel(ThreatLevel.Moderate, "osOwnerSaveAppearance")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 3413 CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
2906 m_host.AddScriptLPS(1);
2907 3414
2908 return SaveAppearanceToNotecard(m_host.OwnerID, notecard); 3415 return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
2909 } 3416 }
2910 3417
2911 public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard) 3418 public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
2912 { 3419 {
2913 if (!CheckThreatLevel(ThreatLevel.High, "osAgentSaveAppearance")) return new LSL_Key(ScriptBaseClass.NULL_KEY); 3420 CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
2914 m_host.AddScriptLPS(1);
2915 3421
2916 return SaveAppearanceToNotecard(avatarId, notecard); 3422 return SaveAppearanceToNotecard(avatarId, notecard);
2917 } 3423 }
@@ -2923,7 +3429,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2923 if (appearanceModule != null) 3429 if (appearanceModule != null)
2924 { 3430 {
2925 appearanceModule.SaveBakedTextures(sp.UUID); 3431 appearanceModule.SaveBakedTextures(sp.UUID);
2926 OSDMap appearancePacked = sp.Appearance.Pack(); 3432 EntityTransferContext ctx = new EntityTransferContext();
3433 OSDMap appearancePacked = sp.Appearance.Pack(ctx);
2927 3434
2928 TaskInventoryItem item 3435 TaskInventoryItem item
2929 = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true); 3436 = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
@@ -2962,7 +3469,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2962 /// <returns>"male" or "female" or "unknown"</returns> 3469 /// <returns>"male" or "female" or "unknown"</returns>
2963 public LSL_String osGetGender(LSL_Key rawAvatarId) 3470 public LSL_String osGetGender(LSL_Key rawAvatarId)
2964 { 3471 {
2965 m_host.AddScriptLPS(1); 3472 CheckThreatLevel(ThreatLevel.None, "osGetGender");
2966 3473
2967 UUID avatarId; 3474 UUID avatarId;
2968 if (!UUID.TryParse(rawAvatarId, out avatarId)) 3475 if (!UUID.TryParse(rawAvatarId, out avatarId))
@@ -3005,7 +3512,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3005 /// <returns></returns> 3512 /// <returns></returns>
3006 public LSL_Key osGetMapTexture() 3513 public LSL_Key osGetMapTexture()
3007 { 3514 {
3008 m_host.AddScriptLPS(1); 3515 CheckThreatLevel();
3009 3516
3010 return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString(); 3517 return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
3011 } 3518 }
@@ -3017,7 +3524,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3017 /// <returns></returns> 3524 /// <returns></returns>
3018 public LSL_Key osGetRegionMapTexture(string regionName) 3525 public LSL_Key osGetRegionMapTexture(string regionName)
3019 { 3526 {
3020 m_host.AddScriptLPS(1); 3527 CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
3021 3528
3022 Scene scene = m_ScriptEngine.World; 3529 Scene scene = m_ScriptEngine.World;
3023 UUID key = UUID.Zero; 3530 UUID key = UUID.Zero;
@@ -3033,6 +3540,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3033 if (region != null) 3540 if (region != null)
3034 key = region.TerrainImage; 3541 key = region.TerrainImage;
3035 3542
3543 ScriptSleep(1000);
3544
3036 return key.ToString(); 3545 return key.ToString();
3037 } 3546 }
3038 3547
@@ -3045,7 +3554,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3045 /// <returns>List of floats</returns> 3554 /// <returns>List of floats</returns>
3046 public LSL_List osGetRegionStats() 3555 public LSL_List osGetRegionStats()
3047 { 3556 {
3048 m_host.AddScriptLPS(1); 3557 CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
3558
3049 LSL_List ret = new LSL_List(); 3559 LSL_List ret = new LSL_List();
3050 float[] stats = World.StatsReporter.LastReportedSimStats; 3560 float[] stats = World.StatsReporter.LastReportedSimStats;
3051 3561
@@ -3058,32 +3568,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3058 3568
3059 public LSL_Vector osGetRegionSize() 3569 public LSL_Vector osGetRegionSize()
3060 { 3570 {
3061 m_host.AddScriptLPS(1); 3571 CheckThreatLevel();
3062 3572
3063 bool isMegaregion; 3573 Scene scene = m_ScriptEngine.World;
3064 IRegionCombinerModule rcMod = World.RequestModuleInterface<IRegionCombinerModule>(); 3574 RegionInfo reg = World.RegionInfo;
3065 if (rcMod != null) 3575// GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID);
3066 isMegaregion = rcMod.IsRootForMegaregion(World.RegionInfo.RegionID); 3576// return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeY, (float)Constants.RegionHeight);
3067 else 3577 return new LSL_Vector((float)reg.RegionSizeX, (float)reg.RegionSizeY, 0.0f);
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 } 3578 }
3082 3579
3083 public int osGetSimulatorMemory() 3580 public int osGetSimulatorMemory()
3084 { 3581 {
3085 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory")) return 0; 3582 CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
3086 m_host.AddScriptLPS(1); 3583
3087 long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; 3584 long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
3088 3585
3089 if (pws > Int32.MaxValue) 3586 if (pws > Int32.MaxValue)
@@ -3094,10 +3591,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3094 return (int)pws; 3591 return (int)pws;
3095 } 3592 }
3096 3593
3594 public int osGetSimulatorMemoryKB()
3595 {
3596 CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemoryKB");
3597
3598 long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
3599
3600 if((pws & 0x3FFL) != 0)
3601 pws += 0x400L;
3602 pws >>= 10;
3603
3604 if (pws > Int32.MaxValue)
3605 return Int32.MaxValue;
3606
3607 return (int)pws;
3608 }
3609
3097 public void osSetSpeed(string UUID, LSL_Float SpeedModifier) 3610 public void osSetSpeed(string UUID, LSL_Float SpeedModifier)
3098 { 3611 {
3099 if (!CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed")) return; 3612 CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
3100 m_host.AddScriptLPS(1); 3613
3101 ScenePresence avatar = World.GetScenePresence(new UUID(UUID)); 3614 ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
3102 3615
3103 if (avatar != null) 3616 if (avatar != null)
@@ -3106,8 +3619,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3106 3619
3107 public void osKickAvatar(string FirstName, string SurName, string alert) 3620 public void osKickAvatar(string FirstName, string SurName, string alert)
3108 { 3621 {
3109 if (!CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar")) return; 3622 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
3110 m_host.AddScriptLPS(1);
3111 3623
3112 World.ForEachRootScenePresence(delegate(ScenePresence sp) 3624 World.ForEachRootScenePresence(delegate(ScenePresence sp)
3113 { 3625 {
@@ -3125,23 +3637,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3125 3637
3126 public LSL_Float osGetHealth(string avatar) 3638 public LSL_Float osGetHealth(string avatar)
3127 { 3639 {
3128 m_host.AddScriptLPS(1); 3640 CheckThreatLevel(ThreatLevel.None, "osGetHealth");
3129 3641
3130 LSL_Float health = new LSL_Float(-1); 3642 LSL_Float health = new LSL_Float(-1);
3131 ScenePresence presence = World.GetScenePresence(new UUID(avatar)); 3643 ScenePresence presence = World.GetScenePresence(new UUID(avatar));
3132 if (presence != null) health = presence.Health; 3644 if (presence != null)
3645 health = presence.Health;
3133 return health; 3646 return health;
3134 } 3647 }
3135 3648
3136 public void osCauseDamage(string avatar, double damage) 3649 public void osCauseDamage(string avatar, double damage)
3137 { 3650 {
3138 if (!CheckThreatLevel(ThreatLevel.High, "osCauseDamage")) return; 3651 CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
3139 m_host.AddScriptLPS(1);
3140 3652
3141 UUID avatarId = new UUID(avatar); 3653 UUID avatarId = new UUID(avatar);
3142 Vector3 pos = m_host.GetWorldPosition(); 3654 Vector3 pos = m_host.GetWorldPosition();
3143 3655
3144 ScenePresence presence = World.GetScenePresence(avatarId); 3656 ScenePresence presence = World.GetScenePresence(avatarId);
3145 if (presence != null) 3657 if (presence != null)
3146 { 3658 {
3147 LandData land = World.GetLandData(pos); 3659 LandData land = World.GetLandData(pos);
@@ -3163,13 +3675,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3163 3675
3164 public void osCauseHealing(string avatar, double healing) 3676 public void osCauseHealing(string avatar, double healing)
3165 { 3677 {
3166 if (!CheckThreatLevel(ThreatLevel.High, "osCauseHealing")) return; 3678 CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
3167 m_host.AddScriptLPS(1);
3168 3679
3169 UUID avatarId = new UUID(avatar); 3680 UUID avatarId = new UUID(avatar);
3170 ScenePresence presence = World.GetScenePresence(avatarId); 3681 ScenePresence presence = World.GetScenePresence(avatarId);
3171 3682
3172 if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition())) 3683 if (presence != null)
3173 { 3684 {
3174 float health = presence.Health; 3685 float health = presence.Health;
3175 health += (float)healing; 3686 health += (float)healing;
@@ -3181,31 +3692,67 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3181 } 3692 }
3182 } 3693 }
3183 3694
3695 public void osSetHealth(string avatar, double health)
3696 {
3697 CheckThreatLevel(ThreatLevel.High, "osSetHealth");
3698
3699 UUID avatarId = new UUID(avatar);
3700 ScenePresence presence = World.GetScenePresence(avatarId);
3701
3702 if (presence != null)
3703 {
3704 if (health > 100.0)
3705 health = 100.0;
3706 else if (health < 1.0)
3707 health = 1.0;
3708
3709 presence.setHealthWithUpdate((float)health);
3710 }
3711 }
3712
3713 public void osSetHealRate(string avatar, double healrate)
3714 {
3715 CheckThreatLevel(ThreatLevel.High, "osSetHealRate");
3716
3717 UUID avatarId = new UUID(avatar);
3718 ScenePresence presence = World.GetScenePresence(avatarId);
3719
3720 if (presence != null)
3721 presence.HealRate = (float)healrate;
3722 }
3723
3724 public LSL_Float osGetHealRate(string avatar)
3725 {
3726 CheckThreatLevel(ThreatLevel.None, "osGetHealRate");
3727
3728 LSL_Float rate = new LSL_Float(0);
3729 ScenePresence presence = World.GetScenePresence(new UUID(avatar));
3730 if (presence != null)
3731 rate = presence.HealRate;
3732 return rate;
3733 }
3734
3184 public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules) 3735 public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
3185 { 3736 {
3186 if (!CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams")) return new LSL_List(); 3737 CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
3187 m_host.AddScriptLPS(1);
3188 InitLSL();
3189 3738
3739 InitLSL();
3190 return m_LSL_Api.GetPrimitiveParamsEx(prim, rules); 3740 return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
3191 } 3741 }
3192 3742
3193 public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules) 3743 public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
3194 { 3744 {
3195 if (!CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams")) return; 3745 CheckThreatLevel(ThreatLevel.High, "osSetPrimitiveParams");
3196 m_host.AddScriptLPS(1);
3197 InitLSL();
3198 3746
3747 InitLSL();
3199 m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams"); 3748 m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
3200 } 3749 }
3201 3750
3202 /// <summary> 3751 /// <summary>
3203 /// Set parameters for light projection in host prim 3752 /// Set parameters for light projection in host prim
3204 /// </summary> 3753 /// </summary>
3205 public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb) 3754 public void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb)
3206 { 3755 {
3207 if (!CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams")) return;
3208
3209 osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb); 3756 osSetProjectionParams(UUID.Zero.ToString(), projection, texture, fov, focus, amb);
3210 } 3757 }
3211 3758
@@ -3214,8 +3761,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3214 /// </summary> 3761 /// </summary>
3215 public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb) 3762 public void osSetProjectionParams(LSL_Key prim, bool projection, LSL_Key texture, double fov, double focus, double amb)
3216 { 3763 {
3217 if (!CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams")) return; 3764 CheckThreatLevel(ThreatLevel.High, "osSetProjectionParams");
3218 m_host.AddScriptLPS(1);
3219 3765
3220 SceneObjectPart obj = null; 3766 SceneObjectPart obj = null;
3221 if (prim == UUID.Zero.ToString()) 3767 if (prim == UUID.Zero.ToString())
@@ -3245,12 +3791,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3245 /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns> 3791 /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
3246 public LSL_List osGetAvatarList() 3792 public LSL_List osGetAvatarList()
3247 { 3793 {
3248 m_host.AddScriptLPS(1); 3794 CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
3249 3795
3250 LSL_List result = new LSL_List(); 3796 LSL_List result = new LSL_List();
3251 World.ForEachRootScenePresence(delegate (ScenePresence avatar) 3797 World.ForEachRootScenePresence(delegate (ScenePresence avatar)
3252 { 3798 {
3253 if (avatar != null && avatar.UUID != m_host.OwnerID) 3799 if (avatar != null && !avatar.IsDeleted && avatar.UUID != m_host.OwnerID )
3800 {
3801 result.Add(new LSL_String(avatar.UUID.ToString()));
3802 result.Add(new LSL_Vector(avatar.AbsolutePosition));
3803 result.Add(new LSL_String(avatar.Name));
3804 }
3805 });
3806
3807 return result;
3808 }
3809
3810 public LSL_List osGetNPCList()
3811 {
3812 CheckThreatLevel(ThreatLevel.None, "osGetNPCList");
3813
3814 LSL_List result = new LSL_List();
3815 World.ForEachRootScenePresence(delegate (ScenePresence avatar)
3816 {
3817 // npcs are not childagents but that is now.
3818 if (avatar != null && avatar.IsNPC && !avatar.IsDeleted && !avatar.IsChildAgent && !avatar.IsInTransit)
3254 { 3819 {
3255 result.Add(new LSL_String(avatar.UUID.ToString())); 3820 result.Add(new LSL_String(avatar.UUID.ToString()));
3256 result.Add(new LSL_Vector(avatar.AbsolutePosition)); 3821 result.Add(new LSL_Vector(avatar.AbsolutePosition));
@@ -3268,7 +3833,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3268 /// <returns></returns> 3833 /// <returns></returns>
3269 public LSL_String osUnixTimeToTimestamp(long time) 3834 public LSL_String osUnixTimeToTimestamp(long time)
3270 { 3835 {
3271 m_host.AddScriptLPS(1); 3836 CheckThreatLevel(ThreatLevel.VeryLow, "osUnixTimeToTimestamp");
3272 3837
3273 long baseTicks = 621355968000000000; 3838 long baseTicks = 621355968000000000;
3274 long tickResolution = 10000000; 3839 long tickResolution = 10000000;
@@ -3282,10 +3847,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3282 /// Get the description from an inventory item 3847 /// Get the description from an inventory item
3283 /// </summary> 3848 /// </summary>
3284 /// <param name="inventoryName"></param> 3849 /// <param name="inventoryName"></param>
3285 /// <returns>Item description</returns> 3850 /// <returns>Item description</returns>
3286 public LSL_String osGetInventoryDesc(string item) 3851 public LSL_String osGetInventoryDesc(string item)
3287 { 3852 {
3288 m_host.AddScriptLPS(1); 3853 CheckThreatLevel();
3289 3854
3290 lock (m_host.TaskInventory) 3855 lock (m_host.TaskInventory)
3291 { 3856 {
@@ -3308,8 +3873,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3308 /// <returns></returns> 3873 /// <returns></returns>
3309 public LSL_Integer osInviteToGroup(LSL_Key agentId) 3874 public LSL_Integer osInviteToGroup(LSL_Key agentId)
3310 { 3875 {
3311 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup")) return ScriptBaseClass.FALSE; 3876 CheckThreatLevel(ThreatLevel.VeryLow, "osInviteToGroup");
3312 m_host.AddScriptLPS(1);
3313 3877
3314 UUID agent = new UUID(agentId); 3878 UUID agent = new UUID(agentId);
3315 3879
@@ -3343,8 +3907,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3343 /// <returns></returns> 3907 /// <returns></returns>
3344 public LSL_Integer osEjectFromGroup(LSL_Key agentId) 3908 public LSL_Integer osEjectFromGroup(LSL_Key agentId)
3345 { 3909 {
3346 if (!CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup")) return ScriptBaseClass.FALSE; 3910 CheckThreatLevel(ThreatLevel.VeryLow, "osEjectFromGroup");
3347 m_host.AddScriptLPS(1);
3348 3911
3349 UUID agent = new UUID(agentId); 3912 UUID agent = new UUID(agentId);
3350 3913
@@ -3378,9 +3941,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3378 /// <returns></returns> 3941 /// <returns></returns>
3379 public void osSetTerrainTexture(int level, LSL_Key texture) 3942 public void osSetTerrainTexture(int level, LSL_Key texture)
3380 { 3943 {
3381 if (!CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture")) return; 3944 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3382 3945
3383 m_host.AddScriptLPS(1);
3384 //Check to make sure that the script's owner is the estate manager/master 3946 //Check to make sure that the script's owner is the estate manager/master
3385 //World.Permissions.GenericEstatePermission( 3947 //World.Permissions.GenericEstatePermission(
3386 if (World.Permissions.IsGod(m_host.OwnerID)) 3948 if (World.Permissions.IsGod(m_host.OwnerID))
@@ -3408,9 +3970,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3408 /// <returns></returns> 3970 /// <returns></returns>
3409 public void osSetTerrainTextureHeight(int corner, double low, double high) 3971 public void osSetTerrainTextureHeight(int corner, double low, double high)
3410 { 3972 {
3411 if (!CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight")) return; 3973 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3412 3974
3413 m_host.AddScriptLPS(1);
3414 //Check to make sure that the script's owner is the estate manager/master 3975 //Check to make sure that the script's owner is the estate manager/master
3415 //World.Permissions.GenericEstatePermission( 3976 //World.Permissions.GenericEstatePermission(
3416 if (World.Permissions.IsGod(m_host.OwnerID)) 3977 if (World.Permissions.IsGod(m_host.OwnerID))
@@ -3429,9 +3990,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3429 3990
3430 public void osForceAttachToAvatar(int attachmentPoint) 3991 public void osForceAttachToAvatar(int attachmentPoint)
3431 { 3992 {
3432 if (!CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar")) return; 3993 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3433
3434 m_host.AddScriptLPS(1);
3435 3994
3436 InitLSL(); 3995 InitLSL();
3437 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint); 3996 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
@@ -3439,18 +3998,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3439 3998
3440 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint) 3999 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
3441 { 4000 {
3442 if (!CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory")) return; 4001 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
3443
3444 m_host.AddScriptLPS(1);
3445 4002
3446 ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint); 4003 ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
3447 } 4004 }
3448 4005
3449 public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint) 4006 public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
3450 { 4007 {
3451 if (!CheckThreatLevel(ThreatLevel.Severe, "osForceAttachToOtherAvatarFromInventory")) return; 4008 CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory");
3452
3453 m_host.AddScriptLPS(1);
3454 4009
3455 UUID avatarId; 4010 UUID avatarId;
3456 4011
@@ -3480,7 +4035,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3480 if (item.InvType != (int)InventoryType.Object) 4035 if (item.InvType != (int)InventoryType.Object)
3481 { 4036 {
3482 // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set 4037 // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
3483 // up the api reference. 4038 // up the api reference.
3484 if (m_LSL_Api != null) 4039 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)); 4040 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
3486 4041
@@ -3509,9 +4064,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3509 4064
3510 public void osForceDetachFromAvatar() 4065 public void osForceDetachFromAvatar()
3511 { 4066 {
3512 if (!CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar")) return; 4067 CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3513
3514 m_host.AddScriptLPS(1);
3515 4068
3516 InitLSL(); 4069 InitLSL();
3517 ((LSL_Api)m_LSL_Api).DetachFromAvatar(); 4070 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
@@ -3519,9 +4072,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3519 4072
3520 public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints) 4073 public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
3521 { 4074 {
3522 if (!CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments")) return new LSL_List(); 4075 CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
3523
3524 m_host.AddScriptLPS(1);
3525 4076
3526 UUID targetUUID; 4077 UUID targetUUID;
3527 ScenePresence target; 4078 ScenePresence target;
@@ -3555,15 +4106,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3555 4106
3556 public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options) 4107 public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
3557 { 4108 {
3558 if (!CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments")) return; 4109 CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
3559 m_host.AddScriptLPS(1);
3560 4110
3561 UUID targetUUID; 4111 UUID targetUUID;
4112 if(!UUID.TryParse(avatar.ToString(), out targetUUID))
4113 return;
4114
4115 if(targetUUID == UUID.Zero)
4116 return;
4117
3562 ScenePresence target; 4118 ScenePresence target;
4119 if(!World.TryGetScenePresence(targetUUID, out target))
4120 return;
3563 4121
3564 if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target)) 4122 if(target.IsDeleted || target.IsInTransit)
4123 return;
4124
4125 List<int> aps = new List<int>();
4126 if(attachmentPoints.Length != 0)
3565 { 4127 {
3566 List<int> aps = new List<int>();
3567 foreach (object point in attachmentPoints.Data) 4128 foreach (object point in attachmentPoints.Data)
3568 { 4129 {
3569 int ipoint; 4130 int ipoint;
@@ -3572,115 +4133,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3572 aps.Add(ipoint); 4133 aps.Add(ipoint);
3573 } 4134 }
3574 } 4135 }
4136 // parsing failed
4137 if(aps.Count != attachmentPoints.Length)
4138 return;
4139 }
3575 4140
3576 List<SceneObjectGroup> attachments = new List<SceneObjectGroup>(); 4141 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 4142
3581 if (msgAll && invertPoints) 4143 bool msgAll;
3582 { 4144 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 4145
3600 // if we have no attachments at this point, exit now 4146 if(aps.Count == 0)
3601 if (attachments.Count == 0) 4147 {
3602 { 4148 if(!invertPoints)
3603 return; 4149 return;
3604 } 4150 msgAll = true;
4151 invertPoints = false;
4152 }
4153 else
4154 msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
3605 4155
3606 List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>(); 4156 if (msgAll && invertPoints)
4157 return;
3607 4158
3608 if (invertPoints) 4159 if (msgAll || invertPoints)
4160 {
4161 attachments = target.GetAttachments();
4162 }
4163 else
4164 {
4165 foreach (int point in aps)
3609 { 4166 {
3610 foreach (SceneObjectGroup attachment in attachments) 4167 if (point > 0)
3611 { 4168 {
3612 if (aps.Contains((int)attachment.AttachmentPoint)) 4169 attachments.AddRange(target.GetAttachments((uint)point));
3613 {
3614 ignoreThese.Add(attachment);
3615 }
3616 } 4170 }
3617 } 4171 }
4172 }
3618 4173
3619 foreach (SceneObjectGroup attachment in ignoreThese) 4174 // if we have no attachments at this point, exit now
3620 { 4175 if (attachments.Count == 0)
3621 attachments.Remove(attachment); 4176 {
3622 } 4177 return;
3623 ignoreThese.Clear(); 4178 }
3624
3625 // if inverting removed all attachments to check, exit now
3626 if (attachments.Count < 1)
3627 {
3628 return;
3629 }
3630 4179
3631 if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0) 4180 bool optionObjCreator = (options &
3632 { 4181 ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0;
3633 foreach (SceneObjectGroup attachment in attachments) 4182 bool optionScriptCreator = (options &
3634 { 4183 ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0;
3635 if (attachment.RootPart.CreatorID != m_host.CreatorID)
3636 {
3637 ignoreThese.Add(attachment);
3638 }
3639 }
3640 4184
3641 foreach (SceneObjectGroup attachment in ignoreThese) 4185 UUID hostCreatorID = m_host.CreatorID;
3642 { 4186 UUID itemCreatorID = m_item.CreatorID;
3643 attachments.Remove(attachment);
3644 }
3645 ignoreThese.Clear();
3646 4187
3647 // if filtering by same object creator removed all 4188 foreach (SceneObjectGroup sog in attachments)
3648 // attachments to check, exit now 4189 {
3649 if (attachments.Count == 0) 4190 if(sog.IsDeleted || sog.inTransit)
3650 { 4191 continue;
3651 return;
3652 }
3653 }
3654 4192
3655 if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0) 4193 if (invertPoints && aps.Contains((int)sog.AttachmentPoint))
3656 { 4194 continue;
3657 foreach (SceneObjectGroup attachment in attachments)
3658 {
3659 if (attachment.RootPart.CreatorID != m_item.CreatorID)
3660 {
3661 ignoreThese.Add(attachment);
3662 }
3663 }
3664 4195
3665 foreach (SceneObjectGroup attachment in ignoreThese) 4196 UUID CreatorID = sog.RootPart.CreatorID;
3666 { 4197 if (optionObjCreator && CreatorID != hostCreatorID)
3667 attachments.Remove(attachment); 4198 continue;
3668 }
3669 ignoreThese.Clear();
3670 4199
3671 // if filtering by object creator must match originating 4200 if (optionScriptCreator && CreatorID != itemCreatorID)
3672 // script creator removed all attachments to check, 4201 continue;
3673 // exit now
3674 if (attachments.Count == 0)
3675 {
3676 return;
3677 }
3678 }
3679 4202
3680 foreach (SceneObjectGroup attachment in attachments) 4203 SceneObjectPart[] parts = sog.Parts;
3681 { 4204 foreach(SceneObjectPart p in parts)
3682 MessageObject(attachment.RootPart.UUID, message); 4205 MessageObject(p.UUID, message);
3683 }
3684 } 4206 }
3685 } 4207 }
3686 4208
@@ -3693,7 +4215,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3693 /// <returns>1 if thing is a valid UUID, 0 otherwise</returns> 4215 /// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
3694 public LSL_Integer osIsUUID(string thing) 4216 public LSL_Integer osIsUUID(string thing)
3695 { 4217 {
3696 m_host.AddScriptLPS(1); 4218 CheckThreatLevel();
3697 4219
3698 UUID test; 4220 UUID test;
3699 return UUID.TryParse(thing, out test) ? 1 : 0; 4221 return UUID.TryParse(thing, out test) ? 1 : 0;
@@ -3707,7 +4229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3707 /// <returns></returns> 4229 /// <returns></returns>
3708 public LSL_Float osMin(double a, double b) 4230 public LSL_Float osMin(double a, double b)
3709 { 4231 {
3710 m_host.AddScriptLPS(1); 4232 CheckThreatLevel();
3711 4233
3712 return Math.Min(a, b); 4234 return Math.Min(a, b);
3713 } 4235 }
@@ -3720,16 +4242,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3720 /// <returns></returns> 4242 /// <returns></returns>
3721 public LSL_Float osMax(double a, double b) 4243 public LSL_Float osMax(double a, double b)
3722 { 4244 {
3723 m_host.AddScriptLPS(1); 4245 CheckThreatLevel();
3724 4246
3725 return Math.Max(a, b); 4247 return Math.Max(a, b);
3726 } 4248 }
3727 4249
3728 public LSL_Key osGetRezzingObject() 4250 public LSL_Key osGetRezzingObject()
3729 { 4251 {
3730 m_host.AddScriptLPS(1); 4252 CheckThreatLevel(ThreatLevel.None, "osGetRezzingObject");
3731 4253
3732 return new LSL_Key(m_host.ParentGroup.FromPartID.ToString()); 4254 UUID rezID = m_host.ParentGroup.RezzerID;
4255 if(rezID == UUID.Zero || m_host.ParentGroup.Scene.GetScenePresence(rezID) != null)
4256 return new LSL_Key(UUID.Zero.ToString());
4257 return new LSL_Key(rezID.ToString());
3733 } 4258 }
3734 4259
3735 /// <summary> 4260 /// <summary>
@@ -3738,7 +4263,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3738 /// <returns></returns> 4263 /// <returns></returns>
3739 public void osSetContentType(LSL_Key id, string type) 4264 public void osSetContentType(LSL_Key id, string type)
3740 { 4265 {
3741 if (!CheckThreatLevel(ThreatLevel.High, "osSetContentType")) return; 4266 CheckThreatLevel(ThreatLevel.High, "osSetContentType");
3742 4267
3743 if (m_UrlModule != null) 4268 if (m_UrlModule != null)
3744 m_UrlModule.HttpContentType(new UUID(id),type); 4269 m_UrlModule.HttpContentType(new UUID(id),type);
@@ -3750,7 +4275,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3750 /// <returns>boolean indicating whether an error was shouted.</returns> 4275 /// <returns>boolean indicating whether an error was shouted.</returns>
3751 protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix) 4276 protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
3752 { 4277 {
3753 m_host.AddScriptLPS(1);
3754 bool fail = false; 4278 bool fail = false;
3755 if (m_item.PermsGranter != m_host.OwnerID) 4279 if (m_item.PermsGranter != m_host.OwnerID)
3756 { 4280 {
@@ -3800,39 +4324,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3800 4324
3801 public void osDropAttachment() 4325 public void osDropAttachment()
3802 { 4326 {
3803 if (!CheckThreatLevel(ThreatLevel.Low, "osDropAttachment")) return; 4327 CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
3804 m_host.AddScriptLPS(1);
3805 4328
3806 DropAttachment(true); 4329 DropAttachment(true);
3807 } 4330 }
3808 4331
3809 public void osForceDropAttachment() 4332 public void osForceDropAttachment()
3810 { 4333 {
3811 if (!CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment")) return; 4334 CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
3812 m_host.AddScriptLPS(1);
3813 4335
3814 DropAttachment(false); 4336 DropAttachment(false);
3815 } 4337 }
3816 4338
3817 public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) 4339 public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
3818 { 4340 {
3819 if (!CheckThreatLevel(ThreatLevel.Low, "osDropAttachmentAt")) return; 4341 CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
3820 m_host.AddScriptLPS(1);
3821 4342
3822 DropAttachmentAt(true, pos, rot); 4343 DropAttachmentAt(true, pos, rot);
3823 } 4344 }
3824 4345
3825 public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) 4346 public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
3826 { 4347 {
3827 if (!CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt")) return; 4348 CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
3828 m_host.AddScriptLPS(1);
3829 4349
3830 DropAttachmentAt(false, pos, rot); 4350 DropAttachmentAt(false, pos, rot);
3831 } 4351 }
3832 4352
3833 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) 4353 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
3834 { 4354 {
3835 m_host.AddScriptLPS(1); 4355 CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
4356
3836 UUID keyID; 4357 UUID keyID;
3837 UUID.TryParse(ID, out keyID); 4358 UUID.TryParse(ID, out keyID);
3838 4359
@@ -3879,7 +4400,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3879 4400
3880 public LSL_Integer osRegexIsMatch(string input, string pattern) 4401 public LSL_Integer osRegexIsMatch(string input, string pattern)
3881 { 4402 {
3882 m_host.AddScriptLPS(1); 4403 CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
4404
3883 try 4405 try
3884 { 4406 {
3885 return Regex.IsMatch(input, pattern) ? 1 : 0; 4407 return Regex.IsMatch(input, pattern) ? 1 : 0;
@@ -3890,5 +4412,392 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3890 return 0; 4412 return 0;
3891 } 4413 }
3892 } 4414 }
4415
4416 public LSL_String osRequestURL(LSL_List options)
4417 {
4418 CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
4419
4420 Hashtable opts = new Hashtable();
4421 for (int i = 0 ; i < options.Length ; i++)
4422 {
4423 object opt = options.Data[i];
4424 if (opt.ToString() == "allowXss")
4425 opts["allowXss"] = true;
4426 }
4427
4428 if (m_UrlModule != null)
4429 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4430 return UUID.Zero.ToString();
4431 }
4432
4433 public LSL_String osRequestSecureURL(LSL_List options)
4434 {
4435 CheckThreatLevel(ThreatLevel.Moderate, "osRequestSecureURL");
4436
4437 Hashtable opts = new Hashtable();
4438 for (int i = 0 ; i < options.Length ; i++)
4439 {
4440 object opt = options.Data[i];
4441 if (opt.ToString() == "allowXss")
4442 opts["allowXss"] = true;
4443 }
4444
4445 if (m_UrlModule != null)
4446 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, opts).ToString();
4447 return UUID.Zero.ToString();
4448 }
4449
4450 public void osCollisionSound(string impact_sound, double impact_volume)
4451 {
4452 CheckThreatLevel();
4453
4454 if(impact_sound == "")
4455 {
4456 m_host.CollisionSoundVolume = (float)impact_volume;
4457 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
4458 if(impact_volume == 0.0)
4459 m_host.CollisionSoundType = -1; // disable all sounds
4460 else if(impact_volume == 1.0f)
4461 m_host.CollisionSoundType = 0; // full return to default sounds
4462 else
4463 m_host.CollisionSoundType = 2; // default sounds with volume
4464 m_host.aggregateScriptEvents();
4465 return;
4466 }
4467 // TODO: Parameter check logic required.
4468 UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
4469 if(soundId != UUID.Zero)
4470 {
4471 m_host.CollisionSound = soundId;
4472 m_host.CollisionSoundVolume = (float)impact_volume;
4473 m_host.CollisionSoundType = 1;
4474 }
4475 else
4476 m_host.CollisionSoundType = -1;
4477
4478 m_host.aggregateScriptEvents();
4479 }
4480
4481 // still not very usefull, detector is lost on rez, restarts, etc
4482 public void osVolumeDetect(int detect)
4483 {
4484 CheckThreatLevel();
4485
4486 if (m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted || m_host.ParentGroup.IsAttachment)
4487 return;
4488
4489 m_host.ScriptSetVolumeDetect(detect != 0);
4490 }
4491
4492 /// <summary>
4493 /// Get inertial data
4494 /// </summary>
4495 /// <remarks>
4496 /// </remarks>
4497 /// <returns>
4498 /// a LSL list with contents:
4499 /// LSL_Float mass, the total mass of a linkset
4500 /// LSL_Vector CenterOfMass, center mass relative to root prim
4501 /// LSL_Vector Inertia, elements of diagonal of inertia Ixx,Iyy,Izz divided by total mass
4502 /// LSL_Vector aux, elements of upper triagle of inertia Ixy (= Iyx), Ixz (= Izx), Iyz(= Izy) divided by total mass
4503 /// </returns>
4504 public LSL_List osGetInertiaData()
4505 {
4506 CheckThreatLevel();
4507
4508 LSL_List result = new LSL_List();
4509 float TotalMass;
4510 Vector3 CenterOfMass;
4511 Vector3 Inertia;
4512 Vector4 aux;
4513
4514 SceneObjectGroup sog = m_host.ParentGroup;
4515 if(sog== null || sog.IsDeleted)
4516 return result;
4517
4518 sog.GetInertiaData(out TotalMass, out CenterOfMass, out Inertia, out aux );
4519 if(TotalMass > 0)
4520 {
4521 float t = 1.0f/TotalMass;
4522 Inertia.X *= t;
4523 Inertia.Y *= t;
4524 Inertia.Z *= t;
4525
4526 aux.X *= t;
4527 aux.Y *= t;
4528 aux.Z *= t;
4529 }
4530
4531 result.Add(new LSL_Float(TotalMass));
4532 result.Add(new LSL_Vector(CenterOfMass.X, CenterOfMass.Y, CenterOfMass.Z));
4533 result.Add(new LSL_Vector(Inertia.X, Inertia.Y, Inertia.Z));
4534 result.Add(new LSL_Vector(aux.X, aux.Y, aux.Z));
4535 return result;
4536 }
4537
4538 /// <summary>
4539 /// set inertial data
4540 /// replaces the automatic calculation of mass, center of mass and inertia
4541 ///
4542 /// </summary>
4543 /// <param name="Mass">total mass of linkset</param>
4544 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4545 /// <param name="principalInertiaScaled">moment of inertia relative to principal axis and center of mass,Ixx, Iyy, Izz divided by mass</param>
4546 /// <param name="lslrot">rotation of the inertia, relative to local axis</param>
4547 /// <remarks>
4548 /// the inertia argument is is inertia divided by mass, so corresponds only to the geometric distribution of mass and both can be changed independently.
4549 /// </remarks>
4550
4551 public void osSetInertia(LSL_Float mass, LSL_Vector centerOfMass, LSL_Vector principalInertiaScaled, LSL_Rotation lslrot)
4552 {
4553 CheckThreatLevel();
4554
4555 SceneObjectGroup sog = m_host.ParentGroup;
4556 if(sog== null || sog.IsDeleted)
4557 return;
4558
4559 if(mass < 0 || principalInertiaScaled.x < 0 || principalInertiaScaled.y < 0 || principalInertiaScaled.z < 0)
4560 return;
4561
4562 // need more checks
4563
4564 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4565 Vector3 Inertia;
4566 float m = (float)mass;
4567
4568 Inertia.X = m * (float)principalInertiaScaled.x;
4569 Inertia.Y = m * (float)principalInertiaScaled.y;
4570 Inertia.Z = m * (float)principalInertiaScaled.z;
4571
4572 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.y, (float)lslrot.s);
4573 rot.Normalize();
4574
4575 sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
4576 }
4577
4578 /// <summary>
4579 /// set inertial data as a sphere
4580 /// replaces the automatic calculation of mass, center of mass and inertia
4581 ///
4582 /// </summary>
4583 /// <param name="Mass">total mass of linkset</param>
4584 /// <param name="boxsize">size of the Box</param>
4585 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4586 /// <param name="lslrot">rotation of the box, and so inertia, relative to local axis</param>
4587 /// <remarks>
4588 /// </remarks>
4589 public void osSetInertiaAsBox(LSL_Float mass, LSL_Vector boxSize, LSL_Vector centerOfMass, LSL_Rotation lslrot)
4590 {
4591 CheckThreatLevel();
4592
4593 SceneObjectGroup sog = m_host.ParentGroup;
4594 if(sog== null || sog.IsDeleted)
4595 return;
4596
4597 if(mass < 0)
4598 return;
4599
4600 // need more checks
4601
4602 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4603 Vector3 Inertia;
4604 float lx = (float)boxSize.x;
4605 float ly = (float)boxSize.y;
4606 float lz = (float)boxSize.z;
4607 float m = (float)mass;
4608 float t = m / 12.0f;
4609
4610 Inertia.X = t * (ly*ly + lz*lz);
4611 Inertia.Y = t * (lx*lx + lz*lz);
4612 Inertia.Z = t * (lx*lx + ly*ly);
4613
4614 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
4615 rot.Normalize();
4616
4617 sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
4618 }
4619
4620 /// <summary>
4621 /// set inertial data as a sphere
4622 /// replaces the automatic calculation of mass, center of mass and inertia
4623 ///
4624 /// </summary>
4625 /// <param name="Mass">total mass of linkset</param>
4626 /// <param name="radius">radius of the sphere</param>
4627 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4628 /// <remarks>
4629 /// </remarks>
4630 public void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, LSL_Vector centerOfMass)
4631 {
4632 CheckThreatLevel();
4633
4634 SceneObjectGroup sog = m_host.ParentGroup;
4635 if(sog== null || sog.IsDeleted)
4636 return;
4637
4638 if(mass < 0)
4639 return;
4640
4641 // need more checks
4642
4643 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4644 Vector3 Inertia;
4645 float r = (float)radius;
4646 float m = (float)mass;
4647 float t = 0.4f * m * r * r;
4648
4649 Inertia.X = t;
4650 Inertia.Y = t;
4651 Inertia.Z = t;
4652
4653 sog.SetInertiaData(m, CenterOfMass, Inertia, new Vector4(0f, 0f, 0f,1.0f));
4654 }
4655
4656 /// <summary>
4657 /// set inertial data as a cylinder
4658 /// replaces the automatic calculation of mass, center of mass and inertia
4659 ///
4660 /// </summary>
4661 /// <param name="Mass">total mass of linkset</param>
4662 /// <param name="radius">radius of the cylinder</param>
4663 /// <param name="lenght">lenght of the cylinder</param>
4664 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4665 /// <param name="lslrot">rotation of the cylinder, and so inertia, relative to local axis</param>
4666 /// <remarks>
4667 /// cylinder axis aligned with Z axis. For other orientations provide the rotation.
4668 /// </remarks>
4669 public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, LSL_Vector centerOfMass, LSL_Rotation lslrot)
4670 {
4671 CheckThreatLevel();
4672
4673 SceneObjectGroup sog = m_host.ParentGroup;
4674 if(sog== null || sog.IsDeleted)
4675 return;
4676
4677 if(mass < 0)
4678 return;
4679
4680 // need more checks
4681
4682 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4683 Vector3 Inertia;
4684 float m = (float)mass;
4685 float r = (float)radius;
4686 r *= r;
4687 Inertia.Z = 0.5f * m * r;
4688 float t = (float)lenght;
4689 t *= t;
4690 t += 3.0f * r;
4691 t *= 8.333333e-2f * m;
4692
4693 Inertia.X = t;
4694 Inertia.Y = t;
4695
4696 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
4697 rot.Normalize();
4698
4699 sog.SetInertiaData(m, CenterOfMass, Inertia, rot);
4700 }
4701
4702 /// <summary>
4703 /// removes inertial data manual override
4704 /// default automatic calculation is used again
4705 ///
4706 /// </summary>
4707 public void osClearInertia()
4708 {
4709 CheckThreatLevel();
4710
4711 SceneObjectGroup sog = m_host.ParentGroup;
4712 if(sog== null || sog.IsDeleted)
4713 return;
4714
4715 sog.SetInertiaData(-1, Vector3.Zero, Vector3.Zero, Vector4.Zero );
4716 }
4717
4718 private bool checkAllowObjectTPbyLandOwner(Vector3 pos)
4719 {
4720 ILandObject land = World.LandChannel.GetLandObject(pos);
4721 if(land == null)
4722 return true;
4723
4724 LandData landdata = land.LandData;
4725 if(landdata == null)
4726 return true;
4727
4728 UUID hostOwner = m_host.OwnerID;
4729 if(landdata.OwnerID == hostOwner)
4730 return true;
4731
4732 EstateSettings es = World.RegionInfo.EstateSettings;
4733 if(es != null && es.IsEstateManagerOrOwner(hostOwner))
4734 return true;
4735
4736 if(!landdata.IsGroupOwned)
4737 return false;
4738
4739 UUID landGroup = landdata.GroupID;
4740 if(landGroup == UUID.Zero)
4741 return false;
4742
4743 if(landGroup == m_host.GroupID)
4744 return true;
4745
4746 return false;
4747 }
4748
4749 /// <summary>
4750 /// teleports a object (full linkset)
4751 /// </summary>
4752 /// <param name="objectUUID">the id of the linkset to teleport</param>
4753 /// <param name="targetPos">target position</param>
4754 /// <param name="rotation"> a rotation to apply</param>
4755 /// <param name="flags">several flags/param>
4756 /// <remarks>
4757 /// only does teleport local to region
4758 /// if object has scripts, owner must have rights to run scripts on target location
4759 /// object owner must have rights to enter ojects on target location
4760 /// target location parcel must have enought free prims capacity for the linkset prims
4761 /// all avatars siting on the object must have access to target location
4762 /// has a cool down time. retries before expire reset it
4763 /// fail conditions are silent ignored
4764 /// </remarks>
4765 public LSL_Integer osTeleportObject(LSL_Key objectUUID, LSL_Vector targetPos, LSL_Rotation rotation, LSL_Integer flags)
4766 {
4767 CheckThreatLevel(ThreatLevel.Severe, "osTeleportObject");
4768
4769 UUID objUUID;
4770 if (!UUID.TryParse(objectUUID, out objUUID))
4771 {
4772 OSSLShoutError("osTeleportObject() invalid object Key");
4773 return -1;
4774 }
4775
4776 SceneObjectGroup sog = World.GetSceneObjectGroup(objUUID);
4777 if(sog== null || sog.IsDeleted || sog.inTransit)
4778 return -1;
4779
4780 if(sog.OwnerID != m_host.OwnerID)
4781 {
4782 Vector3 pos = sog.AbsolutePosition;
4783 if(!checkAllowObjectTPbyLandOwner(pos))
4784 return -1;
4785 }
4786
4787 UUID myid = m_host.ParentGroup.UUID;
4788
4789 return sog.TeleportObject(myid, targetPos, rotation, flags);
4790 // a delay here may break vehicles
4791 }
4792
4793 public LSL_Integer osGetLinkNumber(LSL_String name)
4794 {
4795 CheckThreatLevel();
4796
4797 SceneObjectGroup sog = m_host.ParentGroup;
4798 if(sog== null || sog.IsDeleted)
4799 return -1;
4800 return sog.GetLinkNumber(name);
4801 }
3893 } 4802 }
3894} 4803}