diff options
author | Teravus Ovares | 2007-12-31 22:56:43 +0000 |
---|---|---|
committer | Teravus Ovares | 2007-12-31 22:56:43 +0000 |
commit | 3180432debcd9078e8e838d4bbe3ddaf9cdfe110 (patch) | |
tree | b838c1b5b6f3bb7b2baf5c013b1e74a44caa909f /OpenSim/Framework/Data.MySQL | |
parent | Move unused inventory files into the attic (diff) | |
download | opensim-SC-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.zip opensim-SC-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.tar.gz opensim-SC-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.tar.bz2 opensim-SC-3180432debcd9078e8e838d4bbe3ddaf9cdfe110.tar.xz |
* Added database and UserManagerBase glue for FriendsList management
* Don't forget to run prebuild
Diffstat (limited to 'OpenSim/Framework/Data.MySQL')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLUserData.cs | 159 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MySQL/Resources/CreateUserFriendsTable.sql | 11 |
2 files changed, 169 insertions, 1 deletions
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 @@ | |||
1 | SET FOREIGN_KEY_CHECKS=0; | ||
2 | -- ---------------------------- | ||
3 | -- Table structure for users | ||
4 | -- ---------------------------- | ||
5 | CREATE 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 | ||