aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLEstateData.cs203
1 files changed, 180 insertions, 23 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
index d10ebe4..9c54e77 100644
--- a/OpenSim/Data/MSSQL/MSSQLEstateData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
@@ -41,7 +41,7 @@ namespace OpenSim.Data.MSSQL
41 { 41 {
42 private const string _migrationStore = "EstateStore"; 42 private const string _migrationStore = "EstateStore";
43 43
44 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 45
46 private MSSQLManager _Database; 46 private MSSQLManager _Database;
47 private string m_connectionString; 47 private string m_connectionString;
@@ -72,7 +72,12 @@ namespace OpenSim.Data.MSSQL
72 } 72 }
73 73
74 //Migration settings 74 //Migration settings
75 _Database.CheckMigration(_migrationStore); 75 using (SqlConnection conn = new SqlConnection(m_connectionString))
76 {
77 conn.Open();
78 Migration m = new Migration(conn, GetType().Assembly, "EstateStore");
79 m.Update();
80 }
76 81
77 //Interesting way to get parameters! Maybe implement that also with other types 82 //Interesting way to get parameters! Maybe implement that also with other types
78 Type t = typeof(EstateSettings); 83 Type t = typeof(EstateSettings);
@@ -112,19 +117,19 @@ namespace OpenSim.Data.MSSQL
112 { 117 {
113 FieldInfo f = _FieldMap[name]; 118 FieldInfo f = _FieldMap[name];
114 object v = reader[name]; 119 object v = reader[name];
115 if (f.FieldType == typeof(bool) ) 120 if (f.FieldType == typeof(bool))
116 { 121 {
117 f.SetValue(es, Convert.ToInt32(v) != 0); 122 f.SetValue(es, Convert.ToInt32(v) != 0);
118 } 123 }
119 else if (f.FieldType == typeof(UUID) ) 124 else if (f.FieldType == typeof(UUID))
120 { 125 {
121 f.SetValue(es, new UUID((Guid)v)); // uuid); 126 f.SetValue(es, new UUID((Guid)v)); // uuid);
122 } 127 }
123 else if (f.FieldType == typeof(string)) 128 else if (f.FieldType == typeof(string))
124 { 129 {
125 f.SetValue(es, v.ToString()); 130 f.SetValue(es, v.ToString());
126 } 131 }
127 else if (f.FieldType == typeof(UInt32)) 132 else if (f.FieldType == typeof(UInt32))
128 { 133 {
129 f.SetValue(es, Convert.ToUInt32(v)); 134 f.SetValue(es, Convert.ToUInt32(v));
130 } 135 }
@@ -186,7 +191,7 @@ namespace OpenSim.Data.MSSQL
186 } 191 }
187 catch (Exception e) 192 catch (Exception e)
188 { 193 {
189 _Log.DebugFormat("[ESTATE DB]: Error inserting regionID and EstateID in estate_map: {0}", e); 194 m_log.DebugFormat("[ESTATE DB]: Error inserting regionID and EstateID in estate_map: {0}", e);
190 } 195 }
191 } 196 }
192 197
@@ -310,12 +315,12 @@ namespace OpenSim.Data.MSSQL
310 conn.Open(); 315 conn.Open();
311 using (SqlCommand cmd = conn.CreateCommand()) 316 using (SqlCommand cmd = conn.CreateCommand())
312 { 317 {
313 cmd.CommandText = "delete from estateban where EstateID = @EstateID"; 318 cmd.CommandText = "delete from estateban where EstateID = @EstateID";
314 cmd.Parameters.AddWithValue("@EstateID", (int)es.EstateID); 319 cmd.Parameters.AddWithValue("@EstateID", (int)es.EstateID);
315 cmd.ExecuteNonQuery(); 320 cmd.ExecuteNonQuery();
316 321
317 //Insert after 322 //Insert after
318 cmd.CommandText = "insert into estateban (EstateID, bannedUUID) values ( @EstateID, @bannedUUID )"; 323 cmd.CommandText = "insert into estateban (EstateID, bannedUUID,bannedIp, bannedIpHostMask, bannedNameMask) values ( @EstateID, @bannedUUID, '','','' )";
319 cmd.Parameters.AddWithValue("@bannedUUID", Guid.Empty); 324 cmd.Parameters.AddWithValue("@bannedUUID", Guid.Empty);
320 foreach (EstateBan b in es.EstateBans) 325 foreach (EstateBan b in es.EstateBans)
321 { 326 {
@@ -350,43 +355,195 @@ namespace OpenSim.Data.MSSQL
350 355
351 public EstateSettings LoadEstateSettings(int estateID) 356 public EstateSettings LoadEstateSettings(int estateID)
352 { 357 {
353 // TODO: Implementation! 358 EstateSettings es = new EstateSettings();
354 return new EstateSettings(); 359 string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_settings where EstateID = @EstateID";
360 using (SqlConnection conn = new SqlConnection(m_connectionString))
361 {
362 conn.Open();
363 using (SqlCommand cmd = new SqlCommand(sql, conn))
364 {
365 cmd.Parameters.AddWithValue("@EstateID", (int)estateID);
366 using (SqlDataReader reader = cmd.ExecuteReader())
367 {
368 if (reader.Read())
369 {
370 foreach (string name in FieldList)
371 {
372 FieldInfo f = _FieldMap[name];
373 object v = reader[name];
374 if (f.FieldType == typeof(bool))
375 {
376 f.SetValue(es, Convert.ToInt32(v) != 0);
377 }
378 else if (f.FieldType == typeof(UUID))
379 {
380 f.SetValue(es, new UUID((Guid)v)); // uuid);
381 }
382 else if (f.FieldType == typeof(string))
383 {
384 f.SetValue(es, v.ToString());
385 }
386 else if (f.FieldType == typeof(UInt32))
387 {
388 f.SetValue(es, Convert.ToUInt32(v));
389 }
390 else if (f.FieldType == typeof(Single))
391 {
392 f.SetValue(es, Convert.ToSingle(v));
393 }
394 else
395 f.SetValue(es, v);
396 }
397 }
398
399 }
400 }
401 }
402 LoadBanList(es);
403
404 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
405 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
406 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
407
408 //Set event
409 es.OnSave += StoreEstateSettings;
410 return es;
411
355 } 412 }
356 413
357 public List<EstateSettings> LoadEstateSettingsAll() 414 public List<EstateSettings> LoadEstateSettingsAll()
358 { 415 {
359 // TODO: Implementation! 416 List<EstateSettings> allEstateSettings = new List<EstateSettings>();
360 return new List<EstateSettings>(); 417
418 List<int> allEstateIds = GetEstatesAll();
419
420 foreach (int estateId in allEstateIds)
421 allEstateSettings.Add(LoadEstateSettings(estateId));
422
423 return allEstateSettings;
361 } 424 }
362 425
363 public List<int> GetEstates(string search) 426 public List<int> GetEstates(string search)
364 { 427 {
365 // TODO: Implementation! 428 List<int> result = new List<int>();
366 return new List<int>(); 429 string sql = "select estateID from estate_settings where EstateName = @EstateName";
430 using (SqlConnection conn = new SqlConnection(m_connectionString))
431 {
432 conn.Open();
433 using (SqlCommand cmd = new SqlCommand(sql, conn))
434 {
435 cmd.Parameters.AddWithValue("@EstateName", search);
436
437 using (IDataReader reader = cmd.ExecuteReader())
438 {
439 while (reader.Read())
440 {
441 result.Add(Convert.ToInt32(reader["EstateID"]));
442 }
443 reader.Close();
444 }
445 }
446 }
447
448 return result;
367 } 449 }
368 450
369 public List<int> GetEstatesAll() 451 public List<int> GetEstatesAll()
370 { 452 {
371 // TODO: Implementation! 453 List<int> result = new List<int>();
372 return new List<int>(); 454 string sql = "select estateID from estate_settings";
455 using (SqlConnection conn = new SqlConnection(m_connectionString))
456 {
457 conn.Open();
458 using (SqlCommand cmd = new SqlCommand(sql, conn))
459 {
460 using (IDataReader reader = cmd.ExecuteReader())
461 {
462 while (reader.Read())
463 {
464 result.Add(Convert.ToInt32(reader["EstateID"]));
465 }
466 reader.Close();
467 }
468 }
469 }
470
471 return result;
373 } 472 }
374 473
375 public List<int> GetEstatesByOwner(UUID ownerID) 474 public List<int> GetEstatesByOwner(UUID ownerID)
376 { 475 {
377 return new List<int>(); 476 List<int> result = new List<int>();
477 string sql = "select estateID from estate_settings where EstateOwner = @EstateOwner";
478 using (SqlConnection conn = new SqlConnection(m_connectionString))
479 {
480 conn.Open();
481 using (SqlCommand cmd = new SqlCommand(sql, conn))
482 {
483 cmd.Parameters.AddWithValue("@EstateOwner", ownerID);
484
485 using (IDataReader reader = cmd.ExecuteReader())
486 {
487 while (reader.Read())
488 {
489 result.Add(Convert.ToInt32(reader["EstateID"]));
490 }
491 reader.Close();
492 }
493 }
494 }
495
496 return result;
378 } 497 }
379 498
380 public bool LinkRegion(UUID regionID, int estateID) 499 public bool LinkRegion(UUID regionID, int estateID)
381 { 500 {
382 // TODO: Implementation! 501 string sql = "insert into estate_map values (@RegionID, @EstateID)";
502 using (SqlConnection conn = new SqlConnection(m_connectionString))
503 {
504 conn.Open();
505 try
506 {
507 using (SqlCommand cmd = new SqlCommand(sql, conn))
508 {
509 cmd.Parameters.AddWithValue("@RegionID", regionID);
510 cmd.Parameters.AddWithValue("@EstateID", estateID);
511
512 int ret = cmd.ExecuteNonQuery();
513 return (ret != 0);
514 }
515 }
516 catch (Exception ex)
517 {
518 m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message);
519 }
520 }
383 return false; 521 return false;
384 } 522 }
385 523
386 public List<UUID> GetRegions(int estateID) 524 public List<UUID> GetRegions(int estateID)
387 { 525 {
388 // TODO: Implementation! 526 List<UUID> result = new List<UUID>();
389 return new List<UUID>(); 527 string sql = "select RegionID from estate_map where EstateID = @EstateID";
528 using (SqlConnection conn = new SqlConnection(m_connectionString))
529 {
530 conn.Open();
531 using (SqlCommand cmd = new SqlCommand(sql, conn))
532 {
533 cmd.Parameters.AddWithValue("@EstateID", estateID);
534
535 using (IDataReader reader = cmd.ExecuteReader())
536 {
537 while (reader.Read())
538 {
539 result.Add(DBGuid.FromDB(reader["RegionID"]));
540 }
541 reader.Close();
542 }
543 }
544 }
545
546 return result;
390 } 547 }
391 548
392 public bool DeleteEstate(int estateID) 549 public bool DeleteEstate(int estateID)