summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/common.targets113
-rw-r--r--docs/release-notes.md5
-rw-r--r--src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs2
-rw-r--r--src/SMAPI.Web/ViewModels/ModModel.cs3
-rw-r--r--src/SMAPI.Web/Views/LogParser/Index.cshtml6
-rw-r--r--src/SMAPI.Web/Views/Mods/Index.cshtml34
-rw-r--r--src/SMAPI.Web/wwwroot/Content/css/log-parser.css4
-rw-r--r--src/SMAPI.Web/wwwroot/Content/css/mods.css47
-rw-r--r--src/SMAPI.Web/wwwroot/Content/js/mods.js144
-rw-r--r--src/SMAPI/Framework/Networking/MultiplayerPeer.cs60
-rw-r--r--src/SMAPI/Framework/Networking/SGalaxyNetClient.cs52
-rw-r--r--src/SMAPI/Framework/Networking/SGalaxyNetServer.cs63
-rw-r--r--src/SMAPI/Framework/Networking/SLidgrenClient.cs19
-rw-r--r--src/SMAPI/Framework/Networking/SLidgrenServer.cs114
-rw-r--r--src/SMAPI/Framework/SCore.cs11
-rw-r--r--src/SMAPI/Framework/SMultiplayer.cs90
-rw-r--r--src/SMAPI/Patches/LidgrenServerPatch.cs89
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj9
18 files changed, 459 insertions, 406 deletions
diff --git a/build/common.targets b/build/common.targets
index f631633d..320b3e00 100644
--- a/build/common.targets
+++ b/build/common.targets
@@ -38,72 +38,57 @@
<!-- add game references-->
<Choose>
<When Condition="'$(MSBuildProjectName)' == 'StardewModdingAPI' OR '$(MSBuildProjectName)' == 'StardewModdingAPI.Mods.ConsoleCommands' OR '$(MSBuildProjectName)' == 'StardewModdingAPI.Mods.SaveBackup' OR '$(MSBuildProjectName)' == 'StardewModdingAPI.Tests'">
- <Choose>
- <When Condition="$(OS) == 'Windows_NT'">
- <ItemGroup>
- <!--XNA framework-->
- <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
- <Private>False</Private>
- </Reference>
- <Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
- <Private>False</Private>
- </Reference>
- <Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
- <Private>False</Private>
- </Reference>
- <Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
- <Private>False</Private>
- </Reference>
+ <!-- Windows -->
+ <ItemGroup Condition="$(OS) == 'Windows_NT'">
+ <Reference Include="Stardew Valley">
+ <HintPath>$(GamePath)\Stardew Valley.exe</HintPath>
+ <Private Condition="'$(MSBuildProjectName)' != 'StardewModdingAPI.Tests'">False</Private>
+ </Reference>
+ <Reference Include="Netcode">
+ <HintPath>$(GamePath)\Netcode.dll</HintPath>
+ <Private Condition="'$(MSBuildProjectName)' != 'StardewModdingAPI.Tests'">False</Private>
+ </Reference>
+ <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
+ <Private>False</Private>
+ </Reference>
+ </ItemGroup>
- <!-- game DLLs -->
- <Reference Include="GalaxyCSharp">
- <HintPath>$(GamePath)\GalaxyCSharp.dll</HintPath>
- <Private>False</Private>
- </Reference>
- <Reference Include="Lidgren.Network">
- <HintPath>$(GamePath)\Lidgren.Network.dll</HintPath>
- <Private>False</Private>
- </Reference>
- <Reference Include="Netcode">
- <HintPath>$(GamePath)\Netcode.dll</HintPath>
- <Private Condition="'$(MSBuildProjectName)' != 'StardewModdingAPI.Tests'">False</Private>
- </Reference>
- <Reference Include="Stardew Valley">
- <HintPath>$(GamePath)\Stardew Valley.exe</HintPath>
- <Private Condition="'$(MSBuildProjectName)' != 'StardewModdingAPI.Tests'">False</Private>
- </Reference>
- <Reference Include="xTile, Version=2.0.4.0, Culture=neutral, processorArchitecture=x86">
- <HintPath>$(GamePath)\xTile.dll</HintPath>
- <Private>False</Private>
- <SpecificVersion>False</SpecificVersion>
- </Reference>
- </ItemGroup>
- </When>
- <Otherwise>
- <ItemGroup>
- <!-- MonoGame -->
- <Reference Include="MonoGame.Framework">
- <HintPath>$(GamePath)\MonoGame.Framework.dll</HintPath>
- <Private>False</Private>
- <SpecificVersion>False</SpecificVersion>
- </Reference>
+ <!-- Linux/Mac -->
+ <ItemGroup Condition="$(OS) != 'Windows_NT'">
+ <Reference Include="StardewValley">
+ <HintPath>$(GamePath)\StardewValley.exe</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="MonoGame.Framework">
+ <HintPath>$(GamePath)\MonoGame.Framework.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ </ItemGroup>
- <!-- game DLLs -->
- <Reference Include="Lidgren.Network">
- <HintPath>$(GamePath)\Lidgren.Network.dll</HintPath>
- <Private>False</Private>
- </Reference>
- <Reference Include="StardewValley">
- <HintPath>$(GamePath)\StardewValley.exe</HintPath>
- <Private>False</Private>
- </Reference>
- <Reference Include="xTile">
- <HintPath>$(GamePath)\xTile.dll</HintPath>
- <Private>False</Private>
- </Reference>
- </ItemGroup>
- </Otherwise>
- </Choose>
+ <!-- common -->
+ <ItemGroup>
+ <Reference Include="GalaxyCSharp">
+ <HintPath>$(GamePath)\GalaxyCSharp.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Lidgren.Network">
+ <HintPath>$(GamePath)\Lidgren.Network.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="xTile">
+ <HintPath>$(GamePath)\xTile.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ </ItemGroup>
</When>
</Choose>
diff --git a/docs/release-notes.md b/docs/release-notes.md
index b9a73f99..58d27ba0 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -10,7 +10,7 @@
* You can now mark a mod folder ignored by starting the name with a dot (like `.disabled mods`).
* Improved various error messages to be more clear and intuitive.
* SMAPI now prevents a crash caused by mods adding dialogue the game can't parse.
- * When you have an older game version, SMAPI now recommends a compatible SMAPI version in its error.
+ * SMAPI now recommends a compatible SMAPI version if you have an older game version.
* Fixed transparency issues on Linux/Mac for some mod images.
* Fixed error when a mod manifest is corrupted.
* Fixed error when a mod adds an unnamed location.
@@ -29,6 +29,7 @@
* Added [privacy page](https://smapi.io/privacy).
* The log parser now has a separate filter for game messages.
* The log parser now shows content pack authors (thanks to danvolchek!).
+ * Tweaked log parser UI (thanks to danvolchek!).
* Fixed log parser instructions for Mac.
* For modders:
@@ -50,7 +51,7 @@
* Suppressed the game's 'added crickets' debug output.
* Updated dependencies (Harmony 1.0.9.1 → 1.2.0.1, Mono.Cecil 0.10 → 0.10.1).
* **Deprecations:**
- * Non-string manifest versions are now deprecated and will no longer work in SMAPI 3.0. Affected mods should be updated to use a string version, like `"Version": "1.0.0"`.
+ * Non-string manifest versions are now deprecated and will stop working in SMAPI 3.0. Affected mods should use a string version, like `"Version": "1.0.0"`.
* `ISemanticVersion.Build` is now deprecated and will be removed in SMAPI 3.0. Affected mods should use `ISemanticVersion.PrereleaseTag` instead.
* **Breaking changes:**
* `helper.ModRegistry` now returns `IModInfo` instead of `IManifest` directly. This lets SMAPI return more metadata about mods.
diff --git a/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs b/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
index 61756176..85bf1e46 100644
--- a/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
@@ -29,6 +29,8 @@ namespace StardewModdingAPI.Web.ViewModels
public ModCompatibilityModel(WikiCompatibilityInfo info)
{
this.Status = info.Status.ToString();
+ this.Status = this.Status.Substring(0, 1).ToLower() + this.Status.Substring(1);
+
this.Summary = info.Summary;
this.BrokeIn = info.BrokeIn;
if (info.UnofficialVersion != null)
diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs
index 309ed828..0e7d2076 100644
--- a/src/SMAPI.Web/ViewModels/ModModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModModel.cs
@@ -40,6 +40,9 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>A unique identifier for the mod that can be used in an anchor URL.</summary>
public string Slug { get; set; }
+ /// <summary>The sites where the mod can be downloaded.</summary>
+ public string[] ModPageSites => this.ModPages.Select(p => p.Text).ToArray();
+
/*********
** Public methods
diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml
index 36eb9bb5..58830d64 100644
--- a/src/SMAPI.Web/Views/LogParser/Index.cshtml
+++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml
@@ -145,14 +145,14 @@ else if (Model.ParsedLog?.IsValid == true)
@if (!Model.ShowRaw)
{
<span class="notice txt"><i>click any mod to filter</i></span>
- <span class="notice btn txt" v-on:click="showAllMods" v-show="stats.modsHidden > 0">show all</span>
- <span class="notice btn txt" v-on:click="hideAllMods" v-show="stats.modsShown > 0 && stats.modsHidden > 0">hide all</span>
+ <span class="notice btn txt" v-on:click="showAllMods" v-bind:class="{ invisible: !anyModsHidden }">show all</span>
+ <span class="notice btn txt" v-on:click="hideAllMods" v-bind:class="{ invisible: !anyModsShown || !anyModsHidden }">hide all</span>
}
</caption>
@foreach (var mod in Model.ParsedLog.Mods.Where(p => p.ContentPackFor == null))
{
<tr v-on:click="toggleMod('@Model.GetSlug(mod.Name)')" class="mod-entry" v-bind:class="{ hidden: !showMods['@Model.GetSlug(mod.Name)'] }">
- <td><input type="checkbox" v-bind:checked="showMods['@Model.GetSlug(mod.Name)']" v-show="anyModsHidden" /></td>
+ <td><input type="checkbox" v-bind:checked="showMods['@Model.GetSlug(mod.Name)']" v-bind:class="{ invisible: !anyModsHidden }" /></td>
<td v-pre>
<strong>@mod.Name</strong> @mod.Version
@if (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList))
diff --git a/src/SMAPI.Web/Views/Mods/Index.cshtml b/src/SMAPI.Web/Views/Mods/Index.cshtml
index b326fd36..372d6706 100644
--- a/src/SMAPI.Web/Views/Mods/Index.cshtml
+++ b/src/SMAPI.Web/Views/Mods/Index.cshtml
@@ -4,11 +4,11 @@
ViewData["Title"] = "SMAPI mod compatibility";
}
@section Head {
- <link rel="stylesheet" href="~/Content/css/mods.css?r=20181021" />
+ <link rel="stylesheet" href="~/Content/css/mods.css?r=20181109" />
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/tablesorter@2.31.0/dist/js/jquery.tablesorter.combined.min.js" crossorigin="anonymous"></script>
- <script src="~/Content/js/mods.js?r=20181021"></script>
+ <script src="~/Content/js/mods.js?r=20181109"></script>
<script>
$(function() {
var data = @Json.Serialize(Model.Mods, new JsonSerializerSettings { Formatting = Formatting.None });
@@ -29,14 +29,22 @@
</div>
<div id="app">
- <div>
- <label for="search-box">Search: </label>
- <input type="text" id="search-box" v-model="search" v-on:input="applySearch" />
- </div>
- <div id="show-fields-option">
- <input type="checkbox" id="show-all-fields" v-model="showAllFields" />
- <label for="show-all-fields">show advanced fields</label>
+ <div id="options">
+ <div>
+ <label for="search-box">Search: </label>
+ <input type="text" id="search-box" v-model="search" v-on:input="applyFilters" />
+ </div>
+ <div id="filter-area">
+ <input type="checkbox" id="show-advanced" v-model="showAdvanced" />
+ <label for="show-advanced">show detailed options</label>
+ <div id="filters" v-show="showAdvanced">
+ <div v-for="(filterGroup, key) in filters">
+ {{key}}: <span v-for="filter in filterGroup" v-bind:class="{ active: filter.value }"><input type="checkbox" v-bind:id="filter.id" v-model="filter.value" v-on:change="applyFilters" /> <label v-bind:for="filter.id">{{filter.label}}</label></span>
+ </div>
+ </div>
+ </div>
</div>
+ <div id="mod-count" v-show="showAdvanced">{{visibleCount}} mods shown.</div>
<table class="wikitable" id="mod-list">
<thead>
<tr>
@@ -44,8 +52,8 @@
<th>links</th>
<th>author</th>
<th>compatibility</th>
- <th v-show="showAllFields">broke in</th>
- <th v-show="showAllFields">code</th>
+ <th v-show="showAdvanced">broke in</th>
+ <th v-show="showAdvanced">code</th>
<th>&nbsp;</th>
</tr>
</thead>
@@ -72,8 +80,8 @@
</div>
<div v-for="(warning, i) in mod.Warnings">⚠ {{warning}}</div>
</td>
- <td class="mod-broke-in" v-html="mod.BetaCompatibility ? mod.BetaCompatibility.BrokeIn : mod.Compatibility.BrokeIn" v-show="showAllFields"></td>
- <td v-show="showAllFields">
+ <td class="mod-broke-in" v-html="mod.BetaCompatibility ? mod.BetaCompatibility.BrokeIn : mod.Compatibility.BrokeIn" v-show="showAdvanced"></td>
+ <td v-show="showAdvanced">
<span v-if="mod.SourceUrl"><a v-bind:href="mod.SourceUrl">source</a></span>
<span v-else class="mod-closed-source">no source</span>
</td>
diff --git a/src/SMAPI.Web/wwwroot/Content/css/log-parser.css b/src/SMAPI.Web/wwwroot/Content/css/log-parser.css
index 1fcd1bff..2f3dd0a1 100644
--- a/src/SMAPI.Web/wwwroot/Content/css/log-parser.css
+++ b/src/SMAPI.Web/wwwroot/Content/css/log-parser.css
@@ -63,6 +63,10 @@ table#metadata, table#mods {
box-shadow: 1px 1px 1px 1px #dddddd;
}
+.invisible {
+ visibility: hidden;
+}
+
#mods {
min-width: 400px;
}
diff --git a/src/SMAPI.Web/wwwroot/Content/css/mods.css b/src/SMAPI.Web/wwwroot/Content/css/mods.css
index 9f82e3e6..730bfc2e 100644
--- a/src/SMAPI.Web/wwwroot/Content/css/mods.css
+++ b/src/SMAPI.Web/wwwroot/Content/css/mods.css
@@ -18,7 +18,6 @@
table.wikitable {
background-color:#f8f9fa;
color:#222;
- margin:1em 0;
border:1px solid #a2a9b1;
border-collapse:collapse
}
@@ -40,10 +39,40 @@ table.wikitable > caption {
font-weight:bold
}
-#show-fields-option {
+#options {
+ margin-bottom: 1em;
+}
+
+#options #filter-area {
opacity: 0.7;
}
+#options #filters {
+ margin-left: 2em;
+ padding-left: 0.5em;
+ border-left: 2px solid gray;
+}
+
+#options #filters span {
+ padding: 2px;
+ margin: 2px;
+ display: inline-block;
+ border-radius: 3px;
+ color: #000;
+ border-color: #880000;
+ background-color: #fcc;
+ font-size: 0.9em;
+}
+
+#options #filters span.active {
+ background: #cfc;
+}
+
+#mod-count {
+ font-size: 0.8em;
+ opacity: 0.5;
+}
+
#mod-list {
font-size: 0.9em;
}
@@ -79,22 +108,22 @@ table.wikitable > caption {
display: block;
}
-#mod-list tr[data-status="Ok"],
-#mod-list tr[data-status="Optional"] {
+#mod-list tr[data-status="ok"],
+#mod-list tr[data-status="optional"] {
background: #BFB;
}
-#mod-list tr[data-status="Workaround"],
-#mod-list tr[data-status="Unofficial"] {
+#mod-list tr[data-status="workaround"],
+#mod-list tr[data-status="unofficial"] {
background: #FFFEC6;
}
-#mod-list tr[data-status="Broken"] {
+#mod-list tr[data-status="broken"] {
background: #FBB;
}
-#mod-list tr[data-status="Obsolete"],
-#mod-list tr[data-status="Abandoned"] {
+#mod-list tr[data-status="obsolete"],
+#mod-list tr[data-status="abandoned"] {
background: #BBB;
opacity: 0.7;
}
diff --git a/src/SMAPI.Web/wwwroot/Content/js/mods.js b/src/SMAPI.Web/wwwroot/Content/js/mods.js
index 1af53906..2cff551f 100644
--- a/src/SMAPI.Web/wwwroot/Content/js/mods.js
+++ b/src/SMAPI.Web/wwwroot/Content/js/mods.js
@@ -6,7 +6,76 @@ smapi.modList = function (mods) {
// init data
var data = {
mods: mods,
- showAllFields: false,
+ visibleCount: mods.length,
+ showAdvanced: false,
+ filters: {
+ source: {
+ open: {
+ label: "open",
+ id: "show-open-source",
+ value: true
+ },
+ closed: {
+ label: "closed",
+ id: "show-closed-source",
+ value: true
+ }
+ },
+ status: {
+ ok: {
+ label: "ok",
+ id: "show-status-ok",
+ value: true
+ },
+ optional: {
+ label: "optional",
+ id: "show-status-optional",
+ value: true
+ },
+ unofficial: {
+ label: "unofficial",
+ id: "show-status-unofficial",
+ value: true
+ },
+ workaround: {
+ label: "workaround",
+ id: "show-status-workaround",
+ value: true
+ },
+ broken: {
+ label: "broken",
+ id: "show-status-broken",
+ value: true
+ },
+ abandoned: {
+ label: "abandoned",
+ id: "show-status-abandoned",
+ value: true
+ },
+ obsolete: {
+ label: "obsolete",
+ id: "show-status-obsolete",
+ value: true
+ }
+ },
+ download: {
+ chucklefish: {
+ label: "Chucklefish",
+ id: "show-chucklefish",
+ value: true
+ },
+ nexus: {
+ label: "Nexus",
+ id: "show-nexus",
+ value: true
+ },
+ custom: {
+ label: "custom",
+ id: "show-custom",
+ value: true
+ }
+ }
+ },
search: ""
};
for (var i = 0; i < data.mods.length; i++) {
@@ -54,25 +123,82 @@ smapi.modList = function (mods) {
},
methods: {
/**
- * Update the visibility of all mods based on the current search text.
+ * Update the visibility of all mods based on the current search text and filters.
*/
- applySearch: function () {
+ applyFilters: function () {
// get search terms
var words = data.search.toLowerCase().split(" ");
- // make sure all words match
+ // apply criteria
+ data.visibleCount = data.mods.length;
for (var i = 0; i < data.mods.length; i++) {
var mod = data.mods[i];
- var match = true;
- for (var w = 0; w < words.length; w++) {
- if (mod.SearchableText.indexOf(words[w]) === -1) {
- match = false;
+ mod.Visible = true;
+
+ // check filters
+ if (!this.matchesFilters(mod)) {
+ mod.Visible = false;
+ data.visibleCount--;
+ continue;
+ }
+
+ // check search terms (all search words should match)
+ if (words.length) {
+ for (var w = 0; w < words.length; w++) {
+ if (mod.SearchableText.indexOf(words[w]) === -1) {
+ mod.Visible = false;
+ data.visibleCount--;
+ break;
+ }
+ }
+ }
+ }
+ },
+
+
+ /**
+ * Get whether a mod matches the current filters.
+ * @param {object} mod The mod to check.
+ * @returns {bool} Whether the mod matches the filters.
+ */
+ matchesFilters: function(mod) {
+ var filters = data.filters;
+
+ // check source
+ if (!filters.source.open.value && mod.SourceUrl)
+ return false;
+ if (!filters.source.closed.value && !mod.SourceUrl)
+ return false;
+
+ // check status
+ var status = (mod.BetaCompatibility || mod.Compatibility).Status;
+ if (filters.status[status] && !filters.status[status].value)
+ return false;
+
+ // check download sites
+ var ignoreSites = [];
+
+ if (!filters.download.chucklefish.value)
+ ignoreSites.push("Chucklefish");
+ if (!filters.download.nexus.value)
+ ignoreSites.push("Nexus");
+ if (!filters.download.custom.value)
+ ignoreSites.push("custom");
+
+ if (ignoreSites.length) {
+ var anyLeft = false;
+ for (var i = 0; i < mod.ModPageSites.length; i++) {
+ if (ignoreSites.indexOf(mod.ModPageSites[i]) === -1) {
+ anyLeft = true;
break;
}
}
- mod.Visible = match;
+ if (!anyLeft)
+ return false;
}
+
+ return true;
}
}
});
diff --git a/src/SMAPI/Framework/Networking/MultiplayerPeer.cs b/src/SMAPI/Framework/Networking/MultiplayerPeer.cs
index 7f0fa4f7..44a71978 100644
--- a/src/SMAPI/Framework/Networking/MultiplayerPeer.cs
+++ b/src/SMAPI/Framework/Networking/MultiplayerPeer.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Lidgren.Network;
using StardewValley.Network;
namespace StardewModdingAPI.Framework.Networking
@@ -12,14 +11,8 @@ namespace StardewModdingAPI.Framework.Networking
/*********
** Properties
*********/
- /// <summary>The server through which to send messages, if this is an incoming farmhand.</summary>
- private readonly SLidgrenServer Server;
-
- /// <summary>The client through which to send messages, if this is the host player.</summary>
- private readonly SLidgrenClient Client;
-
- /// <summary>The network connection to the player.</summary>
- private readonly NetConnection ServerConnection;
+ /// <summary>A method which sends a message to the peer.</summary>
+ private readonly Action<OutgoingMessage> SendMessageImpl;
/*********
@@ -53,11 +46,9 @@ namespace StardewModdingAPI.Framework.Networking
/// <summary>Construct an instance.</summary>
/// <param name="playerID">The player's unique ID.</param>
/// <param name="model">The metadata to copy.</param>
- /// <param name="server">The server through which to send messages.</param>
- /// <param name="serverConnection">The server connection through which to send messages.</param>
- /// <param name="client">The client through which to send messages.</param>
+ /// <param name="sendMessage">A method which sends a message to the peer.</param>
/// <param name="isHost">Whether this is a connection to the host player.</param>
- public MultiplayerPeer(long playerID, RemoteContextModel model, SLidgrenServer server, NetConnection serverConnection, SLidgrenClient client, bool isHost)
+ public MultiplayerPeer(long playerID, RemoteContextModel model, Action<OutgoingMessage> sendMessage, bool isHost)
{
this.PlayerID = playerID;
this.IsHost = isHost;
@@ -68,43 +59,7 @@ namespace StardewModdingAPI.Framework.Networking
this.ApiVersion = model.ApiVersion;
this.Mods = model.Mods.Select(mod => new MultiplayerPeerMod(mod)).ToArray();
}
- this.Server = server;
- this.ServerConnection = serverConnection;
- this.Client = client;
- }
-
- /// <summary>Construct an instance for a connection to an incoming farmhand.</summary>
- /// <param name="playerID">The player's unique ID.</param>
- /// <param name="model">The metadata to copy, if available.</param>
- /// <param name="server">The server through which to send messages.</param>
- /// <param name="serverConnection">The server connection through which to send messages.</param>
- public static MultiplayerPeer ForConnectionToFarmhand(long playerID, RemoteContextModel model, SLidgrenServer server, NetConnection serverConnection)
- {
- return new MultiplayerPeer(
- playerID: playerID,
- model: model,
- server: server,
- serverConnection: serverConnection,
- client: null,
- isHost: false
- );
- }
-
- /// <summary>Construct an instance for a connection to the host player.</summary>
- /// <param name="playerID">The player's unique ID.</param>
- /// <param name="model">The metadata to copy.</param>
- /// <param name="client">The client through which to send messages.</param>
- /// <param name="isHost">Whether this connection is for the host player.</param>
- public static MultiplayerPeer ForConnectionToHost(long playerID, RemoteContextModel model, SLidgrenClient client, bool isHost)
- {
- return new MultiplayerPeer(
- playerID: playerID,
- model: model,
- server: null,
- serverConnection: null,
- client: client,
- isHost: isHost
- );
+ this.SendMessageImpl = sendMessage;
}
/// <summary>Get metadata for a mod installed by the player.</summary>
@@ -123,10 +78,7 @@ namespace StardewModdingAPI.Framework.Networking
/// <param name="message">The message to send.</param>
public void SendMessage(OutgoingMessage message)
{
- if (this.IsHost)
- this.Client.sendMessage(message);
- else
- this.Server.SendMessage(this.ServerConnection, message);
+ this.SendMessageImpl(message);
}
}
}
diff --git a/src/SMAPI/Framework/Networking/SGalaxyNetClient.cs b/src/SMAPI/Framework/Networking/SGalaxyNetClient.cs
new file mode 100644
index 00000000..fddd423d
--- /dev/null
+++ b/src/SMAPI/Framework/Networking/SGalaxyNetClient.cs
@@ -0,0 +1,52 @@
+using System;
+using Galaxy.Api;
+using StardewValley.Network;
+using StardewValley.SDKs;
+
+namespace StardewModdingAPI.Framework.Networking
+{
+ /// <summary>A multiplayer client used to connect to a hosted server. This is an implementation of <see cref="GalaxyNetClient"/> with callbacks for SMAPI functionality.</summary>
+ internal class SGalaxyNetClient : GalaxyNetClient
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>A callback to raise when receiving a message. This receives the incoming message, a method to send an arbitrary message, and a callback to run the default logic.</summary>
+ private readonly Action<IncomingMessage, Action<OutgoingMessage>, Action> OnProcessingMessage;
+
+ /// <summary>A callback to raise when sending a message. This receives the outgoing message, a method to send an arbitrary message, and a callback to resume the default logic.</summary>
+ private readonly Action<OutgoingMessage, Action<OutgoingMessage>, Action> OnSendingMessage;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="address">The remote address being connected.</param>
+ /// <param name="onProcessingMessage">A callback to raise when receiving a message. This receives the incoming message, a method to send an arbitrary message, and a callback to run the default logic.</param>
+ /// <param name="onSendingMessage">A callback to raise when sending a message. This receives the outgoing message, a method to send an arbitrary message, and a callback to resume the default logic.</param>
+ public SGalaxyNetClient(GalaxyID address, Action<IncomingMessage, Action<OutgoingMessage>, Action> onProcessingMessage, Action<OutgoingMessage, Action<OutgoingMessage>, Action> onSendingMessage)
+ : base(address)
+ {
+ this.OnProcessingMessage = onProcessingMessage;
+ this.OnSendingMessage = onSendingMessage;
+ }
+
+ /// <summary>Send a message to the connected peer.</summary>
+ public override void sendMessage(OutgoingMessage message)
+ {
+ this.OnSendingMessage(message, base.sendMessage, () => base.sendMessage(message));
+ }
+
+
+ /*********
+ ** Protected methods
+ *********/
+ /// <summary>Process an incoming network message.</summary>
+ /// <param name="message">The message to process.</param>
+ protected override void processIncomingMessage(IncomingMessage message)
+ {
+ this.OnProcessingMessage(message, base.sendMessage, () => base.processIncomingMessage(message));
+ }
+ }
+}
diff --git a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs
new file mode 100644
index 00000000..2fc92737
--- /dev/null
+++ b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using Galaxy.Api;
+using StardewValley.Network;
+using StardewValley.SDKs;
+
+namespace StardewModdingAPI.Framework.Networking
+{
+ /// <summary>A multiplayer server used to connect to an incoming player. This is an implementation of <see cref="LidgrenServer"/> that adds support for SMAPI's metadata context exchange.</summary>
+ internal class SGalaxyNetServer : GalaxyNetServer
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>A callback to r