diff options
Merge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 439 |
1 files changed, 406 insertions, 33 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 80111f9..51c8c7e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -141,6 +141,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
141 | internal bool m_debuggerSafe = false; | 141 | internal bool m_debuggerSafe = false; |
142 | internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); | 142 | internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); |
143 | 143 | ||
144 | protected IUrlModule m_UrlModule = null; | ||
145 | |||
144 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 146 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) |
145 | { | 147 | { |
146 | m_ScriptEngine = ScriptEngine; | 148 | m_ScriptEngine = ScriptEngine; |
@@ -148,6 +150,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
148 | m_item = item; | 150 | m_item = item; |
149 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); | 151 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); |
150 | 152 | ||
153 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); | ||
154 | |||
151 | if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) | 155 | if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) |
152 | m_OSFunctionsEnabled = true; | 156 | m_OSFunctionsEnabled = true; |
153 | 157 | ||
@@ -214,7 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
214 | } | 218 | } |
215 | else | 219 | else |
216 | { | 220 | { |
217 | throw new Exception("OSSL Runtime Error: " + msg); | 221 | throw new ScriptException("OSSL Runtime Error: " + msg); |
218 | } | 222 | } |
219 | } | 223 | } |
220 | 224 | ||
@@ -782,10 +786,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
782 | 786 | ||
783 | // We will launch the teleport on a new thread so that when the script threads are terminated | 787 | // We will launch the teleport on a new thread so that when the script threads are terminated |
784 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. | 788 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. |
785 | Util.FireAndForget( | 789 | Util.FireAndForget(o => World.RequestTeleportLocation( |
786 | o => World.RequestTeleportLocation(presence.ControllingClient, regionName, | 790 | presence.ControllingClient, regionName, position, |
787 | new Vector3((float)position.x, (float)position.y, (float)position.z), | 791 | lookat, (uint)TPFlags.ViaLocation)); |
788 | new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation)); | ||
789 | 792 | ||
790 | ScriptSleep(5000); | 793 | ScriptSleep(5000); |
791 | 794 | ||
@@ -828,10 +831,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
828 | 831 | ||
829 | // We will launch the teleport on a new thread so that when the script threads are terminated | 832 | // We will launch the teleport on a new thread so that when the script threads are terminated |
830 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. | 833 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. |
831 | Util.FireAndForget( | 834 | Util.FireAndForget(o => World.RequestTeleportLocation( |
832 | o => World.RequestTeleportLocation(presence.ControllingClient, regionHandle, | 835 | presence.ControllingClient, regionHandle, |
833 | new Vector3((float)position.x, (float)position.y, (float)position.z), | 836 | position, lookat, (uint)TPFlags.ViaLocation)); |
834 | new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation)); | ||
835 | 837 | ||
836 | ScriptSleep(5000); | 838 | ScriptSleep(5000); |
837 | 839 | ||
@@ -1680,6 +1682,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1680 | return; | 1682 | return; |
1681 | } | 1683 | } |
1682 | 1684 | ||
1685 | MessageObject(objUUID, message); | ||
1686 | } | ||
1687 | |||
1688 | private void MessageObject(UUID objUUID, string message) | ||
1689 | { | ||
1683 | object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) }; | 1690 | object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) }; |
1684 | 1691 | ||
1685 | SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID); | 1692 | SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID); |
@@ -1782,18 +1789,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1782 | protected string LoadNotecard(string notecardNameOrUuid) | 1789 | protected string LoadNotecard(string notecardNameOrUuid) |
1783 | { | 1790 | { |
1784 | UUID assetID = CacheNotecard(notecardNameOrUuid); | 1791 | UUID assetID = CacheNotecard(notecardNameOrUuid); |
1785 | StringBuilder notecardData = new StringBuilder(); | ||
1786 | 1792 | ||
1787 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) | 1793 | if (assetID != UUID.Zero) |
1788 | { | 1794 | { |
1789 | string line = NotecardCache.GetLine(assetID, count) + "\n"; | 1795 | StringBuilder notecardData = new StringBuilder(); |
1790 | 1796 | ||
1791 | // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); | 1797 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) |
1792 | 1798 | { | |
1793 | notecardData.Append(line); | 1799 | string line = NotecardCache.GetLine(assetID, count) + "\n"; |
1800 | |||
1801 | // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); | ||
1802 | |||
1803 | notecardData.Append(line); | ||
1804 | } | ||
1805 | |||
1806 | return notecardData.ToString(); | ||
1794 | } | 1807 | } |
1795 | 1808 | ||
1796 | return notecardData.ToString(); | 1809 | return null; |
1797 | } | 1810 | } |
1798 | 1811 | ||
1799 | /// <summary> | 1812 | /// <summary> |
@@ -2259,11 +2272,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2259 | CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); | 2272 | CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); |
2260 | m_host.AddScriptLPS(1); | 2273 | m_host.AddScriptLPS(1); |
2261 | InitLSL(); | 2274 | InitLSL(); |
2275 | // One needs to cast m_LSL_Api because we're using functions not | ||
2276 | // on the ILSL_Api interface. | ||
2277 | LSL_Api LSL_Api = (LSL_Api)m_LSL_Api; | ||
2262 | LSL_List retVal = new LSL_List(); | 2278 | LSL_List retVal = new LSL_List(); |
2263 | List<SceneObjectPart> parts = ((LSL_Api)m_LSL_Api).GetLinkParts(linknumber); | 2279 | LSL_List remaining = null; |
2280 | List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber); | ||
2264 | foreach (SceneObjectPart part in parts) | 2281 | foreach (SceneObjectPart part in parts) |
2265 | { | 2282 | { |
2266 | retVal += ((LSL_Api)m_LSL_Api).GetLinkPrimitiveParams(part, rules); | 2283 | remaining = LSL_Api.GetPrimParams(part, rules, ref retVal); |
2284 | } | ||
2285 | |||
2286 | while (remaining != null && remaining.Length > 2) | ||
2287 | { | ||
2288 | linknumber = remaining.GetLSLIntegerItem(0); | ||
2289 | rules = remaining.GetSublist(1, -1); | ||
2290 | parts = LSL_Api.GetLinkParts(linknumber); | ||
2291 | |||
2292 | foreach (SceneObjectPart part in parts) | ||
2293 | remaining = LSL_Api.GetPrimParams(part, rules, ref retVal); | ||
2267 | } | 2294 | } |
2268 | return retVal; | 2295 | return retVal; |
2269 | } | 2296 | } |
@@ -2352,17 +2379,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2352 | return UUID.Zero.ToString(); | 2379 | return UUID.Zero.ToString(); |
2353 | } | 2380 | } |
2354 | } | 2381 | } |
2382 | else | ||
2383 | { | ||
2384 | OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); | ||
2385 | } | ||
2355 | } | 2386 | } |
2356 | 2387 | ||
2357 | if (appearance == null) | ||
2358 | return new LSL_Key(UUID.Zero.ToString()); | ||
2359 | |||
2360 | UUID ownerID = UUID.Zero; | 2388 | UUID ownerID = UUID.Zero; |
2361 | if (owned) | 2389 | if (owned) |
2362 | ownerID = m_host.OwnerID; | 2390 | ownerID = m_host.OwnerID; |
2363 | UUID x = module.CreateNPC(firstname, | 2391 | UUID x = module.CreateNPC(firstname, |
2364 | lastname, | 2392 | lastname, |
2365 | new Vector3((float) position.x, (float) position.y, (float) position.z), | 2393 | position, |
2366 | ownerID, | 2394 | ownerID, |
2367 | senseAsAgent, | 2395 | senseAsAgent, |
2368 | World, | 2396 | World, |
@@ -2425,6 +2453,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2425 | return; | 2453 | return; |
2426 | 2454 | ||
2427 | string appearanceSerialized = LoadNotecard(notecard); | 2455 | string appearanceSerialized = LoadNotecard(notecard); |
2456 | |||
2457 | if (appearanceSerialized == null) | ||
2458 | OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); | ||
2459 | |||
2428 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2460 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2429 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2461 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2430 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); | 2462 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); |
@@ -2485,7 +2517,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2485 | return new LSL_Vector(0, 0, 0); | 2517 | return new LSL_Vector(0, 0, 0); |
2486 | } | 2518 | } |
2487 | 2519 | ||
2488 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) | 2520 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos) |
2489 | { | 2521 | { |
2490 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); | 2522 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); |
2491 | m_host.AddScriptLPS(1); | 2523 | m_host.AddScriptLPS(1); |
@@ -2500,7 +2532,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2500 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) | 2532 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) |
2501 | return; | 2533 | return; |
2502 | 2534 | ||
2503 | Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); | ||
2504 | module.MoveToTarget(npcId, World, pos, false, true, false); | 2535 | module.MoveToTarget(npcId, World, pos, false, true, false); |
2505 | } | 2536 | } |
2506 | } | 2537 | } |
@@ -2520,11 +2551,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2520 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) | 2551 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) |
2521 | return; | 2552 | return; |
2522 | 2553 | ||
2523 | Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z); | ||
2524 | module.MoveToTarget( | 2554 | module.MoveToTarget( |
2525 | new UUID(npc.m_string), | 2555 | new UUID(npc.m_string), |
2526 | World, | 2556 | World, |
2527 | pos, | 2557 | target, |
2528 | (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, | 2558 | (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, |
2529 | (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0, | 2559 | (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0, |
2530 | (options & ScriptBaseClass.OS_NPC_RUNNING) != 0); | 2560 | (options & ScriptBaseClass.OS_NPC_RUNNING) != 0); |
@@ -2576,7 +2606,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2576 | ScenePresence sp = World.GetScenePresence(npcId); | 2606 | ScenePresence sp = World.GetScenePresence(npcId); |
2577 | 2607 | ||
2578 | if (sp != null) | 2608 | if (sp != null) |
2579 | sp.Rotation = LSL_Api.Rot2Quaternion(rotation); | 2609 | sp.Rotation = rotation; |
2580 | } | 2610 | } |
2581 | } | 2611 | } |
2582 | 2612 | ||
@@ -2936,7 +2966,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2936 | avatar.SpeedModifier = (float)SpeedModifier; | 2966 | avatar.SpeedModifier = (float)SpeedModifier; |
2937 | } | 2967 | } |
2938 | 2968 | ||
2939 | public void osKickAvatar(string FirstName,string SurName,string alert) | 2969 | public void osKickAvatar(string FirstName, string SurName, string alert) |
2940 | { | 2970 | { |
2941 | CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); | 2971 | CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); |
2942 | m_host.AddScriptLPS(1); | 2972 | m_host.AddScriptLPS(1); |
@@ -2950,10 +2980,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2950 | sp.ControllingClient.Kick(alert); | 2980 | sp.ControllingClient.Kick(alert); |
2951 | 2981 | ||
2952 | // ...and close on our side | 2982 | // ...and close on our side |
2953 | sp.Scene.IncomingCloseAgent(sp.UUID); | 2983 | sp.Scene.IncomingCloseAgent(sp.UUID, false); |
2954 | } | 2984 | } |
2955 | }); | 2985 | }); |
2956 | } | 2986 | } |
2987 | |||
2988 | public LSL_Float osGetHealth(string avatar) | ||
2989 | { | ||
2990 | CheckThreatLevel(ThreatLevel.None, "osGetHealth"); | ||
2991 | m_host.AddScriptLPS(1); | ||
2992 | |||
2993 | LSL_Float health = new LSL_Float(-1); | ||
2994 | ScenePresence presence = World.GetScenePresence(new UUID(avatar)); | ||
2995 | if (presence != null) health = presence.Health; | ||
2996 | return health; | ||
2997 | } | ||
2957 | 2998 | ||
2958 | public void osCauseDamage(string avatar, double damage) | 2999 | public void osCauseDamage(string avatar, double damage) |
2959 | { | 3000 | { |
@@ -2966,7 +3007,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2966 | ScenePresence presence = World.GetScenePresence(avatarId); | 3007 | ScenePresence presence = World.GetScenePresence(avatarId); |
2967 | if (presence != null) | 3008 | if (presence != null) |
2968 | { | 3009 | { |
2969 | LandData land = World.GetLandData((float)pos.X, (float)pos.Y); | 3010 | LandData land = World.GetLandData(pos); |
2970 | if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage) | 3011 | if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage) |
2971 | { | 3012 | { |
2972 | float health = presence.Health; | 3013 | float health = presence.Health; |
@@ -3013,7 +3054,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3013 | m_host.AddScriptLPS(1); | 3054 | m_host.AddScriptLPS(1); |
3014 | InitLSL(); | 3055 | InitLSL(); |
3015 | 3056 | ||
3016 | return m_LSL_Api.GetLinkPrimitiveParamsEx(prim, rules); | 3057 | return m_LSL_Api.GetPrimitiveParamsEx(prim, rules); |
3017 | } | 3058 | } |
3018 | 3059 | ||
3019 | public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules) | 3060 | public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules) |
@@ -3022,7 +3063,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3022 | m_host.AddScriptLPS(1); | 3063 | m_host.AddScriptLPS(1); |
3023 | InitLSL(); | 3064 | InitLSL(); |
3024 | 3065 | ||
3025 | m_LSL_Api.SetPrimitiveParamsEx(prim, rules); | 3066 | m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams"); |
3026 | } | 3067 | } |
3027 | 3068 | ||
3028 | /// <summary> | 3069 | /// <summary> |
@@ -3254,6 +3295,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3254 | } | 3295 | } |
3255 | } | 3296 | } |
3256 | 3297 | ||
3298 | #region Attachment commands | ||
3299 | |||
3257 | public void osForceAttachToAvatar(int attachmentPoint) | 3300 | public void osForceAttachToAvatar(int attachmentPoint) |
3258 | { | 3301 | { |
3259 | CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar"); | 3302 | CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar"); |
@@ -3343,6 +3386,175 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3343 | ((LSL_Api)m_LSL_Api).DetachFromAvatar(); | 3386 | ((LSL_Api)m_LSL_Api).DetachFromAvatar(); |
3344 | } | 3387 | } |
3345 | 3388 | ||
3389 | public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints) | ||
3390 | { | ||
3391 | CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments"); | ||
3392 | |||
3393 | m_host.AddScriptLPS(1); | ||
3394 | |||
3395 | UUID targetUUID; | ||
3396 | ScenePresence target; | ||
3397 | LSL_List resp = new LSL_List(); | ||
3398 | |||
3399 | if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target)) | ||
3400 | { | ||
3401 | foreach (object point in attachmentPoints.Data) | ||
3402 | { | ||
3403 | LSL_Integer ipoint = new LSL_Integer( | ||
3404 | (point is LSL_Integer || point is int || point is uint) ? | ||
3405 | (int)point : | ||
3406 | 0 | ||
3407 | ); | ||
3408 | resp.Add(ipoint); | ||
3409 | if (ipoint == 0) | ||
3410 | { | ||
3411 | // indicates zero attachments | ||
3412 | resp.Add(new LSL_Integer(0)); | ||
3413 | } | ||
3414 | else | ||
3415 | { | ||
3416 | // gets the number of attachments on the attachment point | ||
3417 | resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count)); | ||
3418 | } | ||
3419 | } | ||
3420 | } | ||
3421 | |||
3422 | return resp; | ||
3423 | } | ||
3424 | |||
3425 | public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options) | ||
3426 | { | ||
3427 | CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments"); | ||
3428 | m_host.AddScriptLPS(1); | ||
3429 | |||
3430 | UUID targetUUID; | ||
3431 | ScenePresence target; | ||
3432 | |||
3433 | if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target)) | ||
3434 | { | ||
3435 | List<int> aps = new List<int>(); | ||
3436 | foreach (object point in attachmentPoints.Data) | ||
3437 | { | ||
3438 | int ipoint; | ||
3439 | if (int.TryParse(point.ToString(), out ipoint)) | ||
3440 | { | ||
3441 | aps.Add(ipoint); | ||
3442 | } | ||
3443 | } | ||
3444 | |||
3445 | List<SceneObjectGroup> attachments = new List<SceneObjectGroup>(); | ||
3446 | |||
3447 | bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL); | ||
3448 | bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0; | ||
3449 | |||
3450 | if (msgAll && invertPoints) | ||
3451 | { | ||
3452 | return; | ||
3453 | } | ||
3454 | else if (msgAll || invertPoints) | ||
3455 | { | ||
3456 | attachments = target.GetAttachments(); | ||
3457 | } | ||
3458 | else | ||
3459 | { | ||
3460 | foreach (int point in aps) | ||
3461 | { | ||
3462 | if (point > 0) | ||
3463 | { | ||
3464 | attachments.AddRange(target.GetAttachments((uint)point)); | ||
3465 | } | ||
3466 | } | ||
3467 | } | ||
3468 | |||
3469 | // if we have no attachments at this point, exit now | ||
3470 | if (attachments.Count == 0) | ||
3471 | { | ||
3472 | return; | ||
3473 | } | ||
3474 | |||
3475 | List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>(); | ||
3476 | |||
3477 | if (invertPoints) | ||
3478 | { | ||
3479 | foreach (SceneObjectGroup attachment in attachments) | ||
3480 | { | ||
3481 | if (aps.Contains((int)attachment.AttachmentPoint)) | ||
3482 | { | ||
3483 | ignoreThese.Add(attachment); | ||
3484 | } | ||
3485 | } | ||
3486 | } | ||
3487 | |||
3488 | foreach (SceneObjectGroup attachment in ignoreThese) | ||
3489 | { | ||
3490 | attachments.Remove(attachment); | ||
3491 | } | ||
3492 | ignoreThese.Clear(); | ||
3493 | |||
3494 | // if inverting removed all attachments to check, exit now | ||
3495 | if (attachments.Count < 1) | ||
3496 | { | ||
3497 | return; | ||
3498 | } | ||
3499 | |||
3500 | if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0) | ||
3501 | { | ||
3502 | foreach (SceneObjectGroup attachment in attachments) | ||
3503 | { | ||
3504 | if (attachment.RootPart.CreatorID != m_host.CreatorID) | ||
3505 | { | ||
3506 | ignoreThese.Add(attachment); | ||
3507 | } | ||
3508 | } | ||
3509 | |||
3510 | foreach (SceneObjectGroup attachment in ignoreThese) | ||
3511 | { | ||
3512 | attachments.Remove(attachment); | ||
3513 | } | ||
3514 | ignoreThese.Clear(); | ||
3515 | |||
3516 | // if filtering by same object creator removed all | ||
3517 | // attachments to check, exit now | ||
3518 | if (attachments.Count == 0) | ||
3519 | { | ||
3520 | return; | ||
3521 | } | ||
3522 | } | ||
3523 | |||
3524 | if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0) | ||
3525 | { | ||
3526 | foreach (SceneObjectGroup attachment in attachments) | ||
3527 | { | ||
3528 | if (attachment.RootPart.CreatorID != m_item.CreatorID) | ||
3529 | { | ||
3530 | ignoreThese.Add(attachment); | ||
3531 | } | ||
3532 | } | ||
3533 | |||
3534 | foreach (SceneObjectGroup attachment in ignoreThese) | ||
3535 | { | ||
3536 | attachments.Remove(attachment); | ||
3537 | } | ||
3538 | ignoreThese.Clear(); | ||
3539 | |||
3540 | // if filtering by object creator must match originating | ||
3541 | // script creator removed all attachments to check, | ||
3542 | // exit now | ||
3543 | if (attachments.Count == 0) | ||
3544 | { | ||
3545 | return; | ||
3546 | } | ||
3547 | } | ||
3548 | |||
3549 | foreach (SceneObjectGroup attachment in attachments) | ||
3550 | { | ||
3551 | MessageObject(attachment.RootPart.UUID, message); | ||
3552 | } | ||
3553 | } | ||
3554 | } | ||
3555 | |||
3556 | #endregion | ||
3557 | |||
3346 | /// <summary> | 3558 | /// <summary> |
3347 | /// Checks if thing is a UUID. | 3559 | /// Checks if thing is a UUID. |
3348 | /// </summary> | 3560 | /// </summary> |
@@ -3392,5 +3604,166 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3392 | 3604 | ||
3393 | return new LSL_Key(m_host.ParentGroup.FromPartID.ToString()); | 3605 | return new LSL_Key(m_host.ParentGroup.FromPartID.ToString()); |
3394 | } | 3606 | } |
3607 | |||
3608 | /// <summary> | ||
3609 | /// Sets the response type for an HTTP request/response | ||
3610 | /// </summary> | ||
3611 | /// <returns></returns> | ||
3612 | public void osSetContentType(LSL_Key id, string type) | ||
3613 | { | ||
3614 | CheckThreatLevel(ThreatLevel.High, "osSetContentType"); | ||
3615 | |||
3616 | if (m_UrlModule != null) | ||
3617 | m_UrlModule.HttpContentType(new UUID(id),type); | ||
3618 | } | ||
3619 | |||
3620 | /// Shout an error if the object owner did not grant the script the specified permissions. | ||
3621 | /// </summary> | ||
3622 | /// <param name="perms"></param> | ||
3623 | /// <returns>boolean indicating whether an error was shouted.</returns> | ||
3624 | protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix) | ||
3625 | { | ||
3626 | m_host.AddScriptLPS(1); | ||
3627 | bool fail = false; | ||
3628 | if (m_item.PermsGranter != m_host.OwnerID) | ||
3629 | { | ||
3630 | fail = true; | ||
3631 | OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix)); | ||
3632 | } | ||
3633 | else if ((m_item.PermsMask & perms) == 0) | ||
3634 | { | ||
3635 | fail = true; | ||
3636 | OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix)); | ||
3637 | } | ||
3638 | |||
3639 | return fail; | ||
3640 | } | ||
3641 | |||
3642 | protected void DropAttachment(bool checkPerms) | ||
3643 | { | ||
3644 | if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment")) | ||
3645 | { | ||
3646 | return; | ||
3647 | } | ||
3648 | |||
3649 | IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; | ||
3650 | ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID); | ||
3651 | |||
3652 | if (attachmentsModule != null && sp != null) | ||
3653 | { | ||
3654 | attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId); | ||
3655 | } | ||
3656 | } | ||
3657 | |||
3658 | protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot) | ||
3659 | { | ||
3660 | if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment")) | ||
3661 | { | ||
3662 | return; | ||
3663 | } | ||
3664 | |||
3665 | IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; | ||
3666 | ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID); | ||
3667 | |||
3668 | if (attachmentsModule != null && sp != null) | ||
3669 | { | ||
3670 | attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot); | ||
3671 | } | ||
3672 | } | ||
3673 | |||
3674 | public void osDropAttachment() | ||
3675 | { | ||
3676 | CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment"); | ||
3677 | m_host.AddScriptLPS(1); | ||
3678 | |||
3679 | DropAttachment(true); | ||
3680 | } | ||
3681 | |||
3682 | public void osForceDropAttachment() | ||
3683 | { | ||
3684 | CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment"); | ||
3685 | m_host.AddScriptLPS(1); | ||
3686 | |||
3687 | DropAttachment(false); | ||
3688 | } | ||
3689 | |||
3690 | public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) | ||
3691 | { | ||
3692 | CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt"); | ||
3693 | m_host.AddScriptLPS(1); | ||
3694 | |||
3695 | DropAttachmentAt(true, pos, rot); | ||
3696 | } | ||
3697 | |||
3698 | public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) | ||
3699 | { | ||
3700 | CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt"); | ||
3701 | m_host.AddScriptLPS(1); | ||
3702 | |||
3703 | DropAttachmentAt(false, pos, rot); | ||
3704 | } | ||
3705 | |||
3706 | public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) | ||
3707 | { | ||
3708 | CheckThreatLevel(ThreatLevel.Low, "osListenRegex"); | ||
3709 | m_host.AddScriptLPS(1); | ||
3710 | UUID keyID; | ||
3711 | UUID.TryParse(ID, out keyID); | ||
3712 | |||
3713 | // if we want the name to be used as a regular expression, ensure it is valid first. | ||
3714 | if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME) | ||
3715 | { | ||
3716 | try | ||
3717 | { | ||
3718 | Regex.IsMatch("", name); | ||
3719 | } | ||
3720 | catch (Exception) | ||
3721 | { | ||
3722 | OSSLShoutError("Name regex is invalid."); | ||
3723 | return -1; | ||
3724 | } | ||
3725 | } | ||
3726 | |||
3727 | // if we want the msg to be used as a regular expression, ensure it is valid first. | ||
3728 | if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) | ||
3729 | { | ||
3730 | try | ||
3731 | { | ||
3732 | Regex.IsMatch("", msg); | ||
3733 | } | ||
3734 | catch (Exception) | ||
3735 | { | ||
3736 | OSSLShoutError("Message regex is invalid."); | ||
3737 | return -1; | ||
3738 | } | ||
3739 | } | ||
3740 | |||
3741 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | ||
3742 | return (wComm == null) ? -1 : wComm.Listen( | ||
3743 | m_host.LocalId, | ||
3744 | m_item.ItemID, | ||
3745 | m_host.UUID, | ||
3746 | channelID, | ||
3747 | name, | ||
3748 | keyID, | ||
3749 | msg, | ||
3750 | regexBitfield | ||
3751 | ); | ||
3752 | } | ||
3753 | |||
3754 | public LSL_Integer osRegexIsMatch(string input, string pattern) | ||
3755 | { | ||
3756 | CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch"); | ||
3757 | m_host.AddScriptLPS(1); | ||
3758 | try | ||
3759 | { | ||
3760 | return Regex.IsMatch(input, pattern) ? 1 : 0; | ||
3761 | } | ||
3762 | catch (Exception) | ||
3763 | { | ||
3764 | OSSLShoutError("Possible invalid regular expression detected."); | ||
3765 | return 0; | ||
3766 | } | ||
3767 | } | ||
3395 | } | 3768 | } |
3396 | } | 3769 | } |