/** * Agent-related communications */ 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); }
/// <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 var agentAcct = m_scene.UserAccountService.GetUserAccount(null, agent.AgentID); var agentName = (agentAcct != null) ? agentAcct.Name : agent.AgentID.ToString(); 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", agentName, 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}", agentName, scene.RegionInfo.RegionName); // Tell everyone about it scene.WhiteCoreEventManager.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.WhiteCoreEventManager.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", agentName, agent.CircuitCode); response.Success = true; return(true); }
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("[Simulation Service Connector]: 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); if (!response.Success) { return(false); } return(response.Success); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateAgentResponse response = new CreateAgentResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("AgentArn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.AgentArn = unmarshaller.Unmarshall(context); continue; } } return(response); }
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); }