30 using System.Reflection;
32 using System.Collections.Generic;
34 using OpenMetaverse.StructuredData;
37 using OpenSim.Region.Framework;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Framework;
42 using OpenSim.Framework.Servers;
43 using OpenSim.Framework.Servers.HttpServer;
52 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"DynamicMenu")]
55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
57 private class MenuItemData
66 private Dictionary<UUID, List<MenuItemData>> m_menuItems =
67 new Dictionary<UUID, List<MenuItemData>>();
69 private Scene m_scene;
73 get {
return "DynamicMenuModule"; }
76 public Type ReplaceableInterface
92 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
100 if (featuresModule != null)
101 featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest;
108 private void OnSimulatorFeaturesRequest(UUID agentID, ref
OSDMap features)
111 if (features.ContainsKey(
"menus"))
112 menus = features[
"menus"];
119 if (((
OSDMap)menus).ContainsKey(
"agent"))
121 if (((
OSDMap)menus).ContainsKey(
"world"))
123 if (((
OSDMap)menus).ContainsKey(
"tools"))
125 if (((
OSDMap)menus).ContainsKey(
"advanced"))
127 if (((
OSDMap)menus).ContainsKey(
"admin"))
130 if (m_menuItems.ContainsKey(
UUID.Zero))
132 foreach (MenuItemData d
in m_menuItems[
UUID.Zero])
134 if (!m_scene.Permissions.IsGod(agentID))
136 if (d.Mode ==
UserMode.RegionManager && (!m_scene.Permissions.IsAdministrator(agentID)))
143 case InsertLocation.Agent:
146 case InsertLocation.World:
149 case InsertLocation.Tools:
152 case InsertLocation.Advanced:
155 case InsertLocation.Admin:
163 loc[d.Title] = OSD.FromString(d.Title);
167 if (m_menuItems.ContainsKey(agentID))
169 foreach (MenuItemData d
in m_menuItems[agentID])
171 if (d.Mode ==
UserMode.God && (!m_scene.Permissions.IsGod(agentID)))
177 case InsertLocation.Agent:
180 case InsertLocation.World:
183 case InsertLocation.Tools:
186 case InsertLocation.Advanced:
189 case InsertLocation.Admin:
197 loc[d.Title] = OSD.FromString(d.Title);
202 ((
OSDMap)menus)[
"agent"] = agent;
203 ((
OSDMap)menus)[
"world"] = world;
204 ((
OSDMap)menus)[
"tools"] = tools;
205 ((
OSDMap)menus)[
"advanced"] = advanced;
206 ((
OSDMap)menus)[
"admin"] = admin;
208 features[
"menus"] = menus;
211 private void OnRegisterCaps(UUID agentID,
Caps caps)
213 string capUrl =
"/CAPS/" + UUID.Random() +
"/";
215 capUrl =
"/CAPS/" + UUID.Random() +
"/";
216 caps.RegisterHandler(
"CustomMenuAction",
new MenuActionHandler(capUrl,
"CustomMenuAction", agentID,
this, m_scene));
219 internal void HandleMenuSelection(
string action, UUID agentID, List<uint> selection)
221 if (m_menuItems.ContainsKey(agentID))
223 foreach (MenuItemData d
in m_menuItems[agentID])
225 if (d.Title == action)
226 d.Handler(action, agentID, selection);
230 if (m_menuItems.ContainsKey(
UUID.Zero))
232 foreach (MenuItemData d
in m_menuItems[
UUID.Zero])
234 if (d.Title == action)
235 d.Handler(action, agentID, selection);
242 AddMenuItem(
UUID.Zero, title, location, mode, handler);
247 if (!m_menuItems.ContainsKey(agentID))
248 m_menuItems[agentID] =
new List<MenuItemData>();
250 m_menuItems[agentID].Add(
new MenuItemData() { Title = title, AgentID = agentID,
Location = location, Mode = mode, Handler = handler });
255 foreach (KeyValuePair<
UUID,List< MenuItemData>> kvp
in m_menuItems)
257 List<MenuItemData> pendingDeletes =
new List<MenuItemData>();
258 foreach (MenuItemData d
in kvp.Value)
260 if (d.Title == action)
261 pendingDeletes.Add(d);
264 foreach (MenuItemData d
in pendingDeletes)
272 private static readonly ILog m_log =
273 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
275 private UUID m_agentID;
276 private Scene m_scene;
280 :base(
"POST", path, name, agentID.ToString())
289 StreamReader reader =
new StreamReader(request);
290 string requestBody = reader.ReadToEnd();
292 OSD osd = OSDParser.DeserializeLLSDXml(requestBody);
294 string action = ((
OSDMap)osd)[
"action"].AsString();
296 List<uint> sel =
new List<uint>();
297 for (
int i = 0 ; i < selection.Count ; i++)
298 sel.Add(selection[i].AsUInteger());
301 x => { m_module.HandleMenuSelection(action, m_agentID, sel); }, null,
"DynamicMenuModule.HandleMenuSelection");
303 Encoding encoding = Encoding.UTF8;
304 return encoding.GetBytes(OSDParser.SerializeLLSDXmlString(
new OSD()));
OpenMetaverse.StructuredData.OSDArray OSDArray
Base streamed request handler.
MenuActionHandler(string path, string name, UUID agentID, DynamicMenuModule module, Scene scene)
OpenMetaverse.StructuredData.OSDMap OSDMap
Add remove or retrieve Simulator Features that will be given to a viewer via the SimulatorFeatures ca...
OpenSim.Framework.Capabilities.Caps Caps
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
OpenMetaverse.StructuredData.OSD OSD
Interactive OpenSim region server
delegate void CustomMenuHandler(string action, UUID agentID, List< uint > selection)