Skip to content

Commit

Permalink
Remove reliance on windows-kill to gracefully close the server
Browse files Browse the repository at this point in the history
  • Loading branch information
winglessraven committed Sep 4, 2020
1 parent 463c74d commit 8d46de4
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 39 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="windows-kill.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="zombie_4105.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
19 changes: 16 additions & 3 deletions Dead Matter Server Manager/Dead Matter Server Manager/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -43,6 +44,9 @@ public partial class Form1 : Form
private DateTime lastRestart;
private int killAttempts;

[DllImport("User32.dll")]
static extern int SetForegroundWindow(IntPtr point);

public Form1()
{
InitializeComponent();
Expand Down Expand Up @@ -654,8 +658,13 @@ await Task.Run(() =>
if ((Convert.ToDouble(memory) / 1024 / 1024 / 1024 > Convert.ToDouble(maxMem) && !killSent) || (restartServerTimeOption.Checked && restartTime == ((uptime.Hours * 60) + uptime.Minutes).ToString() && !killSent) || killSent && timeSinceLastKill.Minutes >= 1 && killAttempts <= 3)
{
int processID = dmServerShipping[0].Id;
Process.Start("windows-kill.exe", "-SIGINT " + processID);
//uptime = new TimeSpan(0, 0, 0);

Process p = Process.GetProcessById(processID);

IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
SendKeys.SendWait("^(c)");

killSent = true;
killAttempts += 1;
killCommandSentAt = DateTime.Now;
Expand Down Expand Up @@ -874,7 +883,11 @@ private void stopServer_Click(object sender, EventArgs e)
if (dmServer.Length != 0)
{
int processID = dmServer[0].Id;
Process.Start("windows-kill.exe", "-SIGINT " + processID);
Process p = Process.GetProcessById(processID);

IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
SendKeys.SendWait("^(c)");
}
serverStarted = false;
firstTimeServerStarted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.13.0")]
[assembly: AssemblyFileVersion("1.6.13.0")]
[assembly: AssemblyVersion("1.6.14.0")]
[assembly: AssemblyFileVersion("1.6.14.0")]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ C:\Users\Dave\Source\Repos\DeadMatterServerManager\Dead Matter Server Manager\De
C:\Users\Dave\Source\Repos\DeadMatterServerManager\Dead Matter Server Manager\Dead Matter Server Manager\obj\x64\Debug\Dead Matter Server Manager.exe
C:\Users\Dave\Source\Repos\DeadMatterServerManager\Dead Matter Server Manager\Dead Matter Server Manager\obj\x64\Debug\Dead Matter Server Manager.pdb
C:\Users\Dave\Source\Repos\DeadMatterServerManager\Dead Matter Server Manager\Dead Matter Server Manager\bin\x64\Debug\defaultEngine.txt
C:\Users\Dave\Source\Repos\DeadMatterServerManager\Dead Matter Server Manager\Dead Matter Server Manager\bin\x64\Debug\windows-kill.exe
C:\Users\Dave\Source\Repos\DeadMatterServerManager\Dead Matter Server Manager\Dead Matter Server Manager\obj\x64\Debug\Dead Matter Server Manager.csprojAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
}
"Entry"
{
"MsmKey" = "8:_832B6CC763924BF2AE42191B0C8F1F89"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_884AA8BE0C34A4448A660EDFEC8B34EF"
"OwnerKey" = "8:_262D2683AA2142C289BFC824DDFCD381"
"MsmSig" = "8:_UNDEFINED"
Expand Down Expand Up @@ -287,26 +281,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_832B6CC763924BF2AE42191B0C8F1F89"
{
"SourcePath" = "8:..\\Dead Matter Server Manager\\windows-kill.exe"
"TargetName" = "8:windows-kill.exe"
"Tag" = "8:"
"Folder" = "8:_12EB296AC619417D8A628C01638EB039"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_884AA8BE0C34A4448A660EDFEC8B34EF"
{
"AssemblyRegister" = "3:1"
Expand Down Expand Up @@ -529,15 +503,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:Dead Matter Server Manager"
"ProductCode" = "8:{EDFCAA39-1F4E-4966-96CF-6061F15E0523}"
"PackageCode" = "8:{B92DE7C4-74A1-4F65-8ACD-3EAFEB0034E6}"
"ProductCode" = "8:{ECCEDDD5-6E51-4D29-9009-03A7F2E69EC8}"
"PackageCode" = "8:{0C1CBCDC-CF07-4272-9F6E-53FC71DE26F0}"
"UpgradeCode" = "8:{BC345328-E944-4F2F-9559-E95043070B11}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.6.13"
"ProductVersion" = "8:1.6.14"
"Manufacturer" = "8:winglessraven"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down
Binary file not shown.

0 comments on commit 8d46de4

Please sign in to comment.