Esempio n. 1
0
        public override UUID GetUploaderID(Map reqmap)
        {
            var transaction  = UUID.Random;
            var experienceID = UUID.Zero;

            if (reqmap.ContainsKey("experience"))
            {
                experienceID = reqmap["experience"].AsUUID;
            }
            m_Transactions.Add(transaction, new TransactionInfo(reqmap["task_id"].AsUUID, reqmap["item_id"].AsUUID, reqmap["is_script_running"].AsBoolean, experienceID));
            return(transaction);
        }
        public override bool IMSend(GridInstantMessage im)
        {
            if (im.Dialog == GridInstantMessageDialog.MessageFromAgent)
            {
                m_ScriptedIMSessions.Add(im.FromAgent.ID, im.IMSessionID);
            }

            if (im.Dialog == GridInstantMessageDialog.MessageFromAgent ||
                im.Dialog == GridInstantMessageDialog.MessageFromObject)
            {
                foreach (KeyValuePair <UUID, RwLockedDictionary <UUID, int> > kvp in m_ScriptedChatListeners)
                {
                    ObjectPart part;
                    ObjectPartInventoryItem item;
                    if (CurrentScene.Primitives.TryGetValue(kvp.Key, out part))
                    {
                        foreach (KeyValuePair <UUID, int> kvpinner in kvp.Value)
                        {
                            if (part.Inventory.TryGetValue(kvpinner.Key, out item))
                            {
                                ScriptInstance instance = item.ScriptInstance;

                                /* Translate IM event to mapped channel */
                                instance?.PostEvent(new ListenEvent
                                {
                                    ButtonIndex    = -1,
                                    Channel        = kvpinner.Value,
                                    Distance       = 0,
                                    GlobalPosition = Vector3.Zero,
                                    ID             = im.FromAgent.ID,
                                    Message        = im.Message,
                                    Name           = im.FromAgent.FullName,
                                    OriginSceneID  = UUID.Zero,
                                    OwnerID        = im.FromAgent.ID,
                                    SourceType     = im.Dialog == GridInstantMessageDialog.MessageFromObject ? ListenEvent.ChatSourceType.Object : ListenEvent.ChatSourceType.Agent,
                                    TargetID       = ID,
                                    Type           = ListenEvent.ChatType.Say
                                });
                            }
                        }
                    }
                    else
                    {
                        m_ScriptedIMListeners.Remove(kvp.Key);
                    }
                }
            }
            return(true);
        }
Esempio n. 3
0
        public void AddObjectBuyListen(ScriptInstance instance)
        {
            ObjectPart part = instance.Part;
            ObjectPartInventoryItem item = instance.Item;

            if (part != null && item != null)
            {
                var listen = new ObjectBuyListen
                {
                    PrimitiveID = part.ID,
                    ItemID      = item.ID
                };
                m_ObjectBuyListeners.Add(listen.Key, listen);
            }
        }
Esempio n. 4
0
        public void AddRemoveAllCommand(string cmd, Action <List <string>, TTY, UUID> handler)
        {
            RwLockedDictionary <string, Action <List <string>, TTY, UUID> > removecmds = CheckAddCommandType("remove");
            RwLockedDictionary <string, Action <List <string>, TTY, UUID> > removeallcmds;

            lock (m_RegisterCmdGroupLock)
            {
                if (!m_SubCommands.TryGetValue("remove all", out removeallcmds))
                {
                    removeallcmds = new RwLockedDictionary <string, Action <List <string>, TTY, UUID> >();
                    removecmds.Add("all", new SubCommandType("remove all", removeallcmds).Command_Handler);
                    m_SubCommands.Add("remove all", removeallcmds);
                }
            }
            removeallcmds.Add(cmd, handler);
        }
 public void AddCircuit(Circuit c)
 {
     m_Circuits.Add(c.RemoteEndPoint, c.CircuitCode, c);
     try
     {
         var ac = c as AgentCircuit;
         if (ac != null)
         {
             m_Agents.Add(ac.AgentID, ac.Agent);
         }
     }
     catch
     {
         m_Circuits.Remove(c.RemoteEndPoint, c.CircuitCode);
         throw;
     }
 }
