コード例 #1
0
        public void DeleteFrom(ScriptData script)
        {
            bool changed = false;

            lock (StateSaveLock)
            {
                //if we did remove something, resave it
                if (script.Part.StateSaves.Remove(script.ItemID))
                {
                    changed = true;
                }
                if (script.Part.StateSaves.Remove(script.InventoryItem.OldItemID))
                {
                    changed = true;
                }
                if (script.Part.StateSaves.Remove(script.InventoryItem.ItemID))
                {
                    changed = true;
                }
            }
            if (changed)
            {
                script.Part.ParentEntity.HasGroupChanged = true;
            }
        }
コード例 #2
0
        public StateSave FindScriptStateSave(ScriptData script)
        {
            OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;

            //Attempt to find the state saves we have
            if (component != null)
            {
                OSD o;
                //If we have one for this item, deserialize it
                if (!component.TryGetValue(script.ItemID.ToString(), out o))
                {
                    if (!component.TryGetValue(script.InventoryItem.OldItemID.ToString(), out o))
                    {
                        if (!component.TryGetValue(script.InventoryItem.ItemID.ToString(), out o))
                        {
                            return(null);
                        }
                    }
                }
                StateSave save = new StateSave();
                save.FromOSD((OSDMap)o);
                return(save);
            }
            return(null);
        }
コード例 #3
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority,
                                     params object[] param)
        {
            QueueItemStruct QIS = new QueueItemStruct
            {
                EventsProcData = new ScriptEventsProcData(),
                ID             = ID,
                functionName   = FunctionName,
                llDetectParams = qParams,
                param          = param,
                VersionID      = Interlocked.Read(ref ID.VersionID),
                State          = ID.State,
                CurrentlyAt    = null
            };

            if (ID == null || ID.Script == null || ID.IgnoreNew)
            {
                return;
            }

            if (!ID.SetEventParams(QIS)) // check events delay rules
            {
                return;
            }

            ScriptEvents.Enqueue(QIS);

            long threadCount = Interlocked.Read(ref scriptThreadpool.nthreads);

            if (threadCount == 0 || threadCount < (ScriptEvents.Count + (SleepingScriptEventCount / 2)) * EventPerformance)
            {
                scriptThreadpool.QueueEvent(eventLoop, 2);
            }
        }
コード例 #4
0
 /// <summary>
 ///     Fires the action associated with the limitation
 /// </summary>
 /// <param name="d"></param>
 /// <param name="m_host"></param>
 /// <param name="itemID"></param>
 /// <returns>Whether the event should be dropped</returns>
 private bool TriggerAction(LimitDef d, ISceneChildEntity m_host, UUID itemID)
 {
     if (d.Action == LimitAction.None)
     {
         return(true);
     }
     else if (d.Action == LimitAction.Drop)
     {
         return(false); //Drop it
     }
     else if (d.Action == LimitAction.TerminateEvent)
     {
         throw new Exception(""); //Blank messages kill events, but don't show anything on the console/inworld
     }
     else if (d.Action == LimitAction.TerminateScript)
     {
         ScriptData script = GetScript(itemID);
         script.IgnoreNew = true; //Blocks all new events, can be reversed by resetting or resaving the script
         throw new Exception(""); //Blank messages kill events, but don't show anything on the console/inworld
     }
     else if (d.Action == LimitAction.Delay)
     {
         MainConsole.Instance.Warn("Function delaying is not implemented");
     }
     return(true);
 }
コード例 #5
0
        public void Deserialize(ScriptData instance, StateSave save)
        {
            instance.State               = save.State;
            instance.Running             = save.Running;
            instance.EventDelayTicks     = (long)save.MinEventDelay;
            instance.AssemblyName        = save.AssemblyName;
            instance.Disabled            = save.Disabled;
            instance.UserInventoryItemID = save.UserInventoryID;
            instance.PluginData          = save.Plugins;
            m_module.CreateFromData(instance.Part.UUID, instance.ItemID, instance.Part.UUID,
                                    instance.PluginData);
            instance.Source = save.Source;
            instance.InventoryItem.PermsGranter = save.PermsGranter;
            instance.InventoryItem.PermsMask    = save.PermsMask;
            instance.TargetOmegaWasSet          = save.TargetOmegaWasSet;

            try
            {
                Dictionary <string, object> vars = WebUtils.ParseXmlResponse(save.Variables);
                if (vars != null && vars.Count != 0 || instance.Script != null)
                {
                    instance.Script.SetStoreVars(vars);
                }
            }
            catch
            {
            }
        }
コード例 #6
0
        public void SaveStateTo (ScriptData script)
        {
            StateSave stateSave = new StateSave ();
            stateSave.State = script.State;
            stateSave.ItemID = script.ItemID;
            stateSave.Running = script.Running;
            stateSave.MinEventDelay = script.EventDelayTicks;
            stateSave.Disabled = script.Disabled;
            stateSave.UserInventoryID = script.UserInventoryItemID;
            //Allow for the full path to be put down, not just the assembly name itself
            stateSave.AssemblyName = script.AssemblyName;
            stateSave.Source = script.Source;
            if (script.InventoryItem != null)
            {
                stateSave.PermsGranter = script.InventoryItem.PermsGranter;
                stateSave.PermsMask = script.InventoryItem.PermsMask;
            }
            else
            {
                stateSave.PermsGranter = UUID.Zero;
                stateSave.PermsMask = 0;
            }
            stateSave.TargetOmegaWasSet = script.TargetOmegaWasSet;

            //Vars
            Dictionary<string, Object> vars = new Dictionary<string, object> ();
            if (script.Script != null)
                vars = script.Script.GetStoreVars ();
            stateSave.Variables = WebUtils.BuildXmlResponse (vars);

            //Plugins
            stateSave.Plugins = m_module.GetSerializationData (script.ItemID, script.Part.UUID);

            CreateOSDMapForState (script, stateSave);
        }
