change MoapModule

master
UbitUmarov 2020-04-27 20:02:10 +01:00
parent 27ea249194
commit 5929e43c2c
2 changed files with 123 additions and 159 deletions

View File

@ -26,11 +26,9 @@
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Net;
using System.Reflection; using System.Reflection;
using System.IO;
using System.Web; using System.Web;
using System.Xml; using System.Xml;
using log4net; using log4net;
@ -40,14 +38,11 @@ using OpenMetaverse;
using OpenMetaverse.Messages.Linden; using OpenMetaverse.Messages.Linden;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Capabilities;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.HttpServer; using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using Caps = OpenSim.Framework.Capabilities.Caps; using Caps = OpenSim.Framework.Capabilities.Caps;
using OSDArray = OpenMetaverse.StructuredData.OSDArray;
using OSDMap = OpenMetaverse.StructuredData.OSDMap; using OSDMap = OpenMetaverse.StructuredData.OSDMap;
namespace OpenSim.Region.CoreModules.World.Media.Moap namespace OpenSim.Region.CoreModules.World.Media.Moap
@ -70,26 +65,6 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
/// </summary> /// </summary>
protected Scene m_scene; protected Scene m_scene;
/// <summary>
/// Track the ObjectMedia capabilities given to users keyed by path
/// </summary>
protected Dictionary<string, UUID> m_omCapUsers = new Dictionary<string, UUID>();
/// <summary>
/// Track the ObjectMedia capabilities given to users keyed by agent. Lock m_omCapUsers to manipulate.
/// </summary>
protected Dictionary<UUID, string> m_omCapUrls = new Dictionary<UUID, string>();
/// <summary>
/// Track the ObjectMediaUpdate capabilities given to users keyed by path
/// </summary>
protected Dictionary<string, UUID> m_omuCapUsers = new Dictionary<string, UUID>();
/// <summary>
/// Track the ObjectMediaUpdate capabilities given to users keyed by agent. Lock m_omuCapUsers to manipulate
/// </summary>
protected Dictionary<UUID, string> m_omuCapUrls = new Dictionary<UUID, string>();
public void Initialise(IConfigSource configSource) public void Initialise(IConfigSource configSource)
{ {
IConfig config = configSource.Configs["MediaOnAPrim"]; IConfig config = configSource.Configs["MediaOnAPrim"];
@ -117,7 +92,6 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
return; return;
m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; m_scene.EventManager.OnRegisterCaps += OnRegisterCaps;
m_scene.EventManager.OnDeregisterCaps += OnDeregisterCaps;
m_scene.EventManager.OnSceneObjectPartCopy += OnSceneObjectPartCopy; m_scene.EventManager.OnSceneObjectPartCopy += OnSceneObjectPartCopy;
} }
@ -127,7 +101,6 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
return; return;
m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps; m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
m_scene.EventManager.OnDeregisterCaps -= OnDeregisterCaps;
m_scene.EventManager.OnSceneObjectPartCopy -= OnSceneObjectPartCopy; m_scene.EventManager.OnSceneObjectPartCopy -= OnSceneObjectPartCopy;
} }
@ -136,50 +109,18 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
// m_log.DebugFormat( // m_log.DebugFormat(
// "[MOAP]: Registering ObjectMedia and ObjectMediaNavigate capabilities for agent {0}", agentID); // "[MOAP]: Registering ObjectMedia and ObjectMediaNavigate capabilities for agent {0}", agentID);
string omCapUrl = "/CAPS/" + UUID.Random();
lock (m_omCapUsers) caps.RegisterSimpleHandler("ObjectMedia",
new SimpleStreamHandler("/" + UUID.Random() + "/", delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{ {
m_omCapUsers[omCapUrl] = agentID; HandleObjectMediaMessage(httpRequest, httpResponse, agentID);
m_omCapUrls[agentID] = omCapUrl; }));
// Even though we're registering for POST we're going to get GETS and UPDATES too caps.RegisterSimpleHandler("ObjectMediaNavigate",
caps.RegisterHandler( new SimpleStreamHandler("/" + UUID.Random() + "/", delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
"ObjectMedia",
new RestStreamHandler(
"POST", omCapUrl, HandleObjectMediaMessage, "ObjectMedia", agentID.ToString()));
}
string omuCapUrl = "/CAPS/" + UUID.Random();
lock (m_omuCapUsers)
{ {
m_omuCapUsers[omuCapUrl] = agentID; HandleObjectMediaNavigateMessage(httpRequest, httpResponse, agentID);
m_omuCapUrls[agentID] = omuCapUrl; }));
// Even though we're registering for POST we're going to get GETS and UPDATES too
caps.RegisterHandler(
"ObjectMediaNavigate",
new RestStreamHandler(
"POST", omuCapUrl, HandleObjectMediaNavigateMessage, "ObjectMediaNavigate", agentID.ToString()));
}
}
public void OnDeregisterCaps(UUID agentID, Caps caps)
{
lock (m_omCapUsers)
{
string path = m_omCapUrls[agentID];
m_omCapUrls.Remove(agentID);
m_omCapUsers.Remove(path);
}
lock (m_omuCapUsers)
{
string path = m_omuCapUrls[agentID];
m_omuCapUrls.Remove(agentID);
m_omuCapUsers.Remove(path);
}
} }
protected void OnSceneObjectPartCopy(SceneObjectPart copy, SceneObjectPart original, bool userExposed) protected void OnSceneObjectPartCopy(SceneObjectPart copy, SceneObjectPart original, bool userExposed)
@ -295,30 +236,46 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
/// <summary> /// <summary>
/// Sets or gets per face media textures. /// Sets or gets per face media textures.
/// </summary> /// </summary>
/// <param name="request"></param> protected void HandleObjectMediaMessage(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID)
/// <param name="path"></param>
/// <param name="param"></param>
/// <param name="httpRequest"></param>
/// <param name="httpResponse"></param>
/// <returns></returns>
protected string HandleObjectMediaMessage(
string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{ {
// m_log.DebugFormat("[MOAP]: Got ObjectMedia path [{0}], raw request [{1}]", path, request); // m_log.DebugFormat("[MOAP]: Got ObjectMedia path [{0}], raw request [{1}]", path, request);
OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(request); try
{
OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
ObjectMediaMessage omm = new ObjectMediaMessage(); ObjectMediaMessage omm = new ObjectMediaMessage();
omm.Deserialize(osd); omm.Deserialize(osd);
if (omm.Request is ObjectMediaRequest) if (omm.Request is ObjectMediaRequest)
return HandleObjectMediaRequest(omm.Request as ObjectMediaRequest); {
string ret = HandleObjectMediaRequest(omm.Request as ObjectMediaRequest);
if(!string.IsNullOrEmpty(ret))
{
httpResponse.RawBuffer = Util.UTF8.GetBytes(ret);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
return;
}
}
else if (omm.Request is ObjectMediaUpdate) else if (omm.Request is ObjectMediaUpdate)
return HandleObjectMediaUpdate(path, omm.Request as ObjectMediaUpdate); {
if(HandleObjectMediaUpdate(omm.Request as ObjectMediaUpdate, agentID))
throw new Exception( {
string.Format( httpResponse.StatusCode = (int)HttpStatusCode.OK;
return;
}
}
else
{
m_log.ErrorFormat(
"[MOAP]: ObjectMediaMessage has unrecognized ObjectMediaBlock of {0}", "[MOAP]: ObjectMediaMessage has unrecognized ObjectMediaBlock of {0}",
omm.Request.GetType())); omm.Request.GetType());
}
}
catch
{
}
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
return;
} }
/// <summary> /// <summary>
@ -387,10 +344,9 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
/// <summary> /// <summary>
/// Handle an update of media textures. /// Handle an update of media textures.
/// </summary> /// </summary>
/// <param name="path">Path on which this request was made</param>
/// <param name="omu">/param> /// <param name="omu">/param>
/// <returns></returns> /// <returns></returns>
protected string HandleObjectMediaUpdate(string path, ObjectMediaUpdate omu) protected bool HandleObjectMediaUpdate(ObjectMediaUpdate omu, UUID agentId)
{ {
UUID primId = omu.PrimID; UUID primId = omu.PrimID;
@ -401,7 +357,7 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
m_log.WarnFormat( m_log.WarnFormat(
"[MOAP]: Received an UPDATE ObjectMediaRequest for prim {0} but this doesn't exist in region {1}", "[MOAP]: Received an UPDATE ObjectMediaRequest for prim {0} but this doesn't exist in region {1}",
primId, m_scene.RegionInfo.RegionName); primId, m_scene.RegionInfo.RegionName);
return string.Empty; return false;
} }
// m_log.DebugFormat("[MOAP]: Received {0} media entries for prim {1}", omu.FaceMedia.Length, primId); // m_log.DebugFormat("[MOAP]: Received {0} media entries for prim {1}", omu.FaceMedia.Length, primId);
@ -418,14 +374,9 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
m_log.WarnFormat( m_log.WarnFormat(
"[MOAP]: Received {0} media entries from client for prim {1} {2} but this prim has only {3} faces. Dropping request.", "[MOAP]: Received {0} media entries from client for prim {1} {2} but this prim has only {3} faces. Dropping request.",
omu.FaceMedia.Length, part.Name, part.UUID, part.GetNumberOfSides()); omu.FaceMedia.Length, part.Name, part.UUID, part.GetNumberOfSides());
return string.Empty; return false;
} }
UUID agentId = default(UUID);
lock (m_omCapUsers)
agentId = m_omCapUsers[path];
List<MediaEntry> media = part.Shape.Media; List<MediaEntry> media = part.Shape.Media;
if (null == media) if (null == media)
@ -496,7 +447,7 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
part.TriggerScriptChangedEvent(Changed.MEDIA); part.TriggerScriptChangedEvent(Changed.MEDIA);
return string.Empty; return true;
} }
/// <summary> /// <summary>
@ -508,12 +459,13 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
/// <param name="httpRequest">/param> /// <param name="httpRequest">/param>
/// <param name="httpResponse">/param> /// <param name="httpResponse">/param>
/// <returns></returns> /// <returns></returns>
protected string HandleObjectMediaNavigateMessage( protected void HandleObjectMediaNavigateMessage(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentId)
string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{ {
// m_log.DebugFormat("[MOAP]: Got ObjectMediaNavigate request [{0}]", request); // m_log.DebugFormat("[MOAP]: Got ObjectMediaNavigate request [{0}]", request);
OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(request); try
{
OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
ObjectMediaNavigateMessage omn = new ObjectMediaNavigateMessage(); ObjectMediaNavigateMessage omn = new ObjectMediaNavigateMessage();
omn.Deserialize(osd); omn.Deserialize(osd);
@ -521,21 +473,20 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
SceneObjectPart part = m_scene.GetSceneObjectPart(primId); SceneObjectPart part = m_scene.GetSceneObjectPart(primId);
bool bad = true;
MediaEntry me = null;
while (true)
{
if (null == part) if (null == part)
{ {
m_log.WarnFormat( m_log.WarnFormat(
"[MOAP]: Received an ObjectMediaNavigateMessage for prim {0} but this doesn't exist in region {1}", "[MOAP]: Received an ObjectMediaNavigateMessage for prim {0} but this doesn't exist in region {1}",
primId, m_scene.RegionInfo.RegionName); primId, m_scene.RegionInfo.RegionName);
return string.Empty;
} }
UUID agentId = default(UUID);
lock (m_omuCapUsers)
agentId = m_omuCapUsers[path];
if (!m_scene.Permissions.CanInteractWithPrimMedia(agentId, part.UUID, omn.Face)) if (!m_scene.Permissions.CanInteractWithPrimMedia(agentId, part.UUID, omn.Face))
return string.Empty; break;
//m_log.DebugFormat( //m_log.DebugFormat(
// "[MOAP]: Received request to update media entry for face {0} on prim {1} {2} to {3}", // "[MOAP]: Received request to update media entry for face {0} on prim {1} {2} to {3}",
@ -543,16 +494,14 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
// If media has never been set for this prim, then just return. // If media has never been set for this prim, then just return.
if (null == part.Shape.Media) if (null == part.Shape.Media)
return string.Empty; break;
MediaEntry me = null;
lock (part.Shape.Media) lock (part.Shape.Media)
me = part.Shape.Media[omn.Face]; me = part.Shape.Media[omn.Face];
// Do the same if media has not been set up for a specific face // Do the same if media has not been set up for a specific face
if (null == me) if (null == me)
return string.Empty; break;
if (me.EnableWhiteList) if (me.EnableWhiteList)
{ {
@ -561,10 +510,18 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
//m_log.DebugFormat( //m_log.DebugFormat(
// "[MOAP]: Blocking change of face {0} on prim {1} {2} to {3} since it's not on the enabled whitelist", // "[MOAP]: Blocking change of face {0} on prim {1} {2} to {3} since it's not on the enabled whitelist",
// omn.Face, part.Name, part.UUID, omn.URL); // omn.Face, part.Name, part.UUID, omn.URL);
break;
return string.Empty;
} }
} }
bad = false;
break;
}
if(bad)
{
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
return;
}
me.CurrentURL = omn.URL; me.CurrentURL = omn.URL;
@ -575,7 +532,14 @@ namespace OpenSim.Region.CoreModules.World.Media.Moap
part.TriggerScriptChangedEvent(Changed.MEDIA); part.TriggerScriptChangedEvent(Changed.MEDIA);
return OSDParser.SerializeLLSDXmlString(new OSD()); httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeLLSDXmlString(new OSD()));
httpResponse.StatusCode = (int)HttpStatusCode.OK;
}
catch
{
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
httpResponse.RawBuffer = null;
}
} }
/// <summary> /// <summary>