aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-08-24 20:49:23 +0100
committerJustin Clark-Casey (justincc)2011-08-24 20:49:23 +0100
commitcf3ffe5bb4c6a8bea9599b6143c2f7793500c984 (patch)
tree80ff937e194c85ec7f599bb6e254c239c69f0b56 /OpenSim/Region/Framework/Scenes
parentrename AttachmentsModule.ShowDetachInUserInventory() to DetachSingleAttachmen... (diff)
downloadopensim-SC_OLD-cf3ffe5bb4c6a8bea9599b6143c2f7793500c984.zip
opensim-SC_OLD-cf3ffe5bb4c6a8bea9599b6143c2f7793500c984.tar.gz
opensim-SC_OLD-cf3ffe5bb4c6a8bea9599b6143c2f7793500c984.tar.bz2
opensim-SC_OLD-cf3ffe5bb4c6a8bea9599b6143c2f7793500c984.tar.xz
Fix llAttachToAvatar()
Apart from one obvious bug, this was failing because attempting to serialize the script from inside the script (as part of saving the attachment as an inventory asset) was triggering an extremely long delay. So we now don't do this. The state will be serialized anyway when the avatar normally logs out. The worst that can happen is that if the client/server crashes, the attachment scripts start without previous state.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs14
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs31
2 files changed, 33 insertions, 12 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index afc1a4f..94126f0 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -1873,6 +1873,8 @@ namespace OpenSim.Region.Framework.Scenes
1873 1873
1874 public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID) 1874 public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
1875 { 1875 {
1876// m_log.DebugFormat("[SCENE]: Called attachObjectAssetStore for object {0} {1} for {2} {3} {4}", grp.Name, grp.LocalId, remoteClient.Name, remoteClient.AgentId, AgentId);
1877
1876 itemID = UUID.Zero; 1878 itemID = UUID.Zero;
1877 if (grp != null) 1879 if (grp != null)
1878 { 1880 {
@@ -1881,16 +1883,20 @@ namespace OpenSim.Region.Framework.Scenes
1881 ? 250 1883 ? 250
1882 : grp.AbsolutePosition.X) 1884 : grp.AbsolutePosition.X)
1883 , 1885 ,
1884 (grp.AbsolutePosition.X > (int)Constants.RegionSize) 1886 (grp.AbsolutePosition.Y > (int)Constants.RegionSize)
1885 ? 250 1887 ? 250
1886 : grp.AbsolutePosition.X, 1888 : grp.AbsolutePosition.Y,
1887 grp.AbsolutePosition.Z); 1889 grp.AbsolutePosition.Z);
1888 1890
1889 Vector3 originalPosition = grp.AbsolutePosition; 1891 Vector3 originalPosition = grp.AbsolutePosition;
1890 1892
1891 grp.AbsolutePosition = inventoryStoredPosition; 1893 grp.AbsolutePosition = inventoryStoredPosition;
1892 1894
1893 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); 1895 // If we're being called from a script, then trying to serialize that same script's state will not complete
1896 // in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
1897 // the client/server crashes rather than logging out normally, the attachment's scripts will resume
1898 // without state on relog. Arguably, this is what we want anyway.
1899 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false);
1894 1900
1895 grp.AbsolutePosition = originalPosition; 1901 grp.AbsolutePosition = originalPosition;
1896 1902
@@ -1900,6 +1906,7 @@ namespace OpenSim.Region.Framework.Scenes
1900 (sbyte)AssetType.Object, 1906 (sbyte)AssetType.Object,
1901 Utils.StringToBytes(sceneObjectXml), 1907 Utils.StringToBytes(sceneObjectXml),
1902 remoteClient.AgentId); 1908 remoteClient.AgentId);
1909
1903 AssetService.Store(asset); 1910 AssetService.Store(asset);
1904 1911
1905 InventoryItemBase item = new InventoryItemBase(); 1912 InventoryItemBase item = new InventoryItemBase();
@@ -1948,6 +1955,7 @@ namespace OpenSim.Region.Framework.Scenes
1948 itemID = item.ID; 1955 itemID = item.ID;
1949 return item.AssetID; 1956 return item.AssetID;
1950 } 1957 }
1958
1951 return UUID.Zero; 1959 return UUID.Zero;
1952 } 1960 }
1953 1961
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
index 8fb9fad..a60ee9b 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -127,26 +127,36 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
127 /// <returns></returns> 127 /// <returns></returns>
128 public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject) 128 public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
129 { 129 {
130 return ToOriginalXmlFormat(sceneObject, true);
131 }
132
133 /// <summary>
134 /// Serialize a scene object to the original xml format
135 /// </summary>
136 /// <param name="sceneObject"></param>
137 /// <param name="doScriptStates">Control whether script states are also serialized.</para>
138 /// <returns></returns>
139 public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
140 {
130 using (StringWriter sw = new StringWriter()) 141 using (StringWriter sw = new StringWriter())
131 { 142 {
132 using (XmlTextWriter writer = new XmlTextWriter(sw)) 143 using (XmlTextWriter writer = new XmlTextWriter(sw))
133 { 144 {
134 ToOriginalXmlFormat(sceneObject, writer); 145 ToOriginalXmlFormat(sceneObject, writer, doScriptStates);
135 } 146 }
136 147
137 return sw.ToString(); 148 return sw.ToString();
138 } 149 }
139 } 150 }
140
141 151
142 /// <summary> 152 /// <summary>
143 /// Serialize a scene object to the original xml format 153 /// Serialize a scene object to the original xml format
144 /// </summary> 154 /// </summary>
145 /// <param name="sceneObject"></param> 155 /// <param name="sceneObject"></param>
146 /// <returns></returns> 156 /// <returns></returns>
147 public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer) 157 public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
148 { 158 {
149 ToOriginalXmlFormat(sceneObject, writer, false); 159 ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false);
150 } 160 }
151 161
152 /// <summary> 162 /// <summary>
@@ -156,10 +166,11 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
156 /// <param name="writer"></param> 166 /// <param name="writer"></param>
157 /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param> 167 /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param>
158 /// <returns></returns> 168 /// <returns></returns>
159 public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool noRootElement) 169 public static void ToOriginalXmlFormat(
170 SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
160 { 171 {
161 //m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name); 172// m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name);
162 //int time = System.Environment.TickCount; 173// int time = System.Environment.TickCount;
163 174
164 if (!noRootElement) 175 if (!noRootElement)
165 writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); 176 writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
@@ -182,12 +193,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
182 } 193 }
183 194
184 writer.WriteEndElement(); // OtherParts 195 writer.WriteEndElement(); // OtherParts
185 sceneObject.SaveScriptedState(writer); 196
197 if (doScriptStates)
198 sceneObject.SaveScriptedState(writer);
186 199
187 if (!noRootElement) 200 if (!noRootElement)
188 writer.WriteEndElement(); // SceneObjectGroup 201 writer.WriteEndElement(); // SceneObjectGroup
189 202
190 //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time); 203// m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time);
191 } 204 }
192 205
193 protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer) 206 protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)