From b83960d872d056d645fd034145e5f85ffe76712c Mon Sep 17 00:00:00 2001 From: Li Date: Fri, 22 Jul 2022 18:57:53 +1200 Subject: [PATCH] Finish MPN00Bs --- .github/workflows/build.yml | 8 +- .../HISPd/Resources/DEBIAN/control | 2 +- HorseIsleServer/LibHISP/Game/Chat/Chat.cs | 6 +- .../LibHISP/Properties/AssemblyInfo.cs | 4 +- .../LibHISP/Server/ConfigReader.cs | 12 +- HorseIsleServer/LibHISP/Server/Entry.cs | 8 +- HorseIsleServer/MPN00BS/App.axaml | 29 ++-- HorseIsleServer/MPN00BS/App.axaml.cs | 7 + HorseIsleServer/MPN00BS/HispViewModel.cs | 106 +++++++++++++ HorseIsleServer/MPN00BS/LoadingWindow.axaml | 3 +- .../MPN00BS/LoadingWindow.axaml.cs | 33 +++- .../MPN00BS/MiniMvvm/MiniCommand.cs | 66 ++++++++ .../MiniMvvm/PropertyChangedExtensions.cs | 108 +++++++++++++ .../MPN00BS/MiniMvvm/ViewModelBase.cs | 26 ++++ HorseIsleServer/MPN00BS/ResetWindow.axaml | 29 ++++ HorseIsleServer/MPN00BS/ResetWindow.axaml.cs | 147 ++++++++++++++++++ HorseIsleServer/MPN00BS/ServerStarter.cs | 78 +++++++--- HorseIsleServer/MPN00BS/SystemTrayIcon.axaml | 15 -- .../MPN00BS/SystemTrayIcon.axaml.cs | 73 --------- .../N00BS/Properties/AssemblyInfo.cs | 4 +- HorseIsleServer/N00BS/SystemTrayIcon.cs | 12 +- HorseIsleServer/server.properties | 99 ++++++++++++ 22 files changed, 720 insertions(+), 155 deletions(-) create mode 100644 HorseIsleServer/MPN00BS/HispViewModel.cs create mode 100644 HorseIsleServer/MPN00BS/MiniMvvm/MiniCommand.cs create mode 100644 HorseIsleServer/MPN00BS/MiniMvvm/PropertyChangedExtensions.cs create mode 100644 HorseIsleServer/MPN00BS/MiniMvvm/ViewModelBase.cs create mode 100644 HorseIsleServer/MPN00BS/ResetWindow.axaml create mode 100644 HorseIsleServer/MPN00BS/ResetWindow.axaml.cs delete mode 100644 HorseIsleServer/MPN00BS/SystemTrayIcon.axaml delete mode 100644 HorseIsleServer/MPN00BS/SystemTrayIcon.axaml.cs create mode 100644 HorseIsleServer/server.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9ddc86..baf7656 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -193,7 +193,7 @@ jobs: cd HISPd dotnet publish -p:PublishProfile=Win64.pubxml cd .. - cd N00BS + cd MPN00BS dotnet publish -p:PublishProfile=Win64.pubxml cd .. @@ -218,7 +218,7 @@ jobs: cd HISPd dotnet publish -p:PublishProfile=Win32.pubxml cd .. - cd N00BS + cd MPN00BS dotnet publish -p:PublishProfile=Win32.pubxml cd .. - name: Build win-arm @@ -280,13 +280,13 @@ jobs: uses: actions/upload-artifact@v2 with: name: HISP-Win32-Noobs - path: HorseIsleServer\N00BS\bin\x86\Windows\net7.0\win-x86\publish\ + path: HorseIsleServer\MPN00BS\bin\x86\Windows\net7.0\win-x86\publish\ - name: Upload win-x64-noobs uses: actions/upload-artifact@v2 with: name: HISP-Win64-Noobs - path: HorseIsleServer\N00BS\bin\x64\Windows\net7.0\win-x64\publish\ + path: HorseIsleServer\MPN00BS\bin\x64\Windows\net7.0\win-x64\publish\ diff --git a/HorseIsleServer/HISPd/Resources/DEBIAN/control b/HorseIsleServer/HISPd/Resources/DEBIAN/control index 5bc564e..34dac19 100644 --- a/HorseIsleServer/HISPd/Resources/DEBIAN/control +++ b/HorseIsleServer/HISPd/Resources/DEBIAN/control @@ -1,5 +1,5 @@ Package: hisp -Version: 1.7.102 +Version: 1.7.103 Depends: coreutils,systemd,mariadb-server,libsqlite3-dev,zlib1g-dev,libicu-dev,libkrb5-dev Maintainer: Li Homepage: https://islehorse.com diff --git a/HorseIsleServer/LibHISP/Game/Chat/Chat.cs b/HorseIsleServer/LibHISP/Game/Chat/Chat.cs index 72a8acb..69d6579 100644 --- a/HorseIsleServer/LibHISP/Game/Chat/Chat.cs +++ b/HorseIsleServer/LibHISP/Game/Chat/Chat.cs @@ -110,7 +110,7 @@ namespace HISP.Game.Chat } public static Object FilterMessage(string message) // Handles chat filtering and violation stuffs { - if (!ConfigReader.BadWords) // Freedom of Speech Mode + if (!ConfigReader.EnableSwearFilter) // Freedom of Speech Mode return null; @@ -359,7 +359,7 @@ namespace HISP.Game.Chat public static string DoCorrections(string message) { - if (!ConfigReader.DoCorrections) + if (!ConfigReader.EnableCorrections) return message; foreach(Correction correct in CorrectedWords) @@ -466,7 +466,7 @@ namespace HISP.Game.Chat public static string NonViolationChecks(User user, string message) { - if(!ConfigReader.DoNonViolations) + if(!ConfigReader.EnableNonViolations) return null; // Check if contains password. diff --git a/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs b/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs index 5a9872f..2b9e47a 100644 --- a/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs +++ b/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs @@ -30,5 +30,5 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.7.102.0")] -[assembly: AssemblyFileVersion("1.7.102.0")] +[assembly: AssemblyVersion("1.7.103.0")] +[assembly: AssemblyFileVersion("1.7.103.0")] diff --git a/HorseIsleServer/LibHISP/Server/ConfigReader.cs b/HorseIsleServer/LibHISP/Server/ConfigReader.cs index a93b3d1..224377e 100644 --- a/HorseIsleServer/LibHISP/Server/ConfigReader.cs +++ b/HorseIsleServer/LibHISP/Server/ConfigReader.cs @@ -28,9 +28,9 @@ namespace HISP.Server public static bool EnableSpamFilter = true; public static bool AllUsersSubbed = false; public static bool FixOfficalBugs = false; - public static bool BadWords = true; - public static bool DoCorrections = true; - public static bool DoNonViolations = true; + public static bool EnableSwearFilter = true; + public static bool EnableCorrections = true; + public static bool EnableNonViolations = true; public static string ConfigurationFileName = "server.properties"; public static void OpenConfig() @@ -102,13 +102,13 @@ namespace HISP.Server AllUsersSubbed = data == "true"; break; case "enable_corrections": - DoCorrections = data == "true"; + EnableCorrections = data == "true"; break; case "sql_lite": SqlLite = data == "true"; break; case "enable_non_violation_check": - DoNonViolations = data == "true"; + EnableNonViolations = data == "true"; break; case "enable_spam_filter": EnableSpamFilter = data == "true"; @@ -117,7 +117,7 @@ namespace HISP.Server FixOfficalBugs = data == "true"; break; case "enable_word_filter": - BadWords = data == "true"; + EnableSwearFilter = data == "true"; break; case "mods_folder": ModsFolder = data; diff --git a/HorseIsleServer/LibHISP/Server/Entry.cs b/HorseIsleServer/LibHISP/Server/Entry.cs index 89071ac..4556704 100644 --- a/HorseIsleServer/LibHISP/Server/Entry.cs +++ b/HorseIsleServer/LibHISP/Server/Entry.cs @@ -67,10 +67,10 @@ namespace HISP.Server Exception execpt = (Exception)e.ExceptionObject; - string crashMsg = "HISP HAS CRASHED :("; - crashMsg += "Build: " + ServerVersion.GetBuildString(); - crashMsg += "Unhandled Exception: " + execpt.Message; - crashMsg += execpt.StackTrace; + string crashMsg = "HISP HAS CRASHED :(" + "\n"; + crashMsg += "Build: " + ServerVersion.GetBuildString() + "\n"; + crashMsg += "Unhandled Exception: " + execpt.Message + "\n"; + crashMsg += execpt.StackTrace + "\n"; Logger.CrashPrint(crashMsg); diff --git a/HorseIsleServer/MPN00BS/App.axaml b/HorseIsleServer/MPN00BS/App.axaml index 6a379b5..0bd6d02 100644 --- a/HorseIsleServer/MPN00BS/App.axaml +++ b/HorseIsleServer/MPN00BS/App.axaml @@ -1,5 +1,8 @@ @@ -14,31 +17,31 @@ - - + + - - + + - - + + diff --git a/HorseIsleServer/MPN00BS/App.axaml.cs b/HorseIsleServer/MPN00BS/App.axaml.cs index 7486978..5a2d37e 100644 --- a/HorseIsleServer/MPN00BS/App.axaml.cs +++ b/HorseIsleServer/MPN00BS/App.axaml.cs @@ -1,11 +1,18 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using HISP.Server; +using MPN00BS.ViewModels; namespace MPN00BS { public partial class App : Application { + public App() + { + this.DataContext = new HispViewModel(); + } + public override void Initialize() { AvaloniaXamlLoader.Load(this); diff --git a/HorseIsleServer/MPN00BS/HispViewModel.cs b/HorseIsleServer/MPN00BS/HispViewModel.cs new file mode 100644 index 0000000..8774c7d --- /dev/null +++ b/HorseIsleServer/MPN00BS/HispViewModel.cs @@ -0,0 +1,106 @@ +using HISP.Server; +using MiniMvvm; +using System; +using System.Diagnostics; +using System.IO; + +namespace MPN00BS.ViewModels +{ + public class HispViewModel : ViewModelBase + { + public HispViewModel() + { + ServerStarter.ReadServerProperties(); + swearFilterHeader = (ConfigReader.EnableSwearFilter ? "Disable" : "Enable") + " Swear Filter"; + + createAccountCommand = MiniCommand.Create(() => + { + if (!ServerStarter.HasServerStarted) + { + MessageBox.Show(null, "There is no Horse Isle Server running yet.", "Server not Started.", MessageBox.MessageBoxButtons.Ok); + return; + } + new RegisterWindow().Show(); + }); + + resetPasswordCommand = MiniCommand.Create(() => + { + if (!ServerStarter.HasServerStarted) + { + MessageBox.Show(null, "There is no Horse Isle Server running yet.", "Server not Started.", MessageBox.MessageBoxButtons.Ok); + return; + } + + new ResetWindow().Show(); + }); + + editServerPropertiesCommand = MiniCommand.Create(() => + { + if (!ServerStarter.HasServerStarted) + { + MessageBox.Show(null, "There is no Horse Isle Server running yet.", "Server not Started.", MessageBox.MessageBoxButtons.Ok); + return; + } + + Process p = new Process(); + p.StartInfo.FileName = Path.Combine(ServerStarter.BaseDir, "server.properties"); + p.StartInfo.UseShellExecute = true; + p.Start(); + + }); + + openServerFolderCommand = MiniCommand.Create(() => + { + if (!ServerStarter.HasServerStarted) + { + MessageBox.Show(null, "There is no Horse Isle Server running yet.", "Server not Started.", MessageBox.MessageBoxButtons.Ok); + return; + } + + Process p = new Process(); + p.StartInfo.FileName = ServerStarter.BaseDir; + p.StartInfo.UseShellExecute = true; + p.Start(); + }); + + shutdownServerCommand = MiniCommand.Create(() => + { + if (!ServerStarter.HasServerStarted) + { + MessageBox.Show(null, "There is no Horse Isle Server running yet.", "Server not Started.", MessageBox.MessageBoxButtons.Ok); + return; + } + + GameServer.ShutdownServer(); + }); + + + toggleSwearFilter = MiniCommand.Create(() => + { + if (!ServerStarter.HasServerStarted) + { + MessageBox.Show(null, "There is no Horse Isle Server running yet.", "Server not Started.", MessageBox.MessageBoxButtons.Ok); + return; + } + + bool enab = !ConfigReader.EnableSwearFilter; + ServerStarter.ModifyConfig("enable_word_filter", enab.ToString().ToLowerInvariant()); + ConfigReader.EnableSwearFilter = enab; + swearFilterHeader = (ConfigReader.EnableSwearFilter ? "Disable" : "Enable") + " Swear Filter"; + }); + + } + + + + + public String swearFilterHeader { get; set; } + public MiniCommand shutdownServerCommand { get; } + public MiniCommand createAccountCommand { get; } + public MiniCommand editServerPropertiesCommand { get; } + public MiniCommand openServerFolderCommand { get; } + public MiniCommand toggleSwearFilter { get; } + public MiniCommand resetPasswordCommand { get; } + + } +} \ No newline at end of file diff --git a/HorseIsleServer/MPN00BS/LoadingWindow.axaml b/HorseIsleServer/MPN00BS/LoadingWindow.axaml index 089c2b8..7e71e01 100644 --- a/HorseIsleServer/MPN00BS/LoadingWindow.axaml +++ b/HorseIsleServer/MPN00BS/LoadingWindow.axaml @@ -5,7 +5,8 @@ mc:Ignorable="d" d:DesignWidth="820" d:DesignHeight="200" x:Class="MPN00BS.LoadingWindow" Title="Starting Server ..." Height="200" Width="820" - MaxHeight="200" MaxWidth="820" Icon="/icon.ico"> + MaxHeight="200" MaxWidth="820" Icon="/icon.ico" + Closing="OnServerClose"> diff --git a/HorseIsleServer/MPN00BS/LoadingWindow.axaml.cs b/HorseIsleServer/MPN00BS/LoadingWindow.axaml.cs index 034cedd..f1e855e 100644 --- a/HorseIsleServer/MPN00BS/LoadingWindow.axaml.cs +++ b/HorseIsleServer/MPN00BS/LoadingWindow.axaml.cs @@ -1,22 +1,28 @@ -using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Threading; +using HISP.Server; +using System; +using System.ComponentModel; using System.Threading.Tasks; namespace MPN00BS { public partial class LoadingWindow : Window { - - + private void OnClientExit() + { + try + { + GameServer.ShutdownServer(); + }catch(Exception) { } + } public void OnServerStarted() { Dispatcher.UIThread.InvokeAsync(() => { this.Hide(); - new SystemTrayIcon().Show(); - this.Close(); + ServerStarter.StartHorseIsleClient(OnClientExit, "127.0.0.1", 12321); }); } public void OnNoUsersFound() @@ -27,6 +33,15 @@ namespace MPN00BS }); } + private void OnShutdown() + { + Dispatcher.UIThread.InvokeAsync(() => + { + ServerStarter.CloseHorseIsleClient(); + this.Close(); + }); + } + public void ProgressUpdate() { Dispatcher.UIThread.InvokeAsync(() => @@ -40,9 +55,13 @@ namespace MPN00BS #if DEBUG this.AttachDevTools(); #endif - ServerStarter.StartHttpServer(); - new Task( () => ServerStarter.StartHispServer(ProgressUpdate, OnNoUsersFound, OnServerStarted)).Start(); + new Task( () => ServerStarter.StartHispServer(ProgressUpdate, OnNoUsersFound, OnServerStarted, OnShutdown)).Start(); + } + + private void OnServerClose(object sender, CancelEventArgs e) + { + GameServer.ShutdownServer(); } private void InitializeComponent() diff --git a/HorseIsleServer/MPN00BS/MiniMvvm/MiniCommand.cs b/HorseIsleServer/MPN00BS/MiniMvvm/MiniCommand.cs new file mode 100644 index 0000000..0d93c92 --- /dev/null +++ b/HorseIsleServer/MPN00BS/MiniMvvm/MiniCommand.cs @@ -0,0 +1,66 @@ +using System; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace MiniMvvm +{ + public sealed class MiniCommand : MiniCommand, ICommand + { + private readonly Action _cb; + private bool _busy; + private Func _acb; + + public MiniCommand(Action cb) + { + _cb = cb; + } + + public MiniCommand(Func cb) + { + _acb = cb; + } + + private bool Busy + { + get => _busy; + set + { + _busy = value; + CanExecuteChanged?.Invoke(this, EventArgs.Empty); + } + } + + + public override event EventHandler CanExecuteChanged; + public override bool CanExecute(object parameter) => !_busy; + + public override async void Execute(object parameter) + { + if (Busy) + return; + try + { + Busy = true; + if (_cb != null) + _cb((T)parameter); + else + await _acb((T)parameter); + } + finally + { + Busy = false; + } + } + } + + public abstract class MiniCommand : ICommand + { + public static MiniCommand Create(Action cb) => new MiniCommand(_ => cb()); + public static MiniCommand Create(Action cb) => new MiniCommand(cb); + public static MiniCommand CreateFromTask(Func cb) => new MiniCommand(_ => cb()); + + public abstract bool CanExecute(object parameter); + public abstract void Execute(object parameter); + public abstract event EventHandler CanExecuteChanged; + } +} diff --git a/HorseIsleServer/MPN00BS/MiniMvvm/PropertyChangedExtensions.cs b/HorseIsleServer/MPN00BS/MiniMvvm/PropertyChangedExtensions.cs new file mode 100644 index 0000000..873f7b0 --- /dev/null +++ b/HorseIsleServer/MPN00BS/MiniMvvm/PropertyChangedExtensions.cs @@ -0,0 +1,108 @@ +using System; +using System.ComponentModel; +using System.Linq.Expressions; +using System.Reactive.Linq; +using System.Reflection; + +namespace MiniMvvm +{ + public static class PropertyChangedExtensions + { + class PropertyObservable : IObservable + { + private readonly INotifyPropertyChanged _target; + private readonly PropertyInfo _info; + + public PropertyObservable(INotifyPropertyChanged target, PropertyInfo info) + { + _target = target; + _info = info; + } + + class Subscription : IDisposable + { + private readonly INotifyPropertyChanged _target; + private readonly PropertyInfo _info; + private readonly IObserver _observer; + + public Subscription(INotifyPropertyChanged target, PropertyInfo info, IObserver observer) + { + _target = target; + _info = info; + _observer = observer; + _target.PropertyChanged += OnPropertyChanged; + _observer.OnNext((T)_info.GetValue(_target)); + } + + private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == _info.Name) + _observer.OnNext((T)_info.GetValue(_target)); + } + + public void Dispose() + { + _target.PropertyChanged -= OnPropertyChanged; + _observer.OnCompleted(); + } + } + + public IDisposable Subscribe(IObserver observer) + { + return new Subscription(_target, _info, observer); + } + } + + public static IObservable WhenAnyValue(this TModel model, + Expression> expr) where TModel : INotifyPropertyChanged + { + var l = (LambdaExpression)expr; + var ma = (MemberExpression)l.Body; + var prop = (PropertyInfo)ma.Member; + return new PropertyObservable(model, prop); + } + + public static IObservable WhenAnyValue(this TModel model, + Expression> v1, + Func cb + ) where TModel : INotifyPropertyChanged + { + return model.WhenAnyValue(v1).Select(cb); + } + + public static IObservable WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2, + Func cb + ) where TModel : INotifyPropertyChanged => + Observable.CombineLatest( + model.WhenAnyValue(v1), + model.WhenAnyValue(v2), + cb); + + public static IObservable> WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2 + ) where TModel : INotifyPropertyChanged => + model.WhenAnyValue(v1, v2, (a1, a2) => (a1, a2)); + + public static IObservable WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2, + Expression> v3, + Func cb + ) where TModel : INotifyPropertyChanged => + Observable.CombineLatest( + model.WhenAnyValue(v1), + model.WhenAnyValue(v2), + model.WhenAnyValue(v3), + cb); + + public static IObservable> WhenAnyValue(this TModel model, + Expression> v1, + Expression> v2, + Expression> v3 + ) where TModel : INotifyPropertyChanged => + model.WhenAnyValue(v1, v2, v3, (a1, a2, a3) => (a1, a2, a3)); + } +} diff --git a/HorseIsleServer/MPN00BS/MiniMvvm/ViewModelBase.cs b/HorseIsleServer/MPN00BS/MiniMvvm/ViewModelBase.cs new file mode 100644 index 0000000..c4dd16b --- /dev/null +++ b/HorseIsleServer/MPN00BS/MiniMvvm/ViewModelBase.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.Reactive.Joins; +using System.Runtime.CompilerServices; + +namespace MiniMvvm +{ + public class ViewModelBase : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + protected bool RaiseAndSetIfChanged(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (!EqualityComparer.Default.Equals(field, value)) + { + field = value; + RaisePropertyChanged(propertyName); + return true; + } + return false; + } + + + protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) + => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/HorseIsleServer/MPN00BS/ResetWindow.axaml b/HorseIsleServer/MPN00BS/ResetWindow.axaml new file mode 100644 index 0000000..ac3e8a2 --- /dev/null +++ b/HorseIsleServer/MPN00BS/ResetWindow.axaml @@ -0,0 +1,29 @@ + + + + + + + + + + + +