private byte[] GetRegionByPosition(Dictionary <string, object> request) { UUID scopeID = UUID.Zero; if (request.ContainsKey("SCOPEID")) { UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); } else { MainConsole.Instance.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position"); } int x = 0, y = 0; if (request.ContainsKey("X")) { Int32.TryParse(request["X"].ToString(), out x); } else { MainConsole.Instance.WarnFormat("[GRID HANDLER]: no X in request to get region by position"); } if (request.ContainsKey("Y")) { Int32.TryParse(request["Y"].ToString(), out y); } else { MainConsole.Instance.WarnFormat("[GRID HANDLER]: no Y in request to get region by position"); } GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); rinfo = CleanRegion(rinfo); //MainConsole.Instance.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); Dictionary <string, object> result = new Dictionary <string, object>(); if (rinfo == null) { result["result"] = "null"; } else { result["result"] = rinfo.ToKVP(); } string xmlString = WebUtils.BuildXmlResponse(result); //MainConsole.Instance.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); return(encoding.GetBytes(xmlString)); }
// Get a region given its base world coordinates (in meters). // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. // The coordinates are world coords (meters), NOT region units. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo != null) { // m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Found region {0} on local. Pos=<{1},{2}>, RegionHandle={3}", // rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, rinfo.RegionHandle); return(rinfo); } rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) { // uint regionX = Util.WorldToRegionLoc((uint)x); // uint regionY = Util.WorldToRegionLoc((uint)y); // m_log.WarnFormat("[REMOTE GRID CONNECTOR]: Requested region {0}-{1} not found", regionX, regionY); } else { m_RegionInfoCache.Cache(scopeID, rinfo); // m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", // rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, rinfo.RegionHandle); } return(rinfo); }
public override GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) { rinfo = base.GetRegionByPosition(scopeID, x, y); } return(rinfo); }
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion r = m_localService.GetRegionByPosition(scopeID, x, y); if (r == null) { r = (GridRegion)DoRemoteForced(scopeID, x, y); UpdateGridRegionForIWC(ref r); } return(r); }
// Get a region given its base coordinates. // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion region = null; uint regionX = Util.WorldToRegionLoc((uint)x); uint regionY = Util.WorldToRegionLoc((uint)y); // Sanity check if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y)) { m_log.WarnFormat("{0} GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{1},{2}>, Should Be=<{3},{4}>", LogHeader, x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY)); } // First see if it's a neighbour, even if it isn't on this sim. // Neighbour data is cached in memory, so this is fast lock (m_LocalCache) { foreach (RegionCache rcache in m_LocalCache.Values) { region = rcache.GetRegionByPosition(x, y); if (region != null) { m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache (of region {2}). Pos=<{3},{4}>", LogHeader, region.RegionName, rcache.RegionName, Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY)); break; } } } // Then try on this sim (may be a lookup in DB if this is using MySql). if (region == null) { region = m_GridService.GetRegionByPosition(scopeID, x, y); if (region == null) { m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>", LogHeader, regionX, regionY); } else { m_log.DebugFormat("{0} GetRegionByPosition. Got region {1} from grid service. Pos=<{2},{3}>", LogHeader, region.RegionName, Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY)); } } return(region); }
byte[] GetRegionByPosition(Dictionary <string, object> request) { UUID scopeID = UUID.Zero; if (request.ContainsKey("SCOPEID")) { UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); } else { m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position"); } int x = 0, y = 0; if (request.ContainsKey("X")) { Int32.TryParse(request["X"].ToString(), out x); } else { m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position"); } if (request.ContainsKey("Y")) { Int32.TryParse(request["Y"].ToString(), out y); } else { m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position"); } // m_log.DebugFormat("{0} GetRegionByPosition: loc=<{1},{2}>", LogHeader, x, y); GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); Dictionary <string, object> result = new Dictionary <string, object>(); if (rinfo == null) { result["result"] = "null"; } else { result["result"] = rinfo.ToKeyValuePairs(); } string xmlString = ServerUtils.BuildXmlResponse(result); //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); return(Util.UTF8NoBomEncoding.GetBytes(xmlString)); }
// Get a region given its base coordinates. // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { bool inCache = false; GridRegion rinfo = m_RegionInfoCache.Get(scopeID, (uint)x, (uint)y, out inCache); if (inCache) return rinfo; // Then try on this sim (may be a lookup in DB if this is using MySql). rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); if(rinfo != null) m_RegionInfoCache.Cache(scopeID, rinfo); return rinfo; }
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion region = null; // First see if it's a neighbour, even if it isn't on this sim. // Neighbour data is cached in memory, so this is fast foreach (RegionCache rcache in m_LocalCache.Values) { region = rcache.GetRegionByPosition(x, y); if (region != null) { return(region); } } // Then try on this sim (may be a lookup in DB if this is using MySql). return(m_GridService.GetRegionByPosition(scopeID, x, y)); }
// Get a region given its base coordinates. // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion region = null; // uint regionX = Util.WorldToRegionLoc((uint)x); // uint regionY = Util.WorldToRegionLoc((uint)y); // First see if it's a neighbour, even if it isn't on this sim. // Neighbour data is cached in memory, so this is fast lock (m_LocalCache) { foreach (RegionCache rcache in m_LocalCache.Values) { region = rcache.GetRegionByPosition(x, y); if (region != null) { // m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache. Pos=<{2},{3}>", // LogHeader, region.RegionName, x, y); break; } } } // Then try on this sim (may be a lookup in DB if this is using MySql). if (region == null) { region = m_GridService.GetRegionByPosition(scopeID, x, y); /* * if (region == null) * { * m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>", * LogHeader, regionX, regionY); * } * else * { * m_log.DebugFormat("{0} GetRegionByPosition. Requested region {1} from grid service. Pos=<{2},{3}>", * LogHeader, region.RegionName, regionX, regionY); * } */ } return(region); }
// Get a region given its base world coordinates (in meters). // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. // The coordinates are world coords (meters), NOT region units. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { bool inCache = false; GridRegion rinfo = m_RegionInfoCache.Get(scopeID, Util.RegionWorldLocToHandle((uint)x, (uint)y), out inCache); if (inCache) { return(rinfo); } rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) { rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); } m_RegionInfoCache.Cache(rinfo); return(rinfo); }
// Get a region given its base coordinates. // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { GridRegion region = null; // First see if it's a neighbour, even if it isn't on this sim. // Neighbour data is cached in memory, so this is fast try { m_LocalCache.ForEach(delegate(RegionCache rcache) { region = rcache.GetRegionByPosition(x, y); if (region != null) { // m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache. Pos=<{2},{3}>", // LogHeader, region.RegionName, x, y); throw new ThreadedClasses.ReturnValueException <GridRegion>(region); } }); } catch (ThreadedClasses.ReturnValueException <GridRegion> e) { region = e.Value; } // Then try on this sim (may be a lookup in DB if this is using MySql). if (region == null) { region = m_GridService.GetRegionByPosition(scopeID, x, y); /* * if (region == null) * m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>", * LogHeader, x, y); * else * m_log.DebugFormat("{0} GetRegionByPosition. Requested region {1} from grid service. Pos=<{2},{3}>", * LogHeader, region.RegionName, x, y); */ } return(region); }
protected void ShowUsers(string module, string[] cmd) { //Check for all or full to show child agents bool showChildAgents = cmd.Length == 3 ? cmd[2] == "all" ? true : cmd[2] == "full" ? true : false : false; foreach (IRegionCapsService regionCaps in m_RegionCapsServices.Values) { foreach (IRegionClientCapsService clientCaps in regionCaps.GetClients()) { if ((clientCaps.RootAgent || showChildAgents)) { IGridService gridService = m_registry.RequestModuleInterface <IGridService>(); uint x, y; Utils.LongToUInts(regionCaps.RegionHandle, out x, out y); GridRegion region = gridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); UserAccount account = m_registry.RequestModuleInterface <IUserAccountService>().GetUserAccount(UUID.Zero, clientCaps.AgentID); m_log.InfoFormat("Region - {0}, User {1}, {2}, {3}", region.RegionName, account.Name, clientCaps.RootAgent ? "Root Agent" : "Child Agent", clientCaps.Disabled ? "Disabled" : "Not Disabled"); } } } }
public virtual GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) { uint x = 0, y = 0; Utils.LongToUInts(regionHandle, out x, out y); GridRegion regInfo = m_GridService.GetRegionByPosition(thisRegion.ScopeID, (int)x, (int)y); if ((regInfo != null) && // Don't remote-call this instance; that's a startup hickup !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) { if (!DoHelloNeighbourCall(regInfo, thisRegion)) { return(null); } } else { return(null); } return(regInfo); }
// Get a region given its base world coordinates (in meters). // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST // be the base coordinate of the region. // The coordinates are world coords (meters), NOT region units. public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y); uint regionX = Util.WorldToRegionLoc((uint)x); uint regionY = Util.WorldToRegionLoc((uint)y); /* this is no longer valid * // Sanity check * if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y)) * { * m_log.WarnFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{0},{1}>, Should Be=<{2},{3}>", * x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY)); * } */ bool inCache = false; GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache); if (inCache) { // m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Found region {0} in cache. Pos=<{1},{2}>, RegionHandle={3}", // (rinfo == null) ? "<missing>" : rinfo.RegionName, regionX, regionY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); return(rinfo); } rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); if (rinfo == null) { rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y); } m_RegionInfoCache.Cache(rinfo); m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", (rinfo == null) ? "<missing>" : rinfo.RegionName, regionX, regionY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); return(rinfo); }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path); string body; using (StreamReader sr = new StreamReader(requestData)) body = sr.ReadToEnd(); body = body.Trim(); try { Dictionary <string, object> request = ServerUtils.ParseQueryString(body); if (!request.ContainsKey("X") || !request.ContainsKey("Y")) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; return(FailureResult("Bad request.")); } int x = 0, y = 0; Int32.TryParse(request["X"].ToString(), out x); Int32.TryParse(request["Y"].ToString(), out y); // UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992"); UUID scopeID = UUID.Zero; if (request.ContainsKey("SCOPE")) { UUID.TryParse(request["SCOPE"].ToString(), out scopeID); } m_log.DebugFormat("[MAP REMOVE SERVER CONNECTOR]: Received position data for region at {0}-{1}", x, y); if (m_GridService != null) { System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y)); if (r != null) { if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) { m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address); return(FailureResult("IP address of caller does not match IP address of registered region")); } } else { m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}", ipAddr, x, y); return(FailureResult("Region not found at given coordinates")); } } string reason = string.Empty; bool result = m_MapService.RemoveMapTile(x, y, scopeID, out reason); if (result) { return(SuccessResult()); } else { return(FailureResult(reason)); } } catch (Exception e) { m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace); } return(FailureResult("Unexpected server error")); }
protected OSDMap OnMessageReceived(OSDMap message) { if (!message.ContainsKey("Method")) { return(null); } UUID AgentID = message["AgentID"].AsUUID(); ulong requestingRegion = message["RequestingRegion"].AsULong(); ICapsService capsService = m_registry.RequestModuleInterface <ICapsService>(); if (capsService == null) { //m_log.Info("[AgentProcessing]: Failed OnMessageReceived ICapsService is null"); return(new OSDMap()); } IClientCapsService clientCaps = capsService.GetClientCapsService(AgentID); IRegionClientCapsService regionCaps = null; if (clientCaps != null) { regionCaps = clientCaps.GetCapsService(requestingRegion); } if (message["Method"] == "LogoutRegionAgents") { LogOutAllAgentsForRegion(requestingRegion); } else if (message["Method"] == "RegionIsOnline") //This gets fired when the scene is fully finished starting up { //Log out all the agents first, then add any child agents that should be in this region LogOutAllAgentsForRegion(requestingRegion); IGridService GridService = m_registry.RequestModuleInterface <IGridService>(); if (GridService != null) { int x, y; Util.UlongToInts(requestingRegion, out x, out y); GridRegion requestingGridRegion = GridService.GetRegionByPosition(UUID.Zero, x, y); if (requestingGridRegion != null) { EnableChildAgentsForRegion(requestingGridRegion); } } } else if (message["Method"] == "DisableSimulator") { //KILL IT! if (regionCaps == null || clientCaps == null) { return(null); } regionCaps.Close(); clientCaps.RemoveCAPS(requestingRegion); } else if (message["Method"] == "ArrivedAtDestination") { if (regionCaps == null || clientCaps == null) { return(null); } //Recieved a callback if (clientCaps.InTeleport) //Only set this if we are in a teleport, // otherwise (such as on login), this won't check after the first tp! { clientCaps.CallbackHasCome = true; } regionCaps.Disabled = false; //The agent is getting here for the first time (eg. login) OSDMap body = ((OSDMap)message["Message"]); //Parse the OSDMap int DrawDistance = body["DrawDistance"].AsInteger(); AgentCircuitData circuitData = new AgentCircuitData(); circuitData.UnpackAgentCircuitData((OSDMap)body["Circuit"]); //Now do the creation EnableChildAgents(AgentID, requestingRegion, DrawDistance, circuitData); } else if (message["Method"] == "CancelTeleport") { if (regionCaps == null || clientCaps == null) { return(null); } //Only the region the client is root in can do this IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService(); if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle) { //The user has requested to cancel the teleport, stop them. clientCaps.RequestToCancelTeleport = true; regionCaps.Disabled = false; } } else if (message["Method"] == "AgentLoggedOut") { //ONLY if the agent is root do we even consider it if (regionCaps != null) { if (regionCaps.RootAgent) { LogoutAgent(regionCaps); } } } else if (message["Method"] == "SendChildAgentUpdate") { if (regionCaps == null || clientCaps == null) { return(null); } IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService(); if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle) { OSDMap body = ((OSDMap)message["Message"]); AgentPosition pos = new AgentPosition(); pos.Unpack((OSDMap)body["AgentPos"]); SendChildAgentUpdate(pos, regionCaps); regionCaps.Disabled = false; } } else if (message["Method"] == "TeleportAgent") { if (regionCaps == null || clientCaps == null) { return(null); } IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService(); if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle) { OSDMap body = ((OSDMap)message["Message"]); GridRegion destination = new GridRegion(); destination.FromOSD((OSDMap)body["Region"]); uint TeleportFlags = body["TeleportFlags"].AsUInteger(); int DrawDistance = body["DrawDistance"].AsInteger(); AgentCircuitData Circuit = new AgentCircuitData(); Circuit.UnpackAgentCircuitData((OSDMap)body["Circuit"]); AgentData AgentData = new AgentData(); AgentData.Unpack((OSDMap)body["AgentData"]); regionCaps.Disabled = false; OSDMap result = new OSDMap(); string reason = ""; result["Success"] = TeleportAgent(destination, TeleportFlags, DrawDistance, Circuit, AgentData, AgentID, requestingRegion, out reason); result["Reason"] = reason; return(result); } } else if (message["Method"] == "CrossAgent") { if (regionCaps == null || clientCaps == null) { return(null); } if (clientCaps.GetRootCapsService().RegionHandle == regionCaps.RegionHandle) { //This is a simulator message that tells us to cross the agent OSDMap body = ((OSDMap)message["Message"]); Vector3 pos = body["Pos"].AsVector3(); Vector3 Vel = body["Vel"].AsVector3(); GridRegion Region = new GridRegion(); Region.FromOSD((OSDMap)body["Region"]); AgentCircuitData Circuit = new AgentCircuitData(); Circuit.UnpackAgentCircuitData((OSDMap)body["Circuit"]); AgentData AgentData = new AgentData(); AgentData.Unpack((OSDMap)body["AgentData"]); regionCaps.Disabled = false; OSDMap result = new OSDMap(); string reason = ""; result["Success"] = CrossAgent(Region, pos, Vel, Circuit, AgentData, AgentID, requestingRegion, out reason); result["Reason"] = reason; return(result); } } return(null); }
protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { //m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path); string body; using (StreamReader sr = new StreamReader(httpRequest.InputStream)) body = sr.ReadToEnd(); body = body.Trim(); httpRequest.InputStream.Dispose(); try { Dictionary <string, object> request = ServerUtils.ParseQueryString(body); httpResponse.StatusCode = (int)HttpStatusCode.OK; if (!request.ContainsKey("X") || !request.ContainsKey("Y") || !request.ContainsKey("DATA")) { httpResponse.RawBuffer = Util.ResultFailureMessage("Bad request."); return; } int x = 0, y = 0; //UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992"); UUID scopeID = UUID.Zero; Int32.TryParse(request["X"].ToString(), out x); Int32.TryParse(request["Y"].ToString(), out y); if (request.ContainsKey("SCOPE")) { UUID.TryParse(request["SCOPE"].ToString(), out scopeID); } m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); //string type = "image/jpeg"; //if (request.ContainsKey("TYPE")) // type = request["TYPE"].ToString(); if (m_GridService != null) { IPAddress ipAddr = httpRequest.RemoteIPEndPoint.Address; GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y)); if (r != null) { if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) { m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address); httpResponse.RawBuffer = Util.ResultFailureMessage("IP address of caller does not match IP address of registered region"); } } else { m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}", ipAddr, x, y); httpResponse.RawBuffer = Util.ResultFailureMessage("Region not found at given coordinates"); } } byte[] data = Convert.FromBase64String(request["DATA"].ToString()); bool result = m_MapService.AddMapTile(x, y, data, scopeID, out string reason); if (result) { httpResponse.RawBuffer = Util.sucessResultSuccess; } else { httpResponse.RawBuffer = Util.ResultFailureMessage(reason); } return; } catch (Exception e) { m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace); } httpResponse.RawBuffer = Util.ResultFailureMessage("Unexpected server error"); }
protected override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path); StreamReader sr = new StreamReader(requestData); string body = sr.ReadToEnd(); sr.Close(); body = body.Trim(); try { Dictionary <string, object> request = ServerUtils.ParseQueryString(body); if (!request.ContainsKey("X") || !request.ContainsKey("Y") || !request.ContainsKey("DATA")) { httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; return(FailureResult("Bad request.")); } uint x = 0, y = 0; UInt32.TryParse(request["X"].ToString(), out x); UInt32.TryParse(request["Y"].ToString(), out y); m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); // string type = "image/jpeg"; // // if (request.ContainsKey("TYPE")) // type = request["TYPE"].ToString(); if (m_GridService != null) { System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y)); if (r != null) { if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) { m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address); return(FailureResult("IP address of caller does not match IP address of registered region")); } } else { m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}", ipAddr, x, y); return(FailureResult("Region not found at given coordinates")); } } byte[] data = Convert.FromBase64String(request["DATA"].ToString()); string reason = string.Empty; bool result = m_MapService.AddMapTile((int)x, (int)y, data, out reason); if (result) { return(SuccessResult()); } else { return(FailureResult(reason)); } } catch (Exception e) { m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace); } return(FailureResult("Unexpected server error")); }
public byte [] MapAPIRequest(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { byte [] response = MainServer.BlankResponse; var resp = "var {0} = {{regionName:\"{1}\",xloc:\"{2}\",yloc:\"{3}\",xsize:\"{4}\",ysize:\"{5}\"}};"; var varName = httpRequest.Query ["var"].ToString(); var requestType = path.Substring(0, path.IndexOf("?", StringComparison.Ordinal)); if (requestType == "/MapAPI/get-region-coords-by-name") { string sim_name = httpRequest.Query ["sim_name"].ToString(); var region = m_gridService.GetRegionByName(null, sim_name); if (region == null) { resp = "var " + varName + "={error: true};"; } else { resp = string.Format(resp, varName, region.RegionName, region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize, region.RegionSizeX, region.RegionSizeY); } response = System.Text.Encoding.UTF8.GetBytes(resp); httpResponse.ContentType = "text/javascript"; } else if (requestType == "/MapAPI/get-region-name-by-coords") { int grid_x = int.Parse(httpRequest.Query ["grid_x"].ToString()); int grid_y = int.Parse(httpRequest.Query ["grid_y"].ToString()); var region = m_gridService.GetRegionByPosition(null, grid_x * Constants.RegionSize, grid_y * Constants.RegionSize); if (region == null) { var maxRegionSize = m_gridService.GetMaxRegionSize(); List <GridRegion> regions = m_gridService.GetRegionRange(null, (grid_x * Constants.RegionSize) - maxRegionSize, (grid_x * Constants.RegionSize) + maxRegionSize, (grid_y * Constants.RegionSize) - maxRegionSize, (grid_y * Constants.RegionSize) + maxRegionSize); bool found = false; foreach (var r in regions) { if (r.PointIsInRegion(grid_x * Constants.RegionSize, grid_y * Constants.RegionSize)) { resp = string.Format(resp, varName, r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize, r.RegionSizeX, r.RegionSizeY); found = true; break; } } if (!found) { resp = "var " + varName + "={error: true};"; } } else { resp = string.Format(resp, varName, region.RegionName, region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize, region.RegionSizeX, region.RegionSizeY); } response = System.Text.Encoding.UTF8.GetBytes(resp); httpResponse.ContentType = "text/javascript"; } return(response); }
public byte[] MapAPIRequest(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { byte[] response = MainServer.BlankResponse; string var = httpRequest.Query["var"].ToString(); string requestType = path.Substring(0, path.IndexOf("?")); if (requestType == "/MapAPI/get-region-coords-by-name") { string resp = "var {0} = {\"x\":{1},\"y\":{2}};"; string sim_name = httpRequest.Query["sim_name"].ToString(); var region = m_gridService.GetRegionByName(null, sim_name); if (region == null) { resp = "var " + var + " = {error: true};"; } else { resp = "var " + var + " = {\"x\":" + region.RegionLocX + ",\"y\":" + region.RegionLocY + "};"; } response = System.Text.Encoding.UTF8.GetBytes(resp); httpResponse.ContentType = "text/javascript"; } else if (requestType == "/MapAPI/get-region-name-by-coords") { string resp = "var {0} = \"{1}\";"; int grid_x = int.Parse(httpRequest.Query["grid_x"].ToString()); int grid_y = int.Parse(httpRequest.Query["grid_y"].ToString()); var region = m_gridService.GetRegionByPosition(null, grid_x * Constants.RegionSize, grid_y * Constants.RegionSize); if (region == null) { List <GridRegion> regions = m_gridService.GetRegionRange(null, (grid_x * Constants.RegionSize) - (m_gridService.GetMaxRegionSize()), (grid_x * Constants.RegionSize), (grid_y * Constants.RegionSize) - (m_gridService.GetMaxRegionSize()), (grid_y * Constants.RegionSize)); bool found = false; foreach (var r in regions) { if (r.PointIsInRegion(grid_x * Constants.RegionSize, grid_y * Constants.RegionSize)) { resp = string.Format(resp, var, r.RegionName); found = true; break; } } if (!found) { resp = "var " + var + " = {error: true};"; } } else { resp = string.Format(resp, var, region.RegionName); } response = System.Text.Encoding.UTF8.GetBytes(resp); httpResponse.ContentType = "text/javascript"; } return(response); }
public bool TryCreateLink(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason) { MainConsole.Instance.DebugFormat("[HYPERGRID LINKER]: Link to {0} {1}, in {2}-{3}", ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI), remoteRegionName, xloc / Constants.RegionSize, yloc / Constants.RegionSize); reason = string.Empty; Uri uri = null; regInfo = new GridRegion(); if (externalPort > 0) { regInfo.HttpPort = externalPort; } else { regInfo.HttpPort = 0; } if (externalHostName != null) { regInfo.ExternalHostName = externalHostName; } else { regInfo.ExternalHostName = "0.0.0.0"; } if (serverURI != null) { regInfo.ServerURI = serverURI; try { uri = new Uri(serverURI); regInfo.ExternalHostName = uri.Host; regInfo.HttpPort = (uint)uri.Port; } catch { } } if (!string.IsNullOrEmpty(remoteRegionName)) { regInfo.RegionName = remoteRegionName; } regInfo.RegionLocX = xloc; regInfo.RegionLocY = yloc; regInfo.ScopeID = scopeID; regInfo.EstateOwner = ownerID; // Make sure we're not hyperlinking to regions on this grid! if (m_ThisGatekeeperURI != null) { if (regInfo.ExternalHostName == m_ThisGatekeeperURI.Host && regInfo.HttpPort == m_ThisGatekeeperURI.Port) { reason = "Cannot hyperlink to regions on the same grid"; return(false); } } else { MainConsole.Instance.WarnFormat("[HYPERGRID LINKER]: Please set this grid's Gatekeeper's address in [GridService]!"); } // Check for free coordinates GridRegion region = m_GridService.GetRegionByPosition(null, regInfo.RegionLocX, regInfo.RegionLocY); if (region != null) { MainConsole.Instance.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}", regInfo.RegionLocX / Constants.RegionSize, regInfo.RegionLocY / Constants.RegionSize, region.RegionName, region.RegionID); reason = "Coordinates are already in use"; return(false); } try { regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); } catch (Exception e) { MainConsole.Instance.Warn("[HYPERGRID LINKER]: Wrong format for link-region: " + e.Message); reason = "Internal error"; return(false); } // Finally, link it ulong handle = 0; UUID regionID = UUID.Zero; string externalName = string.Empty; string imageURL = string.Empty; if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason)) { return(false); } if (regionID == UUID.Zero) { MainConsole.Instance.Warn("[HYPERGRID LINKER]: Unable to link region"); reason = "Remote region could not be found"; return(false); } region = m_GridService.GetRegionByUUID(null, regionID); if (region != null) { MainConsole.Instance.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize); regInfo = region; return(true); } uint x, y; if (m_Check4096 && !Check4096(handle, out x, out y)) { RemoveHyperlinkRegion(regInfo.RegionID); reason = "Region is too far (" + x + ", " + y + ")"; MainConsole.Instance.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")"); return(false); } regInfo.RegionID = regionID; if (externalName == string.Empty) { regInfo.RegionName = regInfo.ServerURI; } else { regInfo.RegionName = externalName; } MainConsole.Instance.DebugFormat("[HYPERGRID LINKER]: naming linked region {0}, handle {1}", regInfo.RegionName, handle.ToString()); // Get the map image regInfo.TerrainImage = GetMapImage(regionID, imageURL); // Store the origin's coordinates somewhere //TODO: //regInfo.RegionSecret = handle.ToString (); AddHyperlinkRegion(regInfo, handle); MainConsole.Instance.InfoFormat("[HYPERGRID LINKER]: Successfully linked to region {0} with image {1}", regInfo.RegionName, regInfo.TerrainImage); return(true); }
// Given a world position (fractional meter coordinate), get the GridRegion info for // the region containing that point. // Someday this should be a method on GridService. // 'pSizeHint' is the size of the source region but since the destination point can be anywhere // the size of the target region is unknown thus the search area might have to be very large. // Return 'null' if no such region exists. public GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID, double px, double py, uint pSizeHint) { m_log.DebugFormat("{0} GetRegionContainingWorldLocation: query, loc=<{1},{2}>", LogHeader, px, py); GridRegion ret = null; const double fudge = 2.0; // One problem with this routine is negative results. That is, this can be called lots of times // for regions that don't exist. m_notFoundLocationCache remembers 'not found' results so they // will be quick 'not found's next time. // NotFoundLocationCache is an expiring cache so it will eventually forget about 'not found' and // thus re-ask the GridService about the location. if (m_notFoundLocationCache.Contains(px, py)) { m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found via cache. loc=<{1},{2}>", LogHeader, px, py); return null; } // As an optimization, since most regions will be legacy sized regions (256x256), first try to get // the region at the appropriate legacy region location. uint possibleX = (uint)Math.Floor(px); possibleX -= possibleX % Constants.RegionSize; uint possibleY = (uint)Math.Floor(py); possibleY -= possibleY % Constants.RegionSize; ret = pGridService.GetRegionByPosition(pScopeID, (int)possibleX, (int)possibleY); if (ret != null) { m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Found region using legacy size. rloc=<{1},{2}>. Rname={3}", LogHeader, possibleX, possibleY, ret.RegionName); } if (ret == null) { // If the simple lookup failed, search the larger area for a region that contains this point double range = (double)pSizeHint + fudge; while (ret == null && range <= (Constants.MaximumRegionSize + Constants.RegionSize)) { // Get from the grid service a list of regions that might contain this point. // The region origin will be in the zero direction so only subtract the range. List<GridRegion> possibleRegions = pGridService.GetRegionRange(pScopeID, (int)(px - range), (int)(px), (int)(py - range), (int)(py)); m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegions cnt={1}, range={2}", LogHeader, possibleRegions.Count, range); if (possibleRegions != null && possibleRegions.Count > 0) { // If we found some regions, check to see if the point is within foreach (GridRegion gr in possibleRegions) { m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegion nm={1}, regionLoc=<{2},{3}>, regionSize=<{4},{5}>", LogHeader, gr.RegionName, gr.RegionLocX, gr.RegionLocY, gr.RegionSizeX, gr.RegionSizeY); if (px >= (double)gr.RegionLocX && px < (double)(gr.RegionLocX + gr.RegionSizeX) && py >= (double)gr.RegionLocY && py < (double)(gr.RegionLocY + gr.RegionSizeY)) { // Found a region that contains the point ret = gr; m_log.DebugFormat("{0} GetRegionContainingWorldLocation: found. RegionName={1}", LogHeader, ret.RegionName); break; } } } // Larger search area for next time around if not found range *= 2; } } if (ret == null) { // remember this location was not found so we can quickly not find it next time m_notFoundLocationCache.Add(px, py); m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found. Remembering loc=<{1},{2}>", LogHeader, px, py); } return ret; }
public virtual LandData GetLandData(UUID scopeID, ulong regionHandle, uint x, uint y, out byte regionAccess) { LandData landData = null; Hashtable hash = new Hashtable(); hash["region_handle"] = regionHandle.ToString(); hash["x"] = x.ToString(); hash["y"] = y.ToString(); IList paramList = new ArrayList(); paramList.Add(hash); regionAccess = 42; // Default to adult. Better safe... try { uint xpos = 0, ypos = 0; Util.RegionHandleToWorldLoc(regionHandle, out xpos, out ypos); GridRegion info = m_GridService.GetRegionByPosition(scopeID, (int)xpos, (int)ypos); if (info != null) // just to be sure { XmlRpcRequest request = new XmlRpcRequest("land_data", paramList); XmlRpcResponse response = request.Send(info.ServerURI, 10000); if (response.IsFault) { m_log.ErrorFormat("[LAND CONNECTOR]: remote call returned an error: {0}", response.FaultString); } else { hash = (Hashtable)response.Value; try { landData = new LandData(); landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]); landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]); landData.Area = Convert.ToInt32(hash["Area"]); landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]); landData.Description = (string)hash["Description"]; landData.Flags = Convert.ToUInt32(hash["Flags"]); landData.GlobalID = new UUID((string)hash["GlobalID"]); landData.Name = (string)hash["Name"]; landData.OwnerID = new UUID((string)hash["OwnerID"]); landData.SalePrice = Convert.ToInt32(hash["SalePrice"]); landData.SnapshotID = new UUID((string)hash["SnapshotID"]); landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]); if (hash["RegionAccess"] != null) { regionAccess = (byte)Convert.ToInt32((string)hash["RegionAccess"]); } m_log.DebugFormat("[LAND CONNECTOR]: Got land data for parcel {0}", landData.Name); } catch (Exception e) { m_log.ErrorFormat( "[LAND CONNECTOR]: Got exception while parsing land-data: {0} {1}", e.Message, e.StackTrace); } } } else { m_log.WarnFormat("[LAND CONNECTOR]: Couldn't find region with handle {0}", regionHandle); } } catch (Exception e) { m_log.ErrorFormat( "[LAND CONNECTOR]: Couldn't contact region {0}: {1} {2}", regionHandle, e.Message, e.StackTrace); } return(landData); }
public virtual LandData GetLandData(ulong regionHandle, uint x, uint y) { LandData landData = null; Hashtable hash = new Hashtable(); hash["region_handle"] = regionHandle.ToString(); hash["x"] = x.ToString(); hash["y"] = y.ToString(); IList paramList = new ArrayList(); paramList.Add(hash); try { uint xpos = 0, ypos = 0; Utils.LongToUInts(regionHandle, out xpos, out ypos); GridRegion info = m_GridService.GetRegionByPosition(UUID.Zero, (int)xpos, (int)ypos); if (info != null) // just to be sure { XmlRpcRequest request = new XmlRpcRequest("land_data", paramList); string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; XmlRpcResponse response = request.Send(uri, 10000); if (response.IsFault) { m_log.ErrorFormat("[LAND CONNECTOR] remote call returned an error: {0}", response.FaultString); } else { hash = (Hashtable)response.Value; try { landData = new LandData(); landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]); landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]); landData.Area = Convert.ToInt32(hash["Area"]); landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]); landData.Description = (string)hash["Description"]; landData.Flags = Convert.ToUInt32(hash["Flags"]); landData.GlobalID = new UUID((string)hash["GlobalID"]); landData.Name = (string)hash["Name"]; landData.OwnerID = new UUID((string)hash["OwnerID"]); landData.SalePrice = Convert.ToInt32(hash["SalePrice"]); landData.SnapshotID = new UUID((string)hash["SnapshotID"]); landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]); m_log.DebugFormat("[OGS1 GRID SERVICES] Got land data for parcel {0}", landData.Name); } catch (Exception e) { m_log.Error("[LAND CONNECTOR] Got exception while parsing land-data:", e); } } } else { m_log.WarnFormat("[LAND CONNECTOR] Couldn't find region with handle {0}", regionHandle); } } catch (Exception e) { m_log.ErrorFormat("[LAND CONNECTOR] Couldn't contact region {0}: {1}", regionHandle, e); } return(landData); }