Exemplo n.º 1
0
        public static void SaveState(ScriptData instance, ScriptEngine engine)
        {
            StateSave Insert = new StateSave();
            Insert.State = instance.State;
            Insert.ItemID = instance.ItemID;
            string source = instance.Source.Replace("\n", " ");
            Insert.Source = source.Replace("'", " ");
            Insert.Running = instance.Running;
            //Vars
            Dictionary<string, Object> vars = new Dictionary<string, object>();
            if (instance.Script != null)
                vars = instance.Script.GetVars();
            string varsmap = "";
            foreach (KeyValuePair<string, Object> var in vars)
            {
                varsmap += var.Key + "," + var.Value + "\n";
            }
            Insert.Variables = varsmap;
            //Plugins
            object[] Plugins = engine.GetSerializationData( instance.ItemID, instance.part.UUID);
            string plugins = "";
            foreach (object plugin in Plugins)
                plugins += plugin + ",";
            Insert.Plugins = plugins;

            //perms
            string perms = "";
            if (instance.InventoryItem != null)
            {
                if (instance.InventoryItem.PermsMask != 0 && instance.InventoryItem.PermsGranter != UUID.Zero)
                {
                    perms += instance.InventoryItem.PermsGranter.ToString() + "," + instance.InventoryItem.PermsMask.ToString();

                }
            }
            Insert.Permissions = perms;

            Insert.MinEventDelay = instance.EventDelayTicks;
            string[] AN = instance.AssemblyName.Split('\\');
            if(AN.Length > 2)
                Insert.AssemblyName = instance.AssemblyName.Split('\\')[2];
            else
            	Insert.AssemblyName = instance.AssemblyName;
            Insert.Disabled = instance.Disabled;
            Insert.UserInventoryID = instance.UserInventoryItemID;
            IScriptDataConnector ScriptFrontend = Aurora.DataManager.DataManager.RequestPlugin<IScriptDataConnector>();
            if(ScriptFrontend != null)
                ScriptFrontend.SaveStateSave(Insert);
        }
Exemplo n.º 2
0
        public static string GetXMLState(ScriptData instance, ScriptEngine engine)
        {
            if (instance.Script == null)
                return "";
            //Update PluginData
            instance.PluginData = engine.GetSerializationData(instance.ItemID, instance.part.UUID);

            bool running = instance.Running;

            XmlDocument xmldoc = new XmlDocument();

            XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
                                                "", "");
            xmldoc.AppendChild(xmlnode);

            XmlElement rootElement = xmldoc.CreateElement("", "ScriptState",
                                                          "");
            xmldoc.AppendChild(rootElement);

            XmlElement state = xmldoc.CreateElement("", "State", "");
            state.AppendChild(xmldoc.CreateTextNode(instance.State));

            rootElement.AppendChild(state);

            XmlElement run = xmldoc.CreateElement("", "Running", "");
            run.AppendChild(xmldoc.CreateTextNode(
                    running.ToString()));

            rootElement.AppendChild(run);

            Dictionary<string, Object> vars = instance.Script.GetVars();

            XmlElement variables = xmldoc.CreateElement("", "Variables", "");

            foreach (KeyValuePair<string, Object> var in vars)
                WriteTypedValue(xmldoc, variables, "Variable", var.Key,
                                var.Value);

            rootElement.AppendChild(variables);

            #region Queue

            //We don't do queue...
            XmlElement queue = xmldoc.CreateElement("", "Queue", "");
            rootElement.AppendChild(queue);

            #endregion

            XmlNode plugins = xmldoc.CreateElement("", "Plugins", "");
            DumpList(xmldoc, plugins,
                     new LSL_Types.list(instance.PluginData));

            rootElement.AppendChild(plugins);

            if (instance.InventoryItem != null)
            {
                if (instance.InventoryItem.PermsMask != 0 && instance.InventoryItem.PermsGranter != UUID.Zero)
                {
                    XmlNode permissions = xmldoc.CreateElement("", "Permissions", "");
                    XmlAttribute granter = xmldoc.CreateAttribute("", "granter", "");
                    granter.Value = instance.InventoryItem.PermsGranter.ToString();
                    permissions.Attributes.Append(granter);
                    XmlAttribute mask = xmldoc.CreateAttribute("", "mask", "");
                    mask.Value = instance.InventoryItem.PermsMask.ToString();
                    permissions.Attributes.Append(mask);
                    rootElement.AppendChild(permissions);
                }
            }

            if (instance.EventDelayTicks > 0.0)
            {
                XmlElement eventDelay = xmldoc.CreateElement("", "MinEventDelay", "");
                eventDelay.AppendChild(xmldoc.CreateTextNode(instance.EventDelayTicks.ToString()));
                rootElement.AppendChild(eventDelay);
            }
            Type type = instance.Script.GetType();
            FieldInfo[] mi = type.GetFields();
            string xml = xmldoc.InnerXml;

            XmlDocument sdoc = new XmlDocument();
            sdoc.LoadXml(xml);
            XmlNodeList rootL = sdoc.GetElementsByTagName("ScriptState");
            XmlNode rootNode = rootL[0];

            // Create <State UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">
            XmlDocument doc = new XmlDocument();
            XmlElement stateData = doc.CreateElement("", "State", "");
            XmlAttribute stateID = doc.CreateAttribute("", "UUID", "");
            stateID.Value = instance.ItemID.ToString();
            stateData.Attributes.Append(stateID);
            XmlAttribute assetID = doc.CreateAttribute("", "Asset", "");
            assetID.Value = instance.InventoryItem.AssetID.ToString();
            stateData.Attributes.Append(assetID);
            XmlAttribute engineName = doc.CreateAttribute("", "Engine", "");
            engineName.Value = engine.ScriptEngineName;
            stateData.Attributes.Append(engineName);
            doc.AppendChild(stateData);

            // Add <ScriptState>...</ScriptState>
            XmlNode xmlstate = doc.ImportNode(rootNode, true);
            stateData.AppendChild(xmlstate);

            string assemName = instance.AssemblyName;

            XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
            XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", "");

            assemblyName.Value = assemName;
            assemblyData.Attributes.Append(assemblyName);

            assemblyData.InnerText = assemName;

            stateData.AppendChild(assemblyData);

            XmlElement mapData = doc.CreateElement("", "LineMap", "");
            XmlAttribute mapName = doc.CreateAttribute("", "Filename", "");

            mapName.Value = assemName + ".map";
            mapData.Attributes.Append(mapName);

            mapData.InnerText = assemName;

            stateData.AppendChild(mapData);

            return doc.InnerXml;
        }