aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs')
-rw-r--r--OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs451
1 files changed, 0 insertions, 451 deletions
diff --git a/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs b/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs
deleted file mode 100644
index 4dd225f..0000000
--- a/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs
+++ /dev/null
@@ -1,451 +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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Reflection;
32using log4net;
33using Mono.Data.SqliteClient;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces;
37
38namespace OpenSim.Data.SQLiteLegacy
39{
40 public class SQLiteEstateStore : IEstateDataStore
41 {
42 private static readonly ILog m_log =
43 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 private SqliteConnection m_connection;
46 private string m_connectionString;
47
48 private FieldInfo[] m_Fields;
49 private Dictionary<string, FieldInfo> m_FieldMap =
50 new Dictionary<string, FieldInfo>();
51
52 public SQLiteEstateStore()
53 {
54 }
55
56 public SQLiteEstateStore(string connectionString)
57 {
58 Initialise(connectionString);
59 }
60
61 public void Initialise(string connectionString)
62 {
63 m_connectionString = connectionString;
64
65 m_log.Info("[ESTATE DB]: Sqlite - connecting: "+m_connectionString);
66
67 m_connection = new SqliteConnection(m_connectionString);
68 m_connection.Open();
69
70 Assembly assem = GetType().Assembly;
71 Migration m = new Migration(m_connection, assem, "EstateStore");
72 m.Update();
73
74 m_connection.Close();
75 m_connection.Open();
76
77 Type t = typeof(EstateSettings);
78 m_Fields = t.GetFields(BindingFlags.NonPublic |
79 BindingFlags.Instance |
80 BindingFlags.DeclaredOnly);
81
82 foreach (FieldInfo f in m_Fields)
83 if (f.Name.Substring(0, 2) == "m_")
84 m_FieldMap[f.Name.Substring(2)] = f;
85 }
86
87 private string[] FieldList
88 {
89 get { return new List<string>(m_FieldMap.Keys).ToArray(); }
90 }
91
92 public EstateSettings LoadEstateSettings(UUID regionID, bool create)
93 {
94 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = :RegionID";
95
96 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
97
98 cmd.CommandText = sql;
99 cmd.Parameters.Add(":RegionID", regionID.ToString());
100
101 return DoLoad(cmd, regionID, create);
102 }
103
104 public List<EstateSettings> LoadEstateSettingsAll()
105 {
106 List<EstateSettings> estateSettings = new List<EstateSettings>();
107
108 List<int> estateIds = GetEstatesAll();
109 foreach (int estateId in estateIds)
110 estateSettings.Add(LoadEstateSettings(estateId));
111
112 return estateSettings;
113 }
114
115 private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create)
116 {
117 EstateSettings es = new EstateSettings();
118 es.OnSave += StoreEstateSettings;
119
120 IDataReader r = cmd.ExecuteReader();
121
122 if (r.Read())
123 {
124 foreach (string name in FieldList)
125 {
126 if (m_FieldMap[name].GetValue(es) is bool)
127 {
128 int v = Convert.ToInt32(r[name]);
129 if (v != 0)
130 m_FieldMap[name].SetValue(es, true);
131 else
132 m_FieldMap[name].SetValue(es, false);
133 }
134 else if (m_FieldMap[name].GetValue(es) is UUID)
135 {
136 UUID uuid = UUID.Zero;
137
138 UUID.TryParse(r[name].ToString(), out uuid);
139 m_FieldMap[name].SetValue(es, uuid);
140 }
141 else
142 {
143 m_FieldMap[name].SetValue(es, Convert.ChangeType(r[name], m_FieldMap[name].FieldType));
144 }
145 }
146 r.Close();
147 }
148 else if (create)
149 {
150 r.Close();
151
152 List<string> names = new List<string>(FieldList);
153
154 names.Remove("EstateID");
155
156 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
157
158 cmd.CommandText = sql;
159 cmd.Parameters.Clear();
160
161 foreach (string name in FieldList)
162 {
163 if (m_FieldMap[name].GetValue(es) is bool)
164 {
165 if ((bool)m_FieldMap[name].GetValue(es))
166 cmd.Parameters.Add(":"+name, "1");
167 else
168 cmd.Parameters.Add(":"+name, "0");
169 }
170 else
171 {
172 cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString());
173 }
174 }
175
176 cmd.ExecuteNonQuery();
177
178 cmd.CommandText = "select LAST_INSERT_ROWID() as id";
179 cmd.Parameters.Clear();
180
181 r = cmd.ExecuteReader();
182
183 r.Read();
184
185 es.EstateID = Convert.ToUInt32(r["id"]);
186
187 r.Close();
188
189 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
190 cmd.Parameters.Add(":RegionID", regionID.ToString());
191 cmd.Parameters.Add(":EstateID", es.EstateID.ToString());
192
193 // This will throw on dupe key
194 try
195 {
196 cmd.ExecuteNonQuery();
197 }
198 catch (Exception)
199 {
200 }
201
202 es.Save();
203 }
204
205 LoadBanList(es);
206
207 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
208 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
209 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
210 return es;
211 }
212
213 public void StoreEstateSettings(EstateSettings es)
214 {
215 List<string> fields = new List<string>(FieldList);
216 fields.Remove("EstateID");
217
218 List<string> terms = new List<string>();
219
220 foreach (string f in fields)
221 terms.Add(f+" = :"+f);
222
223 string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = :EstateID";
224
225 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
226
227 cmd.CommandText = sql;
228
229 foreach (string name in FieldList)
230 {
231 if (m_FieldMap[name].GetValue(es) is bool)
232 {
233 if ((bool)m_FieldMap[name].GetValue(es))
234 cmd.Parameters.Add(":"+name, "1");
235 else
236 cmd.Parameters.Add(":"+name, "0");
237 }
238 else
239 {
240 cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString());
241 }
242 }
243
244 cmd.ExecuteNonQuery();
245
246 SaveBanList(es);
247 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
248 SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
249 SaveUUIDList(es.EstateID, "estate_groups", es.EstateGroups);
250 }
251
252 private void LoadBanList(EstateSettings es)
253 {
254 es.ClearBans();
255
256 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
257
258 cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID";
259 cmd.Parameters.Add(":EstateID", es.EstateID);
260
261 IDataReader r = cmd.ExecuteReader();
262
263 while (r.Read())
264 {
265 EstateBan eb = new EstateBan();
266
267 UUID uuid = new UUID();
268 UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
269
270 eb.BannedUserID = uuid;
271 eb.BannedHostAddress = "0.0.0.0";
272 eb.BannedHostIPMask = "0.0.0.0";
273 es.AddBan(eb);
274 }
275 r.Close();
276 }
277
278 private void SaveBanList(EstateSettings es)
279 {
280 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
281
282 cmd.CommandText = "delete from estateban where EstateID = :EstateID";
283 cmd.Parameters.Add(":EstateID", es.EstateID.ToString());
284
285 cmd.ExecuteNonQuery();
286
287 cmd.Parameters.Clear();
288
289 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( :EstateID, :bannedUUID, '', '', '' )";
290
291 foreach (EstateBan b in es.EstateBans)
292 {
293 cmd.Parameters.Add(":EstateID", es.EstateID.ToString());
294 cmd.Parameters.Add(":bannedUUID", b.BannedUserID.ToString());
295
296 cmd.ExecuteNonQuery();
297 cmd.Parameters.Clear();
298 }
299 }
300
301 void SaveUUIDList(uint EstateID, string table, UUID[] data)
302 {
303 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
304
305 cmd.CommandText = "delete from "+table+" where EstateID = :EstateID";
306 cmd.Parameters.Add(":EstateID", EstateID.ToString());
307
308 cmd.ExecuteNonQuery();
309
310 cmd.Parameters.Clear();
311
312 cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( :EstateID, :uuid )";
313
314 foreach (UUID uuid in data)
315 {
316 cmd.Parameters.Add(":EstateID", EstateID.ToString());
317 cmd.Parameters.Add(":uuid", uuid.ToString());
318
319 cmd.ExecuteNonQuery();
320 cmd.Parameters.Clear();
321 }
322 }
323
324 UUID[] LoadUUIDList(uint EstateID, string table)
325 {
326 List<UUID> uuids = new List<UUID>();
327
328 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
329
330 cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID";
331 cmd.Parameters.Add(":EstateID", EstateID);
332
333 IDataReader r = cmd.ExecuteReader();
334
335 while (r.Read())
336 {
337 // EstateBan eb = new EstateBan();
338
339 UUID uuid = new UUID();
340 UUID.TryParse(r["uuid"].ToString(), out uuid);
341
342 uuids.Add(uuid);
343 }
344 r.Close();
345
346 return uuids.ToArray();
347 }
348
349 public EstateSettings LoadEstateSettings(int estateID)
350 {
351 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID = :EstateID";
352
353 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
354
355 cmd.CommandText = sql;
356 cmd.Parameters.Add(":EstateID", estateID.ToString());
357
358 return DoLoad(cmd, UUID.Zero, false);
359 }
360
361 public List<int> GetEstates(string search)
362 {
363 List<int> result = new List<int>();
364
365 string sql = "select EstateID from estate_settings where estate_settings.EstateName = :EstateName";
366
367 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
368
369 cmd.CommandText = sql;
370 cmd.Parameters.Add(":EstateName", search);
371
372 IDataReader r = cmd.ExecuteReader();
373
374 while (r.Read())
375 {
376 result.Add(Convert.ToInt32(r["EstateID"]));
377 }
378 r.Close();
379
380 return result;
381 }
382
383
384 public List<int> GetEstatesAll()
385 {
386 List<int> result = new List<int>();
387
388 string sql = "select EstateID from estate_settings";
389
390 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
391
392 cmd.CommandText = sql;
393
394 IDataReader r = cmd.ExecuteReader();
395
396 while (r.Read())
397 {
398 result.Add(Convert.ToInt32(r["EstateID"]));
399 }
400 r.Close();
401
402 return result;
403 }
404
405 public List<int> GetEstatesByOwner(UUID ownerID)
406 {
407 List<int> result = new List<int>();
408
409 string sql = "select EstateID from estate_settings where estate_settings.EstateOwner = :EstateOwner";
410
411 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
412
413 cmd.CommandText = sql;
414 cmd.Parameters.Add(":EstateOwner", ownerID);
415
416 IDataReader r = cmd.ExecuteReader();
417
418 while (r.Read())
419 {
420 result.Add(Convert.ToInt32(r["EstateID"]));
421 }
422 r.Close();
423
424 return result;
425 }
426
427 public bool LinkRegion(UUID regionID, int estateID)
428 {
429 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
430
431 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
432 cmd.Parameters.Add(":RegionID", regionID.ToString());
433 cmd.Parameters.Add(":EstateID", estateID.ToString());
434
435 if (cmd.ExecuteNonQuery() == 0)
436 return false;
437
438 return true;
439 }
440
441 public List<UUID> GetRegions(int estateID)
442 {
443 return new List<UUID>();
444 }
445
446 public bool DeleteEstate(int estateID)
447 {
448 return false;
449 }
450 }
451}