Skip to content

Commit

Permalink
Merge pull request #4 from Shiroiame-Kusu/preview
Browse files Browse the repository at this point in the history
Ver 0.12.0-A1: Okay, Okay.
  • Loading branch information
Shiroiame-Kusu authored Feb 4, 2024
2 parents 1e267d1 + 31ef8fe commit 9284f11
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 156 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion Serein/Universal/Base/Motd/Motdje.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal override void Get()

MotdjePacket.Packet packet = JsonConvert.DeserializeObject<MotdjePacket.Packet>(Origin) ?? throw new ArgumentNullException();
JObject PacketData = JObject.Parse(Origin);
PlayerListData = PacketData["players"].ToObject<JObject>();
PlayerListData = PacketData["players"]?.ToObject<JObject>();
IsSuccessful = true;
OnlinePlayer = packet.Players.Online;
MaxPlayer = packet.Players.Max;
Expand Down
48 changes: 24 additions & 24 deletions Serein/Universal/Core/Server/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using RegExp = System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Documents;
using System.Windows.Controls;
using RegExp = System.Text.RegularExpressions;

namespace Serein.Core.Server
{
Expand Down Expand Up @@ -97,8 +95,8 @@ internal static class ServerManager
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;}
public static bool AbleToUse_incubator_vector { get; set; }
public static string? Use_incubator_vector { get; set; }
public static bool? StartResult;

/// <summary>
Expand Down Expand Up @@ -169,28 +167,29 @@ 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(string.IsNullOrEmpty(Global.Settings.Server.MaxRAM))
{
if (string.IsNullOrEmpty(Global.Settings.Server.MaxRAM))
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
float AvailableRAM = ramCounter.NextValue();
double AutoSetRAM = Math.Round(AvailableRAM * 0.8, 0);
Global.Settings.Server.MaxRAM = AutoSetRAM.ToString();
JEStartMaxRam = Global.Settings.Server.MaxRAM;
Logger.MsgBox("未设置最大内存\n已自动为您设置启动内存为 " + JEStartMaxRam + "M", "Serein", 0, 48);

}
else
{
JEStartMaxRam = Global.Settings.Server.MaxRAM;
}
string? JavaPathSettings = Global.Settings.Server.JavaPath;
if (string.IsNullOrEmpty(JavaPathSettings) == true){
if (string.IsNullOrEmpty(JavaPathSettings) == true)
{
CurrentJavaPath = "java";
}
else
{
{
CurrentJavaPath = Global.Settings.Server.JavaPath;
}
try
Expand All @@ -202,16 +201,16 @@ public static bool Start(bool quiet)
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));
Process? pr = Process.Start(defaultJava);
JavaVersion = pr?.StandardError?.ReadLine()?.Split(' ')[2].Replace("\"", "");
JavaVersionNumber = int.Parse(JavaVersion?.Substring(0, 2));

Check warning on line 206 in Serein/Universal/Core/Server/ServerManager.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

Check warning on line 206 in Serein/Universal/Core/Server/ServerManager.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