コード例 #7
0
        public static void Deserialize(ScriptData instance, ScriptEngine engine, StateSave save)
        {
            Dictionary<string, object> vars = save.Variables as Dictionary<string, object>;
            instance.State = save.State;
            instance.Running = save.Running;

            if (vars != null && vars.Count != 0)
                instance.Script.SetStoreVars(vars);

            if(save.Plugins is object[])
                instance.PluginData = (object[])save.Plugins;
            else
                instance.PluginData = new object[1] {(object)save.Plugins};

            if (save.Permissions != " " && save.Permissions != "")
            {
                instance.InventoryItem.PermsGranter = new UUID(save.Permissions.Split(',')[0]);
                instance.InventoryItem.PermsMask = int.Parse(save.Permissions.Split(',')[1], NumberStyles.Integer, Culture.NumberFormatInfo);
            }
            instance.EventDelayTicks = (long)save.MinEventDelay;
            instance.AssemblyName = save.AssemblyName;
            instance.Disabled = save.Disabled;
            instance.UserInventoryItemID = save.UserInventoryID;
            // Add it to our script memstruct
            ScriptEngine.ScriptProtection.AddNewScript(instance);
        }
コード例 #8
0
        public void DeleteFrom(ScriptData script)
        {
            OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;

            //Attempt to find the state saves we have
            if (component != null)
            {
                bool changed = false;
                //if we did remove something, resave it
                if (component.Remove(script.ItemID.ToString()))
                {
                    changed = true;
                }
                if (component.Remove(script.InventoryItem.OldItemID.ToString()))
                {
                    changed = true;
                }
                if (component.Remove(script.InventoryItem.ItemID.ToString()))
                {
                    changed = true;
                }
                if (changed)
                {
                    if (component.Count == 0)
                    {
                        m_manager.RemoveComponentState(script.Part.UUID, m_componentName);
                    }
                    else
                    {
                        m_manager.SetComponentState(script.Part, m_componentName, component);
                    }
                    script.Part.ParentEntity.HasGroupChanged = true;
                }
            }
        }
コード例 #9
0
 public void SetEventSchSetIgnoreNew(ScriptData ID, bool yes)
 {
     if (ID == null)
     {
         return;
     }
     ID.IgnoreNew = yes;
 }
コード例 #10
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, int VersionID, EventPriority priority, params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.EventsProcData.IgnoreNew)
            {
                return;
            }

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
            {
                return;
            }

            QIS                = new QueueItemStruct();
            QIS.ID             = ID;
            QIS.functionName   = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param          = param;
            QIS.VersionID      = VersionID;
            QIS.State          = ID.State;
            QIS.CurrentlyAt    = null;

            Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
            lock (ID.EventsProcData)
            {
                if (ID.EventsProcData.EventsQueue.Count > 100)
                {
                    Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
                    return;
                }

                ID.EventsProcData.EventsQueue.Enqueue(QIS);

                lock (ScriptIDs)
                {
                    if (!ID.InEventsProcData)
                    {
                        ID.EventsProcData.State  = (int)ScriptEventsState.Idle;
                        ID.EventsProcData.thread = null;
                        ScriptIDs.AddLast(ID);
                        ID.InEventsProcData = true;
                        Interlocked.Increment(ref nScriptIDs);
                        Interlocked.Increment(ref nEventScripts);
                    }
                }
                Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
            }

            lock (WorkersLock)
            {
                if (WorkersLock.nWorkers < MaxScriptThreads && WorkersLock.nWorkers < nScriptIDs)
                {
                    Scriptthreadpool.QueueEvent(loop, 2);
                }
            }
        }
コード例 #11
0
        public void SaveStateTo(ScriptData script, bool forced, bool saveBackup)
        {
            if (!forced)
            {
                if (script.Script == null)
                    return; //If it didn't compile correctly, this happens
                if (!script.Script.NeedsStateSaved)
                    return; //If it doesn't need a state save, don't save one
            }
            if (script.Script != null)
                script.Script.NeedsStateSaved = false;
            if (saveBackup)
                script.Part.ParentEntity.HasGroupChanged = true;
            StateSave stateSave = new StateSave
                                      {
                                          State = script.State,
                                          ItemID = script.ItemID,
                                          Running = script.Running,
                                          MinEventDelay = script.EventDelayTicks,
                                          Disabled = script.Disabled,
                                          UserInventoryID = script.UserInventoryItemID,
                                          AssemblyName = script.AssemblyName,
                                          Compiled = script.Compiled,
                                          Source = script.Source
                                      };
            //Allow for the full path to be put down, not just the assembly name itself
            if (script.InventoryItem != null)
            {
                stateSave.PermsGranter = script.InventoryItem.PermsGranter;
                stateSave.PermsMask = script.InventoryItem.PermsMask;
            }
            else
            {
                stateSave.PermsGranter = UUID.Zero;
                stateSave.PermsMask = 0;
            }
            stateSave.TargetOmegaWasSet = script.TargetOmegaWasSet;

            //Vars
            Dictionary<string, Object> vars = new Dictionary<string, object>();
            if (script.Script != null)
                vars = script.Script.GetStoreVars();
            try
            {
                stateSave.Variables = WebUtils.BuildXmlResponse(vars);
            }
            catch
            {
            }

            //Plugins
            stateSave.Plugins = m_module.GetSerializationData(script.ItemID, script.Part.UUID);

            CreateOSDMapForState(script, stateSave);
        }
コード例 #12
0
        public void AddPreviouslyCompiled(string source, ScriptData ID)
        {
            string key = Util.Md5Hash(source);

            lock (PreviouslyCompiled)
            {
                if (!PreviouslyCompiled.ContainsKey(key))
                {
                    PreviouslyCompiled.Add(key, ID.AssemblyName);
                }
            }
        }
コード例 #13
0
        public void RemoveFromEventSchQueue(ScriptData ID, bool abortcur)
        {
            if (ID == null)
            {
                return;
            }

            //Ignore any events to be added after this
            ID.IgnoreNew = true;
            //Clear out the old events
            Interlocked.Increment(ref ID.VersionID);
        }
コード例 #14
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, int VersionID, params object[] param)
        {
            QueueItemStruct QIS = new QueueItemStruct();

            QIS.ID             = ID;
            QIS.functionName   = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param          = param;
            QIS.VersionID      = VersionID;
            QIS.State          = ID.State;

            AddEventSchQIS(QIS);
        }
コード例 #15
0
 public void SetEventSchSetIgnoreNew(ScriptData ID, bool yes)
 {
     if (ID == null)
     {
         return;
     }
     Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
     lock (ID.EventsProcData)
     {
         ID.EventsProcData.IgnoreNew = yes;
         Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
     }
 }