Esempio n. 6
0
 protected void AddNewLocalID(IObject v)
 {
     while (true)
     {
         try
         {
             UInt32 localID = NextLocalID;
             m_LocalIDs.Add(localID, v);
             v.LocalID[ID] = localID;
             break;
         }
         catch
         {
             /* no action required */
         }
     }
 }
        public override void Store(AssetData asset)
        {
            AssetData internalAsset;

            if (m_Assets.TryGetValue(asset.ID, out internalAsset))
            {
                if (internalAsset.Flags != AssetFlags.Normal)
                {
                    internalAsset = new AssetData(asset);
                    m_Assets[internalAsset.ID] = internalAsset;
                }
            }
            else
            {
                internalAsset = new AssetData(asset);
                m_Assets.Add(internalAsset.ID, internalAsset);
            }
        }
        public void HandleRequestXfer(Message m)
        {
            var req = (RequestXfer)m;
            DownloadTransferData tdata;

            if (m_DownloadTransfersByName.TryGetValue(req.Filename, out tdata))
            {
                if (tdata.Position != 0)
                {
                    return;
                }

                var res = new SendXferPacket();
                tdata.XferID = req.ID;
                if (tdata.Data.Length > 1400)
                {
                    res.Data = new byte[1400 + 4];
                    Buffer.BlockCopy(tdata.Data, 0, res.Data, 4, 1400);
                    tdata.Position += 1400;
                    m_DownloadTransfersByXferID.Add(tdata.XferID, tdata);
                    res.Packet = 0;
                }
                else
                {
                    res.Data = new byte[tdata.Data.Length + 4];
                    Buffer.BlockCopy(tdata.Data, 0, res.Data, 4, tdata.Data.Length);
                    m_DownloadTransfersByName.Remove(req.Filename);
                    tdata.Position += res.Data.Length;
                    res.Packet      = 0x80000000;
                }
                res.Data[0] = (byte)(tdata.Data.Length & 0xFF);
                res.Data[1] = (byte)((tdata.Data.Length >> 8) & 0xFF);
                res.Data[2] = (byte)((tdata.Data.Length >> 16) & 0xFF);
                res.Data[3] = (byte)((tdata.Data.Length >> 24) & 0xFF);
                res.ID      = tdata.XferID;
                SendMessageAlways(res, req.CircuitSceneID);
            }
        }
Esempio n. 9
0
        public override UUID GetUploaderID(Map reqmap)
        {
            var transaction = UUID.Random;
            var item        = new InventoryItem
            {
                Description       = reqmap["description"].ToString(),
                Name              = reqmap["name"].ToString(),
                ParentFolderID    = reqmap["folder_id"].AsUUID,
                AssetTypeName     = reqmap["asset_type"].ToString(),
                InventoryTypeName = reqmap["inventory_type"].ToString(),
                LastOwner         = Creator,
                Owner             = Creator,
                Creator           = Creator
            };

            item.Permissions.Base      = InventoryPermissionsMask.All;
            item.Permissions.Current   = InventoryPermissionsMask.Every;
            item.Permissions.EveryOne  = (InventoryPermissionsMask)reqmap["everyone_mask"].AsUInt;
            item.Permissions.Group     = (InventoryPermissionsMask)reqmap["group_mask"].AsUInt;
            item.Permissions.NextOwner = (InventoryPermissionsMask)reqmap["next_owner_mask"].AsUInt;
            m_Transactions.Add(transaction, item);
            return(transaction);
        }
Esempio n. 10
0
 public IScriptCompiler this[string name]
 {
     get
     {
         return(string.IsNullOrEmpty(name) ?
                m_ScriptCompilers[DefaultCompilerName] :
                m_ScriptCompilers[name]);
     }
     set
     {
         if (string.IsNullOrEmpty(name))
         {
             throw new ArgumentException("value");
         }
         if (value == null)
         {
             m_ScriptCompilers.Remove(name);
         }
         else
         {
             m_ScriptCompilers.Add(name, value);
         }
     }
 }
