diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs | 356 |
1 files changed, 356 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..b7dc283 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs | |||
@@ -0,0 +1,356 @@ | |||
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.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | using log4net; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Framework.Communications.Clients; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
44 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using OpenSim.Services.Connectors.Simulation; | ||
47 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
48 | |||
49 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation | ||
50 | { | ||
51 | public class RemoteSimulationConnectorModule : ISharedRegionModule, ISimulationService | ||
52 | { | ||
53 | private bool initialized = false; | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
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 | ||
59 | protected LocalSimulationConnectorModule m_localBackend; | ||
60 | protected SimulationServiceConnector m_remoteConnector; | ||
61 | |||
62 | protected CommunicationsManager m_commsManager; | ||
63 | |||
64 | protected IHyperlinkService m_hyperlinkService; | ||
65 | |||
66 | protected bool m_safemode; | ||
67 | protected IPAddress m_thisIP; | ||
68 | |||
69 | #region IRegionModule | ||
70 | |||
71 | public virtual void Initialise(IConfigSource config) | ||
72 | { | ||
73 | |||
74 | IConfig moduleConfig = config.Configs["Modules"]; | ||
75 | if (moduleConfig != null) | ||
76 | { | ||
77 | string name = moduleConfig.GetString("SimulationServices", ""); | ||
78 | if (name == Name) | ||
79 | { | ||
80 | //IConfig userConfig = config.Configs["SimulationService"]; | ||
81 | //if (userConfig == null) | ||
82 | //{ | ||
83 | // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini"); | ||
84 | // return; | ||
85 | //} | ||
86 | |||
87 | m_remoteConnector = new SimulationServiceConnector(); | ||
88 | |||
89 | m_enabled = true; | ||
90 | |||
91 | m_log.Info("[SIMULATION CONNECTOR]: Remote simulation enabled"); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public virtual void PostInitialise() | ||
97 | { | ||
98 | } | ||
99 | |||
100 | public virtual void Close() | ||
101 | { | ||
102 | } | ||
103 | |||
104 | public void AddRegion(Scene scene) | ||
105 | { | ||
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 | { | ||
121 | if (!initialized) | ||
122 | { | ||
123 | InitOnce(scene); | ||
124 | initialized = true; | ||
125 | } | ||
126 | InitEach(scene); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | public Type ReplaceableInterface | ||
131 | { | ||
132 | get { return null; } | ||
133 | } | ||
134 | |||
135 | public virtual string Name | ||
136 | { | ||
137 | get { return "RemoteSimulationConnectorModule"; } | ||
138 | } | ||
139 | |||
140 | protected virtual void InitEach(Scene scene) | ||
141 | { | ||
142 | m_localBackend.Init(scene); | ||
143 | scene.RegisterModuleInterface<ISimulationService>(this); | ||
144 | } | ||
145 | |||
146 | protected virtual void InitOnce(Scene scene) | ||
147 | { | ||
148 | m_localBackend = new LocalSimulationConnectorModule(); | ||
149 | m_commsManager = scene.CommsManager; | ||
150 | m_aScene = scene; | ||
151 | m_hyperlinkService = m_aScene.RequestModuleInterface<IHyperlinkService>(); | ||
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(GridRegion destination, UUID id, string uri) | ||
245 | { | ||
246 | if (destination == null) | ||
247 | return false; | ||
248 | |||
249 | // Try local first | ||
250 | if (m_localBackend.ReleaseAgent(destination, id, uri)) | ||
251 | return true; | ||
252 | |||
253 | // else do the remote thing | ||
254 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
255 | return m_remoteConnector.ReleaseAgent(destination, id, uri); | ||
256 | |||
257 | return false; | ||
258 | } | ||
259 | |||
260 | |||
261 | public bool CloseAgent(GridRegion destination, UUID id) | ||
262 | { | ||
263 | if (destination == null) | ||
264 | return false; | ||
265 | |||
266 | // Try local first | ||
267 | if (m_localBackend.CloseAgent(destination, id)) | ||
268 | return true; | ||
269 | |||
270 | // else do the remote thing | ||
271 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
272 | return m_remoteConnector.CloseAgent(destination, id); | ||
273 | |||
274 | return false; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * Object-related communications | ||
279 | */ | ||
280 | |||
281 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) | ||
282 | { | ||
283 | if (destination == null) | ||
284 | return false; | ||
285 | |||
286 | // Try local first | ||
287 | if (m_localBackend.CreateObject(destination, sog, true)) | ||
288 | { | ||
289 | //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded"); | ||
290 | return true; | ||
291 | } | ||
292 | |||
293 | // else do the remote thing | ||
294 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
295 | return m_remoteConnector.CreateObject(destination, sog, isLocalCall); | ||
296 | |||
297 | return false; | ||
298 | } | ||
299 | |||
300 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) | ||
301 | { | ||
302 | // Not Implemented | ||
303 | return false; | ||
304 | } | ||
305 | |||
306 | #endregion /* IInterregionComms */ | ||
307 | |||
308 | |||
309 | protected class RegionToRegionClient : RegionClient | ||
310 | { | ||
311 | Scene m_aScene = null; | ||
312 | IHyperlinkService m_hyperlinkService; | ||
313 | |||
314 | public RegionToRegionClient(Scene s, IHyperlinkService hyperService) | ||
315 | { | ||
316 | m_aScene = s; | ||
317 | m_hyperlinkService = hyperService; | ||
318 | } | ||
319 | |||
320 | public override ulong GetRegionHandle(ulong handle) | ||
321 | { | ||
322 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | ||
323 | { | ||
324 | if (m_hyperlinkService != null) | ||
325 | return m_hyperlinkService.FindRegionHandle(handle); | ||
326 | } | ||
327 | |||
328 | return handle; | ||
329 | } | ||
330 | |||
331 | public override bool IsHyperlink(ulong handle) | ||
332 | { | ||
333 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | ||
334 | { | ||
335 | if ((m_hyperlinkService != null) && (m_hyperlinkService.GetHyperlinkRegion(handle) != null)) | ||
336 | return true; | ||
337 | } | ||
338 | return false; | ||
339 | } | ||
340 | |||
341 | public override void SendUserInformation(GridRegion regInfo, AgentCircuitData aCircuit) | ||
342 | { | ||
343 | if (m_hyperlinkService != null) | ||
344 | m_hyperlinkService.SendUserInformation(regInfo, aCircuit); | ||
345 | |||
346 | } | ||
347 | |||
348 | public override void AdjustUserInformation(AgentCircuitData aCircuit) | ||
349 | { | ||
350 | if (m_hyperlinkService != null) | ||
351 | m_hyperlinkService.AdjustUserInformation(aCircuit); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | } | ||
356 | } | ||