aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs89
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/EventManager.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs264
4 files changed, 212 insertions, 156 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 712bd7d..ed63aee 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -451,12 +451,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
451 public LSL_Vector llVecNorm(LSL_Vector v) 451 public LSL_Vector llVecNorm(LSL_Vector v)
452 { 452 {
453 m_host.AddScriptLPS(1); 453 m_host.AddScriptLPS(1);
454 double mag = LSL_Vector.Mag(v); 454 return LSL_Vector.Norm(v);
455 LSL_Vector nor = new LSL_Vector();
456 nor.x = v.x / mag;
457 nor.y = v.y / mag;
458 nor.z = v.z / mag;
459 return nor;
460 } 455 }
461 456
462 public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b) 457 public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
@@ -470,22 +465,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
470 465
471 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 466 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
472 467
473 // Utility function for llRot2Euler 468 // Old implementation of llRot2Euler. Normalization not required as Atan2 function will
474 469 // only return values >= -PI (-180 degrees) and <= PI (180 degrees).
475 // normalize an angle between -PI and PI (-180 to +180 degrees)
476 protected double NormalizeAngle(double angle)
477 {
478 if (angle > -Math.PI && angle < Math.PI)
479 return angle;
480
481 int numPis = (int)(Math.PI / angle);
482 double remainder = angle - Math.PI * numPis;
483 if (numPis % 2 == 1)
484 return Math.PI - angle;
485 return remainder;
486 }
487
488 // Old implementation of llRot2Euler, now normalized
489 470
490 public LSL_Vector llRot2Euler(LSL_Rotation r) 471 public LSL_Vector llRot2Euler(LSL_Rotation r)
491 { 472 {
@@ -497,13 +478,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
497 double n = 2 * (r.y * r.s + r.x * r.z); 478 double n = 2 * (r.y * r.s + r.x * r.z);
498 double p = m * m - n * n; 479 double p = m * m - n * n;
499 if (p > 0) 480 if (p > 0)
500 return new LSL_Vector(NormalizeAngle(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s))), 481 return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)),
501 NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))), 482 Math.Atan2(n, Math.Sqrt(p)),
502 NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)))); 483 Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)));
503 else if (n > 0) 484 else if (n > 0)
504 return new LSL_Vector(0.0, Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 485 return new LSL_Vector(0.0, Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
505 else 486 else
506 return new LSL_Vector(0.0, -Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 487 return new LSL_Vector(0.0, -Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
507 } 488 }
508 489
509 /* From wiki: 490 /* From wiki:
@@ -1953,13 +1934,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1953 } 1934 }
1954 else 1935 else
1955 { 1936 {
1956 if (llVecDist(new LSL_Vector(0,0,0), targetPos) <= 10.0f) 1937 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos);
1957 { 1938 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1958 part.OffsetPosition = new Vector3((float)targetPos.x, (float)targetPos.y, (float)targetPos.z); 1939 SceneObjectGroup parent = part.ParentGroup;
1959 SceneObjectGroup parent = part.ParentGroup; 1940 parent.HasGroupChanged = true;
1960 parent.HasGroupChanged = true; 1941 parent.ScheduleGroupForTerseUpdate();
1961 parent.ScheduleGroupForTerseUpdate();
1962 }
1963 } 1942 }
1964 } 1943 }
1965 1944
@@ -2945,9 +2924,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2945 2924
2946 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 2925 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
2947 if (attachmentsModule != null) 2926 if (attachmentsModule != null)
2948 attachmentsModule.AttachObject( 2927 attachmentsModule.AttachObject(presence.ControllingClient,
2949 presence.ControllingClient, grp.LocalId, 2928 grp, (uint)attachment, false);
2950 (uint)attachment, Quaternion.Identity, Vector3.Zero, false);
2951 } 2929 }
2952 } 2930 }
2953 2931
@@ -3270,17 +3248,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3270 public void llPointAt(LSL_Vector pos) 3248 public void llPointAt(LSL_Vector pos)
3271 { 3249 {
3272 m_host.AddScriptLPS(1); 3250 m_host.AddScriptLPS(1);
3273 ScenePresence Owner = World.GetScenePresence(m_host.UUID);
3274 LSL_Rotation rot = llEuler2Rot(pos);
3275 Owner.PreviousRotation = Owner.Rotation;
3276 Owner.Rotation = (new Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s));
3277 } 3251 }
3278 3252
3279 public void llStopPointAt() 3253 public void llStopPointAt()
3280 { 3254 {
3281 m_host.AddScriptLPS(1); 3255 m_host.AddScriptLPS(1);
3282 ScenePresence Owner = m_host.ParentGroup.Scene.GetScenePresence(m_host.OwnerID);
3283 Owner.Rotation = Owner.PreviousRotation;
3284 } 3256 }
3285 3257
3286 public void llTargetOmega(LSL_Vector axis, double spinrate, double gain) 3258 public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
@@ -3938,22 +3910,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3938 UUID uuid = (UUID)id; 3910 UUID uuid = (UUID)id;
3939 3911
3940 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 3912 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
3913 if (account == null)
3914 return UUID.Zero.ToString();
3915
3941 3916
3942 PresenceInfo pinfo = null; 3917 PresenceInfo pinfo = null;
3943 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 3918 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
3944 if (pinfos != null && pinfos.Length > 0) 3919 if (pinfos != null && pinfos.Length > 0)
3945 pinfo = pinfos[0]; 3920 pinfo = pinfos[0];
3946 3921
3947 if (pinfo == null)
3948 return UUID.Zero.ToString();
3949
3950 string reply = String.Empty; 3922 string reply = String.Empty;
3951 3923
3952 switch (data) 3924 switch (data)
3953 { 3925 {
3954 case 1: // DATA_ONLINE (0|1) 3926 case 1: // DATA_ONLINE (0|1)
3955 // TODO: implement fetching of this information 3927 if (pinfo != null && pinfo.RegionID != UUID.Zero)
3956 if (pinfo != null)
3957 reply = "1"; 3928 reply = "1";
3958 else 3929 else
3959 reply = "0"; 3930 reply = "0";
@@ -4950,7 +4921,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4950 case ',': 4921 case ',':
4951 if (parens == 0) 4922 if (parens == 0)
4952 { 4923 {
4953 result.Add(src.Substring(start,length).Trim()); 4924 result.Add(new LSL_String(src.Substring(start,length).Trim()));
4954 start += length+1; 4925 start += length+1;
4955 length = 0; 4926 length = 0;
4956 } 4927 }
@@ -5879,6 +5850,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5879 PSYS_PART_MAX_AGE = 7, 5850 PSYS_PART_MAX_AGE = 7,
5880 PSYS_SRC_ACCEL = 8, 5851 PSYS_SRC_ACCEL = 8,
5881 PSYS_SRC_PATTERN = 9, 5852 PSYS_SRC_PATTERN = 9,
5853 PSYS_SRC_INNERANGLE = 10,
5854 PSYS_SRC_OUTERANGLE = 11,
5882 PSYS_SRC_TEXTURE = 12, 5855 PSYS_SRC_TEXTURE = 12,
5883 PSYS_SRC_BURST_RATE = 13, 5856 PSYS_SRC_BURST_RATE = 13,
5884 PSYS_SRC_BURST_PART_COUNT = 15, 5857 PSYS_SRC_BURST_PART_COUNT = 15,
@@ -6011,6 +5984,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6011 prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi; 5984 prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
6012 break; 5985 break;
6013 5986
5987 // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
5988 // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
5989 // client tells the difference between the two by looking at the 0x02 bit in
5990 // the PartFlags variable.
5991 case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
5992 tempf = (float)rules.GetLSLFloatItem(i + 1);
5993 prules.InnerAngle = (float)tempf;
5994 prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
5995 break;
5996
5997 case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
5998 tempf = (float)rules.GetLSLFloatItem(i + 1);
5999 prules.OuterAngle = (float)tempf;
6000 prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
6001 break;
6002
6014 case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: 6003 case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
6015 prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1)); 6004 prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1));
6016 break; 6005 break;
@@ -6067,11 +6056,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6067 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN: 6056 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
6068 tempf = (float)rules.GetLSLFloatItem(i + 1); 6057 tempf = (float)rules.GetLSLFloatItem(i + 1);
6069 prules.InnerAngle = (float)tempf; 6058 prules.InnerAngle = (float)tempf;
6059 prules.PartFlags |= 0x02; // Set new angle format.
6070 break; 6060 break;
6071 6061
6072 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END: 6062 case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
6073 tempf = (float)rules.GetLSLFloatItem(i + 1); 6063 tempf = (float)rules.GetLSLFloatItem(i + 1);
6074 prules.OuterAngle = (float)tempf; 6064 prules.OuterAngle = (float)tempf;
6065 prules.PartFlags |= 0x02; // Set new angle format.
6075 break; 6066 break;
6076 } 6067 }
6077 6068
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 1ea52c5..91e03ac 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -262,7 +262,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
262 public static Vector3 Norm(Vector3 vector) 262 public static Vector3 Norm(Vector3 vector)
263 { 263 {
264 double mag = Mag(vector); 264 double mag = Mag(vector);
265 return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag); 265 if (mag > 0.0)
266 {
267 double invMag = 1.0 / mag;
268 return vector * invMag;
269 }
270 return new Vector3(0, 0, 0);
266 } 271 }
267 272
268 #endregion 273 #endregion
@@ -663,13 +668,13 @@ namespace OpenSim.Region.ScriptEngine.Shared
663 Object[] ret; 668 Object[] ret;
664 669
665 if (start < 0) 670 if (start < 0)
666 start=m_data.Length-start; 671 start=m_data.Length+start;
667 672
668 if (start < 0) 673 if (start < 0)
669 start=0; 674 start=0;
670 675
671 if (end < 0) 676 if (end < 0)
672 end=m_data.Length-end; 677 end=m_data.Length+end;
673 if (end < 0) 678 if (end < 0)
674 end=0; 679 end=0;
675 680
diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
index 09b79d0..0ac8b5c 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
@@ -356,9 +356,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
356 // timer: not handled here 356 // timer: not handled here
357 // listen: not handled here 357 // listen: not handled here
358 358
359 public void control(uint localID, UUID itemID, UUID agentID, uint held, uint change) 359 public void control(UUID itemID, UUID agentID, uint held, uint change)
360 { 360 {
361 myScriptEngine.PostObjectEvent(localID, new EventParams( 361 myScriptEngine.PostScriptEvent(itemID, new EventParams(
362 "control",new object[] { 362 "control",new object[] {
363 new LSL_Types.LSLString(agentID.ToString()), 363 new LSL_Types.LSLString(agentID.ToString()),
364 new LSL_Types.LSLInteger(held), 364 new LSL_Types.LSLInteger(held),
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 4715690..b050349 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -488,6 +488,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
488 488
489 if (stateSource == (int)StateSource.ScriptedRez) 489 if (stateSource == (int)StateSource.ScriptedRez)
490 { 490 {
491 lock (m_CompileDict)
492 {
493 m_CompileDict[itemID] = 0;
494 }
495
491 DoOnRezScript(parms); 496 DoOnRezScript(parms);
492 } 497 }
493 else 498 else
@@ -696,9 +701,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
696 } 701 }
697 } 702 }
698 703
704 ScriptInstance instance = null;
699 lock (m_Scripts) 705 lock (m_Scripts)
700 { 706 {
701 ScriptInstance instance = null;
702 // Create the object record 707 // Create the object record
703 708
704 if ((!m_Scripts.ContainsKey(itemID)) || 709 if ((!m_Scripts.ContainsKey(itemID)) ||
@@ -765,8 +770,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
765 item.Name, startParam, postOnRez, 770 item.Name, startParam, postOnRez,
766 stateSource, m_MaxScriptQueue); 771 stateSource, m_MaxScriptQueue);
767 772
768 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}", 773 m_log.DebugFormat(
769 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, part.ParentGroup.RootPart.AbsolutePosition.ToString()); 774 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
775 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
776 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
770 777
771 if (presence != null) 778 if (presence != null)
772 { 779 {
@@ -779,28 +786,29 @@ namespace OpenSim.Region.ScriptEngine.XEngine
779 786
780 m_Scripts[itemID] = instance; 787 m_Scripts[itemID] = instance;
781 } 788 }
789 }
782 790
783 lock (m_PrimObjects) 791 lock (m_PrimObjects)
784 { 792 {
785 if (!m_PrimObjects.ContainsKey(localID)) 793 if (!m_PrimObjects.ContainsKey(localID))
786 m_PrimObjects[localID] = new List<UUID>(); 794 m_PrimObjects[localID] = new List<UUID>();
787 795
788 if (!m_PrimObjects[localID].Contains(itemID)) 796 if (!m_PrimObjects[localID].Contains(itemID))
789 m_PrimObjects[localID].Add(itemID); 797 m_PrimObjects[localID].Add(itemID);
790 798
791 } 799 }
792 800
793 if (!m_Assemblies.ContainsKey(assetID)) 801 if (!m_Assemblies.ContainsKey(assetID))
794 m_Assemblies[assetID] = assembly; 802 m_Assemblies[assetID] = assembly;
795 803
796 lock (m_AddingAssemblies) 804 lock (m_AddingAssemblies)
797 { 805 {
798 m_AddingAssemblies[assembly]--; 806 m_AddingAssemblies[assembly]--;
799 }
800
801 if (instance!=null)
802 instance.Init();
803 } 807 }
808
809 if (instance != null)
810 instance.Init();
811
804 return true; 812 return true;
805 } 813 }
806 814
@@ -813,60 +821,60 @@ namespace OpenSim.Region.ScriptEngine.XEngine
813 m_CompileDict.Remove(itemID); 821 m_CompileDict.Remove(itemID);
814 } 822 }
815 823
824 IScriptInstance instance = null;
825
816 lock (m_Scripts) 826 lock (m_Scripts)
817 { 827 {
818 // Do we even have it? 828 // Do we even have it?
819 if (!m_Scripts.ContainsKey(itemID)) 829 if (!m_Scripts.ContainsKey(itemID))
820 return; 830 return;
821 831
822 IScriptInstance instance=m_Scripts[itemID]; 832 instance=m_Scripts[itemID];
823 m_Scripts.Remove(itemID); 833 m_Scripts.Remove(itemID);
834 }
824 835
825 instance.ClearQueue(); 836 instance.ClearQueue();
826 instance.Stop(0); 837 instance.Stop(0);
827
828// bool objectRemoved = false; 838// bool objectRemoved = false;
829 839
830 lock (m_PrimObjects) 840 lock (m_PrimObjects)
841 {
842 // Remove the script from it's prim
843 if (m_PrimObjects.ContainsKey(localID))
831 { 844 {
832 // Remove the script from it's prim 845 // Remove inventory item record
833 if (m_PrimObjects.ContainsKey(localID)) 846 if (m_PrimObjects[localID].Contains(itemID))
834 { 847 m_PrimObjects[localID].Remove(itemID);
835 // Remove inventory item record
836 if (m_PrimObjects[localID].Contains(itemID))
837 m_PrimObjects[localID].Remove(itemID);
838 848
839 // If there are no more scripts, remove prim 849 // If there are no more scripts, remove prim
840 if (m_PrimObjects[localID].Count == 0) 850 if (m_PrimObjects[localID].Count == 0)
841 { 851 {
842 m_PrimObjects.Remove(localID); 852 m_PrimObjects.Remove(localID);
843// objectRemoved = true; 853// objectRemoved = true;
844 }
845 } 854 }
846 } 855 }
856 }
847 857
848 instance.RemoveState(); 858 instance.RemoveState();
849 instance.DestroyScriptInstance(); 859 instance.DestroyScriptInstance();
850 860
851 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 861 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
852 if (m_DomainScripts[instance.AppDomain].Count == 0) 862 if (m_DomainScripts[instance.AppDomain].Count == 0)
853 { 863 {
854 m_DomainScripts.Remove(instance.AppDomain); 864 m_DomainScripts.Remove(instance.AppDomain);
855 UnloadAppDomain(instance.AppDomain); 865 UnloadAppDomain(instance.AppDomain);
856 } 866 }
857 867
858 instance = null; 868 instance = null;
859 869
860 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 870 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
861 if (handlerObjectRemoved != null) 871 if (handlerObjectRemoved != null)
862 { 872 {
863 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); 873 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
864 handlerObjectRemoved(part.UUID); 874 handlerObjectRemoved(part.UUID);
865 }
866
867 CleanAssemblies();
868 } 875 }
869 876
877
870 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 878 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
871 if (handlerScriptRemoved != null) 879 if (handlerScriptRemoved != null)
872 handlerScriptRemoved(itemID); 880 handlerScriptRemoved(itemID);
@@ -1000,26 +1008,33 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1000 public bool PostObjectEvent(uint localID, EventParams p) 1008 public bool PostObjectEvent(uint localID, EventParams p)
1001 { 1009 {
1002 bool result = false; 1010 bool result = false;
1003 1011 List<UUID> uuids = null;
1012
1004 lock (m_PrimObjects) 1013 lock (m_PrimObjects)
1005 { 1014 {
1006 if (!m_PrimObjects.ContainsKey(localID)) 1015 if (!m_PrimObjects.ContainsKey(localID))
1007 return false; 1016 return false;
1008 1017
1009 1018 uuids = m_PrimObjects[localID];
1010 foreach (UUID itemID in m_PrimObjects[localID]) 1019 }
1020
1021 foreach (UUID itemID in uuids)
1022 {
1023 IScriptInstance instance = null;
1024 try
1011 { 1025 {
1012 if (m_Scripts.ContainsKey(itemID)) 1026 if (m_Scripts.ContainsKey(itemID))
1013 { 1027 instance = m_Scripts[itemID];
1014 IScriptInstance instance = m_Scripts[itemID]; 1028 }
1015 if (instance != null) 1029 catch { /* ignore race conditions */ }
1016 { 1030
1017 instance.PostEvent(p); 1031 if (instance != null)
1018 result = true; 1032 {
1019 } 1033 instance.PostEvent(p);
1020 } 1034 result = true;
1021 } 1035 }
1022 } 1036 }
1037
1023 return result; 1038 return result;
1024 } 1039 }
1025 1040
@@ -1336,10 +1351,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1336 1351
1337 try 1352 try
1338 { 1353 {
1339 FileStream tfs = File.Open(assemName + ".text", 1354 using (FileStream tfs = File.Open(assemName + ".text",
1340 FileMode.Open, FileAccess.Read); 1355 FileMode.Open, FileAccess.Read))
1341 tfs.Read(tdata, 0, tdata.Length); 1356 {
1342 tfs.Close(); 1357 tfs.Read(tdata, 0, tdata.Length);
1358 tfs.Close();
1359 }
1343 1360
1344 assem = new System.Text.ASCIIEncoding().GetString(tdata); 1361 assem = new System.Text.ASCIIEncoding().GetString(tdata);
1345 } 1362 }
@@ -1359,9 +1376,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1359 1376
1360 try 1377 try
1361 { 1378 {
1362 FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read); 1379 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read))
1363 fs.Read(data, 0, data.Length); 1380 {
1364 fs.Close(); 1381 fs.Read(data, 0, data.Length);
1382 fs.Close();
1383 }
1365 1384
1366 assem = System.Convert.ToBase64String(data); 1385 assem = System.Convert.ToBase64String(data);
1367 } 1386 }
@@ -1377,13 +1396,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1377 1396
1378 if (File.Exists(fn + ".map")) 1397 if (File.Exists(fn + ".map"))
1379 { 1398 {
1380 FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read); 1399 using (FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read))
1381 StreamReader msr = new StreamReader(mfs); 1400 {
1382 1401 using (StreamReader msr = new StreamReader(mfs))
1383 map = msr.ReadToEnd(); 1402 {
1384 1403 map = msr.ReadToEnd();
1385 msr.Close(); 1404 msr.Close();
1386 mfs.Close(); 1405 }
1406 mfs.Close();
1407 }
1387 } 1408 }
1388 1409
1389 XmlElement assemblyData = doc.CreateElement("", "Assembly", ""); 1410 XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
@@ -1471,30 +1492,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1471 { 1492 {
1472 Byte[] filedata = Convert.FromBase64String(base64); 1493 Byte[] filedata = Convert.FromBase64String(base64);
1473 1494
1474 FileStream fs = File.Create(path); 1495 try
1475 fs.Write(filedata, 0, filedata.Length); 1496 {
1476 fs.Close(); 1497 using (FileStream fs = File.Create(path))
1477 1498 {
1478 fs = File.Create(path + ".text"); 1499 fs.Write(filedata, 0, filedata.Length);
1479 StreamWriter sw = new StreamWriter(fs); 1500 fs.Close();
1480 1501 }
1481 sw.Write(base64); 1502 }
1482 1503 catch (IOException ex)
1483 sw.Close(); 1504 {
1484 fs.Close(); 1505 // if there already exists a file at that location, it may be locked.
1506 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
1507 }
1508 try
1509 {
1510 using (FileStream fs = File.Create(path + ".text"))
1511 {
1512 using (StreamWriter sw = new StreamWriter(fs))
1513 {
1514 sw.Write(base64);
1515 sw.Close();
1516 }
1517 fs.Close();
1518 }
1519 }
1520 catch (IOException ex)
1521 {
1522 // if there already exists a file at that location, it may be locked.
1523 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
1524 }
1485 } 1525 }
1486 } 1526 }
1487 1527
1488 string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); 1528 string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
1489 statepath = Path.Combine(statepath, itemID.ToString() + ".state"); 1529 statepath = Path.Combine(statepath, itemID.ToString() + ".state");
1490 1530
1491 FileStream sfs = File.Create(statepath); 1531 try
1492 StreamWriter ssw = new StreamWriter(sfs); 1532 {
1493 1533 using (FileStream sfs = File.Create(statepath))
1494 ssw.Write(stateE.OuterXml); 1534 {
1495 1535 using (StreamWriter ssw = new StreamWriter(sfs))
1496 ssw.Close(); 1536 {
1497 sfs.Close(); 1537 ssw.Write(stateE.OuterXml);
1538 ssw.Close();
1539 }
1540 sfs.Close();
1541 }
1542 }
1543 catch (IOException ex)
1544 {
1545 // if there already exists a file at that location, it may be locked.
1546 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
1547 }
1498 1548
1499 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); 1549 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
1500 if (mapL.Count > 0) 1550 if (mapL.Count > 0)
@@ -1504,13 +1554,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1504 string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); 1554 string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
1505 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); 1555 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
1506 1556
1507 FileStream mfs = File.Create(mappath); 1557 try
1508 StreamWriter msw = new StreamWriter(mfs); 1558 {
1509 1559 using (FileStream mfs = File.Create(mappath))
1510 msw.Write(mapE.InnerText); 1560 {
1511 1561 using (StreamWriter msw = new StreamWriter(mfs))
1512 msw.Close(); 1562 {
1513 mfs.Close(); 1563 msw.Write(mapE.InnerText);
1564 msw.Close();
1565 }
1566 mfs.Close();
1567 }
1568 }
1569 catch (IOException ex)
1570 {
1571 // if there already exists a file at that location, it may be locked.
1572 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
1573 }
1514 } 1574 }
1515 1575
1516 return true; 1576 return true;