summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Networking
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-16 11:29:40 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-16 11:29:40 -0400
commita090b6c21c877e8835f25e1d70d667abf07d1d3c (patch)
treebcd67890749d2f1c7dcdc7e82aba229cbba65d26 /src/SMAPI/Framework/Networking
parent896f531f4f6fc7f0e8dfcfc0d6433850233ee749 (diff)
downloadSMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.tar.gz
SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.tar.bz2
SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.zip
use newer C# features
Diffstat (limited to 'src/SMAPI/Framework/Networking')
-rw-r--r--src/SMAPI/Framework/Networking/SGalaxyNetServer.cs29
-rw-r--r--src/SMAPI/Framework/Networking/SLidgrenServer.cs31
2 files changed, 29 insertions, 31 deletions
diff --git a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs
index 7dbfa767..ac9cf313 100644
--- a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs
+++ b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs
@@ -45,23 +45,22 @@ namespace StardewModdingAPI.Framework.Networking
[SuppressMessage("ReSharper", "AccessToDisposedClosure", Justification = "The callback is invoked synchronously.")]
protected override void onReceiveMessage(GalaxyID peer, Stream messageStream)
{
- using (IncomingMessage message = new IncomingMessage())
- using (BinaryReader reader = new BinaryReader(messageStream))
+ using IncomingMessage message = new IncomingMessage();
+ using BinaryReader reader = new BinaryReader(messageStream);
+
+ message.Read(reader);
+ 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), () =>
{
- message.Read(reader);
- 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)peerID)
+ this.gameServer.processIncomingMessage(message);
+ else if (message.MessageType == StardewValley.Multiplayer.playerIntroduction)
{
- 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(peerID);
- this.gameServer.checkFarmhandRequest(Convert.ToString(peerID), this.getConnectionId(peer), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64());
- }
- });
- }
+ NetFarmerRoot farmer = this.Multiplayer.readFarmer(message.Reader);
+ GalaxyID capturedPeer = new GalaxyID(peerID);
+ this.gameServer.checkFarmhandRequest(Convert.ToString(peerID), this.getConnectionId(peer), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64());
+ }
+ });
}
/// <summary>Send a message to a remote peer.</summary>
diff --git a/src/SMAPI/Framework/Networking/SLidgrenServer.cs b/src/SMAPI/Framework/Networking/SLidgrenServer.cs
index f2c61917..05c8b872 100644
--- a/src/SMAPI/Framework/Networking/SLidgrenServer.cs
+++ b/src/SMAPI/Framework/Networking/SLidgrenServer.cs
@@ -44,25 +44,24 @@ namespace StardewModdingAPI.Framework.Networking
{
// add hook to call multiplayer core
NetConnection peer = rawMessage.SenderConnection;
- using (IncomingMessage message = new IncomingMessage())
- using (Stream readStream = new NetBufferReadStream(rawMessage))
- using (BinaryReader reader = new BinaryReader(readStream))
+ using IncomingMessage message = new IncomingMessage();
+ using Stream readStream = new NetBufferReadStream(rawMessage);
+ using BinaryReader reader = new BinaryReader(readStream);
+
+ while (rawMessage.LengthBits - rawMessage.Position >= 8)
{
- while (rawMessage.LengthBits - rawMessage.Position >= 8)
+ message.Read(reader);
+ NetConnection connection = rawMessage.SenderConnection; // don't pass rawMessage into context because it gets reused
+ this.OnProcessingMessage(message, outgoing => this.sendMessage(connection, outgoing), () =>
{
- message.Read(reader);
- NetConnection connection = rawMessage.SenderConnection; // don't pass rawMessage into context because it gets reused
- this.OnProcessingMessage(message, outgoing => this.sendMessage(connection, outgoing), () =>
+ if (this.peers.ContainsLeft(message.FarmerID) && this.peers[message.FarmerID] == peer)
+ this.gameServer.processIncomingMessage(message);
+ else if (message.MessageType == StardewValley.Multiplayer.playerIntroduction)
{
- if (this.peers.ContainsLeft(message.FarmerID) && this.peers[message.FarmerID] == peer)
- this.gameServer.processIncomingMessage(message);
- else if (message.MessageType == StardewValley.Multiplayer.playerIntroduction)
- {
- NetFarmerRoot farmer = this.Multiplayer.readFarmer(message.Reader);
- this.gameServer.checkFarmhandRequest("", this.getConnectionId(rawMessage.SenderConnection), farmer, msg => this.sendMessage(peer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = peer);
- }
- });
- }
+ NetFarmerRoot farmer = this.Multiplayer.readFarmer(message.Reader);
+ this.gameServer.checkFarmhandRequest("", this.getConnectionId(rawMessage.SenderConnection), farmer, msg => this.sendMessage(peer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = peer);
+ }
+ });
}
}
}