From c202a7d0aa1976d813489446643a5bcf969734d5 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Wed, 13 Feb 2008 13:55:03 +0000 Subject: * Copied 'Friends' functionality from the MySQLUserData to MSSQLUserData [Provided by openlifegrid.com] --- OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 141 +++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 5 deletions(-) diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs index aacbb2d..95a0c08 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs @@ -161,23 +161,154 @@ namespace OpenSim.Framework.Data.MSSQL public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) { - m_log.Info("[FRIEND]: Stub AddNewUserFriend called"); + int dtvalue = Util.UnixTimeSinceEpoch(); + + Dictionary param = new Dictionary(); + param["@ownerID"] = friendlistowner.UUID.ToString(); + param["@friendID"] = friend.UUID.ToString(); + param["@friendPerms"] = perms.ToString(); + param["@datetimestamp"] = dtvalue.ToString(); + + try + { + lock (database) + { + IDbCommand adder = + database.Query( + "INSERT INTO `" + m_userFriendsTableName + "` " + + "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " + + "VALUES " + + "(@ownerID,@friendID,@friendPerms,@datetimestamp)", + param); + adder.ExecuteNonQuery(); + + adder = + database.Query( + "INSERT INTO `" + m_userFriendsTableName + "` " + + "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " + + "VALUES " + + "(@friendID,@ownerID,@friendPerms,@datetimestamp)", + param); + adder.ExecuteNonQuery(); + + } + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return; + } } public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) { - m_log.Info("[FRIEND]: Stub RemoveUserFriend called"); + Dictionary param = new Dictionary(); + param["@ownerID"] = friendlistowner.UUID.ToString(); + param["@friendID"] = friend.UUID.ToString(); + + + try + { + lock (database) + { + IDbCommand updater = + database.Query( + "delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID", + param); + updater.ExecuteNonQuery(); + + updater = + database.Query( + "delete from " + m_userFriendsTableName + " where ownerID = @friendID and friendID = @ownerID", + param); + updater.ExecuteNonQuery(); + + } + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return; + } } + public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) { - m_log.Info("[FRIEND]: Stub UpdateUserFriendPerms called"); + Dictionary param = new Dictionary(); + param["@ownerID"] = friendlistowner.UUID.ToString(); + param["@friendID"] = friend.UUID.ToString(); + param["@friendPerms"] = perms.ToString(); + + + try + { + lock (database) + { + IDbCommand updater = + database.Query( + "update " + m_userFriendsTableName + + " SET friendPerms = @friendPerms " + + "where ownerID = @ownerID and friendID = @friendID", + param); + + updater.ExecuteNonQuery(); + } + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return; + } } public List GetUserFriendList(LLUUID friendlistowner) { - m_log.Info("[FRIEND]: Stub GetUserFriendList called"); - return new List(); + List Lfli = new List(); + + Dictionary param = new Dictionary(); + param["@ownerID"] = friendlistowner.UUID.ToString(); + + try + { + lock (database) + { + //Left Join userfriends to itself + IDbCommand result = + database.Query( + "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" + + " where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID", + param); + IDataReader reader = result.ExecuteReader(); + + + while (reader.Read()) + { + FriendListItem fli = new FriendListItem(); + fli.FriendListOwner = new LLUUID((string)reader["ownerID"]); + fli.Friend = new LLUUID((string)reader["friendID"]); + fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]); + + // This is not a real column in the database table, it's a joined column from the opposite record + fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]); + + Lfli.Add(fli); + } + reader.Close(); + result.Dispose(); + } + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return Lfli; + } + + return Lfli; } #endregion -- cgit v1.1