aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLGridData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLGridData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLGridData.cs579
1 files changed, 372 insertions, 207 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs
index 47edc4b..552dc04 100644
--- a/OpenSim/Data/MSSQL/MSSQLGridData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs
@@ -28,9 +28,8 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Data; 30using System.Data;
31using System.Data.SqlClient;
31using System.Reflection; 32using System.Reflection;
32using System.Security.Cryptography;
33using System.Text;
34using OpenMetaverse; 33using OpenMetaverse;
35using log4net; 34using log4net;
36using OpenSim.Framework; 35using OpenSim.Framework;
@@ -42,6 +41,8 @@ namespace OpenSim.Data.MSSQL
42 /// </summary> 41 /// </summary>
43 public class MSSQLGridData : GridDataBase 42 public class MSSQLGridData : GridDataBase
44 { 43 {
44 private const string _migrationStore = "GridStore";
45
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 47
47 /// <summary> 48 /// <summary>
@@ -49,49 +50,62 @@ namespace OpenSim.Data.MSSQL
49 /// </summary> 50 /// </summary>
50 private MSSQLManager database; 51 private MSSQLManager database;
51 52
52 private string m_regionsTableName; 53 private string m_regionsTableName = "regions";
54
55 #region IPlugin Members
53 56
54 override public void Initialise() 57 override public void Initialise()
55 { 58 {
56 m_log.Info("[MSSQLGridData]: " + Name + " cannot be default-initialized!"); 59 m_log.Info("[GRID DB]: " + Name + " cannot be default-initialized!");
57 throw new PluginNotInitialisedException (Name); 60 throw new PluginNotInitialisedException(Name);
58 } 61 }
59 62
60 /// <summary> 63 /// <summary>
61 /// Initialises the Grid Interface 64 /// Initialises the Grid Interface
62 /// </summary> 65 /// </summary>
63 /// <param name="connect">connect string</param> 66 /// <param name="connectionString">connect string</param>
64 /// <remarks>use mssql_connection.ini</remarks> 67 /// <remarks>use mssql_connection.ini</remarks>
65 override public void Initialise(string connect) 68 override public void Initialise(string connectionString)
66 { 69 {
67 // TODO: make the connect string actually do something 70 if (string.IsNullOrEmpty(connectionString))
68 IniFile iniFile = new IniFile("mssql_connection.ini");
69
70 string settingDataSource = iniFile.ParseFileReadValue("data_source");
71 string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
72 string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
73 string settingUserId = iniFile.ParseFileReadValue("user_id");
74 string settingPassword = iniFile.ParseFileReadValue("password");
75
76 m_regionsTableName = iniFile.ParseFileReadValue("regionstablename");
77 if (m_regionsTableName == null)
78 { 71 {
79 m_regionsTableName = "regions"; 72 database = new MSSQLManager(connectionString);
80 } 73 }
74 else
75 {
76 // TODO: make the connect string actually do something
77 IniFile iniFile = new IniFile("mssql_connection.ini");
78
79 string settingDataSource = iniFile.ParseFileReadValue("data_source");
80 string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
81 string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
82 string settingUserId = iniFile.ParseFileReadValue("user_id");
83 string settingPassword = iniFile.ParseFileReadValue("password");
81 84
82 database = 85 m_regionsTableName = iniFile.ParseFileReadValue("regionstablename");
83 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, 86 if (m_regionsTableName == null)
84 settingPassword); 87 {
88 m_regionsTableName = "regions";
89 }
90
91 database =
92 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
93 settingPassword);
94 }
85 95
96 //TODO this can be removed at a certain time
86 TestTables(); 97 TestTables();
98
99 //New migrations check of store
100 database.CheckMigration(_migrationStore);
87 } 101 }
88 102
89 /// <summary> 103 /// <summary>
90 /// 104 /// Test is region
91 /// </summary> 105 /// </summary>
92 private void TestTables() 106 private void TestTables()
93 { 107 {
94 using (IDbCommand cmd = database.Query("SELECT TOP 1 * FROM " + m_regionsTableName, new Dictionary<string, string>())) 108 using (AutoClosingSqlCommand cmd = database.Query("SELECT TOP 1 * FROM " + m_regionsTableName, new Dictionary<string, string>()))
95 { 109 {
96 try 110 try
97 { 111 {
@@ -103,6 +117,36 @@ namespace OpenSim.Data.MSSQL
103 database.ExecuteResourceSql("Mssql-regions.sql"); 117 database.ExecuteResourceSql("Mssql-regions.sql");
104 } 118 }
105 } 119 }
120 using (AutoClosingSqlCommand cmd = database.Query("select * from migrations where name = '" + _migrationStore + "'"))
121 {
122 //Special for Migrations to create backword compatible
123 try
124 {
125 bool insert = true;
126 using (SqlDataReader reader = cmd.ExecuteReader())
127 {
128 if (reader.Read()) insert = false;
129 }
130 if (insert)
131 {
132 cmd.CommandText = "insert into migrations(name, version) values('" + _migrationStore + "', 1)";
133 cmd.ExecuteNonQuery();
134 }
135 }
136 catch
137 {
138 //No migrations table
139 //HACK create one and add data
140 cmd.CommandText = "create table migrations(name varchar(100), version int)";
141 cmd.ExecuteNonQuery();
142
143 cmd.CommandText = "insert into migrations(name, version) values('migrations', 1)";
144 cmd.ExecuteNonQuery();
145
146 cmd.CommandText = "insert into migrations(name, version) values('" + _migrationStore + "', 1)";
147 cmd.ExecuteNonQuery();
148 }
149 }
106 } 150 }
107 151
108 /// <summary> 152 /// <summary>
@@ -110,7 +154,7 @@ namespace OpenSim.Data.MSSQL
110 /// </summary> 154 /// </summary>
111 override public void Dispose() 155 override public void Dispose()
112 { 156 {
113 // nothing to close 157 database = null;
114 } 158 }
115 159
116 /// <summary> 160 /// <summary>
@@ -131,18 +175,44 @@ namespace OpenSim.Data.MSSQL
131 get { return "0.1"; } 175 get { return "0.1"; }
132 } 176 }
133 177
178 #endregion
179
180 #region Public override GridDataBase methods
181
134 /// <summary> 182 /// <summary>
135 /// NOT IMPLEMENTED,
136 /// Returns a list of regions within the specified ranges 183 /// Returns a list of regions within the specified ranges
137 /// </summary> 184 /// </summary>
138 /// <param name="a">minimum X coordinate</param> 185 /// <param name="xmin">minimum X coordinate</param>
139 /// <param name="b">minimum Y coordinate</param> 186 /// <param name="ymin">minimum Y coordinate</param>
140 /// <param name="c">maximum X coordinate</param> 187 /// <param name="xmax">maximum X coordinate</param>
141 /// <param name="d">maximum Y coordinate</param> 188 /// <param name="ymax">maximum Y coordinate</param>
142 /// <returns>null</returns> 189 /// <returns>null</returns>
143 /// <remarks>always return null</remarks> 190 /// <remarks>always return null</remarks>
144 override public RegionProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) 191 override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
145 { 192 {
193 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM regions WHERE locX >= @xmin AND locX <= @xmax AND locY >= @ymin AND locY <= @ymax"))
194 {
195 command.Parameters.Add(database.CreateParameter("xmin", xmin));
196 command.Parameters.Add(database.CreateParameter("ymin", ymin));
197 command.Parameters.Add(database.CreateParameter("xmax", xmax));
198 command.Parameters.Add(database.CreateParameter("ymax", ymax));
199
200 List<RegionProfileData> rows = new List<RegionProfileData>();
201
202 using (SqlDataReader reader = command.ExecuteReader())
203 {
204 while (reader.Read())
205 {
206 rows.Add(ReadSimRow(reader));
207 }
208 }
209
210 if (rows.Count > 0)
211 {
212 return rows.ToArray();
213 }
214 }
215 m_log.Info("[GRID DB] : Found no regions within range.");
146 return null; 216 return null;
147 } 217 }
148 218
@@ -153,22 +223,20 @@ namespace OpenSim.Data.MSSQL
153 /// <returns>Sim profile</returns> 223 /// <returns>Sim profile</returns>
154 override public RegionProfileData GetProfileByHandle(ulong handle) 224 override public RegionProfileData GetProfileByHandle(ulong handle)
155 { 225 {
156 226 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle"))
157 Dictionary<string, string> param = new Dictionary<string, string>();
158 param["handle"] = handle.ToString();
159
160 try
161 { 227 {
162 using (IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle", param)) 228 command.Parameters.Add(database.CreateParameter("handle", handle));
163 using (IDataReader reader = result.ExecuteReader()) 229
230 using (SqlDataReader reader = command.ExecuteReader())
164 { 231 {
165 return database.getRegionRow(reader); 232 if (reader.Read())
233 {
234 return ReadSimRow(reader);
235 }
166 } 236 }
167 } 237 }
168 catch 238 m_log.InfoFormat("[GRID DB] : No region found with handle : {0}", handle);
169 { 239 return null;
170 return null;
171 }
172 } 240 }
173 241
174 /// <summary> 242 /// <summary>
@@ -178,50 +246,49 @@ namespace OpenSim.Data.MSSQL
178 /// <returns>The sim profile</returns> 246 /// <returns>The sim profile</returns>
179 override public RegionProfileData GetProfileByUUID(UUID uuid) 247 override public RegionProfileData GetProfileByUUID(UUID uuid)
180 { 248 {
181 Dictionary<string, string> param = new Dictionary<string, string>(); 249 using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid"))
182 param["uuid"] = uuid.ToString();
183
184 using (IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid", param))
185 using (IDataReader reader = result.ExecuteReader())
186 { 250 {
187 return database.getRegionRow(reader); 251 command.Parameters.Add(database.CreateParameter("uuid", uuid));
188 }
189 252
253 using (SqlDataReader reader = command.ExecuteReader())
254 {
255 if (reader.Read())
256 {
257 return ReadSimRow(reader);
258 }
259 }
260 }
261 m_log.InfoFormat("[GRID DB] : No region found with UUID : {0}", uuid);
262 return null;
190 } 263 }
191 264
192 /// <summary> 265 /// <summary>
193 /// Returns a sim profile from it's Region name string 266 /// Returns a sim profile from it's Region name string
194 /// </summary> 267 /// </summary>
195 /// <param name="uuid">The region name search query</param> 268 /// <param name="regionName">The region name search query</param>
196 /// <returns>The sim profile</returns> 269 /// <returns>The sim profile</returns>
197 override public RegionProfileData GetProfileByString(string regionName) 270 override public RegionProfileData GetProfileByString(string regionName)
198 { 271 {
199 if (regionName.Length > 2) 272 if (regionName.Length > 2)
200 { 273 {
201 try 274 using (AutoClosingSqlCommand command = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like @regionName order by regionName"))
202 { 275 {
203 Dictionary<string, string> param = new Dictionary<string, string>(); 276 command.Parameters.Add(database.CreateParameter("regionName", regionName + "%"));
204 // Add % because this is a like query. 277
205 param["?regionName"] = regionName + "%"; 278 using (SqlDataReader reader = command.ExecuteReader())
206 // Order by statement will return shorter matches first. Only returns one record or no record.
207 using (IDbCommand result = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like ?regionName order by regionName", param))
208 using (IDataReader reader = result.ExecuteReader())
209 { 279 {
210 return database.getRegionRow(reader); 280 if (reader.Read())
281 {
282 return ReadSimRow(reader);
283 }
211 } 284 }
212
213 } 285 }
214 catch (Exception e) 286 m_log.InfoFormat("[GRID DB] : No region found with regionName : {0}", regionName);
215 {
216 m_log.Error(e.ToString());
217 return null;
218 }
219 }
220 else
221 {
222 m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
223 return null; 287 return null;
224 } 288 }
289
290 m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
291 return null;
225 } 292 }
226 293
227 /// <summary> 294 /// <summary>
@@ -231,14 +298,11 @@ namespace OpenSim.Data.MSSQL
231 /// <returns>A dataresponse enum indicating success</returns> 298 /// <returns>A dataresponse enum indicating success</returns>
232 override public DataResponse AddProfile(RegionProfileData profile) 299 override public DataResponse AddProfile(RegionProfileData profile)
233 { 300 {
234 if (insertRegionRow(profile)) 301 if (InsertRegionRow(profile))
235 { 302 {
236 return DataResponse.RESPONSE_OK; 303 return DataResponse.RESPONSE_OK;
237 } 304 }
238 else 305 return DataResponse.RESPONSE_ERROR;
239 {
240 return DataResponse.RESPONSE_ERROR;
241 }
242 } 306 }
243 307
244 /// <summary> 308 /// <summary>
@@ -246,156 +310,43 @@ namespace OpenSim.Data.MSSQL
246 /// </summary> 310 /// </summary>
247 /// <param name="profile">The profile to update</param> 311 /// <param name="profile">The profile to update</param>
248 /// <returns>A dataresponse enum indicating success</returns> 312 /// <returns>A dataresponse enum indicating success</returns>
249 public override DataResponse UpdateProfile(RegionProfileData profile) 313 override public DataResponse UpdateProfile(RegionProfileData profile)
250 { 314 {
251 if (updateRegionRow(profile)) 315 if (UpdateRegionRow(profile))
252 { 316 {
253 return DataResponse.RESPONSE_OK; 317 return DataResponse.RESPONSE_OK;
254 } 318 }
255 else 319 return DataResponse.RESPONSE_ERROR;
256 {
257 return DataResponse.RESPONSE_ERROR;
258 }
259 } 320 }
260 321
261 /// <summary> 322 /// <summary>
262 /// Update the specified region in the database 323 /// Deletes a sim profile from the database
263 /// </summary> 324 /// </summary>
264 /// <param name="profile">The profile to update</param> 325 /// <param name="uuid">the sim UUID</param>
265 /// <returns>success ?</returns> 326 /// <returns>Successful?</returns>
266 public bool updateRegionRow(RegionProfileData profile) 327 //public DataResponse DeleteProfile(RegionProfileData profile)
328 override public DataResponse DeleteProfile(string uuid)
267 { 329 {
268 //Insert new region 330 using (AutoClosingSqlCommand command = database.Query("DELETE FROM regions WHERE uuid = @uuid;"))
269 string sql =
270 "UPDATE " + m_regionsTableName + @" SET
271 [regionHandle]=@regionHandle, [regionName]=@regionName,
272 [regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey,
273 [regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI,
274 [locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle,
275 [westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle,
276 [northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI,
277 [regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey,
278 [regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey,
279 [regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort,
280 [serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid
281 where [uuid]=@uuid";
282
283 Dictionary<string, string> parameters = new Dictionary<string, string>();
284
285 parameters["regionHandle"] = profile.regionHandle.ToString();
286 parameters["regionName"] = profile.regionName;
287 parameters["uuid"] = profile.ToString();
288 parameters["regionRecvKey"] = profile.regionRecvKey;
289 parameters["regionSecret"] = profile.regionSecret;
290 parameters["regionSendKey"] = profile.regionSendKey;
291 parameters["regionDataURI"] = profile.regionDataURI;
292 parameters["serverIP"] = profile.serverIP;
293 parameters["serverPort"] = profile.serverPort.ToString();
294 parameters["serverURI"] = profile.serverURI;
295 parameters["locX"] = profile.regionLocX.ToString();
296 parameters["locY"] = profile.regionLocY.ToString();
297 parameters["locZ"] = profile.regionLocZ.ToString();
298 parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
299 parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
300 parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
301 parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
302 parameters["regionAssetURI"] = profile.regionAssetURI;
303 parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
304 parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
305 parameters["regionUserURI"] = profile.regionUserURI;
306 parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
307 parameters["regionUserSendKey"] = profile.regionUserSendKey;
308 parameters["regionMapTexture"] = profile.regionMapTextureID.ToString();
309 parameters["serverHttpPort"] = profile.httpPort.ToString();
310 parameters["serverRemotingPort"] = profile.remotingPort.ToString();
311 parameters["owner_uuid"] = profile.owner_uuid.ToString();
312
313 bool returnval = false;
314
315 try
316 { 331 {
317 using (IDbCommand result = database.Query(sql, parameters)) 332 command.Parameters.Add(database.CreateParameter("uuid", uuid));
333 try
318 { 334 {
319 335 command.ExecuteNonQuery();
320 if (result.ExecuteNonQuery() == 1) 336 return DataResponse.RESPONSE_OK;
321 returnval = true;
322
323 } 337 }
324 } 338 catch (Exception e)
325 catch (Exception e)
326 {
327 m_log.Error("MSSQLManager : " + e.ToString());
328 }
329
330 return returnval;
331 }
332 /// <summary>
333 /// Creates a new region in the database
334 /// </summary>
335 /// <param name="profile">The region profile to insert</param>
336 /// <returns>Successful?</returns>
337 public bool insertRegionRow(RegionProfileData profile)
338 {
339 //Insert new region
340 string sql =
341 "INSERT INTO " + m_regionsTableName + @" ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI],
342 [serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle],
343 [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey],
344 [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort],
345 [serverRemotingPort], [owner_uuid])
346 VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI,
347 @serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle,
348 @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey,
349 @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid);";
350
351 Dictionary<string, string> parameters = new Dictionary<string, string>();
352
353 parameters["regionHandle"] = profile.regionHandle.ToString();
354 parameters["regionName"] = profile.regionName;
355 parameters["uuid"] = profile.ToString();
356 parameters["regionRecvKey"] = profile.regionRecvKey;
357 parameters["regionSecret"] = profile.regionSecret;
358 parameters["regionSendKey"] = profile.regionSendKey;
359 parameters["regionDataURI"] = profile.regionDataURI;
360 parameters["serverIP"] = profile.serverIP;
361 parameters["serverPort"] = profile.serverPort.ToString();
362 parameters["serverURI"] = profile.serverURI;
363 parameters["locX"] = profile.regionLocX.ToString();
364 parameters["locY"] = profile.regionLocY.ToString();
365 parameters["locZ"] = profile.regionLocZ.ToString();
366 parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
367 parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
368 parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
369 parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
370 parameters["regionAssetURI"] = profile.regionAssetURI;
371 parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
372 parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
373 parameters["regionUserURI"] = profile.regionUserURI;
374 parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
375 parameters["regionUserSendKey"] = profile.regionUserSendKey;
376 parameters["regionMapTexture"] = profile.regionMapTextureID.ToString();
377 parameters["serverHttpPort"] = profile.httpPort.ToString();
378 parameters["serverRemotingPort"] = profile.remotingPort.ToString();
379 parameters["owner_uuid"] = profile.owner_uuid.ToString();
380
381 bool returnval = false;
382
383 try
384 {
385 using (IDbCommand result = database.Query(sql, parameters))
386 { 339 {
387 if (result.ExecuteNonQuery() == 1) 340 m_log.DebugFormat("[GRID DB] : Error deleting region info, error is : {0}", e.Message);
388 returnval = true; 341 return DataResponse.RESPONSE_ERROR;
389 } 342 }
390 } 343 }
391 catch (Exception e)
392 {
393 m_log.Error("[GRID DB]: " + e.ToString());
394 }
395
396 return returnval;
397 } 344 }
398 345
346 #endregion
347
348 #region Methods that are not used or deprecated (still needed because of base class)
349
399 /// <summary> 350 /// <summary>
400 /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret. 351 /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
401 /// </summary> 352 /// </summary>
@@ -436,6 +387,7 @@ namespace OpenSim.Data.MSSQL
436 387
437 /// <summary> 388 /// <summary>
438 /// NOT IMPLEMENTED 389 /// NOT IMPLEMENTED
390 /// WHEN IS THIS GONNA BE IMPLEMENTED.
439 /// </summary> 391 /// </summary>
440 /// <param name="x"></param> 392 /// <param name="x"></param>
441 /// <param name="y"></param> 393 /// <param name="y"></param>
@@ -444,5 +396,218 @@ namespace OpenSim.Data.MSSQL
444 { 396 {
445 return null; 397 return null;
446 } 398 }
399
400 #endregion
401
402 #region private methods
403
404 /// <summary>
405 /// Reads a region row from a database reader
406 /// </summary>
407 /// <param name="reader">An active database reader</param>
408 /// <returns>A region profile</returns>
409 private static RegionProfileData ReadSimRow(IDataRecord reader)
410 {
411 RegionProfileData retval = new RegionProfileData();
412
413 // Region Main gotta-have-or-we-return-null parts
414 UInt64 tmp64;
415 if (!UInt64.TryParse(reader["regionHandle"].ToString(), out tmp64))
416 {
417 return null;
418 }
419
420 retval.regionHandle = tmp64;
421
422 UUID tmp_uuid;
423 if (!UUID.TryParse((string)reader["uuid"], out tmp_uuid))
424 {
425 return null;
426 }
427
428 retval.UUID = tmp_uuid;
429
430 // non-critical parts
431 retval.regionName = reader["regionName"].ToString();
432 retval.originUUID = new UUID((string)reader["originUUID"]);
433
434 // Secrets
435 retval.regionRecvKey = reader["regionRecvKey"].ToString();
436 retval.regionSecret = reader["regionSecret"].ToString();
437 retval.regionSendKey = reader["regionSendKey"].ToString();
438
439 // Region Server
440 retval.regionDataURI = reader["regionDataURI"].ToString();
441 retval.regionOnline = false; // Needs to be pinged before this can be set.
442 retval.serverIP = reader["serverIP"].ToString();
443 retval.serverPort = Convert.ToUInt32(reader["serverPort"]);
444 retval.serverURI = reader["serverURI"].ToString();
445 retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString());
446 retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString());
447
448 // Location
449 retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
450 retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
451 retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
452
453 // Neighbours - 0 = No Override
454 retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
455 retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
456 retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
457 retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
458
459 // Assets
460 retval.regionAssetURI = reader["regionAssetURI"].ToString();
461 retval.regionAssetRecvKey = reader["regionAssetRecvKey"].ToString();
462 retval.regionAssetSendKey = reader["regionAssetSendKey"].ToString();
463
464 // Userserver
465 retval.regionUserURI = reader["regionUserURI"].ToString();
466 retval.regionUserRecvKey = reader["regionUserRecvKey"].ToString();
467 retval.regionUserSendKey = reader["regionUserSendKey"].ToString();
468
469 // World Map Addition
470 UUID.TryParse((string)reader["regionMapTexture"], out retval.regionMapTextureID);
471 UUID.TryParse((string)reader["owner_uuid"], out retval.owner_uuid);
472
473 return retval;
474 }
475
476 /// <summary>
477 /// Update the specified region in the database
478 /// </summary>
479 /// <param name="profile">The profile to update</param>
480 /// <returns>success ?</returns>
481 private bool UpdateRegionRow(RegionProfileData profile)
482 {
483 bool returnval = false;
484
485 //Insert new region
486 string sql =
487 "UPDATE " + m_regionsTableName + @" SET
488 [regionHandle]=@regionHandle, [regionName]=@regionName,
489 [regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey,
490 [regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI,
491 [locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle,
492 [westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle,
493 [northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI,
494 [regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey,
495 [regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey,
496 [regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort,
497 [serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid , [originUUID]=@originUUID
498 where [uuid]=@uuid";
499
500 using (AutoClosingSqlCommand command = database.Query(sql))
501 {
502 command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle));
503 command.Parameters.Add(database.CreateParameter("regionName", profile.regionName));
504 command.Parameters.Add(database.CreateParameter("uuid", profile.UUID));
505 command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey));
506 command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret));
507 command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey));
508 command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI));
509 command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP));
510 command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort));
511 command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI));
512 command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX));
513 command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY));
514 command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ));
515 command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle));
516 command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle));
517 command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle));
518 command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle));
519 command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI));
520 command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey));
521 command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey));
522 command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI));
523 command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey));
524 command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey));
525 command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID));
526 command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort));
527 command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
528 command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
529 command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
530
531 try
532 {
533 command.ExecuteNonQuery();
534 returnval = true;
535 }
536 catch (Exception e)
537 {
538 m_log.Error("[GRID DB] : Error updating region, error: " + e.Message);
539 }
540 }
541
542 return returnval;
543 }
544
545 /// <summary>
546 /// Creates a new region in the database
547 /// </summary>
548 /// <param name="profile">The region profile to insert</param>
549 /// <returns>Successful?</returns>
550 private bool InsertRegionRow(RegionProfileData profile)
551 {
552 bool returnval = false;
553
554 //Insert new region
555 string sql =
556 "INSERT INTO " + m_regionsTableName + @" ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI],
557 [serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle],
558 [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey],
559 [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort],
560 [serverRemotingPort], [owner_uuid], [originUUID])
561 VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI,
562 @serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle,
563 @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey,
564 @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid, @originUUID);";
565
566 using (AutoClosingSqlCommand command = database.Query(sql))
567 {
568 command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle));
569 command.Parameters.Add(database.CreateParameter("regionName", profile.regionName));
570 command.Parameters.Add(database.CreateParameter("uuid", profile.UUID));
571 command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey));
572 command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret));
573 command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey));
574 command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI));
575 command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP));
576 command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort));
577 command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI));
578 command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX));
579 command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY));
580 command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ));
581 command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle));
582 command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle));
583 command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle));
584 command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle));
585 command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI));
586 command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey));
587 command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey));
588 command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI));
589 command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey));
590 command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey));
591 command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID));
592 command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort));
593 command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
594 command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
595 command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
596
597 try
598 {
599 command.ExecuteNonQuery();
600 returnval = true;
601 }
602 catch (Exception e)
603 {
604 m_log.Error("[GRID DB] : Error inserting region, error: " + e.Message);
605 }
606 }
607
608 return returnval;
609 }
610
611 #endregion
447 } 612 }
448} 613}