Inheritance: Universe.Framework.Modules.IDataTransferable
        public bool CreateAgent (GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out CreateAgentResponse response)
        {
            response = null;
            if (destination == null) {
                response = new CreateAgentResponse ();
                response.Reason = "Could not connect to destination";
                response.Success = false;
                return false;
            }
            CreateAgentRequest request = new CreateAgentRequest ();
            request.CircuitData = aCircuit;
            request.Destination = destination;
            request.TeleportFlags = teleportFlags;

            AutoResetEvent resetEvent = new AutoResetEvent (false);
            OSDMap result = null;
            MainConsole.Instance.DebugFormat ("[SimulationServiceConnector]: Sending Create Agent to " + destination.ServerURI);
            m_syncMessagePoster.Get (destination.ServerURI, request.ToOSD (), osdresp => {
                result = osdresp;
                resetEvent.Set ();
            });
            bool success = resetEvent.WaitOne (10000);
            if (!success || result == null) {
                response = new CreateAgentResponse ();
                response.Reason = "Could not connect to destination";
                response.Success = false;
                return false;
            }

            response = new CreateAgentResponse ();
            response.FromOSD (result);

            return response.Success;
        }
        /// <summary>
        /// Agent-related communications
        /// </summary>
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out CreateAgentResponse response)
        {
            response = new CreateAgentResponse();
            IScene Scene = destination == null ? null : GetScene(destination.RegionID);
            if (destination == null || Scene == null)
            {
                response.Reason = "Given destination was null";
                response.Success = false;
                return false;
            }

            if (Scene.RegionInfo.RegionID != destination.RegionID)
            {
                response.Reason = "Did not find region " + destination.RegionName;;
                response.Success = false;
                return false;
            }
            IEntityTransferModule transferModule = Scene.RequestModuleInterface<IEntityTransferModule>();
            if (transferModule != null)
                return transferModule.NewUserConnection(Scene, aCircuit, teleportFlags, out response);

            response.Reason = "Did not find region " + destination.RegionName;
            response.Success = false;
            return false;
        }
 OSDMap LocalSimulationServiceConnector_OnMessageReceived (OSDMap message)
 {
     if (!message.ContainsKey ("Method"))
         return null;
     switch (message ["Method"].AsString ()) {
     case "CreateAgentRequest":
         CreateAgentRequest createAgentRequest = new CreateAgentRequest ();
         createAgentRequest.FromOSD (message);
         CreateAgentResponse createAgentResponse = new CreateAgentResponse ();
         createAgentResponse.Success = CreateAgent (createAgentRequest.Destination, createAgentRequest.CircuitData, createAgentRequest.TeleportFlags, out createAgentResponse);
         return createAgentResponse.ToOSD ();
     case "UpdateAgentPositionRequest":
         UpdateAgentPositionRequest updateAgentPositionRequest = new UpdateAgentPositionRequest ();
         updateAgentPositionRequest.FromOSD (message);
         return new OSDMap () { new KeyValuePair<string, OSD> ("Success", UpdateAgent (updateAgentPositionRequest.Destination, updateAgentPositionRequest.Update)) };
     case "UpdateAgentDataRequest":
         UpdateAgentDataRequest updateAgentDataRequest = new UpdateAgentDataRequest ();
         updateAgentDataRequest.FromOSD (message);
         return new OSDMap () { new KeyValuePair<string, OSD> ("Success", UpdateAgent (updateAgentDataRequest.Destination, updateAgentDataRequest.Update)) };
     case "FailedToMoveAgentIntoNewRegionRequest":
         FailedToMoveAgentIntoNewRegionRequest failedToMoveAgentIntoNewRegionRequest = new FailedToMoveAgentIntoNewRegionRequest ();
         failedToMoveAgentIntoNewRegionRequest.FromOSD (message);
         FailedToMoveAgentIntoNewRegion (failedToMoveAgentIntoNewRegionRequest.AgentID, failedToMoveAgentIntoNewRegionRequest.RegionID);
         break;
     case "CloseAgentRequest":
         CloseAgentRequest closeAgentRequest = new CloseAgentRequest ();
         closeAgentRequest.FromOSD (message);
         CloseAgent (closeAgentRequest.Destination, closeAgentRequest.AgentID);
         break;
     case "MakeChildAgentRequest":
         MakeChildAgentRequest makeChildAgentRequest = new MakeChildAgentRequest ();
         makeChildAgentRequest.FromOSD (message);
         MakeChildAgent (makeChildAgentRequest.AgentID, makeChildAgentRequest.OldRegion, makeChildAgentRequest.Destination, makeChildAgentRequest.IsCrossing);
         break;
     case "FailedToTeleportAgentRequest":
         FailedToTeleportAgentRequest failedToTeleportAgentRequest = new FailedToTeleportAgentRequest ();
         failedToTeleportAgentRequest.FromOSD (message);
         FailedToTeleportAgent (failedToTeleportAgentRequest.Destination, failedToTeleportAgentRequest.FailedRegionID,
             failedToTeleportAgentRequest.AgentID, failedToTeleportAgentRequest.Reason, failedToTeleportAgentRequest.IsCrossing);
         break;
     case "RetrieveAgentRequest":
         RetrieveAgentRequest retrieveAgentRequest = new RetrieveAgentRequest ();
         retrieveAgentRequest.FromOSD (message);
         RetrieveAgentResponse retrieveAgentResponse = new RetrieveAgentResponse ();
         retrieveAgentResponse.Success = RetrieveAgent (retrieveAgentRequest.Destination, retrieveAgentRequest.AgentID, retrieveAgentRequest.AgentIsLeaving,
             out retrieveAgentResponse.AgentData, out retrieveAgentResponse.CircuitData);
         return retrieveAgentResponse.ToOSD ();
     case "CreateObjectRequest":
         CreateObjectRequest createObjectRequest = new CreateObjectRequest ();
         createObjectRequest.FromOSD (message);
         createObjectRequest.Scene = GetScene (createObjectRequest.Destination.RegionID);
         createObjectRequest.DeserializeObject ();
         return new OSDMap () { new KeyValuePair<string, OSD> ("Success", CreateObject (createObjectRequest.Destination, createObjectRequest.Object)) };
     }
     return null;
 }
        /// <summary>
        ///     Do the work necessary to initiate a new user connection for a particular scene.
        ///     At the moment, this consists of setting up the caps infrastructure
        ///     The return bool should allow for connections to be refused, but as not all calling paths
        ///     take proper notice of it let, we allowed banned users in still.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="agent">CircuitData of the agent who is connecting</param>
        /// <param name="response">
        ///     Outputs the reason for the false response on this string,
        ///     If the agent was accepted, this will be the Caps SEED for the region
        /// </param>
        /// <param name="teleportFlags"></param>
        /// <returns>
        ///     True if the region accepts this agent.  False if it does not.  False will
        ///     also return a rsponse.
        /// </returns>
        public bool NewUserConnection (IScene scene, AgentCircuitData agent, uint teleportFlags, out CreateAgentResponse response)
        {
            response = new CreateAgentResponse ();
            response.RequestedUDPPort = scene.RegionInfo.RegionPort;
            IScenePresence sp = scene.GetScenePresence (agent.AgentID);

            // Don't disable this log message - it's too helpful
            MainConsole.Instance.TraceFormat (
                "[Connection begin]: Region {0} told of incoming {1} agent {2} (circuit code {3}, teleportflags {4})",
                scene.RegionInfo.RegionName, agent.IsChildAgent ? "child" : "root", agent.AgentID,
                agent.CircuitCode, teleportFlags);

            CacheUserInfo (scene, agent.CachedUserInfo);

            string reason;
            if (!AuthorizeUser (scene, agent, out reason)) {
                response.Reason = reason;
                response.Success = false;
                return false;
            }

            if (sp != null && !sp.IsChildAgent) {
                // We have a zombie from a crashed session. 
                // Or the same user is trying to be root twice here, won't work.
                // Kill it.
                MainConsole.Instance.InfoFormat ("[Scene]: Zombie scene presence detected for {0} in {1}",
                                                 agent.AgentID, scene.RegionInfo.RegionName);
                //Tell everyone about it
                scene.UniverseEventManager.FireGenericEventHandler ("AgentIsAZombie", sp.UUID);
                //Send the killing message (DisableSimulator)
                scene.RemoveAgent (sp, true);
                sp = null;
            }

            response.CapsURIs = scene.EventManager.TriggerOnRegisterCaps (agent.AgentID);
            response.OurIPForClient = MainServer.Instance.HostName;

            scene.UniverseEventManager.FireGenericEventHandler ("NewUserConnection", agent);

            //Add the circuit at the end
            scene.AuthenticateHandler.AddNewCircuit (agent.CircuitCode, agent);

            MainConsole.Instance.InfoFormat (
                "[Connection begin]: Region {0} authenticated and authorized incoming {1} agent {2} (circuit code {3})",
                scene.RegionInfo.RegionName, agent.IsChildAgent ? "child" : "root", agent.AgentID,
                agent.CircuitCode);

            response.Success = true;
            return true;
        }
        bool CreateAgent(GridRegion region, IRegionClientCapsService regionCaps, ref AgentCircuitData aCircuit,
            ISimulationService SimulationService, List<UUID> friendsToInform, out CreateAgentResponse response)
        {
            CachedUserInfo info = new CachedUserInfo();
            IAgentConnector con = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>();

            if (con != null)
                info.AgentInfo = con.GetAgent(aCircuit.AgentID);

            if (regionCaps != null)
                info.UserAccount = regionCaps.ClientCaps.AccountInfo;

            IGroupsServiceConnector groupsConn = Framework.Utilities.DataManager.RequestPlugin<IGroupsServiceConnector>();

            if (groupsConn != null)
            {
                info.ActiveGroup = groupsConn.GetGroupMembershipData(aCircuit.AgentID, UUID.Zero, aCircuit.AgentID);
                info.GroupMemberships = groupsConn.GetAgentGroupMemberships(aCircuit.AgentID, aCircuit.AgentID);
            }

            IOfflineMessagesConnector offlineMessConn =
                Framework.Utilities.DataManager.RequestPlugin<IOfflineMessagesConnector>();

            if (offlineMessConn != null)
                info.OfflineMessages = offlineMessConn.GetOfflineMessages(aCircuit.AgentID);

            IMuteListConnector muteConn = Framework.Utilities.DataManager.RequestPlugin<IMuteListConnector>();

            if (muteConn != null)
                info.MuteList = muteConn.GetMuteList(aCircuit.AgentID);

            IAvatarService avatarService = m_registry.RequestModuleInterface<IAvatarService>();

            if (avatarService != null)
                info.Appearance = avatarService.GetAppearance(aCircuit.AgentID);

            info.FriendOnlineStatuses = friendsToInform;
            IFriendsService friendsService = m_registry.RequestModuleInterface<IFriendsService>();

            if (friendsService != null)
                info.Friends = friendsService.GetFriends(aCircuit.AgentID);

            aCircuit.CachedUserInfo = info;
            return SimulationService.CreateAgent(region, aCircuit, aCircuit.TeleportFlags, out response);
        }