aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs34
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs459
3 files changed, 463 insertions, 35 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
index a9498dd..cfc362c 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
@@ -1092,17 +1092,27 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1092 if(stateN == null) 1092 if(stateN == null)
1093 return false; 1093 return false;
1094 1094
1095 if(stateN.GetAttribute("Engine") != ScriptEngineName) 1095 bool isX = false;
1096 string sen = stateN.GetAttribute("Engine");
1097 if (sen == null)
1096 return false; 1098 return false;
1097 1099 if (sen != ScriptEngineName)
1098 // <ScriptState>...</ScriptState> contains contents of .state file. 1100 {
1099 XmlElement scriptStateN = (XmlElement)stateN.SelectSingleNode("ScriptState"); 1101 if(sen != "XEngine")
1102 return false;
1103 isX = true;
1104 }
1105 // <ScriptState>...</ScriptState> contains contents of .state file.
1106 XmlElement scriptStateN = (XmlElement)stateN.SelectSingleNode("ScriptState");
1100 if(scriptStateN == null) 1107 if(scriptStateN == null)
1101 return false; 1108 return false;
1102 1109
1103 string sen = stateN.GetAttribute("Engine"); 1110 if(!isX)
1104 if((sen == null) || (sen != ScriptEngineName)) 1111 {
1105 return false; 1112 sen = stateN.GetAttribute("Engine");
1113 if ((sen == null) || (sen != ScriptEngineName))
1114 return false;
1115 }
1106 1116
1107 XmlAttribute assetA = doc.CreateAttribute("", "Asset", ""); 1117 XmlAttribute assetA = doc.CreateAttribute("", "Asset", "");
1108 assetA.Value = stateN.GetAttribute("Asset"); 1118 assetA.Value = stateN.GetAttribute("Asset");
@@ -1110,11 +1120,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1110 1120
1111 // Write out the .state file with the <ScriptState ...>...</ScriptState> XML text 1121 // Write out the .state file with the <ScriptState ...>...</ScriptState> XML text
1112 string statePath = XMRInstance.GetStateFileName(m_ScriptBasePath, itemID); 1122 string statePath = XMRInstance.GetStateFileName(m_ScriptBasePath, itemID);
1113 FileStream ss = File.Create(statePath); 1123 using (FileStream ss = File.Create(statePath))
1114 StreamWriter sw = new StreamWriter(ss); 1124 {
1115 sw.Write(scriptStateN.OuterXml); 1125 using (StreamWriter sw = new StreamWriter(ss))
1116 sw.Close(); 1126 sw.Write(scriptStateN.OuterXml);
1117 ss.Close(); 1127 }
1118 1128
1119 return true; 1129 return true;
1120 } 1130 }
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs
index 490de74..092d9c2 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs
@@ -452,6 +452,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
452 return newuse; 452 return newuse;
453 } 453 }
454 454
455 public virtual void AddHeapUse(int delta)
456 {
457 Interlocked.Add(ref heapUsed, delta);
458 }
459
455 public int xmrHeapLeft() 460 public int xmrHeapLeft()
456 { 461 {
457 return heapLimit - heapUsed; 462 return heapLimit - heapUsed;
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs
index f7c4a7d..577a03d 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs
@@ -378,13 +378,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
378 } 378 }
379 else 379 else
380 { 380 {
381 FileStream fs = File.Open(m_StateFileName, 381 string xml;
382 using (FileStream fs = File.Open(m_StateFileName,
382 FileMode.Open, 383 FileMode.Open,
383 FileAccess.Read); 384 FileAccess.Read))
384 StreamReader ss = new StreamReader(fs); 385 {
385 string xml = ss.ReadToEnd(); 386 using(StreamReader ss = new StreamReader(fs))
386 ss.Close(); 387 xml = ss.ReadToEnd();
387 fs.Close(); 388 }
388 389
389 XmlDocument doc = new XmlDocument(); 390 XmlDocument doc = new XmlDocument();
390 doc.LoadXml(xml); 391 doc.LoadXml(xml);
@@ -471,17 +472,22 @@ namespace OpenSim.Region.ScriptEngine.Yengine
471 */ 472 */
472 private void LoadScriptState(XmlDocument doc) 473 private void LoadScriptState(XmlDocument doc)
473 { 474 {
474 DetectParams[] detParams;
475 LinkedList<EventParams> eventQueue;
476 475
477 // Everything we know is enclosed in <ScriptState>...</ScriptState> 476 // Everything we know is enclosed in <ScriptState>...</ScriptState>
478 XmlElement scriptStateN = (XmlElement)doc.SelectSingleNode("ScriptState"); 477 XmlElement scriptStateN = (XmlElement)doc.SelectSingleNode("ScriptState");
479 if(scriptStateN == null) 478 if(scriptStateN == null)
480 throw new Exception("no <ScriptState> tag"); 479 throw new Exception("no <ScriptState> tag");
481 480
481 XmlElement XvariablesN = null;
482 string sen = scriptStateN.GetAttribute("Engine"); 482 string sen = scriptStateN.GetAttribute("Engine");
483 if((sen == null) || (sen != m_Engine.ScriptEngineName)) 483 if((sen == null) || (sen != m_Engine.ScriptEngineName))
484 throw new Exception("<ScriptState> missing Engine=\"YEngine\" attribute"); 484 {
485 XvariablesN = (XmlElement)scriptStateN.SelectSingleNode("Variables");
486 if(XvariablesN == null)
487 throw new Exception("<ScriptState> missing Engine=\"YEngine\" attribute");
488 processXstate(doc);
489 return;
490 }
485 491
486 // AssetID is unique for the script source text so make sure the 492 // AssetID is unique for the script source text so make sure the
487 // state file was written for that source file 493 // state file was written for that source file
@@ -508,18 +514,17 @@ namespace OpenSim.Region.ScriptEngine.Yengine
508 m_Part.Inventory.UpdateInventoryItem(m_Item, false, false); 514 m_Part.Inventory.UpdateInventoryItem(m_Item, false, false);
509 515
510 // get values used by stuff like llDetectedGrab, etc. 516 // get values used by stuff like llDetectedGrab, etc.
511 detParams = RestoreDetectParams(scriptStateN.SelectSingleNode("DetectArray")); 517 DetectParams[] detParams = RestoreDetectParams(scriptStateN.SelectSingleNode("DetectArray"));
512 518
513 // Restore queued events 519 // Restore queued events
514 eventQueue = RestoreEventQueue(scriptStateN.SelectSingleNode("EventQueue")); 520 LinkedList<EventParams> eventQueue = RestoreEventQueue(scriptStateN.SelectSingleNode("EventQueue"));
515 521
516 // Restore timers and listeners 522 // Restore timers and listeners
517 XmlElement pluginN = (XmlElement)scriptStateN.SelectSingleNode("Plugins"); 523 XmlElement pluginN = (XmlElement)scriptStateN.SelectSingleNode("Plugins");
518 Object[] pluginData = ExtractXMLObjectArray(pluginN, "plugin"); 524 Object[] pluginData = ExtractXMLObjectArray(pluginN, "plugin");
519 525
520 // Script's global variables and stack contents 526 // Script's global variables and stack contents
521 XmlElement snapshotN = 527 XmlElement snapshotN = (XmlElement)scriptStateN.SelectSingleNode("Snapshot");
522 (XmlElement)scriptStateN.SelectSingleNode("Snapshot");
523 528
524 Byte[] data = Convert.FromBase64String(snapshotN.InnerText); 529 Byte[] data = Convert.FromBase64String(snapshotN.InnerText);
525 MemoryStream ms = new MemoryStream(); 530 MemoryStream ms = new MemoryStream();
@@ -553,16 +558,424 @@ namespace OpenSim.Region.ScriptEngine.Yengine
553 pluginData); 558 pluginData);
554 } 559 }
555 560
556 /** 561 private void processXstate(XmlDocument doc)
557 * @brief Read llDetectedGrab, etc, values from XML 562 {
558 * <EventQueue> 563
559 * <DetectParams>...</DetectParams> 564 XmlNodeList rootL = doc.GetElementsByTagName("ScriptState");
560 * . 565 if (rootL.Count != 1)
561 * . 566 throw new Exception("Xstate <ScriptState> missing");
562 * . 567
563 * </EventQueue> 568 XmlNode rootNode = rootL[0];
564 */ 569 if (rootNode == null)
565 private LinkedList<EventParams> RestoreEventQueue(XmlNode eventsN) 570 throw new Exception("Xstate root missing");
571
572 string stateName = "";
573 bool running = false;
574
575 UUID permsGranter = UUID.Zero;
576 int permsMask = 0;
577 double minEventDelay = 0.0;
578 Object[] pluginData = new Object[0];
579
580 LinkedList<EventParams> eventQueue = new LinkedList<EventParams>();
581
582 Dictionary<string, int> intNames = new Dictionary<string, int>();
583 Dictionary<string, int> doubleNames = new Dictionary<string, int>();
584 Dictionary<string, int> stringNames = new Dictionary<string, int>();
585 Dictionary<string, int> vectorNames = new Dictionary<string, int>();
586 Dictionary<string, int> rotationNames = new Dictionary<string, int>();
587 Dictionary<string, int> listNames = new Dictionary<string, int>();
588
589 int nn = m_ObjCode.globalVarNames.Count;
590 int[] ints = null;
591 double[] doubles = null;
592 string[] strings = null;
593 LSL_Vector[] vectors = null;
594 LSL_Rotation[] rotations = null;
595 LSL_List[] lists = null;
596
597 if (nn > 0)
598 {
599 if (m_ObjCode.globalVarNames.ContainsKey("iarIntegers"))
600 {
601 getvarNames(m_ObjCode.globalVarNames["iarIntegers"], intNames);
602 ints = new int[m_ObjCode.globalVarNames["iarIntegers"].Count];
603 }
604 if (m_ObjCode.globalVarNames.ContainsKey("iarFloats"))
605 {
606 getvarNames(m_ObjCode.globalVarNames["iarFloats"], doubleNames);
607 doubles = new double[m_ObjCode.globalVarNames["iarFloats"].Count];
608 }
609 if (m_ObjCode.globalVarNames.ContainsKey("iarVectors"))
610 {
611 getvarNames(m_ObjCode.globalVarNames["iarVectors"], vectorNames);
612 vectors = new LSL_Vector[m_ObjCode.globalVarNames["iarVectors"].Count];
613 }
614 if (m_ObjCode.globalVarNames.ContainsKey("iarRotations"))
615 {
616 getvarNames(m_ObjCode.globalVarNames["iarRotations"], rotationNames);
617 rotations = new LSL_Rotation[m_ObjCode.globalVarNames["iarRotations"].Count];
618 }
619 if (m_ObjCode.globalVarNames.ContainsKey("iarStrings"))
620 {
621 getvarNames(m_ObjCode.globalVarNames["iarStrings"], stringNames);
622 strings = new string[m_ObjCode.globalVarNames["iarStrings"].Count];
623 }
624 if (m_ObjCode.globalVarNames.ContainsKey("iarLists"))
625 {
626 getvarNames(m_ObjCode.globalVarNames["iarLists"], listNames);
627 lists = new LSL_List[m_ObjCode.globalVarNames["iarLists"].Count];
628 }
629 }
630
631 int heapsz = 0;
632
633 try
634 {
635 XmlNodeList partL = rootNode.ChildNodes;
636 foreach (XmlNode part in partL)
637 {
638 switch (part.Name)
639 {
640 case "State":
641 stateName = part.InnerText;
642 break;
643 case "Running":
644 running = bool.Parse(part.InnerText);
645 break;
646 case "Variables":
647 int indx;
648 XmlNodeList varL = part.ChildNodes;
649 foreach (XmlNode var in varL)
650 {
651 string varName;
652 object o = ReadXTypedValue(var, out varName);
653 Type otype = o.GetType();
654 if (otype == typeof(LSL_Integer))
655 {
656 if (intNames.TryGetValue(varName, out indx))
657 ints[indx] = ((LSL_Integer)o);
658 continue;
659 }
660 if (otype == typeof(LSL_Float))
661 {
662 if (doubleNames.TryGetValue(varName, out indx))
663 doubles[indx] = ((LSL_Float)o);
664 continue;
665 }
666 if (otype == typeof(LSL_String))
667 {
668 if (stringNames.TryGetValue(varName, out indx))
669 {
670 strings[indx] = ((LSL_String)o);
671 heapsz += ((LSL_String)o).Length;
672 }
673 continue;
674 }
675 if (otype == typeof(LSL_Rotation))
676 {
677 if (rotationNames.TryGetValue(varName, out indx))
678 rotations[indx] = ((LSL_Rotation)o);
679 continue;
680 }
681 if (otype == typeof(LSL_Vector))
682 {
683 if (vectorNames.TryGetValue(varName, out indx))
684 vectors[indx] = ((LSL_Vector)o);
685 continue;
686 }
687 if (otype == typeof(LSL_Key))
688 {
689 if (stringNames.TryGetValue(varName, out indx))
690 {
691 strings[indx] = ((LSL_Key)o);
692 heapsz += ((LSL_String)o).Length;
693 }
694 continue;
695 }
696 if (otype == typeof(UUID))
697 {
698 if (stringNames.TryGetValue(varName, out indx))
699 {
700 LSL_String id = ((UUID)o).ToString();
701 strings[indx] = (id);
702 heapsz += id.Length;
703 }
704 continue;
705 }
706 if (otype == typeof(LSL_List))
707 {
708 if (listNames.TryGetValue(varName, out indx))
709 {
710 LSL_List lo = (LSL_List)o;
711 lists[indx] = (lo);
712 heapsz += lo.Size;
713 }
714 continue;
715 }
716 }
717 break;
718 case "Queue":
719 XmlNodeList itemL = part.ChildNodes;
720 foreach (XmlNode item in itemL)
721 {
722 List<Object> parms = new List<Object>();
723 List<DetectParams> detected = new List<DetectParams>();
724
725 string eventName = item.Attributes.GetNamedItem("event").Value;
726 XmlNodeList eventL = item.ChildNodes;
727 foreach (XmlNode evt in eventL)
728 {
729 switch (evt.Name)
730 {
731 case "Params":
732 XmlNodeList prms = evt.ChildNodes;
733 foreach (XmlNode pm in prms)
734 parms.Add(ReadXTypedValue(pm));
735
736 break;
737 case "Detected":
738 XmlNodeList detL = evt.ChildNodes;
739 foreach (XmlNode det in detL)
740 {
741 string vect = det.Attributes.GetNamedItem("pos").Value;
742 LSL_Vector v = new LSL_Vector(vect);
743
744 int d_linkNum = 0;
745 UUID d_group = UUID.Zero;
746 string d_name = String.Empty;
747 UUID d_owner = UUID.Zero;
748 LSL_Vector d_position = new LSL_Vector();
749 LSL_Rotation d_rotation = new LSL_Rotation();
750 int d_type = 0;
751 LSL_Vector d_velocity = new LSL_Vector();
752
753 try
754 {
755 string tmp;
756
757 tmp = det.Attributes.GetNamedItem("linkNum").Value;
758 int.TryParse(tmp, out d_linkNum);
759
760 tmp = det.Attributes.GetNamedItem("group").Value;
761 UUID.TryParse(tmp, out d_group);
762
763 d_name = det.Attributes.GetNamedItem("name").Value;
764
765 tmp = det.Attributes.GetNamedItem("owner").Value;
766 UUID.TryParse(tmp, out d_owner);
767
768 tmp = det.Attributes.GetNamedItem("position").Value;
769 d_position = new LSL_Types.Vector3(tmp);
770
771 tmp = det.Attributes.GetNamedItem("rotation").Value;
772 d_rotation = new LSL_Rotation(tmp);
773
774 tmp = det.Attributes.GetNamedItem("type").Value;
775 int.TryParse(tmp, out d_type);
776
777 tmp = det.Attributes.GetNamedItem("velocity").Value;
778 d_velocity = new LSL_Vector(tmp);
779 }
780 catch (Exception) // Old version XML
781 {
782 }
783
784 UUID uuid = new UUID();
785 UUID.TryParse(det.InnerText, out uuid);
786
787 DetectParams d = new DetectParams();
788 d.Key = uuid;
789 d.OffsetPos = v;
790 d.LinkNum = d_linkNum;
791 d.Group = d_group;
792 d.Name = d_name;
793 d.Owner = d_owner;
794 d.Position = d_position;
795 d.Rotation = d_rotation;
796 d.Type = d_type;
797 d.Velocity = d_velocity;
798
799 detected.Add(d);
800 }
801 break;
802 }
803 }
804 EventParams ep = new EventParams(
805 eventName, parms.ToArray(),
806 detected.ToArray());
807 eventQueue.AddLast(ep);
808 }
809 break;
810 case "Plugins":
811 List<Object> olist = new List<Object>();
812 XmlNodeList itemLP = part.ChildNodes;
813 foreach (XmlNode item in itemLP)
814 olist.Add(ReadXTypedValue(item));
815 pluginData = olist.ToArray();
816 break;
817 case "Permissions":
818 string tmpPerm;
819 int mask = 0;
820 tmpPerm = part.Attributes.GetNamedItem("mask").Value;
821 if (tmpPerm != null)
822 {
823 int.TryParse(tmpPerm, out mask);
824 if (mask != 0)
825 {
826 tmpPerm = part.Attributes.GetNamedItem("granter").Value;
827 if (tmpPerm != null)
828 {
829 UUID granter = new UUID();
830 UUID.TryParse(tmpPerm, out granter);
831 if (granter != UUID.Zero)
832 {
833 permsMask = mask;
834 permsGranter = granter;
835 }
836 }
837 }
838 }
839 break;
840 case "MinEventDelay":
841 double.TryParse(part.InnerText, out minEventDelay);
842 break;
843 }
844 }
845 }
846 catch
847 {
848 throw new Exception("Xstate fail decode");
849 }
850
851 int k = 0;
852 stateCode = 0;
853 foreach (string sn in m_ObjCode.stateNames)
854 {
855 if (stateName == sn)
856 {
857 stateCode = k;
858 break;
859 }
860 k++;
861 }
862 eventCode = ScriptEventCode.None;
863 m_Running = running;
864 doGblInit = false;
865
866 m_Item.PermsGranter = permsGranter;
867 m_Item.PermsMask = permsMask;
868 m_Part.Inventory.UpdateInventoryItem(m_Item, false, false);
869
870 lock (m_RunLock)
871 {
872 glblVars.iarIntegers = ints;
873 glblVars.iarFloats = doubles;
874 glblVars.iarVectors = vectors;
875 glblVars.iarRotations = rotations;
876 glblVars.iarStrings = strings;
877 glblVars.iarLists = lists;
878
879 AddHeapUse(heapsz);
880 CheckRunLockInvariants(true);
881 }
882
883 lock (m_QueueLock)
884 {
885 m_DetectParams = null;
886 foreach (EventParams evt in m_EventQueue)
887 eventQueue.AddLast(evt);
888
889 m_EventQueue = eventQueue;
890 for (int i = m_EventCounts.Length; --i >= 0;)
891 m_EventCounts[i] = 0;
892 foreach (EventParams evt in m_EventQueue)
893 {
894 ScriptEventCode eventCode = (ScriptEventCode)Enum.Parse(typeof(ScriptEventCode),
895 evt.EventName);
896 m_EventCounts[(int)eventCode]++;
897 }
898 }
899
900 AsyncCommandManager.CreateFromData(m_Engine,
901 m_LocalID, m_ItemID, m_Part.UUID, pluginData);
902 }
903
904 private static void getvarNames(Dictionary<int, string> s, Dictionary<string, int> d)
905 {
906 foreach(KeyValuePair<int, string> kvp in s)
907 d[kvp.Value] = kvp.Key;
908 }
909
910 private static LSL_Types.list ReadXList(XmlNode parent)
911 {
912 List<Object> olist = new List<Object>();
913
914 XmlNodeList itemL = parent.ChildNodes;
915 foreach (XmlNode item in itemL)
916 olist.Add(ReadXTypedValue(item));
917
918 return new LSL_Types.list(olist.ToArray());
919 }
920
921 private static object ReadXTypedValue(XmlNode tag, out string name)
922 {
923 name = tag.Attributes.GetNamedItem("name").Value;
924
925 return ReadXTypedValue(tag);
926 }
927
928 private static object ReadXTypedValue(XmlNode tag)
929 {
930 Object varValue;
931 string assembly;
932
933 string itemType = tag.Attributes.GetNamedItem("type").Value;
934
935 if (itemType == "list")
936 return ReadXList(tag);
937
938 if (itemType == "OpenMetaverse.UUID")
939 {
940 UUID val = new UUID();
941 UUID.TryParse(tag.InnerText, out val);
942
943 return val;
944 }
945
946 Type itemT = Type.GetType(itemType);
947 if (itemT == null)
948 {
949 Object[] args =
950 new Object[] { tag.InnerText };
951
952 assembly = itemType + ", OpenSim.Region.ScriptEngine.Shared";
953 itemT = Type.GetType(assembly);
954 if (itemT == null)
955 return null;
956
957 varValue = Activator.CreateInstance(itemT, args);
958
959 if (varValue == null)
960 return null;
961 }
962 else
963 {
964 varValue = Convert.ChangeType(tag.InnerText, itemT);
965 }
966 return varValue;
967 }
968
969 /**
970 * @brief Read llDetectedGrab, etc, values from XML
971 * <EventQueue>
972 * <DetectParams>...</DetectParams>
973 * .
974 * .
975 * .
976 * </EventQueue>
977 */
978 private LinkedList<EventParams> RestoreEventQueue(XmlNode eventsN)
566 { 979 {
567 LinkedList<EventParams> eventQueue = new LinkedList<EventParams>(); 980 LinkedList<EventParams> eventQueue = new LinkedList<EventParams>();
568 if(eventsN != null) 981 if(eventsN != null)