コード例 #16
0
        public void AddPreviouslyCompiled(string source, ScriptData ID)
        {
            //string key = source.Length.ToString() + source.GetHashCode().ToString();
            string key = Util.Md5Hash(source);

            lock (PreviouslyCompiled)
            {
                if (!PreviouslyCompiled.ContainsKey(key))
                {
                    //PreviouslyCompiled.Add (source, ID.AssemblyName);
                    PreviouslyCompiled.Add(key, ID.AssemblyName);
                }
            }
        }
コード例 #17
0
        public void DeleteFrom(ScriptData script)
        {
            OSDMap component = (OSDMap)m_manager.GetComponentState(script.Part, m_componentName);

            //Attempt to find the state saves we have
            if (component != null)
            {
                //if we did remove something, resave it
                if (component.Remove(script.ItemID.ToString()))
                {
                    m_manager.SetComponentState(script.Part, m_componentName, component);
                }
            }
        }
コード例 #18
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);
        }
コード例 #19
0
        public ScriptData GetScript(UUID primID, UUID itemID)
        {
            Dictionary <UUID, ScriptData> Instances;

            lock (Scripts)
            {
                if (Scripts.TryGetValue(primID, out Instances))
                {
                    ScriptData ID = null;
                    Instances.TryGetValue(itemID, out ID);
                    return(ID);
                }
            }
            return(null);
        }
コード例 #20
0
        public void SaveStateTo(ScriptData script)
        {
            if (script.Script == null)
            {
                return; //If it didn't compile correctly, this happens
            }
            if (!script.Script.NeedsStateSaved)
            {
                return; //If it doesn't need a state save, don't save one
            }
            script.Script.NeedsStateSaved = false;
            StateSave stateSave = new StateSave();

            stateSave.State           = script.State;
            stateSave.ItemID          = script.ItemID;
            stateSave.Running         = script.Running;
            stateSave.MinEventDelay   = script.EventDelayTicks;
            stateSave.Disabled        = script.Disabled;
            stateSave.UserInventoryID = script.UserInventoryItemID;
            //Allow for the full path to be put down, not just the assembly name itself
            stateSave.AssemblyName = script.AssemblyName;
            stateSave.Source       = script.Source;
            if (script.InventoryItem != null)
            {
                stateSave.PermsGranter = script.InventoryItem.PermsGranter;
                stateSave.PermsMask    = script.InventoryItem.PermsMask;
            }
            else
            {
                stateSave.PermsGranter = UUID.Zero;
                stateSave.PermsMask    = 0;
            }
            stateSave.TargetOmegaWasSet = script.TargetOmegaWasSet;

            //Vars
            Dictionary <string, Object> vars = new Dictionary <string, object> ();

            if (script.Script != null)
            {
                vars = script.Script.GetStoreVars();
            }
            stateSave.Variables = WebUtils.BuildXmlResponse(vars);

            //Plugins
            stateSave.Plugins = m_module.GetSerializationData(script.ItemID, script.Part.UUID);

            CreateOSDMapForState(script, stateSave);
        }
コード例 #21
0
 public void DeleteFrom(ScriptData script)
 {
     bool changed = false;
     lock (StateSaveLock)
     {
         //if we did remove something, resave it
         if (script.Part.StateSaves.Remove(script.ItemID))
             changed = true;
         if (script.Part.StateSaves.Remove(script.InventoryItem.OldItemID))
             changed = true;
         if (script.Part.StateSaves.Remove(script.InventoryItem.ItemID))
             changed = true;
     }
     if (changed)
         script.Part.ParentEntity.HasGroupChanged = true;
 }
コード例 #22
0
        private void CreateOSDMapForState(ScriptData script, StateSave save)
        {
            //Get any previous state saves from the component manager
            OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;

            if (component == null)
            {
                component = new OSDMap();
            }

            //Add our state to the list of all scripts in this object
            component[script.ItemID.ToString()] = save.ToOSD();

            //Now resave it
            m_manager.SetComponentState(script.Part, m_componentName, component);
        }
コード例 #23
0
 public void RemoveScript(ScriptData Data)
 {
     lock (ScriptsItems)
     {
         ScriptsItems.Remove(Data.ItemID);
     }
     lock (Scripts)
     {
         Dictionary <UUID, ScriptData> Instances = new Dictionary <UUID, ScriptData>();
         if (Scripts.ContainsKey(Data.Part.UUID))
         {
             Instances = Scripts[Data.Part.UUID];
             Instances.Remove(Data.ItemID);
         }
         Scripts[Data.Part.UUID] = Instances;
     }
 }
コード例 #24
0
 public StateSave FindScriptStateSave(ScriptData script)
 {
     lock (StateSaveLock)
     {
         StateSave save;
         if (!script.Part.StateSaves.TryGetValue(script.ItemID, out save))
         {
             if (!script.Part.StateSaves.TryGetValue(script.InventoryItem.OldItemID, out save))
             {
                 if (!script.Part.StateSaves.TryGetValue(script.InventoryItem.ItemID, out save))
                 {
                     return(null);
                 }
             }
         }
         return(save);
     }
 }
コード例 #25
0
        private void InsertInSleepers(ScriptData ID)
        {
            // insert sorted by time to wakeup
            LinkedListNode <ScriptData> where = null;

            Interlocked.Exchange(ref SleepingScriptIDsLock, 1);
            lock (SleepingScriptIDs)
            {
                if (SleepingScriptIDs.Count > 0)
                {
                    DateTime when = ID.EventsProcData.TimeCheck;
                    if (SleepingScriptIDs.First.Value.EventsProcData.TimeCheck.Ticks > when.Ticks)
                    {
                        SleepingScriptIDs.AddFirst(ID);
                    }
                    else if (SleepingScriptIDs.Last.Value.EventsProcData.TimeCheck.Ticks <= when.Ticks)
                    {
                        SleepingScriptIDs.AddLast(ID);
                    }
                    else
                    {
                        where = SleepingScriptIDs.Last.Previous;
                        while (where != null && where.Value.EventsProcData.TimeCheck.Ticks > when.Ticks)
                        {
                            where = where.Previous;
                        }
                        if (where != null)
                        {
                            SleepingScriptIDs.AddAfter(where, ID);
                        }
                        else
                        {
                            SleepingScriptIDs.AddFirst(ID);
                        }
                    }
                }
                else
                {
                    SleepingScriptIDs.AddLast(ID);
                }
                Interlocked.Exchange(ref SleepingScriptIDsLock, 0);
            }
        }
