From a1dc3dfc9be71d2cf0338fcacaeb6e43197526a2 Mon Sep 17 00:00:00 2001 From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com> Date: Mon, 10 May 2021 17:08:43 -0500 Subject: [PATCH 1/7] Re-add auto updater for legacy users --- SeamlessClient.cs | 31 ++++ SeamlessClientPlugin.csproj | 1 + Utilities/UpdateChecker.cs | 315 ++++++++++++++++++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 Utilities/UpdateChecker.cs diff --git a/SeamlessClient.cs b/SeamlessClient.cs index d416d18..1a29e6f 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -122,6 +122,12 @@ namespace SeamlessClientPlugin public void Init(object gameInstance) { + Utilities.UpdateChecker Checker = new Utilities.UpdateChecker(false); + Task UpdateChecker = new Task(() => Checker.PingUpdateServer()); + UpdateChecker.Start(); + + + Patches.GetPatches(); TryShow("Running Seamless Client Plugin v[" + Version + "]"); PingTimer.Elapsed += PingTimer_Elapsed; @@ -207,6 +213,31 @@ namespace SeamlessClientPlugin } + public static void RestartClientAfterUpdate() + { + try + { + TryShow("Restarting Client!"); + string exe = Assembly.GetEntryAssembly().Location; + Process currentProcess = Process.GetCurrentProcess(); + + string[] CommandArgs = Environment.GetCommandLineArgs(); + string NewCommandLine = ""; + for (int i = 1; i < CommandArgs.Length; i++) + { + NewCommandLine += " " + CommandArgs[i]; + } + + TryShow(NewCommandLine); + Process.Start(exe, NewCommandLine); + currentProcess.Kill(); + } + catch (Exception ex) + { + TryShow("Restarting Client error!"); + } + } + public static void TryShow(string message) { if (MySession.Static?.LocalHumanPlayer != null && Debug) diff --git a/SeamlessClientPlugin.csproj b/SeamlessClientPlugin.csproj index 0f70936..1a3d93f 100644 --- a/SeamlessClientPlugin.csproj +++ b/SeamlessClientPlugin.csproj @@ -166,6 +166,7 @@ + diff --git a/Utilities/UpdateChecker.cs b/Utilities/UpdateChecker.cs new file mode 100644 index 0000000..7cdc29f --- /dev/null +++ b/Utilities/UpdateChecker.cs @@ -0,0 +1,315 @@ +using ProtoBuf; +using Sandbox.Graphics.GUI; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Reflection; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Serialization; +namespace SeamlessClientPlugin.Utilities +{ + public class UpdateChecker + { + public string PluginFolder; + public string CurrentVersion; + public bool DownloadUpdate; + private string GitHubAPILink = "https://api.github.com/repos/Casimir255/SeamlessClientPlugin/releases/latest"; + + private WebClient Client; + + + + + public UpdateChecker(bool AutoUpdate) + { + PluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + Client = new WebClient(); + DeleteOLDFiles(); + } + + + + + public void PingUpdateServer() + { + try + { + //Create new webclient and insert a user-agent + Client.Headers["User-Agent"] = "SeamlessClientUpdater"; + + //Grap API data for latest seamless client release + string data = Client.DownloadString(GitHubAPILink); + + //SeamlessClient.TryShow(data); + + + DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(GithubRelease)); + + GithubRelease Release; + using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) + { + Release = (GithubRelease)s.ReadObject(stream); + } + + + if (Release == null || !TryGetMainRelease(Release.Content, out GitZipFile MainReleaseFile)) + return; + + + //Check if the client needs an update based off of github latest release version + + if (!NeedsUpdate(SeamlessClient.Version, Release.LatestVersion)) + return; + + + //Ask client if they want to update! + ShowDialog(Release, MainReleaseFile); + } + catch (Exception Ex) + { + SeamlessClient.TryShow(Ex.ToString()); + } + } + + + private bool TryGetMainRelease(GitZipFile[] Files, out GitZipFile Release) + { + Release = null; + + //Sanity saftey checks + if (Files == null || Files.Length <= 0) + return false; + + foreach (GitZipFile File in Files) + { + if (File.Name == "SeamlessClientPlugin.zip") + { + Release = File; + return true; + } + + } + + return false; + } + + + private void ShowDialog(GithubRelease Release, GitZipFile MainReleaseFile) + { + StringBuilder Response = new StringBuilder(); + Response.AppendLine($"Current version: {SeamlessClient.Version} Latest: {Release.LatestVersion}"); + Response.AppendLine($"Update: {Release.Name}"); + Response.AppendLine($"Description: {Release.Description}"); + Response.AppendLine($"Size: {MainReleaseFile.Size / 1000}kb"); + Response.AppendLine(); + Response.AppendLine("Warning: If you have a version less than latest seamless will be disabled to prevent crashes!"); + Response.AppendLine("(Clicking yes should restart your game)"); + + DialogResult Result = MessageBox.Show(Response.ToString(), $"Download Seamless Client Plugin Update v{ Release.LatestVersion}?", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); + SeamlessClient.TryShow(Response.ToString()); + + if (Result == DialogResult.Yes) + { + SeamlessClient.TryShow("Client wants to update!"); + string DownloadPath = Path.Combine(PluginFolder, MainReleaseFile.Name); + Client.DownloadFile(new Uri(MainReleaseFile.ZipURL), DownloadPath); + + if (!File.Exists(DownloadPath)) + { + SeamlessClient.TryShow("Failed to download zip!"); + return; + } + + if (ExtractAndReplace(DownloadPath)) + { + StringBuilder ErrorResponse = new StringBuilder(); + ErrorResponse.AppendLine("There was an error during the extraction proccess! Check your logs for more information!"); + ErrorResponse.AppendLine(); + ErrorResponse.AppendLine("You can download manually here:"); + ErrorResponse.AppendLine(Release.GitHubPage); + SeamlessClient.TryShow(ErrorResponse.ToString()); + MessageBox.Show(ErrorResponse.ToString(), $"Failed to update plugin to v{ Release.LatestVersion}!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); + return; + } + + } + else + { + SeamlessClient.TryShow("Client skipped Update!"); + return; + } + + + + + } + + + + + + private void DeleteOLDFiles() + { + foreach (var OLDFile in Directory.GetFiles(PluginFolder, "*.old")) + { + File.Delete(OLDFile); + } + + SeamlessClient.TryShow("Deleted all OLD update files"); + + } + + + private bool ExtractAndReplace(string ZipPath) + { + try + { + + //Start extractor + using (ZipArchive archive = ZipFile.OpenRead(ZipPath)) + { + foreach (ZipArchiveEntry entry in archive.Entries) + { + string ExsistingFilePath = Path.Combine(PluginFolder, entry.Name); + string OldFilePath = Path.Combine(PluginFolder, entry.Name + ".old"); + + //No need to extract to files that dont exsist + if (!File.Exists(ExsistingFilePath)) + continue; + + SeamlessClient.TryShow(ExsistingFilePath + "=>" + OldFilePath); + + if (File.Exists(OldFilePath)) + File.Delete(OldFilePath); + + File.Move(ExsistingFilePath, OldFilePath); + entry.ExtractToFile(ExsistingFilePath, false); + //File.Delete(OldFilePath); + } + } + + //Delete latest zip + File.Delete(ZipPath); + + //Restart client + SeamlessClient.TryShow("UpdateComplete!"); + SeamlessClient.RestartClientAfterUpdate(); + return true; + + } + catch (Exception ex) + { + SeamlessClient.TryShow(ex.ToString()); + return false; + } + } + + private bool NeedsUpdate(string ClientVersion, string ServerVersion) + { + + + Version Client = new Version(ClientVersion); + Version Latest = new Version(ServerVersion); + + var result = Client.CompareTo(Latest); + if (result > 0) + { + //Console.WriteLine("Client is greater"); + SeamlessClient.TryShow("Client version is greater than latest! Wow!"); + return false; + } + else if (result < 0) + { + //Console.WriteLine("Latest is greater"); + SeamlessClient.TryShow("Client version is out-of-date!"); + return true; + } + else + { + //Console.WriteLine("versions are equal"); + SeamlessClient.TryShow("Client is up-to-date!"); + return false; + } + } + + } + + + [ProtoContract] + public class UpdateMessage + { + [ProtoMember(10)] + public string ClientVersion = ""; + + [ProtoMember(20)] + public bool UpToDate = false; + + [ProtoMember(30)] + public bool DownloadNewUpdate = false; + + [ProtoMember(40)] + public string ServerVersion = ""; + + [ProtoMember(50)] + public string UpdateNotes = ""; + + + + /* Misc Stuff incase I need it */ + [ProtoMember(60)] + public byte[] XmlCharactersAsBytes; + + + public UpdateMessage() { } + + + } + + + [DataContract] + public class GithubRelease + { + + [DataMember(Name = "url")] + public string GitHubPage { get; set; } + + [DataMember(Name = "name")] + public string Name { get; set; } + + + [DataMember(Name = "tag_name")] + public string LatestVersion { get; set; } + + [DataMember(Name = "prerelease")] + public bool Beta { get; set; } + + [DataMember(Name = "body")] + public string Description { get; set; } + + [DataMember(Name = "assets")] + public GitZipFile[] Content { get; set; } + + } + + [DataContract] + public class GitZipFile + { + [DataMember(Name = "name")] + public string Name { get; set; } + + [DataMember(Name = "browser_download_url")] + public string ZipURL { get; set; } + + [DataMember(Name = "size")] + public int Size { get; set; } + + } +} From 16eccf9c5ee6ab766c5f4df246f1e29c3f1b9c92 Mon Sep 17 00:00:00 2001 From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com> Date: Mon, 10 May 2021 17:10:27 -0500 Subject: [PATCH 2/7] Update version --- SeamlessClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SeamlessClient.cs b/SeamlessClient.cs index 1a29e6f..90cd149 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -106,7 +106,7 @@ namespace SeamlessClientPlugin - public static string Version = "1.2.12"; + public static string Version = "1.2.20"; public static bool Debug = false; private static bool Initilized = false; From 3352583e5df371dcde10d3ca278f1e8e7c8d9bee Mon Sep 17 00:00:00 2001 From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com> Date: Mon, 10 May 2021 18:13:33 -0500 Subject: [PATCH 3/7] Fixed online players --- SeamlessClient.cs | 2 +- SeamlessTransfer/SwitchServers.cs | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/SeamlessClient.cs b/SeamlessClient.cs index 90cd149..1a29e6f 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -106,7 +106,7 @@ namespace SeamlessClientPlugin - public static string Version = "1.2.20"; + public static string Version = "1.2.12"; public static bool Debug = false; private static bool Initilized = false; diff --git a/SeamlessTransfer/SwitchServers.cs b/SeamlessTransfer/SwitchServers.cs index ec11521..7f3ee6d 100644 --- a/SeamlessTransfer/SwitchServers.cs +++ b/SeamlessTransfer/SwitchServers.cs @@ -7,6 +7,7 @@ using Sandbox.Game.Gui; using Sandbox.Game.GUI; using Sandbox.Game.Multiplayer; using Sandbox.Game.World; +using Sandbox.ModAPI; using SeamlessClientPlugin.Utilities; using System; using System.Collections.Concurrent; @@ -98,7 +99,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer RemoveOldEntities(); StartEntitySync(); - + MyModAPIHelper.Initialize(); // Allow the game to start proccessing incoming messages in the buffer MyMultiplayer.Static.StartProcessingClientMessages(); } @@ -107,12 +108,19 @@ namespace SeamlessClientPlugin.SeamlessTransfer private void LoadOnlinePlayers() { //Get This players ID + MyPlayer.PlayerId? savingPlayerId = new MyPlayer.PlayerId(Sync.MyId); if (!savingPlayerId.HasValue) { SeamlessClient.TryShow("SavingPlayerID is null! Creating Default!"); savingPlayerId = new MyPlayer.PlayerId(Sync.MyId); } + SeamlessClient.TryShow("Saving PlayerID: " + savingPlayerId.ToString()); + + Sync.Players.LoadConnectedPlayers(TargetWorld.Checkpoint, savingPlayerId); + Sync.Players.LoadControlledEntities(TargetWorld.Checkpoint.ControlledEntities, TargetWorld.Checkpoint.ControlledObject, savingPlayerId); + /* + SeamlessClient.TryShow("Saving PlayerID: " + savingPlayerId.ToString()); @@ -145,6 +153,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer } } + */ + } private void SetWorldSettings() @@ -169,7 +179,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer MySession.Static.WorldBoundaries = TargetWorld.Checkpoint.WorldBoundaries; MySession.Static.InGameTime = MyObjectBuilder_Checkpoint.DEFAULT_DATE; MySession.Static.ElapsedGameTime = new TimeSpan(TargetWorld.Checkpoint.ElapsedGameTime); - + MySession.Static.Settings.EnableSpectator = false; MySession.Static.Password = TargetWorld.Checkpoint.Password; @@ -248,16 +258,23 @@ namespace SeamlessClientPlugin.SeamlessTransfer private void LoadConnectedClients() { + + + Patches.LoadMembersFromWorld.Invoke(MySession.Static, new object[] { TargetWorld, MyMultiplayer.Static }); + + //Re-Initilize Virtual clients object VirtualClientsValue = Patches.VirtualClients.GetValue(MySession.Static); Patches.InitVirtualClients.Invoke(VirtualClientsValue, null); + /* SeamlessClient.TryShow("Loading exsisting Members From World!"); foreach (var Client in TargetWorld.Checkpoint.Clients) { SeamlessClient.TryShow("Adding New Client: " + Client.Name); Sync.Clients.AddClient(Client.SteamId, Client.Name); - } + }*/ + } private void StartEntitySync() @@ -302,7 +319,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer //Clear all old players and clients. Sync.Clients.Clear(); Sync.Players.ClearPlayers(); - + MyHud.Chat.UnregisterChat(MyMultiplayer.Static); MySession.Static.Gpss.RemovePlayerGpss(MySession.Static.LocalPlayerId); From cf738384c450b5022230fc785896f23c9420cd25 Mon Sep 17 00:00:00 2001 From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com> Date: Mon, 10 May 2021 18:13:54 -0500 Subject: [PATCH 4/7] Updated Version --- SeamlessClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SeamlessClient.cs b/SeamlessClient.cs index 1a29e6f..90cd149 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -106,7 +106,7 @@ namespace SeamlessClientPlugin - public static string Version = "1.2.12"; + public static string Version = "1.2.20"; public static bool Debug = false; private static bool Initilized = false; From bb8387d8b9aaa7ad0c6c4bcf04f1e1ddee4a9508 Mon Sep 17 00:00:00 2001 From: Bob Da Ross <52760019+BobDaRoss@users.noreply.github.com> Date: Mon, 10 May 2021 18:16:19 -0500 Subject: [PATCH 5/7] fixed crash --- SeamlessClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SeamlessClient.cs b/SeamlessClient.cs index 90cd149..5120032 100644 --- a/SeamlessClient.cs +++ b/SeamlessClient.cs @@ -188,7 +188,7 @@ namespace SeamlessClientPlugin public static void DisposeInitilizations() { PingTimer.Stop(); - MyAPIGateway.Multiplayer.UnregisterSecureMessageHandler(SeamlessClientNetID, MessageHandler); + MyAPIGateway.Multiplayer?.UnregisterSecureMessageHandler(SeamlessClientNetID, MessageHandler); Initilized = false; } From ce7ef352bec588ceb0cde968ea1b2d8a51404f59 Mon Sep 17 00:00:00 2001 From: Garrett <52760019+Casimir255@users.noreply.github.com> Date: Mon, 10 May 2021 18:20:35 -0500 Subject: [PATCH 6/7] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. From 16bab75888cfc2acd5e0e9aa3e1ff72b8fe54572 Mon Sep 17 00:00:00 2001 From: Garrett <52760019+Casimir255@users.noreply.github.com> Date: Mon, 10 May 2021 18:21:45 -0500 Subject: [PATCH 7/7] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..3af8e6e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -23,16 +23,6 @@ A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] **Additional context** Add any other context about the problem here.