Exemplo n.º 1
0
        public void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            var state = GetPlayerState(e.Peer.PlayerID);

            state.IsOnline = true;
            state.IsPaused = InitialPauseState.Value;
        }
Exemplo n.º 2
0
        /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            // log join
            this.Monitor.Log($"Player joined: {e.Peer.PlayerID}");

            // kick: blocked mods found
            if (e.Peer.HasSmapi)
            {
                string[] blockedModNames = this
                                           .GetBlockedMods(e.Peer)
                                           .Distinct(StringComparer.InvariantCultureIgnoreCase)
                                           .OrderBy(p => p)
                                           .ToArray();
                if (blockedModNames.Any())
                {
                    this.Monitor.Log($"   Will kick in {this.SecondsUntilKick} seconds: found prohibited mods {string.Join(", ", blockedModNames)}.");
                    this.PlayersToKick.Add(new PlayerSlot
                    {
                        Peer             = e.Peer,
                        CountDownSeconds = this.SecondsUntilKick,
                        BlockedModNames  = blockedModNames
                    });
                    return;
                }
            }

            // no issues found
            this.Monitor.Log("   No issues found.");
        }
        private static void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            //  Whenever a new client connects to the host, force the NetStrings that store bag data to get re-loaded on the other clients
            if (Context.IsMainPlayer)
            {
                ItemBag.GetAllBags(false).ForEach(x => x.Resync());

                //  I have no idea why, but it seems like the items in the connected farmhand's inventory are getting replaced with new instances after I've synchronized the current instances.
                //  So to maintain bags in their inventory, send the data to the peer using IMultiplayerEvents.SendMessage/IMultiplayerEvents.ModMessageReceived.
                //  This will force the connected client to overwrite their inventory with the correct data.
                Farmer ConnectedFarmer = Game1.getAllFarmers().First(x => x.UniqueMultiplayerID == e.Peer.PlayerID);
                Dictionary <int, string> PendingSync = new Dictionary <int, string>();
                for (int i = 0; i < ConnectedFarmer.Items.Count; i++)
                {
                    Item Item = ConnectedFarmer.Items[i];
                    if (Item != null && Item is ItemBag Bag && Bag.TrySerializeToString(out string DataString, out Exception Error))
                    {
                        PendingSync.Add(i, DataString);
                    }
                }
                if (PendingSync.Any())
                {
                    Helper.Multiplayer.SendMessage(PendingSync, ForceResyncCommandType, new string[] { ItemBagsMod.ModUniqueId }, new long[] { ConnectedFarmer.UniqueMultiplayerID });
                }

                Helper.Multiplayer.SendMessage("", OnConnectedCommandType, new string[] { ItemBagsMod.ModUniqueId }, new long[] { ConnectedFarmer.UniqueMultiplayerID });
            }
        }
Exemplo n.º 4
0
        private void onPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            //Log.debug($"Sending hunger data to {e.Peer.PlayerID}");
            var data = Helper.Data.ReadSaveData <SaveData>($"spacechase0.AnotherHungerMod.{e.Peer.PlayerID}") ?? new SaveData();

            Helper.Multiplayer.SendMessage(data, MSG_HUNGERDATA, null, new long[] { e.Peer.PlayerID });
        }
        public void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs args)
        {
            Task requestTask = Task.Run(() =>
            {
                bool hasPlayerConnected = Game1.getOnlineFarmers().Any(f => f.UniqueMultiplayerID == args.Peer.PlayerID);;
                int intervalsWaited     = 0;
                while (!hasPlayerConnected && intervalsWaited < 300)
                {
                    hasPlayerConnected = Game1.getOnlineFarmers().Any(f => f.UniqueMultiplayerID == args.Peer.PlayerID);

                    if (hasPlayerConnected)
                    {
                        break;
                    }

                    Thread.Sleep(100);
                    intervalsWaited++;
                }

                if (hasPlayerConnected)
                {
                    CheckForValidModInstall(args.Peer, Game1.getFarmer(args.Peer.PlayerID).Name);
                }
                else
                {
                    CheckForValidModInstall(args.Peer, args.Peer.PlayerID.ToString());
                }
            });
        }
