29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Collections.Specialized;
32 using System.Reflection;
40 using OpenMetaverse.Messages.Linden;
41 using OpenMetaverse.StructuredData;
42 using OpenSim.Framework;
43 using OpenSim.Framework.Capabilities;
44 using OpenSim.Framework.Servers;
45 using OpenSim.Framework.Servers.HttpServer;
46 using OpenSim.Region.Framework.Interfaces;
47 using OpenSim.Region.Framework.Scenes;
48 using OpenSim.Services.Interfaces;
55 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"MoapModule")]
58 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
60 public string Name {
get {
return "MoapModule"; } }
61 public Type ReplaceableInterface {
get {
return null; } }
66 protected bool m_isEnabled =
true;
76 protected Dictionary<string, UUID> m_omCapUsers =
new Dictionary<string, UUID>();
81 protected Dictionary<UUID, string> m_omCapUrls =
new Dictionary<UUID, string>();
86 protected Dictionary<string, UUID> m_omuCapUsers =
new Dictionary<string, UUID>();
91 protected Dictionary<UUID, string> m_omuCapUrls =
new Dictionary<UUID, string>();
95 IConfig config = configSource.Configs[
"MediaOnAPrim"];
97 if (config != null && !config.GetBoolean(
"Enabled",
false))
109 m_scene.RegisterModuleInterface<
IMoapModule>(
this);
119 m_scene.EventManager.OnRegisterCaps += OnRegisterCaps;
120 m_scene.EventManager.OnDeregisterCaps += OnDeregisterCaps;
121 m_scene.EventManager.OnSceneObjectPartCopy += OnSceneObjectPartCopy;
129 m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
130 m_scene.EventManager.OnDeregisterCaps -= OnDeregisterCaps;
131 m_scene.EventManager.OnSceneObjectPartCopy -= OnSceneObjectPartCopy;
139 string omCapUrl =
"/CAPS/" + UUID.Random();
143 m_omCapUsers[omCapUrl] = agentID;
144 m_omCapUrls[agentID] = omCapUrl;
147 caps.RegisterHandler(
150 "POST", omCapUrl, HandleObjectMediaMessage,
"ObjectMedia", agentID.ToString()));
153 string omuCapUrl =
"/CAPS/" + UUID.Random();
157 m_omuCapUsers[omuCapUrl] = agentID;
158 m_omuCapUrls[agentID] = omuCapUrl;
161 caps.RegisterHandler(
162 "ObjectMediaNavigate",
164 "POST", omuCapUrl, HandleObjectMediaNavigateMessage,
"ObjectMediaNavigate", agentID.ToString()));
172 string path = m_omCapUrls[agentID];
173 m_omCapUrls.Remove(agentID);
174 m_omCapUsers.Remove(path);
179 string path = m_omuCapUrls[agentID];
180 m_omuCapUrls.Remove(agentID);
181 m_omuCapUsers.Remove(path);
192 foreach (MediaEntry me
in original.
Shape.
Media)
195 dupeMedia.Add(MediaEntry.FromOSD(me.GetOSD()));
201 copy.Shape.Media = dupeMedia;
207 MediaEntry me = null;
209 CheckFaceParam(part, face);
211 List<MediaEntry> media = part.Shape.Media;
224 me = MediaEntry.FromOSD(me.GetOSD());
242 CheckFaceParam(part, face);
253 part.Shape.Media[face] = me;
255 UpdateMediaUrl(part,
UUID.Zero);
257 SetPartMediaFlags(part, face, me != null);
259 part.ScheduleFullUpdate();
260 part.TriggerScriptChangedEvent(Changed.MEDIA);
270 SetMediaEntry(part, face, null);
284 Primitive.TextureEntry te = part.Shape.Textures;
285 Primitive.TextureEntryFace teFace = te.CreateFace((uint)face);
286 teFace.MediaFlags = flag;
287 part.Shape.Textures = te;
304 OSDMap osd = (
OSDMap)OSDParser.DeserializeLLSDXml(request);
305 ObjectMediaMessage omm =
new ObjectMediaMessage();
306 omm.Deserialize(osd);
308 if (omm.Request is ObjectMediaRequest)
309 return HandleObjectMediaRequest(omm.Request as ObjectMediaRequest);
310 else if (omm.Request is ObjectMediaUpdate)
311 return HandleObjectMediaUpdate(path, omm.Request as ObjectMediaUpdate);
315 "[MOAP]: ObjectMediaMessage has unrecognized ObjectMediaBlock of {0}",
316 omm.Request.GetType()));
326 UUID primId = omr.PrimID;
333 "[MOAP]: Received a GET ObjectMediaRequest for prim {0} but this doesn't exist in region {1}",
334 primId, m_scene.RegionInfo.RegionName);
341 ObjectMediaResponse resp =
new ObjectMediaResponse();
343 resp.PrimID = primId;
346 resp.FaceMedia = part.Shape.Media.ToArray();
348 resp.Version = part.MediaUrl;
350 string rawResp = OSDParser.SerializeLLSDXmlString(resp.Serialize());
365 UUID primId = omu.PrimID;
372 "[MOAP]: Received an UPDATE ObjectMediaRequest for prim {0} but this doesn't exist in region {1}",
373 primId, m_scene.RegionInfo.RegionName);
389 "[MOAP]: Received {0} media entries from client for prim {1} {2} but this prim has only {3} faces. Dropping request.",
390 omu.FaceMedia.Length, part.Name, part.UUID, part.GetNumberOfSides());
397 agentId = m_omCapUsers[path];
399 List<MediaEntry> media = part.Shape.Media;
406 for (
int i = 0; i < omu.FaceMedia.Length; i++)
408 if (omu.FaceMedia[i] != null)
413 SetPartMediaFlags(part, i,
true);
430 Primitive.TextureEntry te = part.Shape.Textures;
434 for (
int i = 0; i < media.Count; i++)
436 if (m_scene.Permissions.CanControlPrimMedia(agentId, part.
UUID, i))
438 media[i] = omu.FaceMedia[i];
442 if (null == media[i])
445 SetPartMediaFlags(part, i,
true);
455 part.Shape.Textures = te;
461 UpdateMediaUrl(part, agentId);
464 part.ScheduleFullUpdate();
466 part.TriggerScriptChangedEvent(Changed.MEDIA);
485 OSDMap osd = (
OSDMap)OSDParser.DeserializeLLSDXml(request);
486 ObjectMediaNavigateMessage omn =
new ObjectMediaNavigateMessage();
487 omn.Deserialize(osd);
489 UUID primId = omn.PrimID;
496 "[MOAP]: Received an ObjectMediaNavigateMessage for prim {0} but this doesn't exist in region {1}",
497 primId, m_scene.RegionInfo.RegionName);
504 agentId = m_omuCapUsers[path];
506 if (!m_scene.Permissions.CanInteractWithPrimMedia(agentId, part.
UUID, omn.Face))
517 MediaEntry me = null;
520 me = part.Shape.Media[omn.Face];
526 if (me.EnableWhiteList)
528 if (!CheckUrlAgainstWhitelist(omn.URL, me.WhiteList))
538 me.CurrentURL = omn.URL;
540 UpdateMediaUrl(part, agentId);
542 part.ScheduleFullUpdate();
544 part.TriggerScriptChangedEvent(Changed.MEDIA);
546 return OSDParser.SerializeLLSDXmlString(
new OSD());
557 throw new ArgumentException(
"Face cannot be less than zero");
559 int maxFaces = part.GetNumberOfSides() - 1;
561 throw new ArgumentException(
562 string.Format(
"Face argument was {0} but max is {1}", face, maxFaces));
578 part.MediaUrl =
"x-mv:0000000000/" + updateId;
582 string rawVersion = part.MediaUrl.Substring(5, 10);
583 int version = int.Parse(rawVersion);
584 part.MediaUrl = string.Format(
"x-mv:{0:D10}/{1}", ++version, updateId);
598 if (whitelist == null)
601 Uri url =
new Uri(rawUrl);
603 foreach (
string origWlUrl
in whitelist)
605 string wlUrl = origWlUrl;
608 if (wlUrl.EndsWith(
"*"))
609 wlUrl = wlUrl.Remove(wlUrl.Length - 1);
614 if (wlUrl.StartsWith(
"*"))
616 wlUrl = wlUrl.Substring(1);
618 if (url.Host.Contains(wlUrl))
626 string urlToMatch = url.Authority + url.AbsolutePath;
628 if (urlToMatch.StartsWith(wlUrl))
int GetNumberOfSides()
Get the number of sides that this part has.
OpenMetaverse.StructuredData.OSDMap OSDMap
MediaList Media
Entries to store media textures on each face
string MediaUrl
Used for media on a prim.
OpenMetaverse.StructuredData.OSD OSD
OpenMetaverse.StructuredData.OSDArray OSDArray
Interactive OpenSim region server
OpenSim.Framework.Capabilities.Caps Caps
Provides methods from manipulating media-on-a-prim