コード例 #26
0
 /// <summary>
 ///     Makes sure that all the threads that need to be running are running and starts them if they need to be running
 /// </summary>
 public void PokeThreads(UUID itemID)
 {
     if (itemID != UUID.Zero)
     {
         ScriptData script = ScriptEngine.ScriptProtection.GetScript(itemID);
         if (script != null && script.Script != null)
         {
             script.Script.NeedsStateSaved = true;
         }
     }
     if (LUQueue.Count() > 0 && !ScriptChangeIsRunning)
     {
         StartThread("Change");
     }
     if (Interlocked.Read(ref CmdHandlerQueueIsRunning) == 0)
     {
         StartThread("CmdHandlerQueue");
     }
 }
コード例 #27
0
        public void RemoveFromEventSchQueue(ScriptData ID, bool abortcur)
        {
            if (ID == null)
            {
                return;
            }

            Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
            lock (ID.EventsProcData)
            {
                ID.EventsProcData.IgnoreNew = true;
                ID.EventsProcData.EventsQueue.Clear();
                if (ID.InEventsProcData)
                {
                    if (ID.EventsProcData.State == (int)ScriptEventsState.InExec)
                    {
                        if (abortcur)
                        {
                            ID.EventsProcData.State = (int)ScriptEventsState.InExecAbort;
                        }
                    }
                    else
                    {
                        if (ID.EventsProcData.State == (int)ScriptEventsState.Sleep)
                        {
                            lock (SleepingScriptIDs)
                                SleepingScriptIDs.Remove(ID);
                        }
                        else
                        {
                            lock (ScriptIDs)
                                ScriptIDs.Remove(ID);
                            Interlocked.Decrement(ref nScriptIDs);
                        }
                        Interlocked.Decrement(ref nEventScripts);
                        ID.InEventsProcData = false;
                    }
                }
                Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
            }
        }
コード例 #28
0
        public void AddNewScript(ScriptData ID)
        {
            lock (ScriptsItems)
            {
                if (ID.Part != null)
                {
                    ScriptsItems[ID.ItemID] = ID.Part.UUID;
                }
            }
            lock (Scripts)
            {
                Dictionary <UUID, ScriptData> Instances = new Dictionary <UUID, ScriptData>();
                if (!Scripts.TryGetValue(ID.Part.UUID, out Instances))
                {
                    Instances = new Dictionary <UUID, ScriptData>();
                }

                Instances[ID.ItemID]  = ID;
                Scripts[ID.Part.UUID] = Instances;
            }
        }
コード例 #29
0
        public void FlushEventSchQueue(ScriptData ID, bool ignorenew)
        {
            if (ID == null)
            {
                return;
            }
            Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
            lock (ID.EventsProcData)
            {
                ID.EventsProcData.EventsQueue.Clear();
                ID.EventsProcData.IgnoreNew = ignorenew;
                if (ID.EventsProcData.State == (int)ScriptEventsState.Sleep)
                {
                    lock (SleepingScriptIDs)
                        SleepingScriptIDs.Remove(ID);
                    ID.EventsProcData.State = (int)ScriptEventsState.Idle;
                }

                Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
            }
        }
コード例 #30
0
        public void control(ISceneChildEntity part, UUID itemID, UUID agentID, uint held, uint change)
        {
            ScriptData ID = ScriptEngine.ScriptProtection.GetScript(part.UUID, itemID);

            if (ID == null)
            {
                return;
            }

            string functionName = "control";

            object[] param = new object[] {
                new LSL_Types.LSLString(agentID.ToString()),
                new LSL_Types.LSLInteger(held),
                new LSL_Types.LSLInteger(change)
            };

            if (CheckIfEventShouldFire(ID, functionName, param))
            {
                m_scriptEngine.AddToScriptQueue(ID, functionName, new DetectParams[0], ID.VersionID, param);
            }
        }
コード例 #31
0
 public void RemoveScript(ScriptData Data)
 {
     lock (ScriptsItems)
     {
         ScriptsItems.Remove(Data.ItemID);
     }
     lock (Scripts)
     {
         Dictionary <UUID, ScriptData> Instances = new Dictionary <UUID, ScriptData>();
         if (Scripts.TryGetValue(Data.Part.UUID, out Instances))
         {
             Instances.Remove(Data.ItemID);
             if (Instances.Count > 0)
             {
                 Scripts[Data.Part.UUID] = Instances;
             }
             else
             {
                 Scripts.Remove(Data.Part.UUID);
             }
         }
     }
 }
コード例 #32
0
        public void Deserialize(ScriptData instance, StateSave save)
        {
            instance.State               = save.State;
            instance.Running             = save.Running;
            instance.EventDelayTicks     = (long)save.MinEventDelay;
            instance.AssemblyName        = save.AssemblyName;
            instance.Disabled            = save.Disabled;
            instance.UserInventoryItemID = save.UserInventoryID;
            if (save.Plugins != "")
            {
                instance.PluginData = (OSDMap)OSDParser.DeserializeJson(save.Plugins);
            }
            m_module.CreateFromData(instance.Part.UUID, instance.ItemID, instance.Part.UUID,
                                    instance.PluginData);
            instance.Source = save.Source;
            instance.InventoryItem.PermsGranter = save.PermsGranter;
            instance.InventoryItem.PermsMask    = save.PermsMask;
            instance.TargetOmegaWasSet          = save.TargetOmegaWasSet;

            if (save.Variables != null && instance.Script != null)
            {
                instance.Script.SetStoreVars(XMLUtils.ParseXmlResponse(save.Variables));
            }
        }
コード例 #33
0
 public void DeleteFrom(ScriptData script)
 {
     OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;
     //Attempt to find the state saves we have
     if (component != null)
     {
         bool changed = false;
         //if we did remove something, resave it
         if (component.Remove(script.ItemID.ToString()))
             changed = true;
         if (component.Remove(script.InventoryItem.OldItemID.ToString()))
             changed = true;
         if (component.Remove(script.InventoryItem.ItemID.ToString()))
             changed = true;
         if (changed)
         {
             if (component.Count == 0)
                 m_manager.RemoveComponentState(script.Part.UUID, m_componentName);
             else
                 m_manager.SetComponentState(script.Part, m_componentName, component);
             script.Part.ParentEntity.HasGroupChanged = true;
         }
     }
 }