Exemplo n.º 6
0
        /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game. This is the earliest point where messages can be sent to the peer via SMAPI.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void onPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            Log.debug($"Sending tool geode data to {e.Peer.PlayerID}");
            var data = Helper.Data.ReadSaveData <SaveData>($"spacechase0.ToolGeodes.{e.Peer.PlayerID}") ?? new SaveData();

            Helper.Multiplayer.SendMessage(data, MSG_TOOLGEODEDATA);
        }
Exemplo n.º 7
0
 private void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     if (e.Peer.HasSmapi && e.Peer.GetMod(ModEntry.Instance.PongId) != null)
     {
         this.peers.Add(e.Peer);
         this.UpdatePeers();
     }
 }
Exemplo n.º 8
0
 private void clientConnected(object sender, PeerContextReceivedEventArgs e)
 {
     if (!Context.IsMainPlayer)
     {
         Log.debug("Loading stuff early (MP client)");
         initStuff(loadIdFiles: true);
     }
 }
Exemplo n.º 9
0
 /*********
 ** Event Handlers
 *********/
 /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game. This is the earliest point where messages can be sent to the peer via SMAPI.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     // If the host doesn't have the same version of Better Doors installed, disable for this player.
     if (e.Peer.IsHost && (!e.Peer.HasSmapi || e.Peer.GetMod(this.Helper.Multiplayer.ModID)?.Version != this.Helper.ModRegistry.Get(this.Helper.Multiplayer.ModID).Manifest.Version))
     {
         this.Disable();
     }
 }
Exemplo n.º 10
0
 /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game. This is the earliest point where messages can be sent to the peer via SMAPI.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 private void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     // If the host doesn't have the same version of Better Doors installed, disable for this player.
     if (e.Peer.IsHost && (!e.Peer.HasSmapi || !this.Helper.ModRegistry.Get(this.Helper.Multiplayer.ModID).Manifest.Version.Equals(e.Peer.GetMod(this.Helper.Multiplayer.ModID)?.Version)))
     {
         this.Monitor.Log("Disabling mod for farmhand because the host doesn't have a compatible Better Doors version.");
         this.Monitor.Log($"Host version: {e.Peer.GetMod(this.Helper.Multiplayer.ModID)?.Version}. Local version: {this.Helper.ModRegistry.Get(this.Helper.Multiplayer.ModID).Manifest.Version}.");
         this.Disable();
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Send message method.
 /// The method to call when a peer connects. Host will send the SaveFolderName using this.
 /// </summary>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">Contains all the arguments of PeerConnectedEvent</param>
 public static void OnPeerConnected(object sender, PeerContextReceivedEventArgs e)
 {
     if (Context.IsMainPlayer)
     {
         Utilities.Data.Helper.Multiplayer.SendMessage <SaveFolderNameModel>(new SaveFolderNameModel()
         {
             SaveFolderName = Utilities.Data.SaveFolderName
         }, "SaveFolderName", modIDs: new[] { Utilities.Data.Helper.ModRegistry.ModID }, playerIDs: new[] { e.Peer.PlayerID });
     }
 }
Exemplo n.º 12
0
 private void PlayerConnected(object sender, PeerContextReceivedEventArgs e)
 {
     if (Context.IsMainPlayer)
     {
         peers.Add(e.Peer);
         if (e.Peer.GetMod("lolmaj.MultiplayerTime") == null)
         {
             Game1.chatBox.addMessage(Game1.getOnlineFarmers().FirstOrDefault(p => p.UniqueMultiplayerID == e.Peer.PlayerID)?.Name ?? e.Peer.PlayerID.ToString() + " does not have Multiplayer Time mod", Color.Red);
         }
     }
 }
Exemplo n.º 13
0
        private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            // if player isn't host, just return
            if (!CheckIfServer())
            {
                return;
            }

            // add to the NewPlayers list to process once online
            NewPlayers.Add(e.Peer);
        }
