public List <GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
        {
            List <GridRegion> r             = m_localService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
            List <GridRegion> remoteRegions = (List <GridRegion>)DoRemoteForced(scopeID, xmin, xmax, ymin, ymax);

            if (remoteRegions != null)
            {
                UpdateGridRegionsForIWC(ref remoteRegions);
                r.AddRange(remoteRegions);
            }
            return(r);
        }
        /// <summary>
        /// Get all the neighboring regions of the given region
        /// </summary>
        /// <param name="region"></param>
        /// <returns></returns>
        private List <GridRegion> FindNewNeighbors(GridRegion region)
        {
            int startX = (int)(region.RegionLocX - 8192); //Give 8196 by default so that we pick up neighbors next to us
            int startY = (int)(region.RegionLocY - 8192);

            if (m_gridService.MaxRegionSize != 0)
            {
                startX = (int)(region.RegionLocX - m_gridService.MaxRegionSize);
                startY = (int)(region.RegionLocY - m_gridService.MaxRegionSize);
            }

            //-1 so that we don't get size (256) + viewsize (256) and get a region two 256 blocks over
            int endX = (region.RegionLocX + RegionViewSize + region.RegionSizeX - 1);
            int endY = (region.RegionLocY + RegionViewSize + region.RegionSizeY - 1);

            List <GridRegion> neighbors = m_gridService.GetRegionRange(region.ScopeID, startX, endX, startY, endY);

            //If we arn't supposed to close local regions, add all of the scene ones if they are not already there
            if (!CloseLocalRegions)
            {
                foreach (Scene scene in m_Scenes)
                {
                    GridRegion gregion = m_gridService.GetRegionByUUID(scene.RegionInfo.ScopeID, scene.RegionInfo.RegionID);
                    if (!neighbors.Contains(gregion))
                    {
                        neighbors.Add(gregion);
                    }
                }
            }
            neighbors.RemoveAll(delegate(GridRegion r)
            {
                if (r.RegionID == region.RegionID)
                {
                    return(true);
                }

                if (r.RegionLocX + r.RegionSizeX - 1 < (region.RegionLocX - RegionViewSize) ||
                    r.RegionLocY + r.RegionSizeY - 1 < (region.RegionLocY - RegionViewSize)) //Check for regions outside of the boundry (created above when checking for large regions next to us)
                {
                    return(true);
                }

                return(false);
            });
            return(neighbors);
        }
示例#3
0
        public List <GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
        {
            List <GridRegion> r             = m_localService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
            List <GridRegion> remoteRegions = m_remoteService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);

            UpdateGridRegionsForIWC(ref remoteRegions);
            r.AddRange(remoteRegions);
            return(r);
        }
