diff options
author | Sean Dague | 2008-04-02 15:24:31 +0000 |
---|---|---|
committer | Sean Dague | 2008-04-02 15:24:31 +0000 |
commit | c52c68f314c67c76c7181a6d0828f476290fbd66 (patch) | |
tree | 66ab347502892902a096fa985f31b25738eb1381 /OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | |
parent | reorganizing namespaces to put all the Data stuff into it's own namespace (diff) | |
download | opensim-SC_OLD-c52c68f314c67c76c7181a6d0828f476290fbd66.zip opensim-SC_OLD-c52c68f314c67c76c7181a6d0828f476290fbd66.tar.gz opensim-SC_OLD-c52c68f314c67c76c7181a6d0828f476290fbd66.tar.bz2 opensim-SC_OLD-c52c68f314c67c76c7181a6d0828f476290fbd66.tar.xz |
whole lot more moving
Diffstat (limited to 'OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs')
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 771 |
1 files changed, 0 insertions, 771 deletions
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs deleted file mode 100644 index be0417d..0000000 --- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs +++ /dev/null | |||
@@ -1,771 +0,0 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Data.SqlClient; | ||
32 | using libsecondlife; | ||
33 | using OpenSim.Framework.Console; | ||
34 | |||
35 | namespace OpenSim.Framework.Data.MSSQL | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A database interface class to a user profile storage system | ||
39 | /// </summary> | ||
40 | public class MSSQLUserData : UserDataBase | ||
41 | { | ||
42 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | /// <summary> | ||
45 | /// Database manager for MySQL | ||
46 | /// </summary> | ||
47 | public MSSQLManager database; | ||
48 | |||
49 | private string m_agentsTableName; | ||
50 | private string m_usersTableName; | ||
51 | private string m_userFriendsTableName; | ||
52 | |||
53 | /// <summary> | ||
54 | /// Loads and initialises the MySQL storage plugin | ||
55 | /// </summary> | ||
56 | override public void Initialise() | ||
57 | { | ||
58 | // Load from an INI file connection details | ||
59 | // TODO: move this to XML? | ||
60 | IniFile iniFile = new IniFile("mssql_connection.ini"); | ||
61 | string settingDataSource = iniFile.ParseFileReadValue("data_source"); | ||
62 | string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog"); | ||
63 | string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info"); | ||
64 | string settingUserId = iniFile.ParseFileReadValue("user_id"); | ||
65 | string settingPassword = iniFile.ParseFileReadValue("password"); | ||
66 | |||
67 | m_usersTableName = iniFile.ParseFileReadValue("userstablename"); | ||
68 | if (m_usersTableName == null) | ||
69 | { | ||
70 | m_usersTableName = "users"; | ||
71 | } | ||
72 | |||
73 | m_userFriendsTableName = iniFile.ParseFileReadValue("userfriendstablename"); | ||
74 | if (m_userFriendsTableName == null) | ||
75 | { | ||
76 | m_userFriendsTableName = "userfriends"; | ||
77 | } | ||
78 | |||
79 | m_agentsTableName = iniFile.ParseFileReadValue("agentstablename"); | ||
80 | if (m_agentsTableName == null) | ||
81 | { | ||
82 | m_agentsTableName = "agents"; | ||
83 | } | ||
84 | |||
85 | database = | ||
86 | new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||
87 | settingPassword); | ||
88 | |||
89 | TestTables(); | ||
90 | } | ||
91 | |||
92 | private bool TestTables() | ||
93 | { | ||
94 | IDbCommand cmd; | ||
95 | |||
96 | cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary<string, string>()); | ||
97 | try | ||
98 | { | ||
99 | cmd.ExecuteNonQuery(); | ||
100 | } | ||
101 | catch | ||
102 | { | ||
103 | database.ExecuteResourceSql("Mssql-users.sql"); | ||
104 | } | ||
105 | |||
106 | cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary<string, string>()); | ||
107 | try | ||
108 | { | ||
109 | cmd.ExecuteNonQuery(); | ||
110 | } | ||
111 | catch | ||
112 | { | ||
113 | database.ExecuteResourceSql("Mssql-agents.sql"); | ||
114 | } | ||
115 | |||
116 | cmd = database.Query("select top 1 * from " + m_userFriendsTableName, new Dictionary<string, string>()); | ||
117 | try | ||
118 | { | ||
119 | cmd.ExecuteNonQuery(); | ||
120 | } | ||
121 | catch | ||
122 | { | ||
123 | database.ExecuteResourceSql("CreateUserFriendsTable.sql"); | ||
124 | } | ||
125 | |||
126 | return true; | ||
127 | } | ||
128 | /// <summary> | ||
129 | /// Searches the database for a specified user profile by name components | ||
130 | /// </summary> | ||
131 | /// <param name="user">The first part of the account name</param> | ||
132 | /// <param name="last">The second part of the account name</param> | ||
133 | /// <returns>A user profile</returns> | ||
134 | override public UserProfileData GetUserByName(string user, string last) | ||
135 | { | ||
136 | try | ||
137 | { | ||
138 | lock (database) | ||
139 | { | ||
140 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
141 | param["first"] = user; | ||
142 | param["second"] = last; | ||
143 | |||
144 | IDbCommand result = | ||
145 | database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", param); | ||
146 | IDataReader reader = result.ExecuteReader(); | ||
147 | |||
148 | UserProfileData row = database.readUserRow(reader); | ||
149 | |||
150 | reader.Close(); | ||
151 | result.Dispose(); | ||
152 | |||
153 | return row; | ||
154 | } | ||
155 | } | ||
156 | catch (Exception e) | ||
157 | { | ||
158 | database.Reconnect(); | ||
159 | m_log.Error(e.ToString()); | ||
160 | return null; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | #region User Friends List Data | ||
165 | |||
166 | override public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) | ||
167 | { | ||
168 | int dtvalue = Util.UnixTimeSinceEpoch(); | ||
169 | |||
170 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
171 | param["@ownerID"] = friendlistowner.UUID.ToString(); | ||
172 | param["@friendID"] = friend.UUID.ToString(); | ||
173 | param["@friendPerms"] = perms.ToString(); | ||
174 | param["@datetimestamp"] = dtvalue.ToString(); | ||
175 | |||
176 | try | ||
177 | { | ||
178 | lock (database) | ||
179 | { | ||
180 | IDbCommand adder = | ||
181 | database.Query( | ||
182 | "INSERT INTO " + m_userFriendsTableName + " " + | ||
183 | "(ownerID,friendID,friendPerms,datetimestamp) " + | ||
184 | "VALUES " + | ||
185 | "(@ownerID,@friendID,@friendPerms,@datetimestamp)", | ||
186 | param); | ||
187 | |||
188 | adder.ExecuteNonQuery(); | ||
189 | |||
190 | adder = | ||
191 | database.Query( | ||
192 | "INSERT INTO " + m_userFriendsTableName + " " + | ||
193 | "(ownerID,friendID,friendPerms,datetimestamp) " + | ||
194 | "VALUES " + | ||
195 | "(@friendID,@ownerID,@friendPerms,@datetimestamp)", | ||
196 | param); | ||
197 | adder.ExecuteNonQuery(); | ||
198 | |||
199 | } | ||
200 | } | ||
201 | catch (Exception e) | ||
202 | { | ||
203 | database.Reconnect(); | ||
204 | m_log.Error(e.ToString()); | ||
205 | return; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | override public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) | ||
210 | { | ||
211 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
212 | param["@ownerID"] = friendlistowner.UUID.ToString(); | ||
213 | param["@friendID"] = friend.UUID.ToString(); | ||
214 | |||
215 | |||
216 | try | ||
217 | { | ||
218 | lock (database) | ||
219 | { | ||
220 | IDbCommand updater = | ||
221 | database.Query( | ||
222 | "delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID", | ||
223 | param); | ||
224 | updater.ExecuteNonQuery(); | ||
225 | |||
226 | updater = | ||
227 | database.Query( | ||
228 | "delete from " + m_userFriendsTableName + " where ownerID = @friendID and friendID = @ownerID", | ||
229 | param); | ||
230 | updater.ExecuteNonQuery(); | ||
231 | |||
232 | } | ||
233 | } | ||
234 | catch (Exception e) | ||
235 | { | ||
236 | database.Reconnect(); | ||
237 | m_log.Error(e.ToString()); | ||
238 | return; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | override public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) | ||
243 | { | ||
244 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
245 | param["@ownerID"] = friendlistowner.UUID.ToString(); | ||
246 | param["@friendID"] = friend.UUID.ToString(); | ||
247 | param["@friendPerms"] = perms.ToString(); | ||
248 | |||
249 | |||
250 | try | ||
251 | { | ||
252 | lock (database) | ||
253 | { | ||
254 | IDbCommand updater = | ||
255 | database.Query( | ||
256 | "update " + m_userFriendsTableName + | ||
257 | " SET friendPerms = @friendPerms " + | ||
258 | "where ownerID = @ownerID and friendID = @friendID", | ||
259 | param); | ||
260 | |||
261 | updater.ExecuteNonQuery(); | ||
262 | } | ||
263 | } | ||
264 | catch (Exception e) | ||
265 | { | ||
266 | database.Reconnect(); | ||
267 | m_log.Error(e.ToString()); | ||
268 | return; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | |||
273 | override public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) | ||
274 | { | ||
275 | List<FriendListItem> Lfli = new List<FriendListItem>(); | ||
276 | |||
277 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
278 | param["@ownerID"] = friendlistowner.UUID.ToString(); | ||
279 | |||
280 | try | ||
281 | { | ||
282 | lock (database) | ||
283 | { | ||
284 | //Left Join userfriends to itself | ||
285 | IDbCommand result = | ||
286 | database.Query( | ||
287 | "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" + | ||
288 | " where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID", | ||
289 | param); | ||
290 | IDataReader reader = result.ExecuteReader(); | ||
291 | |||
292 | |||
293 | while (reader.Read()) | ||
294 | { | ||
295 | FriendListItem fli = new FriendListItem(); | ||
296 | fli.FriendListOwner = new LLUUID((string)reader["ownerID"]); | ||
297 | fli.Friend = new LLUUID((string)reader["friendID"]); | ||
298 | fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]); | ||
299 | |||
300 | // This is not a real column in the database table, it's a joined column from the opposite record | ||
301 | fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]); | ||
302 | |||
303 | Lfli.Add(fli); | ||
304 | } | ||
305 | reader.Close(); | ||
306 | result.Dispose(); | ||
307 | } | ||
308 | } | ||
309 | catch (Exception e) | ||
310 | { | ||
311 | database.Reconnect(); | ||
312 | m_log.Error(e.ToString()); | ||
313 | return Lfli; | ||
314 | } | ||
315 | |||
316 | return Lfli; | ||
317 | } | ||
318 | |||
319 | #endregion | ||
320 | |||
321 | override public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid) | ||
322 | { | ||
323 | m_log.Info("[USER]: Stub UpdateUserCUrrentRegion called"); | ||
324 | } | ||
325 | |||
326 | |||
327 | |||
328 | override public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) | ||
329 | { | ||
330 | List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>(); | ||
331 | string[] querysplit; | ||
332 | querysplit = query.Split(' '); | ||
333 | if (querysplit.Length == 2) | ||
334 | { | ||
335 | try | ||
336 | { | ||
337 | lock (database) | ||
338 | { | ||
339 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
340 | param["first"] = querysplit[0]; | ||
341 | param["second"] = querysplit[1]; | ||
342 | |||
343 | IDbCommand result = | ||
344 | database.Query( | ||
345 | "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", | ||
346 | param); | ||
347 | IDataReader reader = result.ExecuteReader(); | ||
348 | |||
349 | |||
350 | while (reader.Read()) | ||
351 | { | ||
352 | Framework.AvatarPickerAvatar user = new Framework.AvatarPickerAvatar(); | ||
353 | user.AvatarID = new LLUUID((string)reader["UUID"]); | ||
354 | user.firstName = (string)reader["username"]; | ||
355 | user.lastName = (string)reader["lastname"]; | ||
356 | returnlist.Add(user); | ||
357 | } | ||
358 | reader.Close(); | ||
359 | result.Dispose(); | ||
360 | } | ||
361 | } | ||
362 | catch (Exception e) | ||
363 | { | ||
364 | database.Reconnect(); | ||
365 | m_log.Error(e.ToString()); | ||
366 | return returnlist; | ||
367 | } | ||
368 | } | ||
369 | else if (querysplit.Length == 1) | ||
370 | { | ||
371 | try | ||
372 | { | ||
373 | lock (database) | ||
374 | { | ||
375 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
376 | param["first"] = querysplit[0]; | ||
377 | |||
378 | IDbCommand result = | ||
379 | database.Query( | ||
380 | "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first OR lastname = @first", | ||
381 | param); | ||
382 | IDataReader reader = result.ExecuteReader(); | ||
383 | |||
384 | |||
385 | while (reader.Read()) | ||
386 | { | ||
387 | Framework.AvatarPickerAvatar user = new Framework.AvatarPickerAvatar(); | ||
388 | user.AvatarID = new LLUUID((string)reader["UUID"]); | ||
389 | user.firstName = (string)reader["username"]; | ||
390 | user.lastName = (string)reader["lastname"]; | ||
391 | returnlist.Add(user); | ||
392 | } | ||
393 | reader.Close(); | ||
394 | result.Dispose(); | ||
395 | } | ||
396 | } | ||
397 | catch (Exception e) | ||
398 | { | ||
399 | database.Reconnect(); | ||
400 | m_log.Error(e.ToString()); | ||
401 | return returnlist; | ||
402 | } | ||
403 | } | ||
404 | return returnlist; | ||
405 | } | ||
406 | |||
407 | // See IUserData | ||
408 | override public UserProfileData GetUserByUUID(LLUUID uuid) | ||
409 | { | ||
410 | try | ||
411 | { | ||
412 | lock (database) | ||
413 | { | ||
414 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
415 | param["uuid"] = uuid.ToString(); | ||
416 | |||
417 | IDbCommand result = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = @uuid", param); | ||
418 | IDataReader reader = result.ExecuteReader(); | ||
419 | |||
420 | UserProfileData row = database.readUserRow(reader); | ||
421 | |||
422 | reader.Close(); | ||
423 | result.Dispose(); | ||
424 | |||
425 | return row; | ||
426 | } | ||
427 | } | ||
428 | catch (Exception e) | ||
429 | { | ||
430 | database.Reconnect(); | ||
431 | m_log.Error(e.ToString()); | ||
432 | return null; | ||
433 | } | ||
434 | } | ||
435 | |||
436 | /// <summary> | ||
437 | /// Returns a user session searching by name | ||
438 | /// </summary> | ||
439 | /// <param name="name">The account name</param> | ||
440 | /// <returns>The users session</returns> | ||
441 | override public UserAgentData GetAgentByName(string name) | ||
442 | { | ||
443 | return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
444 | } | ||
445 | |||
446 | /// <summary> | ||
447 | /// Returns a user session by account name | ||
448 | /// </summary> | ||
449 | /// <param name="user">First part of the users account name</param> | ||
450 | /// <param name="last">Second part of the users account name</param> | ||
451 | /// <returns>The users session</returns> | ||
452 | override public UserAgentData GetAgentByName(string user, string last) | ||
453 | { | ||
454 | UserProfileData profile = GetUserByName(user, last); | ||
455 | return GetAgentByUUID(profile.UUID); | ||
456 | } | ||
457 | |||
458 | /// <summary> | ||
459 | /// Returns an agent session by account UUID | ||
460 | /// </summary> | ||
461 | /// <param name="uuid">The accounts UUID</param> | ||
462 | /// <returns>The users session</returns> | ||
463 | override public UserAgentData GetAgentByUUID(LLUUID uuid) | ||
464 | { | ||
465 | try | ||
466 | { | ||
467 | lock (database) | ||
468 | { | ||
469 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
470 | param["uuid"] = uuid.ToString(); | ||
471 | |||
472 | IDbCommand result = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = @uuid", param); | ||
473 | IDataReader reader = result.ExecuteReader(); | ||
474 | |||
475 | UserAgentData row = database.readAgentRow(reader); | ||
476 | |||
477 | reader.Close(); | ||
478 | result.Dispose(); | ||
479 | |||
480 | return row; | ||
481 | } | ||
482 | } | ||
483 | catch (Exception e) | ||
484 | { | ||
485 | database.Reconnect(); | ||
486 | m_log.Error(e.ToString()); | ||
487 | return null; | ||
488 | } | ||
489 | } | ||
490 | override public void StoreWebLoginKey(LLUUID AgentID, LLUUID WebLoginKey) | ||
491 | { | ||
492 | UserProfileData user = GetUserByUUID(AgentID); | ||
493 | user.webLoginKey = WebLoginKey; | ||
494 | UpdateUserProfile(user); | ||
495 | |||
496 | } | ||
497 | /// <summary> | ||
498 | /// Creates a new users profile | ||
499 | /// </summary> | ||
500 | /// <param name="user">The user profile to create</param> | ||
501 | override public void AddNewUserProfile(UserProfileData user) | ||
502 | { | ||
503 | try | ||
504 | { | ||
505 | lock (database) | ||
506 | { | ||
507 | InsertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, | ||
508 | user.homeRegion, user.homeLocation.X, user.homeLocation.Y, | ||
509 | user.homeLocation.Z, | ||
510 | user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, | ||
511 | user.lastLogin, user.userInventoryURI, user.userAssetURI, | ||
512 | user.profileCanDoMask, user.profileWantDoMask, | ||
513 | user.profileAboutText, user.profileFirstText, user.profileImage, | ||
514 | user.profileFirstImage, user.webLoginKey); | ||
515 | } | ||
516 | } | ||
517 | catch (Exception e) | ||
518 | { | ||
519 | database.Reconnect(); | ||
520 | m_log.Error(e.ToString()); | ||
521 | } | ||
522 | } | ||
523 | |||
524 | /// <summary> | ||
525 | /// Creates a new user and inserts it into the database | ||
526 | /// </summary> | ||
527 | /// <param name="uuid">User ID</param> | ||
528 | /// <param name="username">First part of the login</param> | ||
529 | /// <param name="lastname">Second part of the login</param> | ||
530 | /// <param name="passwordHash">A salted hash of the users password</param> | ||
531 | /// <param name="passwordSalt">The salt used for the password hash</param> | ||
532 | /// <param name="homeRegion">A regionHandle of the users home region</param> | ||
533 | /// <param name="homeLocX">Home region position vector</param> | ||
534 | /// <param name="homeLocY">Home region position vector</param> | ||
535 | /// <param name="homeLocZ">Home region position vector</param> | ||
536 | /// <param name="homeLookAtX">Home region 'look at' vector</param> | ||
537 | /// <param name="homeLookAtY">Home region 'look at' vector</param> | ||
538 | /// <param name="homeLookAtZ">Home region 'look at' vector</param> | ||
539 | /// <param name="created">Account created (unix timestamp)</param> | ||
540 | /// <param name="lastlogin">Last login (unix timestamp)</param> | ||
541 | /// <param name="inventoryURI">Users inventory URI</param> | ||
542 | /// <param name="assetURI">Users asset URI</param> | ||
543 | /// <param name="canDoMask">I can do mask</param> | ||
544 | /// <param name="wantDoMask">I want to do mask</param> | ||
545 | /// <param name="aboutText">Profile text</param> | ||
546 | /// <param name="firstText">Firstlife text</param> | ||
547 | /// <param name="profileImage">UUID for profile image</param> | ||
548 | /// <param name="firstImage">UUID for firstlife image</param> | ||
549 | /// <returns>Success?</returns> | ||
550 | private bool InsertUserRow(LLUUID uuid, string username, string lastname, string passwordHash, | ||
551 | string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ, | ||
552 | float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, | ||
553 | string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, | ||
554 | string aboutText, string firstText, | ||
555 | LLUUID profileImage, LLUUID firstImage, LLUUID webLoginKey) | ||
556 | { | ||
557 | string sql = "INSERT INTO "+m_usersTableName; | ||
558 | sql += " ([UUID], [username], [lastname], [passwordHash], [passwordSalt], [homeRegion], "; | ||
559 | sql += | ||
560 | "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], "; | ||
561 | sql += | ||
562 | "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], "; | ||
563 | sql += "[profileFirstText], [profileImage], [profileFirstImage], [webLoginKey]) VALUES "; | ||
564 | |||
565 | sql += "(@UUID, @username, @lastname, @passwordHash, @passwordSalt, @homeRegion, "; | ||
566 | sql += | ||
567 | "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, "; | ||
568 | sql += | ||
569 | "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, "; | ||
570 | sql += "@profileFirstText, @profileImage, @profileFirstImage, @webLoginKey);"; | ||
571 | |||
572 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
573 | parameters["UUID"] = uuid.ToString(); | ||
574 | parameters["username"] = username.ToString(); | ||
575 | parameters["lastname"] = lastname.ToString(); | ||
576 | parameters["passwordHash"] = passwordHash.ToString(); | ||
577 | parameters["passwordSalt"] = passwordSalt.ToString(); | ||
578 | parameters["homeRegion"] = homeRegion.ToString(); | ||
579 | parameters["homeLocationX"] = homeLocX.ToString(); | ||
580 | parameters["homeLocationY"] = homeLocY.ToString(); | ||
581 | parameters["homeLocationZ"] = homeLocZ.ToString(); | ||
582 | parameters["homeLookAtX"] = homeLookAtX.ToString(); | ||
583 | parameters["homeLookAtY"] = homeLookAtY.ToString(); | ||
584 | parameters["homeLookAtZ"] = homeLookAtZ.ToString(); | ||
585 | parameters["created"] = created.ToString(); | ||
586 | parameters["lastLogin"] = lastlogin.ToString(); | ||
587 | parameters["userInventoryURI"] = String.Empty; | ||
588 | parameters["userAssetURI"] = String.Empty; | ||
589 | parameters["profileCanDoMask"] = "0"; | ||
590 | parameters["profileWantDoMask"] = "0"; | ||
591 | parameters["profileAboutText"] = aboutText; | ||
592 | parameters["profileFirstText"] = firstText; | ||
593 | parameters["profileImage"] = profileImage.ToString(); | ||
594 | parameters["profileFirstImage"] = firstImage.ToString(); | ||
595 | parameters["webLoginKey"] = LLUUID.Random().ToString(); | ||
596 | |||
597 | bool returnval = false; | ||
598 | |||
599 | try | ||
600 | { | ||
601 | IDbCommand result = database.Query(sql, parameters); | ||
602 | |||
603 | if (result.ExecuteNonQuery() == 1) | ||
604 | returnval = true; | ||
605 | |||
606 | result.Dispose(); | ||
607 | } | ||
608 | catch (Exception e) | ||
609 | { | ||
610 | m_log.Error(e.ToString()); | ||
611 | return false; | ||
612 | } | ||
613 | |||
614 | return returnval; | ||
615 | } | ||
616 | |||
617 | /// <summary> | ||
618 | /// Creates a new agent | ||
619 | /// </summary> | ||
620 | /// <param name="agent">The agent to create</param> | ||
621 | override public void AddNewUserAgent(UserAgentData agent) | ||
622 | { | ||
623 | // Do nothing. | ||
624 | } | ||
625 | |||
626 | |||
627 | override public bool UpdateUserProfile(UserProfileData user) | ||
628 | { | ||
629 | SqlCommand command = new SqlCommand("UPDATE " + m_usersTableName + " set UUID = @uuid, " + | ||
630 | "username = @username, " + | ||
631 | "lastname = @lastname," + | ||
632 | "passwordHash = @passwordHash," + | ||
633 | "passwordSalt = @passwordSalt," + | ||
634 | "homeRegion = @homeRegion," + | ||
635 | "homeLocationX = @homeLocationX," + | ||
636 | "homeLocationY = @homeLocationY," + | ||
637 | "homeLocationZ = @homeLocationZ," + | ||
638 | "homeLookAtX = @homeLookAtX," + | ||
639 | "homeLookAtY = @homeLookAtY," + | ||
640 | "homeLookAtZ = @homeLookAtZ," + | ||
641 | "created = @created," + | ||
642 | "lastLogin = @lastLogin," + | ||
643 | "userInventoryURI = @userInventoryURI," + | ||
644 | "userAssetURI = @userAssetURI," + | ||
645 | "profileCanDoMask = @profileCanDoMask," + | ||
646 | "profileWantDoMask = @profileWantDoMask," + | ||
647 | "profileAboutText = @profileAboutText," + | ||
648 | "profileFirstText = @profileFirstText," + | ||
649 | "profileImage = @profileImage," + | ||
650 | "profileFirstImage = @profileFirstImage, " + | ||
651 | "webLoginKey = @webLoginKey where " + | ||
652 | "UUID = @keyUUUID;", database.getConnection()); | ||
653 | SqlParameter param1 = new SqlParameter("@uuid", user.UUID.ToString()); | ||
654 | SqlParameter param2 = new SqlParameter("@username", user.username); | ||
655 | SqlParameter param3 = new SqlParameter("@lastname", user.surname); | ||
656 | SqlParameter param4 = new SqlParameter("@passwordHash", user.passwordHash); | ||
657 | SqlParameter param5 = new SqlParameter("@passwordSalt", user.passwordSalt); | ||
658 | SqlParameter param6 = new SqlParameter("@homeRegion", Convert.ToInt64(user.homeRegion)); | ||
659 | SqlParameter param7 = new SqlParameter("@homeLocationX", user.homeLocation.X); | ||
660 | SqlParameter param8 = new SqlParameter("@homeLocationY", user.homeLocation.Y); | ||
661 | SqlParameter param9 = new SqlParameter("@homeLocationZ", user.homeLocation.Y); | ||
662 | SqlParameter param10 = new SqlParameter("@homeLookAtX", user.homeLookAt.X); | ||
663 | SqlParameter param11 = new SqlParameter("@homeLookAtY", user.homeLookAt.Y); | ||
664 | SqlParameter param12 = new SqlParameter("@homeLookAtZ", user.homeLookAt.Z); | ||
665 | SqlParameter param13 = new SqlParameter("@created", Convert.ToInt32(user.created)); | ||
666 | SqlParameter param14 = new SqlParameter("@lastLogin", Convert.ToInt32(user.lastLogin)); | ||
667 | SqlParameter param15 = new SqlParameter("@userInventoryURI", user.userInventoryURI); | ||
668 | SqlParameter param16 = new SqlParameter("@userAssetURI", user.userAssetURI); | ||
669 | SqlParameter param17 = new SqlParameter("@profileCanDoMask", Convert.ToInt32(user.profileCanDoMask)); | ||
670 | SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.profileWantDoMask)); | ||
671 | SqlParameter param19 = new SqlParameter("@profileAboutText", user.profileAboutText); | ||
672 | SqlParameter param20 = new SqlParameter("@profileFirstText", user.profileFirstText); | ||
673 | SqlParameter param21 = new SqlParameter("@profileImage", user.profileImage.ToString()); | ||
674 | SqlParameter param22 = new SqlParameter("@profileFirstImage", user.profileFirstImage.ToString()); | ||
675 | SqlParameter param23 = new SqlParameter("@keyUUUID", user.UUID.ToString()); | ||
676 | SqlParameter param24 = new SqlParameter("@webLoginKey", user.webLoginKey.UUID.ToString()); | ||
677 | command.Parameters.Add(param1); | ||
678 | command.Parameters.Add(param2); | ||
679 | command.Parameters.Add(param3); | ||
680 | command.Parameters.Add(param4); | ||
681 | command.Parameters.Add(param5); | ||
682 | command.Parameters.Add(param6); | ||
683 | command.Parameters.Add(param7); | ||
684 | command.Parameters.Add(param8); | ||
685 | command.Parameters.Add(param9); | ||
686 | command.Parameters.Add(param10); | ||
687 | command.Parameters.Add(param11); | ||
688 | command.Parameters.Add(param12); | ||
689 | command.Parameters.Add(param13); | ||
690 | command.Parameters.Add(param14); | ||
691 | command.Parameters.Add(param15); | ||
692 | command.Parameters.Add(param16); | ||
693 | command.Parameters.Add(param17); | ||
694 | command.Parameters.Add(param18); | ||
695 | command.Parameters.Add(param19); | ||
696 | command.Parameters.Add(param20); | ||
697 | command.Parameters.Add(param21); | ||
698 | command.Parameters.Add(param22); | ||
699 | command.Parameters.Add(param23); | ||
700 | command.Parameters.Add(param24); | ||
701 | try | ||
702 | { | ||
703 | int affected = command.ExecuteNonQuery(); | ||
704 | if (affected != 0) | ||
705 | { | ||
706 | return true; | ||
707 | } | ||
708 | else | ||
709 | { | ||
710 | return false; | ||
711 | } | ||
712 | } | ||
713 | catch (Exception e) | ||
714 | { | ||
715 | m_log.Error(e.ToString()); | ||
716 | } | ||
717 | return false; | ||
718 | } | ||
719 | |||
720 | /// <summary> | ||
721 | /// Performs a money transfer request between two accounts | ||
722 | /// </summary> | ||
723 | /// <param name="from">The senders account ID</param> | ||
724 | /// <param name="to">The receivers account ID</param> | ||
725 | /// <param name="amount">The amount to transfer</param> | ||
726 | /// <returns>Success?</returns> | ||
727 | override public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount) | ||
728 | { | ||
729 | return false; | ||
730 | } | ||
731 | |||
732 | /// <summary> | ||
733 | /// Performs an inventory transfer request between two accounts | ||
734 | /// </summary> | ||
735 | /// <remarks>TODO: Move to inventory server</remarks> | ||
736 | /// <param name="from">The senders account ID</param> | ||
737 | /// <param name="to">The receivers account ID</param> | ||
738 | /// <param name="item">The item to transfer</param> | ||
739 | /// <returns>Success?</returns> | ||
740 | override public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item) | ||
741 | { | ||
742 | return false; | ||
743 | } | ||
744 | |||
745 | /// <summary> | ||
746 | /// Database provider name | ||
747 | /// </summary> | ||
748 | /// <returns>Provider name</returns> | ||
749 | override public string getName() | ||
750 | { | ||
751 | return "MSSQL Userdata Interface"; | ||
752 | } | ||
753 | |||
754 | /// <summary> | ||
755 | /// Database provider version | ||
756 | /// </summary> | ||
757 | /// <returns>provider version</returns> | ||
758 | override public string GetVersion() | ||
759 | { | ||
760 | return database.getVersion(); | ||
761 | } | ||
762 | |||
763 | /// <summary> | ||
764 | /// Not implemented | ||
765 | /// </summary> | ||
766 | /// <param name="query"></param> | ||
767 | public void runQuery(string query) | ||
768 | { | ||
769 | } | ||
770 | } | ||
771 | } | ||