From 6c4649fe3fc912d75bbe2799fc8ebc208056be24 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 26 Mar 2019 17:10:20 +0200 Subject: [PATCH] (4b1fa5c86) Fixed client-side console errors during campaign setup because the client tried to load save files that only exist server-side. Now the server sends the information needed for the campaign setup window in the CAMPAIGN_SETUP_INFO message. --- .../Source/Screens/CampaignSetupUI.cs | 49 +++++++++++++------ .../Source/Networking/GameServer.cs | 16 +++++- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs index fd030ef09..e36c3b0dc 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs @@ -266,10 +266,12 @@ namespace Barotrauma { OnSelected = SelectSaveFile }; - + foreach (string saveFile in saveFiles) { - XDocument doc = SaveUtil.LoadGameSessionDoc(saveFile); + string fileName = saveFile; + string subName = ""; + string saveTime = ""; var saveFrame = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.1f), saveList.Content.RectTransform), style: "ListBoxElement") { UserData = saveFile @@ -277,25 +279,38 @@ namespace Barotrauma var nameText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), saveFrame.RectTransform), text: Path.GetFileNameWithoutExtension(saveFile)); - if (doc?.Root == null) - { - DebugConsole.ThrowError("Error loading save file \"" + saveFile + "\". The file may be corrupted."); - nameText.Color = Color.Red; - continue; - } - string submarineName = doc.Root.GetAttributeString("submarine", ""); - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), saveFrame.RectTransform, Anchor.BottomLeft), - text: submarineName, font: GUI.SmallFont) + if (!isMultiplayer) { - UserData = saveFile + XDocument doc = SaveUtil.LoadGameSessionDoc(saveFile); + if (doc?.Root == null) + { + DebugConsole.ThrowError("Error loading save file \"" + saveFile + "\". The file may be corrupted."); + nameText.Color = Color.Red; + continue; + } + subName = doc.Root.GetAttributeString("submarine", ""); + saveTime = doc.Root.GetAttributeString("savetime", ""); + } + else + { + string[] splitSaveFile = saveFile.Split(';'); + saveFrame.UserData = splitSaveFile[0]; + fileName = nameText.Text = Path.GetFileNameWithoutExtension(splitSaveFile[0]); + if (splitSaveFile.Length > 1) { subName = splitSaveFile[1]; } + if (splitSaveFile.Length > 2) { saveTime = splitSaveFile[2]; } + } + + new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), saveFrame.RectTransform, Anchor.BottomLeft), + text: subName, font: GUI.SmallFont) + { + UserData = fileName }; - string saveTime = doc.Root.GetAttributeString("savetime", ""); new GUITextBlock(new RectTransform(new Vector2(1.0f, 1.0f), saveFrame.RectTransform), text: saveTime, textAlignment: Alignment.Right, font: GUI.SmallFont) { - UserData = saveFile + UserData = fileName }; } @@ -349,6 +364,12 @@ namespace Barotrauma private bool SelectSaveFile(GUIComponent component, object obj) { + if (isMultiplayer) + { + loadGameButton.Enabled = true; + return true; + } + string fileName = (string)obj; XDocument doc = SaveUtil.LoadGameSessionDoc(fileName); diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index 202c87097..b4e3bf3a9 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -10,6 +10,7 @@ using System.Text; using System.IO.Compression; using System.IO; using Barotrauma.Steam; +using System.Xml.Linq; namespace Barotrauma.Networking { @@ -1125,9 +1126,22 @@ namespace Barotrauma.Networking UInt16 modeIndex = inc.ReadUInt16(); if (GameMain.NetLobbyScreen.GameModes[modeIndex].Identifier.ToLowerInvariant() == "multiplayercampaign") { + string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer); + for (int i = 0; i < saveFiles.Length; i++) + { + XDocument doc = SaveUtil.LoadGameSessionDoc(saveFiles[i]); + if (doc?.Root != null) + { + saveFiles[i] = + string.Join(";", + saveFiles[i].Replace(';', ' '), + doc.Root.GetAttributeString("submarine", ""), + doc.Root.GetAttributeString("savetime", "")); + } + } + NetOutgoingMessage msg = server.CreateMessage(); msg.Write((byte)ServerPacketHeader.CAMPAIGN_SETUP_INFO); - string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer); msg.Write((UInt16)saveFiles.Count()); foreach (string saveFile in saveFiles) {