Skip to content

Commit

Permalink
Ver 0.2.0-A1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Jul 11, 2023
1 parent 721c4e2 commit d277d45
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 14 deletions.
51 changes: 42 additions & 9 deletions Serein/Universal/Core/Server/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ internal static class ServerManager
public static readonly List<string> CommandHistory = new();

public static string? JEOptimizationArguments { get; set; }
public static string? JEStartMaxRam { get; set; }
public static string? JEStartMaxRam { get; set; }
public static string? JavaVersion { get; set; }
public static int? JavaVersionNumber { get; set; }
public static bool AbleToUse_incubator_vector { get; set;}
public static string? Use_incubator_vector {get; set;}

/// <summary>
/// 编码列表
Expand Down Expand Up @@ -162,24 +166,53 @@ public static bool Start(bool quiet)
Logger.Output(LogType.Server_Clear);
#endif
Logger.Output(LogType.Server_Notice, "启动中");

string ServerType = Global.Settings.Server.Path.Substring(Global.Settings.Server.Path.Length - 3);
if(Global.Settings.Server.MaxRAM != null)
if(Global.Settings.Server.MaxRAM == null || Global.Settings.Server.MaxRAM == "")
{
ServerManager.JEStartMaxRam = Global.Settings.Server.MaxRAM;
Logger.MsgBox("最大内存为空", "Serein", 0, 48);
return false;
}
else
{
ServerManager.JEStartMaxRam = "2048";
JEStartMaxRam = Global.Settings.Server.MaxRAM;
}

try
{
ProcessStartInfo defaultJava = new ProcessStartInfo();
defaultJava.FileName = "java.exe";
defaultJava.Arguments = " -version";
defaultJava.RedirectStandardError = true;
defaultJava.UseShellExecute = false;
defaultJava.CreateNoWindow = true;

Process pr = Process.Start(defaultJava);
JavaVersion = pr.StandardError.ReadLine().Split(' ')[2].Replace("\"", "");
JavaVersionNumber = int.Parse(JavaVersion.Substring(0, 2));

}
catch (Exception ex)
{
Console.WriteLine("Exception is " + ex.Message);
}
if(JavaVersionNumber == 16 || JavaVersionNumber == 17 || JavaVersionNumber == 18 || JavaVersionNumber == 19)
{
AbleToUse_incubator_vector = true;
Use_incubator_vector = " --add-modules=jdk.incubator.vector";
}
else
{
Use_incubator_vector = "";
}

#region 主变量初始化
if (ServerType == "jar")
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
float AvailableRAM = ramCounter.NextValue();
if(AvailableRAM >= 12288)
{
ServerManager.JEOptimizationArguments = "--add-modules=jdk.incubator.vector -XX:+UseG1GC " +
JEOptimizationArguments = Use_incubator_vector + " -XX:+UseG1GC " +
"-XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions " +
"-XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 " +
"-XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 " +
Expand All @@ -188,7 +221,7 @@ public static bool Start(bool quiet)
}
else
{
ServerManager.JEOptimizationArguments = "--add-modules=jdk.incubator.vector -XX:+UseG1GC " +
JEOptimizationArguments = Use_incubator_vector + " -XX:+UseG1GC " +
"-XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions " +
"-XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 " +
"-XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 " +
Expand All @@ -199,7 +232,7 @@ public static bool Start(bool quiet)
{

FileName = "java",
Arguments = " -jar -Xmx" + JEStartMaxRam + "M " + ServerManager.JEOptimizationArguments + Global.Settings.Server.Path + " --nogui",
Arguments = " -jar -Xmx" + JEStartMaxRam + "M " + JEOptimizationArguments + Global.Settings.Server.Path + " --nogui",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
Expand All @@ -224,7 +257,7 @@ public static bool Start(bool quiet)
};
StartInfo = ServerStartInfo;
}

_serverProcess = Process.Start(StartInfo);
_serverProcess!.EnableRaisingEvents = true;
_serverProcess.Exited += (_, _) => CloseAll();
Expand Down
2 changes: 1 addition & 1 deletion Serein/Universal/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class Global
/// <summary>
/// 版本号
/// </summary>
public const string VERSION = "v0.0.1-A1";
public const string VERSION = "v0.2.0-A1";

/// <summary>
/// 类型
Expand Down
2 changes: 1 addition & 1 deletion Serein/Universal/Settings/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class Server

public string[] StopCommands = { "stop" };

public int Type = 1;
public int Type = 2;

public string MaxRAM;
}
Expand Down
2 changes: 1 addition & 1 deletion Serein/WPF/Serein-WPF.csproj.user
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugFramework>net472</ActiveDebugFramework>
<ActiveDebugFramework>net6.0-windows</ActiveDebugFramework>
</PropertyGroup>
<ItemGroup>
<Compile Update="Windows\Pages\Debug.xaml.cs">
Expand Down
10 changes: 10 additions & 0 deletions Serein/WPF/Windows/Pages/Server/Panel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel>
<Label Content="状态" DockPanel.Dock="Left" />
Expand Down Expand Up @@ -90,6 +91,15 @@
-
</Label>
</DockPanel>
<DockPanel Grid.Row="6">
<Label Content="Java版本" DockPanel.Dock="Left" />
<Label
Name="JavaVersion"
DockPanel.Dock="Left"
FlowDirection="RightToLeft">
-
</Label>
</DockPanel>
</Grid>
</GroupBox>
<GroupBox
Expand Down
3 changes: 2 additions & 1 deletion Serein/WPF/Windows/Pages/Server/Panel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class Panel : UiPage
public Panel()
{
InitializeComponent();

MaxRAM.Text = Global.Settings.Server.MaxRAM;
_updateInfoTimer.Elapsed += (_, _) => UpdateInfos();
_updateInfoTimer.Start();
PanelRichTextBox.Document.Blocks.Clear();
Expand Down Expand Up @@ -124,6 +124,7 @@ private void UpdateInfos()
Time.Content = ServerManager.Status ? ServerManager.Time : "-";
CPUPerc.Content = ServerManager.Status ? "%" + ServerManager.CPUUsage.ToString("N1") : "-";
Catalog.MainWindow?.UpdateTitle(ServerManager.Status ? ServerManager.StartFileName : null);
});
}
}
2 changes: 1 addition & 1 deletion Serein/WPF/Windows/Pages/Settings/Server.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<ComboBox
Name="Type"
HorizontalAlignment="Left"
SelectedIndex="1"
SelectedIndex="2"
SelectionChanged="Type_SelectionChanged">
<ComboBoxItem Content="未知/其他" ToolTip="不指定任何类型(将禁用Motd获取)" />
<ComboBoxItem Content="基岩版" ToolTip="Minecraft: Bedrock Edition" />
Expand Down
1 change: 1 addition & 0 deletions Serein/WPF/Windows/Pages/Settings/Server.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private void Load()
Path.Text = Global.Settings.Server.Path;
Port.Value = Global.Settings.Server.Port;
LineTerminator.Text = Global.Settings.Server.LineTerminator.Replace("\r", "\\r").Replace("\n", "\\n");

}

private void StopCommands_TextChanged(object sender, TextChangedEventArgs e)
Expand Down

0 comments on commit d277d45

Please sign in to comment.