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