Skip to content

Commit

Permalink
Ver x.x.x: I'm boring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Sep 11, 2023
1 parent ec6dc9c commit 97d7939
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 74 deletions.
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
8 changes: 4 additions & 4 deletions Serein/Universal/Core/Server/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ 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 207 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 207 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)
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
6 changes: 3 additions & 3 deletions Serein/Universal/Utils/PropertyOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 +62,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 +132,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
62 changes: 23 additions & 39 deletions Serein/WPF/Windows/Pages/Server/Download.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using System.Threading;
using System.Windows.Threading;
using System.Timers;
using System.Collections.Generic;

namespace Serein.Windows.Pages.Server
{
Expand All @@ -42,21 +41,21 @@ public partial class Download : UiPage
public static string? DownloadAPI = "https://download.fastmirror.net/download/";
public static string? VersionAPI;
public static string? VersionAPIStatus;
public JObject VersionAPIDataPrase;
public JObject? VersionAPIDataPrase;
public static string? DetailedAPI;
public static string? DetailedAPIStatus;
public JObject DetailedAPIDataPrase;
public static int DownloadableServerNumber {get; set; }
public static int DownloadableServerVersion { get; set; }
public static string ServerPath;
public JObject? DetailedAPIDataPrase;
public static int? DownloadableServerNumber {get; set; }
public static int? DownloadableServerVersion { get; set; }
public static string? ServerPath;
private double b;

public string DownloadUnit { get; private set; }
public string? DownloadUnit { get; private set; }
public static int a { get; set;}
public string CurrentServerPath { get; private set; }
public string DownloadFileURL { get; private set; }
public static string ResponseStatus { get; private set; }
public static string ResponseData { get; private set; }
public string? CurrentServerPath { get; private set; }
public string? DownloadFileURL { get; private set; }
public static string? ResponseStatus { get; private set; }
public static string? ResponseData { get; private set; }

public static bool isDownloadFinished = true;

Expand Down Expand Up @@ -96,9 +95,9 @@ private async void ServerDownload(object sender, RoutedEventArgs e)
DownloadFileURL = DownloadAPI + ServerName + "/" + ServerVersion + "/" + ServerDownloadCoreVersion.SelectedItem;
}
}
catch (Exception ex)
catch
{
DownloadFileURL = DownloadAPI + ServerName + "/" + ServerVersion + "/" + DetailedAPIDataPrase["data"]["builds"][0]["core_version"];
DownloadFileURL = DownloadAPI + ServerName + "/" + ServerVersion + "/" + DetailedAPIDataPrase?["data"]?["builds"]?[0]?["core_version"];
}
var DownloadStatus = DownloadFile(DownloadFileURL, CurrentServerPath + "\\server.jar");
if (DownloadStatus == true)
Expand All @@ -122,7 +121,7 @@ private async void ServerDownload(object sender, RoutedEventArgs e)
{
DownloadButton.IsEnabled = true;
}
}catch(Exception ex)
}catch
{

}
Expand Down Expand Up @@ -157,13 +156,13 @@ private async void LoadAPIInfo()
}

