aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs396
1 files changed, 0 insertions, 396 deletions
diff --git a/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs b/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs
deleted file mode 100644
index 547ea6b..0000000
--- a/OpenSim/Data/SQLiteLegacy/SQLiteEstateData.cs
+++ /dev/null
@@ -1,396 +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 private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create)
105 {
106 EstateSettings es = new EstateSettings();
107 es.OnSave += StoreEstateSettings;
108
109 IDataReader r = cmd.ExecuteReader();
110
111 if (r.Read())
112 {
113 foreach (string name in FieldList)
114 {
115 if (m_FieldMap[name].GetValue(es) is bool)
116 {
117 int v = Convert.ToInt32(r[name]);
118 if (v != 0)
119 m_FieldMap[name].SetValue(es, true);
120 else
121 m_FieldMap[name].SetValue(es, false);
122 }
123 else if (m_FieldMap[name].GetValue(es) is UUID)
124 {
125 UUID uuid = UUID.Zero;
126
127 UUID.TryParse(r[name].ToString(), out uuid);
128 m_FieldMap[name].SetValue(es, uuid);
129 }
130 else
131 {
132 m_FieldMap[name].SetValue(es, Convert.ChangeType(r[name], m_FieldMap[name].FieldType));
133 }
134 }
135 r.Close();
136 }
137 else if (create)
138 {
139 r.Close();
140
141 List<string> names = new List<string>(FieldList);
142
143 names.Remove("EstateID");
144
145 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
146
147 cmd.CommandText = sql;
148 cmd.Parameters.Clear();
149
150 foreach (string name in FieldList)
151 {
152 if (m_FieldMap[name].GetValue(es) is bool)
153 {
154 if ((bool)m_FieldMap[name].GetValue(es))
155 cmd.Parameters.Add(":"+name, "1");
156 else
157 cmd.Parameters.Add(":"+name, "0");
158 }
159 else
160 {
161 cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString());
162 }
163 }
164
165 cmd.ExecuteNonQuery();
166
167 cmd.CommandText = "select LAST_INSERT_ROWID() as id";
168 cmd.Parameters.Clear();
169
170 r = cmd.ExecuteReader();
171
172 r.Read();
173
174 es.EstateID = Convert.ToUInt32(r["id"]);
175
176 r.Close();
177
178 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
179 cmd.Parameters.Add(":RegionID", regionID.ToString());
180 cmd.Parameters.Add(":EstateID", es.EstateID.ToString());
181
182 // This will throw on dupe key
183 try
184 {
185 cmd.ExecuteNonQuery();
186 }
187 catch (Exception)
188 {
189 }
190
191 es.Save();
192 }
193
194 LoadBanList(es);
195
196 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
197 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
198 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
199 return es;
200 }
201
202 public void StoreEstateSettings(EstateSettings es)
203 {
204 List<string> fields = new List<string>(FieldList);
205 fields.Remove("EstateID");
206
207 List<string> terms = new List<string>();
208
209 foreach (string f in fields)
210 terms.Add(f+" = :"+f);
211
212 string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = :EstateID";
213
214 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
215
216 cmd.CommandText = sql;
217
218 foreach (string name in FieldList)
219 {
220 if (m_FieldMap[name].GetValue(es) is bool)
221 {
222 if ((bool)m_FieldMap[name].GetValue(es))
223 cmd.Parameters.Add(":"+name, "1");
224 else
225 cmd.Parameters.Add(":"+name, "0");
226 }
227 else
228 {
229 cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString());
230 }
231 }
232
233 cmd.ExecuteNonQuery();
234
235 SaveBanList(es);
236 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
237 SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
238 SaveUUIDList(es.EstateID, "estate_groups", es.EstateGroups);
239 }
240
241 private void LoadBanList(EstateSettings es)
242 {
243 es.ClearBans();
244
245 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
246
247 cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID";
248 cmd.Parameters.Add(":EstateID", es.EstateID);
249
250 IDataReader r = cmd.ExecuteReader();
251
252 while (r.Read())
253 {
254 EstateBan eb = new EstateBan();
255
256 UUID uuid = new UUID();
257 UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
258
259 eb.BannedUserID = uuid;
260 eb.BannedHostAddress = "0.0.0.0";
261 eb.BannedHostIPMask = "0.0.0.0";
262 es.AddBan(eb);
263 }
264 r.Close();
265 }
266
267 private void SaveBanList(EstateSettings es)
268 {
269 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
270
271 cmd.CommandText = "delete from estateban where EstateID = :EstateID";
272 cmd.Parameters.Add(":EstateID", es.EstateID.ToString());
273
274 cmd.ExecuteNonQuery();
275
276 cmd.Parameters.Clear();
277
278 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( :EstateID, :bannedUUID, '', '', '' )";
279
280 foreach (EstateBan b in es.EstateBans)
281 {
282 cmd.Parameters.Add(":EstateID", es.EstateID.ToString());
283 cmd.Parameters.Add(":bannedUUID", b.BannedUserID.ToString());
284
285 cmd.ExecuteNonQuery();
286 cmd.Parameters.Clear();
287 }
288 }
289
290 void SaveUUIDList(uint EstateID, string table, UUID[] data)
291 {
292 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
293
294 cmd.CommandText = "delete from "+table+" where EstateID = :EstateID";
295 cmd.Parameters.Add(":EstateID", EstateID.ToString());
296
297 cmd.ExecuteNonQuery();
298
299 cmd.Parameters.Clear();
300
301 cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( :EstateID, :uuid )";
302
303 foreach (UUID uuid in data)
304 {
305 cmd.Parameters.Add(":EstateID", EstateID.ToString());
306 cmd.Parameters.Add(":uuid", uuid.ToString());
307
308 cmd.ExecuteNonQuery();
309 cmd.Parameters.Clear();
310 }
311 }
312
313 UUID[] LoadUUIDList(uint EstateID, string table)
314 {
315 List<UUID> uuids = new List<UUID>();
316
317 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
318
319 cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID";
320 cmd.Parameters.Add(":EstateID", EstateID);
321
322 IDataReader r = cmd.ExecuteReader();
323
324 while (r.Read())
325 {
326 // EstateBan eb = new EstateBan();
327
328 UUID uuid = new UUID();
329 UUID.TryParse(r["uuid"].ToString(), out uuid);
330
331 uuids.Add(uuid);
332 }
333 r.Close();
334
335 return uuids.ToArray();
336 }
337
338 public EstateSettings LoadEstateSettings(int estateID)
339 {
340 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID = :EstateID";
341
342 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
343
344 cmd.CommandText = sql;
345 cmd.Parameters.Add(":EstateID", estateID.ToString());
346
347 return DoLoad(cmd, UUID.Zero, false);
348 }
349
350 public List<int> GetEstates(string search)
351 {
352 List<int> result = new List<int>();
353
354 string sql = "select EstateID from estate_settings where estate_settings.EstateName = :EstateName";
355
356 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
357
358 cmd.CommandText = sql;
359 cmd.Parameters.Add(":EstateName", search);
360
361 IDataReader r = cmd.ExecuteReader();
362
363 while (r.Read())
364 {
365 result.Add(Convert.ToInt32(r["EstateID"]));
366 }
367 r.Close();
368
369 return result;
370 }
371
372 public bool LinkRegion(UUID regionID, int estateID)
373 {
374 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
375
376 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
377 cmd.Parameters.Add(":RegionID", regionID.ToString());
378 cmd.Parameters.Add(":EstateID", estateID.ToString());
379
380 if (cmd.ExecuteNonQuery() == 0)
381 return false;
382
383 return true;
384 }
385
386 public List<UUID> GetRegions(int estateID)
387 {
388 return new List<UUID>();
389 }
390
391 public bool DeleteEstate(int estateID)
392 {
393 return false;
394 }
395 }
396}