diff --git a/libsecondlife/FriendsManager.cs b/libsecondlife/FriendsManager.cs index 9f697971..bed4b794 100644 --- a/libsecondlife/FriendsManager.cs +++ b/libsecondlife/FriendsManager.cs @@ -285,6 +285,7 @@ namespace libsecondlife Client.Network.RegisterCallback(PacketType.OnlineNotification, OnlineNotificationHandler); Client.Network.RegisterCallback(PacketType.OfflineNotification, OfflineNotificationHandler); Client.Network.RegisterCallback(PacketType.ChangeUserRights, ChangeUserRightsHandler); + Client.Network.RegisterCallback(PacketType.TerminateFriendship, TerminateFriendshipHandler); } @@ -345,7 +346,10 @@ namespace libsecondlife FriendInfo friend = new FriendInfo(fromAgentID, RightsFlags.CanSeeOnline, RightsFlags.CanSeeOnline); - lock (_Friends) _Friends.Add(friend.UUID, friend); + lock (_Friends) + { + if(!_Friends.ContainsKey(fromAgentID)) _Friends.Add(friend.UUID, friend); + } lock (_Requests) { if (_Requests.ContainsKey(fromAgentID)) _Requests.Remove(fromAgentID); } Client.Avatars.RequestAvatarName(fromAgentID); @@ -408,8 +412,21 @@ namespace libsecondlife } } } - - + /// + /// Fired when another friend terminates friendship. We need to remove them from + /// our cached list. + /// + /// + /// + private void TerminateFriendshipHandler(Packet packet, Simulator simulator) + { + TerminateFriendshipPacket itsOver = (TerminateFriendshipPacket)packet; + lock (_Friends) + { + if (_Friends.ContainsKey(itsOver.ExBlock.OtherID)) + _Friends.Remove(itsOver.ExBlock.OtherID); + } + } /// /// Change the rights of a friend avatar. To use this routine, first change the right of the /// avatar stored in the item property. diff --git a/libsecondlife/examples/TestClient/Commands/Friends/FriendsCommand.cs b/libsecondlife/examples/TestClient/Commands/Friends/FriendsCommand.cs new file mode 100644 index 00000000..2f7d24a5 --- /dev/null +++ b/libsecondlife/examples/TestClient/Commands/Friends/FriendsCommand.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using libsecondlife; +using libsecondlife.Packets; +using System.Text; + +namespace libsecondlife.TestClient +{ + public class FriendsCommand : Command + { + ManualResetEvent GetCurrentGroupsEvent = new ManualResetEvent(false); + + public FriendsCommand(TestClient testClient) + { + Name = "friends"; + Description = "List avatar friends. Usage: friends"; + } + public override string Execute(string[] args, LLUUID fromAgentID) + { + List friends = Client.Friends.FriendsList(); + if (friends.Count > 0) + { + StringBuilder sb = new StringBuilder(); + foreach (FriendsManager.FriendInfo friend in friends) + { + sb.AppendLine(friend.Name); + } + return sb.ToString(); + } + else + { + return "No friends"; + } + } + } +} diff --git a/libsecondlife/examples/TestClient/TestClient.csproj b/libsecondlife/examples/TestClient/TestClient.csproj index 6f3b7fcf..f17ab521 100644 --- a/libsecondlife/examples/TestClient/TestClient.csproj +++ b/libsecondlife/examples/TestClient/TestClient.csproj @@ -43,6 +43,7 @@ +