Esempio n. 11
0
        public override void Add(IObject obj)
        {
            var objgroup = obj as ObjectGroup;

            if (objgroup != null)
            {
                UGUI uui = objgroup.LastOwner;
                if (uui.HomeURI == null && AvatarNameService.TryGetValue(uui, out uui))
                {
                    objgroup.LastOwner = uui;
                }
                foreach (ObjectPart part in objgroup.Values)
                {
                    uui = part.Owner;
                    if (uui.HomeURI == null && AvatarNameService.TryGetValue(uui, out uui))
                    {
                        part.Owner = uui;
                    }
                    uui = part.Creator;
                    if (uui.HomeURI == null && AvatarNameService.TryGetValue(uui, out uui))
                    {
                        part.Creator = uui;
                    }
                    foreach (ObjectPartInventoryItem item in part.Inventory.ValuesByKey1)
                    {
                        uui = item.Owner;
                        if (uui.HomeURI == null && AvatarNameService.TryGetValue(uui, out uui))
                        {
                            item.Owner = uui;
                        }
                        uui = item.LastOwner;
                        if (uui.HomeURI == null && AvatarNameService.TryGetValue(uui, out uui))
                        {
                            item.LastOwner = uui;
                        }
                        uui = item.Creator;
                        if (uui.HomeURI == null && AvatarNameService.TryGetValue(uui, out uui))
                        {
                            item.Creator = uui;
                        }
                    }
                    part.RezDate = Date.Now;
                }

                var removeAgain = new List <ObjectPart>();

                AddLegacyMaterials(objgroup);

                try
                {
                    objgroup.Scene = this;
                    foreach (ObjectPart objpart in objgroup.Values)
                    {
                        AddNewLocalID(objpart);
                        m_Primitives.Add(objpart.ID, objpart.LocalID[ID], objpart);
                        removeAgain.Add(objpart);
                    }
                    m_Objects.Add(objgroup.ID, objgroup);

                    foreach (ObjectPart objpart in objgroup.Values)
                    {
                        Interlocked.Increment(ref m_PrimitiveCount);
                        objpart.SendObjectUpdate();
                    }
                    Interlocked.Increment(ref m_ObjectCount);
                }
                catch (Exception e)
                {
                    m_Log.DebugFormat("Failed to add object: {0}: {1}\n{2}", e.GetType().FullName, e.Message, e.StackTrace);
                    m_Objects.Remove(objgroup.ID);
                    foreach (ObjectPart objpart in removeAgain)
                    {
                        m_Primitives.Remove(objpart.ID);
                        RemoveLocalID(objpart);
                    }
                    objgroup.Scene = null;
                }
            }
            else
            {
                AddNewLocalID(obj);
                try
                {
                    m_Objects.Add(obj.ID, obj);
                    if (obj.GetType().GetInterfaces().Contains(typeof(IAgent)))
                    {
                        var agent = (IAgent)obj;
                        m_Agents.Add(obj.ID, agent);
                        Interlocked.Increment(ref m_AgentCount);
                        foreach (IAgentListener aglistener in AgentListeners)
                        {
                            try
                            {
                                aglistener.AddedAgent(agent);
                            }
                            catch (Exception e)
                            {
                                m_Log.DebugFormat("Exception {0}\n{1}", e.Message, e.StackTrace);
                            }
                        }
                    }
                }
                catch
                {
                    if (m_Agents.Remove(obj.ID))
                    {
                        Interlocked.Decrement(ref m_AgentCount);
                    }
                    m_Objects.Remove(obj.ID);
                    RemoveLocalID(obj);
                }
            }
        }
Esempio n. 12
0
        private bool TryGetConvexShapeFromPrim(PrimitivePhysicsShapeType physicsShape, ObjectPart.PrimitiveShape shape, out PhysicsShapeReference physicshaperef)
        {
            PhysicsConvexShape    physicshape;
            PhysicsShapeReference physicshaperes = null;
            bool s = m_Lock.AcquireReaderLock(() =>
            {
                if (m_ConvexShapesByPrimShape.TryGetValue(shape, out physicshape))
                {
                    physicshaperes = new PhysicsShapePrimShapeReference(shape, this, physicshape);
                    return(true);
                }
                return(false);
            });

            if (s)
            {
                physicshaperef = physicshaperes;
                return(true);
            }

            if (m_DisableCache || !m_SimulationStorage.PhysicsConvexShapes.TryGetValue(shape, out physicshape))
            {
                /* we may produce additional meshes sometimes but it is better not to lock while generating the mesh */
                physicshape = ConvertToMesh(physicsShape, shape);
                if (physicshape == null)
                {
                    physicshaperef = null;
                    return(false);
                }
                foreach (PhysicsConvexShape.ConvexHull hull in physicshape.Hulls)
                {
                    if (hull.Vertices.Count == 0)
                    {
                        if (shape.Type == PrimitiveShapeType.Sculpt)
                        {
                            m_Log.WarnFormat("Physics shape of sculpt generated a 0 point hull: {0} / {1}", physicsShape, shape.Serialization.ToHexString());
                        }
                        else
                        {
                            m_Log.WarnFormat("Physics shape of prim generated a 0 point hull: {0} / {1} / {2} / {3}", physicsShape, shape.PCode, shape.Type, shape.Serialization.ToHexString());
                        }
                        physicshaperef = null;
                        return(false);
                    }
                }
                m_SimulationStorage.PhysicsConvexShapes[shape] = physicshape;
            }

            /* we only lock out the decrement use count here */
            physicshaperef = m_Lock.AcquireReaderLock(() =>
            {
                try
                {
                    m_ConvexShapesByPrimShape.Add(shape, physicshape);
                }
                catch
                {
                    physicshape = m_ConvexShapesByPrimShape[shape];
                }
                return(new PhysicsShapePrimShapeReference(shape, this, physicshape));
            });

            return(true);
        }
