Friend Request System
Comprehensive documentation for the BlinkBox Friend Request Addon
Introduction
The BlinkBox Friend Request system extends the standard MFPS functionality by adding a robust, persistent friend request mechanism. It allows users to send, receive, accept, and decline friend requests, with built-in spam protection and database persistence.
Key Features
- Database Persistence: All requests are stored in a MySQL database via PHP, ensuring data survives game sessions.
- Smart Cooldowns: Prevents spam with global cooldowns, per-user cooldowns, and declined request timeouts.
- UI Management: Complete UI system for viewing pending (sent) and received requests.
- Event System: Rich C# event system for developers to hook into (e.g., `OnRequestSent`, `OnRequestAccepted`).
- Integrations: Seamlessly works with ULogin System Pro (ULSP), Photon, and supports other BlinkBox addons like Player Profile Inspect.
Setup & Installation
1. Database Setup
- Upload the provided
bl_FriendRequest.phpfile to your web server (same directory as your other MFPS PHP files). - The system will automatically attempt to create the necessary tables (`bl_friend_requests`) on the first run.
2. Unity Setup
- Drag the FriendRequests[Panel] prefab into your Lobby scene (usually under the Canvas/UI hierarchy).
- Ensure the
bl_FriendRequestcomponent is present in your scene (often attached to a manager object or the UI panel itself). - Assign the FriendRequestSettings asset to the
bl_FriendRequestcomponent in the Inspector.
Configuration
The system is configured via the FriendRequestSettings ScriptableObject. Create one via Create > BlinkBox > Friend Request > Settings if needed.
Cooldown Settings
| Setting | Description |
|---|---|
| Global Cooldown | Minimum time (seconds) between sending any friend request. |
| Per User Cooldown | Time (seconds) to wait before sending another request to the same user. |
| Declined Cooldown | Time (seconds) to wait if a user previously declined your request. |
Limits & Logs
- Max Pending Requests: Limit how many outgoing requests a user can have active.
- Log Colors: Customize the console output colors for debugging.
- Notification Type: Choose between Dialog boxes or Toast notifications for feedback.
Core Components
bl_FriendRequest.cs
The central manager (Singleton: bl_FriendRequest.instance). It handles all network logic and state management.
SendFriendRequest(string identifier): Main entry point. Identifier can be a User ID or Player Name.PlayerName: Automatically syncs with Photon NickName.
bl_FriendRequestUI.cs
Manages the visual interface.
- Handles the "Received" vs "Pending" tabs.
- Instantiates UI items from templates (`FR_PendingUITemplate`, `FR_RecivedUITemplate`).
- Manages loading screens and refresh logic.
bl_FriendRequestInfo.cs
Attached to individual list items. Holds data for a specific request.
PLAYER_PROFILE_INSPECT is enabled, visual elements like avatars and calling cards are delegated to the bl_ProfileDataRenderer component.
UI System
The UI is template-based. You can customize the look of list items by editing the prefabs:
- FriendRequestRecived [Template]: Shows incoming requests with Accept/Decline buttons.
- FriendRequestSent [Template]: Shows outgoing requests (waiting for approval).
The main panel FriendRequests[Panel] contains the lists and navigation logic.
Integration Guide
How to use the system from your own scripts.
Sending a Request
// Send by Name
bl_FriendRequest.instance.SendFriendRequest("PlayerName123");
// Send by ID (if known)
bl_FriendRequest.instance.SendFriendRequestByID("54");
Listening to Events
You can subscribe to events to react to changes (e.g., play a sound, show a custom notification).
void OnEnable()
{
if (bl_FriendRequest.instance != null)
{
bl_FriendRequest.instance.OnRequestSent += HandleRequestSent;
bl_FriendRequest.instance.OnRequestAccepted += HandleRequestAccepted;
}
}
void HandleRequestSent(bool success)
{
if (success) Debug.Log("Friend request sent successfully!");
}
void HandleRequestAccepted(bool success)
{
if (success) Debug.Log("New friend added!");
}