using System.Collections.Generic; using StardewModdingAPI.Framework.Networking; using StardewValley; namespace StardewModdingAPI.Framework.ModHelpers { /// Provides multiplayer utilities. internal class MultiplayerHelper : BaseHelper, IMultiplayerHelper { /********* ** Properties *********/ /// SMAPI's core multiplayer utility. private readonly SMultiplayer Multiplayer; /********* ** Public methods *********/ /// Construct an instance. /// The unique ID of the relevant mod. /// SMAPI's core multiplayer utility. public MultiplayerHelper(string modID, SMultiplayer multiplayer) : base(modID) { this.Multiplayer = multiplayer; } /// Get the locations which are being actively synced from the host. public IEnumerable GetActiveLocations() { return this.Multiplayer.activeLocations(); } /// Get a new multiplayer ID. public long GetNewID() { return this.Multiplayer.getNewID(); } /// Get a connected player. /// The player's unique ID. /// Returns the connected player, or null if no such player is connected. public IMultiplayerPeer GetConnectedPlayer(long id) { return this.Multiplayer.Peers.TryGetValue(id, out MultiplayerPeer peer) ? peer : null; } /// Get all connected players. public IEnumerable GetConnectedPlayers() { return this.Multiplayer.Peers.Values; } } }