VersionAPIDataPrase = JObject.Parse(VersionAPI);
DownloadableServerNumber = VersionAPIDataPrase["data"].Count();
DownloadableServerNumber = VersionAPIDataPrase?["data"]?.Count();
for(int i = 0; i < DownloadableServerNumber; i++)
{
ServerDownloadName.Items.Add(VersionAPIDataPrase["data"][i]["name"]);
ServerDownloadName.Items.Add(VersionAPIDataPrase?["data"]?[i]?["name"]);
}
}
catch(Exception ex){
catch{

}

Expand Down Expand Up @@ -208,31 +207,17 @@ private void ServerDownloadName_SelectionChanged(object sender, SelectionChanged
if (i >= 0)
{

DownloadableServerVersion = VersionAPIDataPrase["data"][i]["mc_versions"].Count();
DownloadableServerVersion = VersionAPIDataPrase?["data"]?[i]?["mc_versions"]?.Count();
}
else
{
i = 0;
DownloadableServerVersion = VersionAPIDataPrase["data"][i]["mc_versions"].Count();
DownloadableServerVersion = VersionAPIDataPrase?["data"]?[i]?["mc_versions"]?.Count();
}
for (int i2 = 0; i2 < DownloadableServerVersion; i2++)
{
ServerDownloadVersion.Items.Add(VersionAPIDataPrase["data"][i]["mc_versions"][i2]);
}
/*DownloadButton.IsEnabled = false;
var i = ServerDownloadName.SelectedIndex;
JObject APIDataPrase = JObject.Parse(APIResult);
DownloadableServerVersion = APIDataPrase["data"][i]["mc_versions"].Count();
ServerDownloadVersion.Items.Clear();
ServerDownloadCoreVersion.Items.Clear();
for (int i2 = 0;i2 < DownloadableServerVersion; i2++)
{
ServerDownloadVersion.Items.Add(APIDataPrase["data"][i]["mc_versions"][i2]);
ServerDownloadVersion.Items.Add(VersionAPIDataPrase?["data"]?[i]?["mc_versions"]?[i2]);
}
DownloadButton.IsEnabled = false;
CoreVersion.Visibility = Visibility.Collapsed;
ServerDownloadVersion.IsEnabled = true;*/
}

private async void ServerDownloadVersion_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -261,8 +246,7 @@ private async void ServerDownloadVersion_SelectionChanged(object sender, Selecti
DetailedAPIDataPrase = JObject.Parse(DetailedAPI);
DownloadButton.IsEnabled = true;
}
}catch(Exception ex)
{
}catch{

}
}
Expand All @@ -286,7 +270,7 @@ private void Refresh_Click(object sender, RoutedEventArgs e)
LoadAPIInfo();
}

