clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 Mono.Addins; |
||
36 | using Nini.Config; |
||
37 | using OpenMetaverse; |
||
38 | using OpenMetaverse.StructuredData; |
||
39 | using OpenSim.Framework; |
||
40 | using OpenSim.Framework.Communications; |
||
41 | using OpenSim.Region.Framework.Interfaces; |
||
42 | using OpenSim.Region.Framework.Scenes; |
||
43 | using OpenSim.Region.Framework.Scenes.Serialization; |
||
44 | using OpenSim.Services.Interfaces; |
||
45 | using OpenSim.Services.Connectors.Simulation; |
||
46 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
47 | |||
48 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation |
||
49 | { |
||
50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteSimulationConnectorModule")] |
||
51 | public class RemoteSimulationConnectorModule : ISharedRegionModule, ISimulationService |
||
52 | { |
||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
54 | |||
55 | private bool initialized = false; |
||
56 | protected bool m_enabled = false; |
||
57 | protected Scene m_aScene; |
||
58 | // RemoteSimulationConnector does not care about local regions; it delegates that to the Local module |
||
59 | protected LocalSimulationConnectorModule m_localBackend; |
||
60 | protected SimulationServiceConnector m_remoteConnector; |
||
61 | |||
62 | protected bool m_safemode; |
||
63 | protected IPAddress m_thisIP; |
||
64 | |||
65 | #region Region Module interface |
||
66 | |||
67 | public virtual void Initialise(IConfigSource configSource) |
||
68 | { |
||
69 | IConfig moduleConfig = configSource.Configs["Modules"]; |
||
70 | if (moduleConfig != null) |
||
71 | { |
||
72 | string name = moduleConfig.GetString("SimulationServices", ""); |
||
73 | if (name == Name) |
||
74 | { |
||
75 | m_localBackend = new LocalSimulationConnectorModule(); |
||
76 | |||
77 | m_localBackend.InitialiseService(configSource); |
||
78 | |||
79 | m_remoteConnector = new SimulationServiceConnector(); |
||
80 | |||
81 | m_enabled = true; |
||
82 | |||
83 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Remote simulation enabled."); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | public virtual void PostInitialise() |
||
89 | { |
||
90 | } |
||
91 | |||
92 | public virtual void Close() |
||
93 | { |
||
94 | } |
||
95 | |||
96 | public void AddRegion(Scene scene) |
||
97 | { |
||
98 | if (!m_enabled) |
||
99 | return; |
||
100 | |||
101 | if (!initialized) |
||
102 | { |
||
103 | InitOnce(scene); |
||
104 | initialized = true; |
||
105 | } |
||
106 | InitEach(scene); |
||
107 | } |
||
108 | |||
109 | public void RemoveRegion(Scene scene) |
||
110 | { |
||
111 | if (m_enabled) |
||
112 | { |
||
113 | m_localBackend.RemoveScene(scene); |
||
114 | scene.UnregisterModuleInterface<ISimulationService>(this); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | public void RegionLoaded(Scene scene) |
||
119 | { |
||
120 | if (!m_enabled) |
||
121 | return; |
||
122 | } |
||
123 | |||
124 | public Type ReplaceableInterface |
||
125 | { |
||
126 | get { return null; } |
||
127 | } |
||
128 | |||
129 | public virtual string Name |
||
130 | { |
||
131 | get { return "RemoteSimulationConnectorModule"; } |
||
132 | } |
||
133 | |||
134 | protected virtual void InitEach(Scene scene) |
||
135 | { |
||
136 | m_localBackend.Init(scene); |
||
137 | scene.RegisterModuleInterface<ISimulationService>(this); |
||
138 | } |
||
139 | |||
140 | protected virtual void InitOnce(Scene scene) |
||
141 | { |
||
142 | m_aScene = scene; |
||
143 | //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService); |
||
144 | m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName); |
||
145 | } |
||
146 | |||
147 | #endregion |
||
148 | |||
149 | #region IInterregionComms |
||
150 | |||
151 | public IScene GetScene(UUID regionId) |
||
152 | { |
||
153 | return m_localBackend.GetScene(regionId); |
||
154 | } |
||
155 | |||
156 | public ISimulationService GetInnerService() |
||
157 | { |
||
158 | return m_localBackend; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Agent-related communications |
||
163 | */ |
||
164 | |||
165 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) |
||
166 | { |
||
167 | if (destination == null) |
||
168 | { |
||
169 | reason = "Given destination was null"; |
||
170 | m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent was given a null destination"); |
||
171 | return false; |
||
172 | } |
||
173 | |||
174 | // Try local first |
||
175 | if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, out reason)) |
||
176 | return true; |
||
177 | |||
178 | // else do the remote thing |
||
179 | if (!m_localBackend.IsLocalRegion(destination.RegionID)) |
||
180 | { |
||
181 | return m_remoteConnector.CreateAgent(destination, aCircuit, teleportFlags, out reason); |
||
182 | } |
||
183 | return false; |
||
184 | } |
||
185 | |||
186 | public bool UpdateAgent(GridRegion destination, AgentData cAgentData) |
||
187 | { |
||
188 | if (destination == null) |
||
189 | return false; |
||
190 | |||
191 | // Try local first |
||
192 | if (m_localBackend.IsLocalRegion(destination.RegionID)) |
||
193 | return m_localBackend.UpdateAgent(destination, cAgentData); |
||
194 | |||
195 | return m_remoteConnector.UpdateAgent(destination, cAgentData); |
||
196 | } |
||
197 | |||
198 | public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData) |
||
199 | { |
||
200 | if (destination == null) |
||
201 | return false; |
||
202 | |||
203 | // Try local first |
||
204 | if (m_localBackend.IsLocalRegion(destination.RegionID)) |
||
205 | return m_localBackend.UpdateAgent(destination, cAgentData); |
||
206 | |||
207 | return m_remoteConnector.UpdateAgent(destination, cAgentData); |
||
208 | } |
||
209 | |||
210 | public bool QueryAccess(GridRegion destination, UUID id, Vector3 position, out string version, out string reason) |
||
211 | { |
||
212 | reason = "Communications failure"; |
||
213 | version = "Unknown"; |
||
214 | |||
215 | if (destination == null) |
||
216 | return false; |
||
217 | |||
218 | // Try local first |
||
219 | if (m_localBackend.QueryAccess(destination, id, position, out version, out reason)) |
||
220 | return true; |
||
221 | |||
222 | // else do the remote thing |
||
223 | if (!m_localBackend.IsLocalRegion(destination.RegionID)) |
||
224 | return m_remoteConnector.QueryAccess(destination, id, position, out version, out reason); |
||
225 | |||
226 | return false; |
||
227 | } |
||
228 | |||
229 | public bool ReleaseAgent(UUID origin, UUID id, string uri) |
||
230 | { |
||
231 | // Try local first |
||
232 | if (m_localBackend.ReleaseAgent(origin, id, uri)) |
||
233 | return true; |
||
234 | |||
235 | // else do the remote thing |
||
236 | if (!m_localBackend.IsLocalRegion(origin)) |
||
237 | return m_remoteConnector.ReleaseAgent(origin, id, uri); |
||
238 | |||
239 | return false; |
||
240 | } |
||
241 | |||
242 | |||
243 | public bool CloseAgent(GridRegion destination, UUID id, string auth_token) |
||
244 | { |
||
245 | if (destination == null) |
||
246 | return false; |
||
247 | |||
248 | // Try local first |
||
249 | if (m_localBackend.CloseAgent(destination, id, auth_token)) |
||
250 | return true; |
||
251 | |||
252 | // else do the remote thing |
||
253 | if (!m_localBackend.IsLocalRegion(destination.RegionID)) |
||
254 | return m_remoteConnector.CloseAgent(destination, id, auth_token); |
||
255 | |||
256 | return false; |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Object-related communications |
||
261 | */ |
||
262 | |||
263 | public bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog, bool isLocalCall) |
||
264 | { |
||
265 | if (destination == null) |
||
266 | return false; |
||
267 | |||
268 | // Try local first |
||
269 | if (m_localBackend.CreateObject(destination, newPosition, sog, isLocalCall)) |
||
270 | { |
||
271 | //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded"); |
||
272 | return true; |
||
273 | } |
||
274 | |||
275 | // else do the remote thing |
||
276 | if (!m_localBackend.IsLocalRegion(destination.RegionID)) |
||
277 | return m_remoteConnector.CreateObject(destination, newPosition, sog, isLocalCall); |
||
278 | |||
279 | return false; |
||
280 | } |
||
281 | |||
282 | #endregion /* IInterregionComms */ |
||
283 | } |
||
284 | } |