Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replace common code to fetch self inventory item (as opposed to uuid)…

… with GetSelfInventoryItem()

However, at some point it would be far more convenient to receive the TaskInventoryItem in the constructor rather than just the item UUID, so we don't have to constantly refetch our self item.
  • Loading branch information...
commit 1f8d1bcdcf7ae48ad0b3609e532ad87859f6300b 1 parent 60065f0
Justin Clark-Casey authored April 23, 2012
231  OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -272,6 +272,20 @@ public List<SceneObjectPart> GetLinkParts(int linkType)
272 272
             }
273 273
         }
274 274
 
  275
+        /// <summary>
  276
+        /// Get the inventory item that hosts ourselves.
  277
+        /// </summary>
  278
+        /// <remarks>
  279
+        /// FIXME: It would be far easier to pass in TaskInventoryItem rather than just m_itemID so that we don't need
  280
+        /// to keep looking ourselves up.
  281
+        /// </remarks>
  282
+        /// <returns></returns>
  283
+        protected TaskInventoryItem GetSelfInventoryItem()
  284
+        {
  285
+            lock (m_host.TaskInventory)
  286
+                return m_host.TaskInventory[m_itemID];
  287
+        }
  288
+
275 289
         protected UUID InventoryKey(string name, int type)
276 290
         {
277 291
             m_host.AddScriptLPS(1);
@@ -2685,12 +2699,7 @@ public LSL_Integer llGiveMoney(string destination, int amount)
2685 2699
         {
2686 2700
             m_host.AddScriptLPS(1);
2687 2701
 
2688  
-            TaskInventoryItem item;
2689  
-
2690  
-            lock (m_host.TaskInventory)
2691  
-            {
2692  
-                item = m_host.TaskInventory[m_itemID];
2693  
-            }
  2702
+            TaskInventoryItem item = GetSelfInventoryItem();
2694 2703
 
2695 2704
             if (item.PermsGranter == UUID.Zero)
2696 2705
                 return 0;
@@ -2933,15 +2942,7 @@ public void llCollisionFilter(string name, string id, int accept)
2933 2942
 
2934 2943
         public void llTakeControls(int controls, int accept, int pass_on)
2935 2944
         {
2936  
-            TaskInventoryItem item;
2937  
-
2938  
-            lock (m_host.TaskInventory)
2939  
-            {
2940  
-                if (!m_host.TaskInventory.ContainsKey(m_itemID))
2941  
-                    return;
2942  
-                else
2943  
-                    item = m_host.TaskInventory[m_itemID];
2944  
-            }
  2945
+            TaskInventoryItem item = GetSelfInventoryItem();
2945 2946
 
2946 2947
             if (item.PermsGranter != UUID.Zero)
2947 2948
             {
@@ -2961,18 +2962,10 @@ public void llTakeControls(int controls, int accept, int pass_on)
2961 2962
 
2962 2963
         public void llReleaseControls()
2963 2964
         {
2964  
-            TaskInventoryItem item;
2965  
-
2966  
-            lock (m_host.TaskInventory)
2967  
-            {
2968  
-                if (!m_host.TaskInventory.ContainsKey(m_itemID))
2969  
-                    return;
2970  
-                else
2971  
-                    item = m_host.TaskInventory[m_itemID];
2972  
-            }
2973  
-
2974 2965
             m_host.AddScriptLPS(1);
2975 2966
 
  2967
+            TaskInventoryItem item = GetSelfInventoryItem();
  2968
+
2976 2969
             if (item.PermsGranter != UUID.Zero)
2977 2970
             {
2978 2971
                 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
@@ -3004,15 +2997,7 @@ public void llAttachToAvatar(int attachment)
3004 2997
 //            if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
3005 2998
 //                return;
3006 2999
 
3007  
-            TaskInventoryItem item;
3008  
-
3009  
-            lock (m_host.TaskInventory)
3010  
-            {
3011  
-                if (!m_host.TaskInventory.ContainsKey(m_itemID))
3012  
-                    return;
3013  
-                else
3014  
-                    item = m_host.TaskInventory[m_itemID];
3015  
-            }
  3000
+            TaskInventoryItem item = GetSelfInventoryItem();
3016 3001
 
3017 3002
             if (item.PermsGranter != m_host.OwnerID)
3018 3003
                 return;
@@ -3036,15 +3021,7 @@ public void llDetachFromAvatar()
3036 3021
             if (m_host.ParentGroup.AttachmentPoint == 0)
3037 3022
                 return;
3038 3023
 
3039  
-            TaskInventoryItem item;
3040  
-
3041  
-            lock (m_host.TaskInventory)
3042  
-            {
3043  
-                if (!m_host.TaskInventory.ContainsKey(m_itemID))
3044  
-                    return;
3045  
-                else
3046  
-                    item = m_host.TaskInventory[m_itemID];
3047  
-            }
  3024
+            TaskInventoryItem item = GetSelfInventoryItem();
3048 3025
 
3049 3026
             if (item.PermsGranter != m_host.OwnerID)
3050 3027
                 return;
@@ -3295,15 +3272,7 @@ public void llStartAnimation(string anim)
3295 3272
         {
3296 3273
             m_host.AddScriptLPS(1);
3297 3274
 
3298  
-            TaskInventoryItem item;
3299  
-
3300  
-            lock (m_host.TaskInventory)
3301  
-            {
3302  
-                if (!m_host.TaskInventory.ContainsKey(m_itemID))
3303  
-                    return;
3304  
-                else
3305  
-                    item = m_host.TaskInventory[m_itemID];
3306  
-            }
  3275
+            TaskInventoryItem item = GetSelfInventoryItem();
3307 3276
 
3308 3277
             if (item.PermsGranter == UUID.Zero)
3309 3278
                 return;
@@ -3328,15 +3297,7 @@ public void llStopAnimation(string anim)
3328 3297
         {
3329 3298
             m_host.AddScriptLPS(1);
3330 3299
 
3331  
-            TaskInventoryItem item;
3332  
-
3333  
-            lock (m_host.TaskInventory)
3334  
-            {
3335  
-                if (!m_host.TaskInventory.ContainsKey(m_itemID))
3336  
-                    return;
3337  
-                else
3338  
-                    item = m_host.TaskInventory[m_itemID];
3339  
-            }
  3300
+            TaskInventoryItem item = GetSelfInventoryItem();
3340 3301
 
3341 3302
             if (item.PermsGranter == UUID.Zero)
3342 3303
                 return;
@@ -3396,12 +3357,7 @@ public void llRequestPermissions(string agent, int perm)
3396 3357
             if (!UUID.TryParse(agent, out agentID))
3397 3358
                 return;
3398 3359
 
3399  
-            TaskInventoryItem item;
3400  
-
3401  
-            lock (m_host.TaskInventory)
3402  
-            {
3403  
-                item = m_host.TaskInventory[m_itemID];
3404  
-            }
  3360
+            TaskInventoryItem item = GetSelfInventoryItem();
3405 3361
 
3406 3362
             if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3407 3363
             {
@@ -3531,39 +3487,19 @@ public LSL_String llGetPermissionsKey()
3531 3487
         {
3532 3488
             m_host.AddScriptLPS(1);
3533 3489
 
3534  
-            lock (m_host.TaskInventory)
3535  
-            {
3536  
-                foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3537  
-                {
3538  
-                    if (item.Type == 10 && item.ItemID == m_itemID)
3539  
-                    {
3540  
-                        return item.PermsGranter.ToString();
3541  
-                    }
3542  
-                }
3543  
-            }
3544  
-
3545  
-            return UUID.Zero.ToString();
  3490
+            return GetSelfInventoryItem().PermsGranter.ToString();
3546 3491
         }
3547 3492
 
3548 3493
         public LSL_Integer llGetPermissions()
3549 3494
         {
3550 3495
             m_host.AddScriptLPS(1);
3551 3496
 
3552  
-            lock (m_host.TaskInventory)
3553  
-            {
3554  
-                foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3555  
-                {
3556  
-                    if (item.Type == 10 && item.ItemID == m_itemID)
3557  
-                    {
3558  
-                        int perms = item.PermsMask;
3559  
-                        if (m_automaticLinkPermission)
3560  
-                            perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3561  
-                        return perms;
3562  
-                    }
3563  
-                }
3564  
-            }
  3497
+            int perms = GetSelfInventoryItem().PermsMask;
3565 3498
 
3566  
-            return 0;
  3499
+            if (m_automaticLinkPermission)
  3500
+                perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3501
+
  3502
+            return perms;
3567 3503
         }
3568 3504
 
3569 3505
         public LSL_Integer llGetLinkNumber()
@@ -3597,11 +3533,7 @@ public void llCreateLink(string target, int parent)
3597 3533
             if (!UUID.TryParse(target, out targetID))
3598 3534
                 return;
3599 3535
 
3600  
-            TaskInventoryItem item;
3601  
-            lock (m_host.TaskInventory)
3602  
-            {
3603  
-                item = m_host.TaskInventory[m_itemID];
3604  
-            }
  3536
+            TaskInventoryItem item = GetSelfInventoryItem();
3605 3537
 
3606 3538
             if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3607 3539
                 && !m_automaticLinkPermission)
@@ -3653,14 +3585,11 @@ public void llBreakLink(int linknum)
3653 3585
         {
3654 3586
             m_host.AddScriptLPS(1);
3655 3587
 
3656  
-            lock (m_host.TaskInventory)
  3588
+            if ((GetSelfInventoryItem().PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3589
+                && !m_automaticLinkPermission)
3657 3590
             {
3658  
-                if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3659  
-                    && !m_automaticLinkPermission)
3660  
-                {
3661  
-                    ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3662  
-                    return;
3663  
-                }
  3591
+                ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3592
+                return;
3664 3593
             }
3665 3594
 
3666 3595
             if (linknum < ScriptBaseClass.LINK_THIS)
@@ -4537,23 +4466,11 @@ public void llPassCollisions(int pass)
4537 4466
 
4538 4467
         public LSL_String llGetScriptName()
4539 4468
         {
4540  
-            string result = String.Empty;
4541  
-
4542 4469
             m_host.AddScriptLPS(1);
4543 4470
 
4544  
-            lock (m_host.TaskInventory)
4545  
-            {
4546  
-                foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4547  
-                {
4548  
-                    if (item.Type == 10 && item.ItemID == m_itemID)
4549  
-                    {
4550  
-                        result = item.Name != null ? item.Name : String.Empty;
4551  
-                        break;
4552  
-                    }
4553  
-                }
4554  
-            }
  4471
+            TaskInventoryItem item = GetSelfInventoryItem();
4555 4472
 
4556  
-            return result;
  4473
+            return item.Name != null ? item.Name : String.Empty;
4557 4474
         }
4558 4475
 
4559 4476
         public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -9655,16 +9572,15 @@ public LSL_Vector llGetCameraPos()
9655 9572
         {
9656 9573
             m_host.AddScriptLPS(1);
9657 9574
 
9658  
-            lock (m_host.TaskInventory)
9659  
-            {
9660  
-                if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
9661  
-                   return new LSL_Vector();
  9575
+            TaskInventoryItem item = GetSelfInventoryItem();
9662 9576
 
9663  
-                if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9664  
-                {
9665  
-                    ShoutError("No permissions to track the camera");
9666  
-                    return new LSL_Vector();
9667  
-                }
  9577
+            if (item.PermsGranter == UUID.Zero)
  9578
+               return new LSL_Vector();
  9579
+
  9580
+            if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  9581
+            {
  9582
+                ShoutError("No permissions to track the camera");
  9583
+                return new LSL_Vector();
9668 9584
             }
9669 9585
 
9670 9586
             ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
@@ -9680,16 +9596,15 @@ public LSL_Rotation llGetCameraRot()
9680 9596
         {
9681 9597
             m_host.AddScriptLPS(1);
9682 9598
 
9683  
-            lock (m_host.TaskInventory)
9684  
-            {
9685  
-                if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
9686  
-                   return new LSL_Rotation();
  9599
+            TaskInventoryItem item = GetSelfInventoryItem();
9687 9600
 
9688  
-                if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9689  
-                {
9690  
-                    ShoutError("No permissions to track the camera");
9691  
-                    return new LSL_Rotation();
9692  
-                }
  9601
+            if (item.PermsGranter == UUID.Zero)
  9602
+               return new LSL_Rotation();
  9603
+
  9604
+            if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  9605
+            {
  9606
+                ShoutError("No permissions to track the camera");
  9607
+                return new LSL_Rotation();
9693 9608
             }
9694 9609
 
9695 9610
             ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
@@ -9865,17 +9780,19 @@ public void llSetCameraParams(LSL_List rules)
9865 9780
 
9866 9781
             // the object we are in
9867 9782
             UUID objectID = m_host.ParentUUID;
9868  
-            if (objectID == UUID.Zero) return;
  9783
+            if (objectID == UUID.Zero)
  9784
+                return;
9869 9785
 
9870  
-            UUID agentID;
9871  
-            lock (m_host.TaskInventory)
9872  
-            {
9873  
-                // we need the permission first, to know which avatar we want to set the camera for
9874  
-                agentID = m_host.TaskInventory[m_itemID].PermsGranter;
  9786
+            TaskInventoryItem item = GetSelfInventoryItem();
9875 9787
 
9876  
-                if (agentID == UUID.Zero) return;
9877  
-                if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
9878  
-            }
  9788
+            // we need the permission first, to know which avatar we want to set the camera for
  9789
+            UUID agentID = item.PermsGranter;
  9790
+
  9791
+            if (agentID == UUID.Zero)
  9792
+                return;
  9793
+
  9794
+            if ((item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  9795
+                return;
9879 9796
 
9880 9797
             ScenePresence presence = World.GetScenePresence(agentID);
9881 9798
 
@@ -9917,21 +9834,25 @@ public void llClearCameraParams()
9917 9834
 
9918 9835
             // the object we are in
9919 9836
             UUID objectID = m_host.ParentUUID;
9920  
-            if (objectID == UUID.Zero) return;
  9837
+            if (objectID == UUID.Zero)
  9838
+                return;
  9839
+
  9840
+            TaskInventoryItem item = GetSelfInventoryItem();
9921 9841
 
9922 9842
             // we need the permission first, to know which avatar we want to clear the camera for
9923  
-            UUID agentID;
9924  
-            lock (m_host.TaskInventory)
9925  
-            {
9926  
-                agentID = m_host.TaskInventory[m_itemID].PermsGranter;
9927  
-                if (agentID == UUID.Zero) return;
9928  
-                if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
9929  
-            }
  9843
+            UUID agentID = item.PermsGranter;
  9844
+
  9845
+            if (agentID == UUID.Zero)
  9846
+                return;
  9847
+
  9848
+            if ((item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  9849
+                return;
9930 9850
 
9931 9851
             ScenePresence presence = World.GetScenePresence(agentID);
9932 9852
 
9933 9853
             // we are not interested in child-agents
9934  
-            if (presence.IsChildAgent) return;
  9854
+            if (presence.IsChildAgent)
  9855
+                return;
9935 9856
 
9936 9857
             presence.ControllingClient.SendClearFollowCamProperties(objectID);
9937 9858
         }

0 notes on commit 1f8d1bc

Please sign in to comment.
Something went wrong with that request. Please try again.