diff options
Diffstat (limited to 'OpenSim/Services/Connectors')
3 files changed, 340 insertions, 331 deletions
diff --git a/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs b/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs new file mode 100644 index 0000000..9d01b47 --- /dev/null +++ b/OpenSim/Services/Connectors/Estate/EstateDataConnector.cs | |||
@@ -0,0 +1,340 @@ | |||
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.Net; | ||
30 | using System.Reflection; | ||
31 | |||
32 | using log4net; | ||
33 | |||
34 | using OpenMetaverse; | ||
35 | using Nini.Config; | ||
36 | |||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.ServiceAuth; | ||
39 | using OpenSim.Services.Connectors; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Server.Base; | ||
42 | |||
43 | namespace OpenSim.Service.Connectors | ||
44 | { | ||
45 | public class EstateDataRemoteConnector : BaseServiceConnector, IEstateDataService | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private string m_ServerURI = String.Empty; | ||
52 | private ExpiringCache<string, List<EstateSettings>> m_EstateCache = new ExpiringCache<string, List<EstateSettings>>(); | ||
53 | private const int EXPIRATION = 5 * 60; // 5 minutes in secs | ||
54 | |||
55 | public EstateDataRemoteConnector(IConfigSource source) | ||
56 | { | ||
57 | Initialise(source); | ||
58 | } | ||
59 | |||
60 | public virtual void Initialise(IConfigSource source) | ||
61 | { | ||
62 | IConfig gridConfig = source.Configs["EstateService"]; | ||
63 | if (gridConfig == null) | ||
64 | { | ||
65 | m_log.Error("[ESTATE CONNECTOR]: EstateService missing from OpenSim.ini"); | ||
66 | throw new Exception("Estate connector init error"); | ||
67 | } | ||
68 | |||
69 | string serviceURI = gridConfig.GetString("EstateServerURI", | ||
70 | String.Empty); | ||
71 | |||
72 | if (serviceURI == String.Empty) | ||
73 | { | ||
74 | m_log.Error("[ESTATE CONNECTOR]: No Server URI named in section EstateService"); | ||
75 | throw new Exception("Estate connector init error"); | ||
76 | } | ||
77 | m_ServerURI = serviceURI; | ||
78 | |||
79 | base.Initialise(source, "EstateService"); | ||
80 | } | ||
81 | |||
82 | #region IEstateDataService | ||
83 | |||
84 | public List<EstateSettings> LoadEstateSettingsAll() | ||
85 | { | ||
86 | string reply = string.Empty; | ||
87 | string uri = m_ServerURI + "/estates"; | ||
88 | |||
89 | reply = MakeRequest("GET", uri, string.Empty); | ||
90 | if (String.IsNullOrEmpty(reply)) | ||
91 | return new List<EstateSettings>(); | ||
92 | |||
93 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
94 | |||
95 | List<EstateSettings> estates = new List<EstateSettings>(); | ||
96 | if (replyData != null && replyData.Count > 0) | ||
97 | { | ||
98 | m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettingsAll returned {0} elements", replyData.Count); | ||
99 | Dictionary<string, object>.ValueCollection estateData = replyData.Values; | ||
100 | foreach (object r in estateData) | ||
101 | { | ||
102 | if (r is Dictionary<string, object>) | ||
103 | { | ||
104 | EstateSettings es = new EstateSettings((Dictionary<string, object>)r); | ||
105 | estates.Add(es); | ||
106 | } | ||
107 | } | ||
108 | m_EstateCache.AddOrUpdate("estates", estates, EXPIRATION); | ||
109 | } | ||
110 | else | ||
111 | m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettingsAll from {0} received null or zero response", uri); | ||
112 | |||
113 | return estates; | ||
114 | |||
115 | } | ||
116 | |||
117 | public List<int> GetEstatesAll() | ||
118 | { | ||
119 | List<int> eids = new List<int>(); | ||
120 | // If we don't have them, load them from the server | ||
121 | List<EstateSettings> estates = null; | ||
122 | if (!m_EstateCache.TryGetValue("estates", out estates)) | ||
123 | LoadEstateSettingsAll(); | ||
124 | |||
125 | foreach (EstateSettings es in estates) | ||
126 | eids.Add((int)es.EstateID); | ||
127 | |||
128 | return eids; | ||
129 | } | ||
130 | |||
131 | public List<int> GetEstates(string search) | ||
132 | { | ||
133 | // If we don't have them, load them from the server | ||
134 | List<EstateSettings> estates = null; | ||
135 | if (!m_EstateCache.TryGetValue("estates", out estates)) | ||
136 | LoadEstateSettingsAll(); | ||
137 | |||
138 | List<int> eids = new List<int>(); | ||
139 | foreach (EstateSettings es in estates) | ||
140 | if (es.EstateName == search) | ||
141 | eids.Add((int)es.EstateID); | ||
142 | |||
143 | return eids; | ||
144 | } | ||
145 | |||
146 | public List<int> GetEstatesByOwner(UUID ownerID) | ||
147 | { | ||
148 | // If we don't have them, load them from the server | ||
149 | List<EstateSettings> estates = null; | ||
150 | if (!m_EstateCache.TryGetValue("estates", out estates)) | ||
151 | LoadEstateSettingsAll(); | ||
152 | |||
153 | List<int> eids = new List<int>(); | ||
154 | foreach (EstateSettings es in estates) | ||
155 | if (es.EstateOwner == ownerID) | ||
156 | eids.Add((int)es.EstateID); | ||
157 | |||
158 | return eids; | ||
159 | } | ||
160 | |||
161 | public List<UUID> GetRegions(int estateID) | ||
162 | { | ||
163 | string reply = string.Empty; | ||
164 | // /estates/regions/?eid=int | ||
165 | string uri = m_ServerURI + "/estates/regions/?eid=" + estateID.ToString(); | ||
166 | |||
167 | reply = MakeRequest("GET", uri, string.Empty); | ||
168 | if (String.IsNullOrEmpty(reply)) | ||
169 | return new List<UUID>(); | ||
170 | |||
171 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
172 | |||
173 | List<UUID> regions = new List<UUID>(); | ||
174 | if (replyData != null && replyData.Count > 0) | ||
175 | { | ||
176 | m_log.DebugFormat("[ESTATE CONNECTOR]: GetRegions for estate {0} returned {1} elements", estateID, replyData.Count); | ||
177 | Dictionary<string, object>.ValueCollection data = replyData.Values; | ||
178 | foreach (object r in data) | ||
179 | { | ||
180 | UUID uuid = UUID.Zero; | ||
181 | if (UUID.TryParse(r.ToString(), out uuid)) | ||
182 | regions.Add(uuid); | ||
183 | } | ||
184 | } | ||
185 | else | ||
186 | m_log.DebugFormat("[ESTATE CONNECTOR]: GetRegions from {0} received null or zero response", uri); | ||
187 | |||
188 | return regions; | ||
189 | } | ||
190 | |||
191 | public EstateSettings LoadEstateSettings(UUID regionID, bool create) | ||
192 | { | ||
193 | string reply = string.Empty; | ||
194 | // /estates/estate/?region=uuid&create=[t|f] | ||
195 | string uri = m_ServerURI + string.Format("/estates/estate/?region={0}&create={1}", regionID, create); | ||
196 | |||
197 | reply = MakeRequest("GET", uri, string.Empty); | ||
198 | if (String.IsNullOrEmpty(reply)) | ||
199 | return null; | ||
200 | |||
201 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
202 | |||
203 | if (replyData != null && replyData.Count > 0) | ||
204 | { | ||
205 | m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettings({0}) returned {1} elements", regionID, replyData.Count); | ||
206 | EstateSettings es = new EstateSettings(replyData); | ||
207 | return es; | ||
208 | } | ||
209 | else | ||
210 | m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettings(regionID) from {0} received null or zero response", uri); | ||
211 | |||
212 | return null; | ||
213 | } | ||
214 | |||
215 | public EstateSettings LoadEstateSettings(int estateID) | ||
216 | { | ||
217 | string reply = string.Empty; | ||
218 | // /estates/estate/?eid=int | ||
219 | string uri = m_ServerURI + string.Format("/estates/estate/?eid={0}", estateID); | ||
220 | |||
221 | reply = MakeRequest("GET", uri, string.Empty); | ||
222 | if (String.IsNullOrEmpty(reply)) | ||
223 | return null; | ||
224 | |||
225 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
226 | |||
227 | if (replyData != null && replyData.Count > 0) | ||
228 | { | ||
229 | m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettings({0}) returned {1} elements", estateID, replyData.Count); | ||
230 | EstateSettings es = new EstateSettings(replyData); | ||
231 | return es; | ||
232 | } | ||
233 | else | ||
234 | m_log.DebugFormat("[ESTATE CONNECTOR]: LoadEstateSettings(estateID) from {0} received null or zero response", uri); | ||
235 | |||
236 | return null; | ||
237 | } | ||
238 | |||
239 | /// <summary> | ||
240 | /// Forbidden operation | ||
241 | /// </summary> | ||
242 | /// <returns></returns> | ||
243 | public EstateSettings CreateNewEstate() | ||
244 | { | ||
245 | // No can do | ||
246 | return null; | ||
247 | } | ||
248 | |||
249 | public void StoreEstateSettings(EstateSettings es) | ||
250 | { | ||
251 | string reply = string.Empty; | ||
252 | // /estates/estate/ | ||
253 | string uri = m_ServerURI + ("/estates/estate"); | ||
254 | |||
255 | Dictionary<string, object> formdata = es.ToMap(); | ||
256 | formdata["OP"] = "STORE"; | ||
257 | |||
258 | PostRequest(uri, formdata); | ||
259 | } | ||
260 | |||
261 | public bool LinkRegion(UUID regionID, int estateID) | ||
262 | { | ||
263 | string reply = string.Empty; | ||
264 | // /estates/estate/?eid=int®ion=uuid | ||
265 | string uri = m_ServerURI + String.Format("/estates/estate/?eid={0}®ion={1}", estateID, regionID); | ||
266 | |||
267 | Dictionary<string, object> formdata = new Dictionary<string, object>(); | ||
268 | formdata["OP"] = "LINK"; | ||
269 | return PostRequest(uri, formdata); | ||
270 | } | ||
271 | |||
272 | private bool PostRequest(string uri, Dictionary<string, object> sendData) | ||
273 | { | ||
274 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
275 | |||
276 | string reply = MakeRequest("POST", uri, reqString); | ||
277 | if (String.IsNullOrEmpty(reply)) | ||
278 | return false; | ||
279 | |||
280 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
281 | |||
282 | bool result = false; | ||
283 | if (replyData != null && replyData.Count > 0) | ||
284 | { | ||
285 | if (replyData.ContainsKey("Result")) | ||
286 | { | ||
287 | if (Boolean.TryParse(replyData["Result"].ToString(), out result)) | ||
288 | m_log.DebugFormat("[ESTATE CONNECTOR]: PostRequest {0} returned {1}", uri, result); | ||
289 | } | ||
290 | } | ||
291 | else | ||
292 | m_log.DebugFormat("[ESTATE CONNECTOR]: PostRequest {0} received null or zero response", uri); | ||
293 | |||
294 | return result; | ||
295 | } | ||
296 | |||
297 | /// <summary> | ||
298 | /// Forbidden operation | ||
299 | /// </summary> | ||
300 | /// <returns></returns> | ||
301 | public bool DeleteEstate(int estateID) | ||
302 | { | ||
303 | return false; | ||
304 | } | ||
305 | |||
306 | #endregion | ||
307 | |||
308 | private string MakeRequest(string verb, string uri, string formdata) | ||
309 | { | ||
310 | string reply = string.Empty; | ||
311 | try | ||
312 | { | ||
313 | reply = SynchronousRestFormsRequester.MakeRequest(verb, uri, formdata, m_Auth); | ||
314 | } | ||
315 | catch (WebException e) | ||
316 | { | ||
317 | using (HttpWebResponse hwr = (HttpWebResponse)e.Response) | ||
318 | { | ||
319 | if (hwr != null) | ||
320 | { | ||
321 | if (hwr.StatusCode == HttpStatusCode.NotFound) | ||
322 | m_log.Error(string.Format("[ESTATE CONNECTOR]: Resource {0} not found ", uri)); | ||
323 | if (hwr.StatusCode == HttpStatusCode.Unauthorized) | ||
324 | m_log.Error(string.Format("[ESTATE CONNECTOR]: Web request {0} requires authentication ", uri)); | ||
325 | } | ||
326 | else | ||
327 | m_log.Error(string.Format( | ||
328 | "[ESTATE CONNECTOR]: WebException for {0} {1} {2} ", | ||
329 | verb, uri, formdata, e)); | ||
330 | } | ||
331 | } | ||
332 | catch (Exception e) | ||
333 | { | ||
334 | m_log.DebugFormat("[ESTATE CONNECTOR]: Exception when contacting estate server at {0}: {1}", uri, e.Message); | ||
335 | } | ||
336 | |||
337 | return reply; | ||
338 | } | ||
339 | } | ||
340 | } | ||
diff --git a/OpenSim/Services/Connectors/Simulation/EstateDataService.cs b/OpenSim/Services/Connectors/Simulation/EstateDataService.cs deleted file mode 100644 index 5962b99..0000000 --- a/OpenSim/Services/Connectors/Simulation/EstateDataService.cs +++ /dev/null | |||
@@ -1,139 +0,0 @@ | |||
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.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using log4net; | ||
32 | using Mono.Addins; | ||
33 | using Nini.Config; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Services.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Data; | ||
38 | using OpenSim.Framework; | ||
39 | //using OpenSim.Region.Framework.Interfaces; | ||
40 | //using OpenSim.Region.Framework.Scenes; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class EstateDataService : ServiceBase, IEstateDataService | ||
45 | { | ||
46 | // private static readonly ILog m_log = | ||
47 | // LogManager.GetLogger( | ||
48 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | protected IEstateDataStore m_database; | ||
51 | |||
52 | public EstateDataService(IConfigSource config) | ||
53 | : base(config) | ||
54 | { | ||
55 | string dllName = String.Empty; | ||
56 | string connString = String.Empty; | ||
57 | |||
58 | // Try reading the [DatabaseService] section, if it exists | ||
59 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
60 | if (dbConfig != null) | ||
61 | { | ||
62 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
63 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
64 | connString = dbConfig.GetString("EstateConnectionString", connString); | ||
65 | } | ||
66 | |||
67 | // Try reading the [EstateDataStore] section, if it exists | ||
68 | IConfig estConfig = config.Configs["EstateDataStore"]; | ||
69 | if (estConfig != null) | ||
70 | { | ||
71 | dllName = estConfig.GetString("StorageProvider", dllName); | ||
72 | connString = estConfig.GetString("ConnectionString", connString); | ||
73 | } | ||
74 | |||
75 | // We tried, but this doesn't exist. We can't proceed | ||
76 | if (dllName == String.Empty) | ||
77 | throw new Exception("No StorageProvider configured"); | ||
78 | |||
79 | m_database = LoadPlugin<IEstateDataStore>(dllName, new Object[] { connString }); | ||
80 | if (m_database == null) | ||
81 | throw new Exception("Could not find a storage interface in the given module"); | ||
82 | } | ||
83 | |||
84 | public EstateSettings LoadEstateSettings(UUID regionID, bool create) | ||
85 | { | ||
86 | return m_database.LoadEstateSettings(regionID, create); | ||
87 | } | ||
88 | |||
89 | public EstateSettings LoadEstateSettings(int estateID) | ||
90 | { | ||
91 | return m_database.LoadEstateSettings(estateID); | ||
92 | } | ||
93 | |||
94 | public EstateSettings CreateNewEstate() | ||
95 | { | ||
96 | return m_database.CreateNewEstate(); | ||
97 | } | ||
98 | |||
99 | public List<EstateSettings> LoadEstateSettingsAll() | ||
100 | { | ||
101 | return m_database.LoadEstateSettingsAll(); | ||
102 | } | ||
103 | |||
104 | public void StoreEstateSettings(EstateSettings es) | ||
105 | { | ||
106 | m_database.StoreEstateSettings(es); | ||
107 | } | ||
108 | |||
109 | public List<int> GetEstates(string search) | ||
110 | { | ||
111 | return m_database.GetEstates(search); | ||
112 | } | ||
113 | |||
114 | public List<int> GetEstatesAll() | ||
115 | { | ||
116 | return m_database.GetEstatesAll(); | ||
117 | } | ||
118 | |||
119 | public List<int> GetEstatesByOwner(UUID ownerID) | ||
120 | { | ||
121 | return m_database.GetEstatesByOwner(ownerID); | ||
122 | } | ||
123 | |||
124 | public bool LinkRegion(UUID regionID, int estateID) | ||
125 | { | ||
126 | return m_database.LinkRegion(regionID, estateID); | ||
127 | } | ||
128 | |||
129 | public List<UUID> GetRegions(int estateID) | ||
130 | { | ||
131 | return m_database.GetRegions(estateID); | ||
132 | } | ||
133 | |||
134 | public bool DeleteEstate(int estateID) | ||
135 | { | ||
136 | return m_database.DeleteEstate(estateID); | ||
137 | } | ||
138 | } | ||
139 | } | ||
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs b/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs deleted file mode 100644 index 2cbf967..0000000 --- a/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs +++ /dev/null | |||
@@ -1,192 +0,0 @@ | |||
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.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using log4net; | ||
32 | using Mono.Addins; | ||
33 | using Nini.Config; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Services.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Data; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class SimulationDataService : ServiceBase, ISimulationDataService | ||
45 | { | ||
46 | // private static readonly ILog m_log = | ||
47 | // LogManager.GetLogger( | ||
48 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | protected ISimulationDataStore m_database; | ||
51 | |||
52 | public SimulationDataService(IConfigSource config) | ||
53 | : base(config) | ||
54 | { | ||
55 | string dllName = String.Empty; | ||
56 | string connString = String.Empty; | ||
57 | |||
58 | // Try reading the [DatabaseService] section, if it exists | ||
59 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
60 | if (dbConfig != null) | ||
61 | { | ||
62 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
63 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
64 | } | ||
65 | |||
66 | // Try reading the [SimulationDataStore] section | ||
67 | IConfig simConfig = config.Configs["SimulationDataStore"]; | ||
68 | if (simConfig != null) | ||
69 | { | ||
70 | dllName = simConfig.GetString("StorageProvider", dllName); | ||
71 | connString = simConfig.GetString("ConnectionString", connString); | ||
72 | } | ||
73 | |||
74 | // We tried, but this doesn't exist. We can't proceed | ||
75 | if (dllName == String.Empty) | ||
76 | throw new Exception("No StorageProvider configured"); | ||
77 | |||
78 | m_database = LoadPlugin<ISimulationDataStore>(dllName, new Object[] { connString }); | ||
79 | if (m_database == null) | ||
80 | throw new Exception("Could not find a storage interface in the given module"); | ||
81 | } | ||
82 | |||
83 | public void StoreObject(SceneObjectGroup obj, UUID regionUUID) | ||
84 | { | ||
85 | m_database.StoreObject(obj, regionUUID); | ||
86 | } | ||
87 | |||
88 | public void RemoveObject(UUID uuid, UUID regionUUID) | ||
89 | { | ||
90 | m_database.RemoveObject(uuid, regionUUID); | ||
91 | } | ||
92 | |||
93 | public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) | ||
94 | { | ||
95 | m_database.StorePrimInventory(primID, items); | ||
96 | } | ||
97 | |||
98 | public List<SceneObjectGroup> LoadObjects(UUID regionUUID) | ||
99 | { | ||
100 | return m_database.LoadObjects(regionUUID); | ||
101 | } | ||
102 | |||
103 | public void StoreTerrain(TerrainData terrain, UUID regionID) | ||
104 | { | ||
105 | m_database.StoreTerrain(terrain, regionID); | ||
106 | } | ||
107 | |||
108 | public void StoreTerrain(double[,] terrain, UUID regionID) | ||
109 | { | ||
110 | m_database.StoreTerrain(terrain, regionID); | ||
111 | } | ||
112 | |||
113 | public double[,] LoadTerrain(UUID regionID) | ||
114 | { | ||
115 | return m_database.LoadTerrain(regionID); | ||
116 | } | ||
117 | |||
118 | public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) | ||
119 | { | ||
120 | return m_database.LoadTerrain(regionID, pSizeX, pSizeY, pSizeZ); | ||
121 | } | ||
122 | |||
123 | public void StoreLandObject(ILandObject Parcel) | ||
124 | { | ||
125 | m_database.StoreLandObject(Parcel); | ||
126 | } | ||
127 | |||
128 | public void RemoveLandObject(UUID globalID) | ||
129 | { | ||
130 | m_database.RemoveLandObject(globalID); | ||
131 | } | ||
132 | |||
133 | public List<LandData> LoadLandObjects(UUID regionUUID) | ||
134 | { | ||
135 | return m_database.LoadLandObjects(regionUUID); | ||
136 | } | ||
137 | |||
138 | public void StoreRegionSettings(RegionSettings rs) | ||
139 | { | ||
140 | m_database.StoreRegionSettings(rs); | ||
141 | } | ||
142 | |||
143 | public RegionSettings LoadRegionSettings(UUID regionUUID) | ||
144 | { | ||
145 | return m_database.LoadRegionSettings(regionUUID); | ||
146 | } | ||
147 | |||
148 | public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID) | ||
149 | { | ||
150 | return m_database.LoadRegionWindlightSettings(regionUUID); | ||
151 | } | ||
152 | |||
153 | public void StoreRegionWindlightSettings(RegionLightShareData wl) | ||
154 | { | ||
155 | m_database.StoreRegionWindlightSettings(wl); | ||
156 | } | ||
157 | public void RemoveRegionWindlightSettings(UUID regionID) | ||
158 | { | ||
159 | m_database.RemoveRegionWindlightSettings(regionID); | ||
160 | } | ||
161 | |||
162 | public string LoadRegionEnvironmentSettings(UUID regionUUID) | ||
163 | { | ||
164 | return m_database.LoadRegionEnvironmentSettings(regionUUID); | ||
165 | } | ||
166 | |||
167 | public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings) | ||
168 | { | ||
169 | m_database.StoreRegionEnvironmentSettings(regionUUID, settings); | ||
170 | } | ||
171 | |||
172 | public void RemoveRegionEnvironmentSettings(UUID regionUUID) | ||
173 | { | ||
174 | m_database.RemoveRegionEnvironmentSettings(regionUUID); | ||
175 | } | ||
176 | |||
177 | public void SaveExtra(UUID regionID, string name, string val) | ||
178 | { | ||
179 | m_database.SaveExtra(regionID, name, val); | ||
180 | } | ||
181 | |||
182 | public void RemoveExtra(UUID regionID, string name) | ||
183 | { | ||
184 | m_database.RemoveExtra(regionID, name); | ||
185 | } | ||
186 | |||
187 | public Dictionary<string, string> GetExtra(UUID regionID) | ||
188 | { | ||
189 | return m_database.GetExtra(regionID); | ||
190 | } | ||
191 | } | ||
192 | } | ||