OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
RemoteSimulationConnector.cs
Go to the documentation of this file.
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.IO;
32 using System.Net;
33 using System.Reflection;
34 using System.Text;
35 using log4net;
36 using Mono.Addins;
37 using Nini.Config;
38 using OpenMetaverse;
39 using OpenMetaverse.StructuredData;
40 using OpenSim.Framework;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Region.Framework.Scenes.Serialization;
44 using OpenSim.Services.Interfaces;
45 using OpenSim.Services.Connectors.Simulation;
47 
48 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
49 {
50  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteSimulationConnectorModule")]
52  {
53  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 
55  private bool initialized = false;
56  protected bool m_enabled = false;
57  protected Scene m_aScene;
58  // RemoteSimulationConnector does not care about local regions; it delegates that to the Local module
61 
62  protected bool m_safemode;
63 
64  #region Region Module interface
65 
66  public virtual void Initialise(IConfigSource configSource)
67  {
68  IConfig moduleConfig = configSource.Configs["Modules"];
69  if (moduleConfig != null)
70  {
71  string name = moduleConfig.GetString("SimulationServices", "");
72  if (name == Name)
73  {
74  m_localBackend = new LocalSimulationConnectorModule();
75 
76  m_localBackend.InitialiseService(configSource);
77 
78  m_remoteConnector = new SimulationServiceConnector();
79 
80  m_enabled = true;
81 
82  m_log.Info("[REMOTE SIMULATION CONNECTOR]: Remote simulation enabled.");
83  }
84  }
85  }
86 
87  public virtual void PostInitialise()
88  {
89  }
90 
91  public virtual void Close()
92  {
93  }
94 
95  public void AddRegion(Scene scene)
96  {
97  if (!m_enabled)
98  return;
99 
100  if (!initialized)
101  {
102  InitOnce(scene);
103  initialized = true;
104  }
105  InitEach(scene);
106  }
107 
108  public void RemoveRegion(Scene scene)
109  {
110  if (m_enabled)
111  {
112  m_localBackend.RemoveScene(scene);
113  scene.UnregisterModuleInterface<ISimulationService>(this);
114  }
115  }
116 
117  public void RegionLoaded(Scene scene)
118  {
119  if (!m_enabled)
120  return;
121  }
122 
123  public Type ReplaceableInterface
124  {
125  get { return null; }
126  }
127 
128  public virtual string Name
129  {
130  get { return "RemoteSimulationConnectorModule"; }
131  }
132 
133  protected virtual void InitEach(Scene scene)
134  {
135  m_localBackend.Init(scene);
136  scene.RegisterModuleInterface<ISimulationService>(this);
137  }
138 
139  protected virtual void InitOnce(Scene scene)
140  {
141  m_aScene = scene;
142  //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService);
143  }
144 
145  #endregion
146 
147  #region ISimulationService
148 
149  public IScene GetScene(UUID regionId)
150  {
151  return m_localBackend.GetScene(regionId);
152  }
153 
155  {
156  return m_localBackend;
157  }
158 
163  public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, EntityTransferContext ctx, out string reason)
164  {
165  if (destination == null)
166  {
167  reason = "Given destination was null";
168  m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent was given a null destination");
169  return false;
170  }
171 
172  // Try local first
173  if (m_localBackend.CreateAgent(source, destination, aCircuit, teleportFlags, ctx, out reason))
174  return true;
175 
176  // else do the remote thing
177  if (!m_localBackend.IsLocalRegion(destination.RegionID))
178  {
179  return m_remoteConnector.CreateAgent(source, destination, aCircuit, teleportFlags, ctx, out reason);
180  }
181  return false;
182  }
183 
184  public bool UpdateAgent(GridRegion destination, AgentData cAgentData, EntityTransferContext ctx)
185  {
186  if (destination == null)
187  return false;
188 
189  // Try local first
190  if (m_localBackend.IsLocalRegion(destination.RegionID))
191  return m_localBackend.UpdateAgent(destination, cAgentData, ctx);
192 
193  return m_remoteConnector.UpdateAgent(destination, cAgentData, ctx);
194  }
195 
196  public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
197  {
198  if (destination == null)
199  return false;
200 
201  // Try local first
202  if (m_localBackend.IsLocalRegion(destination.RegionID))
203  return m_localBackend.UpdateAgent(destination, cAgentData);
204 
205  return m_remoteConnector.UpdateAgent(destination, cAgentData);
206  }
207 
208  public bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, List<UUID> features, EntityTransferContext ctx, out string reason)
209  {
210  reason = "Communications failure";
211 
212  if (destination == null)
213  return false;
214 
215  // Try local first
216  if (m_localBackend.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, features, ctx, out reason))
217  return true;
218 
219  // else do the remote thing
220  if (!m_localBackend.IsLocalRegion(destination.RegionID))
221  return m_remoteConnector.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, features, ctx, out reason);
222 
223  return false;
224  }
225 
226  public bool ReleaseAgent(UUID origin, UUID id, string uri)
227  {
228  // Try local first
229  if (m_localBackend.ReleaseAgent(origin, id, uri))
230  return true;
231 
232  // else do the remote thing
233  if (!m_localBackend.IsLocalRegion(origin))
234  return m_remoteConnector.ReleaseAgent(origin, id, uri);
235 
236  return false;
237  }
238 
239  public bool CloseAgent(GridRegion destination, UUID id, string auth_token)
240  {
241  if (destination == null)
242  return false;
243 
244  // Try local first
245  if (m_localBackend.CloseAgent(destination, id, auth_token))
246  return true;
247 
248  // else do the remote thing
249  if (!m_localBackend.IsLocalRegion(destination.RegionID))
250  return m_remoteConnector.CloseAgent(destination, id, auth_token);
251 
252  return false;
253  }
254 
259  public bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog, bool isLocalCall)
260  {
261  if (destination == null)
262  return false;
263 
264  // Try local first
265  if (m_localBackend.CreateObject(destination, newPosition, sog, isLocalCall))
266  {
267  //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded");
268  return true;
269  }
270 
271  // else do the remote thing
272  if (!m_localBackend.IsLocalRegion(destination.RegionID))
273  return m_remoteConnector.CreateObject(destination, newPosition, sog, isLocalCall);
274 
275  return false;
276  }
277 
278  #endregion
279  }
280 }
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
bool QueryAccess(GridRegion destination, UUID agentID, string agentHomeURI, bool viaTeleport, Vector3 position, List< UUID > features, EntityTransferContext ctx, out string reason)
Returns whether a propspective user is allowed to visit the region.
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
bool CloseAgent(GridRegion destination, UUID id, string auth_token)
Close agent.
virtual void Initialise(IConfigSource configSource)
This is called to initialize the region module. For shared modules, this is called exactly once...
bool ReleaseAgent(UUID origin, UUID id, string uri)
Message from receiving region to departing region, telling it got contacted by the client...
OpenSim.Services.Interfaces.GridRegion GridRegion
virtual void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
virtual void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms.
bool UpdateAgent(GridRegion destination, AgentData cAgentData, EntityTransferContext ctx)
Full child agent update.
bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
Short child agent update, mostly for position.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, EntityTransferContext ctx, out string reason)
bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog, bool isLocalCall)