aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs357
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs300
2 files changed, 657 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
new file mode 100644
index 0000000..e913891
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
@@ -0,0 +1,357 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using log4net;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Services.Interfaces;
37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38
39namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
40{
41 public class LocalSimulationConnectorModule : ISharedRegionModule, ISimulationService
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 private List<Scene> m_sceneList = new List<Scene>();
45
46 private IEntityTransferModule m_AgentTransferModule;
47 protected IEntityTransferModule AgentTransferModule
48 {
49 get
50 {
51 if (m_AgentTransferModule == null)
52 m_AgentTransferModule = m_sceneList[0].RequestModuleInterface<IEntityTransferModule>();
53 return m_AgentTransferModule;
54 }
55 }
56
57 private bool m_ModuleEnabled = false;
58
59 #region IRegionModule
60
61 public void Initialise(IConfigSource config)
62 {
63 IConfig moduleConfig = config.Configs["Modules"];
64 if (moduleConfig != null)
65 {
66 string name = moduleConfig.GetString("SimulationServices", "");
67 if (name == Name)
68 {
69 //IConfig userConfig = config.Configs["SimulationService"];
70 //if (userConfig == null)
71 //{
72 // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini");
73 // return;
74 //}
75
76 m_ModuleEnabled = true;
77
78 m_log.Info("[SIMULATION CONNECTOR]: Local simulation enabled");
79 }
80 }
81 }
82
83 public void PostInitialise()
84 {
85 }
86
87 public void AddRegion(Scene scene)
88 {
89 if (!m_ModuleEnabled)
90 return;
91
92 Init(scene);
93 scene.RegisterModuleInterface<ISimulationService>(this);
94 }
95
96 public void RemoveRegion(Scene scene)
97 {
98 if (!m_ModuleEnabled)
99 return;
100
101 RemoveScene(scene);
102 scene.UnregisterModuleInterface<ISimulationService>(this);
103 }
104
105 public void RegionLoaded(Scene scene)
106 {
107 }
108
109 public void Close()
110 {
111 }
112
113 public Type ReplaceableInterface
114 {
115 get { return null; }
116 }
117
118 public string Name
119 {
120 get { return "LocalSimulationConnectorModule"; }
121 }
122
123 /// <summary>
124 /// Can be called from other modules.
125 /// </summary>
126 /// <param name="scene"></param>
127 public void RemoveScene(Scene scene)
128 {
129 lock (m_sceneList)
130 {
131 if (m_sceneList.Contains(scene))
132 {
133 m_sceneList.Remove(scene);
134 }
135 }
136 }
137
138 /// <summary>
139 /// Can be called from other modules.
140 /// </summary>
141 /// <param name="scene"></param>
142 public void Init(Scene scene)
143 {
144 if (!m_sceneList.Contains(scene))
145 {
146 lock (m_sceneList)
147 {
148 m_sceneList.Add(scene);
149 }
150
151 }
152 }
153
154 #endregion /* IRegionModule */
155
156 #region ISimulation
157
158 public IScene GetScene(ulong regionhandle)
159 {
160 foreach (Scene s in m_sceneList)
161 {
162 if (s.RegionInfo.RegionHandle == regionhandle)
163 return s;
164 }
165 // ? weird. should not happen
166 return m_sceneList[0];
167 }
168
169 /**
170 * Agent-related communications
171 */
172
173 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason)
174 {
175 if (destination == null)
176 {
177 reason = "Given destination was null";
178 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: CreateAgent was given a null destination");
179 return false;
180 }
181
182 foreach (Scene s in m_sceneList)
183 {
184 if (s.RegionInfo.RegionHandle == destination.RegionHandle)
185 {
186 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Found region {0} to send SendCreateChildAgent", destination.RegionName);
187 return s.NewUserConnection(aCircuit, teleportFlags, out reason);
188 }
189 }
190
191 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Did not find region {0} for SendCreateChildAgent", destination.RegionName);
192 reason = "Did not find region " + destination.RegionName;
193 return false;
194 }
195
196 public bool UpdateAgent(GridRegion destination, AgentData cAgentData)
197 {
198 if (destination == null)
199 return false;
200
201 foreach (Scene s in m_sceneList)
202 {
203 if (s.RegionInfo.RegionHandle == destination.RegionHandle)
204 {
205 m_log.DebugFormat(
206 "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
207 s.RegionInfo.RegionName, destination.RegionHandle);
208
209 s.IncomingChildAgentDataUpdate(cAgentData);
210 return true;
211 }
212 }
213
214// m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle);
215 return false;
216 }
217
218 public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
219 {
220 if (destination == null)
221 return false;
222
223 foreach (Scene s in m_sceneList)
224 {
225 if (s.RegionInfo.RegionHandle == destination.RegionHandle)
226 {
227 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
228 s.IncomingChildAgentDataUpdate(cAgentData);
229 return true;
230 }
231 }
232 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
233 return false;
234 }
235
236 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
237 {
238 agent = null;
239
240 if (destination == null)
241 return false;
242
243 foreach (Scene s in m_sceneList)
244 {
245 if (s.RegionInfo.RegionHandle == destination.RegionHandle)
246 {
247 //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
248 return s.IncomingRetrieveRootAgent(id, out agent);
249 }
250 }
251 //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
252 return false;
253 }
254
255 public bool ReleaseAgent(UUID origin, UUID id, string uri)
256 {
257 foreach (Scene s in m_sceneList)
258 {
259 if (s.RegionInfo.RegionID == origin)
260 {
261 m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent");
262 AgentTransferModule.AgentArrivedAtDestination(id);
263 return true;
264// return s.IncomingReleaseAgent(id);
265 }
266 }
267 //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin);
268 return false;
269 }
270
271 public bool CloseAgent(GridRegion destination, UUID id)
272 {
273 if (destination == null)
274 return false;
275
276 foreach (Scene s in m_sceneList)
277 {
278 if (s.RegionInfo.RegionID == destination.RegionID)
279 {
280 //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent");
281 return s.IncomingCloseAgent(id);
282 }
283 }
284 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
285 return false;
286 }
287
288 /**
289 * Object-related communications
290 */
291
292 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
293 {
294 if (destination == null)
295 return false;
296
297 foreach (Scene s in m_sceneList)
298 {
299 if (s.RegionInfo.RegionHandle == destination.RegionHandle)
300 {
301 //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject");
302 if (isLocalCall)
303 {
304 // We need to make a local copy of the object
305 ISceneObject sogClone = sog.CloneForNewScene();
306 sogClone.SetState(sog.GetStateSnapshot(), s);
307 return s.IncomingCreateObject(sogClone);
308 }
309 else
310 {
311 // Use the object as it came through the wire
312 return s.IncomingCreateObject(sog);
313 }
314 }
315 }
316 return false;
317 }
318
319 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
320 {
321 if (destination == null)
322 return false;
323
324 foreach (Scene s in m_sceneList)
325 {
326 if (s.RegionInfo.RegionHandle == destination.RegionHandle)
327 {
328 return s.IncomingCreateObject(userID, itemID);
329 }
330 }
331 return false;
332 }
333
334
335 #endregion /* IInterregionComms */
336
337 #region Misc
338
339 public bool IsLocalRegion(ulong regionhandle)
340 {
341 foreach (Scene s in m_sceneList)
342 if (s.RegionInfo.RegionHandle == regionhandle)
343 return true;
344 return false;
345 }
346
347 public bool IsLocalRegion(UUID id)
348 {
349 foreach (Scene s in m_sceneList)
350 if (s.RegionInfo.RegionID == id)
351 return true;
352 return false;
353 }
354
355 #endregion
356 }
357}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
new file mode 100644
index 0000000..2b1f815
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
@@ -0,0 +1,300 @@
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.Serialization;
43using OpenSim.Services.Interfaces;
44using OpenSim.Services.Connectors.Simulation;
45using GridRegion = OpenSim.Services.Interfaces.GridRegion;
46
47namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
48{
49 public class RemoteSimulationConnectorModule : ISharedRegionModule, ISimulationService
50 {
51 private bool initialized = false;
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 protected bool m_enabled = false;
55 protected Scene m_aScene;
56 // RemoteSimulationConnector does not care about local regions; it delegates that to the Local module
57 protected LocalSimulationConnectorModule m_localBackend;
58 protected SimulationServiceConnector m_remoteConnector;
59
60 protected bool m_safemode;
61 protected IPAddress m_thisIP;
62
63 #region IRegionModule
64
65 public virtual void Initialise(IConfigSource config)
66 {
67
68 IConfig moduleConfig = config.Configs["Modules"];
69 if (moduleConfig != null)
70 {
71 string name = moduleConfig.GetString("SimulationServices", "");
72 if (name == Name)
73 {
74 //IConfig userConfig = config.Configs["SimulationService"];
75 //if (userConfig == null)
76 //{
77 // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini");
78 // return;
79 //}
80
81 m_remoteConnector = new SimulationServiceConnector();
82
83 m_enabled = true;
84
85 m_log.Info("[SIMULATION CONNECTOR]: Remote simulation enabled");
86 }
87 }
88 }
89
90 public virtual void PostInitialise()
91 {
92 }
93
94 public virtual void Close()
95 {
96 }
97
98 public void AddRegion(Scene scene)
99 {
100 if (!m_enabled)
101 return;
102
103 if (!initialized)
104 {
105 InitOnce(scene);
106 initialized = true;
107 }
108 InitEach(scene);
109 }
110
111 public void RemoveRegion(Scene scene)
112 {
113 if (m_enabled)
114 {
115 m_localBackend.RemoveScene(scene);
116 scene.UnregisterModuleInterface<ISimulationService>(this);
117 }
118 }
119
120 public void RegionLoaded(Scene scene)
121 {
122 if (!m_enabled)
123 return;
124 }
125
126 public Type ReplaceableInterface
127 {
128 get { return null; }
129 }
130
131 public virtual string Name
132 {
133 get { return "RemoteSimulationConnectorModule"; }
134 }
135
136 protected virtual void InitEach(Scene scene)
137 {
138 m_localBackend.Init(scene);
139 scene.RegisterModuleInterface<ISimulationService>(this);
140 }
141
142 protected virtual void InitOnce(Scene scene)
143 {
144 m_localBackend = new LocalSimulationConnectorModule();
145 m_aScene = scene;
146 //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService);
147 m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName);
148 }
149
150 #endregion /* IRegionModule */
151
152 #region IInterregionComms
153
154 public IScene GetScene(ulong handle)
155 {
156 return m_localBackend.GetScene(handle);
157 }
158
159 /**
160 * Agent-related communications
161 */
162
163 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, 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(destination, aCircuit, teleportFlags, out reason))
174 return true;
175
176 // else do the remote thing
177 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
178 {
179 //m_regionClient.SendUserInformation(regInfo, aCircuit);
180 return m_remoteConnector.CreateAgent(destination, aCircuit, teleportFlags, out reason);
181 }
182 return false;
183 }
184
185 public bool UpdateAgent(GridRegion destination, AgentData cAgentData)
186 {
187 if (destination == null)
188 return false;
189
190 // Try local first
191 if (m_localBackend.UpdateAgent(destination, cAgentData))
192 return true;
193
194 // else do the remote thing
195 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
196 return m_remoteConnector.UpdateAgent(destination, cAgentData);
197
198 return false;
199
200 }
201
202 public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
203 {
204 if (destination == null)
205 return false;
206
207 // Try local first
208 if (m_localBackend.UpdateAgent(destination, cAgentData))
209 return true;
210
211 // else do the remote thing
212 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
213 return m_remoteConnector.UpdateAgent(destination, cAgentData);
214
215 return false;
216
217 }
218
219 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
220 {
221 agent = null;
222
223 if (destination == null)
224 return false;
225
226 // Try local first
227 if (m_localBackend.RetrieveAgent(destination, id, out agent))
228 return true;
229
230 // else do the remote thing
231 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
232 return m_remoteConnector.RetrieveAgent(destination, id, out agent);
233
234 return false;
235
236 }
237
238 public bool ReleaseAgent(UUID origin, UUID id, string uri)
239 {
240 // Try local first
241 if (m_localBackend.ReleaseAgent(origin, id, uri))
242 return true;
243
244 // else do the remote thing
245 if (!m_localBackend.IsLocalRegion(origin))
246 return m_remoteConnector.ReleaseAgent(origin, id, uri);
247
248 return false;
249 }
250
251
252 public bool CloseAgent(GridRegion destination, UUID id)
253 {
254 if (destination == null)
255 return false;
256
257 // Try local first
258 if (m_localBackend.CloseAgent(destination, id))
259 return true;
260
261 // else do the remote thing
262 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
263 return m_remoteConnector.CloseAgent(destination, id);
264
265 return false;
266 }
267
268 /**
269 * Object-related communications
270 */
271
272 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
273 {
274 if (destination == null)
275 return false;
276
277 // Try local first
278 if (m_localBackend.CreateObject(destination, sog, isLocalCall))
279 {
280 //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded");
281 return true;
282 }
283
284 // else do the remote thing
285 if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
286 return m_remoteConnector.CreateObject(destination, sog, isLocalCall);
287
288 return false;
289 }
290
291 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
292 {
293 // Not Implemented
294 return false;
295 }
296
297 #endregion /* IInterregionComms */
298
299 }
300}