diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 157 |
1 files changed, 118 insertions, 39 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 415166a..f4e4f44 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -139,6 +139,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
139 | internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; | 139 | internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; |
140 | internal float m_ScriptDelayFactor = 1.0f; | 140 | internal float m_ScriptDelayFactor = 1.0f; |
141 | internal float m_ScriptDistanceFactor = 1.0f; | 141 | internal float m_ScriptDistanceFactor = 1.0f; |
142 | internal bool m_debuggerSafe = false; | ||
142 | internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); | 143 | internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); |
143 | 144 | ||
144 | protected IUrlModule m_UrlModule = null; | 145 | protected IUrlModule m_UrlModule = null; |
@@ -149,6 +150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
149 | m_ScriptEngine = scriptEngine; | 150 | m_ScriptEngine = scriptEngine; |
150 | m_host = host; | 151 | m_host = host; |
151 | m_item = item; | 152 | m_item = item; |
153 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); | ||
152 | 154 | ||
153 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); | 155 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); |
154 | 156 | ||
@@ -212,7 +214,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
212 | 214 | ||
213 | internal void OSSLError(string msg) | 215 | internal void OSSLError(string msg) |
214 | { | 216 | { |
215 | throw new ScriptException("OSSL Runtime Error: " + msg); | 217 | if (m_debuggerSafe) |
218 | { | ||
219 | OSSLShoutError(msg); | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | throw new ScriptException("OSSL Runtime Error: " + msg); | ||
224 | } | ||
216 | } | 225 | } |
217 | 226 | ||
218 | /// <summary> | 227 | /// <summary> |
@@ -931,18 +940,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
931 | if (target != null) | 940 | if (target != null) |
932 | { | 941 | { |
933 | UUID animID=UUID.Zero; | 942 | UUID animID=UUID.Zero; |
934 | lock (m_host.TaskInventory) | 943 | m_host.TaskInventory.LockItemsForRead(true); |
944 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
935 | { | 945 | { |
936 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 946 | if (inv.Value.Name == animation) |
937 | { | 947 | { |
938 | if (inv.Value.Name == animation) | 948 | if (inv.Value.Type == (int)AssetType.Animation) |
939 | { | 949 | animID = inv.Value.AssetID; |
940 | if (inv.Value.Type == (int)AssetType.Animation) | 950 | continue; |
941 | animID = inv.Value.AssetID; | ||
942 | continue; | ||
943 | } | ||
944 | } | 951 | } |
945 | } | 952 | } |
953 | m_host.TaskInventory.LockItemsForRead(false); | ||
946 | if (animID == UUID.Zero) | 954 | if (animID == UUID.Zero) |
947 | target.Animator.AddAnimation(animation, m_host.UUID); | 955 | target.Animator.AddAnimation(animation, m_host.UUID); |
948 | else | 956 | else |
@@ -983,6 +991,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
983 | else | 991 | else |
984 | animID = UUID.Zero; | 992 | animID = UUID.Zero; |
985 | } | 993 | } |
994 | m_host.TaskInventory.LockItemsForRead(false); | ||
986 | 995 | ||
987 | if (animID == UUID.Zero) | 996 | if (animID == UUID.Zero) |
988 | target.Animator.RemoveAnimation(animation); | 997 | target.Animator.RemoveAnimation(animation); |
@@ -1645,7 +1654,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1645 | } | 1654 | } |
1646 | } | 1655 | } |
1647 | 1656 | ||
1648 | public Object osParseJSONNew(string JSON) | 1657 | private Object osParseJSONNew(string JSON) |
1649 | { | 1658 | { |
1650 | CheckThreatLevel(ThreatLevel.None, "osParseJSONNew"); | 1659 | CheckThreatLevel(ThreatLevel.None, "osParseJSONNew"); |
1651 | 1660 | ||
@@ -1847,15 +1856,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1847 | { | 1856 | { |
1848 | UUID assetID = UUID.Zero; | 1857 | UUID assetID = UUID.Zero; |
1849 | 1858 | ||
1850 | if (!UUID.TryParse(notecardNameOrUuid, out assetID)) | 1859 | bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID); |
1860 | |||
1861 | if (!notecardNameIsUUID) | ||
1851 | { | 1862 | { |
1852 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 1863 | assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid); |
1853 | { | ||
1854 | if (item.Type == 7 && item.Name == notecardNameOrUuid) | ||
1855 | { | ||
1856 | assetID = item.AssetID; | ||
1857 | } | ||
1858 | } | ||
1859 | } | 1864 | } |
1860 | 1865 | ||
1861 | if (assetID == UUID.Zero) | 1866 | if (assetID == UUID.Zero) |
@@ -1866,7 +1871,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1866 | AssetBase a = World.AssetService.Get(assetID.ToString()); | 1871 | AssetBase a = World.AssetService.Get(assetID.ToString()); |
1867 | 1872 | ||
1868 | if (a == null) | 1873 | if (a == null) |
1869 | return UUID.Zero; | 1874 | { |
1875 | // Whoops, it's still possible here that the notecard name was properly | ||
1876 | // formatted like a UUID but isn't an asset UUID so lets look it up by name after all | ||
1877 | assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid); | ||
1878 | if (assetID == UUID.Zero) | ||
1879 | return UUID.Zero; | ||
1880 | |||
1881 | if (!NotecardCache.IsCached(assetID)) | ||
1882 | { | ||
1883 | a = World.AssetService.Get(assetID.ToString()); | ||
1884 | |||
1885 | if (a == null) | ||
1886 | { | ||
1887 | return UUID.Zero; | ||
1888 | } | ||
1889 | } | ||
1890 | } | ||
1870 | 1891 | ||
1871 | string data = Encoding.UTF8.GetString(a.Data); | 1892 | string data = Encoding.UTF8.GetString(a.Data); |
1872 | NotecardCache.Cache(assetID, data); | 1893 | NotecardCache.Cache(assetID, data); |
@@ -1874,6 +1895,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1874 | 1895 | ||
1875 | return assetID; | 1896 | return assetID; |
1876 | } | 1897 | } |
1898 | protected UUID SearchTaskInventoryForAssetId(string name) | ||
1899 | { | ||
1900 | UUID assetId = UUID.Zero; | ||
1901 | m_host.TaskInventory.LockItemsForRead(true); | ||
1902 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1903 | { | ||
1904 | if (item.Type == 7 && item.Name == name) | ||
1905 | { | ||
1906 | assetId = item.AssetID; | ||
1907 | } | ||
1908 | } | ||
1909 | m_host.TaskInventory.LockItemsForRead(false); | ||
1910 | return assetId; | ||
1911 | } | ||
1877 | 1912 | ||
1878 | /// <summary> | 1913 | /// <summary> |
1879 | /// Directly get an entire notecard at once. | 1914 | /// Directly get an entire notecard at once. |
@@ -2351,7 +2386,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2351 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); | 2386 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); |
2352 | m_host.AddScriptLPS(1); | 2387 | m_host.AddScriptLPS(1); |
2353 | 2388 | ||
2354 | return NpcCreate(firstname, lastname, position, notecard, false, false); | 2389 | return NpcCreate(firstname, lastname, position, notecard, true, false); |
2355 | } | 2390 | } |
2356 | 2391 | ||
2357 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) | 2392 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) |
@@ -2362,24 +2397,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2362 | return NpcCreate( | 2397 | return NpcCreate( |
2363 | firstname, lastname, position, notecard, | 2398 | firstname, lastname, position, notecard, |
2364 | (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, | 2399 | (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, |
2365 | (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); | 2400 | false); |
2401 | // (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); | ||
2366 | } | 2402 | } |
2367 | 2403 | ||
2368 | private LSL_Key NpcCreate( | 2404 | private LSL_Key NpcCreate( |
2369 | string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) | 2405 | string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) |
2370 | { | 2406 | { |
2407 | if (!owned) | ||
2408 | OSSLError("Unowned NPCs are unsupported"); | ||
2409 | |||
2410 | string groupTitle = String.Empty; | ||
2411 | |||
2412 | if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z))) | ||
2413 | return new LSL_Key(UUID.Zero.ToString()); | ||
2414 | |||
2415 | if (firstname != String.Empty || lastname != String.Empty) | ||
2416 | { | ||
2417 | if (firstname != "Shown outfit:") | ||
2418 | groupTitle = "- NPC -"; | ||
2419 | } | ||
2420 | |||
2371 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2421 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2372 | if (module != null) | 2422 | if (module != null) |
2373 | { | 2423 | { |
2374 | AvatarAppearance appearance = null; | 2424 | AvatarAppearance appearance = null; |
2375 | 2425 | ||
2376 | UUID id; | 2426 | // UUID id; |
2377 | if (UUID.TryParse(notecard, out id)) | 2427 | // if (UUID.TryParse(notecard, out id)) |
2378 | { | 2428 | // { |
2379 | ScenePresence clonePresence = World.GetScenePresence(id); | 2429 | // ScenePresence clonePresence = World.GetScenePresence(id); |
2380 | if (clonePresence != null) | 2430 | // if (clonePresence != null) |
2381 | appearance = clonePresence.Appearance; | 2431 | // appearance = clonePresence.Appearance; |
2382 | } | 2432 | // } |
2383 | 2433 | ||
2384 | if (appearance == null) | 2434 | if (appearance == null) |
2385 | { | 2435 | { |
@@ -2387,9 +2437,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2387 | 2437 | ||
2388 | if (appearanceSerialized != null) | 2438 | if (appearanceSerialized != null) |
2389 | { | 2439 | { |
2390 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2440 | try |
2391 | appearance = new AvatarAppearance(); | 2441 | { |
2392 | appearance.Unpack(appearanceOsd); | 2442 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2443 | appearance = new AvatarAppearance(); | ||
2444 | appearance.Unpack(appearanceOsd); | ||
2445 | } | ||
2446 | catch | ||
2447 | { | ||
2448 | return UUID.Zero.ToString(); | ||
2449 | } | ||
2393 | } | 2450 | } |
2394 | else | 2451 | else |
2395 | { | 2452 | { |
@@ -2408,6 +2465,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2408 | World, | 2465 | World, |
2409 | appearance); | 2466 | appearance); |
2410 | 2467 | ||
2468 | ScenePresence sp; | ||
2469 | if (World.TryGetScenePresence(x, out sp)) | ||
2470 | { | ||
2471 | sp.Grouptitle = groupTitle; | ||
2472 | sp.SendAvatarDataToAllAgents(); | ||
2473 | } | ||
2411 | return new LSL_Key(x.ToString()); | 2474 | return new LSL_Key(x.ToString()); |
2412 | } | 2475 | } |
2413 | 2476 | ||
@@ -2705,16 +2768,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2705 | CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); | 2768 | CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); |
2706 | m_host.AddScriptLPS(1); | 2769 | m_host.AddScriptLPS(1); |
2707 | 2770 | ||
2708 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2771 | ManualResetEvent ev = new ManualResetEvent(false); |
2709 | if (module != null) | ||
2710 | { | ||
2711 | UUID npcId = new UUID(npc.m_string); | ||
2712 | 2772 | ||
2713 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) | 2773 | Util.FireAndForget(delegate(object x) { |
2714 | return; | 2774 | try |
2775 | { | ||
2776 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | ||
2777 | if (module != null) | ||
2778 | { | ||
2779 | UUID npcId = new UUID(npc.m_string); | ||
2715 | 2780 | ||
2716 | module.DeleteNPC(npcId, World); | 2781 | ILandObject l = World.LandChannel.GetLandObject(m_host.GroupPosition.X, m_host.GroupPosition.Y); |
2717 | } | 2782 | if (l == null || m_host.OwnerID != l.LandData.OwnerID) |
2783 | { | ||
2784 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) | ||
2785 | return; | ||
2786 | } | ||
2787 | |||
2788 | module.DeleteNPC(npcId, World); | ||
2789 | } | ||
2790 | } | ||
2791 | finally | ||
2792 | { | ||
2793 | ev.Set(); | ||
2794 | } | ||
2795 | }); | ||
2796 | ev.WaitOne(); | ||
2718 | } | 2797 | } |
2719 | 2798 | ||
2720 | public void osNpcPlayAnimation(LSL_Key npc, string animation) | 2799 | public void osNpcPlayAnimation(LSL_Key npc, string animation) |