Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        public void CmdHandlerQueue()
        {
            if (m_ScriptEngine.Scene == null)
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }
            Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 1);
            IMonitorModule module    = m_ScriptEngine.Scene.RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled || !m_ScriptEngine.Scene.ShouldRunHeartbeat)
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }

            //Check timers, etc
            bool didAnything = false;

            try
            {
                didAnything = m_ScriptEngine.DoOneScriptPluginPass();
            }
            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName,
                                                ex);
            }

            if (module != null)
            {
                IScriptFrameTimeMonitor scriptMonitor = module.GetMonitor <IScriptFrameTimeMonitor>(m_ScriptEngine.Scene);
                if (scriptMonitor != null)
                {
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
            }

            if (didAnything) //If we did something, run us again soon
            {
                cmdThreadpool.QueueEvent(CmdHandlerQueue, 2);
            }
            else
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
            }
        }
Ejemplo n.º 4
0
 protected virtual void ClickedOnTile(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
 {
     m_blockitemsToRequest.Add(new MapBlockRequester()
     {
         maxX         = maxX,
         maxY         = maxY,
         minX         = minX,
         minY         = minY,
         remoteClient = remoteClient
     });
     if (!blockRequesterIsRunning)
     {
         blockthreadpool.QueueEvent(GetMapBlocks, 3);
     }
 }
Ejemplo n.º 5
0
        public bool CmdHandlerQueue()
        {
            if (m_ScriptEngine.Worlds.Count == 0)
            {
                return(false);
            }
            IMonitorModule module    = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                return(true);
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled)
            {
                return(true);
            }

            //Check timers, etc
            try
            {
                m_ScriptEngine.DoOneScriptPluginPass();
            }
            catch (Exception ex)
            {
                m_log.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex);
            }

            if (module != null)
            {
                foreach (Scene scene in m_ScriptEngine.Worlds)
                {
                    ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), "Script Frame Time");
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
            }

            threadpool.QueueEvent(CmdHandlerQueue, 2);
            return(false);
        }