示例#4
0
        /// <summary>
        /// Callback for a map layer request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path"></param>
        /// <param name="param"></param>
        /// <param name="agentID"></param>
        /// <param name="caps"></param>
        /// <returns></returns>
        public string MapLayerRequest(string request, string path, string param,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse, UUID agentID)
        {
            int bottom = (m_service.RegionY / Constants.RegionSize) - 100;
            int top    = (int)(m_service.RegionY / Constants.RegionSize) + 100;
            int left   = (int)(m_service.RegionX / Constants.RegionSize) - 100;
            int right  = (int)(m_service.RegionX / Constants.RegionSize) + 100;

            OSDMap map = (OSDMap)OSDParser.DeserializeLLSDXml(request);

            int flags = map["Flags"].AsInteger();

            OSDArray layerData = new OSDArray();

            layerData.Add(GetOSDMapLayerResponse(bottom, left, right, top, new UUID("00000000-0000-1111-9999-000000000006")));
            OSDArray mapBlocksData = new OSDArray();

            List <MapBlockData> mapBlocks = new List <MapBlockData>();

            if (m_allowCapsMessage)
            {
                if (m_mapLayer != null && m_mapLayer.Count != 0)
                {
                    mapBlocks = m_mapLayer;
                }
                else
                {
                    List <GridRegion> regions = m_gridService.GetRegionRange(UUID.Zero,
                                                                             left * (int)Constants.RegionSize,
                                                                             right * (int)Constants.RegionSize,
                                                                             bottom * (int)Constants.RegionSize,
                                                                             top * (int)Constants.RegionSize);
                    foreach (GridRegion r in regions)
                    {
                        if (flags == 0) //Map
                        {
                            mapBlocks.Add(MapBlockFromGridRegion(r));
                        }
                        else
                        {
                            mapBlocks.Add(TerrainBlockFromGridRegion(r));
                        }
                    }
                    m_mapLayer = mapBlocks;
                }
            }
            foreach (MapBlockData block in m_mapLayer)
            {
                //Add to the array
                mapBlocksData.Add(block.ToOSD());
            }
            OSDMap response = MapLayerResponce(layerData, mapBlocksData, flags);
            string resp     = OSDParser.SerializeLLSDXmlString(response);

            return(resp);
        }
        /// <summary>
        /// Cope with this viewer limitation.
        /// </summary>
        /// <param name="regInfo"></param>
        /// <returns></returns>
        public bool Check4096(ulong realHandle, out uint x, out uint y)
        {
            uint ux = 0, uy = 0;

            Utils.LongToUInts(realHandle, out ux, out uy);
            x = ux / Constants.RegionSize;
            y = uy / Constants.RegionSize;

            const uint limit = (4096 - 1) * Constants.RegionSize;
            uint       xmin  = ux - limit;
            uint       xmax  = ux + limit;
            uint       ymin  = uy - limit;
            uint       ymax  = uy + limit;

            // World map boundary checks
            if (xmin < 0 || xmin > ux)
            {
                xmin = 0;
            }
            if (xmax > int.MaxValue || xmax < ux)
            {
                xmax = int.MaxValue;
            }
            if (ymin < 0 || ymin > uy)
            {
                ymin = 0;
            }
            if (ymax > int.MaxValue || ymax < uy)
            {
                ymax = int.MaxValue;
            }

            // Check for any regions that are within the possible teleport range to the linked region
            List <GridRegion> regions = m_GridService.GetRegionRange(null, (int)xmin, (int)xmax, (int)ymin, (int)ymax);

            if (regions.Count == 0)
            {
                return(false);
            }
            else
            {
                // Check for regions which are not linked regions
                List <GridRegion> hyperlinks = m_Database.Get(Aurora.Framework.RegionFlags.Hyperlink);
                regions.RemoveAll(delegate(GridRegion r)
                {
                    return(hyperlinks.Contains(r));
                });
                if (regions.Count == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
        /// <summary>
        ///     Callback for a map layer request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="httpRequest"></param>
        /// <param name="httpResponse"></param>
        /// <param name="agentID"></param>
        /// <returns></returns>
        public byte[] MapLayerRequest(string request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            int bottom = (m_region.RegionLocY / Constants.RegionSize) - m_mapDistance;
            int top    = (m_region.RegionLocY / Constants.RegionSize) + m_mapDistance;
            int left   = (m_region.RegionLocX / Constants.RegionSize) - m_mapDistance;
            int right  = (m_region.RegionLocX / Constants.RegionSize) + m_mapDistance;

            OSDMap map = (OSDMap)OSDParser.DeserializeLLSDXml(request);

            int flags = map["Flags"].AsInteger();

            OSDArray layerData = new OSDArray
            {
                GetOSDMapLayerResponse(bottom, left, right, top,
                                       new UUID("00000000-0000-1111-9999-000000000006"))
            };
            OSDArray mapBlocksData = new OSDArray();

            if (m_allowCapsMessage)
            {
                if (m_mapLayer == null || m_mapLayer.Count == 0)
                {
                    List <GridRegion> regions = m_gridService.GetRegionRange(
                        m_userScopeIDs,
                        left * Constants.RegionSize,
                        right * Constants.RegionSize,
                        bottom * Constants.RegionSize,
                        top * Constants.RegionSize);
                    foreach (GridRegion r in regions)
                    {
                        m_mapLayer.Add(MapBlockFromGridRegion(r, flags));
                    }
                }
            }
            foreach (MapBlockData block in m_mapLayer)
            {
                //Add to the array
                mapBlocksData.Add(block.ToOSD());
            }
            OSDMap response = MapLayerResponce(layerData, mapBlocksData, flags);

            return(OSDParser.SerializeLLSDXmlBytes(response));
        }
        public virtual List <GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
        {
            List <GridRegion> rinfo = m_LocalGridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
            //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionRange {0} found {1} regions", name, rinfo.Count);
            List <GridRegion> grinfo = m_RemoteGridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);

            if (grinfo != null)
            {
                //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Remote GetRegionRange {0} found {1} regions", name, grinfo.Count);
                foreach (GridRegion r in grinfo)
                {
                    if (rinfo.Find(delegate(GridRegion gr) { return(gr.RegionID == r.RegionID); }) == null)
                    {
                        rinfo.Add(r);
                    }
                }
            }

            return(rinfo);
        }
示例#8
0
        // 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 List <GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
 {
     return(m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax));
 }
示例#10
0
        private Bitmap CreateZoomLevel(uint zoomLevel, uint regionX, uint regionY)
        {
            if (!Directory.Exists(tileCacheDir))
            {
                Directory.CreateDirectory(tileCacheDir);
            }

            zoomLevel += 1;
            uint regionsPerTileEdge = (uint)Math.Pow(2, zoomLevel - 1);

            regionX -= regionX % regionsPerTileEdge;
            regionY -= regionY % regionsPerTileEdge;

            string fileName = Path.Combine(tileCacheDir, (zoomLevel - 1) + "-" + regionX + "-" + regionY + ".jpg");

            if (File.Exists(fileName))
            {
                DateTime lastWritten = File.GetLastWriteTime(fileName);
                if ((DateTime.Now - lastWritten).Minutes < 10) //10 min cache
                {
                    return((Bitmap)Bitmap.FromFile(fileName));
                }
            }

            int        imageSize  = 256;
            Bitmap     mapTexture = new Bitmap(imageSize, imageSize);
            Graphics   g          = Graphics.FromImage(mapTexture);
            Color      seaColor   = Color.FromArgb(29, 71, 95);
            SolidBrush sea        = new SolidBrush(seaColor);

            g.FillRectangle(sea, 0, 0, imageSize, imageSize);

            IGridService gridService = m_registry.RequestModuleInterface <IGridService>();

            if (gridService == null)
            {
                MainConsole.Instance.Error("[" + Name + "] Could not find grid service, cannot generate textures");
                return(mapTexture);
            }

            uint imageX   = regionX * Constants.RegionSize;
            uint imageY   = regionY * Constants.RegionSize;
            uint imageTop = (regionY - regionsPerTileEdge) * Constants.RegionSize;

            float tileCenterX = (regionX + ((float)regionsPerTileEdge / (float)2.0)) * Constants.RegionSize;
            float tileCenterY = (regionY + ((float)regionsPerTileEdge / (float)2.0)) * Constants.RegionSize;

            uint squareRange = (Constants.RegionSize / 2) * regionsPerTileEdge;

            List <GridRegion> regions = gridService.GetRegionRange(UUID.Zero, tileCenterX, tileCenterY, squareRange - 1);

            if (regions.Count == 0)
            {
                return(mapTexture);
            }

            List <Image>      bitImages     = new List <Image>();
            List <FastBitmap> fastbitImages = new List <FastBitmap>();

            foreach (GridRegion r in regions)
            {
                AssetBase texAsset = m_registry.RequestModuleInterface <IAssetService>().Get(r.TerrainImage.ToString());

                if (texAsset != null)
                {
                    ManagedImage managedImage;
                    Image        image;
                    if (OpenJPEG.DecodeToImage(texAsset.Data, out managedImage, out image))
                    {
                        bitImages.Add(image);
                        fastbitImages.Add(new FastBitmap((Bitmap)image));
                    }
                }
            }

            float regionSizeOnImage = (float)imageSize / (float)regionsPerTileEdge;
            float zoomScale         = (imageSize / zoomLevel);

            for (int i = 0; i < regions.Count; i++)
            {
                float width  = (bitImages[i].Width * (regions[i].RegionSizeX / bitImages[i].Width)) * ((float)regionSizeOnImage / (float)Constants.RegionSize);
                float height = (bitImages[i].Height * (regions[i].RegionSizeY / bitImages[i].Height)) * ((float)regionSizeOnImage / (float)Constants.RegionSize);

                float tileFactorWidth  = (float)bitImages[i].Width / (float)regions[i].RegionSizeX;
                float tileFactorHeight = (float)bitImages[i].Height / (float)regions[i].RegionSizeY;

                float posX = ((((float)regions[i].RegionLocX - (float)imageX)) / Constants.RegionSize) * regionSizeOnImage;
                float posY = ((((float)regions[i].RegionLocY - (float)imageY)) / Constants.RegionSize) * regionSizeOnImage;

                g.DrawImage(bitImages[i], posX, imageSize - posY - height, width, height); // y origin is top
            }

            mapTexture.Save(fileName, ImageFormat.Jpeg);

            return(mapTexture);
        }
示例#11
0
        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);
        }
        byte[] GetRegionRange(Dictionary <string, object> request)
        {
            //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
            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 range");
            }

            int xmin = 0, xmax = 0, ymin = 0, ymax = 0;

            if (request.ContainsKey("XMIN"))
            {
                Int32.TryParse(request["XMIN"].ToString(), out xmin);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
            }
            if (request.ContainsKey("XMAX"))
            {
                Int32.TryParse(request["XMAX"].ToString(), out xmax);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
            }
            if (request.ContainsKey("YMIN"))
            {
                Int32.TryParse(request["YMIN"].ToString(), out ymin);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
            }
            if (request.ContainsKey("YMAX"))
            {
                Int32.TryParse(request["YMAX"].ToString(), out ymax);
            }
            else
            {
                m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
            }


            List <GridRegion> rinfos           = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);

            Dictionary <string, object> result = new Dictionary <string, object>();

            if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
            {
                result["result"] = "null";
            }
            else
            {
                int i = 0;
                foreach (GridRegion rinfo in rinfos)
                {
                    Dictionary <string, object> rinfoDict = rinfo.ToKeyValuePairs();
                    result["region" + i] = rinfoDict;
                    i++;
                }
            }
            string xmlString                   = ServerUtils.BuildXmlResponse(result);

            //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
            return(Util.UTF8NoBomEncoding.GetBytes(xmlString));
        }
