aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
diff options
context:
space:
mode:
authorTeravus Ovares2007-12-05 15:53:58 +0000
committerTeravus Ovares2007-12-05 15:53:58 +0000
commit71fd737a66c58faa6854ad1c1d8c58f64491fdb0 (patch)
treec9c876c361afbf76d416b7f2c413ff56a1f9beef /OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
parentmade one or two more methods in Scene virtual to allow overriding in sub clas... (diff)
downloadopensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.zip
opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.tar.gz
opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.tar.bz2
opensim-SC_OLD-71fd737a66c58faa6854ad1c1d8c58f64491fdb0.tar.xz
* Applied MSSQL Patch from akokko, Thanks! akokko
* This hasn't been tested in MSSQL mode, however it's been checked to make sure it doesn't cause any issues with mySQL/SQLlite
Diffstat (limited to 'OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs')
-rw-r--r--OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs452
1 files changed, 452 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
new file mode 100644
index 0000000..2c4dfdc
--- /dev/null
+++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
@@ -0,0 +1,452 @@
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 OpenSim 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.Data.SqlClient;
32using libsecondlife;
33using OpenSim.Framework.Console;
34
35namespace OpenSim.Framework.Data.MSSQL
36{
37 /// <summary>
38 /// A database interface class to a user profile storage system
39 /// </summary>
40 class MSSQLUserData : IUserData
41 {
42 /// <summary>
43 /// Database manager for MySQL
44 /// </summary>
45 public MSSQLManager database;
46
47 /// <summary>
48 /// Loads and initialises the MySQL storage plugin
49 /// </summary>
50 public void Initialise()
51 {
52 // Load from an INI file connection details
53 // TODO: move this to XML?
54 IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
55 string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
56 string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
57 string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
58 string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
59 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
60
61 database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
62 }
63
64 /// <summary>
65 /// Searches the database for a specified user profile
66 /// </summary>
67 /// <param name="name">The account name of the user</param>
68 /// <returns>A user profile</returns>
69 public UserProfileData GetUserByName(string name)
70 {
71 return GetUserByName(name.Split(' ')[0], name.Split(' ')[1]);
72 }
73
74 /// <summary>
75 /// Searches the database for a specified user profile by name components
76 /// </summary>
77 /// <param name="user">The first part of the account name</param>
78 /// <param name="last">The second part of the account name</param>
79 /// <returns>A user profile</returns>
80 public UserProfileData GetUserByName(string user, string last)
81 {
82 try
83 {
84 lock (database)
85 {
86 Dictionary<string, string> param = new Dictionary<string, string>();
87 param["first"] = user;
88 param["second"] = last;
89
90 IDbCommand result = database.Query("SELECT * FROM users WHERE username = @first AND lastname = @second", param);
91 IDataReader reader = result.ExecuteReader();
92
93 UserProfileData row = database.readUserRow(reader);
94
95 reader.Close();
96 result.Dispose();
97
98 return row;
99 }
100 }
101 catch (Exception e)
102 {
103 database.Reconnect();
104 MainLog.Instance.Error(e.ToString());
105 return null;
106 }
107 }
108
109 public List<OpenSim.Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
110 {
111 List<OpenSim.Framework.AvatarPickerAvatar> returnlist = new List<OpenSim.Framework.AvatarPickerAvatar>();
112 string[] querysplit;
113 querysplit = query.Split(' ');
114 if (querysplit.Length == 2)
115 {
116 try
117 {
118 lock (database)
119 {
120 Dictionary<string, string> param = new Dictionary<string, string>();
121 param["first"] = querysplit[0];
122 param["second"] = querysplit[1];
123
124 IDbCommand result =
125 database.Query("SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", param);
126 IDataReader reader = result.ExecuteReader();
127
128
129 while (reader.Read())
130 {
131 OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar();
132 user.AvatarID = new LLUUID((string)reader["UUID"]);
133 user.firstName = (string)reader["username"];
134 user.lastName = (string)reader["surname"];
135 returnlist.Add(user);
136
137 }
138 reader.Close();
139 result.Dispose();
140 }
141 }
142 catch (Exception e)
143 {
144 database.Reconnect();
145 MainLog.Instance.Error(e.ToString());
146 return returnlist;
147 }
148
149
150
151 }
152 else if (querysplit.Length == 1)
153 {
154
155 try
156 {
157 lock (database)
158 {
159 Dictionary<string, string> param = new Dictionary<string, string>();
160 param["first"] = querysplit[0];
161 param["second"] = querysplit[1];
162
163 IDbCommand result =
164 database.Query("SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", param);
165 IDataReader reader = result.ExecuteReader();
166
167
168 while (reader.Read())
169 {
170 OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar();
171 user.AvatarID = new LLUUID((string)reader["UUID"]);
172 user.firstName = (string)reader["username"];
173 user.lastName = (string)reader["surname"];
174 returnlist.Add(user);
175
176 }
177 reader.Close();
178 result.Dispose();
179 }
180 }
181 catch (Exception e)
182 {
183 database.Reconnect();
184 MainLog.Instance.Error(e.ToString());
185 return returnlist;
186 }
187 }
188 return returnlist;
189 }
190
191 /// <summary>
192 /// Searches the database for a specified user profile by UUID
193 /// </summary>
194 /// <param name="uuid">The account ID</param>
195 /// <returns>The users profile</returns>
196 public UserProfileData GetUserByUUID(LLUUID uuid)
197 {
198 try
199 {
200 lock (database)
201 {
202 Dictionary<string, string> param = new Dictionary<string, string>();
203 param["uuid"] = uuid.ToStringHyphenated();
204
205 IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = @uuid", param);
206 IDataReader reader = result.ExecuteReader();
207
208 UserProfileData row = database.readUserRow(reader);
209
210 reader.Close();
211 result.Dispose();
212
213 return row;
214 }
215 }
216 catch (Exception e)
217 {
218 database.Reconnect();
219 MainLog.Instance.Error(e.ToString());
220 return null;
221 }
222 }
223
224 /// <summary>
225 /// Returns a user session searching by name
226 /// </summary>
227 /// <param name="name">The account name</param>
228 /// <returns>The users session</returns>
229 public UserAgentData GetAgentByName(string name)
230 {
231 return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
232 }
233
234 /// <summary>
235 /// Returns a user session by account name
236 /// </summary>
237 /// <param name="user">First part of the users account name</param>
238 /// <param name="last">Second part of the users account name</param>
239 /// <returns>The users session</returns>
240 public UserAgentData GetAgentByName(string user, string last)
241 {
242 UserProfileData profile = GetUserByName(user, last);
243 return GetAgentByUUID(profile.UUID);
244 }
245
246 /// <summary>
247 /// Returns an agent session by account UUID
248 /// </summary>
249 /// <param name="uuid">The accounts UUID</param>
250 /// <returns>The users session</returns>
251 public UserAgentData GetAgentByUUID(LLUUID uuid)
252 {
253 try
254 {
255 lock (database)
256 {
257 Dictionary<string, string> param = new Dictionary<string, string>();
258 param["uuid"] = uuid.ToStringHyphenated();
259
260 IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = @uuid", param);
261 IDataReader reader = result.ExecuteReader();
262
263 UserAgentData row = database.readAgentRow(reader);
264
265 reader.Close();
266 result.Dispose();
267
268 return row;
269 }
270 }
271 catch (Exception e)
272 {
273 database.Reconnect();
274 MainLog.Instance.Error(e.ToString());
275 return null;
276 }
277 }
278
279 /// <summary>
280 /// Creates a new users profile
281 /// </summary>
282 /// <param name="user">The user profile to create</param>
283 public void AddNewUserProfile(UserProfileData user)
284 {
285 try
286 {
287 lock (database)
288 {
289 database.insertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, user.homeRegion, user.homeLocation.X, user.homeLocation.Y, user.homeLocation.Z,
290 user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, user.lastLogin, user.userInventoryURI, user.userAssetURI, user.profileCanDoMask, user.profileWantDoMask,
291 user.profileAboutText, user.profileFirstText, user.profileImage, user.profileFirstImage);
292 }
293 }
294 catch (Exception e)
295 {
296 database.Reconnect();
297 MainLog.Instance.Error(e.ToString());
298 }
299
300 }
301
302 /// <summary>
303 /// Creates a new agent
304 /// </summary>
305 /// <param name="agent">The agent to create</param>
306 public void AddNewUserAgent(UserAgentData agent)
307 {
308 // Do nothing.
309 }
310
311
312 public bool UpdateUserProfile(UserProfileData user)
313 {
314
315 SqlCommand command = new SqlCommand("UPDATE users set UUID = @uuid, " +
316 "username = @username, " +
317 "lastname = @lastname," +
318 "passwordHash = @passwordHash," +
319 "passwordSalt = @passwordSalt," +
320 "homeRegion = @homeRegion," +
321 "homeLocationX = @homeLocationX," +
322 "homeLocationY = @homeLocationY," +
323 "homeLocationZ = @homeLocationZ," +
324 "homeLookAtX = @homeLookAtX," +
325 "homeLookAtY = @homeLookAtY," +
326 "homeLookAtZ = @homeLookAtZ," +
327 "created = @created," +
328 "lastLogin = @lastLogin," +
329 "userInventoryURI = @userInventoryURI," +
330 "userAssetURI = @userAssetURI," +
331 "profileCanDoMask = @profileCanDoMask," +
332 "profileWantDoMask = @profileWantDoMask," +
333 "profileAboutText = @profileAboutText," +
334 "profileFirstText = @profileFirstText," +
335 "profileImage = @profileImage," +
336 "profileFirstImage = @profileFirstImage where " +
337 "UUID = @keyUUUID;", database.getConnection());
338 SqlParameter param1 = new SqlParameter("@uuid", user.UUID.ToStringHyphenated());
339 SqlParameter param2 = new SqlParameter("@username", user.username);
340 SqlParameter param3 = new SqlParameter("@lastname", user.surname);
341 SqlParameter param4 = new SqlParameter("@passwordHash", user.passwordHash);
342 SqlParameter param5 = new SqlParameter("@passwordSalt", user.passwordSalt);
343 SqlParameter param6 = new SqlParameter("@homeRegion", Convert.ToInt64(user.homeRegion));
344 SqlParameter param7 = new SqlParameter("@homeLocationX", user.homeLocation.X);
345 SqlParameter param8 = new SqlParameter("@homeLocationY", user.homeLocation.Y);
346 SqlParameter param9 = new SqlParameter("@homeLocationZ", user.homeLocation.Y);
347 SqlParameter param10 = new SqlParameter("@homeLookAtX", user.homeLookAt.X);
348 SqlParameter param11 = new SqlParameter("@homeLookAtY", user.homeLookAt.Y);
349 SqlParameter param12 = new SqlParameter("@homeLookAtZ", user.homeLookAt.Z);
350 SqlParameter param13 = new SqlParameter("@created", Convert.ToInt32(user.created));
351 SqlParameter param14 = new SqlParameter("@lastLogin", Convert.ToInt32(user.lastLogin));
352 SqlParameter param15 = new SqlParameter("@userInventoryURI", user.userInventoryURI);
353 SqlParameter param16 = new SqlParameter("@userAssetURI", user.userAssetURI);
354 SqlParameter param17 = new SqlParameter("@profileCanDoMask", Convert.ToInt32(user.profileCanDoMask));
355 SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.profileWantDoMask));
356 SqlParameter param19 = new SqlParameter("@profileAboutText", user.profileAboutText);
357 SqlParameter param20 = new SqlParameter("@profileFirstText", user.profileFirstText);
358 SqlParameter param21 = new SqlParameter("@profileImage", libsecondlife.LLUUID.Zero.ToStringHyphenated());
359 SqlParameter param22 = new SqlParameter("@profileFirstImage", libsecondlife.LLUUID.Zero.ToStringHyphenated());
360 SqlParameter param23 = new SqlParameter("@keyUUUID", user.UUID.ToStringHyphenated());
361 command.Parameters.Add(param1);
362 command.Parameters.Add(param2);
363 command.Parameters.Add(param3);
364 command.Parameters.Add(param4);
365 command.Parameters.Add(param5);
366 command.Parameters.Add(param6);
367 command.Parameters.Add(param7);
368 command.Parameters.Add(param8);
369 command.Parameters.Add(param9);
370 command.Parameters.Add(param10);
371 command.Parameters.Add(param11);
372 command.Parameters.Add(param12);
373 command.Parameters.Add(param13);
374 command.Parameters.Add(param14);
375 command.Parameters.Add(param15);
376 command.Parameters.Add(param16);
377 command.Parameters.Add(param17);
378 command.Parameters.Add(param18);
379 command.Parameters.Add(param19);
380 command.Parameters.Add(param20);
381 command.Parameters.Add(param21);
382 command.Parameters.Add(param22);
383 command.Parameters.Add(param23);
384 try
385 {
386 int affected = command.ExecuteNonQuery();
387 if (affected != 0) {
388 return true;
389 } else {
390 return false;
391 }
392 }
393 catch (Exception e)
394 {
395 MainLog.Instance.Error(e.ToString());
396 }
397 return false;
398 }
399
400 /// <summary>
401 /// Performs a money transfer request between two accounts
402 /// </summary>
403 /// <param name="from">The senders account ID</param>
404 /// <param name="to">The recievers account ID</param>
405 /// <param name="amount">The amount to transfer</param>
406 /// <returns>Success?</returns>
407 public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
408 {
409 return false;
410 }
411
412 /// <summary>
413 /// Performs an inventory transfer request between two accounts
414 /// </summary>
415 /// <remarks>TODO: Move to inventory server</remarks>
416 /// <param name="from">The senders account ID</param>
417 /// <param name="to">The recievers account ID</param>
418 /// <param name="item">The item to transfer</param>
419 /// <returns>Success?</returns>
420 public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
421 {
422 return false;
423 }
424
425 /// <summary>
426 /// Database provider name
427 /// </summary>
428 /// <returns>Provider name</returns>
429 public string getName()
430 {
431 return "MSSQL Userdata Interface";
432 }
433
434 /// <summary>
435 /// Database provider version
436 /// </summary>
437 /// <returns>provider version</returns>
438 public string GetVersion()
439 {
440 return database.getVersion();
441 }
442
443 /// <summary>
444 /// Not implemented
445 /// </summary>
446 /// <param name="query"></param>
447 public void runQuery(string query)
448 {
449 }
450
451 }
452} \ No newline at end of file