Ejemplo n.º 6
0
        private void DearchiveRegion0DotStar()
        {
            if (m_loadStream == null)
            {
                return;
            }
            int      successfulAssetRestores = 0;
            int      failedAssetRestores     = 0;
            string   filePath = "NONE";
            DateTime start    = DateTime.Now;

            TarArchiveReader archive = new TarArchiveReader(m_loadStream);

            if (!m_skipAssets)
            {
                m_threadpool = new AuroraThreadPool(new AuroraThreadPoolStartInfo()
                {
                    Threads  = 1,
                    priority =
                        System.Threading.ThreadPriority
                        .BelowNormal
                });
            }

            IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>();

            if (!m_merge)
            {
                DateTime before = DateTime.Now;
                MainConsole.Instance.Info("[ARCHIVER]: Clearing all existing scene objects");
                if (backup != null)
                {
                    backup.DeleteAllSceneObjects();
                }
                MainConsole.Instance.Info("[ARCHIVER]: Cleared all existing scene objects in " +
                                          (DateTime.Now - before).Minutes + ":" + (DateTime.Now - before).Seconds);
            }

            IScriptModule[] modules = m_scene.RequestModuleInterfaces <IScriptModule>();
            //Disable the script engine so that it doesn't load in the background and kill OAR loading
            foreach (IScriptModule module in modules)
            {
                module.Disabled = true;
            }
            //Disable backup for now as well
            if (backup != null)
            {
                backup.LoadingPrims = true;
            }

            IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface <IRegionSerialiserModule>();
            int sceneObjectsLoadedCount        = 0;

            //We save the groups so that we can back them up later
            List <ISceneEntity> groupsToBackup = new List <ISceneEntity>();
            List <LandData>     landData       = new List <LandData>();

            // must save off some stuff until after assets have been saved and recieved new uuids
            // keeping these collection local because I am sure they will get large and garbage collection is better that way
            List <byte[]>           seneObjectGroups        = new List <byte[]>();
            Dictionary <UUID, UUID> assetBinaryChangeRecord = new Dictionary <UUID, UUID>();
            Queue <UUID>            assets2Save             = new Queue <UUID>();

            try
            {
                byte[] data;
                TarArchiveReader.TarEntryType entryType;
                while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
                {
                    if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    {
                        continue;
                    }

                    if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                    {
                        seneObjectGroups.Add(data);
                    }
                    else if (!m_skipAssets && filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                    {
                        AssetBase asset;
                        if (LoadAsset(filePath, data, out asset))
                        {
                            successfulAssetRestores++;
                            if (m_useAsync)
                            {
                                lock (AssetsToAdd) AssetsToAdd.Add(asset);
                            }
                            else
                            {
                                if (asset.IsBinaryAsset)
                                {
                                    UUID aid = asset.ID;
                                    asset.ID = m_scene.AssetService.Store(asset);
                                    if (asset.ID != aid && asset.ID != UUID.Zero)
                                    {
                                        assetBinaryChangeRecord.Add(aid, asset.ID);
                                    }
                                }
                                else
                                {
                                    if (!assetNonBinaryCollection.ContainsKey(asset.ID))
                                    {
                                        assetNonBinaryCollection.Add(asset.ID, asset);
                                        // I need something I can safely loop through
                                        assets2Save.Enqueue(asset.ID);
                                    }
                                }
                            }
                        }
                        else
                        {
                            failedAssetRestores++;
                        }

                        if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
                        {
                            MainConsole.Instance.Info("[ARCHIVER]: Loaded " + successfulAssetRestores +
                                                      " assets and failed to load " + failedAssetRestores + " assets...");
                        }
                    }
                    else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
                    {
                        LoadTerrain(filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                    {
                        LoadRegionSettings(filePath, data);
                    }
                    else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
                    {
                        LandData parcel = LandDataSerializer.Deserialize(m_utf8Encoding.GetString(data));
                        parcel.OwnerID = ResolveUserUuid(parcel.OwnerID, UUID.Zero, "", Vector3.Zero, null);
                        landData.Add(parcel);
                    }
                    else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                    {
                        LoadControlFile(data);
                    }
                }
                // Save Assets
                int savingAssetsCount = 0;
                while (assets2Save.Count > 0)
                {
                    try
                    {
                        UUID assetid = assets2Save.Dequeue();
                        SaveNonBinaryAssets(assetid, assetNonBinaryCollection[assetid], assetBinaryChangeRecord);
                        savingAssetsCount++;
                        if ((savingAssetsCount) % 250 == 0)
                        {
                            MainConsole.Instance.Info("[ARCHIVER]: Saving " + savingAssetsCount + " assets...");
                        }
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.Info("[ARCHIVER]: Exception in saving an asset: " + ex.ToString());
                    }
                }

                foreach (byte[] data2 in seneObjectGroups)
                {
                    byte[] data3 = data2;

                    string          stringData = Utils.BytesToString(data3);
                    MatchCollection mc         = Regex.Matches(stringData, sPattern);
                    bool            didChange  = false;
                    if (mc.Count >= 1)
                    {
                        foreach (Match match in mc)
                        {
                            UUID thematch = new UUID(match.Value);
                            UUID newvalue = thematch;
                            if (assetNonBinaryCollection.ContainsKey(thematch))
                            {
                                newvalue = assetNonBinaryCollection[thematch].ID;
                            }
                            else if (assetBinaryChangeRecord.ContainsKey(thematch))
                            {
                                newvalue = assetBinaryChangeRecord[thematch];
                            }
                            if (thematch == newvalue)
                            {
                                continue;
                            }
                            stringData = stringData.Replace(thematch.ToString().Trim(), newvalue.ToString().Trim());
                            didChange  = true;
                        }
                    }
                    if (didChange)
                    {
                        data3 = Utils.StringToBytes(stringData);
                    }

                    ISceneEntity sceneObject = serialiser.DeserializeGroupFromXml2(data3, m_scene);

                    if (sceneObject == null)
                    {
                        //! big error!
                        MainConsole.Instance.Error("Error reading SOP XML (Please mantis this!): " +
                                                   m_asciiEncoding.GetString(data3));
                        continue;
                    }

                    foreach (ISceneChildEntity part in sceneObject.ChildrenEntities())
                    {
                        if (string.IsNullOrEmpty(part.CreatorData))
                        {
                            part.CreatorID = ResolveUserUuid(part.CreatorID, part.CreatorID, part.CreatorData,
                                                             part.AbsolutePosition, landData);
                        }

                        part.OwnerID = ResolveUserUuid(part.OwnerID, part.CreatorID, part.CreatorData,
                                                       part.AbsolutePosition, landData);

                        part.LastOwnerID = ResolveUserUuid(part.LastOwnerID, part.CreatorID, part.CreatorData,
                                                           part.AbsolutePosition, landData);

                        // And zap any troublesome sit target information
                        part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
                        part.SitTargetPosition    = new Vector3(0, 0, 0);

                        // Fix ownership/creator of inventory items
                        // Not doing so results in inventory items
                        // being no copy/no mod for everyone
                        lock (part.TaskInventory)
                        {
                            TaskInventoryDictionary inv = part.TaskInventory;
                            foreach (KeyValuePair <UUID, TaskInventoryItem> kvp in inv)
                            {
                                kvp.Value.OwnerID = ResolveUserUuid(kvp.Value.OwnerID, kvp.Value.CreatorID,
                                                                    kvp.Value.CreatorData, part.AbsolutePosition,
                                                                    landData);
                                if (string.IsNullOrEmpty(kvp.Value.CreatorData))
                                {
                                    kvp.Value.CreatorID = ResolveUserUuid(kvp.Value.CreatorID, kvp.Value.CreatorID,
                                                                          kvp.Value.CreatorData, part.AbsolutePosition,
                                                                          landData);
                                }
                            }
                        }
                    }

                    //Add the offsets of the region
                    Vector3 newPos = new Vector3(sceneObject.AbsolutePosition.X + m_offsetX,
                                                 sceneObject.AbsolutePosition.Y + m_offsetY,
                                                 sceneObject.AbsolutePosition.Z + m_offsetZ);
                    if (m_flipX)
                    {
                        newPos.X = m_scene.RegionInfo.RegionSizeX - newPos.X;
                    }
                    if (m_flipY)
                    {
                        newPos.Y = m_scene.RegionInfo.RegionSizeY - newPos.Y;
                    }
                    sceneObject.SetAbsolutePosition(false, newPos);

                    if (m_scene.SceneGraph.AddPrimToScene(sceneObject))
                    {
                        groupsToBackup.Add(sceneObject);
                        sceneObject.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
                        sceneObject.CreateScriptInstances(0, false, StateSource.RegionStart, UUID.Zero, true);
                    }
                    sceneObjectsLoadedCount++;
                    if (sceneObjectsLoadedCount % 250 == 0)
                    {
                        MainConsole.Instance.Info("[ARCHIVER]: Loaded " + sceneObjectsLoadedCount + " objects...");
                    }
                }
                assetNonBinaryCollection.Clear();
                assetBinaryChangeRecord.Clear();
                seneObjectGroups.Clear();
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat(
                    "[ARCHIVER]: Aborting load with error in archive file {0}.  {1}", filePath, e);
                m_errorMessage += e.ToString();
                m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage);
                return;
            }
            finally
            {
                archive.Close();
                m_loadStream.Close();
                m_loadStream.Dispose();

                //Reeanble now that we are done
                foreach (IScriptModule module in modules)
                {
                    module.Disabled = false;
                }
                //Reset backup too
                if (backup != null)
                {
                    backup.LoadingPrims = false;
                }
            }

            //Now back up the prims
            foreach (ISceneEntity grp in groupsToBackup)
            {
                //Backup!
                grp.HasGroupChanged = true;
            }

            if (!m_skipAssets && m_useAsync && !AssetSaverIsRunning)
            {
                m_threadpool.QueueEvent(SaveAssets, 0);
            }

            if (!m_skipAssets)
            {
                MainConsole.Instance.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);

                if (failedAssetRestores > 0)
                {
                    MainConsole.Instance.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
                    m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
                }
            }

            // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
            // otherwise, use the master avatar uuid instead

            // Reload serialized parcels
            MainConsole.Instance.InfoFormat("[ARCHIVER]: Loading {0} parcels.  Please wait.", landData.Count);

            IParcelManagementModule parcelManagementModule = m_scene.RequestModuleInterface <IParcelManagementModule>();

            if (parcelManagementModule != null)
            {
                parcelManagementModule.IncomingLandDataFromOAR(landData, m_merge, new Vector2(m_offsetX, m_offsetY));
            }

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);

            //Clean it out
            landData.Clear();

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Successfully loaded archive in " +
                                            (DateTime.Now - start).Minutes + ":" + (DateTime.Now - start).Seconds);

            m_validUserUuids.Clear();
            m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This loop deals with starting and stoping scripts
        /// </summary>
        /// <returns></returns>
        public bool ScriptChangeQueue()
        {
            IMonitorModule module    = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                return(true);
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled)
            {
                return(true);
            }

            ScriptChangeIsRunning = true;

            object oitems;

            if (LUQueue.GetNext(out oitems))
            {
                LUStruct[]      items      = oitems as LUStruct[];
                List <LUStruct> NeedsFired = new List <LUStruct>();
                foreach (LUStruct item in items)
                {
                    if (item.Action == LUType.Unload)
                    {
                        //Close
                        item.ID.CloseAndDispose(true);
                    }
                    else if (item.Action == LUType.Load)
                    {
                        try
                        {
                            //Start
                            if (item.ID.Start(false))
                            {
                                NeedsFired.Add(item);
                            }
                        }
                        catch (Exception ex) { m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: LEAKED COMPILE ERROR: " + ex); }
                    }
                    else if (item.Action == LUType.Reupload)
                    {
                        try
                        {
                            //Start, but don't add to the queue's again
                            if (item.ID.Start(true))
                            {
                                NeedsFired.Add(item);
                            }
                        }
                        catch (Exception ex) { m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: LEAKED COMPILE ERROR: " + ex); }
                    }
                }
                foreach (LUStruct item in NeedsFired)
                {
                    //Fire the events afterward so that they all start at the same time
                    item.ID.FireEvents();
                }
                threadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us
                Thread.Sleep(5);
                return(false);
            }

            if (!FiredStartupEvent)
            {
                //If we are empty, we are all done with script startup and can tell the region that we are all done
                if (LUQueue.Count() == 0)
                {
                    FiredStartupEvent = true;
                    foreach (OpenSim.Region.Framework.Scenes.Scene scene in m_ScriptEngine.Worlds)
                    {
                        scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount,
                                                                          m_ScriptEngine.ScriptErrorMessages);

                        scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string>()
                        {
                            m_ScriptEngine.ScriptFailCount.ToString(),
                            m_ScriptEngine.ScriptErrorMessages
                        });                                                                               //Tell that we are done
                    }
                }
            }
            ScriptChangeIsRunning = false;
            Thread.Sleep(20);

            if (module != null)
            {
                foreach (Scene scene in m_ScriptEngine.Worlds)
                {
                    ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), "Script Frame Time");
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
            }

            return(false);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     This loop deals with starting and stoping scripts
        /// </summary>
        /// <returns></returns>
        public void ScriptChangeQueue()
        {
            if (m_ScriptEngine.Scene == null)
            {
                return;
            }

            IMonitorModule module    = m_ScriptEngine.Scene.RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                return;
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled || !m_ScriptEngine.Scene.ShouldRunHeartbeat)
            {
                return;
            }

            ScriptChangeIsRunning = true;

            object oitems;
            bool   broken = false;

            for (int i = 0; i < 5; i++)
            {
                if (LUQueue.GetNext(out oitems))
                {
                    StartScripts(oitems as LUStruct[]);
                }
                else
                {
                    //None left, stop looping
                    broken = true;
                    break;
                }
            }
            if (!broken)
            {
                scriptChangeThreadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us, still more to do
                return;
            }

            if (!FiredStartupEvent)
            {
                //If we are empty, we are all done with script startup and can tell the region that we are all done
                if (LUQueue.Count() == 0)
                {
                    FiredStartupEvent = true;
                    m_ScriptEngine.Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount,
                                                                                     m_ScriptEngine.ScriptErrorMessages);

                    m_ScriptEngine.Scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string>
                    {
                        m_ScriptEngine.ScriptFailCount.ToString(),
                        m_ScriptEngine.ScriptErrorMessages
                    });
                    //Tell that we are done
                }
            }
            ScriptChangeIsRunning = false;
            Thread.Sleep(20);

            if (module != null)
            {
                IScriptFrameTimeMonitor scriptMonitor = module.GetMonitor <IScriptFrameTimeMonitor>(m_ScriptEngine.Scene);
                if (scriptMonitor != null)
                {
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
            }
        }
        public void CmdHandlerQueue()
        {
            if (m_ScriptEngine.Worlds.Count == 0)
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }
            Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 1);
            IMonitorModule module    = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                return;
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled)
            {
                return;
            }

            //Check timers, etc
            bool didAnything = false;

            try
            {
                didAnything = m_ScriptEngine.DoOneScriptPluginPass();
            }
            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex);
            }

            if (module != null)
            {
#if (!ISWIN)
                foreach (IScene scene in m_ScriptEngine.Worlds)
                {
                    ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime);
                    if (scriptMonitor != null)
                    {
                        scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                    }
                }