示例#13
0
        private byte[] GetRegionRange(Dictionary <string, object> request)
        {
            //MainConsole.Instance.DebugFormat("[GRID HANDLER]: GetRegionRange");
            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 range");
            }

            int xmin = 0, xmax = 0, ymin = 0, ymax = 0;

            if (request.ContainsKey("XMIN"))
            {
                Int32.TryParse(request["XMIN"].ToString(), out xmin);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
            }
            if (request.ContainsKey("XMAX"))
            {
                Int32.TryParse(request["XMAX"].ToString(), out xmax);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
            }
            if (request.ContainsKey("YMIN"))
            {
                Int32.TryParse(request["YMIN"].ToString(), out ymin);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
            }
            if (request.ContainsKey("YMAX"))
            {
                Int32.TryParse(request["YMAX"].ToString(), out ymax);
            }
            else
            {
                MainConsole.Instance.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
            }


            List <GridRegion> rinfos           = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);

            rinfos = CleanRegions(rinfos);

            Dictionary <string, object> result = new Dictionary <string, object>();

            if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
            {
                result["result"] = "null";
            }
            else
            {
                int i = 0;
#if (!ISWIN)
                foreach (GridRegion rinfo in rinfos)
                {
                    Dictionary <string, object> rinfoDict = rinfo.ToKVP();
                    result["region" + i] = rinfoDict;
                    i++;
                }
#else
                foreach (Dictionary <string, object> rinfoDict in rinfos.Select(rinfo => rinfo.ToKVP()))
                {
                    result["region" + i] = rinfoDict;
                    i++;
                }
#endif
            }
            string xmlString                   = WebUtils.BuildXmlResponse(result);
            //MainConsole.Instance.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
            UTF8Encoding encoding = new UTF8Encoding();
            return(encoding.GetBytes(xmlString));
        }
示例#14
0
        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);
        }