summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-01-02 12:33:19 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-01-02 12:33:19 -0500
commit251ee2121a870bd8210830a8bdb943f64c00e030 (patch)
tree40482154c50f4c875c94b2e2f8b30963e169d22f
parent0fdb09f5f9ef463dbf867c3a46ce680706305f0e (diff)
downloadSMAPI-251ee2121a870bd8210830a8bdb943f64c00e030.tar.gz
SMAPI-251ee2121a870bd8210830a8bdb943f64c00e030.tar.bz2
SMAPI-251ee2121a870bd8210830a8bdb943f64c00e030.zip
fix players in split-screen mode sharing peer state (#747)
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/SMultiplayer.cs15
2 files changed, 14 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index dcd638a3..a12a5482 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -10,6 +10,7 @@
## Upcoming release
* For players:
* Updated compatibility list.
+ * Fixed errors when multiple players join in split-screen mode.
* Fixed 'skipped mods' section repeating mods in some cases.
* For modders:
diff --git a/src/SMAPI/Framework/SMultiplayer.cs b/src/SMAPI/Framework/SMultiplayer.cs
index f3b5e9b9..2f89fce9 100644
--- a/src/SMAPI/Framework/SMultiplayer.cs
+++ b/src/SMAPI/Framework/SMultiplayer.cs
@@ -10,6 +10,7 @@ using StardewModdingAPI.Framework.Events;
using StardewModdingAPI.Framework.Networking;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Toolkit.Serialization;
+using StardewModdingAPI.Utilities;
using StardewValley;
using StardewValley.Network;
using StardewValley.SDKs;
@@ -54,15 +55,25 @@ namespace StardewModdingAPI.Framework
/// <summary>Whether to log network traffic.</summary>
private readonly bool LogNetworkTraffic;
+ /// <summary>The backing field for <see cref="Peers"/>.</summary>
+ private readonly PerScreen<IDictionary<long, MultiplayerPeer>> PeersImpl = new(() => new Dictionary<long, MultiplayerPeer>());
+
+ /// <summary>The backing field for <see cref="HostPeer"/>.</summary>
+ private readonly PerScreen<MultiplayerPeer> HostPeerImpl = new();
+
/*********
** Accessors
*********/
/// <summary>The metadata for each connected peer.</summary>
- public IDictionary<long, MultiplayerPeer> Peers { get; } = new Dictionary<long, MultiplayerPeer>();
+ public IDictionary<long, MultiplayerPeer> Peers => this.PeersImpl.Value;
/// <summary>The metadata for the host player, if the current player is a farmhand.</summary>
- public MultiplayerPeer HostPeer;
+ public MultiplayerPeer HostPeer
+ {
+ get => this.HostPeerImpl.Value;
+ private set => this.HostPeerImpl.Value = value;
+ }
/*********