#else
                foreach (ITimeMonitor scriptMonitor in m_ScriptEngine.Worlds.Select(scene => (ITimeMonitor)
                                                                                    module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime)).Where(scriptMonitor => scriptMonitor != null))
                {
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
#endif
            }

            if (didAnything) //If we did something, run us again soon
            {
                cmdThreadpool.QueueEvent(CmdHandlerQueue, 2);
            }
            else
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
            }
        }
Ejemplo n.º 10
0
        public virtual void HandleMapItemRequest(IClientAPI remoteClient, uint flags,
                                                 uint EstateID, bool godlike, uint itemtype, ulong regionhandle)
        {
            if (remoteClient.Scene.GetScenePresence(remoteClient.AgentId).IsChildAgent)
            {
                return;//No child agent requests
            }
            uint xstart;
            uint ystart;

            Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out xstart, out ystart);

            List <mapItemReply> mapitems = new List <mapItemReply>();
            int tc = Environment.TickCount;

            if (itemtype == (int)GridItemType.AgentLocations)
            {
                //If its local, just let it do it on its own.
                if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle)
                {
                    //Only one person here, send a zero person response
                    mapItemReply       mapitem;
                    IEntityCountModule entityCountModule = m_scene.RequestModuleInterface <IEntityCountModule>();
                    if (entityCountModule != null && entityCountModule.RootAgents <= 1)
                    {
                        mapitem = new mapItemReply
                        {
                            x      = xstart + 1,
                            y      = ystart + 1,
                            id     = UUID.Zero,
                            name   = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()),
                            Extra  = 0,
                            Extra2 = 0
                        };
                        mapitems.Add(mapitem);
                        remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags);
                        return;
                    }
                    m_scene.ForEachScenePresence(delegate(IScenePresence sp)
                    {
                        // Don't send a green dot for yourself
                        if (!sp.IsChildAgent && sp.UUID != remoteClient.AgentId)
                        {
                            mapitem = new mapItemReply
                            {
                                x      = (uint)(xstart + sp.AbsolutePosition.X),
                                y      = (uint)(ystart + sp.AbsolutePosition.Y),
                                id     = UUID.Zero,
                                name   = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()),
                                Extra  = 1,
                                Extra2 = 0
                            };
                            mapitems.Add(mapitem);
                        }
                    });
                    remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags);
                }
                else
                {
                    List <mapItemReply> reply;
                    if (!m_mapItemCache.TryGetValue(regionhandle, out reply))
                    {
                        m_itemsToRequest.Enqueue(new MapItemRequester
                        {
                            flags        = flags,
                            itemtype     = itemtype,
                            regionhandle = regionhandle,
                            remoteClient = remoteClient
                        });

                        if (!itemRequesterIsRunning)
                        {
                            threadpool.QueueEvent(GetMapItems, 3);
                        }
                    }
                    else
                    {
                        remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags);
                    }
                }
            }
        }