private async void FetchDetail_Click(object sender, RoutedEventArgs e)
private void FetchDetail_Click(object sender, RoutedEventArgs e)
{
try
{
Expand All @@ -305,7 +289,7 @@ public bool DownloadFile(string URL, string filename)
try
{
isDownloadFinished = false;
HttpWebRequest Myrq = (HttpWebRequest)HttpWebRequest.Create(URL);
HttpWebRequest Myrq = (HttpWebRequest)WebRequest.Create(URL);
Myrq.Referer = "https://www.fastmirror.net/";
Myrq.Host = "download.fastmirror.net";
Myrq.Headers.Add("Origin", "https://www.fastmirror.net");
Expand Down Expand Up @@ -391,7 +375,7 @@ public static void DoEvents()
try { Dispatcher.PushFrame(frame); }
catch (InvalidOperationException) { }
}
private static object ExitFrames(object frame)
private static object? ExitFrames(object frame)
{
((DispatcherFrame)frame).Continue = false;
return null;
Expand Down
33 changes: 18 additions & 15 deletions Serein/WPF/Windows/Pages/Server/PlayerList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace Serein.Windows.Pages.Server
/// </summary>
public partial class PlayerList : UiPage
{
public static JObject? PlayerListData = Motd.PlayerListData;
public static JObject PlayerListData = Motd.PlayerListData;

Check warning on line 30 in Serein/WPF/Windows/Pages/Server/PlayerList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference assignment.
public static int CurrentSelectedIndex;
//public bool isPlayerListNotNull = true;
public List<Player> items { get; set; }
public List<Player>? items { get; set; }
public PlayerList()
{

Expand All @@ -55,7 +55,7 @@ private void refresh()
PlayerListData = Motd.PlayerListData;

Check warning on line 55 in Serein/WPF/Windows/Pages/Server/PlayerList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference assignment.

Check warning on line 55 in Serein/WPF/Windows/Pages/Server/PlayerList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference assignment.

Check warning on line 55 in Serein/WPF/Windows/Pages/Server/PlayerList.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference assignment.
try
{
PlayerListItems = PlayerListData["sample"].ToString();
PlayerListItems = PlayerListData?["sample"]?.ToString();
}
catch
{
Expand All @@ -66,10 +66,10 @@ private void refresh()
{
if (!string.IsNullOrEmpty(PlayerListItems))
{
for (int a = 0; a < PlayerListData["sample"].Count(); a++)
for (int a = 0; a < PlayerListData?["sample"]?.Count(); a++)
{
string? Username = PlayerListData["sample"][a]["name"].ToString();
string? UUID = PlayerListData["sample"][a]["id"].ToString();
string? Username = PlayerListData["sample"]?[a]?["name"]?.ToString();
string? UUID = PlayerListData["sample"]?[a]?["id"]?.ToString();

string UsernameFilter = Username + @"\[\/(.*?)\]";
string IPFilter = @"\[\/(.*?)\]";
Expand Down Expand Up @@ -137,7 +137,7 @@ private void GamemodeSurvival_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -152,7 +152,7 @@ private void GamemodeCreative_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -167,7 +167,7 @@ private void GamemodeAdventure_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -182,7 +182,7 @@ private void GamemodeSpectator_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -197,7 +197,7 @@ private void SetOperator_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -212,7 +212,7 @@ private void DeleteOperator_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -227,7 +227,7 @@ private void KickPlayer_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -242,7 +242,7 @@ private void BanPlayer_Click(object sender, RoutedEventArgs e)
string? username = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
//username = items[-1].Username;
}
catch
Expand All @@ -255,16 +255,19 @@ private void BanPlayer_Click(object sender, RoutedEventArgs e)
private void BanPlayerIP_Click(object sender, RoutedEventArgs e)
{
string? username = null;
string? IP = null;
try
{
username = items[CurrentSelectedIndex].Username;
username = items?[CurrentSelectedIndex].Username;
IP = items?[CurrentSelectedIndex].IP;
//username = items[-1].Username;
}
catch
{
return;
}
ServerManager.InputCommand("ipban " + username);
ServerManager.InputCommand("ipban " + IP);
}

private void PlayerListView_MouseDown(object sender, MouseButtonEventArgs e)
Expand Down
24 changes: 12 additions & 12 deletions Serein/WPF/Windows/Pages/Server/Properties.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Properties()
ReloadinBackground();
}
}
catch (Exception ex)
catch
{

}
Expand Down Expand Up @@ -244,26 +244,26 @@ private void LoadProperties()
default:
throw new Exception();
}
SERVER_SEED.Text = PropertiesOperation["level-seed"].ToString();
SERVER_PORT.Text = PropertiesOperation["server-port"].ToString();
SERVER_SEED.Text = PropertiesOperation["level-seed"]?.ToString();
SERVER_PORT.Text = PropertiesOperation["server-port"]?.ToString();
try
{
if(int.Parse(PropertiesOperation["server-port"].ToString()) != 0)
if(int.Parse(PropertiesOperation["server-port"]?.ToString()) != 0)

Check warning on line 251 in Serein/WPF/Windows/Pages/Server/Properties.xaml.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 251 in Serein/WPF/Windows/Pages/Server/Properties.xaml.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 251 in Serein/WPF/Windows/Pages/Server/Properties.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.
{
Global.Settings.Server.Port = int.Parse(PropertiesOperation["server-port"].ToString());
Global.Settings.Server.Port = int.Parse(PropertiesOperation["server-port"]?.ToString());

Check warning on line 253 in Serein/WPF/Windows/Pages/Server/Properties.xaml.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 253 in Serein/WPF/Windows/Pages/Server/Properties.xaml.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 253 in Serein/WPF/Windows/Pages/Server/Properties.xaml.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
{

}
SPAWNPOINT_PROTECT.Text = PropertiesOperation["spawn-protection"].ToString();
MAINWORLD_NAME.Text = PropertiesOperation["level-name"].ToString();
WORLD_BORDER.Text = PropertiesOperation["max-world-size"].ToString();
SERVER_MAXPLAYER.Text = PropertiesOperation["max-players"].ToString();
SERVER_MOTD.Text = PropertiesOperation["motd"].ToString();
SERVER_VIEWDISTANCE.Text = PropertiesOperation["view-distance"].ToString();
SERVER_SIMULATEDISTANCE.Text = PropertiesOperation["simulation-distance"].ToString();
SPAWNPOINT_PROTECT.Text = PropertiesOperation["spawn-protection"]?.ToString();
MAINWORLD_NAME.Text = PropertiesOperation["level-name"]?.ToString();
WORLD_BORDER.Text = PropertiesOperation["max-world-size"]?.ToString();
SERVER_MAXPLAYER.Text = PropertiesOperation["max-players"]?.ToString();
SERVER_MOTD.Text = PropertiesOperation["motd"]?.ToString();
SERVER_VIEWDISTANCE.Text = PropertiesOperation["view-distance"]?.ToString();
SERVER_SIMULATEDISTANCE.Text = PropertiesOperation["simulation-distance"]?.ToString();



Expand Down

0 comments on commit 97d7939

Please sign in to comment.