IFriendController - jimdroberts/FishMMO GitHub Wiki

Description

Interface for friend controllers, providing access and management for a character's friend list. Used to add, remove, and track friends, and handle related events.


API Access

Fields

  • event Action<long, bool> OnAddFriend

    Event invoked when a friend is added. Parameters: friend ID, online status.

  • event Action OnRemoveFriend

    Event invoked when a friend is removed. Parameter: friend ID.

Properties

  • HashSet Friends { get; }

    Set of friend IDs for this character.

Methods

  • void AddFriend(long friendID)

    Adds a friend by ID if not already present. friendID (long): The ID of the friend to add.


Basic Usage

Setup

  1. Implement IFriendController on your character or controller class.
  2. Provide logic for managing the Friends set and handling events.
  3. Use AddFriend to add friends by their ID.

Example

// Example 1: Implementing IFriendController
public class MyFriendController : IFriendController {
    public event Action<long, bool> OnAddFriend;
    public event Action<long> OnRemoveFriend;
    public HashSet<long> Friends { get; private set; } = new HashSet<long>();
    public void AddFriend(long friendID) {
        if (!Friends.Contains(friendID)) Friends.Add(friendID);
    }
}

// Example 2: Using the interface
friendController.AddFriend(1234567890L);

Best Practices

  • Always use AddFriend to add friends to ensure duplicates are not added.
  • Subscribe to OnAddFriend and OnRemoveFriend to update UI or trigger gameplay logic.
  • Keep the Friends set up to date and clear it on character reset or logout.
⚠️ **GitHub.com Fallback** ⚠️