mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
Added AsyncStatus class to keep track of the timing of each update on servers
This commit is contained in:
50
SharedLibrary/AsyncStatus.cs
Normal file
50
SharedLibrary/AsyncStatus.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public sealed class AsyncStatus
|
||||
{
|
||||
CancellationToken Token;
|
||||
DateTime StartTime;
|
||||
int TimesRun;
|
||||
public double RunAverage { get; private set; }
|
||||
public object Dependant { get; private set; }
|
||||
public Task RequestedTask { get; private set; }
|
||||
|
||||
public AsyncStatus(object dependant)
|
||||
{
|
||||
Token = new CancellationToken();
|
||||
StartTime = DateTime.Now;
|
||||
Dependant = dependant;
|
||||
// technically 0 but it's faster than checking for division by 0
|
||||
TimesRun = 1;
|
||||
}
|
||||
|
||||
public CancellationToken GetToken()
|
||||
{
|
||||
return Token;
|
||||
}
|
||||
|
||||
public double ElapsedMillisecondsTime()
|
||||
{
|
||||
return (DateTime.Now - StartTime).TotalMilliseconds;
|
||||
}
|
||||
|
||||
public void Update(Task T)
|
||||
{
|
||||
RequestedTask = T;
|
||||
RequestedTask.Start();
|
||||
|
||||
if (TimesRun > 100)
|
||||
TimesRun = 1;
|
||||
|
||||
RunAverage = RunAverage + ((DateTime.Now - StartTime).TotalMilliseconds - RunAverage) / TimesRun;
|
||||
StartTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
@ -236,7 +236,10 @@ namespace SharedLibrary.Commands
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.Broadcast($"Fast restarting in ^53 ^7seconds [^5{E.Origin.Name}^7]");
|
||||
if (!E.Origin.Masked)
|
||||
await E.Owner.Broadcast($"Fast restarting in ^53 ^7seconds [^5{E.Origin.Name}^7]");
|
||||
else
|
||||
await E.Owner.Broadcast($"Fast restarting in ^53 ^7seconds [^5Masked Admin^7]");
|
||||
await Task.Delay(3000);
|
||||
await E.Owner.ExecuteCommandAsync("fast_restart");
|
||||
}
|
||||
@ -248,7 +251,10 @@ namespace SharedLibrary.Commands
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
await E.Owner.Broadcast($"Map rotating in ^55 ^7seconds [^5{E.Origin.Name}^7]");
|
||||
if (!E.Origin.Masked)
|
||||
await E.Owner.Broadcast($"Map rotating in ^55 ^7seconds [^5{E.Origin.Name}^7]");
|
||||
else
|
||||
await E.Owner.Broadcast($"Map rotating in ^55 ^7seconds [^5Masked Admin^7]");
|
||||
await Task.Delay(5000);
|
||||
await E.Owner.ExecuteCommandAsync("map_rotate");
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ namespace SharedLibrary
|
||||
#if DEBUG == false
|
||||
catch (Exception E)
|
||||
{
|
||||
SV.Log.Write("Error requesting event " + E.Message, Log.Level.Debug);
|
||||
SV.Manager.GetLogger().WriteError("Error requesting event " + E.Message);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
@ -189,7 +189,7 @@ namespace SharedLibrary
|
||||
/// <returns></returns>
|
||||
abstract public Task<Command> ProcessCommand(Event E, Command C);
|
||||
|
||||
virtual public Task<int> ProcessUpdatesAsync()
|
||||
virtual public Task ProcessUpdatesAsync(CancellationToken cts)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AsyncStatus.cs" />
|
||||
<Compile Include="Commands\NativeCommands.cs" />
|
||||
<Compile Include="Exceptions\CommandException.cs" />
|
||||
<Compile Include="Exceptions\DvarException.cs" />
|
||||
|
Reference in New Issue
Block a user