* Adds additional background layer for VWoHTTP ClientStack

* Implements asset handling.
0.6.5-rc1
Adam Frisby 2009-04-23 04:51:29 +00:00
parent bd8e4a8892
commit 2af4ca44a6
3 changed files with 111 additions and 13 deletions

View File

@ -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
}
}

View File

@ -13,17 +13,21 @@ namespace OpenSim.Client.VWoHTTP
{
class VWoHTTPModule : IRegionModule, IHttpAgentHandler
{
private bool m_disabled = true;
private IHttpServer m_httpd;
private readonly List<Scene> m_scenes = new List<Scene>();
//private Dictionary<UUID, VWHClientView> m_clients = new Dictionary<UUID, VWHClientView>();
private Dictionary<UUID, VWHClientView> m_clients = new Dictionary<UUID, VWHClientView>();
#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)
{
string[] urlparts = req.Url.AbsolutePath.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
return false;
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)

View File

@ -1830,6 +1830,7 @@
<Reference name="OpenMetaverseTypes.dll"/>
<Reference name="OpenMetaverse.dll"/>
<Reference name="System"/>
<Reference name="System.Drawing"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Region.Framework"/>