aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs306
1 files changed, 306 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
new file mode 100644
index 0000000..227c37f
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
@@ -0,0 +1,306 @@
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
28using System;
29using System.Collections;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using log4net;
35using Nini.Config;
36using OpenMetaverse;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Scenes.Hypergrid;
43using OpenSim.Region.Framework.Scenes.Serialization;
44using OpenSim.Services.Interfaces;
45using OpenSim.Services.Connectors.Simulation;
46using GridRegion = OpenSim.Services.Interfaces.GridRegion;
47
48namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
49{
50 public class RemoteSimulationConnectorModule : ISharedRegionModule, ISimulationService
51 {
52 private bool initialized = false;
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 protected bool m_enabled = false;
56 protected Scene m_aScene;
57 // RemoteSimulationConnector does not care about local regions; it delegates that to the Local module
58 protected LocalSimulationConnectorModule m_localBackend;
59 protected SimulationServiceConnector m_remoteConnector;
60
61 protected IHyperlinkService m_hyperlinkService;
62
63 protected bool m_safemode;
64 protected IPAddress m_thisIP;
65
66 #region IRegionModule
67
68 public virtual void Initialise(IConfigSource config)
69 {
70
71 IConfig moduleConfig = config.Configs["Modules"];
72 if (moduleConfig != null)
73 {
74 string name = moduleConfig.GetString("SimulationServices", "");
75 if (name == Name)
76 {
77 //IConfig userConfig = config.Configs["SimulationService"];
78 //if (userConfig == null)
79 //{
80 // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini");
81 // return;
82 //}
83
84 m_remoteConnector = new SimulationServiceConnector();
85
86 m_enabled = true;
87
88 m_log.Info("[SIMULATION CONNECTOR]: Remote simulation enabled");
89 }
90 }
91 }
92
93 public virtual void PostInitialise()
94 {
95 }
96
97 public virtual void Close()
98 {
99 }
100
101 public void AddRegion(Scene scene)
102 {
103 if (!m_enabled)
104 return;
105
106 if (!initialized)
107 {
108 InitOnce(scene);
109 initialized = true;
110 }
111 InitEach(scene);
112 }
113
114 public void RemoveRegion(Scene scene)
115 {
116 if (m_enabled)
117 {
118 m_localBackend.RemoveScene(scene);
119 scene.UnregisterModuleInterface<ISimulationService>(this);
120 }
121 }
122
123 public void RegionLoaded(Scene scene)
124 {
125 if (!m_enabled)
126 return;
127
128 m_hyperlinkService = m_aScene.RequestModuleInterface<IHyperlinkService>();
129
130 }
131
132 public Type ReplaceableInterface
133 {
134 get { return null; }
135 }
136
137 public virtual string Name
138 {
139 get { return "RemoteSimulationConnectorModule"; }
140 }
141
142 protected virtual void InitEach(Scene scene)
143 {
144 m_localBackend.Init(scene);
145 scene.RegisterModuleInterface<ISimulationService>(this);
146 }
147
148 protected virtual void InitOnce(Scene scene)
149 {
150 m_localBackend = new LocalSimulationConnectorModule();
151 m_aScene = scene;
152 //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService);
153 m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName);
154 }
155
156 #endregion /* IRegionModule */
157
158 #region IInterregionComms
159
160 public IScene GetScene(ulong handle)
161 {
162 return m_localBackend.GetScene(handle);
163 }
164
165 /**
166 * Agent-related communications
167 */
168
169 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason)
170 {
171 if (destination == null)
172 {
173 reason = "Given destination was null";
174 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent was given a null destination");
175 return false;
176 }
177
178 // Try local first
179 if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, out reason))
180 return true;
181
182 // else do the remote thing
183 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
184 {
185 //m_regionClient.SendUserInformation(regInfo, aCircuit);
186 return m_remoteConnector.CreateAgent(destination, aCircuit, teleportFlags, out reason);
187 }
188 return false;
189 }
190
191 public bool UpdateAgent(GridRegion destination, AgentData cAgentData)
192 {
193 if (destination == null)
194 return false;
195
196 // Try local first
197 if (m_localBackend.UpdateAgent(destination, cAgentData))
198 return true;
199
200 // else do the remote thing
201 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
202 return m_remoteConnector.UpdateAgent(destination, cAgentData);
203
204 return false;
205
206 }
207
208 public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
209 {
210 if (destination == null)
211 return false;
212
213 // Try local first
214 if (m_localBackend.UpdateAgent(destination, cAgentData))
215 return true;
216
217 // else do the remote thing
218 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
219 return m_remoteConnector.UpdateAgent(destination, cAgentData);
220
221 return false;
222
223 }
224
225 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
226 {
227 agent = null;
228
229 if (destination == null)
230 return false;
231
232 // Try local first
233 if (m_localBackend.RetrieveAgent(destination, id, out agent))
234 return true;
235
236 // else do the remote thing
237 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
238 return m_remoteConnector.RetrieveAgent(destination, id, out agent);
239
240 return false;
241
242 }
243
244 public bool ReleaseAgent(UUID origin, UUID id, string uri)
245 {
246 // Try local first
247 if (m_localBackend.ReleaseAgent(origin, id, uri))
248 return true;
249
250 // else do the remote thing
251 if (!m_localBackend.IsLocalRegion(origin))
252 return m_remoteConnector.ReleaseAgent(origin, id, uri);
253
254 return false;
255 }
256
257
258 public bool CloseAgent(GridRegion destination, UUID id)
259 {
260 if (destination == null)
261 return false;
262
263 // Try local first
264 if (m_localBackend.CloseAgent(destination, id))
265 return true;
266
267 // else do the remote thing
268 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
269 return m_remoteConnector.CloseAgent(destination, id);
270
271 return false;
272 }
273
274 /**
275 * Object-related communications
276 */
277
278 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
279 {
280 if (destination == null)
281 return false;
282
283 // Try local first
284 if (m_localBackend.CreateObject(destination, sog, isLocalCall))
285 {
286 //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded");
287 return true;
288 }
289
290 // else do the remote thing
291 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
292 return m_remoteConnector.CreateObject(destination, sog, isLocalCall);
293
294 return false;
295 }
296
297 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
298 {
299 // Not Implemented
300 return false;
301 }
302
303 #endregion /* IInterregionComms */
304
305 }
306}