Check warning on line 206 in Serein/Universal/Core/Server/ServerManager.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

}
catch (Exception ex)
{
Console.WriteLine("Exception is " + ex.Message);
}
if(JavaVersionNumber == 16 || JavaVersionNumber == 17 || JavaVersionNumber == 18 || JavaVersionNumber == 19)
if (JavaVersionNumber == 16 || JavaVersionNumber == 17 || JavaVersionNumber == 18 || JavaVersionNumber == 19)
{
AbleToUse_incubator_vector = true;
Use_incubator_vector = " --add-modules=jdk.incubator.vector";
Expand All @@ -223,7 +222,7 @@ public static bool Start(bool quiet)

#region 主变量初始化
if (ServerType == "jar")
{
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
float AvailableRAM = ramCounter.NextValue();
if (Global.Settings.Server.AutoJVMOptimization)
Expand Down Expand Up @@ -251,7 +250,7 @@ public static bool Start(bool quiet)
{
JEOptimizationArguments = Use_incubator_vector;
}

ProcessStartInfo ServerStartInfo = new ProcessStartInfo(Global.Settings.Server.Path)
{

Expand Down Expand Up @@ -280,10 +279,10 @@ public static bool Start(bool quiet)
StandardOutputEncoding = _encodings[Global.Settings.Server.OutputEncoding],
WorkingDirectory = Path.GetDirectoryName(Global.Settings.Server.Path)
};

StartInfo = ServerStartInfo;
}

_serverProcess = Process.Start(StartInfo);
_serverProcess!.EnableRaisingEvents = true;
_serverProcess.Exited += (_, _) => CloseAll();
Expand All @@ -306,7 +305,8 @@ public static bool Start(bool quiet)
Difficulty = string.Empty;
_tempLine = string.Empty;
CommandHistory.Clear();
StartFileName = Path.GetFileName(Global.Settings.Server.Path);
//StartFileName = Path.GetFileName(Global.Settings.Server.Path);
StartFileName = ServerType == "jar" ? Path.GetFullPath(Global.Settings.Server.Path) : Path.GetFileName(Global.Settings.Server.Path);
_prevProcessCpuTime = TimeSpan.Zero;
#endregion

Expand All @@ -322,8 +322,8 @@ public static bool Start(bool quiet)
return false;
}
public static void MainProcess()
{
{

}
/// <summary>
/// 关闭服务器
Expand Down Expand Up @@ -677,7 +677,7 @@ public static void UpdateInfo()
/// <returns>运行时间</returns>
public static string Time => Status && _serverProcess is not null ? (DateTime.Now - _serverProcess.StartTime).ToCustomString() : string.Empty;

public static ProcessStartInfo StartInfo { get; private set; }
public static ProcessStartInfo? StartInfo { get; private set; }
public static string? CurrentJavaPath { get; private set; }

/// <summary>
Expand Down
7 changes: 3 additions & 4 deletions Serein/Universal/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ internal static class Global
/// <summary>
/// 版本号
/// </summary>
public const string VERSION = "v0.10.0-RC1";
public const string VERSION = "v0.12.0-A1";
//public static readonly string VERSION = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString();

/// <summary>
/// 分支
/// </summary>
public const string BRANCH = "ReleaseCandidate";


public const string BRANCH = "Preview";
//public static readonly Object[]? Shiroiame_Kusu = { };
/// <summary>
/// 类型
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Serein/Universal/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("0.10.0.1")]
[assembly: AssemblyFileVersion("0.10.0-RC1")]
[assembly: AssemblyVersion("0.12.0.0")]
[assembly: AssemblyFileVersion("0.12.0-A1")]
2 changes: 1 addition & 1 deletion Serein/Universal/Utils/CrashInterception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void ShowException(Exception e)
$"◦ 崩溃日志已保存在 {Path.Combine("logs", "crash", $"{DateTime.Now:yyyy-MM-dd}.log")}\n" +
$"◦ 反馈此问题可以帮助作者更好的改进Serein",
MainIcon = TaskDialogIcon.Error,
Footer = $"你可以<a href=\"https://github.com/Shiroiame-Kusu/Serein/issues/new?labels=%E2%9D%97+%E5%B4%A9%E6%BA%83&template=crush_report.yml&title=崩溃反馈+{e.GetType()}\">提交Issue</a>",
Footer = $"你可以<a href=\"https://github.com/Shiroiame-Kusu/Serein/issues/new?labels=%E2%9D%97+%E5%B4%A9%E6%BA%83&template=crash_report.yml&title=崩溃反馈+{e.GetType()}\">提交Issue</a>",
FooterIcon = TaskDialogIcon.Information,
EnableHyperlinks = true,
ExpandedInformation = exceptionMsg
Expand Down
10 changes: 7 additions & 3 deletions Serein/Universal/Utils/PropertyOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public ArrayList List
/// </summary>
/// <param name="fileName">要读写的properties文件名</param>
public PropertyOperation(string fileName)
{
PropertyOperator(fileName);
}
public void PropertyOperator(string fileName)
{
this.fileName = fileName;
this.Load(fileName);
Expand All @@ -27,7 +31,7 @@ public PropertyOperation(string fileName)
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
public override void Add(object key, object value)
public override void Add(object key, object? value)
{
base.Add(key, value);
list.Add(key);
Expand Down Expand Up @@ -62,7 +66,7 @@ private void Load(string filePath)
string bufLine = string.Empty;
bool hasSep;
bool precedingBackslash;
using (StreamReader sr = new StreamReader(filePath))
using (StreamReader? sr = new StreamReader(filePath))
{
while (sr.Peek() >= 0)
{
Expand Down Expand Up @@ -132,7 +136,7 @@ private void Load(string filePath)
/// <param name="filePath">要保存的文件的路径</param>
public void Save()
{
string filePath = this.fileName;
string? filePath = this.fileName;
if (File.Exists(filePath))
{
File.Delete(filePath);
Expand Down
6 changes: 3 additions & 3 deletions Serein/WPF/Windows/Pages/Function/Frp/Login.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Margin="20,0,20,10" Header="用户名" FontSize="12">
<TextBox Grid.Row="0" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="用户名" />
<TextBox Grid.Row="0" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="用户名" Name="Username"/>
</GroupBox>

<GroupBox Grid.Row="1" Margin="20,10" Header="密码" FontSize="12">
<TextBox Grid.Row="1" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="密码"/>
<TextBox Grid.Row="1" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="密码" Name="Password"/>
</GroupBox>

<ui:Button Grid.Row="2" Content="登录" Height="40" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ui:Button Grid.Row="2" Content="登录" Height="40" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" Name="_Login" Click="Login_Click"/>
</Grid>
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
Expand Down
46 changes: 45 additions & 1 deletion Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using Newtonsoft.Json.Linq;
using Serein.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -23,6 +27,7 @@ namespace Serein.Windows.Pages.Function.Frp
/// </summary>
public partial class Login : UiPage
{
private string? token { get; set; }
public Login()
{
InitializeComponent();
Expand All @@ -47,5 +52,44 @@ private void ForgetPassword_Navigate(object sender, RequestNavigateEventArgs e)
});
e.Handled = true;
}

private async void Login_Click(object sender, RoutedEventArgs e)
{
Username.IsEnabled = false;
Password.IsEnabled = false;
using var client = new HttpClient();
string username = Username.Text;
string password = Password.Text;
var result = await client.GetAsync("https://api.locyanfrp.cn/User/DoLogin?username=" + username + "&password=" + password);

if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
var result2 = result.Content.ReadAsStringAsync().ToString();
JObject? ParsedResult = JObject.Parse(result2);

Check warning on line 68 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'json' in 'JObject JObject.Parse(string json)'.

Check warning on line 68 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'json' in 'JObject JObject.Parse(string json)'.

Check warning on line 68 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'json' in 'JObject JObject.Parse(string json)'.

Check warning on line 68 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'json' in 'JObject JObject.Parse(string json)'.

Check warning on line 68 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'json' in 'JObject JObject.Parse(string json)'.
if(result.StatusCode.ToString() == "200")
{
if(ParsedResult["status"].ToString() == "0")

Check warning on line 71 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.

Check warning on line 71 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.

Check warning on line 71 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
{
token = ParsedResult["token"].ToString();

Check warning on line 73 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.

Check warning on line 73 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
}
else
{
Logger.MsgBox("Serein", ParsedResult["message"].ToString(), 0, 48);

Check warning on line 77 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
}
}
else
{
Logger.MsgBox("Serein", "请检查您的网络连接", 0, 48);
}
}
else
{
Username.IsEnabled = true;
Password.IsEnabled = true;
Logger.MsgBox("Serein", "你到底打没打用户名和密码", 0, 48);
}


}
}
}
8 changes: 4 additions & 4 deletions Serein/WPF/Windows/Pages/Server/Container.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public Container()
switch (ServerType)
{
case "jar":
Dispatcher.Invoke(() => { MinecraftProperties.Visibility = Visibility.Visible; }, System.Windows.Threading.DispatcherPriority.Background);
Dispatcher.Invoke(() => { PlayerList.Visibility = Visibility.Visible; }, System.Windows.Threading.DispatcherPriority.Background);
Dispatcher.InvokeAsync(() => { MinecraftProperties.Visibility = Visibility.Visible; }, System.Windows.Threading.DispatcherPriority.Background);
Dispatcher.InvokeAsync(() => { PlayerList.Visibility = Visibility.Visible; }, System.Windows.Threading.DispatcherPriority.Background);
break;
default:
Dispatcher.Invoke(() => { MinecraftProperties.Visibility = Visibility.Collapsed; }, System.Windows.Threading.DispatcherPriority.Background);
Dispatcher.Invoke(() => { PlayerList.Visibility = Visibility.Collapsed; }, System.Windows.Threading.DispatcherPriority.Background);
Dispatcher.InvokeAsync(() => { MinecraftProperties.Visibility = Visibility.Collapsed; }, System.Windows.Threading.DispatcherPriority.Background);
Dispatcher.InvokeAsync(() => { PlayerList.Visibility = Visibility.Collapsed; }, System.Windows.Threading.DispatcherPriority.Background);
break;
}
System.Threading.Thread.Sleep(500);
Expand Down
Loading

0 comments on commit 9284f11

Please sign in to comment.