Exemplo n.º 1
0
        private bool ConvertAndUploadMaptile(IScene scene, Image tileImage, uint locX, uint locY, string regionName)
        {
            byte[] jpgData = Utils.EmptyBytes;

            using (MemoryStream stream = new MemoryStream())
            {
                tileImage.Save(stream, ImageFormat.Jpeg);
                jpgData = stream.ToArray();
            }

            if (jpgData == Utils.EmptyBytes)
            {
                m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, regionName);
                return(false);
            }

            string reason = string.Empty;

            if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, scene.RegionInfo.ScopeID, out reason))
            {
                m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
                                  regionName, locX, locY, reason);
                return(false);
            }
            return(true);
        }
        public override byte[] Handle(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."));
                }
                int x = 0, y = 0;
                Int32.TryParse(request["X"].ToString(), out x);
                Int32.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();

                byte[] data = Convert.FromBase64String(request["DATA"].ToString());

                string reason = string.Empty;
                bool   result = m_MapService.AddMapTile(x, 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"));
        }
Exemplo n.º 3
0
        ///<summary>
        ///
        ///</summary>
        private void UploadMapTile(IScene scene)
        {
            m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: upload maptile for {0}", scene.RegionInfo.RegionName);

            // Create a JPG map tile and upload it to the AddMapTile API
            byte[]             jpgData       = Utils.EmptyBytes;
            IMapImageGenerator tileGenerator = scene.RequestModuleInterface <IMapImageGenerator>();

            if (tileGenerator == null)
            {
                m_log.Warn("[MAP IMAGE SERVICE MODULE]: Cannot upload PNG map tile without an ImageGenerator");
                return;
            }

            using (Image mapTile = tileGenerator.CreateMapTile())
            {
                // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there
                // is no static map tile.
                if (mapTile == null)
                {
                    return;
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    mapTile.Save(stream, ImageFormat.Jpeg);
                    jpgData = stream.ToArray();
                }
            }

            if (jpgData == Utils.EmptyBytes)
            {
                m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Tile image generation failed");
                return;
            }

            string reason = string.Empty;

            if (!m_MapService.AddMapTile((int)scene.RegionInfo.RegionLocX, (int)scene.RegionInfo.RegionLocY, jpgData, out reason))
            {
                m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}",
                                  scene.RegionInfo.RegionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, reason);
            }
        }
        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"));
        }
Exemplo n.º 5
0
        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");
        }