diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index bec2f708..b2b4a737 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -587,16 +587,29 @@ namespace IW4MAdmin.Application public async Task Start() => await UpdateServerStates(); - public void Stop() + public async Task Stop() { _tokenSource.Cancel(); + + foreach (var plugin in Plugins) + { + try + { + await plugin.OnUnloadAsync(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Could not cleanly unload plugin {PluginName}", plugin.Name); + } + } + IsRunning = false; } public void Restart() { IsRestartRequested = true; - Stop(); + Stop().GetAwaiter().GetResult(); } [Obsolete] diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 7b1c0660..7ed4596b 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -903,11 +903,6 @@ namespace IW4MAdmin await e.WaitAsync(Utilities.DefaultCommandTimeout, new CancellationTokenRegistration().Token); } - - foreach (var plugin in Manager.Plugins) - { - await plugin.OnUnloadAsync(); - } } DateTime start = DateTime.Now; diff --git a/Application/Main.cs b/Application/Main.cs index 91ee0d85..506297c6 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -77,8 +77,12 @@ namespace IW4MAdmin.Application /// private static async void OnCancelKey(object sender, ConsoleCancelEventArgs e) { - _serverManager?.Stop(); - if (_applicationTask != null) + if (_serverManager is not null) + { + await _serverManager.Stop(); + } + + if (_applicationTask is not null) { await _applicationTask; } @@ -153,8 +157,11 @@ namespace IW4MAdmin.Application { Console.WriteLine(e.Message); } - - _serverManager?.Stop(); + + if (_serverManager is not null) + { + await _serverManager?.Stop(); + } Console.WriteLine(exitMessage); await Console.In.ReadAsync(new char[1], 0, 1); diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index b28d0c1e..6052fae8 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -33,10 +33,9 @@ namespace SharedLibraryCore.Commands RequiresTarget = false; } - public override Task ExecuteAsync(GameEvent E) + public override async Task ExecuteAsync(GameEvent E) { - E.Owner.Manager.Stop(); - return Task.CompletedTask; + await E.Owner.Manager.Stop(); } } @@ -731,7 +730,7 @@ namespace SharedLibraryCore.Commands var ruleFormat = rules.Select(r => $"- {r}"); if (gameEvent.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix)) { - gameEvent.Owner.Broadcast(ruleFormat); + await gameEvent.Owner.BroadcastAsync(ruleFormat, token: gameEvent.Owner.Manager.CancellationToken); } else { diff --git a/SharedLibraryCore/Helpers/Hashing.cs b/SharedLibraryCore/Helpers/Hashing.cs index 183d5151..75afbf82 100644 --- a/SharedLibraryCore/Helpers/Hashing.cs +++ b/SharedLibraryCore/Helpers/Hashing.cs @@ -8,6 +8,7 @@ namespace SharedLibraryCore.Helpers /// Generate password hash and salt /// /// plaintext password + /// salt of password /// public static string[] Hash(string password, string saltStr = null) { @@ -35,4 +36,4 @@ namespace SharedLibraryCore.Helpers }; } } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/Interfaces/IManager.cs b/SharedLibraryCore/Interfaces/IManager.cs index d10f35f3..4b498540 100644 --- a/SharedLibraryCore/Interfaces/IManager.cs +++ b/SharedLibraryCore/Interfaces/IManager.cs @@ -32,7 +32,7 @@ namespace SharedLibraryCore.Interfaces ConcurrentDictionary ProcessingEvents { get; } Task Init(); Task Start(); - void Stop(); + Task Stop(); void Restart(); [Obsolete] @@ -103,4 +103,4 @@ namespace SharedLibraryCore.Interfaces /// event EventHandler OnGameEventExecuted; } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/Interfaces/IMetaService.cs b/SharedLibraryCore/Interfaces/IMetaService.cs index c4f10d96..e80c213d 100644 --- a/SharedLibraryCore/Interfaces/IMetaService.cs +++ b/SharedLibraryCore/Interfaces/IMetaService.cs @@ -17,6 +17,7 @@ namespace SharedLibraryCore.Interfaces /// key of meta data /// value of the meta data /// client to save the meta for + /// /// Task AddPersistentMeta(string metaKey, string metaValue, EFClient client, EFMeta linkedMeta = null); diff --git a/SharedLibraryCore/Interfaces/IMetaServiceV2.cs b/SharedLibraryCore/Interfaces/IMetaServiceV2.cs index 2b09c7fa..c545710a 100644 --- a/SharedLibraryCore/Interfaces/IMetaServiceV2.cs +++ b/SharedLibraryCore/Interfaces/IMetaServiceV2.cs @@ -42,7 +42,6 @@ public interface IMetaServiceV2 /// Id in the list of lookup values /// id of the client /// - /// /// Task SetPersistentMetaForLookupKey(string metaKey, string lookupKey, int lookupId, int clientId, CancellationToken token = default); @@ -100,7 +99,6 @@ public interface IMetaServiceV2 /// /// /// - /// /// Task GetPersistentMetaByLookup(string metaKey, string lookupKey, int clientId, CancellationToken token = default); @@ -141,7 +139,6 @@ public interface IMetaServiceV2 /// removes meta key with given value /// /// key of the meta data - /// value of the meta data /// /// Task RemovePersistentMeta(string metaKey, CancellationToken token = default); diff --git a/SharedLibraryCore/Interfaces/IRConConnection.cs b/SharedLibraryCore/Interfaces/IRConConnection.cs index da56406d..fefd58a4 100644 --- a/SharedLibraryCore/Interfaces/IRConConnection.cs +++ b/SharedLibraryCore/Interfaces/IRConConnection.cs @@ -14,6 +14,7 @@ namespace SharedLibraryCore.Interfaces /// /// type of RCon query to perform /// optional parameter list + /// /// Task SendQueryAsync(StaticHelpers.QueryType type, string parameters = "", CancellationToken token = default); diff --git a/SharedLibraryCore/Interfaces/IRConParser.cs b/SharedLibraryCore/Interfaces/IRConParser.cs index 4b9e59f3..e879c5de 100644 --- a/SharedLibraryCore/Interfaces/IRConParser.cs +++ b/SharedLibraryCore/Interfaces/IRConParser.cs @@ -52,6 +52,7 @@ namespace SharedLibraryCore.Interfaces /// RCon connection to retrieve with /// name of DVAR /// default value to return if dvar retrieval fails + /// /// Task> GetDvarAsync(IRConConnection connection, string dvarName, T fallbackValue = default, CancellationToken token = default); @@ -61,6 +62,7 @@ namespace SharedLibraryCore.Interfaces /// RCon connection to use /// name of DVAR to set /// value to set DVAR to + /// /// Task SetDvarAsync(IRConConnection connection, string dvarName, object dvarValue, CancellationToken token = default); @@ -69,13 +71,15 @@ namespace SharedLibraryCore.Interfaces /// /// RCon connection to use /// console command to execute + /// /// Task ExecuteCommandAsync(IRConConnection connection, string command, CancellationToken token = default); - + /// /// get the list of connected clients from status response /// /// RCon connection to use + /// /// /// /// diff --git a/SharedLibraryCore/Interfaces/IScriptPluginServiceResolver.cs b/SharedLibraryCore/Interfaces/IScriptPluginServiceResolver.cs index 0ec29fa1..8c25faf1 100644 --- a/SharedLibraryCore/Interfaces/IScriptPluginServiceResolver.cs +++ b/SharedLibraryCore/Interfaces/IScriptPluginServiceResolver.cs @@ -16,8 +16,8 @@ /// resolves a service with the given name and generic params /// /// class name of service - /// generic class names + /// generic class names /// object ResolveService(string serviceName, string[] genericParameters); } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/Interfaces/ITokenAuthentication.cs b/SharedLibraryCore/Interfaces/ITokenAuthentication.cs index 9ffbcdcd..a19c3cc8 100644 --- a/SharedLibraryCore/Interfaces/ITokenAuthentication.cs +++ b/SharedLibraryCore/Interfaces/ITokenAuthentication.cs @@ -14,8 +14,9 @@ namespace SharedLibraryCore.Interfaces /// /// authorizes given token /// + /// network id of the client to authorize /// token to authorize /// true if token authorized successfully, false otherwise bool AuthorizeToken(long networkId, string token); } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index 24ea46e9..7baad66b 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -307,6 +307,7 @@ namespace SharedLibraryCore.Database.Models /// /// reason for flagging /// client performing the flag + /// how long the flag should last /// game event for the flag public GameEvent Flag(string flagReason, EFClient sender, TimeSpan? flagLength = null) { @@ -442,6 +443,7 @@ namespace SharedLibraryCore.Database.Models /// /// reason for the ban /// client performing the ban + /// obsolete public GameEvent Ban(string banReason, EFClient sender, bool isEvade) { var e = new GameEvent diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index 5b9211e3..da784983 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -159,14 +159,13 @@ namespace SharedLibraryCore /// Add a player to the server's player list /// /// EFClient pulled from memory reading - /// True if player added sucessfully, false otherwise + /// True if player added successfully, false otherwise public abstract Task OnClientConnected(EFClient P); /// /// Remove player by client number /// - /// Client ID of player to be removed - /// true if removal succeded, false otherwise + /// true if removal succeeded, false otherwise public abstract Task OnClientDisconnected(EFClient client); /// @@ -219,6 +218,7 @@ namespace SharedLibraryCore /// Send a message to all players /// /// Message to be sent to all players + /// Client that initiated the broadcast public GameEvent Broadcast(string message, EFClient sender = null) { var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "", @@ -322,39 +322,44 @@ namespace SharedLibraryCore /// Kick a player from the server /// /// Reason for kicking - /// EFClient to kick - public Task Kick(string reason, EFClient Target, EFClient Origin) + /// EFClient to kick + /// Client initating the kick + public Task Kick(string reason, EFClient target, EFClient origin) { - return Kick(reason, Target, Origin, null); + return Kick(reason, target, origin, null); } /// /// Temporarily ban a player ( default 1 hour ) from the server /// /// Reason for banning the player - /// The player to ban - public abstract Task TempBan(string reason, TimeSpan length, EFClient Target, EFClient Origin); + /// Duration of the ban + /// The client to ban + /// The client performing the ban + public abstract Task TempBan(string reason, TimeSpan length, EFClient target, EFClient origin); /// /// Perm ban a player from the server /// - /// The reason for the ban - /// The person to ban - /// The person who banned the target - public abstract Task Ban(string Reason, EFClient Target, EFClient Origin, bool isEvade = false); + /// The reason for the ban + /// The person to ban + /// The person who banned the target + /// obsolete + public abstract Task Ban(string reason, EFClient target, EFClient origin, bool isEvade = false); - public abstract Task Warn(string Reason, EFClient Target, EFClient Origin); + public abstract Task Warn(string reason, EFClient target, EFClient origin); /// /// Unban a player by npID / GUID /// - /// npID of the player - /// I don't remember what this is for + /// reason for unban + /// client being unbanned + /// client performing the unban /// public abstract Task Unban(string reason, EFClient targetClient, EFClient originClient); /// - /// Change the current searver map + /// Change the current server map /// /// Non-localized map name public async Task LoadMap(string mapName) diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index f8019b72..e13f4f28 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -593,7 +593,6 @@ namespace SharedLibraryCore.Services /// /// /// - /// /// public virtual async Task UpdateLevel(Permission newPermission, EFClient temporalClient, EFClient origin) { diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index 79d7fbdd..2d434ca3 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -121,7 +121,9 @@ namespace WebfrontCore services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService()); services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService()); services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService>()); +#pragma warning disable CS0618 services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService()); +#pragma warning restore CS0618 services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService()); services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService()); services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService());