diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs | 298 |
1 files changed, 298 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..430cc6e --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs | |||
@@ -0,0 +1,298 @@ | |||
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 | |||
38 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation | ||
39 | { | ||
40 | public class LocalSimulationConnectorModule : ISharedRegionModule, ISimulationService | ||
41 | { | ||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | private List<Scene> m_sceneList = new List<Scene>(); | ||
44 | |||
45 | |||
46 | #region IRegionModule | ||
47 | |||
48 | public void Initialise(IConfigSource config) | ||
49 | { | ||
50 | // This module is always on | ||
51 | m_log.Debug("[LOCAL SIMULATION]: Enabling LocalSimulation module"); | ||
52 | } | ||
53 | |||
54 | public void PostInitialise() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | public void AddRegion(Scene scene) | ||
59 | { | ||
60 | } | ||
61 | |||
62 | public void RemoveRegion(Scene scene) | ||
63 | { | ||
64 | RemoveScene(scene); | ||
65 | } | ||
66 | |||
67 | public void RegionLoaded(Scene scene) | ||
68 | { | ||
69 | Init(scene); | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public Type ReplaceableInterface | ||
77 | { | ||
78 | get { return null; } | ||
79 | } | ||
80 | |||
81 | public string Name | ||
82 | { | ||
83 | get { return "LocalSimulationConnectorModule"; } | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Can be called from other modules. | ||
88 | /// </summary> | ||
89 | /// <param name="scene"></param> | ||
90 | public void RemoveScene(Scene scene) | ||
91 | { | ||
92 | lock (m_sceneList) | ||
93 | { | ||
94 | if (m_sceneList.Contains(scene)) | ||
95 | { | ||
96 | m_sceneList.Remove(scene); | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Can be called from other modules. | ||
103 | /// </summary> | ||
104 | /// <param name="scene"></param> | ||
105 | public void Init(Scene scene) | ||
106 | { | ||
107 | if (!m_sceneList.Contains(scene)) | ||
108 | { | ||
109 | lock (m_sceneList) | ||
110 | { | ||
111 | m_sceneList.Add(scene); | ||
112 | scene.RegisterModuleInterface<ISimulationService>(this); | ||
113 | } | ||
114 | |||
115 | } | ||
116 | } | ||
117 | |||
118 | #endregion /* IRegionModule */ | ||
119 | |||
120 | #region ISimulation | ||
121 | |||
122 | /** | ||
123 | * Agent-related communications | ||
124 | */ | ||
125 | |||
126 | public bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
127 | { | ||
128 | |||
129 | foreach (Scene s in m_sceneList) | ||
130 | { | ||
131 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
132 | { | ||
133 | // m_log.DebugFormat("[LOCAL COMMS]: Found region {0} to send SendCreateChildAgent", regionHandle); | ||
134 | return s.NewUserConnection(aCircuit, teleportFlags, out reason); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for SendCreateChildAgent", regionHandle); | ||
139 | uint x = 0, y = 0; | ||
140 | Utils.LongToUInts(regionHandle, out x, out y); | ||
141 | reason = "Did not find region " + x + "-" + y; | ||
142 | return false; | ||
143 | } | ||
144 | |||
145 | public bool UpdateAgent(ulong regionHandle, AgentData cAgentData) | ||
146 | { | ||
147 | foreach (Scene s in m_sceneList) | ||
148 | { | ||
149 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
150 | { | ||
151 | //m_log.DebugFormat( | ||
152 | // "[LOCAL COMMS]: Found region {0} {1} to send ChildAgentUpdate", | ||
153 | // s.RegionInfo.RegionName, regionHandle); | ||
154 | |||
155 | s.IncomingChildAgentDataUpdate(cAgentData); | ||
156 | return true; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle); | ||
161 | return false; | ||
162 | } | ||
163 | |||
164 | public bool UpdateAgent(ulong regionHandle, AgentPosition cAgentData) | ||
165 | { | ||
166 | foreach (Scene s in m_sceneList) | ||
167 | { | ||
168 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
169 | { | ||
170 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); | ||
171 | s.IncomingChildAgentDataUpdate(cAgentData); | ||
172 | return true; | ||
173 | } | ||
174 | } | ||
175 | //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); | ||
176 | return false; | ||
177 | } | ||
178 | |||
179 | public bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent) | ||
180 | { | ||
181 | agent = null; | ||
182 | foreach (Scene s in m_sceneList) | ||
183 | { | ||
184 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
185 | { | ||
186 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); | ||
187 | return s.IncomingRetrieveRootAgent(id, out agent); | ||
188 | } | ||
189 | } | ||
190 | //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); | ||
191 | return false; | ||
192 | } | ||
193 | |||
194 | public bool ReleaseAgent(ulong regionHandle, UUID id, string uri) | ||
195 | { | ||
196 | //uint x, y; | ||
197 | //Utils.LongToUInts(regionHandle, out x, out y); | ||
198 | //x = x / Constants.RegionSize; | ||
199 | //y = y / Constants.RegionSize; | ||
200 | //m_log.Debug("\n >>> Local SendReleaseAgent " + x + "-" + y); | ||
201 | foreach (Scene s in m_sceneList) | ||
202 | { | ||
203 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
204 | { | ||
205 | //m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); | ||
206 | return s.IncomingReleaseAgent(id); | ||
207 | } | ||
208 | } | ||
209 | //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent"); | ||
210 | return false; | ||
211 | } | ||
212 | |||
213 | public bool CloseAgent(ulong regionHandle, UUID id) | ||
214 | { | ||
215 | //uint x, y; | ||
216 | //Utils.LongToUInts(regionHandle, out x, out y); | ||
217 | //x = x / Constants.RegionSize; | ||
218 | //y = y / Constants.RegionSize; | ||
219 | //m_log.Debug("\n >>> Local SendCloseAgent " + x + "-" + y); | ||
220 | foreach (Scene s in m_sceneList) | ||
221 | { | ||
222 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
223 | { | ||
224 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent"); | ||
225 | return s.IncomingCloseAgent(id); | ||
226 | } | ||
227 | } | ||
228 | //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); | ||
229 | return false; | ||
230 | } | ||
231 | |||
232 | /** | ||
233 | * Object-related communications | ||
234 | */ | ||
235 | |||
236 | public bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall) | ||
237 | { | ||
238 | foreach (Scene s in m_sceneList) | ||
239 | { | ||
240 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
241 | { | ||
242 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject"); | ||
243 | if (isLocalCall) | ||
244 | { | ||
245 | // We need to make a local copy of the object | ||
246 | ISceneObject sogClone = sog.CloneForNewScene(); | ||
247 | sogClone.SetState(sog.GetStateSnapshot(), s); | ||
248 | return s.IncomingCreateObject(sogClone); | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | // Use the object as it came through the wire | ||
253 | return s.IncomingCreateObject(sog); | ||
254 | } | ||
255 | } | ||
256 | } | ||
257 | return false; | ||
258 | } | ||
259 | |||
260 | public bool CreateObject(ulong regionHandle, UUID userID, UUID itemID) | ||
261 | { | ||
262 | foreach (Scene s in m_sceneList) | ||
263 | { | ||
264 | if (s.RegionInfo.RegionHandle == regionHandle) | ||
265 | { | ||
266 | return s.IncomingCreateObject(userID, itemID); | ||
267 | } | ||
268 | } | ||
269 | return false; | ||
270 | } | ||
271 | |||
272 | |||
273 | #endregion /* IInterregionComms */ | ||
274 | |||
275 | #region Misc | ||
276 | |||
277 | public IScene GetScene(ulong regionhandle) | ||
278 | { | ||
279 | foreach (Scene s in m_sceneList) | ||
280 | { | ||
281 | if (s.RegionInfo.RegionHandle == regionhandle) | ||
282 | return s; | ||
283 | } | ||
284 | // ? weird. should not happen | ||
285 | return m_sceneList[0]; | ||
286 | } | ||
287 | |||
288 | public bool IsLocalRegion(ulong regionhandle) | ||
289 | { | ||
290 | foreach (Scene s in m_sceneList) | ||
291 | if (s.RegionInfo.RegionHandle == regionhandle) | ||
292 | return true; | ||
293 | return false; | ||
294 | } | ||
295 | |||
296 | #endregion | ||
297 | } | ||
298 | } | ||