clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using log4net;
33 using Nini.Config;
34 using Mono.Addins;
35 using OpenMetaverse;
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;
41 // using OpenSim.Services.Interfaces;
42 using Caps = OpenSim.Framework.Capabilities.Caps;
43  
44 namespace OpenSim.Region.ClientStack.Linden
45 {
46 /// <summary>
47 /// SimulatorFeatures capability.
48 /// </summary>
49 /// <remarks>
50 /// This is required for uploading Mesh.
51 /// Since is accepts an open-ended response, we also send more information
52 /// for viewers that care to interpret it.
53 ///
54 /// NOTE: Part of this code was adapted from the Aurora project, specifically
55 /// the normal part of the response in the capability handler.
56 /// </remarks>
57 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SimulatorFeaturesModule")]
58 public class SimulatorFeaturesModule : ISharedRegionModule, ISimulatorFeaturesModule
59 {
60 private static readonly ILog m_log =
61 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62  
63 public event SimulatorFeaturesRequestDelegate OnSimulatorFeaturesRequest;
64  
65 private Scene m_scene;
66  
67 /// <summary>
68 /// Simulator features
69 /// </summary>
70 private OSDMap m_features = new OSDMap();
71  
72 private string m_SearchURL = string.Empty;
73 private string m_DestinationGuideURL = string.Empty;
74 private bool m_ExportSupported = false;
75  
76 #region ISharedRegionModule Members
77  
78 public void Initialise(IConfigSource source)
79 {
80 IConfig config = source.Configs["SimulatorFeatures"];
81  
82 if (config != null)
83 {
84 // These are normaly set in their respective modules
85 m_SearchURL = config.GetString("SearchServerURI", m_SearchURL);
86 m_DestinationGuideURL = config.GetString ("DestinationGuideURI", m_DestinationGuideURL);
87 m_ExportSupported = config.GetBoolean("ExportSupported", m_ExportSupported);
88 }
89  
90 AddDefaultFeatures();
91 }
92  
93 public void AddRegion(Scene s)
94 {
95 m_scene = s;
96 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
97  
98 m_scene.RegisterModuleInterface<ISimulatorFeaturesModule>(this);
99 }
100  
101 public void RemoveRegion(Scene s)
102 {
103 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
104 }
105  
106 public void RegionLoaded(Scene s)
107 {
108 GetGridExtraFeatures(s);
109 }
110  
111 public void PostInitialise()
112 {
113 }
114  
115 public void Close() { }
116  
117 public string Name { get { return "SimulatorFeaturesModule"; } }
118  
119 public Type ReplaceableInterface
120 {
121 get { return null; }
122 }
123  
124 #endregion
125  
126 /// <summary>
127 /// Add default features
128 /// </summary>
129 /// <remarks>
130 /// TODO: These should be added from other modules rather than hardcoded.
131 /// </remarks>
132 private void AddDefaultFeatures()
133 {
134  
135 lock (m_features)
136 {
137 m_features["MeshRezEnabled"] = true;
138 m_features["MeshUploadEnabled"] = true;
139 m_features["MeshXferEnabled"] = true;
140 m_features["PhysicsMaterialsEnabled"] = true;
141  
142 OSDMap typesMap = new OSDMap();
143 typesMap["convex"] = true;
144 typesMap["none"] = true;
145 typesMap["prim"] = true;
146 m_features["PhysicsShapeTypes"] = typesMap;
147  
148 // Extra information for viewers that want to use it
149 // TODO: Take these out of here into their respective modules, like map-server-url
150 OSDMap extrasMap;
151 if(m_features.ContainsKey("OpenSimExtras"))
152 {
153 extrasMap = (OSDMap)m_features["OpenSimExtras"];
154 }
155 else
156 extrasMap = new OSDMap();
157  
158 if (m_SearchURL != string.Empty)
159 extrasMap["search-server-url"] = m_SearchURL;
160 if (!string.IsNullOrEmpty(m_DestinationGuideURL))
161 extrasMap["destination-guide-url"] = m_DestinationGuideURL;
162 if (m_ExportSupported)
163 extrasMap["ExportSupported"] = true;
164  
165 if (extrasMap.Count > 0)
166 m_features["OpenSimExtras"] = extrasMap;
167 }
168 }
169  
170 public void RegisterCaps(UUID agentID, Caps caps)
171 {
172 IRequestHandler reqHandler
173 = new RestHTTPHandler(
174 "GET", "/CAPS/" + UUID.Random(),
175 x => { return HandleSimulatorFeaturesRequest(x, agentID); }, "SimulatorFeatures", agentID.ToString());
176  
177 caps.RegisterHandler("SimulatorFeatures", reqHandler);
178 }
179  
180 public void AddFeature(string name, OSD value)
181 {
182 lock (m_features)
183 m_features[name] = value;
184 }
185  
186 public bool RemoveFeature(string name)
187 {
188 lock (m_features)
189 return m_features.Remove(name);
190 }
191  
192 public bool TryGetFeature(string name, out OSD value)
193 {
194 lock (m_features)
195 return m_features.TryGetValue(name, out value);
196 }
197  
198 public OSDMap GetFeatures()
199 {
200 lock (m_features)
201 return new OSDMap(m_features);
202 }
203  
204 private OSDMap DeepCopy()
205 {
206 // This isn't the cheapest way of doing this but the rate
207 // of occurrence is low (on sim entry only) and it's a sure
208 // way to get a true deep copy.
209 OSD copy = OSDParser.DeserializeLLSDXml(OSDParser.SerializeLLSDXmlString(m_features));
210  
211 return (OSDMap)copy;
212 }
213  
214 private Hashtable HandleSimulatorFeaturesRequest(Hashtable mDhttpMethod, UUID agentID)
215 {
216 // m_log.DebugFormat("[SIMULATOR FEATURES MODULE]: SimulatorFeatures request");
217  
218 OSDMap copy = DeepCopy();
219  
220 SimulatorFeaturesRequestDelegate handlerOnSimulatorFeaturesRequest = OnSimulatorFeaturesRequest;
221  
222 if (handlerOnSimulatorFeaturesRequest != null)
223 handlerOnSimulatorFeaturesRequest(agentID, ref copy);
224  
225 //Send back data
226 Hashtable responsedata = new Hashtable();
227 responsedata["int_response_code"] = 200;
228 responsedata["content_type"] = "text/plain";
229 responsedata["keepalive"] = false;
230  
231 responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(copy);
232  
233 return responsedata;
234 }
235  
236 /// <summary>
237 /// Gets the grid extra features.
238 /// </summary>
239 /// <param name='featuresURI'>
240 /// The URI Robust uses to handle the get_extra_features request
241 /// </param>
242 private void GetGridExtraFeatures(Scene scene)
243 {
244 Dictionary<string, object> extraFeatures = scene.GridService.GetExtraFeatures();
245  
246 lock (m_features)
247 {
248 OSDMap extrasMap = new OSDMap();
249  
250 foreach(string key in extraFeatures.Keys)
251 {
252 extrasMap[key] = (string)extraFeatures[key];
253  
254 if (key == "ExportSupported")
255 {
256 bool.TryParse(extraFeatures[key].ToString(), out m_ExportSupported);
257 }
258 }
259 m_features["OpenSimExtras"] = extrasMap;
260 }
261 }
262 }
263 }