コード例 #34
0
 public void SaveStateTo(ScriptData script)
 {
     SaveStateTo(script, false);
 }
コード例 #35
0
 public void RemoveState(ScriptData ID)
 {
     m_ScriptEngine.StateSave.DeleteFrom(ID);
 }
コード例 #36
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority,
                                     params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.Script == null || ID.IgnoreNew)
                return;

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
                return;

            QIS = new QueueItemStruct
                      {
                          EventsProcData = new ScriptEventsProcData(),
                          ID = ID,
                          functionName = FunctionName,
                          llDetectParams = qParams,
                          param = param,
                          VersionID = Interlocked.Read(ref ID.VersionID),
                          State = ID.State,
                          CurrentlyAt = null
                      };

            ScriptEvents.Enqueue(QIS);

            long threadCount = Interlocked.Read(ref scriptThreadpool.nthreads);
            if (threadCount == 0 || threadCount < (ScriptEvents.Count + (SleepingScriptEventCount/2))*EventPerformance)
            {
                scriptThreadpool.QueueEvent(eventLoop, 2);
            }
        }
コード例 #37
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;
        }
コード例 #38
0
        public void Deserialize(ScriptData instance, StateSave save)
        {
            instance.State = save.State;
            instance.Running = save.Running;
            instance.EventDelayTicks = (long)save.MinEventDelay;
            instance.AssemblyName = save.AssemblyName;
            instance.Disabled = save.Disabled;
            instance.UserInventoryItemID = save.UserInventoryID;
            instance.PluginData = save.Plugins;
            m_module.CreateFromData(instance.Part.UUID, instance.ItemID, instance.Part.UUID,
                                    instance.PluginData);
            instance.Source = save.Source;
            instance.InventoryItem.PermsGranter = save.PermsGranter;
            instance.InventoryItem.PermsMask = save.PermsMask;
            instance.TargetOmegaWasSet = save.TargetOmegaWasSet;

            try
            {
                Dictionary<string, object> vars = WebUtils.ParseXmlResponse(save.Variables);
                if (vars != null && vars.Count != 0 || instance.Script != null)
                    instance.Script.SetStoreVars(vars);
            }
            catch
            {
            }
        }
コード例 #39
0
        /// <summary>
        /// This checks the minimum amount of time between script firings as well as control events, making sure that events do NOT fire after scripts reset, close or restart, etc
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="FunctionName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        private bool CheckIfEventShouldFire(ScriptData ID, string FunctionName, object[] param)
        {
            if (ID.Loading)
            {
                //If the script is loading, enqueue all events
                return(true);
            }
            //This will happen if the script doesn't compile correctly
            if (ID.Script == null)
            {
                m_log.Info("[AuroraDotNetEngine]: Could not load script from item '" + ID.InventoryItem.Name + "' to fire event " + FunctionName);
                return(false);
            }
            scriptEvents eventType = (scriptEvents)Enum.Parse(typeof(scriptEvents), FunctionName);

            // this must be done even if there is no event method

            if (eventType == scriptEvents.touch_start)
            {
                ID.RemoveTouchEvents = false;
            }
            else if (eventType == scriptEvents.collision_start)
            {
                ID.RemoveCollisionEvents = false;
            }
            else if (eventType == scriptEvents.land_collision_start)
            {
                ID.RemoveLandCollisionEvents = false;
            }


            if ((ID.Script.GetStateEventFlags(ID.State) & (long)eventType) == 0)
            {
                return(false); //If the script doesn't contain the state, don't even bother queueing it
            }
            //Make sure we can execute events at position
            if (!m_scriptEngine.PipeEventsForScript(ID.Part))
            {
                return(false);
            }

            if (eventType == scriptEvents.timer)
            {
                if (ID.TimerQueued)
                {
                    return(false);
                }
                ID.TimerQueued = true;
            }
            else if (eventType == scriptEvents.control)
            {
                int held = ((LSL_Types.LSLInteger)param[1]).value;
                // int changed = ((LSL_Types.LSLInteger)data.Params[2]).value;

                // If the last message was a 0 (nothing held)
                // and this one is also nothing held, drop it
                //
                if (ID.LastControlLevel == held && held == 0)
                {
                    return(true);
                }

                // If there is one or more queued, then queue
                // only changed ones, else queue unconditionally
                //
                if (ID.ControlEventsInQueue > 0)
                {
                    if (ID.LastControlLevel == held)
                    {
                        return(false);
                    }
                }
            }
            else if (eventType == scriptEvents.collision)
            {
                if (ID.CollisionInQueue || ID.RemoveCollisionEvents)
                {
                    return(false);
                }

                ID.CollisionInQueue = true;
            }
            else if (eventType == scriptEvents.moving_start)
            {
                if (ID.MovingInQueue) //Block all other moving_starts until moving_end is called
                {
                    return(false);
                }
                ID.MovingInQueue = true;
            }
            else if (eventType == scriptEvents.moving_end)
            {
                if (!ID.MovingInQueue) //If we get a moving_end after we have sent one event, don't fire another
                {
                    return(false);
                }
            }
            else if (eventType == scriptEvents.collision_end)
            {
                if (ID.RemoveCollisionEvents)
                {
                    return(false);
                }
            }
            else if (eventType == scriptEvents.touch)
            {
                if (ID.TouchInQueue || ID.RemoveTouchEvents)
                {
                    return(false);
                }

                ID.TouchInQueue = true;
            }
            else if (eventType == scriptEvents.touch_end)
            {
                if (ID.RemoveTouchEvents)
                {
                    return(false);
                }
            }
            else if (eventType == scriptEvents.land_collision)
            {
                if (ID.LandCollisionInQueue || ID.RemoveLandCollisionEvents)
                {
                    return(false);
                }

                ID.LandCollisionInQueue = true;
            }
            else if (eventType == scriptEvents.land_collision_end)
            {
                if (ID.RemoveLandCollisionEvents)
                {
                    return(false);
                }
            }
            else if (eventType == scriptEvents.changed)
            {
                Changed changed;
                if (param[0] is Changed)
                {
                    changed = (Changed)param[0];
                }
                else
                {
                    changed = (Changed)(((LSL_Types.LSLInteger)param[0]).value);
                }
                if (ID.ChangedInQueue.Contains(changed))
                {
                    return(false);
                }
                ID.ChangedInQueue.Add(changed);
            }

            if (FunctionName == "state_entry")
            {
                ID.ResetEvents();
            }
            return(true);
        }
