aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLEstateData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLEstateData.cs195
1 files changed, 139 insertions, 56 deletions
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs
index 2eae2d8..d0c02f0 100644
--- a/OpenSim/Data/MySQL/MySQLEstateData.cs
+++ b/OpenSim/Data/MySQL/MySQLEstateData.cs
@@ -121,111 +121,110 @@ namespace OpenSim.Data.MySQL
121 } 121 }
122 } 122 }
123 123
124 public EstateSettings LoadEstateSettings(UUID regionID) 124 public EstateSettings LoadEstateSettings(UUID regionID, bool create)
125 { 125 {
126 EstateSettings es = new EstateSettings();
127 es.OnSave += StoreEstateSettings;
128
129 string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + 126 string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) +
130 " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID"; 127 " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID";
131 128
132 bool migration = true; 129 using (MySqlCommand cmd = new MySqlCommand())
130 {
131 cmd.CommandText = sql;
132 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
133
134 return DoLoad(cmd, regionID, create);
135 }
136 }
137
138 private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create)
139 {
140 EstateSettings es = new EstateSettings();
141 es.OnSave += StoreEstateSettings;
133 142
134 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 143 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
135 { 144 {
136 dbcon.Open(); 145 dbcon.Open();
137 146
138 using (MySqlCommand cmd = dbcon.CreateCommand()) 147 cmd.Connection = dbcon;
139 {
140 cmd.CommandText = sql;
141 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
142 148
143 using (IDataReader r = cmd.ExecuteReader()) 149 bool found = false;
150
151 using (IDataReader r = cmd.ExecuteReader())
152 {
153 if (r.Read())
144 { 154 {
145 if (r.Read()) 155 found = true;
146 {
147 migration = false;
148 156
149 foreach (string name in FieldList) 157 foreach (string name in FieldList)
158 {
159 if (m_FieldMap[name].GetValue(es) is bool)
150 { 160 {
151 if (m_FieldMap[name].GetValue(es) is bool) 161 int v = Convert.ToInt32(r[name]);
152 { 162 if (v != 0)
153 int v = Convert.ToInt32(r[name]); 163 m_FieldMap[name].SetValue(es, true);
154 if (v != 0)
155 m_FieldMap[name].SetValue(es, true);
156 else
157 m_FieldMap[name].SetValue(es, false);
158 }
159 else if (m_FieldMap[name].GetValue(es) is UUID)
160 {
161 UUID uuid = UUID.Zero;
162
163 UUID.TryParse(r[name].ToString(), out uuid);
164 m_FieldMap[name].SetValue(es, uuid);
165 }
166 else 164 else
167 { 165 m_FieldMap[name].SetValue(es, false);
168 m_FieldMap[name].SetValue(es, r[name]); 166 }
169 } 167 else if (m_FieldMap[name].GetValue(es) is UUID)
168 {
169 UUID uuid = UUID.Zero;
170
171 UUID.TryParse(r[name].ToString(), out uuid);
172 m_FieldMap[name].SetValue(es, uuid);
173 }
174 else
175 {
176 m_FieldMap[name].SetValue(es, r[name]);
170 } 177 }
171 } 178 }
172 } 179 }
173 } 180 }
174 181
175 if (migration) 182 if (!found && create)
176 { 183 {
177 // Migration case 184 // Migration case
178 List<string> names = new List<string>(FieldList); 185 List<string> names = new List<string>(FieldList);
179 186
180 names.Remove("EstateID"); 187 names.Remove("EstateID");
181 188
182 sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; 189 string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
183 190
184 using (MySqlCommand cmd = dbcon.CreateCommand()) 191 using (MySqlCommand cmd2 = dbcon.CreateCommand())
185 { 192 {
186 cmd.CommandText = sql; 193 cmd2.CommandText = sql;
187 cmd.Parameters.Clear(); 194 cmd2.Parameters.Clear();
188 195
189 foreach (string name in FieldList) 196 foreach (string name in FieldList)
190 { 197 {
191 if (m_FieldMap[name].GetValue(es) is bool) 198 if (m_FieldMap[name].GetValue(es) is bool)
192 { 199 {
193 if ((bool)m_FieldMap[name].GetValue(es)) 200 if ((bool)m_FieldMap[name].GetValue(es))
194 cmd.Parameters.AddWithValue("?" + name, "1"); 201 cmd2.Parameters.AddWithValue("?" + name, "1");
195 else 202 else
196 cmd.Parameters.AddWithValue("?" + name, "0"); 203 cmd2.Parameters.AddWithValue("?" + name, "0");
197 } 204 }
198 else 205 else
199 { 206 {
200 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); 207 cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
201 } 208 }
202 } 209 }
203 210
204 cmd.ExecuteNonQuery(); 211 cmd2.ExecuteNonQuery();
205 212
206 cmd.CommandText = "select LAST_INSERT_ID() as id"; 213 cmd2.CommandText = "select LAST_INSERT_ID() as id";
207 cmd.Parameters.Clear(); 214 cmd2.Parameters.Clear();
208 215
209 using (IDataReader r = cmd.ExecuteReader()) 216 using (IDataReader r = cmd2.ExecuteReader())
210 { 217 {
211 r.Read(); 218 r.Read();
212 es.EstateID = Convert.ToUInt32(r["id"]); 219 es.EstateID = Convert.ToUInt32(r["id"]);
213 } 220 }
214 221
215 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; 222 cmd2.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
216 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); 223 cmd2.Parameters.AddWithValue("?RegionID", regionID.ToString());
217 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); 224 cmd2.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
218 225
219 // This will throw on dupe key 226 // This will throw on dupe key
220 try { cmd.ExecuteNonQuery(); } 227 try { cmd2.ExecuteNonQuery(); }
221 catch (Exception) { }
222
223 // Munge and transfer the ban list
224 cmd.Parameters.Clear();
225 cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
226 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
227
228 try { cmd.ExecuteNonQuery(); }
229 catch (Exception) { } 228 catch (Exception) { }
230 229
231 es.Save(); 230 es.Save();
@@ -398,5 +397,89 @@ namespace OpenSim.Data.MySQL
398 397
399 return uuids.ToArray(); 398 return uuids.ToArray();
400 } 399 }
400
401 public EstateSettings LoadEstateSettings(int estateID)
402 {
403 using (MySqlCommand cmd = new MySqlCommand())
404 {
405 string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_settings where EstateID = ?EstateID";
406
407 cmd.CommandText = sql;
408 cmd.Parameters.AddWithValue("?EstateID", estateID);
409
410 return DoLoad(cmd, UUID.Zero, false);
411 }
412 }
413
414 public List<int> GetEstates(string search)
415 {
416 List<int> result = new List<int>();
417
418 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
419 {
420 dbcon.Open();
421
422 using (MySqlCommand cmd = dbcon.CreateCommand())
423 {
424 cmd.CommandText = "select estateID from estate_settings where EstateName = ?EstateName";
425 cmd.Parameters.AddWithValue("?EstateName", search);
426
427 using (IDataReader reader = cmd.ExecuteReader())
428 {
429 while (reader.Read())
430 {
431 result.Add(Convert.ToInt32(reader["EstateID"]));
432 }
433 reader.Close();
434 }
435 }
436
437
438 dbcon.Close();
439 }
440
441 return result;
442 }
443
444 public bool LinkRegion(UUID regionID, int estateID)
445 {
446 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
447 {
448 dbcon.Open();
449
450 try
451 {
452 using (MySqlCommand cmd = dbcon.CreateCommand())
453 {
454 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
455 cmd.Parameters.AddWithValue("?RegionID", regionID);
456 cmd.Parameters.AddWithValue("?EstateID", estateID);
457
458 int ret = cmd.ExecuteNonQuery();
459 dbcon.Close();
460
461 return (ret != 0);
462 }
463 }
464 catch (MySqlException ex)
465 {
466 m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message);
467 }
468
469 dbcon.Close();
470 }
471
472 return false;
473 }
474
475 public List<UUID> GetRegions(int estateID)
476 {
477 return new List<UUID>();
478 }
479
480 public bool DeleteEstate(int estateID)
481 {
482 return false;
483 }
401 } 484 }
402} 485}