Skip to main content

Friends

Friends are a great way to build a social community. Users can add other users to their list of friends, see who is online or when they were last online, chat together in real-time, and interact together in gameplay or collaboration.

Each user builds up a list of friends by who they know already from their social networks, friend requests they send, requests they receive, and who the server recommends they should know. This information is stored in a social graph within the system as a powerful way to interact with other users. Much like how Twitter or Facebook work.

Any social community must be maintained carefully to prevent spam or abuse. To help with this problem it’s also possible for a user to block users they no longer want to communicate with and for the server to ban a user via server-side code to completely disable an account.

info

LayerG is a common Japanese word that directly translates to friend or comrade. Some believe the word means “people who are considered closer than family”, though that is not a part of the official definition. We feel it expresses the kind of social communities we want developers to build into their games and apps!

Add friends

A user can add one or more friends by that user’s ID or username. The user added will not be marked as a friend in the list until they’ve confirmed the friend request. The user who receives the request can confirm it by adding the user back.

When a friend request is sent or the user is added an in-app notification will be sent. See the in-app notification section for more info.

When both users have added each other as friends, it’s easy to initiate real-time chat in a 1-on-1 channel. See the real-time chat section for more info.

Import friends

A user who registers or links their account with Facebook, Steam, or another social network can select to have friends from that network imported into their friend list.

Alternatively, you can enable users to perform this import at any time via LayerG’s support for on-demand importing of friends.

Facebook

Import a user’s Facebook friends into your app at any time, and optionally reset their current friends list when doing so.

Steam

Import a user’s Facebook friends into your app at any time, and optionally reset their current friends list when doing so.

List friends

You can list all of a user’s friends, blocked users, friend requests received (invited), and invites they’ve sent. These statuses are returned together as part of the friend list which makes it easy to display in a UI. A single friends listing will return a page of up to 1000 friends. Pass the returned cursor to subsequent list calls to retrieve more friend pages.

List friends of friends

To list friends of friends for this user. A maximum of 100 results per request is allowed. An optional cursor can be supplied, don’t set to start fetching from the beginning.

Remove friends

A user can remove a friend, reject a received invite, cancel a friend request sent, or unblock a user. If a user is unblocked they are removed from the friend list entirely. To re-add them each user must add the other again.

Similar to how Friend Add works we reuse Friend Remove to cancel or undo whatever friend state is current with another user.

Block a friend

You can stop a user from using 1-on-1 chat or other social features with a user if you block them. The user who wants to block should send the message. They can be unblocked later with a Friend Remove message.

A user who has been blocked will not know which users have blocked them. That user can continue to add friends and interact with other users.

Ban a user

A user can be banned with server-side code.

This is best used by a moderator system within your player community. You can assign particular users the ability to send an RPC to permanently ban a user.

Banning a user will prevent them from being able to connect to the server and interact at all in the future, but it does not implicitly logout or disconnect their session.

To ensure a banned user cannot reconnect using a still valid auth token, and that any open socket connections are closed, you must ban the user and logout and disconnect their active session(s). See a complete example on banning users.

Friend state

CodePurpose
0Users are friends with each other.
1User A has sent an invitation and pending acceptance from user B.
2User A has received an invitation but has not accepted yet.
3User A has banned user B.