Exemplo n.º 14
0
        private void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            //this.Log( "Context from ID: " + e.Peer.PlayerID );
            //this.Log( Game1.IsMasterGame ? "Master" : "Not-Master" );
            //this.Log( Game1.IsMultiplayer ? "Multi" : "Single" );
            //this.Log( Game1.IsClient ? "Client" : "Not-Client" );
            //this.Log( Game1.IsServer ? "Server" : "Not-Server" );

            if (!Context.IsMainPlayer)
            {
                return;
            }
        }
Exemplo n.º 15
0
        /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game. This is the earliest point where messages can be sent to the peer via SMAPI.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void onPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            Log.debug("Received peer context: " + e.Peer.PlayerID + " " + Game1.IsMasterGame);
            if (!Game1.IsServer)
            {
                return;
            }

            Log.debug($"Sending tool geode data to {e.Peer.PlayerID}");
            var data = Helper.Data.ReadSaveData <SaveData>($"spacechase0.ToolGeodes.{e.Peer.PlayerID}") ?? new SaveData();

            Helper.Multiplayer.SendMessage(data, MSG_TOOLGEODEDATA, playerIDs: new[] { e.Peer.PlayerID });
        }
Exemplo n.º 16
0
        /// <summary>
        /// Newly connected player is assigned an id to use with their portal gun
        /// </summary>
        private void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            if (!PlayerList.Contains(e.Peer.PlayerID))
            {
                PlayerList.Add(e.Peer.PlayerID);
                int playerIndexForNewPlayer = PlayerList.Count;
                this.Helper.Multiplayer.SendMessage(playerIndexForNewPlayer, "PlayerIndex", modIDs: new[] { this.ModManifest.UniqueID }, new long[] { e.Peer.PlayerID });
            }
        }
Exemplo n.º 17
0
        /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            // log join
            this.Monitor.Log($"Player joined: {e.Peer.PlayerID}");

            // kick: blocked mods found
            if (e.Peer.HasSmapi)
            {
                foreach (IMultiplayerPeerMod mood in  e.Peer.Mods)
                {
                    this.Monitor.Log($"MOOOOD {mood.Name}");
                }

                string[] excessMods = this
                                      .GetExcessMods(e.Peer)
                                      .Distinct(StringComparer.InvariantCultureIgnoreCase)
                                      .OrderBy(p => p)
                                      .ToArray();

                string[] neededMods = this
                                      .GetNeededMods(e.Peer)
                                      .Distinct(StringComparer.InvariantCultureIgnoreCase)
                                      .OrderBy(p => p)
                                      .ToArray();

                if (excessMods.Any() || neededMods.Any())
                {
                    this.Monitor.Log($"   Will kick in {this.SecondsUntilKick} seconds: mod mismatch.");
                    this.Monitor.Log($"     Player has excess mods: {string.Join(", ", excessMods)}");
                    this.Monitor.Log($"     Player needs mods: {string.Join(", ", neededMods)}");
                    this.PlayersToKick.Add(new PlayerSlot
                    {
                        Peer             = e.Peer,
                        CountDownSeconds = this.SecondsUntilKick,
                        ExcessMods       = excessMods,
                        NeededMods       = neededMods
                    });
                    return;
                }
            }

            // no issues found
            this.Monitor.Log("   No issues found.");
        }
Exemplo n.º 18
0
        /*
         * Multiplayer config syncs
         */

        private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            if (!config.multiplayerSync)
            {
                return;
            }


            SendConfigSyncMessages(new[] { e.Peer.PlayerID });
        }
Exemplo n.º 19
0
 private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     if (Context.IsMainPlayer)
     {
         if (e.Peer.GetMod(ModManifest.UniqueID) == null)
         {
             string playerName = Utils.GetFarmerNameFromID(e.Peer.PlayerID);
             Utils.SendMessage(Helper.Translation.Get("message.less.mod", new { playerName = playerName, ModManifestName = ModManifest.Name }), Color.Red);
         }
         else
         {
             Active = true;
             Monitor.Log($"{ModManifest.Name} Is Active", LogLevel);
         }
     }
 }
Exemplo n.º 20
0
 private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     if (Context.IsMainPlayer)
     {
         if (e.Peer.GetMod(ModManifest.UniqueID) == null)
         {
             string playerName = Utils.GetFarmerNameFromID(e.Peer.PlayerID);
             Utils.SendMessage($"{playerName} 没有安装 {ModManifest.Name} Mod", Color.Red);
         }
         else
         {
             Active = true;
             Monitor.Log($"{ModManifest.Name} Is Active", LogLevel);
         }
     }
 }
