Friend Lists

Friend Lists

The friend list feature of uLobby provides support for adding other accounts as friends and sending friend invitations. Friend information is stored in the database and retrieved upon logging in to an account. The friend list manager is implemented in the FriendListManager class.
Friend lists are associated with accounts. All of the client-side methods in the friend list manager require that an account be logged in to when called, and it is the friend list for this account that is operated upon.

Adding and Removing Friends

Friends are added lobby-side using the FriendListManager.Master.AddFriend() method:
Request AddFriend(IAccount account, IAccount friend, bool verifyFriendExists = true)
This adds friend as a friend of account. Neither account needs to be logged in when this method is called. Friendship is not bidirectional, so account will not be added to friend's friend list. The verifyFriendExists argument says whether to verify with the account manager that the friend account is a registered account before continuing with the operation. This is good to do when you cannot be sure of the authenticity of the account instance, such as when you received it from a client.
If the friend was successfully added, the OnFriendAdded event will be raised in the peer logged in as account, if any.
The corresponding method for removing friends lobby-side is FriendListManager.Master.RemoveFriend():
Request RemoveFriend(IAccount account, IAccount friend)
This removes friend as a friend of account. If account is logged in, the OnFriendRemoved event will be raised in that peer.
It is also possible to explicitly set the friend list of an account using the FriendListManager.Master.SetFriends method.
Request SetFriends(IAccount account, IEnumerable<IAccount> friends, bool verifyFriendsExist = true)
This sets the friends of account to the specified list. If verifyFriendsExist is true, the accounts are first checked with the account manager to make sure they exist.
The current implementation of SetFriends will remove all friend invitations of the account. This will be changed in the future.
Clients can use the FriendListManager.AddFriend() and FriendListManager.RemoveFriend() methods to modify the friend list.
void AddFriend(IAccount friend)

void RemoveFriend(IAccount friend)
These add and remove accounts as friends of the currently logged in account, and have the same effects as FriendListManager.Master.AddFriend() and FriendListManager.Master.RemoveFriend(), respectively. The friend account does not need to be logged in.

Retrieving the Friend List

The friend list of an arbitrary account can be retrieved in the lobby using the method
FriendListManager.Master.GetFriendList().
Request<FriendList> GetFriendList(IAccount account)
This will load the friend list of the specified account and return it as the result of the request. The returned instance is a static representation of what the friend list looked like when the method was called, and will not change if the friend list is later changed.
On the client, as soon as you log in to an account, the associated friend list will be loaded and sent from the lobby. Only after it has been received can you request the friend list. To see if the friend list has been loaded and is ready to be read, you can use the isFriendListLoaded property (or the OnFriendListLoaded event, described below). When it has been loaded, you can retrieve the friend list using the FriendListManager.GetFriendList() method:
FriendList GetFriendList()
The FriendList class contains the method GetFriends() that returns a list of FriendInfo, which contains the friend account and a boolean saying whether the account is currently logged in or not.

Friend Invitations

You can invite accounts to become friends by sending friend invitations between them. The account that receives the invitation can choose to either accept or decline it.
The FriendListManager.Master.SendFriendInvitation() method sends an invitation lobby-side.
Request SendFriendInvitation(IAccount inviter, IAccount recipient, bool verifyRecipientExists = true)
An invitation is sent to recipient inviting it to become friends with inviter. If verifyRecipientExists is true, the recipient account is first checked with the account manager to ensure it is a valid account.
When the invitation is received, the OnFriendInvitationReceived event will be raised in the recipient account, containing the invitation.
Clients can send invitations using the FriendListManager.SendFriendInvitation() method:
void SendFriendInvitation(IAccount recipient)
This sends an invitation from the currently logged in account to recipient, and has the same effect as calling FriendListManager.Master.SendFriendInvitation().
Received friend invitations can be obtained from the FriendList class through the GetReceivedFriendInvitations() method, which returns a list of FriendInvitation.
A friend invitation can be accepted lobby-side using the FriendListManager.Master.AcceptFriendInvitation() method.
Request AcceptFriendInvitation(FriendInvitation invitation)
Accepting an invitation will add both accounts as friends of each other, and remove the invitation from the recipient. The OnFriendInvitationAccepted event will be raised in the peer of the inviter, if logged in.
Similarly, an invitation is declined on the lobby using FriendListManager.Master.DeclineFriendInvitation():
Request DeclineFriendInvitation(FriendInvitation invitation)
This will simply remove the invitation from the recipient, without adding the accounts as friends. The OnFriendInvitationDeclined event will be raised in the peer of the inviter, if logged in.
Clients can accept or decline invitations by calling the FriendInvitation.Accept() or FriendInvitation.Decline() methods directly on the FriendInvitation instances retrieved from the friend list. The effect is the same as that of their lobby-side counterparts.

Friend List Notifications

The following is a list of the events that can be raised in clients.