diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index 61bb9fe4a..4938bb4e7 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -12,6 +12,9 @@ using System.Reflection; using GameAnalyticsSDK.Net; using System.Threading; using System.IO; +using RestSharp; +using System.Net; +using System.Xml.Linq; namespace Barotrauma { @@ -23,7 +26,13 @@ namespace Barotrauma public static FrameCounter FrameCounter; public static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version; - + + public static string SteamVersionUrl + { + get; + private set; + } + public static GameScreen GameScreen; public static MainMenuScreen MainMenuScreen; public static LobbyScreen LobbyScreen; @@ -549,6 +558,63 @@ namespace Barotrauma } } + + public void CheckSteamReleaseStatus() + { + CoroutineManager.StartCoroutine(WaitForVersionInfo()); + } + + IEnumerable WaitForVersionInfo() + { + var client = new RestClient(Config.MasterServerUrl); + var request = new RestRequest("versioninfo.xml", Method.GET); + IRestResponse response = null; + client.ExecuteAsync(request, + (receivedResponse) => + { + response = receivedResponse; + if (response.StatusCode != HttpStatusCode.OK) { return; } + + string xml = response.Content; + XDocument doc = null; + try + { + doc = XDocument.Parse(xml); + } + + catch + { + int index = xml.IndexOf('<'); + xml = xml.Substring(index, xml.Length - index); + doc = XDocument.Parse(xml); + } + if (doc?.Root != null) + { + SteamVersionUrl = doc.Root.GetAttributeString("steamversionurl", ""); + } + }); + while (response == null) + { + yield return CoroutineStatus.Running; + } + + if (!string.IsNullOrEmpty(SteamVersionUrl)) + { + var msgBox = new GUIMessageBox("", + "This version of Barotrauma is no longer supported. You can get the latest version of Barotrauma on Steam. Do you want to open Barotrauma's Steam page on your web browser?", + new string[] { "Yes", "No" }); + msgBox.Buttons[0].OnClicked = (btn, userdata) => + { + Process.Start(SteamVersionUrl); + return true; + }; + msgBox.Buttons[0].OnClicked += msgBox.Close; + msgBox.Buttons[1].OnClicked += msgBox.Close; + } + + yield return CoroutineStatus.Success; + } + static bool waitForKeyHit = true; public CoroutineHandle ShowLoading(IEnumerable loader, bool waitKeyHit = true) { diff --git a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs index 04a119090..e2c451b7e 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs @@ -276,7 +276,7 @@ namespace Barotrauma if (client == null) yield return CoroutineStatus.Success; - var request = new RestRequest("masterserver2.php", Method.GET); + var request = new RestRequest("masterserver8.php", Method.GET); request.AddParameter("gamename", "barotrauma"); request.AddParameter("action", "listservers"); @@ -291,7 +291,16 @@ namespace Barotrauma { serverList.ClearChildren(); restRequestHandle.Abort(); - new GUIMessageBox(TextManager.Get("MasterServerErrorLabel"), TextManager.Get("MasterServerTimeOutError")); + if (string.IsNullOrEmpty(GameMain.SteamVersionUrl)) + { + //Steam version is out and could not reach the master server + // -> assume legacy master server has been deprecated + new GUIMessageBox(TextManager.Get("MasterServerErrorLabel"), TextManager.Get("MasterServerTimeOutError")); + } + else + { + ShowMasterServerDeprecatedMessage(); + } yield return CoroutineStatus.Success; } yield return CoroutineStatus.Running; @@ -302,6 +311,7 @@ namespace Barotrauma serverList.ClearChildren(); new GUIMessageBox(TextManager.Get("MasterServerErrorLabel"), TextManager.Get("MasterServerErrorException").Replace("[error]", masterServerResponse.ErrorException.ToString())); } + else if (masterServerResponse.StatusCode != System.Net.HttpStatusCode.OK) { serverList.ClearChildren(); @@ -309,11 +319,20 @@ namespace Barotrauma switch (masterServerResponse.StatusCode) { case System.Net.HttpStatusCode.NotFound: - new GUIMessageBox(TextManager.Get("MasterServerErrorLabel"), - TextManager.Get("MasterServerError404") - .Replace("[masterserverurl]", NetConfig.MasterServerUrl) - .Replace("[statuscode]", masterServerResponse.StatusCode.ToString()) - .Replace("[statusdescription]", masterServerResponse.StatusDescription)); + //Steam version is out and server file wasn't found on the legacy master server + // -> assume legacy master server has been deprecated + if (string.IsNullOrEmpty(GameMain.SteamVersionUrl)) + { + new GUIMessageBox(TextManager.Get("MasterServerErrorLabel"), + TextManager.Get("MasterServerError404") + .Replace("[masterserverurl]", NetConfig.MasterServerUrl) + .Replace("[statuscode]", masterServerResponse.StatusCode.ToString()) + .Replace("[statusdescription]", masterServerResponse.StatusDescription)); + } + else + { + ShowMasterServerDeprecatedMessage(); + } break; case System.Net.HttpStatusCode.ServiceUnavailable: new GUIMessageBox(TextManager.Get("MasterServerErrorLabel"), @@ -338,7 +357,18 @@ namespace Barotrauma } yield return CoroutineStatus.Success; + } + private void ShowMasterServerDeprecatedMessage() + { + serverList.ClearChildren(); + new GUITextBlock(new Rectangle(0, 0, (int)(serverList.Rect.Width * 0.8f), (int)(serverList.Rect.Height * 0.8f)), + "This version of Barotrauma is no longer supported and the legacy server list is no longer available.", + alignment: Alignment.Center, textAlignment: Alignment.Center, + style: "", parent: serverList, wrap: true) + { + CanBeFocused = false + }; } private void MasterServerCallBack(IRestResponse response)