Custom Backend Integration
If you have your own existing backend server, you can integrate it with Universal Friend List by implementing the INetworkFriendSystem interface or extending BaseCustomFriendSystem.
Why Implement a Custom Backend?
- You already have an existing game server with user accounts
- You need tight integration with your existing database
- You have specific business logic requirements
- You want to use your own authentication system
- You need custom moderation or anti-cheat features
Implementation Guide
Step 1: Create Your Implementation
Extend BaseCustomFriendSystem or implement INetworkFriendSystem directly:
using System;
using System.Collections.Generic;
using ElderWorldStudio.FriendList.Abstractions;
using ElderWorldStudio.FriendList.Models;
public class MyGameFriendSystem : BaseCustomFriendSystem
{
public MyGameFriendSystem(FriendManagerSettings settings)
: base(settings) { }
public override void Initialize(string userId)
{
// Connect to your server and set up user session
base.Initialize(userId);
}
public override void RefreshFriendList()
{
// Call your API to get friend list
// Parse response and call OnFriendsListUpdated event
}
public override void SendFriendRequest(string userId, Action<bool, string> callback)
{
// Call your API to send friend request
}
// Implement other required methods...
}
Step 2: Register Your Implementation
Register your custom system with the factory:
// At game startup, before using FriendManager
GameTypeFactory.RegisterCustomFactory<MyGameFriendSystem>();
Required Interface Methods
When implementing INetworkFriendSystem, you must provide:
| Category | Methods |
|---|---|
| Properties | BackendType, IsUsingNativeImplementation, IsConnected |
| Events | OnFriendsListUpdated, OnFriendRequestReceived, OnFriendRequestsUpdated, OnFriendStatusChanged, OnInvitationReceived |
| Initialization | Initialize(string userId) |
| Friend Operations | RefreshFriendList(), SendFriendRequest(), AcceptFriendRequest(), RejectFriendRequest(), CancelFriendRequest(), RemoveFriend() |
| Block Operations | BlockUser(), UnblockUser() |
| Room Operations | GetFriendRoomInfo(), JoinFriendRoom(), InviteFriend() |
Reference Implementations
Study these existing implementations for guidance:
Scripts/Networking/CustomBackendFriendSystem.cs- Main custom implementation baseScripts/Networking/Server/ElderWorldStudioServerClient.cs- HTTP client to ElderWorldStudio serverScripts/Networking/Server/ElderWorldStudioWebSocketClient.cs- WebSocket client