diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs | 339 |
1 files changed, 339 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..074bfb5 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs | |||
@@ -0,0 +1,339 @@ | |||
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.Reflection; | ||
30 | using log4net; | ||
31 | using Nini.Config; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | |||
39 | namespace 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 bool m_ModuleEnabled = false; | ||
47 | |||
48 | #region IRegionModule | ||
49 | |||
50 | public void Initialise(IConfigSource config) | ||
51 | { | ||
52 | IConfig moduleConfig = config.Configs["Modules"]; | ||
53 | if (moduleConfig != null) | ||
54 | { | ||
55 | string name = moduleConfig.GetString("SimulationServices", ""); | ||
56 | if (name == Name) | ||
57 | { | ||
58 | //IConfig userConfig = config.Configs["SimulationService"]; | ||
59 | //if (userConfig == null) | ||
60 | //{ | ||
61 | // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini"); | ||
62 | // return; | ||
63 | //} | ||
64 | |||
65 | m_ModuleEnabled = true; | ||
66 | |||
67 | m_log.Info("[SIMULATION CONNECTOR]: Local simulation enabled"); | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | public void PostInitialise() | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public void AddRegion(Scene scene) | ||
77 | { | ||
78 | if (!m_ModuleEnabled) | ||
79 | return; | ||
80 | |||
81 | Init(scene); | ||
82 | scene.RegisterModuleInterface<ISimulationService>(this); | ||
83 | } | ||
84 | |||
85 | public void RemoveRegion(Scene scene) | ||
86 | { | ||
87 | if (!m_ModuleEnabled) | ||
88 | return; | ||
89 | |||
90 | RemoveScene(scene); | ||
91 | scene.UnregisterModuleInterface<ISimulationService>(this); | ||
92 | } | ||
93 | |||
94 | public void RegionLoaded(Scene scene) | ||
95 | { | ||
96 | } | ||
97 | |||
98 | public void Close() | ||
99 | { | ||
100 | } | ||
101 | |||
102 | public Type ReplaceableInterface | ||
103 | { | ||
104 | get { return null; } | ||
105 | } | ||
106 | |||
107 | public string Name | ||
108 | { | ||
109 | get { return "LocalSimulationConnectorModule"; } | ||
110 | } | ||
111 | |||
112 | /// <summary> | ||
113 | /// Can be called from other modules. | ||
114 | /// </summary> | ||
115 | /// <param name="scene"></param> | ||
116 | public void RemoveScene(Scene scene) | ||
117 | { | ||
118 | lock (m_sceneList) | ||
119 | { | ||
120 | if (m_sceneList.Contains(scene)) | ||
121 | { | ||
122 | m_sceneList.Remove(scene); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /// <summary> | ||
128 | /// Can be called from other modules. | ||
129 | /// </summary> | ||
130 | /// <param name="scene"></param> | ||
131 | public void Init(Scene scene) | ||
132 | { | ||
133 | if (!m_sceneList.Contains(scene)) | ||
134 | { | ||
135 | lock (m_sceneList) | ||
136 | { | ||
137 | m_sceneList.Add(scene); | ||
138 | } | ||
139 | |||
140 | } | ||
141 | } | ||
142 | |||
143 | #endregion /* IRegionModule */ | ||
144 | |||
145 | #region ISimulation | ||
146 | |||
147 | public IScene GetScene(ulong regionhandle) | ||
148 | { | ||
149 | foreach (Scene s in m_sceneList) | ||
150 | { | ||
151 | if (s.RegionInfo.RegionHandle == regionhandle) | ||
152 | return s; | ||
153 | } | ||
154 | // ? weird. should not happen | ||
155 | return m_sceneList[0]; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * Agent-related communications | ||
160 | */ | ||
161 | |||
162 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
163 | { | ||
164 | if (destination == null) | ||
165 | { | ||
166 | reason = "Given destination was null"; | ||
167 | m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: CreateAgent was given a null destination"); | ||
168 | return false; | ||
169 | } | ||
170 | |||
171 | foreach (Scene s in m_sceneList) | ||
172 | { | ||
173 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
174 | { | ||
175 | // m_log.DebugFormat("[LOCAL COMMS]: Found region {0} to send SendCreateChildAgent", regionHandle); | ||
176 | return s.NewUserConnection(aCircuit, teleportFlags, out reason); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for SendCreateChildAgent", regionHandle); | ||
181 | reason = "Did not find region " + destination.RegionName; | ||
182 | return false; | ||
183 | } | ||
184 | |||
185 | public bool UpdateAgent(GridRegion destination, AgentData cAgentData) | ||
186 | { | ||
187 | if (destination == null) | ||
188 | return false; | ||
189 | |||
190 | foreach (Scene s in m_sceneList) | ||
191 | { | ||
192 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
193 | { | ||
194 | //m_log.DebugFormat( | ||
195 | // "[LOCAL COMMS]: Found region {0} {1} to send ChildAgentUpdate", | ||
196 | // s.RegionInfo.RegionName, regionHandle); | ||
197 | |||
198 | s.IncomingChildAgentDataUpdate(cAgentData); | ||
199 | return true; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle); | ||
204 | return false; | ||
205 | } | ||
206 | |||
207 | public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData) | ||
208 | { | ||
209 | if (destination == null) | ||
210 | return false; | ||
211 | |||
212 | foreach (Scene s in m_sceneList) | ||
213 | { | ||
214 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
215 | { | ||
216 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); | ||
217 | s.IncomingChildAgentDataUpdate(cAgentData); | ||
218 | return true; | ||
219 | } | ||
220 | } | ||
221 | //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); | ||
222 | return false; | ||
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 | foreach (Scene s in m_sceneList) | ||
233 | { | ||
234 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
235 | { | ||
236 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); | ||
237 | return s.IncomingRetrieveRootAgent(id, out agent); | ||
238 | } | ||
239 | } | ||
240 | //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); | ||
241 | return false; | ||
242 | } | ||
243 | |||
244 | public bool ReleaseAgent(GridRegion destination, UUID id, string uri) | ||
245 | { | ||
246 | if (destination == null) | ||
247 | return false; | ||
248 | |||
249 | foreach (Scene s in m_sceneList) | ||
250 | { | ||
251 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
252 | { | ||
253 | //m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); | ||
254 | return s.IncomingReleaseAgent(id); | ||
255 | } | ||
256 | } | ||
257 | //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent"); | ||
258 | return false; | ||
259 | } | ||
260 | |||
261 | public bool CloseAgent(GridRegion destination, UUID id) | ||
262 | { | ||
263 | if (destination == null) | ||
264 | return false; | ||
265 | |||
266 | foreach (Scene s in m_sceneList) | ||
267 | { | ||
268 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
269 | { | ||
270 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent"); | ||
271 | return s.IncomingCloseAgent(id); | ||
272 | } | ||
273 | } | ||
274 | //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); | ||
275 | return false; | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * Object-related communications | ||
280 | */ | ||
281 | |||
282 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) | ||
283 | { | ||
284 | if (destination == null) | ||
285 | return false; | ||
286 | |||
287 | foreach (Scene s in m_sceneList) | ||
288 | { | ||
289 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
290 | { | ||
291 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject"); | ||
292 | if (isLocalCall) | ||
293 | { | ||
294 | // We need to make a local copy of the object | ||
295 | ISceneObject sogClone = sog.CloneForNewScene(); | ||
296 | sogClone.SetState(sog.GetStateSnapshot(), s); | ||
297 | return s.IncomingCreateObject(sogClone); | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | // Use the object as it came through the wire | ||
302 | return s.IncomingCreateObject(sog); | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | return false; | ||
307 | } | ||
308 | |||
309 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) | ||
310 | { | ||
311 | if (destination == null) | ||
312 | return false; | ||
313 | |||
314 | foreach (Scene s in m_sceneList) | ||
315 | { | ||
316 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) | ||
317 | { | ||
318 | return s.IncomingCreateObject(userID, itemID); | ||
319 | } | ||
320 | } | ||
321 | return false; | ||
322 | } | ||
323 | |||
324 | |||
325 | #endregion /* IInterregionComms */ | ||
326 | |||
327 | #region Misc | ||
328 | |||
329 | public bool IsLocalRegion(ulong regionhandle) | ||
330 | { | ||
331 | foreach (Scene s in m_sceneList) | ||
332 | if (s.RegionInfo.RegionHandle == regionhandle) | ||
333 | return true; | ||
334 | return false; | ||
335 | } | ||
336 | |||
337 | #endregion | ||
338 | } | ||
339 | } | ||