diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs | 300 |
1 files changed, 300 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..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 | |||
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.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
43 | using OpenSim.Services.Interfaces; | ||
44 | using OpenSim.Services.Connectors.Simulation; | ||
45 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
46 | |||
47 | namespace 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 | } | ||