opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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.Reflection;
31 using log4net;
32 using Nini.Config;
33 using Mono.Addins;
34 using OpenMetaverse;
35 using OpenMetaverse.StructuredData;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Servers.HttpServer;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Services.Interfaces;
41 using Caps = OpenSim.Framework.Capabilities.Caps;
42  
43 namespace OpenSim.Region.ClientStack.Linden
44 {
45 /// <summary>
46 /// SimulatorFeatures capability.
47 /// </summary>
48 /// <remarks>
49 /// This is required for uploading Mesh.
50 /// Since is accepts an open-ended response, we also send more information
51 /// for viewers that care to interpret it.
52 ///
53 /// NOTE: Part of this code was adapted from the Aurora project, specifically
54 /// the normal part of the response in the capability handler.
55 /// </remarks>
56 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SimulatorFeaturesModule")]
57 public class SimulatorFeaturesModule : ISharedRegionModule, ISimulatorFeaturesModule
58 {
59 // private static readonly ILog m_log =
60 // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
61  
62 public event SimulatorFeaturesRequestDelegate OnSimulatorFeaturesRequest;
63  
64 private Scene m_scene;
65  
66 /// <summary>
67 /// Simulator features
68 /// </summary>
69 private OSDMap m_features = new OSDMap();
70  
71 private string m_SearchURL = string.Empty;
72 private bool m_ExportSupported = false;
73  
74 #region ISharedRegionModule Members
75  
76 public void Initialise(IConfigSource source)
77 {
78 IConfig config = source.Configs["SimulatorFeatures"];
79 if (config != null)
80 {
81 m_SearchURL = config.GetString("SearchServerURI", string.Empty);
82  
83 m_ExportSupported = config.GetBoolean("ExportSupported", m_ExportSupported);
84 }
85  
86 AddDefaultFeatures();
87 }
88  
89 public void AddRegion(Scene s)
90 {
91 m_scene = s;
92 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
93  
94 m_scene.RegisterModuleInterface<ISimulatorFeaturesModule>(this);
95 }
96  
97 public void RemoveRegion(Scene s)
98 {
99 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
100 }
101  
102 public void RegionLoaded(Scene s)
103 {
104 }
105  
106 public void PostInitialise()
107 {
108 }
109  
110 public void Close() { }
111  
112 public string Name { get { return "SimulatorFeaturesModule"; } }
113  
114 public Type ReplaceableInterface
115 {
116 get { return null; }
117 }
118  
119 #endregion
120  
121 /// <summary>
122 /// Add default features
123 /// </summary>
124 /// <remarks>
125 /// TODO: These should be added from other modules rather than hardcoded.
126 /// </remarks>
127 private void AddDefaultFeatures()
128 {
129 lock (m_features)
130 {
131 m_features["MeshRezEnabled"] = true;
132 m_features["MeshUploadEnabled"] = true;
133 m_features["MeshXferEnabled"] = true;
134 m_features["PhysicsMaterialsEnabled"] = true;
135  
136 OSDMap typesMap = new OSDMap();
137 typesMap["convex"] = true;
138 typesMap["none"] = true;
139 typesMap["prim"] = true;
140 m_features["PhysicsShapeTypes"] = typesMap;
141  
142 // Extra information for viewers that want to use it
143 // TODO: Take these out of here into their respective modules, like map-server-url
144 OSDMap extrasMap = new OSDMap();
145 if (m_SearchURL != string.Empty)
146 extrasMap["search-server-url"] = m_SearchURL;
147 if (m_ExportSupported)
148 extrasMap["ExportSupported"] = true;
149  
150 if (extrasMap.Count > 0)
151 m_features["OpenSimExtras"] = extrasMap;
152  
153 }
154 }
155  
156 public void RegisterCaps(UUID agentID, Caps caps)
157 {
158 IRequestHandler reqHandler
159 = new RestHTTPHandler(
160 "GET", "/CAPS/" + UUID.Random(),
161 x => { return HandleSimulatorFeaturesRequest(x, agentID); }, "SimulatorFeatures", agentID.ToString());
162  
163 caps.RegisterHandler("SimulatorFeatures", reqHandler);
164 }
165  
166 public void AddFeature(string name, OSD value)
167 {
168 lock (m_features)
169 m_features[name] = value;
170 }
171  
172 public bool RemoveFeature(string name)
173 {
174 lock (m_features)
175 return m_features.Remove(name);
176 }
177  
178 public bool TryGetFeature(string name, out OSD value)
179 {
180 lock (m_features)
181 return m_features.TryGetValue(name, out value);
182 }
183  
184 public OSDMap GetFeatures()
185 {
186 lock (m_features)
187 return new OSDMap(m_features);
188 }
189  
190 private OSDMap DeepCopy()
191 {
192 // This isn't the cheapest way of doing this but the rate
193 // of occurrence is low (on sim entry only) and it's a sure
194 // way to get a true deep copy.
195 OSD copy = OSDParser.DeserializeLLSDXml(OSDParser.SerializeLLSDXmlString(m_features));
196  
197 return (OSDMap)copy;
198 }
199  
200 private Hashtable HandleSimulatorFeaturesRequest(Hashtable mDhttpMethod, UUID agentID)
201 {
202 // m_log.DebugFormat("[SIMULATOR FEATURES MODULE]: SimulatorFeatures request");
203  
204 OSDMap copy = DeepCopy();
205  
206 SimulatorFeaturesRequestDelegate handlerOnSimulatorFeaturesRequest = OnSimulatorFeaturesRequest;
207 if (handlerOnSimulatorFeaturesRequest != null)
208 handlerOnSimulatorFeaturesRequest(agentID, ref copy);
209  
210 //Send back data
211 Hashtable responsedata = new Hashtable();
212 responsedata["int_response_code"] = 200;
213 responsedata["content_type"] = "text/plain";
214 responsedata["keepalive"] = false;
215  
216 responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(copy);
217  
218 return responsedata;
219 }
220 }
221 }