コード例 #40
0
 public void DeleteFrom (ScriptData script)
 {
     OSDMap component = m_manager.GetComponentState (script.Part, m_componentName) as OSDMap;
     //Attempt to find the state saves we have
     if (component != null)
     {
         //if we did remove something, resave it
         if(component.Remove(script.ItemID.ToString()))
         {
             if (component.Count == 0)
                 m_manager.RemoveComponentState(script.Part.UUID, m_componentName);
             else
                 m_manager.SetComponentState (script.Part, m_componentName, component);
         }
     }
 }
コード例 #41
0
 public void RemoveScript(ScriptData Data)
 {
     lock (ScriptsItems)
     {
         ScriptsItems.Remove(Data.ItemID);
     }
     lock (Scripts)
     {
         Dictionary<UUID, ScriptData> Instances = new Dictionary<UUID, ScriptData>();
         if (Scripts.TryGetValue(Data.Part.UUID, out Instances))
         {
             Instances.Remove(Data.ItemID);
             if (Instances.Count > 0)
                 Scripts[Data.Part.UUID] = Instances;
             else
                 Scripts.Remove(Data.Part.UUID);
         }
     }
 }
コード例 #42
0
 public void AddPreviouslyCompiled(string source, ScriptData ID)
 {
     //string key = source.Length.ToString() + source.GetHashCode().ToString();
     string key = Util.Md5Hash(source);
     lock (PreviouslyCompiled)
     {
         if (!PreviouslyCompiled.ContainsKey(key))
         {
             //PreviouslyCompiled.Add (source, ID.AssemblyName);
             PreviouslyCompiled.Add(key, ID.AssemblyName);
         }
     }
 }
コード例 #43
0
 public void AddPreviouslyCompiled(string source, ScriptData ID)
 {
     lock (PreviouslyCompiled)
     {
         if (!PreviouslyCompiled.ContainsKey(source))
         {
             PreviouslyCompiled.Add(source, ID.AssemblyName);
         }
     }
 }
コード例 #44
0
        public void EventSchExec(ScriptData ID)
        {
            QueueItemStruct QIS;

            Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
            lock (ID.EventsProcData)
            {
                QIS = ID.EventsProcData.CurExecQIS;
                if (!ID.Running)
                {
                    //do only state_entry and on_rez
                    if (QIS.functionName != "state_entry" ||
                        QIS.functionName != "on_rez")
                    {
                        Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
                        return;
                    }
                }
                ID.EventsProcData.thread = Thread.CurrentThread;
                Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
            }


            lock (ScriptInExec)
            {
                ScriptInExec.Add(ID);
            }

            bool res = EventSchProcessQIS(ref QIS);

            lock (ScriptInExec)
            {
                ScriptInExec.Remove(ID);
            }

            Interlocked.Exchange(ref ID.EventsProcDataLocked, 1);
            lock (ID.EventsProcData)
            {
                ID.EventsProcData.thread = null;

                if (ID.EventsProcData.State == (int)ScriptEventsState.InExecAbort)
                {
                    ID.EventsProcData.State = (int)ScriptEventsState.Delete;
                }

//                else if (!res || ID.VersionID != QIS.VersionID)
                else if (!res)
                {
                    ID.EventsProcData.State = (int)ScriptEventsState.Idle;
                }

                else
                {
                    ID.EventsProcData.CurExecQIS = QIS;

                    if (QIS.CurrentlyAt.SleepTo.Ticks != 0)
                    {
                        ID.EventsProcData.TimeCheck = QIS.CurrentlyAt.SleepTo;
                        ID.EventsProcData.State     = (int)ScriptEventsState.Sleep;
                    }
                    else
                    {
                        ID.EventsProcData.State = (int)ScriptEventsState.Running;
                    }
                }
                Interlocked.Exchange(ref ID.EventsProcDataLocked, 0);
            }
            return;
        }
コード例 #45
0
 public void AddNewScript(ScriptData ID)
 {
     lock (Scripts)
     {
         ScriptsItems[ID.ItemID] = ID.part.UUID;
         Dictionary<UUID, ScriptData> Instances = new Dictionary<UUID, ScriptData>();
         if (!Scripts.TryGetValue(ID.part.UUID, out Instances))
         {
             Instances = new Dictionary<UUID, ScriptData>();
         }
         Instances[ID.ItemID] = ID;
         Scripts[ID.part.UUID] = Instances;
     }
 }
コード例 #46
0
        public void RemoveFromEventSchQueue(ScriptData ID, bool abortcur)
        {
            if (ID == null)
                return;

            //Ignore any events to be added after this
            ID.IgnoreNew = true;
            //Clear out the old events
            Interlocked.Increment(ref ID.VersionID);
        }
コード例 #47
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, int VersionID, params object[] param)
        {
            QueueItemStruct QIS = new QueueItemStruct();
            QIS.ID = ID;
            QIS.functionName = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param = param;
            QIS.VersionID = VersionID;
            QIS.State = ID.State;

            AddEventSchQIS(QIS);
        }
コード例 #48
0
        public static void SetXMLState(string xml, ScriptData instance, ScriptEngine engine)
        {
            XmlDocument doc = new XmlDocument();

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

            doc.LoadXml(xml);

            XmlNodeList rootL = doc.GetElementsByTagName("ScriptState");
            if (rootL.Count != 1)
            {
                return;
            }
            XmlNode rootNode = rootL[0];

            if (rootNode != null)
            {
                object varValue;
                XmlNodeList partL = rootNode.ChildNodes;

                foreach (XmlNode part in partL)
                {
                    switch (part.Name)
                    {
                        case "State":
                            instance.State = part.InnerText;
                            break;
                        case "Running":
                            instance.Running = bool.Parse(part.InnerText);
                            break;
                        case "Variables":
                            XmlNodeList varL = part.ChildNodes;
                            foreach (XmlNode var in varL)
                            {
                                string varName;
                                varValue = ReadTypedValue(var, out varName);

                                if (vars.ContainsKey(varName))
                                    vars[varName] = varValue;
                            }
                            instance.Script.SetVars(vars);
                            break;
                        case "Plugins":
                            instance.PluginData = ReadList(part).Data;
                            break;
                        case "Permissions":
                            string tmpPerm;
                            int mask = 0;
                            tmpPerm = part.Attributes.GetNamedItem("mask").Value;
                            if (tmpPerm != null)
                            {
                                int.TryParse(tmpPerm, out mask);
                                if (mask != 0)
                                {
                                    tmpPerm = part.Attributes.GetNamedItem("granter").Value;
                                    if (tmpPerm != null)
                                    {
                                        UUID granter = new UUID();
                                        UUID.TryParse(tmpPerm, out granter);
                                        if (granter != UUID.Zero)
                                        {
                                            instance.InventoryItem.PermsMask = mask;
                                            instance.InventoryItem.PermsGranter = granter;
                                        }
                                    }
                                }
                            }
                            break;
                        case "MinEventDelay":
                            double minEventDelay = 0.0;
                            double.TryParse(part.InnerText, NumberStyles.Float, Culture.NumberFormatInfo, out minEventDelay);
                            instance.EventDelayTicks = (long)minEventDelay;
                            break;
                    }
                }
            }
        }
