using System.Collections.Generic; using StardewModdingAPI.Framework.Networking; using StardewValley; namespace StardewModdingAPI.Framework.ModHelpers { /// Provides multiplayer utilities. internal class MultiplayerHelper : BaseHelper, IMultiplayerHelper { /********* ** Fields *********/ /// 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; } /// public long GetNewID() { return this.Multiplayer.getNewID(); } /// public IEnumerable GetActiveLocations() { return this.Multiplayer.activeLocations(); } /// public IMultiplayerPeer GetConnectedPlayer(long id) { return this.Multiplayer.Peers.TryGetValue(id, out MultiplayerPeer peer) ? peer : null; } /// public IEnumerable GetConnectedPlayers() { return this.Multiplayer.Peers.Values; } /// public void SendMessage(TMessage message, string messageType, string[] modIDs = null, long[] playerIDs = null) { this.Multiplayer.BroadcastModMessage( message: message, messageType: messageType, fromModID: this.ModID, toModIDs: modIDs, toPlayerIDs: playerIDs ); } } }