From 1407837b668123888b5cc0a4870bacdc44859129 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 25 Sep 2020 03:17:37 +0200 Subject: [PATCH] add new MapGetServiceConnector --- src/NEWMapGetServerConnector.cs | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/NEWMapGetServerConnector.cs diff --git a/src/NEWMapGetServerConnector.cs b/src/NEWMapGetServerConnector.cs new file mode 100644 index 0000000..d883198 --- /dev/null +++ b/src/NEWMapGetServerConnector.cs @@ -0,0 +1,79 @@ +using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Handlers.Base; +using OpenSim.Services.Connectors; +using System; +using System.IO; +using System.Net; +using System.Threading; + +namespace OpenSim.Robust.MapImageClient +{ + class NEWMapGetServerConnector : ServiceConnector + { + private string m_ConfigName = "MapImageService"; + + public NEWMapGetServerConnector(IConfigSource config, IHttpServer server, string configName) : base(config, server, configName) + { + IConfig serverConfig = config.Configs[m_ConfigName]; + if (serverConfig == null) + throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); + + string remoteServer = serverConfig.GetString("RemoteMapServer", String.Empty); + + if (remoteServer == String.Empty) + throw new Exception("No RemoteServer in config file"); + + server.AddStreamHandler(new NEWMapServerGetHandler(remoteServer)); + } + } + + class NEWMapServerGetHandler : BaseStreamHandler + { + public static ManualResetEvent ev = new ManualResetEvent(true); + + private String m_remoteServer = null; + + public NEWMapServerGetHandler(String remoteServer) : base("GET", "/map") + { + m_remoteServer = remoteServer; + } + + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) + { + UUID scopeID = UUID.Zero; + string format = string.Empty; + + IniConfigSource configuration = new IniConfigSource(); + configuration.AddConfig("MapImageService"); + configuration.Configs["MapImageService"].Set("MapImageServerURI", m_remoteServer); + + MapImageServicesConnector mapServiceModule = new MapImageServicesConnector(); + mapServiceModule.Initialise(configuration); + + string[] bits = path.Trim('/').Split(new char[] { '/' }); + + if (bits.Length > 2) + scopeID = UUID.Parse(bits[1]); + + byte[] result = mapServiceModule.GetMapTile(path.Trim('/'), scopeID, out format); + + if (result.Length > 0) + { + httpResponse.StatusCode = (int)HttpStatusCode.OK; + if (format.Equals(".png")) + httpResponse.ContentType = "image/png"; + else if (format.Equals(".jpg") || format.Equals(".jpeg")) + httpResponse.ContentType = "image/jpeg"; + + return result; + } + + httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + httpResponse.ContentType = "text/plain"; + return new byte[0]; + } + } +} +