PartySystem - jimdroberts/FishMMO GitHub Wiki

Description

The PartySystem is a server-side system in FishMMO responsible for managing all aspects of player parties, including creation, invitations, membership, rank changes, and synchronization of party data. It registers and handles network broadcasts for all party actions, tracks online party members, processes party updates from the database, and ensures that all party-related events are validated and synchronized between the server, database, and client.


API Access

Fields

  • public int MaxPartySize

    Maximum number of members allowed in a party.

  • public float UpdatePumpRate

    The server party update pump rate limit in seconds.

  • private LocalConnectionState serverState

    Current connection state of the server.

  • private DateTime lastFetchTime

    Timestamp of the last successful fetch from the database.

  • private float nextPump

    Time remaining until the next database poll for party updates.

  • private Dictionary<long, HashSet> partyMemberTracker

    Tracks all of the members for a party if any of the party members are logged in to this server.

  • private Dictionary<long, HashSet> partyCharacterTracker

    Tracks all active parties and currently online party members on this scene server.

  • private readonly Dictionary<long, long> pendingInvitations

    Tracks pending party invitations by client ID and party ID.

  • private Dictionary<string, ChatCommand> partyChatCommands

    Registered chat commands for party actions.

Methods

  • public bool OnPartyInvite(IPlayerCharacter sender, ChatBroadcast msg)

    Handles party invite chat commands, sending an invite to the target character. sender (IPlayerCharacter): The character sending the invite. msg (ChatBroadcast): Chat broadcast message containing the target character name. Returns: bool - True if invite was sent, false otherwise.

  • public override void InitializeOnce()

    Called once to initialize the party system. Registers chat commands, broadcast handlers, and character events.

  • public override void Destroying()

    Called when the system is being destroyed. Unregisters broadcast handlers and character events.

  • void LateUpdate()

    Unity LateUpdate callback. Polls the database for party updates at the specified rate and processes them.

  • private List FetchPartyUpdates()

    Fetches new party updates from the database since the last fetch. Returns: List - List of new party update entities.

  • private void ProcessPartyUpdates(List updates)

    Processes a list of party updates, synchronizing party membership and broadcasting changes to clients. updates (List): List of party update entities to process.

  • public void AddPartyCharacterTracker(long partyID, long characterID)

    Adds a mapping for the Party to Party Members connected to this Scene Server. partyID (long): ID of the party. characterID (long): ID of the character to add.

  • public void RemovePartyCharacterTracker(long partyID, long characterID)

    Removes the mapping of Party to Party Members connected to this Scene Server. partyID (long): ID of the party. characterID (long): ID of the character to remove.

  • public void CharacterSystem_OnConnect(NetworkConnection conn, IPlayerCharacter character)

    Handles character connect event, adding the character to the party tracker and saving party update. conn (NetworkConnection): Network connection of the character. character (IPlayerCharacter): The character that connected.

  • public void CharacterSystem_OnDisconnect(NetworkConnection conn, IPlayerCharacter character)

    Handles character disconnect event, removing the character from the party tracker and saving party update. conn (NetworkConnection): Network connection of the character. character (IPlayerCharacter): The character that disconnected.

  • public void OnServerPartyCreateBroadcastReceived(NetworkConnection conn, PartyCreateBroadcast msg, Channel channel)

    Handles party creation broadcast, validates and creates a new party for the requesting character. conn (NetworkConnection): Network connection of the requester. msg (PartyCreateBroadcast): Message containing party creation details. channel (Channel): Network channel used for the broadcast.

  • public void OnServerPartyInviteBroadcastReceived(NetworkConnection conn, PartyInviteBroadcast msg, Channel channel)

    Handles party invitation broadcast, validates inviter and target, and sends invitation to the target character. conn (NetworkConnection): Network connection of the inviter. msg (PartyInviteBroadcast): Message containing inviter and target IDs. channel (Channel): Network channel used for the broadcast.

  • public void OnServerPartyAcceptInviteBroadcastReceived(NetworkConnection conn, PartyAcceptInviteBroadcast msg, Channel channel)

    Handles acceptance of a party invitation, validates the invite, adds the character to the party, and broadcasts the update. conn (NetworkConnection): Network connection of the accepting character. msg (PartyAcceptInviteBroadcast): Message containing acceptance details. channel (Channel): Network channel used for the broadcast.

  • public void OnServerPartyDeclineInviteBroadcastReceived(NetworkConnection conn, PartyDeclineInviteBroadcast msg, Channel channel)

    Handles decline of a party invitation, removes pending invitation for the character. conn (NetworkConnection): Network connection of the declining character. msg (PartyDeclineInviteBroadcast): Message containing decline details. channel (Channel): Network channel used for the broadcast.

  • public void OnServerPartyLeaveBroadcastReceived(NetworkConnection conn, PartyLeaveBroadcast msg, Channel channel)

    Handles party leave broadcast, validates character, transfers leadership if needed, removes member from party, and updates or deletes party as appropriate. conn (NetworkConnection): Network connection of the leaving character. msg (PartyLeaveBroadcast): Message containing leave details. channel (Channel): Network channel used for the broadcast.

  • public void OnServerPartyRemoveBroadcastReceived(NetworkConnection conn, PartyRemoveBroadcast msg, Channel channel)

    Handles party member removal broadcast, validates and removes a member from the party in the database. Only party leaders can remove other members. conn (NetworkConnection): Network connection of the requester. msg (PartyRemoveBroadcast): Message containing member ID to remove. channel (Channel): Network channel used for the broadcast.

  • public void OnServerPartyChangeRankBroadcastReceived(NetworkConnection conn, PartyChangeRankBroadcast msg, Channel channel)

    Handles party rank change broadcast, validates leader and target, and updates ranks in the database. Only party leaders can promote another member to leader. conn (NetworkConnection): Network connection of the requester. msg (PartyChangeRankBroadcast): Message containing target member ID. channel (Channel): Network channel used for the broadcast.


Basic Usage

Setup

  1. Requires the server to be running and the party system to be initialized as part of the server startup.
  2. All party-related broadcast handlers and chat commands are registered automatically by the system.
  3. The system automatically polls the database for new party updates and processes them at the configured rate.
  4. No manual registration is required unless extending or customizing party logic.

Example

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

// Example 2: Inviting a player to a party (server-side)
// This is handled automatically by the system when a PartyInviteBroadcast is received from a client or via chat command.
// No manual invocation is required unless extending or customizing the logic.

Best Practices

  • Always validate all party actions and membership changes to prevent exploits and errors.
  • Use the provided broadcast handlers and chat commands to extend or customize party logic if needed.
  • Ensure all party data is properly synchronized between the server, database, and client.
  • Avoid direct manipulation of party membership or data outside of the provided interfaces and system methods.
  • Periodically poll and process party updates to keep all clients in sync with the latest party state.
⚠️ **GitHub.com Fallback** ⚠️