aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Communications/LoginService.cs15
-rw-r--r--OpenSim/Framework/Communications/UserManagerBase.cs74
-rw-r--r--OpenSim/Framework/Data.DB4o/DB4oUserData.cs10
-rw-r--r--OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs10
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLUserData.cs159
-rw-r--r--OpenSim/Framework/Data.MySQL/Resources/CreateUserFriendsTable.sql11
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteBase.cs7
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteUserData.cs190
-rw-r--r--OpenSim/Framework/IUserData.cs13
9 files changed, 482 insertions, 7 deletions
diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs
index 2ac34b1..afc6c9a 100644
--- a/OpenSim/Framework/Communications/LoginService.cs
+++ b/OpenSim/Framework/Communications/LoginService.cs
@@ -168,6 +168,7 @@ namespace OpenSim.Framework.UserManagement
168 //logResponse.SimAddress = "127.0.0.1"; //overwritten 168 //logResponse.SimAddress = "127.0.0.1"; //overwritten
169 //logResponse.SimPort = 0; //overwritten 169 //logResponse.SimPort = 0; //overwritten
170 logResponse.Message = GetMessage(); 170 logResponse.Message = GetMessage();
171 logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));
171 172
172 try 173 try
173 { 174 {
@@ -265,6 +266,20 @@ namespace OpenSim.Framework.UserManagement
265 return m_welcomeMessage; 266 return m_welcomeMessage;
266 } 267 }
267 268
269 private LoginResponse.BuddyList ConvertFriendListItem(List<FriendListItem> LFL)
270 {
271 LoginResponse.BuddyList buddylistreturn = new LoginResponse.BuddyList();
272 foreach (FriendListItem fl in LFL)
273 {
274 LoginResponse.BuddyList.BuddyInfo buddyitem = new LoginResponse.BuddyList.BuddyInfo(fl.Friend);
275 buddyitem.BuddyID = fl.Friend;
276 buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms;
277 buddyitem.BuddyRightsGiven = (int) fl.FriendPerms;
278 buddylistreturn.AddNewBuddy(buddyitem);
279
280 }
281 return buddylistreturn;
282 }
268 /// <summary> 283 /// <summary>
269 /// Converts the inventory library skeleton into the form required by the rpc request. 284 /// Converts the inventory library skeleton into the form required by the rpc request.
270 /// </summary> 285 /// </summary>
diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs
index f913d2c..5d62e5e 100644
--- a/OpenSim/Framework/Communications/UserManagerBase.cs
+++ b/OpenSim/Framework/Communications/UserManagerBase.cs
@@ -197,6 +197,80 @@ namespace OpenSim.Framework.UserManagement
197 } 197 }
198 198
199 /// <summary> 199 /// <summary>
200 /// Loads a user's friend list
201 /// </summary>
202 /// <param name="name">the UUID of the friend list owner</param>
203 /// <returns>A List of FriendListItems that contains info about the user's friends</returns>
204 public List<FriendListItem> GetUserFriendList(LLUUID ownerID)
205 {
206
207 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
208 {
209 try
210 {
211 return plugin.Value.GetUserFriendList(ownerID);
212 }
213 catch (Exception e)
214 {
215 MainLog.Instance.Verbose("USERSTORAGE",
216 "Unable to GetUserFriendList via " + plugin.Key + "(" + e.ToString() + ")");
217 }
218 }
219
220 return null;
221
222 }
223
224 public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
225 {
226 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
227 {
228 try
229 {
230 plugin.Value.AddNewUserFriend(friendlistowner,friend,perms);
231 }
232 catch (Exception e)
233 {
234 MainLog.Instance.Verbose("USERSTORAGE",
235 "Unable to AddNewUserFriend via " + plugin.Key + "(" + e.ToString() + ")");
236 }
237 }
238
239 }
240
241
242 public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
243 {
244 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
245 {
246 try
247 {
248 plugin.Value.RemoveUserFriend(friendlistowner, friend);
249 }
250 catch (Exception e)
251 {
252 MainLog.Instance.Verbose("USERSTORAGE",
253 "Unable to RemoveUserFriend via " + plugin.Key + "(" + e.ToString() + ")");
254 }
255 }
256 }
257
258 public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
259 {
260 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
261 {
262 try
263 {
264 plugin.Value.UpdateUserFriendPerms(friendlistowner, friend, perms);
265 }
266 catch (Exception e)
267 {
268 MainLog.Instance.Verbose("USERSTORAGE",
269 "Unable to UpdateUserFriendPerms via " + plugin.Key + "(" + e.ToString() + ")");
270 }
271 }
272 }
273 /// <summary>
200 /// Loads a user agent by name (not called directly) 274 /// Loads a user agent by name (not called directly)
201 /// </summary> 275 /// </summary>
202 /// <param name="name">The agent's name</param> 276 /// <param name="name">The agent's name</param>
diff --git a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
index acd14fa..c6ac526 100644
--- a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
+++ b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
@@ -158,6 +158,16 @@ namespace OpenSim.Framework.Data.DB4o
158 158
159 #endregion 159 #endregion
160 160
161 public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid)
162 {
163 //MainLog.Instance.Verbose("USER", "Stub UpdateUserCUrrentRegion called");
164 }
165
166 public void LogOffUser(LLUUID avatarid)
167 {
168 //MainLog.Instance.Verbose("USER", "Stub LogOffUser called");
169 }
170
161 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) 171 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
162 { 172 {
163 //Do nothing yet 173 //Do nothing yet
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
index 2c1d6d5..f8a951e 100644
--- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
+++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
@@ -124,6 +124,16 @@ namespace OpenSim.Framework.Data.MSSQL
124 124
125 #endregion 125 #endregion
126 126
127 public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid)
128 {
129 MainLog.Instance.Verbose("USER", "Stub UpdateUserCUrrentRegion called");
130 }
131
132 public void LogOffUser(LLUUID avatarid)
133 {
134 MainLog.Instance.Verbose("USER", "Stub LogOffUser called");
135 }
136
127 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) 137 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
128 { 138 {
129 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>(); 139 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>();
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
index c8f0517..779d050 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -77,10 +77,13 @@ namespace OpenSim.Framework.Data.MySQL
77 77
78 tableList["agents"] = null; 78 tableList["agents"] = null;
79 tableList["users"] = null; 79 tableList["users"] = null;
80 tableList["userfriends"] = null;
80 database.GetTableVersion(tableList); 81 database.GetTableVersion(tableList);
81 82
82 UpgradeAgentsTable(tableList["agents"]); 83 UpgradeAgentsTable(tableList["agents"]);
83 UpgradeUsersTable(tableList["users"]); 84 UpgradeUsersTable(tableList["users"]);
85 UpgradeFriendsTable(tableList["userfriends"]);
86
84 } 87 }
85 88
86 /// <summary> 89 /// <summary>
@@ -113,6 +116,21 @@ namespace OpenSim.Framework.Data.MySQL
113 } 116 }
114 } 117 }
115 118
119 /// <summary>
120 /// Create or upgrade the table if necessary
121 /// </summary>
122 /// <param name="oldVersion">A null indicates that the table does not
123 /// currently exist</param>
124 private void UpgradeFriendsTable(string oldVersion)
125 {
126 // null as the version, indicates that the table didn't exist
127 if (oldVersion == null)
128 {
129 database.ExecuteResourceSql("CreateUserFriendsTable.sql");
130 return;
131 }
132 }
133
116 #endregion 134 #endregion
117 135
118 // see IUserData 136 // see IUserData
@@ -149,27 +167,166 @@ namespace OpenSim.Framework.Data.MySQL
149 167
150 public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) 168 public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
151 { 169 {
170 int dtvalue = Util.UnixTimeSinceEpoch();
171
172 Dictionary<string, string> param = new Dictionary<string, string>();
173 param["?ownerID"] = friendlistowner.UUID.ToString();
174 param["?friendID"] = friend.UUID.ToString();
175 param["?friendPerms"] = perms.ToString();
176 param["?datetimestamp"] = dtvalue.ToString();
177
178 try
179 {
180 lock (database)
181 {
182 IDbCommand adder =
183 database.Query(
184 "INSERT INTO `userfriends` " +
185 "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
186 "VALUES " +
187 "(?ownerID,?friendID,?friendPerms,?datetimestamp)",
188 param);
189 adder.ExecuteNonQuery();
190
191 adder =
192 database.Query(
193 "INSERT INTO `userfriends` " +
194 "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
195 "VALUES " +
196 "(?friendID,?ownerID,?friendPerms,?datetimestamp)",
197 param);
198 adder.ExecuteNonQuery();
199
200 }
201 }
202 catch (Exception e)
203 {
204 database.Reconnect();
205 MainLog.Instance.Error(e.ToString());
206 return;
207 }
152 MainLog.Instance.Verbose("FRIEND", "Stub AddNewUserFriend called"); 208 MainLog.Instance.Verbose("FRIEND", "Stub AddNewUserFriend called");
153 } 209 }
154 210
155 public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) 211 public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
156 { 212 {
213 Dictionary<string, string> param = new Dictionary<string, string>();
214 param["?ownerID"] = friendlistowner.UUID.ToString();
215 param["?friendID"] = friend.UUID.ToString();
216
217
218 try
219 {
220 lock (database)
221 {
222 IDbCommand updater =
223 database.Query(
224 "delete from userfriends " +
225 "where ownerID = ?ownerID and friendID = ?friendID",
226 param);
227 updater.ExecuteNonQuery();
228
229 }
230 }
231 catch (Exception e)
232 {
233 database.Reconnect();
234 MainLog.Instance.Error(e.ToString());
235 return;
236 }
157 MainLog.Instance.Verbose("FRIEND", "Stub RemoveUserFriend called"); 237 MainLog.Instance.Verbose("FRIEND", "Stub RemoveUserFriend called");
158 } 238 }
159 public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) 239 public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
160 { 240 {
241 Dictionary<string, string> param = new Dictionary<string, string>();
242 param["?ownerID"] = friendlistowner.UUID.ToString();
243 param["?friendID"] = friend.UUID.ToString();
244 param["?friendPerms"] = perms.ToString();
245
246
247 try
248 {
249 lock (database)
250 {
251 IDbCommand updater =
252 database.Query(
253 "update userfriends " +
254 "SET friendPerms = ?friendPerms " +
255 "where ownerID = ?ownerID and friendID = ?friendID",
256 param);
257 updater.ExecuteNonQuery();
258
259 }
260 }
261 catch (Exception e)
262 {
263 database.Reconnect();
264 MainLog.Instance.Error(e.ToString());
265 return;
266 }
161 MainLog.Instance.Verbose("FRIEND", "Stub UpdateUserFriendPerms called"); 267 MainLog.Instance.Verbose("FRIEND", "Stub UpdateUserFriendPerms called");
162 } 268 }
163 269
164 270
165 public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) 271 public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
166 { 272 {
273 List<FriendListItem> Lfli = new List<FriendListItem>();
274
275 Dictionary<string, string> param = new Dictionary<string, string>();
276 param["?ownerID"] = friendlistowner.UUID.ToString();
277
278 try
279 {
280 lock (database)
281 {
282 //Left Join userfriends to itself
283 IDbCommand result =
284 database.Query(
285 "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from userfriends as a, userfriends as b" +
286 " where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
287 param);
288 IDataReader reader = result.ExecuteReader();
289
290
291 while (reader.Read())
292 {
293 FriendListItem fli = new FriendListItem();
294 fli.FriendListOwner = new LLUUID((string)reader["ownerID"]);
295 fli.Friend = new LLUUID((string)reader["friendID"]);
296 fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);
297
298 // This is not a real column in the database table, it's a joined column from the opposite record
299 fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
300
301 Lfli.Add(fli);
302 }
303 reader.Close();
304 result.Dispose();
305 }
306 }
307 catch (Exception e)
308 {
309 database.Reconnect();
310 MainLog.Instance.Error(e.ToString());
311 return Lfli;
312 }
313
167 MainLog.Instance.Verbose("FRIEND", "Stub GetUserFriendList called"); 314 MainLog.Instance.Verbose("FRIEND", "Stub GetUserFriendList called");
168 return new List<FriendListItem>(); 315 return Lfli;
169 } 316 }
170 317
171 #endregion 318 #endregion
172 319
320 public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid)
321 {
322 MainLog.Instance.Verbose("USER", "Stub UpdateUserCUrrentRegion called");
323 }
324
325 public void LogOffUser(LLUUID avatarid)
326 {
327 MainLog.Instance.Verbose("USER", "Stub LogOffUser called");
328 }
329
173 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) 330 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
174 { 331 {
175 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>(); 332 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>();
diff --git a/OpenSim/Framework/Data.MySQL/Resources/CreateUserFriendsTable.sql b/OpenSim/Framework/Data.MySQL/Resources/CreateUserFriendsTable.sql
new file mode 100644
index 0000000..157fe4b
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/Resources/CreateUserFriendsTable.sql
@@ -0,0 +1,11 @@
1SET FOREIGN_KEY_CHECKS=0;
2-- ----------------------------
3-- Table structure for users
4-- ----------------------------
5CREATE TABLE `userfriends` (
6 `ownerID` VARCHAR(37) NOT NULL,
7 `friendID` VARCHAR(47) NOT NULL,
8 `friendPerms` INT NOT NULL,
9 `datetimestamp` INT NOT NULL,
10 UNIQUE KEY (`ownerID`, `friendID`)
11) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Rev.1'; \ No newline at end of file
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteBase.cs b/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
index 2e8d341..9131a41 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteBase.cs
@@ -135,9 +135,12 @@ namespace OpenSim.Framework.Data.SQLite
135 subsql += ",\n"; 135 subsql += ",\n";
136 } 136 }
137 subsql += col.ColumnName + " " + sqliteType(col.DataType); 137 subsql += col.ColumnName + " " + sqliteType(col.DataType);
138 if (col == dt.PrimaryKey[0]) 138 if (dt.PrimaryKey.Length > 0)
139 { 139 {
140 subsql += " primary key"; 140 if (col == dt.PrimaryKey[0])
141 {
142 subsql += " primary key";
143 }
141 } 144 }
142 } 145 }
143 sql += subsql; 146 sql += subsql;
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 {
diff --git a/OpenSim/Framework/IUserData.cs b/OpenSim/Framework/IUserData.cs
index 4e576b9..eba2329 100644
--- a/OpenSim/Framework/IUserData.cs
+++ b/OpenSim/Framework/IUserData.cs
@@ -93,6 +93,19 @@ namespace OpenSim.Framework
93 bool UpdateUserProfile(UserProfileData user); 93 bool UpdateUserProfile(UserProfileData user);
94 94
95 /// <summary> 95 /// <summary>
96 /// Updates the current region the User is in
97 /// </summary>
98 /// <param name="avatarid">User Region the Avatar is IN</param>
99 /// <param name="retionuuid">User Region the Avatar is IN</param>
100 void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid);
101
102 /// <summary>
103 /// Log User Off
104 /// </summary>
105 /// <param name="avatarid">avatar to log off</param>
106 void LogOffUser(LLUUID avatarid);
107
108 /// <summary>
96 /// Adds a new agent to the database 109 /// Adds a new agent to the database
97 /// </summary> 110 /// </summary>
98 /// <param name="agent">The agent to add</param> 111 /// <param name="agent">The agent to add</param>