aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLEstateData.cs
diff options
context:
space:
mode:
authorMelanie2009-10-05 10:17:23 +0100
committerMelanie2009-10-05 10:17:23 +0100
commit0744292b479446eb1ebec828afafacc0189709ca (patch)
tree3c43b5f425aff61d3625b75b7aef35ce5062ae56 /OpenSim/Data/MySQL/MySQLEstateData.cs
parentMerge branch 'master' into vehicles (diff)
parentMake the asset connector async Get overload return false if the asset (diff)
downloadopensim-SC-0744292b479446eb1ebec828afafacc0189709ca.zip
opensim-SC-0744292b479446eb1ebec828afafacc0189709ca.tar.gz
opensim-SC-0744292b479446eb1ebec828afafacc0189709ca.tar.bz2
opensim-SC-0744292b479446eb1ebec828afafacc0189709ca.tar.xz
Merge branch 'master' into vehicles
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLEstateData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLEstateData.cs310
1 files changed, 152 insertions, 158 deletions
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs
index e8694fc..7166b29 100644
--- a/OpenSim/Data/MySQL/MySQLEstateData.cs
+++ b/OpenSim/Data/MySQL/MySQLEstateData.cs
@@ -95,21 +95,17 @@ namespace OpenSim.Data.MySQL
95 95
96 protected void GetWaitTimeout() 96 protected void GetWaitTimeout()
97 { 97 {
98 MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, 98 using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, m_connection))
99 m_connection);
100
101 using (MySqlDataReader dbReader =
102 cmd.ExecuteReader(CommandBehavior.SingleRow))
103 { 99 {
104 if (dbReader.Read()) 100 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
105 { 101 {
106 m_waitTimeout 102 if (dbReader.Read())
107 = Convert.ToInt32(dbReader["@@wait_timeout"]) * 103 {
108 TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; 104 m_waitTimeout
105 = Convert.ToInt32(dbReader["@@wait_timeout"]) *
106 TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
107 }
109 } 108 }
110
111 dbReader.Close();
112 cmd.Dispose();
113 } 109 }
114 110
115 m_lastConnectionUse = DateTime.Now.Ticks; 111 m_lastConnectionUse = DateTime.Now.Ticks;
@@ -147,110 +143,103 @@ namespace OpenSim.Data.MySQL
147 143
148 CheckConnection(); 144 CheckConnection();
149 145
150 MySqlCommand cmd = m_connection.CreateCommand(); 146 bool migration = true;
151 147
152 cmd.CommandText = sql; 148 using (MySqlCommand cmd = m_connection.CreateCommand())
153 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
154
155 IDataReader r = cmd.ExecuteReader();
156
157 if (r.Read())
158 { 149 {
159 foreach (string name in FieldList) 150 cmd.CommandText = sql;
160 { 151 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
161 if (m_FieldMap[name].GetValue(es) is bool)
162 {
163 int v = Convert.ToInt32(r[name]);
164 if (v != 0)
165 m_FieldMap[name].SetValue(es, true);
166 else
167 m_FieldMap[name].SetValue(es, false);
168 }
169 else if (m_FieldMap[name].GetValue(es) is UUID)
170 {
171 UUID uuid = UUID.Zero;
172 152
173 UUID.TryParse(r[name].ToString(), out uuid); 153 using (IDataReader r = cmd.ExecuteReader())
174 m_FieldMap[name].SetValue(es, uuid); 154 {
175 } 155 if (r.Read())
176 else
177 { 156 {
178 m_FieldMap[name].SetValue(es, r[name]); 157 migration = false;
158
159 foreach (string name in FieldList)
160 {
161 if (m_FieldMap[name].GetValue(es) is bool)
162 {
163 int v = Convert.ToInt32(r[name]);
164 if (v != 0)
165 m_FieldMap[name].SetValue(es, true);
166 else
167 m_FieldMap[name].SetValue(es, false);
168 }
169 else if (m_FieldMap[name].GetValue(es) is UUID)
170 {
171 UUID uuid = UUID.Zero;
172
173 UUID.TryParse(r[name].ToString(), out uuid);
174 m_FieldMap[name].SetValue(es, uuid);
175 }
176 else
177 {
178 m_FieldMap[name].SetValue(es, r[name]);
179 }
180 }
179 } 181 }
180 } 182 }
181 r.Close();
182 } 183 }
183 else 184
185 if (migration)
184 { 186 {
185 // Migration case 187 // Migration case
186 //
187 r.Close();
188
189 List<string> names = new List<string>(FieldList); 188 List<string> names = new List<string>(FieldList);
190 189
191 names.Remove("EstateID"); 190 names.Remove("EstateID");
192 191
193 sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; 192 sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
194 193
195 cmd.CommandText = sql; 194 using (MySqlCommand cmd = m_connection.CreateCommand())
196 cmd.Parameters.Clear();
197
198 foreach (string name in FieldList)
199 { 195 {
200 if (m_FieldMap[name].GetValue(es) is bool) 196 cmd.CommandText = sql;
197 cmd.Parameters.Clear();
198
199 foreach (string name in FieldList)
201 { 200 {
202 if ((bool)m_FieldMap[name].GetValue(es)) 201 if (m_FieldMap[name].GetValue(es) is bool)
203 cmd.Parameters.AddWithValue("?" + name, "1"); 202 {
203 if ((bool)m_FieldMap[name].GetValue(es))
204 cmd.Parameters.AddWithValue("?" + name, "1");
205 else
206 cmd.Parameters.AddWithValue("?" + name, "0");
207 }
204 else 208 else
205 cmd.Parameters.AddWithValue("?" + name, "0"); 209 {
210 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
211 }
206 } 212 }
207 else
208 {
209 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
210 }
211 }
212
213 cmd.ExecuteNonQuery();
214 213
215 cmd.CommandText = "select LAST_INSERT_ID() as id"; 214 cmd.ExecuteNonQuery();
216 cmd.Parameters.Clear();
217
218 r = cmd.ExecuteReader();
219 215
220 r.Read(); 216 cmd.CommandText = "select LAST_INSERT_ID() as id";
217 cmd.Parameters.Clear();
221 218
222 es.EstateID = Convert.ToUInt32(r["id"]); 219 using (IDataReader r = cmd.ExecuteReader())
220 {
221 r.Read();
222 es.EstateID = Convert.ToUInt32(r["id"]);
223 }
223 224
224 r.Close(); 225 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
226 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
227 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
225 228
226 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; 229 // This will throw on dupe key
227 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); 230 try { cmd.ExecuteNonQuery(); }
228 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); 231 catch (Exception) { }
229 232
230 // This will throw on dupe key 233 // Munge and transfer the ban list
231 try 234 cmd.Parameters.Clear();
232 { 235 cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
233 cmd.ExecuteNonQuery(); 236 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
234 }
235 catch (Exception)
236 {
237 }
238 237
239 // Munge and transfer the ban list 238 try { cmd.ExecuteNonQuery(); }
240 // 239 catch (Exception) { }
241 cmd.Parameters.Clear();
242 cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
243 cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
244 240
245 try 241 es.Save();
246 {
247 cmd.ExecuteNonQuery();
248 }
249 catch (Exception)
250 {
251 } 242 }
252
253 es.Save();
254 } 243 }
255 244
256 LoadBanList(es); 245 LoadBanList(es);
@@ -267,26 +256,27 @@ namespace OpenSim.Data.MySQL
267 256
268 CheckConnection(); 257 CheckConnection();
269 258
270 MySqlCommand cmd = m_connection.CreateCommand(); 259 using (MySqlCommand cmd = m_connection.CreateCommand())
271
272 cmd.CommandText = sql;
273
274 foreach (string name in FieldList)
275 { 260 {
276 if (m_FieldMap[name].GetValue(es) is bool) 261 cmd.CommandText = sql;
262
263 foreach (string name in FieldList)
277 { 264 {
278 if ((bool)m_FieldMap[name].GetValue(es)) 265 if (m_FieldMap[name].GetValue(es) is bool)
279 cmd.Parameters.AddWithValue("?" + name, "1"); 266 {
267 if ((bool)m_FieldMap[name].GetValue(es))
268 cmd.Parameters.AddWithValue("?" + name, "1");
269 else
270 cmd.Parameters.AddWithValue("?" + name, "0");
271 }
280 else 272 else
281 cmd.Parameters.AddWithValue("?" + name, "0"); 273 {
282 } 274 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
283 else 275 }
284 {
285 cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
286 } 276 }
287 }
288 277
289 cmd.ExecuteNonQuery(); 278 cmd.ExecuteNonQuery();
279 }
290 280
291 SaveBanList(es); 281 SaveBanList(es);
292 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); 282 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
@@ -300,50 +290,52 @@ namespace OpenSim.Data.MySQL
300 290
301 CheckConnection(); 291 CheckConnection();
302 292
303 MySqlCommand cmd = m_connection.CreateCommand(); 293 using (MySqlCommand cmd = m_connection.CreateCommand())
304
305 cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
306 cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
307
308 IDataReader r = cmd.ExecuteReader();
309
310 while (r.Read())
311 { 294 {
312 EstateBan eb = new EstateBan(); 295 cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
296 cmd.Parameters.AddWithValue("?EstateID", es.EstateID);
297
298 using (IDataReader r = cmd.ExecuteReader())
299 {
300 while (r.Read())
301 {
302 EstateBan eb = new EstateBan();
313 303
314 UUID uuid = new UUID(); 304 UUID uuid = new UUID();
315 UUID.TryParse(r["bannedUUID"].ToString(), out uuid); 305 UUID.TryParse(r["bannedUUID"].ToString(), out uuid);
316 306
317 eb.BannedUserID = uuid; 307 eb.BannedUserID = uuid;
318 eb.BannedHostAddress = "0.0.0.0"; 308 eb.BannedHostAddress = "0.0.0.0";
319 eb.BannedHostIPMask = "0.0.0.0"; 309 eb.BannedHostIPMask = "0.0.0.0";
320 es.AddBan(eb); 310 es.AddBan(eb);
311 }
312 }
321 } 313 }
322 r.Close();
323 } 314 }
324 315
325 private void SaveBanList(EstateSettings es) 316 private void SaveBanList(EstateSettings es)
326 { 317 {
327 CheckConnection(); 318 CheckConnection();
328 319
329 MySqlCommand cmd = m_connection.CreateCommand(); 320 using (MySqlCommand cmd = m_connection.CreateCommand())
330
331 cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
332 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
333
334 cmd.ExecuteNonQuery();
335
336 cmd.Parameters.Clear();
337
338 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )";
339
340 foreach (EstateBan b in es.EstateBans)
341 { 321 {
322 cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
342 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); 323 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
343 cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString());
344 324
345 cmd.ExecuteNonQuery(); 325 cmd.ExecuteNonQuery();
326
346 cmd.Parameters.Clear(); 327 cmd.Parameters.Clear();
328
329 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( ?EstateID, ?bannedUUID, '', '', '' )";
330
331 foreach (EstateBan b in es.EstateBans)
332 {
333 cmd.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
334 cmd.Parameters.AddWithValue("?bannedUUID", b.BannedUserID.ToString());
335
336 cmd.ExecuteNonQuery();
337 cmd.Parameters.Clear();
338 }
347 } 339 }
348 } 340 }
349 341
@@ -351,24 +343,25 @@ namespace OpenSim.Data.MySQL
351 { 343 {
352 CheckConnection(); 344 CheckConnection();
353 345
354 MySqlCommand cmd = m_connection.CreateCommand(); 346 using (MySqlCommand cmd = m_connection.CreateCommand())
355
356 cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
357 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
358
359 cmd.ExecuteNonQuery();
360
361 cmd.Parameters.Clear();
362
363 cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )";
364
365 foreach (UUID uuid in data)
366 { 347 {
348 cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
367 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString()); 349 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
368 cmd.Parameters.AddWithValue("?uuid", uuid.ToString());
369 350
370 cmd.ExecuteNonQuery(); 351 cmd.ExecuteNonQuery();
352
371 cmd.Parameters.Clear(); 353 cmd.Parameters.Clear();
354
355 cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )";
356
357 foreach (UUID uuid in data)
358 {
359 cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
360 cmd.Parameters.AddWithValue("?uuid", uuid.ToString());
361
362 cmd.ExecuteNonQuery();
363 cmd.Parameters.Clear();
364 }
372 } 365 }
373 } 366 }
374 367
@@ -378,23 +371,24 @@ namespace OpenSim.Data.MySQL
378 371
379 CheckConnection(); 372 CheckConnection();
380 373
381 MySqlCommand cmd = m_connection.CreateCommand(); 374 using (MySqlCommand cmd = m_connection.CreateCommand())
382
383 cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
384 cmd.Parameters.AddWithValue("?EstateID", EstateID);
385
386 IDataReader r = cmd.ExecuteReader();
387
388 while (r.Read())
389 { 375 {
390 // EstateBan eb = new EstateBan(); 376 cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
377 cmd.Parameters.AddWithValue("?EstateID", EstateID);
391 378
392 UUID uuid = new UUID(); 379 using (IDataReader r = cmd.ExecuteReader())
393 UUID.TryParse(r["uuid"].ToString(), out uuid); 380 {
381 while (r.Read())
382 {
383 // EstateBan eb = new EstateBan();
394 384
395 uuids.Add(uuid); 385 UUID uuid = new UUID();
386 UUID.TryParse(r["uuid"].ToString(), out uuid);
387
388 uuids.Add(uuid);
389 }
390 }
396 } 391 }
397 r.Close();
398 392
399 return uuids.ToArray(); 393 return uuids.ToArray();
400 } 394 }