aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
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
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')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs35
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs14
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs31
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs9
6 files changed, 80 insertions, 24 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index a854c11..c274a5b 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -101,7 +101,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
101 /// <param name="silent"></param> 101 /// <param name="silent"></param>
102 public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) 102 public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent)
103 { 103 {
104// m_log.Debug("[ATTACHMENTS MODULE]: Invoking AttachObject"); 104// m_log.DebugFormat(
105// "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
106// objectLocalID, remoteClient.Name, AttachmentPt, silent);
105 107
106 try 108 try
107 { 109 {
@@ -163,8 +165,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
163 return AttachObject(sp, group, AttachmentPt, silent); 165 return AttachObject(sp, group, AttachmentPt, silent);
164 } 166 }
165 167
166 public bool AttachObject(ScenePresence sp, SceneObjectGroup group, uint AttachmentPt, bool silent) 168 private bool AttachObject(ScenePresence sp, SceneObjectGroup group, uint AttachmentPt, bool silent)
167 { 169 {
170// m_log.DebugFormat(
171// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
172// group.Name, group.LocalId, sp.Name, AttachmentPt, silent);
173
174 if (sp.GetAttachments(AttachmentPt).Contains(group))
175 {
176// m_log.WarnFormat(
177// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
178// group.Name, group.LocalId, sp.Name, AttachmentPt);
179
180 return false;
181 }
182
168 Vector3 attachPos = group.AbsolutePosition; 183 Vector3 attachPos = group.AbsolutePosition;
169 184
170 // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should 185 // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should
@@ -211,14 +226,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
211 if (itemID != UUID.Zero) 226 if (itemID != UUID.Zero)
212 DetachSingleAttachmentToInv(itemID, sp); 227 DetachSingleAttachmentToInv(itemID, sp);
213 228
214 if (group.GetFromItemID() == UUID.Zero) 229 itemID = group.GetFromItemID();
215 { 230 if (itemID == UUID.Zero)
216 m_scene.attachObjectAssetStore(sp.ControllingClient, group, sp.UUID, out itemID); 231 m_scene.attachObjectAssetStore(sp.ControllingClient, group, sp.UUID, out itemID);
217 }
218 else
219 {
220 itemID = group.GetFromItemID();
221 }
222 232
223 ShowAttachInUserInventory(sp, AttachmentPt, itemID, group); 233 ShowAttachInUserInventory(sp, AttachmentPt, itemID, group);
224 234
@@ -548,7 +558,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
548 "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", 558 "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}",
549 grp.UUID, grp.GetAttachmentPoint()); 559 grp.UUID, grp.GetAttachmentPoint());
550 560
551 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); 561 // If we're being called from a script, then trying to serialize that same script's state will not complete
562 // in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
563 // the client/server crashes rather than logging out normally, the attachment's scripts will resume
564 // without state on relog. Arguably, this is what we want anyway.
565 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false);
566
552 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); 567 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
553 item = m_scene.InventoryService.GetItem(item); 568 item = m_scene.InventoryService.GetItem(item);
554 569
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)
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index 8b7871b..0cc0fe7 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -58,7 +58,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
58 /// </summary> 58 /// </summary>
59 public interface IScriptInstance 59 public interface IScriptInstance
60 { 60 {
61 /// <summary>
62 /// Is this script currently running?
63 /// </summary>
61 bool Running { get; set; } 64 bool Running { get; set; }
65
62 bool ShuttingDown { get; set; } 66 bool ShuttingDown { get; set; }
63 string State { get; set; } 67 string State { get; set; }
64 IScriptEngine Engine { get; } 68 IScriptEngine Engine { get; }
@@ -78,7 +82,14 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
78 82
79 void Init(); 83 void Init();
80 void Start(); 84 void Start();
85
86 /// <summary>
87 /// Stop the script.
88 /// </summary>
89 /// <param name="timeout"></param>
90 /// <returns>true if the script was successfully stopped, false otherwise</returns>
81 bool Stop(int timeout); 91 bool Stop(int timeout);
92
82 void SetState(string state); 93 void SetState(string state);
83 94
84 void PostEvent(EventParams data); 95 void PostEvent(EventParams data);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ffa0e24..d340ef2 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2964,8 +2964,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2964 { 2964 {
2965 m_host.AddScriptLPS(1); 2965 m_host.AddScriptLPS(1);
2966 2966
2967 if (m_host.ParentGroup.RootPart.AttachmentPoint == 0) 2967// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2968 return; 2968// return;
2969 2969
2970 TaskInventoryItem item; 2970 TaskInventoryItem item;
2971 2971
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index d253c6a..c443669 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1294,9 +1294,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1294 1294
1295 public string GetXMLState(UUID itemID) 1295 public string GetXMLState(UUID itemID)
1296 { 1296 {
1297// m_log.DebugFormat("[XEngine]: Getting XML state for {0}", itemID);
1298
1297 IScriptInstance instance = GetInstance(itemID); 1299 IScriptInstance instance = GetInstance(itemID);
1298 if (instance == null) 1300 if (instance == null)
1301 {
1302// m_log.DebugFormat("[XEngine]: Found no script for {0}, returning empty string", itemID);
1299 return ""; 1303 return "";
1304 }
1305
1300 string xml = instance.GetXMLState(); 1306 string xml = instance.GetXMLState();
1301 1307
1302 XmlDocument sdoc = new XmlDocument(); 1308 XmlDocument sdoc = new XmlDocument();
@@ -1437,6 +1443,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1437 mapData.InnerText = map; 1443 mapData.InnerText = map;
1438 1444
1439 stateData.AppendChild(mapData); 1445 stateData.AppendChild(mapData);
1446
1447// m_log.DebugFormat("[XEngine]: Got XML state for {0}", itemID);
1448
1440 return doc.InnerXml; 1449 return doc.InnerXml;
1441 } 1450 }
1442 1451