コード例 #49
0
 public StateSave FindScriptStateSave(ScriptData script)
 {
     OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;
     //Attempt to find the state saves we have
     if (component != null)
     {
         OSD o;
         //If we have one for this item, deserialize it
         if (!component.TryGetValue(script.ItemID.ToString(), out o))
         {
             if (!component.TryGetValue(script.InventoryItem.OldItemID.ToString(), out o))
             {
                 if (!component.TryGetValue(script.InventoryItem.ItemID.ToString(), out o))
                 {
                     return null;
                 }
             }
         }
         StateSave save = new StateSave();
         save.FromOSD((OSDMap)o);
         return save;
     }
     return null;
 }
コード例 #50
0
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority, params object[] param)
        {
            QueueItemStruct QIS;

            if (ID == null || ID.Script == null || ID.IgnoreNew)
                return;

            if (!ID.SetEventParams(FunctionName, qParams)) // check events delay rules
                return;

            QIS = new QueueItemStruct();
            QIS.EventsProcData = new ScriptEventsProcData ();
            QIS.ID = ID;
            QIS.functionName = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param = param;
            QIS.VersionID = Interlocked.Read(ref ID.VersionID);
            QIS.State = ID.State;
            QIS.CurrentlyAt = null;

            lock (ScriptEvents)
            {
                ScriptEvents.Enqueue (QIS);
                ScriptEventCount++;
#if Debug
                m_log.Warn (ScriptEventCount + ", " + QIS.functionName);
#endif
            }

            long threadCount = Interlocked.Read (ref scriptThreadpool.nthreads);
            if (threadCount == 0 || threadCount < (ScriptEventCount + (SleepingScriptEventCount / 2)) * EventPerformance)
            {
                scriptThreadpool.QueueEvent (eventLoop, 2);
            }
        }
コード例 #51
0
        private void CreateOSDMapForState(ScriptData script, StateSave save)
        {
            //Get any previous state saves from the component manager
            OSDMap component = m_manager.GetComponentState(script.Part, m_componentName) as OSDMap;
            if (component == null)
                component = new OSDMap();

            //Add our state to the list of all scripts in this object
            component[script.ItemID.ToString()] = save.ToOSD();

            //Now resave it
            m_manager.SetComponentState(script.Part, m_componentName, component);
        }
コード例 #52
0
 public void RemoveScript(ScriptData Data)
 {
     lock (ScriptsItems)
     {
         ScriptsItems.Remove(Data.ItemID);
     }
     lock (Scripts)
     {
         Dictionary<UUID, ScriptData> Instances = new Dictionary<UUID, ScriptData>();
         if (Scripts.ContainsKey(Data.Part.UUID))
         {
             Instances = Scripts[Data.Part.UUID];
             Instances.Remove(Data.ItemID);
         }
         Scripts[Data.Part.UUID] = Instances;
     }
 }
コード例 #53
0
 public void SaveStateTo(ScriptData script, bool forced)
 {
     SaveStateTo(script, forced, true);
 }
コード例 #54
0
ファイル: ScriptEngine.cs プロジェクト: NickyPerian/Aurora
        /// <summary>
        /// Posts the event to the given object.
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="FunctionName"></param>
        /// <param name="qParams"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool AddToScriptQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, int VersionID, EventPriority priority, params object[] param)
        {
            // Create a structure and add data
            QueueItemStruct QIS = new QueueItemStruct();
            QIS.ID = ID;
            QIS.functionName = FunctionName;
            QIS.llDetectParams = qParams;
            QIS.param = param;
            QIS.VersionID = VersionID;
            QIS.State = ID.State;

            MaintenanceThread.AddEvent(QIS, priority);
            return true;
        }
コード例 #55
0
 public void RemoveState(ScriptData ID)
 {
     m_ScriptEngine.StateSave.DeleteFrom(ID);
 }
コード例 #56
0
ファイル: ScriptEngine.cs プロジェクト: NickyPerian/Aurora
 /// <summary>
 /// Fetches, loads and hooks up a script to an objects events
 /// </summary>
 /// <param name="itemID"></param>
 /// <param name="localID"></param>
 public LUStruct StartScript(SceneObjectPart part, UUID itemID, string Script, int startParam, bool postOnRez, StateSource statesource, UUID RezzedFrom)
 {
     ScriptData id = ScriptProtection.GetScript(part.UUID, itemID);
     
     LUStruct ls = new LUStruct();
     //Its a change of the script source, needs to be recompiled and such.
     if (id != null)
     {
         //Ignore prims that have crossed regions, they are already started and working
         if ((statesource & StateSource.PrimCrossing) != 0)
         {
             //Post the changed event though
             AddToScriptQueue(id, "changed", new DetectParams[0], id.VersionID, EventPriority.FirstStart, new Object[] { new LSL_Types.LSLInteger(512) });
             return new LUStruct() { Action = LUType.Unknown };
         }
         else
         {
             //Restart other scripts
             ls.Action = LUType.Load;
         }
         id.EventDelayTicks = 0;
         ScriptEngine.ScriptProtection.RemovePreviouslyCompiled(id.Source);
     }
     else
         ls.Action = LUType.Load;
     if (id == null)
         id = new ScriptData(this);
     id.ItemID = itemID;
     id.PostOnRez = postOnRez;
     id.StartParam = startParam;
     id.stateSource = statesource;
     id.State = "default";
     id.Source = Script;
     id.part = part;
     id.World = part.ParentGroup.Scene;
     id.RezzedFrom = RezzedFrom;
     ls.ID = id;
     return ls;
 }
