[Problem] Friend Check,

09/03/2010 23:52 -Shunsui-#1
##Close
09/04/2010 00:03 Korvacs#2
Tried debugging and stepping through it?
09/04/2010 00:11 _tao4229_#3
Loop through the dictionary of friends and check and see if they're in Kernel.GamePool instead.
09/04/2010 00:15 Korvacs#4
Well, ive noticed a few things, FriendsUID <--- is a ushort? The dictionary is a uint, seems to me that the FriendsUID cannot be the same thing as client.Entity.UID.
09/04/2010 00:26 _DreadNought_#5
I would of done it kinda like well 2 ways
Code:
foreach (Client.GameState aFriend in Kernel.GamePool.Values)
                                        {
                                                Console.WriteLine(client.Entity.UID + " " + client.Entity.Name + " <- Clients Info .. Friends info - > " + aFriend.Entity.UID + " " + aFriend.Entity.Name);
                                                if (client.Entity.Friends.ContainsKey(afriend.Entity.UID))
                                                {
                                                    Console.WriteLine("Has Friend Online");
                                                }
                                        }
^ Wont work either, but im tired :) Tao's way is more efficent.
09/04/2010 00:59 ImmuneOne#6
Quote:
Originally Posted by -Shunsui- View Post
huh ? and no cant check the client u need to check every person in the game that has the client (wich is the one login in ) as a friend,

But anyways, tnx guys i got it
Code:
LoadFriends(caller);
caller.FriendManagement.SendCollection(caller);


Class:
public Friends
{
    private Dictionary<uint, FriendPacket> friendsCollection;
    public Friends()
    { 
        friendsCollection = new Dictionary<uint, FriendPacket>();
    }
    
    public void Insert(uint friendID, FriendPacket friend)
    { 
        if (!friendsCollection.Containskey(friendID))
           friendsCollection.Add(friendID, friend);
        else
           friendsCollection[friendID] = friend;
    }

    public void Remove(uint friendID)
    {
        if (friendsCollection.Containskey(friendID))
           friendsCollection.Remove(friendID);
    }
    
    public void SendCollection(ConquerClient caller)
    {
        foreach (KeyValuePair<uint, FriendPacket> entry in Collection)
        {
            entry.Value.Online = Kernel.GamePool.Containskey(entry.Key);
            caller.WinsockClient.Send(&entry.Value, Marshal.SizeOf(entry.Value));
            if (entry.Value.Online)
               caller.WinsockClient[entry.Key].Send(&caller.FriendPacket, Marshal.SizeOf(caller.FriendPacket));
        }
    }
}
:confused:
09/04/2010 06:43 -Shunsui-#7
Reusing !