30 using System.Threading;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Security.Policy;
34 using System.Reflection;
35 using System.Globalization;
41 using OpenSim.Framework;
42 using OpenSim.Region.CoreModules;
43 using OpenSim.Region.Framework.Scenes;
44 using OpenSim.Region.Framework.Interfaces;
45 using OpenSim.Region.ScriptEngine.Shared;
46 using OpenSim.Region.ScriptEngine.Shared.Api;
47 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
48 using OpenSim.Region.ScriptEngine.Shared.CodeTools;
49 using OpenSim.Region.ScriptEngine.Interfaces;
51 namespace OpenSim.
Region.ScriptEngine.Shared.Instance
57 bool running = instance.Running;
59 XmlDocument xmldoc =
new XmlDocument();
61 XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
63 xmldoc.AppendChild(xmlnode);
65 XmlElement rootElement = xmldoc.CreateElement(
"",
"ScriptState",
67 xmldoc.AppendChild(rootElement);
69 XmlElement state = xmldoc.CreateElement(
"",
"State",
"");
70 state.AppendChild(xmldoc.CreateTextNode(instance.State));
72 rootElement.AppendChild(state);
74 XmlElement run = xmldoc.CreateElement(
"",
"Running",
"");
75 run.AppendChild(xmldoc.CreateTextNode(
78 rootElement.AppendChild(run);
80 Dictionary<string, Object> vars = instance.GetVars();
82 XmlElement variables = xmldoc.CreateElement(
"",
"Variables",
"");
84 foreach (KeyValuePair<string, Object> var
in vars)
85 WriteTypedValue(xmldoc, variables,
"Variable", var.Key,
88 rootElement.AppendChild(variables);
90 XmlElement queue = xmldoc.CreateElement(
"",
"Queue",
"");
92 int count = instance.EventQueue.Count;
97 instance.EventQueue.Enqueue(ep);
100 XmlElement item = xmldoc.CreateElement(
"",
"Item",
"");
101 XmlAttribute itemEvent = xmldoc.CreateAttribute(
"",
"event",
103 itemEvent.Value = ep.EventName;
104 item.Attributes.Append(itemEvent);
106 XmlElement parms = xmldoc.CreateElement(
"",
"Params",
"");
108 foreach (
Object o
in ep.Params)
109 WriteTypedValue(xmldoc, parms,
"Param",
String.Empty, o);
111 item.AppendChild(parms);
113 XmlElement detect = xmldoc.CreateElement(
"",
"Detected",
"");
117 XmlElement objectElem = xmldoc.CreateElement(
"",
"Object",
119 XmlAttribute pos = xmldoc.CreateAttribute(
"",
"pos",
"");
120 pos.Value = det.OffsetPos.ToString();
121 objectElem.Attributes.Append(pos);
123 XmlAttribute d_linkNum = xmldoc.CreateAttribute(
"",
125 d_linkNum.Value = det.LinkNum.ToString();
126 objectElem.Attributes.Append(d_linkNum);
128 XmlAttribute d_group = xmldoc.CreateAttribute(
"",
130 d_group.Value = det.Group.ToString();
131 objectElem.Attributes.Append(d_group);
133 XmlAttribute d_name = xmldoc.CreateAttribute(
"",
135 d_name.Value = det.Name.ToString();
136 objectElem.Attributes.Append(d_name);
138 XmlAttribute d_owner = xmldoc.CreateAttribute(
"",
140 d_owner.Value = det.Owner.ToString();
141 objectElem.Attributes.Append(d_owner);
143 XmlAttribute d_position = xmldoc.CreateAttribute(
"",
145 d_position.Value = det.Position.ToString();
146 objectElem.Attributes.Append(d_position);
148 XmlAttribute d_rotation = xmldoc.CreateAttribute(
"",
150 d_rotation.Value = det.Rotation.ToString();
151 objectElem.Attributes.Append(d_rotation);
153 XmlAttribute d_type = xmldoc.CreateAttribute(
"",
155 d_type.Value = det.Type.ToString();
156 objectElem.Attributes.Append(d_type);
158 XmlAttribute d_velocity = xmldoc.CreateAttribute(
"",
160 d_velocity.Value = det.Velocity.ToString();
161 objectElem.Attributes.Append(d_velocity);
163 objectElem.AppendChild(
164 xmldoc.CreateTextNode(det.Key.ToString()));
166 detect.AppendChild(objectElem);
169 item.AppendChild(detect);
171 queue.AppendChild(item);
174 rootElement.AppendChild(queue);
176 XmlNode plugins = xmldoc.CreateElement(
"",
"Plugins",
"");
177 DumpList(xmldoc, plugins,
178 new LSL_Types.list(instance.PluginData));
180 rootElement.AppendChild(plugins);
182 if (instance.ScriptTask != null)
184 if (instance.ScriptTask.PermsMask != 0 && instance.ScriptTask.PermsGranter !=
UUID.Zero)
186 XmlNode permissions = xmldoc.CreateElement(
"",
"Permissions",
"");
187 XmlAttribute granter = xmldoc.CreateAttribute(
"",
"granter",
"");
188 granter.Value = instance.ScriptTask.PermsGranter.ToString();
189 permissions.Attributes.Append(granter);
190 XmlAttribute mask = xmldoc.CreateAttribute(
"",
"mask",
"");
191 mask.Value = instance.ScriptTask.PermsMask.ToString();
192 permissions.Attributes.Append(mask);
193 rootElement.AppendChild(permissions);
197 if (instance.MinEventDelay > 0.0)
199 XmlElement eventDelay = xmldoc.CreateElement(
"",
"MinEventDelay",
"");
200 eventDelay.AppendChild(xmldoc.CreateTextNode(instance.MinEventDelay.ToString()));
201 rootElement.AppendChild(eventDelay);
204 return xmldoc.InnerXml;
209 XmlDocument doc =
new XmlDocument();
211 Dictionary<string, object> vars = instance.GetVars();
213 instance.PluginData =
new Object[0];
217 XmlNodeList rootL = doc.GetElementsByTagName(
"ScriptState");
218 if (rootL.Count != 1)
222 XmlNode rootNode = rootL[0];
224 if (rootNode != null)
227 XmlNodeList partL = rootNode.ChildNodes;
229 foreach (XmlNode part
in partL)
234 instance.State=part.InnerText;
237 instance.Running=bool.Parse(part.InnerText);
240 XmlNodeList varL = part.ChildNodes;
241 foreach (XmlNode var
in varL)
244 varValue=ReadTypedValue(var, out varName);
246 if (vars.ContainsKey(varName))
247 vars[varName] = varValue;
249 instance.SetVars(vars);
252 XmlNodeList itemL = part.ChildNodes;
253 foreach (XmlNode item
in itemL)
255 List<Object> parms =
new List<Object>();
256 List<DetectParams> detected =
257 new List<DetectParams>();
260 item.Attributes.GetNamedItem(
"event").
Value;
261 XmlNodeList eventL = item.ChildNodes;
262 foreach (XmlNode evt
in eventL)
267 XmlNodeList prms = evt.ChildNodes;
268 foreach (XmlNode pm
in prms)
269 parms.Add(ReadTypedValue(pm));
273 XmlNodeList detL = evt.ChildNodes;
274 foreach (XmlNode det
in detL)
277 det.Attributes.GetNamedItem(
283 UUID d_group = UUID.Zero;
284 string d_name = String.Empty;
285 UUID d_owner = UUID.Zero;
298 tmp = det.Attributes.GetNamedItem(
300 int.TryParse(tmp, out d_linkNum);
302 tmp = det.Attributes.GetNamedItem(
304 UUID.TryParse(tmp, out d_group);
306 d_name = det.Attributes.GetNamedItem(
309 tmp = det.Attributes.GetNamedItem(
311 UUID.TryParse(tmp, out d_owner);
313 tmp = det.Attributes.GetNamedItem(
318 tmp = det.Attributes.GetNamedItem(
323 tmp = det.Attributes.GetNamedItem(
325 int.TryParse(tmp, out d_type);
327 tmp = det.Attributes.GetNamedItem(
338 UUID.TryParse(det.InnerText,
344 d.LinkNum = d_linkNum;
348 d.Position = d_position;
349 d.Rotation = d_rotation;
351 d.Velocity = d_velocity;
359 eventName, parms.ToArray(),
361 instance.EventQueue.Enqueue(ep);
365 instance.PluginData = ReadList(part).Data;
370 tmpPerm = part.Attributes.GetNamedItem(
"mask").
Value;
373 int.TryParse(tmpPerm, out mask);
376 tmpPerm = part.Attributes.GetNamedItem(
"granter").
Value;
380 UUID.TryParse(tmpPerm, out granter);
381 if (granter !=
UUID.Zero)
383 instance.ScriptTask.PermsMask = mask;
384 instance.ScriptTask.PermsGranter = granter;
390 case "MinEventDelay":
391 double minEventDelay = 0.0;
392 double.TryParse(part.InnerText, NumberStyles.Float, Culture.NumberFormatInfo, out minEventDelay);
393 instance.MinEventDelay = minEventDelay;
400 private static void DumpList(XmlDocument doc, XmlNode parent,
403 foreach (Object o
in l.Data)
404 WriteTypedValue(doc, parent,
"ListItem",
"", o);
409 List<Object> olist =
new List<Object>();
411 XmlNodeList itemL = parent.ChildNodes;
412 foreach (XmlNode item
in itemL)
413 olist.Add(ReadTypedValue(item));
418 private static void WriteTypedValue(XmlDocument doc, XmlNode parent,
419 string tag,
string name,
object value)
421 Type t=value.GetType();
422 XmlAttribute typ = doc.CreateAttribute(
"",
"type",
"");
423 XmlNode n = doc.CreateElement(
"", tag,
"");
428 n.Attributes.Append(typ);
430 DumpList(doc, n, (
LSL_Types.list) value);
434 XmlAttribute nam = doc.CreateAttribute(
"",
"name",
"");
436 n.Attributes.Append(nam);
439 parent.AppendChild(n);
443 n.AppendChild(doc.CreateTextNode(value.ToString()));
445 typ.Value = t.ToString();
446 n.Attributes.Append(typ);
449 XmlAttribute nam = doc.CreateAttribute(
"",
"name",
"");
451 n.Attributes.Append(nam);
454 parent.AppendChild(n);
457 private static object ReadTypedValue(XmlNode tag, out
string name)
459 name = tag.Attributes.GetNamedItem(
"name").Value;
461 return ReadTypedValue(tag);
464 private static object ReadTypedValue(XmlNode tag)
469 string itemType = tag.Attributes.GetNamedItem(
"type").Value;
471 if (itemType ==
"list")
472 return ReadList(tag);
474 if (itemType ==
"OpenMetaverse.UUID")
477 UUID.TryParse(tag.InnerText, out val);
482 Type itemT = Type.GetType(itemType);
486 new Object[] { tag.InnerText };
488 assembly = itemType+
", OpenSim.Region.ScriptEngine.Shared";
489 itemT = Type.GetType(assembly);
493 varValue = Activator.CreateInstance(itemT, args);
495 if (varValue == null)
500 varValue = Convert.ChangeType(tag.InnerText, itemT);
static void Deserialize(string xml, ScriptInstance instance)
static string Serialize(ScriptInstance instance)
Holds all the data required to execute a scripting event.