aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
diff options
context:
space:
mode:
authorTeravus Ovares2007-12-31 22:56:43 +0000
committerTeravus Ovares2007-12-31 22:56:43 +0000
commit3180432debcd9078e8e838d4bbe3ddaf9cdfe110 (patch)
treeb838c1b5b6f3bb7b2baf5c013b1e74a44caa909f /OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
parentMove unused inventory files into the attic (diff)
downloadopensim-SC_OLD-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.zip
opensim-SC_OLD-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.tar.gz
opensim-SC_OLD-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.tar.bz2
opensim-SC_OLD-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.tar.xz
* Added database and UserManagerBase glue for FriendsList management
* Don't forget to run prebuild
Diffstat (limited to 'OpenSim/Framework/Data.SQLite/SQLiteUserData.cs')
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteUserData.cs190
1 files changed, 186 insertions, 4 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
index 48a09d3..c97dc52 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
@@ -46,9 +46,11 @@ namespace OpenSim.Framework.Data.SQLite
46 /// Artificial constructor called upon plugin load 46 /// Artificial constructor called upon plugin load
47 /// </summary> 47 /// </summary>
48 private const string userSelect = "select * from users"; 48 private const string userSelect = "select * from users";
49 private const string userFriendsSelect = "select a.ownerID as ownerID,a.friendID as friendID,a.friendPerms as friendPerms,b.friendPerms as ownerperms, b.ownerID as fownerID, b.friendID as ffriendID from userfriends as a, userfriends as b";
49 50
50 private DataSet ds; 51 private DataSet ds;
51 private SqliteDataAdapter da; 52 private SqliteDataAdapter da;
53 private SqliteDataAdapter daf;
52 54
53 public void Initialise() 55 public void Initialise()
54 { 56 {
@@ -57,14 +59,29 @@ namespace OpenSim.Framework.Data.SQLite
57 59
58 ds = new DataSet(); 60 ds = new DataSet();
59 da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn)); 61 da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn));
62 daf = new SqliteDataAdapter(new SqliteCommand(userFriendsSelect, conn));
60 63
61 lock (ds) 64 lock (ds)
62 { 65 {
63 ds.Tables.Add(createUsersTable()); 66 ds.Tables.Add(createUsersTable());
64 ds.Tables.Add(createUserAgentsTable()); 67 ds.Tables.Add(createUserAgentsTable());
68 ds.Tables.Add(createUserFriendsTable());
65 69
66 setupUserCommands(da, conn); 70 setupUserCommands(da, conn);
67 da.Fill(ds.Tables["users"]); 71 da.Fill(ds.Tables["users"]);
72
73 setupUserFriendsCommands(daf, conn);
74 try
75 {
76 daf.Fill(ds.Tables["userfriends"]);
77 }
78 catch (SqliteSyntaxException)
79 {
80 MainLog.Instance.Verbose("SQLITE", "userfriends table not found, creating.... ");
81 InitDB(conn);
82 daf.Fill(ds.Tables["userfriends"]);
83 }
84
68 } 85 }
69 86
70 return; 87 return;
@@ -121,27 +138,120 @@ namespace OpenSim.Framework.Data.SQLite
121 138
122 public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) 139 public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
123 { 140 {
141 //do stuff;
124 MainLog.Instance.Verbose("FRIEND", "Stub AddNewUserFriend called"); 142 MainLog.Instance.Verbose("FRIEND", "Stub AddNewUserFriend called");
143 DataTable friends = ds.Tables["userfriends"];
144 DataTable ua = ds.Tables["userfriends"];
145 lock (ds)
146 {
147
148
149 DataRow row = friends.NewRow();
150 fillFriendRow(row, friendlistowner,friend,perms);
151 friends.Rows.Add(row);
152
153 row = friends.NewRow();
154 fillFriendRow(row, friend, friendlistowner, perms);
155 friends.Rows.Add(row);
156
157 MainLog.Instance.Verbose("SQLITE",
158 "Adding Friend: " + ds.Tables["userfriends"].Rows.Count + " friends stored");
159 // save changes off to disk
160 daf.Update(ds, "userfriends");
161 }
125 } 162 }
126 163
127 public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) 164 public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
128 { 165 {
166 DataTable ua = ds.Tables["userfriends"];
167 string select = "a.ownernID '" + friendlistowner.UUID.ToString() + "' and b.friendID ='" + friend.UUID.ToString() + "';";
168 lock (ds)
169 {
170 DataRow[] rows = ds.Tables["userfriends"].Select(select);
171
172 if ( rows != null)
173 {
174 if (rows.Length > 0)
175 {
176 for (int i = 0; i < rows.Length; i++)
177 {
178 FriendListItem user = new FriendListItem();
179 DataRow row = rows[i];
180 row.Delete();
181 }
182 daf.Update(ds, "userfriends");
183 }
184 }
185 }
129 MainLog.Instance.Verbose("FRIEND", "Stub RemoveUserFriend called"); 186 MainLog.Instance.Verbose("FRIEND", "Stub RemoveUserFriend called");
130 } 187 }
131 public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) 188 public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
132 { 189 {
190 DataTable ua = ds.Tables["userfriends"];
191 string select = "a.ownernID '" + friendlistowner.UUID.ToString() + "' and b.friendID ='" + friend.UUID.ToString() + "';";
192 lock (ds)
193 {
194 DataRow[] rows = ds.Tables["userfriends"].Select(select);
195
196 if ( rows != null)
197 {
198 if (rows.Length > 0)
199 {
200 for (int i = 0; i < rows.Length; i++)
201 {
202 FriendListItem user = new FriendListItem();
203 DataRow row = rows[i];
204 row["friendPerms"] = Convert.ToInt32(perms);
205 }
206 daf.Update(ds, "userfriends");
207 }
208 }
209 }
133 MainLog.Instance.Verbose("FRIEND", "Stub UpdateUserFriendPerms called"); 210 MainLog.Instance.Verbose("FRIEND", "Stub UpdateUserFriendPerms called");
134 } 211 }
135 212
136 213
137 public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) 214 public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
138 { 215 {
139 MainLog.Instance.Verbose("FRIEND", "Stub GetUserFriendList called"); 216 List<FriendListItem> returnlist = new List<FriendListItem>();
140 return new List<FriendListItem>(); 217
218 string select = "ownerID = '" + friendlistowner.UUID.ToString() + "' and fownerID = friendID and ffriendID = ownerID";
219 lock (ds)
220 {
221 DataRow[] rows = ds.Tables["userfriends"].Select(select);
222
223 if (rows.Length > 0)
224 {
225 for (int i = 0; i < rows.Length; i++)
226 {
227 FriendListItem user = new FriendListItem();
228 DataRow row = rows[i];
229 user.FriendListOwner = new LLUUID((string)row[0]);
230 user.Friend = new LLUUID((string)row[1]);
231 user.FriendPerms = Convert.ToUInt32(row[2]);
232 user.FriendListOwnerPerms = Convert.ToUInt32(row[3]);
233 returnlist.Add(user);
234 }
235 }
236 }
237 return returnlist;
141 } 238 }
239
240
241
142 242
143 #endregion 243 #endregion
144 244
245 public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid)
246 {
247 MainLog.Instance.Verbose("USER", "Stub UpdateUserCUrrentRegion called");
248 }
249
250 public void LogOffUser(LLUUID avatarid)
251 {
252 MainLog.Instance.Verbose("USER", "Stub LogOffUser called");
253 }
254
145 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) 255 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
146 { 256 {
147 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>(); 257 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>();
@@ -441,6 +551,19 @@ namespace OpenSim.Framework.Data.SQLite
441 return ua; 551 return ua;
442 } 552 }
443 553
554 private DataTable createUserFriendsTable()
555 {
556 DataTable ua = new DataTable("userfriends");
557 // table contains user <----> user relationship with perms
558 createCol(ua, "ownerID", typeof(String));
559 createCol(ua, "friendID", typeof(String));
560 createCol(ua, "friendPerms", typeof(Int32));
561 createCol(ua, "ownerPerms", typeof(Int32));
562 createCol(ua, "datetimestamp", typeof(Int32));
563
564 return ua;
565 }
566
444 /*********************************************************************** 567 /***********************************************************************
445 * 568 *
446 * Convert between ADO.NET <=> OpenSim Objects 569 * Convert between ADO.NET <=> OpenSim Objects
@@ -448,7 +571,7 @@ namespace OpenSim.Framework.Data.SQLite
448 * These should be database independant 571 * These should be database independant
449 * 572 *
450 **********************************************************************/ 573 **********************************************************************/
451 574
452 private UserProfileData buildUserProfile(DataRow row) 575 private UserProfileData buildUserProfile(DataRow row)
453 { 576 {
454 // TODO: this doesn't work yet because something more 577 // TODO: this doesn't work yet because something more
@@ -487,6 +610,20 @@ namespace OpenSim.Framework.Data.SQLite
487 return user; 610 return user;
488 } 611 }
489 612
613 private void fillFriendRow(DataRow row, LLUUID ownerID, LLUUID friendID, uint perms)
614 {
615 row["ownerID"] = ownerID.UUID.ToString();
616 row["friendID"] = friendID.UUID.ToString();
617 row["friendPerms"] = perms;
618 foreach (DataColumn col in ds.Tables["userfriends"].Columns)
619 {
620 if (row[col] == null)
621 {
622 row[col] = "";
623 }
624 }
625 }
626
490 private void fillUserRow(DataRow row, UserProfileData user) 627 private void fillUserRow(DataRow row, UserProfileData user)
491 { 628 {
492 row["UUID"] = Util.ToRawUuidString(user.UUID); 629 row["UUID"] = Util.ToRawUuidString(user.UUID);
@@ -592,23 +729,68 @@ namespace OpenSim.Framework.Data.SQLite
592 da.DeleteCommand = delete; 729 da.DeleteCommand = delete;
593 } 730 }
594 731
732 private void setupUserFriendsCommands(SqliteDataAdapter daf, SqliteConnection conn)
733 {
734 daf.InsertCommand = createInsertCommand("userfriends", ds.Tables["userfriends"]);
735 daf.InsertCommand.Connection = conn;
736
737 daf.UpdateCommand = createUpdateCommand("userfriends", "ownerID=:ownerID and friendID=:friendID", ds.Tables["userfriends"]);
738 daf.UpdateCommand.Connection = conn;
739
740 SqliteCommand delete = new SqliteCommand("delete from users where ownerID=:ownerID and friendID=:friendID");
741 delete.Parameters.Add(createSqliteParameter("ownerID", typeof(String)));
742 delete.Parameters.Add(createSqliteParameter("friendID", typeof(String)));
743 delete.Connection = conn;
744 daf.DeleteCommand = delete;
745
746 }
747
595 private void InitDB(SqliteConnection conn) 748 private void InitDB(SqliteConnection conn)
596 { 749 {
597 string createUsers = defineTable(createUsersTable()); 750 string createUsers = defineTable(createUsersTable());
751 string createFriends = defineTable(createUserFriendsTable());
752
598 SqliteCommand pcmd = new SqliteCommand(createUsers, conn); 753 SqliteCommand pcmd = new SqliteCommand(createUsers, conn);
754 SqliteCommand fcmd = new SqliteCommand(createFriends, conn);
755
599 conn.Open(); 756 conn.Open();
600 pcmd.ExecuteNonQuery(); 757
758 try
759 {
760
761 pcmd.ExecuteNonQuery();
762 }
763 catch (System.Exception)
764 {
765 MainLog.Instance.Verbose("USERS", "users table already exists");
766 }
767
768 try
769 {
770 fcmd.ExecuteNonQuery();
771 }
772 catch (System.Exception)
773 {
774 MainLog.Instance.Verbose("USERS", "userfriends table already exists");
775 }
776
601 conn.Close(); 777 conn.Close();
602 } 778 }
603 779
604 private bool TestTables(SqliteConnection conn) 780 private bool TestTables(SqliteConnection conn)
605 { 781 {
606 SqliteCommand cmd = new SqliteCommand(userSelect, conn); 782 SqliteCommand cmd = new SqliteCommand(userSelect, conn);
783 SqliteCommand fcmd = new SqliteCommand(userFriendsSelect, conn);
607 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd); 784 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd);
785 SqliteDataAdapter fDa = new SqliteDataAdapter(cmd);
786
608 DataSet tmpDS = new DataSet(); 787 DataSet tmpDS = new DataSet();
788 DataSet tmpDS2 = new DataSet();
789
609 try 790 try
610 { 791 {
611 pDa.Fill(tmpDS, "users"); 792 pDa.Fill(tmpDS, "users");
793 fDa.Fill(tmpDS2, "userfriends");
612 } 794 }
613 catch (SqliteSyntaxException) 795 catch (SqliteSyntaxException)
614 { 796 {