Esempio n. 13
0
 public override void Add(EstateInfo estateInfo)
 {
     m_Data.Add(estateInfo.ID, new EstateInfo(estateInfo));
 }
 public override void Store(AssetData asset)
 {
     m_Assets.Add(asset.ID, asset);
 }
Esempio n. 15
0
        private ProfileServiceData LookupProfileService(SceneInterface scene, UUID agentID, out UGUI agentUUI)
        {
            ProfileServiceData        serviceData      = null;
            ProfileServiceInterface   profileService   = null;
            UserAgentServiceInterface userAgentService = null;

            agentUUI = UGUI.Unknown;

            if (profileService == null)
            {
                try
                {
                    IAgent agent = scene.Agents[agentID];
                    agentUUI         = agent.NamedOwner;
                    profileService   = agent.ProfileService;
                    userAgentService = agent.UserAgentService;
                    if (profileService == null)
                    {
                        profileService = new DummyProfileService();
                    }
                    if (userAgentService == null)
                    {
                        userAgentService = new DummyUserAgentService();
                    }
                    serviceData = new ProfileServiceData(userAgentService, profileService);
                }
                catch
                {
                    agentUUI = UGUI.Unknown;
                }
            }

            if (profileService == null && userAgentService == null)
            {
                UGUI uui;
                try
                {
                    uui      = scene.AvatarNameService[agentID];
                    agentUUI = uui;

                    if (!m_LastKnownProfileServices.TryGetValue(uui.HomeURI.ToString(), out serviceData))
                    {
                        foreach (IUserAgentServicePlugin userAgentPlugin in m_UserAgentServices)
                        {
                            if (userAgentPlugin.IsProtocolSupported(uui.HomeURI.ToString()))
                            {
                                userAgentService = userAgentPlugin.Instantiate(uui.HomeURI.ToString());
                                break;
                            }
                        }

                        Dictionary <string, string> urls = userAgentService.GetServerURLs(uui);
                        if (urls.ContainsKey("ProfileServerURI"))
                        {
                            string profileServerURI = urls["ProfileServerURI"];
                            foreach (IProfileServicePlugin profilePlugin in m_ProfileServices)
                            {
                                if (profilePlugin.IsProtocolSupported(profileServerURI))
                                {
                                    profileService = profilePlugin.Instantiate(profileServerURI);
                                }
                            }
                        }

                        if (userAgentService != null)
                        {
                            if (profileService == null)
                            {
                                profileService = new DummyProfileService();
                            }

                            serviceData = new ProfileServiceData(userAgentService, profileService);
                            m_LastKnownProfileServices.Add(uui.HomeURI.ToString(), serviceData);
                        }
                    }
                }
                catch
                {
                    agentUUI = UGUI.Unknown;
                }
            }

            return(serviceData);
        }
