private void Multiplayer_PeerConnected(object?sender, StardewModdingAPI.Events.PeerConnectedEventArgs e)
        {
            if (Context.IsMainPlayer)
            {
                pauseTimeAll[e.Peer.PlayerID] = "false";
                inSkullAll[e.Peer.PlayerID]   = "false";
                votePauseAll[e.Peer.PlayerID] = false;
                eventStatus[e.Peer.PlayerID]  = false;

                //send current pause state
                this.Helper.Multiplayer.SendMessage(shouldPauseLast ? "true" : "false", "pauseCommand", new[] { this.ModManifest.UniqueID }, new[] { e.Peer.PlayerID });

                //send message denoting whether or not monsters will be locked
                this.Helper.Multiplayer.SendMessage(lockMonsters ? "true" : "false", "lockMonsters", modIDs: new[] { this.ModManifest.UniqueID }, playerIDs: new[] { e.Peer.PlayerID });


                //check for version match
                IMultiplayerPeerMod pauseMod = null;
                pauseMod = e.Peer.GetMod(this.ModManifest.UniqueID);
                if (pauseMod == null)
                {
                    Game1.chatBox.addErrorMessage("Farmhand " + Game1.getFarmer(e.Peer.PlayerID).Name + " does not have Pause in Multiplayer mod.");
                }
                else if (!pauseMod.Version.Equals(this.ModManifest.Version))
                {
                    Game1.chatBox.addErrorMessage("Farmhand " + Game1.getFarmer(e.Peer.PlayerID).Name + " has mismatched Pause in Multiplayer version.");
                    Game1.chatBox.addErrorMessage($"Host Version: {this.ModManifest.Version} | {Game1.getFarmer(e.Peer.PlayerID).Name} Version: {pauseMod.Version}");
                }

                //sets the joined player's vote to pause as the host's if enabled
                if (this.config.JoinVoteMatchesHost && this.config.EnableVotePause)
                {
                    votePauseAll[e.Peer.PlayerID] = votePause;

                    //sync votePause to local client for joining player
                    this.Helper.Multiplayer.SendMessage <bool>(votePause, "setVotePause", new[] { this.ModManifest.UniqueID }, new[] { e.Peer.PlayerID });

                    int votedYes = 0;
                    foreach (bool vote in votePauseAll.Values)
                    {
                        if (vote)
                        {
                            votedYes++;
                        }
                    }

                    if (votePause)
                    {
                        this.Helper.Multiplayer.SendMessage <string>($"{Game1.getFarmer(e.Peer.PlayerID).Name} joined with a vote to pause. ({votedYes}/{Game1.getOnlineFarmers().Count})", "info", new[] { this.ModManifest.UniqueID });
                        Game1.chatBox.addInfoMessage($"{Game1.getFarmer(e.Peer.PlayerID).Name} joined with a vote to pause. ({votedYes}/{Game1.getOnlineFarmers().Count})");
                    }
                    else
                    {
                        //seems unnecessary to display message for joining without a votepause via host
                        //this.Helper.Multiplayer.SendMessage<string>($"{Game1.getFarmer(e.Peer.PlayerID).Name} joined with a vote to unpause. ({votedYes}/{Game1.getOnlineFarmers().Count})", "info", new[] { this.ModManifest.UniqueID });
                        //Game1.chatBox.addInfoMessage($"{Game1.getFarmer(e.Peer.PlayerID).Name} joined with a vote to unpause. ({votedYes}/{Game1.getOnlineFarmers().Count})");
                    }
                }
            }
        }
        /// <summary>
        /// Displays an error message if a user does not have EqualMoneySplit installed properly
        /// </summary>
        /// <param name="newPlayerData"></param>
        /// <param name="newPlayerName"></param>
        private void CheckForValidModInstall(IMultiplayerPeer newPlayerData, string newPlayerName)
        {
            IModInfo            currentPlayerMod = EqualMoneyMod.SMAPI.ModRegistry.Get(Models.Constants.ModId);
            IMultiplayerPeerMod newPlayerModData = newPlayerData.GetMod(Models.Constants.ModId);
            string errorMessage = "";

            if (!newPlayerData.HasSmapi)
            {
                errorMessage = $"Player {newPlayerName} does not have SMAPI installed! EqualMoneySplit will not function properly!";
            }
            else if (newPlayerData.Mods.Count() == 0)
            {
                errorMessage = $"Player {newPlayerName} does not have any mods installed! EqualMoneySplit will not function properly!";
            }
            else if (newPlayerModData == null)
            {
                errorMessage = $"Player {newPlayerName} does not have EqualMoneySplit installed! EqualMoneySplit will not function properly!";
            }
            else if (newPlayerModData.Version.IsOlderThan(currentPlayerMod.Manifest.Version))
            {
                errorMessage = $"Player {newPlayerName} has an older version ({newPlayerModData.Version}) EqualMoneySplit than yours ({currentPlayerMod.Manifest.Version})! EqualMoneySplit will not function properly!";
            }
            else if (newPlayerModData.Version.IsNewerThan(currentPlayerMod.Manifest.Version))
            {
                errorMessage = $"Player {newPlayerName} has a newer version ({newPlayerModData.Version}) of EqualMoneySplit than yours ({currentPlayerMod.Manifest.Version})! EqualMoneySplit will not function properly!";
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                Game1.chatBox.addErrorMessage(errorMessage);
            }
        }
示例#3
0
        /// <summary>Get whether the host player has Automate installed.</summary>
        /// <param name="version">The installed version, if any.</param>
        private bool HostHasAutomate(out ISemanticVersion version)
        {
            if (Context.IsMainPlayer)
            {
                version = this.ModManifest.Version;
                return(true);
            }

            IMultiplayerPeer    host = this.Helper.Multiplayer.GetConnectedPlayer(Game1.MasterPlayer.UniqueMultiplayerID);
            IMultiplayerPeerMod mod  = host?.Mods?.SingleOrDefault(p => string.Equals(p.ID, this.ModManifest.UniqueID, StringComparison.OrdinalIgnoreCase));

            version = mod?.Version;
            return(mod != null);
        }
示例#4
0
 internal static bool IsLegal(IMultiplayerPeerMod mod)
 {
     return(new string[] { "Ilyaki.BattleRoyale", "Ilyaki.Elevator", "Ilyaki.SplitScreen", "thatnzguy.WindowResize", "Ilyaki.ServerBookmarker", "funnysnek.socialtabpatch", "Ilyaki.ServerBrowser" }.Contains(mod.ID));
 }