FriendSystem - jimdroberts/FishMMO GitHub Wiki

Description

The FriendSystem is a server-side system in FishMMO responsible for managing player friend lists. It registers and handles network broadcasts for adding and removing friends, validates friend requests, manages friend data in the database, and synchronizes friend status with the client. The system enforces friend limits and prevents invalid or duplicate friend relationships.


API Access

Fields

  • public int MaxFriends

    Maximum number of friends allowed per character.

Methods

  • public override void InitializeOnce()

    Initializes the friend system, registering broadcast handlers for friend add and remove requests.

  • public override void Destroying()

    Cleans up the friend system, unregistering broadcast handlers.

  • public void OnServerFriendAddNewBroadcastReceived(NetworkConnection conn, FriendAddNewBroadcast msg, Channel channel)

    Handles broadcast to add a new friend for a player character. Validates character, friend count, and prevents self-friending. Adds friend to database and notifies client. conn (NetworkConnection): Network connection of the requesting client. msg (FriendAddNewBroadcast): Message containing friend data. channel (Channel): Network channel used for the broadcast.

  • public void OnServerFriendRemoveBroadcastReceived(NetworkConnection conn, FriendRemoveBroadcast msg, Channel channel)

    Handles broadcast to remove a friend for a player character. Validates character and removes friend from database and notifies client if successful. conn (NetworkConnection): Network connection of the requesting client. msg (FriendRemoveBroadcast): Message containing friend removal data. channel (Channel): Network channel used for the broadcast.


Basic Usage

Setup

  1. Requires the server to be running and the friend system to be initialized as part of the server startup.
  2. The system automatically registers broadcast handlers for friend add and remove requests.
  3. No manual registration is required unless extending or customizing friend logic.

Example

// Example 1: Adding a friend (server-side)
// This is handled automatically by the system when a FriendAddNewBroadcast is received from a client.
// No manual invocation is required unless extending or customizing the logic.

// Example 2: Removing a friend (server-side)
// This is handled automatically by the system when a FriendRemoveBroadcast is received from a client.
// No manual invocation is required unless extending or customizing the logic.

Best Practices

  • Always validate friend requests to prevent self-friending and enforce friend limits.
  • Use the provided broadcast handlers to extend or customize friend logic if needed.
  • Ensure all friend data is properly synchronized between the server, database, and client.
  • Avoid direct manipulation of friend lists outside of the provided interfaces and system methods.
⚠️ **GitHub.com Fallback** ⚠️