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 using System;
28 using System.Collections.Generic;
29 using System.Linq;
30 using System.Reflection;
31 using log4net;
32 using Mono.Addins;
33 using Nini.Config;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Services.Interfaces;
39 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
40  
41 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
42 {
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalSimulationConnectorModule")]
44 public class LocalSimulationConnectorModule : ISharedRegionModule, ISimulationService
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47  
48 /// <summary>
49 /// Version of this service.
50 /// </summary>
51 /// <remarks>
52 /// Currently valid versions are "SIMULATION/0.1" and "SIMULATION/0.2"
53 /// </remarks>
54 public string ServiceVersion { get; set; }
55 private float m_VersionNumber = 0.3f;
56  
57 /// <summary>
58 /// Map region ID to scene.
59 /// </summary>
60 private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
61  
62 /// <summary>
63 /// Is this module enabled?
64 /// </summary>
65 private bool m_ModuleEnabled = false;
66  
67 #region Region Module interface
68  
69 public void Initialise(IConfigSource configSource)
70 {
71 IConfig moduleConfig = configSource.Configs["Modules"];
72 if (moduleConfig != null)
73 {
74 string name = moduleConfig.GetString("SimulationServices", "");
75 if (name == Name)
76 {
77 InitialiseService(configSource);
78  
79 m_ModuleEnabled = true;
80  
81 m_log.Info("[LOCAL SIMULATION CONNECTOR]: Local simulation enabled.");
82 }
83 }
84 }
85  
86 public void InitialiseService(IConfigSource configSource)
87 {
88 ServiceVersion = "SIMULATION/0.3";
89 IConfig config = configSource.Configs["SimulationService"];
90 if (config != null)
91 {
92 ServiceVersion = config.GetString("ConnectorProtocolVersion", ServiceVersion);
93  
94 if (ServiceVersion != "SIMULATION/0.1" && ServiceVersion != "SIMULATION/0.2" && ServiceVersion != "SIMULATION/0.3")
95 throw new Exception(string.Format("Invalid ConnectorProtocolVersion {0}", ServiceVersion));
96  
97 string[] versionComponents = ServiceVersion.Split(new char[] { '/' });
98 if (versionComponents.Length >= 2)
99 float.TryParse(versionComponents[1], out m_VersionNumber);
100  
101 m_log.InfoFormat(
102 "[LOCAL SIMULATION CONNECTOR]: Initialized with connector protocol version {0}", ServiceVersion);
103 }
104 }
105  
106 public void PostInitialise()
107 {
108 }
109  
110 public void AddRegion(Scene scene)
111 {
112 if (!m_ModuleEnabled)
113 return;
114  
115 Init(scene);
116 scene.RegisterModuleInterface<ISimulationService>(this);
117 }
118  
119 public void RemoveRegion(Scene scene)
120 {
121 if (!m_ModuleEnabled)
122 return;
123  
124 RemoveScene(scene);
125 scene.UnregisterModuleInterface<ISimulationService>(this);
126 }
127  
128 public void RegionLoaded(Scene scene)
129 {
130 }
131  
132 public void Close()
133 {
134 }
135  
136 public Type ReplaceableInterface
137 {
138 get { return null; }
139 }
140  
141 public string Name
142 {
143 get { return "LocalSimulationConnectorModule"; }
144 }
145  
146 /// <summary>
147 /// Can be called from other modules.
148 /// </summary>
149 /// <param name="scene"></param>
150 public void RemoveScene(Scene scene)
151 {
152 lock (m_scenes)
153 {
154 if (m_scenes.ContainsKey(scene.RegionInfo.RegionID))
155 m_scenes.Remove(scene.RegionInfo.RegionID);
156 else
157 m_log.WarnFormat(
158 "[LOCAL SIMULATION CONNECTOR]: Tried to remove region {0} but it was not present",
159 scene.RegionInfo.RegionName);
160 }
161 }
162  
163 /// <summary>
164 /// Can be called from other modules.
165 /// </summary>
166 /// <param name="scene"></param>
167 public void Init(Scene scene)
168 {
169 lock (m_scenes)
170 {
171 if (!m_scenes.ContainsKey(scene.RegionInfo.RegionID))
172 m_scenes[scene.RegionInfo.RegionID] = scene;
173 else
174 m_log.WarnFormat(
175 "[LOCAL SIMULATION CONNECTOR]: Tried to add region {0} but it is already present",
176 scene.RegionInfo.RegionName);
177 }
178 }
179  
180 #endregion
181  
182 #region ISimulationService
183  
184 public IScene GetScene(UUID regionId)
185 {
186 if (m_scenes.ContainsKey(regionId))
187 {
188 return m_scenes[regionId];
189 }
190 else
191 {
192 // FIXME: This was pre-existing behaviour but possibly not a good idea, since it hides an error rather
193 // than making it obvious and fixable. Need to see if the error message comes up in practice.
194 Scene s = m_scenes.Values.ToArray()[0];
195  
196 m_log.ErrorFormat(
197 "[LOCAL SIMULATION CONNECTOR]: Region with id {0} not found. Returning {1} {2} instead",
198 regionId, s.RegionInfo.RegionName, s.RegionInfo.RegionID);
199  
200 return s;
201 }
202 }
203  
204 public ISimulationService GetInnerService()
205 {
206 return this;
207 }
208  
209 /**
210 * Agent-related communications
211 */
212  
213 public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason)
214 {
215 if (destination == null)
216 {
217 reason = "Given destination was null";
218 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: CreateAgent was given a null destination");
219 return false;
220 }
221  
222 if (m_scenes.ContainsKey(destination.RegionID))
223 {
224 // m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Found region {0} to send SendCreateChildAgent", destination.RegionName);
225 return m_scenes[destination.RegionID].NewUserConnection(aCircuit, teleportFlags, source, out reason);
226 }
227  
228 reason = "Did not find region " + destination.RegionName;
229 return false;
230 }
231  
232 public bool UpdateAgent(GridRegion destination, AgentData cAgentData)
233 {
234 if (destination == null)
235 return false;
236  
237 if (m_scenes.ContainsKey(destination.RegionID))
238 {
239 // m_log.DebugFormat(
240 // "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
241 // destination.RegionName, destination.RegionID);
242  
243 return m_scenes[destination.RegionID].IncomingUpdateChildAgent(cAgentData);
244 }
245  
246 // m_log.DebugFormat(
247 // "[LOCAL COMMS]: Did not find region {0} {1} for ChildAgentUpdate",
248 // destination.RegionName, destination.RegionID);
249  
250 return false;
251 }
252  
253 public bool UpdateAgent(GridRegion destination, AgentPosition agentPosition)
254 {
255 if (destination == null)
256 return false;
257  
258 // We limit the number of messages sent for a position change to just one per
259 // simulator so when we receive the update we need to hand it to each of the
260 // scenes; scenes each check to see if the is a scene presence for the avatar
261 // note that we really don't need the GridRegion for this call
262 foreach (Scene s in m_scenes.Values)
263 {
264 // m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
265 s.IncomingUpdateChildAgent(agentPosition);
266 }
267  
268 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
269 return true;
270 }
271  
272 public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, string theirversion, out string version, out string reason)
273 {
274 reason = "Communications failure";
275 version = ServiceVersion;
276 if (destination == null)
277 return false;
278  
279 if (m_scenes.ContainsKey(destination.RegionID))
280 {
281 // m_log.DebugFormat(
282 // "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
283 // s.RegionInfo.RegionName, destination.RegionHandle);
284 uint size = m_scenes[destination.RegionID].RegionInfo.RegionSizeX;
285  
286 float theirVersionNumber = 0f;
287 string[] versionComponents = theirversion.Split(new char[] { '/' });
288 if (versionComponents.Length >= 2)
289 float.TryParse(versionComponents[1], out theirVersionNumber);
290  
291 // Var regions here, and the requesting simulator is in an older version.
292 // We will forbide this, because it crashes the viewers
293 if (theirVersionNumber < 0.3f && size > 256)
294 {
295 reason = "Destination is a variable-sized region, and source is an old simulator. Consider upgrading.";
296 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Request to access this variable-sized region from {0} simulator was denied", theirVersionNumber);
297 return false;
298  
299 }
300  
301 return m_scenes[destination.RegionID].QueryAccess(agentID, agentHomeURI, viaTeleport, position, out reason);
302 }
303  
304 //m_log.Debug("[LOCAL COMMS]: region not found for QueryAccess");
305 return false;
306 }
307  
308 public bool ReleaseAgent(UUID originId, UUID agentId, string uri)
309 {
310 if (m_scenes.ContainsKey(originId))
311 {
312 // m_log.DebugFormat(
313 // "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
314 // s.RegionInfo.RegionName, destination.RegionHandle);
315  
316 m_scenes[originId].EntityTransferModule.AgentArrivedAtDestination(agentId);
317 return true;
318 }
319  
320 //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin);
321 return false;
322 }
323  
324 public bool CloseAgent(GridRegion destination, UUID id, string auth_token)
325 {
326 if (destination == null)
327 return false;
328  
329 if (m_scenes.ContainsKey(destination.RegionID))
330 {
331 // m_log.DebugFormat(
332 // "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
333 // s.RegionInfo.RegionName, destination.RegionHandle);
334  
335 m_scenes[destination.RegionID].CloseAgent(id, false, auth_token);
336 return true;
337 }
338  
339 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
340 return false;
341 }
342  
343 /**
344 * Object-related communications
345 */
346  
347 public bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog, bool isLocalCall)
348 {
349 if (destination == null)
350 return false;
351  
352 if (m_scenes.ContainsKey(destination.RegionID))
353 {
354 // m_log.DebugFormat(
355 // "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
356 // s.RegionInfo.RegionName, destination.RegionHandle);
357  
358 Scene s = m_scenes[destination.RegionID];
359  
360 if (isLocalCall)
361 {
362 // We need to make a local copy of the object
363 ISceneObject sogClone = sog.CloneForNewScene();
364 sogClone.SetState(sog.GetStateSnapshot(), s);
365 return s.IncomingCreateObject(newPosition, sogClone);
366 }
367 else
368 {
369 // Use the object as it came through the wire
370 return s.IncomingCreateObject(newPosition, sog);
371 }
372 }
373  
374 return false;
375 }
376  
377 #endregion
378  
379 #region Misc
380  
381 public bool IsLocalRegion(ulong regionhandle)
382 {
383 foreach (Scene s in m_scenes.Values)
384 if (s.RegionInfo.RegionHandle == regionhandle)
385 return true;
386  
387 return false;
388 }
389  
390 public bool IsLocalRegion(UUID id)
391 {
392 return m_scenes.ContainsKey(id);
393 }
394  
395 #endregion
396 }
397 }