Exemplo n.º 21
0
 private void Multiplayer_PeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     if (!e.Peer.HasSmapi || e.Peer.IsHost)
     {
         return;
     }
     foreach (IMultiplayerPeerMod mod in e.Peer.Mods)
     {
         if (Config.ModBlackListIds.Any(mod.ID.Contains) || Config.ModBlackListNames.Any(mod.Name.Contains))
         {
             var cheater = Game1.getAllFarmhands().First(x => x.UniqueMultiplayerID == e.Peer.PlayerID);
             Monitor.Log("Cheater has joined: " + cheater.name, LogLevel.Warn);
             cheatingFarmers.Add(cheater);
             if (!timer.Enabled)
             {
                 timer.Start();
             }
             return;
         }
     }
 }
 /// <summary>Raised after the mod context for a peer is received. This happens before the game approves the connection, so the player doesn't yet exist in the game. This is the earliest point where messages can be sent to the peer via SMAPI.</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 protected virtual void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
 }
Exemplo n.º 23
0
 private void OnPeerContextReceived(object sender, PeerContextReceivedEventArgs e)
 {
     newPlayerConnectTime.Add(e.Peer.PlayerID, DateTime.Now);
     this.Monitor.Log($"New Player: {e.Peer.PlayerID}");
 }
Exemplo n.º 24
0
        /*********
        ** Private methods
        *********/

        private void OnClientConnected(object sender, PeerContextReceivedEventArgs e)
        {
            this.Helper.Content.AssetEditors.Add(new VoidshroomDataInjector(this.Monitor));
        }
Exemplo n.º 25
0
        private void PeerConnected(object sender, PeerContextReceivedEventArgs e)
        {
            if (!Context.IsMainPlayer)
            {
                return;
            }

            var report = new MultiplayerReportData();

            report.TimeConnected = DateTime.Now;

            report.SmapiGameGameVersions.FarmhandHasSmapi = e.Peer.HasSmapi;

            report.FarmhandID   = e.Peer.PlayerID;
            report.FarmhandName = Game1.getAllFarmers()
                                  .FirstOrDefault(f => f.UniqueMultiplayerID == e.Peer.PlayerID)
                                  ?.Name;

            if (string.IsNullOrEmpty(report.FarmhandName))
            {
                report.FarmhandName = Helper.Translation.Get("UnnamedFarmhand");
            }

            if (e.Peer.HasSmapi)
            {
                report.SmapiGameGameVersions.HostSmapiVersion     = Constants.ApiVersion;
                report.SmapiGameGameVersions.FarmhandSmapiVersion = e.Peer.ApiVersion;

                var HostMods     = Helper.ModRegistry.GetAll().Select(m => m.Manifest.UniqueID);
                var farmHandMods = e.Peer.Mods.Select(m => m.ID);
                var allMods      = HostMods.Union(farmHandMods).Distinct();

                foreach (var mod in allMods)
                {
                    if (_config.IgnoredMods.Contains(mod))
                    {
                        continue;
                    }

                    var modVersionData = new ModVersions();

                    var hostMod = Helper.ModRegistry.Get(mod);
                    if (hostMod != null)
                    {
                        modVersionData.DoesHostHave   = true;
                        modVersionData.HostModVersion = hostMod.Manifest.Version;
                    }


                    var farmhandMod = e.Peer.GetMod(mod);
                    if (farmhandMod != null)
                    {
                        modVersionData.DoesFarmhandHave   = true;
                        modVersionData.FarmhandModVersion = farmhandMod.Version;
                    }

                    if (hostMod != null)
                    {
                        modVersionData.ModName = hostMod.Manifest.Name;
                    }
                    else if (farmhandMod != null)
                    {
                        modVersionData.ModName = farmhandMod.Name;
                    }

                    modVersionData.ModUniqueID = mod;
                    report.Mods.Add(modVersionData);
                }
            }

            _rawReports.Add(report);
            GenerateReport(report);
        }