diff --git a/StardewArchipelago/Archipelago/ArchipelagoClient.cs b/StardewArchipelago/Archipelago/ArchipelagoClient.cs index 727c05a9f..bd50f8e5c 100644 --- a/StardewArchipelago/Archipelago/ArchipelagoClient.cs +++ b/StardewArchipelago/Archipelago/ArchipelagoClient.cs @@ -26,6 +26,7 @@ public class ArchipelagoClient private ChatForwarder _chatForwarder; private GiftHandler _giftHandler; private ArchipelagoConnectionInfo _connectionInfo; + private IManifest _modManifest; private Action _itemReceivedFunction; @@ -34,13 +35,14 @@ public class ArchipelagoClient public Dictionary ScoutedLocations { get; set; } // public Random MultiRandom { get; set; } - public ArchipelagoClient(IMonitor console, IModHelper modHelper, Harmony harmony, Action itemReceivedFunction) + public ArchipelagoClient(IMonitor console, IModHelper modHelper, Harmony harmony, Action itemReceivedFunction, IManifest manifest) { _console = console; _modHelper = modHelper; _harmony = harmony; _itemReceivedFunction = itemReceivedFunction; IsConnected = false; + _modManifest = manifest; ScoutedLocations = new Dictionary(); } @@ -52,6 +54,15 @@ public void Connect(ArchipelagoConnectionInfo connectionInfo, GiftHandler giftHa if (!success) { DisconnectPermanently(); + return; + } + + var majorVersion = _modManifest.Version.MajorVersion.ToString(); + if (!SlotData.MultiworldVersion.StartsWith(majorVersion)) + { + errorMessage = $"This Multiworld has been created for StardewArchipelago version {SlotData.MultiworldVersion},\nbut this is StardewArchipelago version {_modManifest.Version}.\nPlease update to a compatible mod version."; + DisconnectPermanently(); + return; } } @@ -62,7 +73,7 @@ private bool TryConnect(ArchipelagoConnectionInfo connectionInfo, out string err { InitSession(connectionInfo); var itemsHandling = ItemsHandlingFlags.AllItems; - var minimumVersion = new Version(0, 3, 7); + var minimumVersion = new Version(0, 3, 9); var tags = connectionInfo.DeathLink ? new[] { "AP", "DeathLink" } : new[] { "AP" }; result = _session.TryConnectAndLogin(GAME_NAME, _connectionInfo.SlotName, itemsHandling, minimumVersion, tags, null, _connectionInfo.Password); } @@ -99,14 +110,14 @@ private bool TryConnect(ArchipelagoConnectionInfo connectionInfo, out string err _console.Log(loginMessage, LogLevel.Info); // Must go AFTER a successful connection attempt - InitializeAfterConnection(loginSuccess, connectionInfo.SlotName); + InitializeSlotData(connectionInfo.SlotName, loginSuccess.SlotData); + InitializeAfterConnection(); connectionInfo.DeathLink = SlotData.DeathLink; return true; } - private void InitializeAfterConnection(LoginSuccessful loginSuccess, string slotName) + private void InitializeAfterConnection() { - InitializeSlotData(slotName, loginSuccess.SlotData); _session.Items.ItemReceived += OnItemReceived; _session.MessageLog.OnMessageReceived += OnMessageReceived; _session.Socket.ErrorReceived += SessionErrorReceived; diff --git a/StardewArchipelago/Archipelago/SlotData.cs b/StardewArchipelago/Archipelago/SlotData.cs index 3c1fdabb3..879c19270 100644 --- a/StardewArchipelago/Archipelago/SlotData.cs +++ b/StardewArchipelago/Archipelago/SlotData.cs @@ -33,6 +33,7 @@ public class SlotData private const string SEED_KEY = "seed"; private const string MODIFIED_BUNDLES_KEY = "modified_bundles"; private const string MODIFIED_ENTRANCES_KEY = "randomized_entrances"; + private const string MULTIWORLD_VERSION_KEY = "client_version"; private Dictionary _slotDataFields; private IMonitor _console; @@ -58,6 +59,7 @@ public class SlotData public double GiftTax { get; private set; } public bool DeathLink { get; private set; } public string Seed { get; private set; } + public string MultiworldVersion { get; private set; } private Dictionary ModifiedBundles { get; set; } public Dictionary ModifiedEntrances { get; set; } @@ -87,6 +89,7 @@ public SlotData(string slotName, Dictionary slotDataFields, IMon GiftTax = GetSlotSetting(GIFT_TAX_KEY, 30) / 100.0; DeathLink = GetSlotSetting(DEATH_LINK_KEY, false); Seed = GetSlotSetting(SEED_KEY, ""); + MultiworldVersion = GetSlotSetting(MULTIWORLD_VERSION_KEY, ""); var newBundleStringData = GetSlotSetting(MODIFIED_BUNDLES_KEY, ""); ModifiedBundles = JsonConvert.DeserializeObject>(newBundleStringData); var newEntrancesStringData = GetSlotSetting(MODIFIED_ENTRANCES_KEY, ""); diff --git a/StardewArchipelago/ModEntry.cs b/StardewArchipelago/ModEntry.cs index 984e428c6..4835103f9 100644 --- a/StardewArchipelago/ModEntry.cs +++ b/StardewArchipelago/ModEntry.cs @@ -65,7 +65,7 @@ public override void Entry(IModHelper helper) _helper = helper; _harmony = new Harmony(this.ModManifest.UniqueID); - _archipelago = new ArchipelagoClient(Monitor, _helper, _harmony, OnItemReceived); + _archipelago = new ArchipelagoClient(Monitor, _helper, _harmony, OnItemReceived, ModManifest); _helper.Events.GameLoop.GameLaunched += this.OnGameLaunched; _helper.Events.GameLoop.SaveCreating += this.OnSaveCreating; diff --git a/StardewArchipelago/manifest.json b/StardewArchipelago/manifest.json index 5429dbebf..bcc0a5321 100644 --- a/StardewArchipelago/manifest.json +++ b/StardewArchipelago/manifest.json @@ -1,7 +1,7 @@ { "Name": "StardewArchipelago", "Author": "Kaito Kid", - "Version": "2.2.1", + "Version": "2.2.2", "Description": "Stardew Valley Randomizer for Archipelago", "UniqueID": "KaitoKid.StardewArchipelago", "EntryDll": "StardewArchipelago.dll",