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