From 2af4ca44a62d00026515635efb073d3d6877b804 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 23 Apr 2009 04:51:29 +0000 Subject: * Adds additional background layer for VWoHTTP ClientStack * Implements asset handling. --- .../Client/VWoHTTP/ClientStack/VWHClientView.cs | 80 +++++++++++++++++++--- OpenSim/Client/VWoHTTP/VWoHTTPModule.cs | 43 +++++++++++- 2 files changed, 110 insertions(+), 13 deletions(-) (limited to 'OpenSim/Client') diff --git a/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs b/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs index bf622c6..70b7d6c 100644 --- a/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs +++ b/OpenSim/Client/VWoHTTP/ClientStack/VWHClientView.cs @@ -1,8 +1,12 @@ using System; using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; using System.Net; using System.Text; using OpenMetaverse; +using OpenMetaverse.Imaging; using OpenMetaverse.Packets; using OpenSim.Framework; using OpenSim.Framework.Servers; @@ -12,21 +16,79 @@ namespace OpenSim.Client.VWoHTTP.ClientStack { class VWHClientView : IClientAPI { -// private Scene m_scene; + private Scene m_scene; - public void ProcessInMsg(OSHttpRequest req, OSHttpResponse resp) + + public bool ProcessInMsg(OSHttpRequest req, OSHttpResponse resp) { -// string method = req.Url.AbsolutePath.Split('/')[2]; + // 0 1 2 3 + // http://simulator.com:9000/vwohttp/sessionid/methodname/param + string[] urlparts = req.Url.AbsolutePath.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries); + + UUID sessionID; + // Check for session + if (!UUID.TryParse(urlparts[1], out sessionID)) + return false; + // Check we match session + if(sessionID != SessionId) + return false; + + string method = urlparts[2]; + + string param = String.Empty; + if (urlparts.Length > 3) + param = urlparts[3]; + + bool found; + + switch (method.ToLower()) + { + case "textures": + found = ProcessTextureRequest(param, resp); + break; + default: + found = false; + break; + } + + return found; } -// private void ProcessAssetRequest(OSHttpRequest req, OSHttpResponse resp) -// { -// -// } + private bool ProcessTextureRequest(string param, OSHttpResponse resp) + { + UUID assetID; + if(!UUID.TryParse(param, out assetID)) + return false; + + AssetBase asset = m_scene.CommsManager.AssetCache.GetAsset(assetID, true); + + if(asset == null) + return false; + + ManagedImage tmp; + Image imgData; + + OpenJPEG.DecodeToImage(asset.Data, out tmp, out imgData); + + MemoryStream ms = new MemoryStream(); + + imgData.Save(ms, ImageFormat.Jpeg); + + byte[] jpegdata = ms.GetBuffer(); + + ms.Close(); + + resp.ContentType = "image/jpeg"; + resp.ContentLength = jpegdata.Length; + resp.StatusCode = 200; + resp.Body.Write(jpegdata, 0, jpegdata.Length); + + return true; + } public VWHClientView(UUID sessionID, UUID agentID, string agentName, Scene scene) { -// m_scene = scene; + m_scene = scene; } #region Implementation of IClientAPI @@ -1031,8 +1093,6 @@ namespace OpenSim.Client.VWoHTTP.ClientStack throw new System.NotImplementedException(); } - public event PlacesQuery OnPlacesQuery; - #endregion } } diff --git a/OpenSim/Client/VWoHTTP/VWoHTTPModule.cs b/OpenSim/Client/VWoHTTP/VWoHTTPModule.cs index 451bf1e..c5b5c09 100644 --- a/OpenSim/Client/VWoHTTP/VWoHTTPModule.cs +++ b/OpenSim/Client/VWoHTTP/VWoHTTPModule.cs @@ -13,17 +13,21 @@ namespace OpenSim.Client.VWoHTTP { class VWoHTTPModule : IRegionModule, IHttpAgentHandler { + private bool m_disabled = true; private IHttpServer m_httpd; private readonly List m_scenes = new List(); - //private Dictionary m_clients = new Dictionary(); + private Dictionary m_clients = new Dictionary(); #region Implementation of IRegionModule public void Initialise(Scene scene, IConfigSource source) { + if(m_disabled) + return; + m_scenes.Add(scene); m_httpd = scene.CommsManager.HttpServer; @@ -31,11 +35,17 @@ namespace OpenSim.Client.VWoHTTP public void PostInitialise() { + if (m_disabled) + return; + m_httpd.AddAgentHandler("vwohttp", this); } public void Close() { + if (m_disabled) + return; + m_httpd.RemoveAgentHandler("vwohttp", this); } @@ -55,8 +65,35 @@ namespace OpenSim.Client.VWoHTTP public bool Handle(OSHttpRequest req, OSHttpResponse resp) { - - return false; + string[] urlparts = req.Url.AbsolutePath.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries); + + if (urlparts.Length < 2) + return false; + + if (urlparts[1] == "connect") + { + UUID sessID = UUID.Random(); + + VWHClientView client = new VWHClientView(sessID, UUID.Random(), "VWoHTTPClient", m_scenes[0]); + + m_clients.Add(sessID, client); + + return true; + } + else + { + if (urlparts.Length < 3) + return false; + + UUID sessionID; + if (!UUID.TryParse(urlparts[1], out sessionID)) + return false; + + if (!m_clients.ContainsKey(sessionID)) + return false; + + return m_clients[sessionID].ProcessInMsg(req, resp); + } } public bool Match(OSHttpRequest req, OSHttpResponse resp) -- cgit v1.1