1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

harden up the script timer/game interface dvar operations for multithreading

This commit is contained in:
RaidMax
2022-10-23 14:03:33 -05:00
parent 5b7e56f894
commit 7b2cd19fc1
5 changed files with 95 additions and 48 deletions

View File

@ -409,24 +409,9 @@ namespace SharedLibraryCore
public abstract Task<long> GetIdForServer(Server server = null);
public string[] ExecuteServerCommand(string command, int timeoutMs = 1000)
{
var tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutMs));
try
{
return this.ExecuteCommandAsync(command, tokenSource.Token).GetAwaiter().GetResult();
}
catch
{
return null;
}
}
public string GetServerDvar(string dvarName, int timeoutMs = 1000)
{
var tokenSource = new CancellationTokenSource();
using var tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutMs));
try
{
@ -440,7 +425,7 @@ namespace SharedLibraryCore
public bool SetServerDvar(string dvarName, string dvarValue, int timeoutMs = 1000)
{
var tokenSource = new CancellationTokenSource();
using var tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutMs));
try
{

View File

@ -18,7 +18,6 @@ using Microsoft.Extensions.Logging;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos.Meta;
using SharedLibraryCore.Formatting;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Localization;
@ -1003,9 +1002,9 @@ namespace SharedLibraryCore
return true;
}
catch (Exception e)
catch (Exception ex)
{
logger.LogError(e, $"Could not create penalty of type {penalty.Type.ToString()}");
logger.LogError(ex, "Could not create penalty of type {PenaltyType}", penalty.Type.ToString());
}
return false;
@ -1052,8 +1051,7 @@ namespace SharedLibraryCore
{
await Task.WhenAny(task, Task.Delay(timeout));
}
public static bool ShouldHideLevel(this Permission perm)
{
return perm == Permission.Flagged;