コード例 #57
0
 public void SetEventSchSetIgnoreNew(ScriptData ID, bool yes)
 {
     if (ID == null)
         return;
     ID.IgnoreNew = yes;
 }
コード例 #58
0
ファイル: ScriptEngine.cs プロジェクト: NickyPerian/Aurora
        public void UpdateScript(UUID partID, UUID itemID, string script, int startParam, bool postOnRez, int stateSource)
        {
            ScriptData id = ScriptProtection.GetScript(partID, itemID);
            LUStruct ls = new LUStruct();
            //Its a change of the script source, needs to be recompiled and such.
            if (id == null)
                id = new ScriptData(this);
            ls.Action = LUType.Reupload;
            id.PostOnRez = postOnRez;
            id.StartParam = startParam;
            id.stateSource = (StateSource)stateSource;
            id.State = "default";
            id.Source = script;
            id.EventDelayTicks = 0;
            id.part = findPrim(partID);
            id.ItemID = itemID;
            id.EventDelayTicks = 0;

            //No SOP, no compile.
            if (id.part == null)
            {
                m_log.ErrorFormat("[{0}]: Could not find scene object part corresponding " + "to localID {1} to start script", ScriptEngineName, partID);
                return;
            }
            id.World = id.part.ParentGroup.Scene;
            ls.ID = id;
            MaintenanceThread.AddScriptChange(new LUStruct[] { ls }, LoadPriority.Restart);
        }
コード例 #59
0
        /// <summary>
        /// This checks the minimum amount of time between script firings as well as control events, making sure that events do NOT fire after scripts reset, close or restart, etc
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="FunctionName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        private bool CheckIfEventShouldFire(ScriptData ID, string FunctionName, object[] param)
        {
            lock (ID.ScriptEventLock)
            {
                if (ID.Loading)
                {
                    //If the script is loading, enqueue all events
                    return true;
                }
                //This will happen if the script doesn't compile correctly
                if (ID.Script == null)
                {
                    m_log.Info ("[AuroraDotNetEngine]: Could not load script from item '" + ID.InventoryItem.Name + "' to fire event " + FunctionName);
                    return false;
                }
                scriptEvents eventType = (scriptEvents)Enum.Parse (typeof (scriptEvents), FunctionName);

                // this must be done even if there is no event method

                if (eventType == scriptEvents.touch_start)
                    ID.RemoveTouchEvents = false;
                else if (eventType == scriptEvents.collision_start)
                    ID.RemoveCollisionEvents = false;
                else if (eventType == scriptEvents.land_collision_start)
                    ID.RemoveLandCollisionEvents = false;


                if ((ID.Script.GetStateEventFlags (ID.State) & (long)eventType) == 0)
                    return false; //If the script doesn't contain the state, don't even bother queueing it

                //Make sure we can execute events at position
                if (!m_scriptEngine.PipeEventsForScript (ID.Part))
                    return false;

                if (eventType == scriptEvents.timer)
                {
                    if (ID.TimerQueued)
                        return false;
                    ID.TimerQueued = true;
                }
                else if (eventType == scriptEvents.control)
                {
                    int held = ((LSL_Types.LSLInteger)param[1]).value;
                    // int changed = ((LSL_Types.LSLInteger)data.Params[2]).value;

                    // If the last message was a 0 (nothing held)
                    // and this one is also nothing held, drop it
                    //
                    if (ID.LastControlLevel == held && held == 0)
                        return true;

                    // If there is one or more queued, then queue
                    // only changed ones, else queue unconditionally
                    //
                    if (ID.ControlEventsInQueue > 0)
                    {
                        if (ID.LastControlLevel == held)
                            return false;
                    }
                }
                else if (eventType == scriptEvents.collision)
                {
                    if (ID.CollisionInQueue || ID.RemoveCollisionEvents)
                        return false;

                    ID.CollisionInQueue = true;
                }
                else if (eventType == scriptEvents.moving_start)
                {
                    if (ID.MovingInQueue) //Block all other moving_starts until moving_end is called
                        return false;
                    ID.MovingInQueue = true;
                }
                else if (eventType == scriptEvents.moving_end)
                {
                    if (!ID.MovingInQueue) //If we get a moving_end after we have sent one event, don't fire another
                        return false;
                }
                else if (eventType == scriptEvents.collision_end)
                {
                    if (ID.RemoveCollisionEvents)
                        return false;
                }
                else if (eventType == scriptEvents.touch)
                {
                    if (ID.TouchInQueue || ID.RemoveTouchEvents)
                        return false;

                    ID.TouchInQueue = true;
                }
                else if (eventType == scriptEvents.touch_end)
                {
                    if (ID.RemoveTouchEvents)
                        return false;
                }
                else if (eventType == scriptEvents.land_collision)
                {
                    if (ID.LandCollisionInQueue || ID.RemoveLandCollisionEvents)
                        return false;

                    ID.LandCollisionInQueue = true;
                }
                else if (eventType == scriptEvents.land_collision_end)
                {
                    if (ID.RemoveLandCollisionEvents)
                        return false;
                }
                else if (eventType == scriptEvents.changed)
                {
                    Changed changed;
                    if (param[0] is Changed)
                    {
                        changed = (Changed)param[0];
                    }
                    else
                    {
                        changed = (Changed)(((LSL_Types.LSLInteger)param[0]).value);
                    }
                    if (ID.ChangedInQueue.Contains (changed))
                        return false;
                    ID.ChangedInQueue.Add (changed);
                }

                if (FunctionName == "state_entry")
                    ID.ResetEvents ();
            }
            return true;
        }
コード例 #60
0
        public void AddNewScript(ScriptData ID)
        {
            lock (ScriptsItems)
            {
                if (ID.Part != null)
                    ScriptsItems[ID.ItemID] = ID.Part.UUID;
            }
            lock (Scripts)
            {
                Dictionary<UUID, ScriptData> Instances = new Dictionary<UUID, ScriptData>();
                if (!Scripts.TryGetValue(ID.Part.UUID, out Instances))
                    Instances = new Dictionary<UUID, ScriptData>();

                Instances[ID.ItemID] = ID;
                Scripts[ID.Part.UUID] = Instances;
            }
        }