Esempio n. 16
0
 private void OnSceneAdded(SceneInterface scene)
 {
     m_KnownScenes.Add(scene.ID, scene);
     scene.LoginControl.OnLoginsEnabled += LoginControl_OnLoginsEnabled;
 }
        private void ThreadMain(object obj)
        {
            var            tc   = (ScriptThreadContext)obj;
            var            pool = tc.ThreadPool;
            ScriptInstance ev;

            while (!m_ShutdownThreads)
            {
                try
                {
                    ev = pool.m_ScriptTriggerQueue.Dequeue(1000);
                }
                catch
                {
                    lock (m_Threads)
                    {
                        if (m_Threads.Count > m_MinimumThreads)
                        {
                            break;
                        }
                    }
                    continue;
                }

                long executionStart = TimeSource.TickCount;
                tc.ExecutionStartTickCount = executionStart;
                tc.IsExecuting             = true;
                ObjectPartInventoryItem item = ev.Item;
                try
                {
                    Interlocked.Increment(ref m_ExecutingScripts);
                    lock (tc)
                    {
                        if (Interlocked.CompareExchange(ref ev.ThreadPool, this, null) != null)
                        {
                            continue;
                        }
                        tc.CurrentScriptInstance = ev;
                    }
                    ev.ProcessEvent();
                }
                catch (ThreadAbortException)
                {
                    /* no in script event should abort us */
                    Thread.ResetAbort();
                    try
                    {
                        item.ScriptInstance = null;
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                    catch (Exception e)
                    {
                        m_Log.WarnFormat("Exception at script removal {0} ({1}): {2}\n{3}",
                                         item.Name, item.AssetID.ToString(),
                                         e.Message,
                                         e.StackTrace);
                    }
                    ScriptLoader.Remove(item.AssetID, ev);
                    continue;
                }
                catch (ScriptAbortException)
                {
                    ev.AbortBegin();
                    try
                    {
                        item.ScriptInstance = null;
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                    catch (Exception e)
                    {
                        m_Log.WarnFormat("Exception at script removal {0} ({1}): {2}\n{3}",
                                         item.Name, item.AssetID.ToString(),
                                         e.Message,
                                         e.StackTrace);
                    }
                    ScriptLoader.Remove(item.AssetID, ev);
                    continue;
                }
                catch (InvalidProgramException e)
                {
                    /* stop the broken script */
                    m_Log.WarnFormat("Automatically stopped script {0} ({1}) of {2} ({3}) in {4} ({5}) due to program error: {6}\n{7}",
                                     item.Name, item.AssetID.ToString(),
                                     ev.Part?.Name ?? "?", ev.Part?.ID.ToString() ?? "?",
                                     ev.Part?.ObjectGroup?.Name ?? "?", ev.Part?.ObjectGroup?.ID.ToString() ?? "?",
                                     e.Message,
                                     e.StackTrace);
                    ev.IsRunning = false;
                    continue;
                }
                catch (Exception e)
                {
                    m_Log.WarnFormat("Exception at script {0} ({1}) of {2} ({3}) in {4} ({5}) due to program error: {6}\n{7}",
                                     item.Name, item.AssetID.ToString(),
                                     ev.Part?.Name ?? "?", ev.Part?.ID.ToString() ?? "?",
                                     ev.Part?.ObjectGroup?.Name, ev.Part?.ObjectGroup?.ID.ToString() ?? "?",
                                     e.Message,
                                     e.StackTrace);
                }
                finally
                {
                    Interlocked.Decrement(ref m_ExecutingScripts);
                    tc.IsExecuting = false;
                    uint localId;
                    lock (tc)
                    {
                        try
                        {
                            localId        = tc.CurrentScriptInstance.Part.LocalID[m_SceneID];
                            executionStart = TimeSource.TicksElapsed(TimeSource.TickCount, executionStart);
                            if (executionStart > 0)
                            {
                                RwLockedDictionary <uint, ScriptReportData> execTime = m_TopScripts;
                                ScriptReportData prevexectime;
                                if (!execTime.TryGetValue(localId, out prevexectime))
                                {
                                    prevexectime = new ScriptReportData();
                                    execTime.Add(localId, prevexectime);
                                }
                                prevexectime.AddScore(TimeSource.TicksToMsecs(executionStart));
                                Interlocked.Add(ref m_ScriptRuntimeAccumulatingTickCount, executionStart);
                            }
                        }
                        catch
                        {
                            /* ignore it here */
                        }
                        tc.CurrentScriptInstance = null;
                    }
                }

                ev.ThreadPool = null;
                if (ev.HasEventsPending)
                {
                    pool.m_ScriptTriggerQueue.Enqueue(ev);
                }
            }

            lock (m_Threads)
            {
                m_Threads.Remove(tc);
                if (m_ShutdownThreads && m_Threads.Count == 0)
                {
                    m_WaitShutdownEvent.Set();
                }
            }
        }
Esempio n. 18
0
 internal static void RegisterAppDomain(UUID assetID, AppDomain appDom)
 {
     m_LoadedDomains.Add(assetID, appDom);
 }
Esempio n. 19
0
        private void LoginControl_OnLoginsEnabled(UUID sceneID, bool obj)
        {
            SceneInterface scene;
            bool           notrezzedbefore = true;

            if (m_NpcPresenceService != null && m_KnownScenes.TryGetValue(sceneID, out scene))
            {
                foreach (NpcPresenceInfo npcInfo in m_NpcPresenceService[scene.ID])
                {
                    NpcAgent agent;
                    IAgent   d;
                    if (!scene.Agents.TryGetValue(npcInfo.Npc.ID, out d))
                    {
                        if (notrezzedbefore)
                        {
                            m_Log.Info("Rezzing persistent NPCs");
                            notrezzedbefore = false;
                        }
                        /* only rez if not rezzed before */
                        m_Log.InfoFormat("Rezzing persistent NPC {0} {1} ({2})", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID);
                        try
                        {
                            agent = new NpcAgent(npcInfo.Npc, m_PersistentAgentServices, sceneID)
                            {
                                GlobalPosition = npcInfo.Position,
                                LookAt         = npcInfo.LookAt,
                                NpcOwner       = npcInfo.Owner,
                                Group          = npcInfo.Group,
                                CurrentScene   = scene
                            };
                            m_NpcAgents.Add(npcInfo.Npc.ID, agent);
                            scene.Add(agent);
                            agent.EnableListen();
                            try
                            {
                                if (npcInfo.SittingOnObjectID != UUID.Zero)
                                {
                                    agent.DoSit(npcInfo.SittingOnObjectID);
                                }
                            }
                            catch
                            {
                                m_Log.WarnFormat("Failed to sit persistent NPC {0} {1} ({2}) on object id {3}", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID.ToString(), npcInfo.SittingOnObjectID.ToString());
                            }
                        }
                        catch
                        {
                            m_Log.WarnFormat("Failed to instantiate persistent NPC {0} {1} ({2})", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID.ToString());
                            continue;
                        }

                        try
                        {
                            agent.RebakeAppearance();
                        }
                        catch
                        {
                            m_Log.WarnFormat("Failed to rebake persistent NPC {0} {1} ({2})", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID.ToString());
                        }
                    }
                }
            }
        }
Esempio n. 20
0
        private void HandleChildAgentChanges(AgentCircuit circuit)
        {
            SceneInterface scene = circuit.Scene;

            if (scene == null)
            {
                return;
            }

            Dictionary <GridVector, IChildAgentConnection> disconnects = new Dictionary <GridVector, IChildAgentConnection>();

            foreach (KeyValuePair <GridVector, IChildAgentConnection> kvp in KnownChildAgentConnections)
            {
                UUID childSceneID = kvp.Value.SceneID;
                if (childSceneID == scene.ID)
                {
                    continue;
                }

                disconnects.Add(kvp.Key, kvp.Value);
            }

            /* remove all that stay active */
            foreach (KeyValuePair <UUID, SceneInterface.NeighborEntry> kvp in scene.Neighbors)
            {
                disconnects.Remove(kvp.Value.RemoteRegionData.Location);
            }

            /* connect new child agents */
            foreach (KeyValuePair <UUID, SceneInterface.NeighborEntry> kvp in scene.Neighbors)
            {
                if (!KnownChildAgentConnections.ContainsKey(kvp.Value.RemoteRegionData.Location))
                {
                    SceneInterface childScene;
                    if (m_Scenes.TryGetValue(kvp.Key, out childScene))
                    {
                        /* local connect */
#if DEBUG
                        m_Log.DebugFormat("Connect agent {0} to scene {1} as child locally", NamedOwner.FullName, childScene.ID);
#endif

                        UUID            seedId;
                        string          seedCapsUri  = NewCapsURL(childScene, out seedId);
                        var             udpServer    = (UDPCircuitsManager)childScene.UDPServer;
                        AgentCircuit    childCircuit = circuit.CreateChild(udpServer, seedId);
                        DestinationInfo connectInfo  = new DestinationInfo(kvp.Value.RemoteRegionData)
                        {
                            TeleportFlags = TeleportFlags.None
                        };
                        Circuits.Add(childScene.ID, childCircuit);
                        try
                        {
                            childScene.Add(this);
                            try
                            {
                                udpServer.AddCircuit(childCircuit);
                            }
                            catch
                            {
                                childScene.Remove(this);
                                continue;
                            }
                        }
                        catch
                        {
                            Circuits.Remove(childScene.ID);
                            continue;
                        }
                        EnableSimulator(scene.ID, circuit.CircuitCode, seedCapsUri, connectInfo);
                    }
                    else
                    {
                    }
                }
            }

            /* disconnect unneeded child agents */
            foreach (IChildAgentConnection conn in disconnects.Values)
            {
#if DEBUG
                m_Log.DebugFormat("Disconnect agent {0} from scene {1}", NamedOwner.FullName, conn.SceneID);
#endif
                conn.Disable();
            }
        }