diff options
-rw-r--r-- | docs/release-notes.md | 1 | ||||
-rw-r--r-- | src/SMAPI/Framework/Networking/SGalaxyNetServer.cs | 24 | ||||
-rw-r--r-- | src/SMAPI/Framework/SMultiplayer.cs | 2 |
3 files changed, 21 insertions, 6 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 2e826350..1f1dcab2 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## Upcoming release * For players: * SMAPI now prevents invalid items from crashing the game on hover. + * Fixed some multiplayer mod features not working when connecting via Steam friends. * Fixed cryptic error message when the game isn't installed correctly. * Fixed error when a mod makes invalid changes to an NPC schedule. * Fixed invalid NPC data propagated when a mod changes NPC dispositions. diff --git a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs index 2fc92737..82d11938 100644 --- a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs +++ b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs @@ -34,9 +34,14 @@ namespace StardewModdingAPI.Framework.Networking this.OnProcessingMessage = onProcessingMessage; } + + /********* + ** Protected methods + *********/ /// <summary>Read and process a message from the client.</summary> /// <param name="peer">The Galaxy peer ID.</param> /// <param name="messageStream">The data to process.</param> + /// <remarks>This reimplements <see cref="GalaxyNetServer.onReceiveMessage"/>, but adds a callback to <see cref="OnProcessingMessage"/>.</remarks> [SuppressMessage("ReSharper", "AccessToDisposedClosure", Justification = "The callback is invoked synchronously.")] protected override void onReceiveMessage(GalaxyID peer, Stream messageStream) { @@ -44,20 +49,27 @@ namespace StardewModdingAPI.Framework.Networking using (BinaryReader reader = new BinaryReader(messageStream)) { message.Read(reader); - this.OnProcessingMessage(message, outgoing => this.sendMessage(peer, outgoing), () => + ulong peerID = peer.ToUint64(); // note: GalaxyID instances get reused, so need to store the underlying ID instead + this.OnProcessingMessage(message, outgoing => this.SendMessageToPeerID(peerID, outgoing), () => { - if (this.peers.ContainsLeft(message.FarmerID) && (long)this.peers[message.FarmerID] == (long)peer.ToUint64()) - { + if (this.peers.ContainsLeft(message.FarmerID) && (long)this.peers[message.FarmerID] == (long)peerID) this.gameServer.processIncomingMessage(message); - } else if (message.MessageType == StardewValley.Multiplayer.playerIntroduction) { NetFarmerRoot farmer = this.Multiplayer.readFarmer(message.Reader); - GalaxyID capturedPeer = new GalaxyID(peer.ToUint64()); - this.gameServer.checkFarmhandRequest(Convert.ToString(peer.ToUint64()), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64()); + GalaxyID capturedPeer = new GalaxyID(peerID); + this.gameServer.checkFarmhandRequest(Convert.ToString(peerID), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64()); } }); } } + + /// <summary>Send a message to a remote peer.</summary> + /// <param name="peerID">The unique Galaxy ID, derived from <see cref="GalaxyID.ToUint64"/>.</param> + /// <param name="message">The message to send.</param> + private void SendMessageToPeerID(ulong peerID, OutgoingMessage message) + { + this.sendMessage(new GalaxyID(peerID), message); + } } } diff --git a/src/SMAPI/Framework/SMultiplayer.cs b/src/SMAPI/Framework/SMultiplayer.cs index 12cd2d46..784edae3 100644 --- a/src/SMAPI/Framework/SMultiplayer.cs +++ b/src/SMAPI/Framework/SMultiplayer.cs @@ -119,6 +119,7 @@ namespace StardewModdingAPI.Framework } default: + this.Monitor.Log($"Unknown multiplayer client type: {client.GetType().AssemblyQualifiedName}", LogLevel.Trace); return client; } } @@ -142,6 +143,7 @@ namespace StardewModdingAPI.Framework } default: + this.Monitor.Log($"Unknown multiplayer server type: {server.GetType().AssemblyQualifiedName}", LogLevel.Trace); return server; } } |