29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
36 using OpenMetaverse.StructuredData;
37 using OpenSim.Framework;
38 using OpenSim.Framework.Servers.HttpServer;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
44 namespace OpenSim.
Region.ClientStack.Linden
57 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SimulatorFeaturesModule")]
60 private static readonly ILog m_log =
61 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
65 private Scene m_scene;
72 private string m_SearchURL = string.Empty;
73 private string m_DestinationGuideURL = string.Empty;
74 private bool m_ExportSupported =
false;
75 private string m_GridName = string.Empty;
76 private string m_GridURL = string.Empty;
78 #region ISharedRegionModule Members
82 IConfig config = source.Configs[
"SimulatorFeatures"];
90 m_SearchURL = config.GetString(
"SearchServerURI", m_SearchURL);
92 m_DestinationGuideURL = config.GetString (
"DestinationGuideURI", m_DestinationGuideURL);
94 if (m_DestinationGuideURL ==
string.Empty)
95 m_DestinationGuideURL = config.GetString(
"DestinationGuide", m_DestinationGuideURL);
97 m_ExportSupported = config.GetBoolean(
"ExportSupported", m_ExportSupported);
99 m_GridURL = Util.GetConfigVarFromSections<
string>(
100 source,
"GatekeeperURI",
new string[] {
"Startup",
"Hypergrid",
"SimulatorFeatures" }, String.Empty);
102 m_GridName = config.GetString(
"GridName", string.Empty);
103 if (m_GridName ==
string.Empty)
104 m_GridName = Util.GetConfigVarFromSections<
string>(
105 source,
"gridname",
new string[] {
"GridInfo",
"SimulatorFeatures" }, String.Empty);
108 AddDefaultFeatures();
114 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
121 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
126 GetGridExtraFeatures(s);
135 public string Name {
get {
return "SimulatorFeaturesModule"; } }
137 public Type ReplaceableInterface
150 private void AddDefaultFeatures()
155 m_features[
"MeshRezEnabled"] =
true;
156 m_features[
"MeshUploadEnabled"] =
true;
157 m_features[
"MeshXferEnabled"] =
true;
159 m_features[
"PhysicsMaterialsEnabled"] =
true;
162 typesMap[
"convex"] =
true;
163 typesMap[
"none"] =
true;
164 typesMap[
"prim"] =
true;
165 m_features[
"PhysicsShapeTypes"] = typesMap;
170 if(m_features.ContainsKey(
"OpenSimExtras"))
172 extrasMap = (
OSDMap)m_features[
"OpenSimExtras"];
177 extrasMap[
"AvatarSkeleton"] =
true;
178 extrasMap[
"AnimationSet"] =
true;
181 if (m_SearchURL !=
string.Empty)
182 extrasMap[
"search-server-url"] = m_SearchURL;
183 if (!
string.IsNullOrEmpty(m_DestinationGuideURL))
184 extrasMap[
"destination-guide-url"] = m_DestinationGuideURL;
185 if (m_ExportSupported)
186 extrasMap[
"ExportSupported"] =
true;
187 if (m_GridURL !=
string.Empty)
188 extrasMap[
"GridURL"] = m_GridURL;
189 if (m_GridName !=
string.Empty)
190 extrasMap[
"GridName"] = m_GridName;
192 if (extrasMap.Count > 0)
193 m_features[
"OpenSimExtras"] = extrasMap;
201 "GET",
"/CAPS/" +
UUID.Random(),
202 x => {
return HandleSimulatorFeaturesRequest(x, agentID); },
"SimulatorFeatures", agentID.ToString());
204 caps.RegisterHandler(
"SimulatorFeatures", reqHandler);
210 m_features[name] = value;
216 return m_features.Remove(name);
222 return m_features.TryGetValue(name, out value);
228 return new OSDMap(m_features);
236 OSD copy = OSDParser.DeserializeLLSDXml(OSDParser.SerializeLLSDXmlString(m_features));
241 private Hashtable HandleSimulatorFeaturesRequest(Hashtable mDhttpMethod, UUID agentID)
248 if (copy.ContainsKey(
"OpenSimExtras") && ((
OSDMap)(copy[
"OpenSimExtras"])).ContainsKey(
"destination-guide-url"))
249 ((
OSDMap)copy[
"OpenSimExtras"])[
"destination-guide-url"] = Replace(((
OSDMap)copy[
"OpenSimExtras"])[
"destination-guide-url"],
"[USERID]", agentID.ToString());
253 if (handlerOnSimulatorFeaturesRequest != null)
254 handlerOnSimulatorFeaturesRequest(agentID, ref copy);
257 Hashtable responsedata =
new Hashtable();
258 responsedata[
"int_response_code"] = 200;
259 responsedata[
"content_type"] =
"text/plain";
260 responsedata[
"keepalive"] =
false;
262 responsedata[
"str_response_string"] = OSDParser.SerializeLLSDXmlString(copy);
273 private void GetGridExtraFeatures(
Scene scene)
275 Dictionary<string, object> extraFeatures = scene.GridService.GetExtraFeatures();
276 if (extraFeatures.ContainsKey(
"Result") && extraFeatures[
"Result"] != null && extraFeatures[
"Result"].ToString() ==
"Failure")
278 m_log.WarnFormat(
"[SIMULATOR FEATURES MODULE]: Unable to retrieve grid-wide features");
286 foreach(
string key in extraFeatures.Keys)
288 extrasMap[
key] = (string)extraFeatures[key];
290 if (key ==
"ExportSupported")
292 bool.TryParse(extraFeatures[
key].ToString(), out m_ExportSupported);
295 m_features[
"OpenSimExtras"] = extrasMap;
300 private string Replace(
string url,
string substring,
string replacement)
302 if (!
String.IsNullOrEmpty(url) && url.Contains(substring))
303 return url.Replace(substring, replacement);
bool TryGetFeature(string name, out OSD value)
void RemoveRegion(Scene s)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
SimulatorFeaturesRequestDelegate OnSimulatorFeaturesRequest
OpenSim.Framework.Capabilities.Caps Caps
bool RemoveFeature(string name)
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
void RegionLoaded(Scene s)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
delegate void SimulatorFeaturesRequestDelegate(UUID agentID, ref OSDMap features)
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
OpenMetaverse.StructuredData.OSD OSD
void RegisterCaps(UUID agentID, Caps caps)
void AddRegion(Scene s)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void AddFeature(string name, OSD value)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
SimulatorFeatures capability.
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...