2020-11-11 18:31:26 -05:00
|
|
|
|
using IW4MAdmin.Application.EventParsers;
|
2020-05-30 15:06:04 -04:00
|
|
|
|
using IW4MAdmin.Application.Extensions;
|
2019-02-15 23:19:59 -05:00
|
|
|
|
using IW4MAdmin.Application.Misc;
|
2021-06-03 11:51:03 -04:00
|
|
|
|
using IW4MAdmin.Application.RConParsers;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Commands;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2020-01-17 18:31:53 -05:00
|
|
|
|
using SharedLibraryCore.Configuration.Validation;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-11-25 21:00:36 -05:00
|
|
|
|
using SharedLibraryCore.Exceptions;
|
|
|
|
|
using SharedLibraryCore.Helpers;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using System;
|
2019-07-16 16:27:19 -04:00
|
|
|
|
using System.Collections;
|
2019-05-08 21:34:17 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
2018-11-25 21:00:36 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Abstractions;
|
|
|
|
|
using Data.Context;
|
2020-11-14 19:24:51 -05:00
|
|
|
|
using IW4MAdmin.Application.Migration;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Serilog.Context;
|
2019-10-07 18:35:37 -04:00
|
|
|
|
using static SharedLibraryCore.GameEvent;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
|
using ObsoleteLogger = SharedLibraryCore.Interfaces.ILogger;
|
2018-09-29 15:52:22 -04:00
|
|
|
|
|
2018-04-08 14:48:40 -04:00
|
|
|
|
namespace IW4MAdmin.Application
|
2015-07-03 00:10:01 -04:00
|
|
|
|
{
|
2018-02-21 20:29:23 -05:00
|
|
|
|
public class ApplicationManager : IManager
|
2015-07-03 00:10:01 -04:00
|
|
|
|
{
|
2019-07-19 15:54:39 -04:00
|
|
|
|
private readonly ConcurrentBag<Server> _servers;
|
2017-10-04 19:01:04 -04:00
|
|
|
|
public List<Server> Servers => _servers.OrderByDescending(s => s.ClientNum).ToList();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
[Obsolete] public ObsoleteLogger Logger => _serviceProvider.GetRequiredService<ObsoleteLogger>();
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public bool IsRunning { get; private set; }
|
2018-07-04 22:09:42 -04:00
|
|
|
|
public bool IsInitialized { get; private set; }
|
2018-04-18 16:46:53 -04:00
|
|
|
|
public DateTime StartTime { get; private set; }
|
2018-09-16 16:34:16 -04:00
|
|
|
|
public string Version => Assembly.GetEntryAssembly().GetName().Version.ToString();
|
2017-06-19 13:58:01 -04:00
|
|
|
|
|
2019-02-01 20:49:25 -05:00
|
|
|
|
public IList<IRConParser> AdditionalRConParsers { get; }
|
|
|
|
|
public IList<IEventParser> AdditionalEventParsers { get; }
|
2019-05-02 23:33:38 -04:00
|
|
|
|
public ITokenAuthentication TokenAuthenticator { get; }
|
2019-05-08 21:34:17 -04:00
|
|
|
|
public CancellationToken CancellationToken => _tokenSource.Token;
|
2019-04-08 13:29:48 -04:00
|
|
|
|
public string ExternalIPAddress { get; private set; }
|
2019-05-08 21:34:17 -04:00
|
|
|
|
public bool IsRestartRequested { get; private set; }
|
2020-01-13 21:06:57 -05:00
|
|
|
|
public IMiddlewareActionHandler MiddlewareActionHandler { get; }
|
2020-05-22 22:38:38 -04:00
|
|
|
|
public event EventHandler<GameEvent> OnGameEventExecuted;
|
2020-01-26 19:06:50 -05:00
|
|
|
|
private readonly List<IManagerCommand> _commands;
|
2020-04-04 13:40:23 -04:00
|
|
|
|
private readonly ILogger _logger;
|
2019-07-19 15:54:39 -04:00
|
|
|
|
private readonly List<MessageToken> MessageTokens;
|
|
|
|
|
private readonly ClientService ClientSvc;
|
2018-08-03 22:11:58 -04:00
|
|
|
|
readonly PenaltyService PenaltySvc;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
public IConfigurationHandler<ApplicationConfiguration> ConfigHandler;
|
2018-08-03 18:10:20 -04:00
|
|
|
|
readonly IPageList PageList;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
private readonly IMetaService _metaService;
|
2019-04-23 18:27:20 -04:00
|
|
|
|
private readonly TimeSpan _throttleTimeout = new TimeSpan(0, 1, 0);
|
2019-05-08 21:34:17 -04:00
|
|
|
|
private readonly CancellationTokenSource _tokenSource;
|
2019-07-16 16:27:19 -04:00
|
|
|
|
private readonly Dictionary<string, Task<IList>> _operationLookup = new Dictionary<string, Task<IList>>();
|
2020-01-26 19:06:50 -05:00
|
|
|
|
private readonly ITranslationLookup _translationLookup;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
private readonly IConfigurationHandler<CommandConfiguration> _commandConfiguration;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
private readonly IGameServerInstanceFactory _serverInstanceFactory;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
private readonly IParserRegexFactory _parserRegexFactory;
|
2020-04-04 13:40:23 -04:00
|
|
|
|
private readonly IEnumerable<IRegisterEvent> _customParserEvents;
|
2020-05-04 17:50:02 -04:00
|
|
|
|
private readonly IEventHandler _eventHandler;
|
2020-05-11 17:10:43 -04:00
|
|
|
|
private readonly IScriptCommandFactory _scriptCommandFactory;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
private readonly IMetaRegistration _metaRegistration;
|
2020-09-26 19:13:56 -04:00
|
|
|
|
private readonly IScriptPluginServiceResolver _scriptPluginServiceResolver;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ChangeHistoryService _changeHistoryService;
|
|
|
|
|
private readonly ApplicationConfiguration _appConfig;
|
2021-01-17 22:58:18 -05:00
|
|
|
|
public ConcurrentDictionary<long, GameEvent> ProcessingEvents { get; } = new ConcurrentDictionary<long, GameEvent>();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
public ApplicationManager(ILogger<ApplicationManager> logger, IMiddlewareActionHandler actionHandler, IEnumerable<IManagerCommand> commands,
|
2020-01-31 21:15:07 -05:00
|
|
|
|
ITranslationLookup translationLookup, IConfigurationHandler<CommandConfiguration> commandConfiguration,
|
2020-04-04 13:40:23 -04:00
|
|
|
|
IConfigurationHandler<ApplicationConfiguration> appConfigHandler, IGameServerInstanceFactory serverInstanceFactory,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
IEnumerable<IPlugin> plugins, IParserRegexFactory parserRegexFactory, IEnumerable<IRegisterEvent> customParserEvents,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
IEventHandler eventHandler, IScriptCommandFactory scriptCommandFactory, IDatabaseContextFactory contextFactory, IMetaService metaService,
|
2020-11-11 18:31:26 -05:00
|
|
|
|
IMetaRegistration metaRegistration, IScriptPluginServiceResolver scriptPluginServiceResolver, ClientService clientService, IServiceProvider serviceProvider,
|
2020-11-27 22:52:52 -05:00
|
|
|
|
ChangeHistoryService changeHistoryService, ApplicationConfiguration appConfig, PenaltyService penaltyService)
|
2015-07-03 00:10:01 -04:00
|
|
|
|
{
|
2020-01-13 21:06:57 -05:00
|
|
|
|
MiddlewareActionHandler = actionHandler;
|
2019-05-08 21:34:17 -04:00
|
|
|
|
_servers = new ConcurrentBag<Server>();
|
2017-06-19 13:58:01 -04:00
|
|
|
|
MessageTokens = new List<MessageToken>();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
ClientSvc = clientService;
|
2020-11-27 22:52:52 -05:00
|
|
|
|
PenaltySvc = penaltyService;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
ConfigHandler = appConfigHandler;
|
2018-04-18 16:46:53 -04:00
|
|
|
|
StartTime = DateTime.UtcNow;
|
2018-08-03 18:10:20 -04:00
|
|
|
|
PageList = new PageList();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
AdditionalEventParsers = new List<IEventParser>() { new BaseEventParser(parserRegexFactory, logger, _appConfig) };
|
|
|
|
|
AdditionalRConParsers = new List<IRConParser>() { new BaseRConParser(serviceProvider.GetRequiredService<ILogger<BaseRConParser>>(), parserRegexFactory) };
|
2019-05-02 23:33:38 -04:00
|
|
|
|
TokenAuthenticator = new TokenAuthentication();
|
2020-04-04 13:40:23 -04:00
|
|
|
|
_logger = logger;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
_metaService = metaService;
|
2019-05-08 21:34:17 -04:00
|
|
|
|
_tokenSource = new CancellationTokenSource();
|
2020-01-26 19:06:50 -05:00
|
|
|
|
_commands = commands.ToList();
|
|
|
|
|
_translationLookup = translationLookup;
|
|
|
|
|
_commandConfiguration = commandConfiguration;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
_serverInstanceFactory = serverInstanceFactory;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
_parserRegexFactory = parserRegexFactory;
|
2020-04-04 13:40:23 -04:00
|
|
|
|
_customParserEvents = customParserEvents;
|
2020-05-04 17:50:02 -04:00
|
|
|
|
_eventHandler = eventHandler;
|
2020-05-11 17:10:43 -04:00
|
|
|
|
_scriptCommandFactory = scriptCommandFactory;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
_metaRegistration = metaRegistration;
|
2020-09-26 19:13:56 -04:00
|
|
|
|
_scriptPluginServiceResolver = scriptPluginServiceResolver;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
_changeHistoryService = changeHistoryService;
|
|
|
|
|
_appConfig = appConfig;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
Plugins = plugins;
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
public IEnumerable<IPlugin> Plugins { get; }
|
|
|
|
|
|
2019-11-15 15:50:20 -05:00
|
|
|
|
public async Task ExecuteEvent(GameEvent newEvent)
|
2018-08-27 18:07:54 -04:00
|
|
|
|
{
|
2021-01-17 22:58:18 -05:00
|
|
|
|
ProcessingEvents.TryAdd(newEvent.Id, newEvent);
|
|
|
|
|
|
2018-10-02 13:39:08 -04:00
|
|
|
|
// the event has failed already
|
|
|
|
|
if (newEvent.Failed)
|
|
|
|
|
{
|
|
|
|
|
goto skip;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 18:07:54 -04:00
|
|
|
|
try
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
|
|
|
|
await newEvent.Owner.ExecuteEvent(newEvent);
|
2018-09-29 15:52:22 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
// save the event info to the database
|
2020-11-11 18:31:26 -05:00
|
|
|
|
await _changeHistoryService.Add(newEvent);
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 16:51:02 -04:00
|
|
|
|
catch (TaskCanceledException)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger.LogDebug("Received quit signal for event id {eventId}, so we are aborting early", newEvent.Id);
|
2019-10-09 16:51:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger.LogDebug("Received quit signal for event id {eventId}, so we are aborting early", newEvent.Id);
|
2019-10-09 16:51:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 18:07:54 -04:00
|
|
|
|
// this happens if a plugin requires login
|
|
|
|
|
catch (AuthorizationException ex)
|
|
|
|
|
{
|
2019-11-18 09:08:09 -05:00
|
|
|
|
newEvent.FailReason = EventFailReason.Permission;
|
2018-09-29 15:52:22 -04:00
|
|
|
|
newEvent.Origin.Tell($"{Utilities.CurrentLocalization.LocalizationIndex["COMMAND_NOTAUTHORIZED"]} - {ex.Message}");
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (NetworkException ex)
|
|
|
|
|
{
|
2019-11-18 09:08:09 -05:00
|
|
|
|
newEvent.FailReason = EventFailReason.Exception;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using (LogContext.PushProperty("Server", newEvent.Owner?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, ex.Message);
|
|
|
|
|
}
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (ServerException ex)
|
|
|
|
|
{
|
2019-11-18 09:08:09 -05:00
|
|
|
|
newEvent.FailReason = EventFailReason.Exception;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using (LogContext.PushProperty("Server", newEvent.Owner?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, ex.Message);
|
|
|
|
|
}
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-11-18 09:08:09 -05:00
|
|
|
|
newEvent.FailReason = EventFailReason.Exception;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_EXCEPTION"].FormatExt(newEvent.Owner));
|
|
|
|
|
using (LogContext.PushProperty("Server", newEvent.Owner?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Unexpected exception");
|
|
|
|
|
}
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
2018-09-23 20:45:54 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
skip:
|
2021-01-17 22:58:18 -05:00
|
|
|
|
if (newEvent.Type == EventType.Command && newEvent.ImpersonationOrigin == null)
|
|
|
|
|
{
|
|
|
|
|
var correlatedEvents =
|
|
|
|
|
ProcessingEvents.Values.Where(ev =>
|
|
|
|
|
ev.CorrelationId == newEvent.CorrelationId && ev.Id != newEvent.Id)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(correlatedEvents.Select(ev =>
|
|
|
|
|
ev.WaitAsync(Utilities.DefaultCommandTimeout, CancellationToken)));
|
|
|
|
|
newEvent.Output.AddRange(correlatedEvents.SelectMany(ev => ev.Output));
|
|
|
|
|
|
|
|
|
|
foreach (var correlatedEvent in correlatedEvents)
|
|
|
|
|
{
|
|
|
|
|
ProcessingEvents.Remove(correlatedEvent.Id, out _);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we don't want to remove events that are correlated to command
|
2021-01-17 23:12:18 -05:00
|
|
|
|
if (ProcessingEvents.Values.ToList()?.Count(gameEvent => gameEvent.CorrelationId == newEvent.CorrelationId) == 1)
|
2021-01-17 22:58:18 -05:00
|
|
|
|
{
|
|
|
|
|
ProcessingEvents.Remove(newEvent.Id, out _);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 18:07:54 -04:00
|
|
|
|
// tell anyone waiting for the output that we're done
|
2019-11-15 15:50:20 -05:00
|
|
|
|
newEvent.Complete();
|
2020-05-22 22:38:38 -04:00
|
|
|
|
OnGameEventExecuted?.Invoke(this, newEvent);
|
2018-03-14 01:36:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 22:42:24 -04:00
|
|
|
|
public IList<Server> GetServers()
|
2015-07-03 00:10:01 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return Servers;
|
2015-07-03 00:10:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-31 21:15:07 -05:00
|
|
|
|
public IList<IManagerCommand> GetCommands()
|
2015-08-17 16:38:42 -04:00
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
return _commands;
|
2015-08-17 16:38:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-08 21:34:17 -04:00
|
|
|
|
public async Task UpdateServerStates()
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-07-01 20:30:38 -04:00
|
|
|
|
// store the server hash code and task for it
|
2021-06-03 11:51:03 -04:00
|
|
|
|
var runningUpdateTasks = new Dictionary<long, (Task task, CancellationTokenSource tokenSource, DateTime startTime)>();
|
2018-04-26 20:19:42 -04:00
|
|
|
|
|
2019-05-08 21:34:17 -04:00
|
|
|
|
while (!_tokenSource.IsCancellationRequested)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-07-01 20:30:38 -04:00
|
|
|
|
// select the server ids that have completed the update task
|
|
|
|
|
var serverTasksToRemove = runningUpdateTasks
|
2021-06-03 11:51:03 -04:00
|
|
|
|
.Where(ut => ut.Value.task.Status == TaskStatus.RanToCompletion ||
|
|
|
|
|
ut.Value.task.Status == TaskStatus.Canceled || // we want to cancel if a task takes longer than 5 minutes
|
|
|
|
|
ut.Value.task.Status == TaskStatus.Faulted || DateTime.Now - ut.Value.startTime > TimeSpan.FromMinutes(5))
|
2018-07-01 20:30:38 -04:00
|
|
|
|
.Select(ut => ut.Key)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2018-07-04 22:09:42 -04:00
|
|
|
|
// this is to prevent the log reader from starting before the initial
|
2018-07-29 15:43:42 -04:00
|
|
|
|
// query of players on the server
|
2018-07-04 22:09:42 -04:00
|
|
|
|
if (serverTasksToRemove.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
IsInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 11:51:03 -04:00
|
|
|
|
// remove the update tasks as they have completed
|
|
|
|
|
foreach (var serverId in serverTasksToRemove)
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
if (!runningUpdateTasks[serverId].tokenSource.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
runningUpdateTasks[serverId].tokenSource.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-01 20:30:38 -04:00
|
|
|
|
runningUpdateTasks.Remove(serverId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// select the servers where the tasks have completed
|
2018-11-27 19:31:48 -05:00
|
|
|
|
var serverIds = Servers.Select(s => s.EndPoint).Except(runningUpdateTasks.Select(r => r.Key)).ToList();
|
|
|
|
|
foreach (var server in Servers.Where(s => serverIds.Contains(s.EndPoint)))
|
2018-07-01 20:30:38 -04:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
var tokenSource = new CancellationTokenSource();
|
|
|
|
|
runningUpdateTasks.Add(server.EndPoint, (Task.Run(async () =>
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
await server.ProcessUpdatesAsync(_tokenSource.Token).WithWaitCancellation(runningUpdateTasks[server.EndPoint].tokenSource.Token);
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using (LogContext.PushProperty("Server", server.ToString()))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(e, "Failed to update status");
|
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
2019-04-02 21:20:37 -04:00
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
server.IsInitialized = true;
|
|
|
|
|
}
|
2021-06-03 11:51:03 -04:00
|
|
|
|
}, tokenSource.Token), tokenSource, DateTime.Now));
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
2020-11-11 18:31:26 -05:00
|
|
|
|
|
2019-04-08 13:29:48 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2019-05-08 21:34:17 -04:00
|
|
|
|
await Task.Delay(ConfigHandler.Configuration().RConPollRate, _tokenSource.Token);
|
2019-04-08 13:29:48 -04:00
|
|
|
|
}
|
2019-08-24 11:02:53 -04:00
|
|
|
|
// if a cancellation is received, we want to return immediately after shutting down
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
foreach (var server in Servers.Where(s => serverIds.Contains(s.EndPoint)))
|
|
|
|
|
{
|
|
|
|
|
await server.ProcessUpdatesAsync(_tokenSource.Token);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public async Task Init()
|
2015-07-06 13:13:42 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
IsRunning = true;
|
2019-04-08 13:29:48 -04:00
|
|
|
|
ExternalIPAddress = await Utilities.GetExternalIP();
|
2019-02-04 20:38:24 -05:00
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
#region DATABASE
|
|
|
|
|
_logger.LogInformation("Beginning database migration sync");
|
|
|
|
|
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_START"]);
|
|
|
|
|
await ContextSeed.Seed(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
|
|
|
|
|
await DatabaseHousekeeping.RemoveOldRatings(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
|
|
|
|
|
_logger.LogInformation("Finished database migration sync");
|
|
|
|
|
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_END"]);
|
|
|
|
|
#endregion
|
|
|
|
|
|
2019-02-04 20:38:24 -05:00
|
|
|
|
#region PLUGINS
|
2020-02-11 17:44:06 -05:00
|
|
|
|
foreach (var plugin in Plugins)
|
2019-02-04 20:38:24 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
if (plugin is ScriptPlugin scriptPlugin)
|
|
|
|
|
{
|
2020-09-26 19:13:56 -04:00
|
|
|
|
await scriptPlugin.Initialize(this, _scriptCommandFactory, _scriptPluginServiceResolver);
|
2020-02-01 13:27:14 -05:00
|
|
|
|
scriptPlugin.Watcher.Changed += async (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-09-26 19:13:56 -04:00
|
|
|
|
await scriptPlugin.Initialize(this, _scriptCommandFactory, _scriptPluginServiceResolver);
|
2020-02-01 13:27:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_IMPORTER_ERROR"].FormatExt(scriptPlugin.Name));
|
|
|
|
|
_logger.LogError(ex, "Could not properly load plugin {plugin}", scriptPlugin.Name);
|
2020-02-01 13:27:14 -05:00
|
|
|
|
}
|
|
|
|
|
};
|
2020-01-31 21:15:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-01 13:27:14 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await plugin.OnLoadAsync(this);
|
|
|
|
|
}
|
2019-02-04 20:38:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger.LogError(ex, $"{_translationLookup["SERVER_ERROR_PLUGIN"]} {plugin.Name}");
|
2019-02-04 20:38:24 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2019-01-27 19:41:54 -05:00
|
|
|
|
#region CONFIG
|
2018-04-19 01:48:14 -04:00
|
|
|
|
// copy over default config if it doesn't exist
|
2020-11-11 18:31:26 -05:00
|
|
|
|
if (!_appConfig.Servers?.Any() ?? true)
|
2018-03-18 22:25:11 -04:00
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
var defaultConfig = new BaseConfigurationHandler<DefaultSettings>("DefaultSettings").Configuration();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
//ConfigHandler.Set((ApplicationConfiguration)new ApplicationConfiguration().Generate());
|
|
|
|
|
//var newConfig = ConfigHandler.Configuration();
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_appConfig.AutoMessages = defaultConfig.AutoMessages;
|
|
|
|
|
_appConfig.GlobalRules = defaultConfig.GlobalRules;
|
|
|
|
|
_appConfig.Maps = defaultConfig.Maps;
|
|
|
|
|
_appConfig.DisallowedClientNames = defaultConfig.DisallowedClientNames;
|
|
|
|
|
_appConfig.QuickMessages = defaultConfig.QuickMessages;
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
//if (newConfig.Servers == null)
|
2018-04-19 01:48:14 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
ConfigHandler.Set(_appConfig);
|
|
|
|
|
_appConfig.Servers = new ServerConfiguration[1];
|
2018-04-23 17:03:50 -04:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2019-02-04 20:38:24 -05:00
|
|
|
|
var serverConfig = new ServerConfiguration();
|
|
|
|
|
foreach (var parser in AdditionalRConParsers)
|
|
|
|
|
{
|
|
|
|
|
serverConfig.AddRConParser(parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var parser in AdditionalEventParsers)
|
|
|
|
|
{
|
|
|
|
|
serverConfig.AddEventParser(parser);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_appConfig.Servers = _appConfig.Servers.Where(_servers => _servers != null).Append((ServerConfiguration)serverConfig.Generate()).ToArray();
|
2020-01-31 21:15:07 -05:00
|
|
|
|
} while (Utilities.PromptBool(_translationLookup["SETUP_SERVER_SAVE"]));
|
2018-04-23 17:03:50 -04:00
|
|
|
|
|
2018-04-19 01:48:14 -04:00
|
|
|
|
await ConfigHandler.Save();
|
|
|
|
|
}
|
2018-03-18 22:25:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 21:31:32 -04:00
|
|
|
|
else
|
2018-04-18 16:46:53 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
if (string.IsNullOrEmpty(_appConfig.Id))
|
2018-04-18 16:46:53 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_appConfig.Id = Guid.NewGuid().ToString();
|
2018-04-18 16:46:53 -04:00
|
|
|
|
await ConfigHandler.Save();
|
|
|
|
|
}
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
if (string.IsNullOrEmpty(_appConfig.WebfrontBindUrl))
|
2018-04-19 01:48:14 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_appConfig.WebfrontBindUrl = "http://0.0.0.0:1624";
|
2018-04-19 01:48:14 -04:00
|
|
|
|
await ConfigHandler.Save();
|
|
|
|
|
}
|
2019-02-05 12:14:43 -05:00
|
|
|
|
|
2020-01-17 18:31:53 -05:00
|
|
|
|
var validator = new ApplicationConfigurationValidator();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
var validationResult = validator.Validate(_appConfig);
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
if (!validationResult.IsValid)
|
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
throw new ConfigurationException("MANAGER_CONFIGURATION_ERROR")
|
2020-01-17 18:31:53 -05:00
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
Errors = validationResult.Errors.Select(_error => _error.ErrorMessage).ToArray(),
|
|
|
|
|
ConfigurationFileName = ConfigHandler.FileName
|
2020-01-17 18:31:53 -05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
foreach (var serverConfig in _appConfig.Servers)
|
2019-02-05 12:14:43 -05:00
|
|
|
|
{
|
2019-02-09 16:35:13 -05:00
|
|
|
|
Migration.ConfigurationMigration.ModifyLogPath020919(serverConfig);
|
|
|
|
|
|
2019-02-05 12:14:43 -05:00
|
|
|
|
if (serverConfig.RConParserVersion == null || serverConfig.EventParserVersion == null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var parser in AdditionalRConParsers)
|
|
|
|
|
{
|
|
|
|
|
serverConfig.AddRConParser(parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var parser in AdditionalEventParsers)
|
|
|
|
|
{
|
|
|
|
|
serverConfig.AddEventParser(parser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverConfig.ModifyParsers();
|
|
|
|
|
}
|
2019-02-09 16:35:13 -05:00
|
|
|
|
await ConfigHandler.Save();
|
2019-02-05 12:14:43 -05:00
|
|
|
|
}
|
2018-04-18 16:46:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
if (_appConfig.Servers.Length == 0)
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2018-03-18 22:25:11 -04:00
|
|
|
|
throw new ServerException("A server configuration in IW4MAdminSettings.json is invalid");
|
2018-11-25 21:00:36 -05:00
|
|
|
|
}
|
2018-03-18 22:25:11 -04:00
|
|
|
|
|
2018-04-21 18:18:20 -04:00
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
2020-11-11 18:31:26 -05:00
|
|
|
|
Utilities.EncodingType = Encoding.GetEncoding(!string.IsNullOrEmpty(_appConfig.CustomParserEncoding) ? _appConfig.CustomParserEncoding : "windows-1252");
|
2018-04-21 18:18:20 -04:00
|
|
|
|
|
2018-07-29 15:43:42 -04:00
|
|
|
|
#endregion
|
2019-01-27 19:41:54 -05:00
|
|
|
|
|
2018-07-29 15:43:42 -04:00
|
|
|
|
#region COMMANDS
|
2020-11-27 22:52:52 -05:00
|
|
|
|
if (await ClientSvc.HasOwnerAsync(_tokenSource.Token))
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2020-01-26 19:06:50 -05:00
|
|
|
|
_commands.RemoveAll(_cmd => _cmd.GetType() == typeof(OwnerCommand));
|
2018-11-25 21:00:36 -05:00
|
|
|
|
}
|
2017-11-15 16:04:13 -05:00
|
|
|
|
|
2020-01-31 21:15:07 -05:00
|
|
|
|
List<IManagerCommand> commandsToAddToConfig = new List<IManagerCommand>();
|
|
|
|
|
var cmdConfig = _commandConfiguration.Configuration();
|
|
|
|
|
|
|
|
|
|
if (cmdConfig == null)
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
cmdConfig = new CommandConfiguration();
|
|
|
|
|
commandsToAddToConfig.AddRange(_commands);
|
2020-01-26 19:06:50 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-31 21:15:07 -05:00
|
|
|
|
else
|
2020-01-26 19:06:50 -05:00
|
|
|
|
{
|
2020-05-30 15:06:04 -04:00
|
|
|
|
var unsavedCommands = _commands.Where(_cmd => !cmdConfig.Commands.Keys.Contains(_cmd.CommandConfigNameForType()));
|
2020-01-31 21:15:07 -05:00
|
|
|
|
commandsToAddToConfig.AddRange(unsavedCommands);
|
|
|
|
|
}
|
2020-01-26 19:06:50 -05:00
|
|
|
|
|
2020-07-31 21:40:03 -04:00
|
|
|
|
// this is because I want to store the command prefix in IW4MAdminSettings, but can't easily
|
|
|
|
|
// inject it to all the places that need it
|
2020-11-11 18:31:26 -05:00
|
|
|
|
cmdConfig.CommandPrefix = _appConfig.CommandPrefix;
|
|
|
|
|
cmdConfig.BroadcastCommandPrefix = _appConfig.BroadcastCommandPrefix;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
|
2020-01-31 21:15:07 -05:00
|
|
|
|
foreach (var cmd in commandsToAddToConfig)
|
|
|
|
|
{
|
2020-05-30 15:06:04 -04:00
|
|
|
|
cmdConfig.Commands.Add(cmd.CommandConfigNameForType(),
|
2020-01-31 21:15:07 -05:00
|
|
|
|
new CommandProperties()
|
2020-01-26 19:06:50 -05:00
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
Name = cmd.Name,
|
|
|
|
|
Alias = cmd.Alias,
|
2020-04-26 22:12:49 -04:00
|
|
|
|
MinimumPermission = cmd.Permission,
|
2020-09-26 18:17:21 -04:00
|
|
|
|
AllowImpersonation = cmd.AllowImpersonation,
|
|
|
|
|
SupportedGames = cmd.SupportedGames
|
2020-01-31 21:15:07 -05:00
|
|
|
|
});
|
2018-11-25 21:00:36 -05:00
|
|
|
|
}
|
2020-01-31 21:15:07 -05:00
|
|
|
|
|
|
|
|
|
_commandConfiguration.Set(cmdConfig);
|
|
|
|
|
await _commandConfiguration.Save();
|
2018-07-29 15:43:42 -04:00
|
|
|
|
#endregion
|
2017-06-19 13:58:01 -04:00
|
|
|
|
|
2020-08-17 22:21:11 -04:00
|
|
|
|
_metaRegistration.Register();
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2020-04-04 13:40:23 -04:00
|
|
|
|
#region CUSTOM_EVENTS
|
|
|
|
|
foreach (var customEvent in _customParserEvents.SelectMany(_events => _events.Events))
|
|
|
|
|
{
|
|
|
|
|
foreach (var parser in AdditionalEventParsers)
|
|
|
|
|
{
|
|
|
|
|
parser.RegisterCustomEvent(customEvent.Item1, customEvent.Item2, customEvent.Item3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
Console.WriteLine(_translationLookup["MANAGER_COMMUNICATION_INFO"]);
|
2019-05-08 21:34:17 -04:00
|
|
|
|
await InitializeServers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task InitializeServers()
|
|
|
|
|
{
|
|
|
|
|
var config = ConfigHandler.Configuration();
|
2019-02-24 20:35:59 -05:00
|
|
|
|
int successServers = 0;
|
|
|
|
|
Exception lastException = null;
|
|
|
|
|
|
2018-04-16 16:31:14 -04:00
|
|
|
|
async Task Init(ServerConfiguration Conf)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
// todo: this might not always be an IW4MServer
|
|
|
|
|
var ServerInstance = _serverInstanceFactory.CreateServer(Conf, this) as IW4MServer;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using (LogContext.PushProperty("Server", ServerInstance.ToString()))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Beginning server communication initialization");
|
|
|
|
|
await ServerInstance.Initialize();
|
2018-04-16 16:31:14 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_servers.Add(ServerInstance);
|
|
|
|
|
Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_MONITORING_TEXT"].FormatExt(ServerInstance.Hostname.StripColors()));
|
|
|
|
|
_logger.LogInformation("Finishing initialization and now monitoring [{server}]", ServerInstance.Hostname, ServerInstance.ToString());
|
|
|
|
|
}
|
2018-04-16 16:31:14 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
// add the start event for this server
|
2018-08-30 21:53:00 -04:00
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
Type = EventType.Start,
|
2018-08-30 21:53:00 -04:00
|
|
|
|
Data = $"{ServerInstance.GameName} started",
|
|
|
|
|
Owner = ServerInstance
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
AddEvent(e);
|
2019-02-24 20:35:59 -05:00
|
|
|
|
successServers++;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (ServerException e)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_UNFIXABLE"].FormatExt($"[{Conf.IPAddress}:{Conf.Port}]"));
|
|
|
|
|
using (LogContext.PushProperty("Server", $"{Conf.IPAddress}:{Conf.Port}"))
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger.LogError(e, "Unexpected exception occurred during initialization");
|
2018-04-16 16:31:14 -04:00
|
|
|
|
}
|
2019-02-24 20:35:59 -05:00
|
|
|
|
lastException = e;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(config.Servers.Select(c => Init(c)).ToArray());
|
2019-02-24 20:35:59 -05:00
|
|
|
|
|
2019-05-03 21:13:51 -04:00
|
|
|
|
if (successServers == 0)
|
|
|
|
|
{
|
|
|
|
|
throw lastException;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 18:31:53 -05:00
|
|
|
|
if (successServers != config.Servers.Length)
|
2019-02-24 20:35:59 -05:00
|
|
|
|
{
|
|
|
|
|
if (!Utilities.PromptBool(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_START_WITH_ERRORS"]))
|
|
|
|
|
{
|
|
|
|
|
throw lastException;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-03 00:10:01 -04:00
|
|
|
|
}
|
2019-05-08 21:34:17 -04:00
|
|
|
|
|
2020-06-30 17:39:32 -04:00
|
|
|
|
public async Task Start() => await UpdateServerStates();
|
2015-07-06 15:51:08 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public void Stop()
|
2015-07-06 15:51:08 -04:00
|
|
|
|
{
|
2019-05-08 21:34:17 -04:00
|
|
|
|
_tokenSource.Cancel();
|
2020-05-04 17:50:02 -04:00
|
|
|
|
IsRunning = false;
|
2019-05-08 21:34:17 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Restart()
|
|
|
|
|
{
|
|
|
|
|
IsRestartRequested = true;
|
|
|
|
|
Stop();
|
2015-07-06 15:51:08 -04:00
|
|
|
|
}
|
2017-05-27 18:08:04 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
[Obsolete]
|
|
|
|
|
public ObsoleteLogger GetLogger(long serverId)
|
2017-05-27 19:29:20 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
return _serviceProvider.GetRequiredService<ObsoleteLogger>();
|
2017-05-27 19:29:20 -04:00
|
|
|
|
}
|
2017-05-31 01:31:56 -04:00
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
public IList<MessageToken> GetMessageTokens()
|
2017-05-31 01:31:56 -04:00
|
|
|
|
{
|
|
|
|
|
return MessageTokens;
|
|
|
|
|
}
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
public IList<EFClient> GetActiveClients()
|
|
|
|
|
{
|
2019-07-29 13:08:25 -04:00
|
|
|
|
// we're adding another to list here so we don't get a collection modified exception..
|
|
|
|
|
return _servers.SelectMany(s => s.Clients).ToList().Where(p => p != null).ToList();
|
2018-11-25 21:00:36 -05:00
|
|
|
|
}
|
2017-08-17 19:28:08 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
public ClientService GetClientService()
|
|
|
|
|
{
|
|
|
|
|
return ClientSvc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PenaltyService GetPenaltyService()
|
|
|
|
|
{
|
|
|
|
|
return PenaltySvc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfigurationHandler<ApplicationConfiguration> GetApplicationSettings()
|
|
|
|
|
{
|
|
|
|
|
return ConfigHandler;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public void AddEvent(GameEvent gameEvent)
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
_eventHandler.HandleEvent(this, gameEvent);
|
2018-11-25 21:00:36 -05:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
public IPageList GetPageList()
|
|
|
|
|
{
|
|
|
|
|
return PageList;
|
|
|
|
|
}
|
2019-01-26 21:33:37 -05:00
|
|
|
|
|
2020-01-21 19:08:18 -05:00
|
|
|
|
public IRConParser GenerateDynamicRConParser(string name)
|
2019-01-27 19:41:54 -05:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
return new DynamicRConParser(_serviceProvider.GetRequiredService<ILogger<BaseRConParser>>(), _parserRegexFactory)
|
2020-01-21 19:08:18 -05:00
|
|
|
|
{
|
|
|
|
|
Name = name
|
|
|
|
|
};
|
2019-01-27 19:41:54 -05:00
|
|
|
|
}
|
2019-01-26 21:33:37 -05:00
|
|
|
|
|
2020-01-21 19:08:18 -05:00
|
|
|
|
public IEventParser GenerateDynamicEventParser(string name)
|
2019-01-27 19:41:54 -05:00
|
|
|
|
{
|
2020-07-31 21:40:03 -04:00
|
|
|
|
return new DynamicEventParser(_parserRegexFactory, _logger, ConfigHandler.Configuration())
|
2020-01-21 19:08:18 -05:00
|
|
|
|
{
|
|
|
|
|
Name = name
|
|
|
|
|
};
|
2019-01-27 19:41:54 -05:00
|
|
|
|
}
|
2019-07-16 16:27:19 -04:00
|
|
|
|
|
|
|
|
|
public async Task<IList<T>> ExecuteSharedDatabaseOperation<T>(string operationName)
|
|
|
|
|
{
|
|
|
|
|
var result = await _operationLookup[operationName];
|
|
|
|
|
return (IList<T>)result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterSharedDatabaseOperation(Task<IList> operation, string operationName)
|
|
|
|
|
{
|
|
|
|
|
_operationLookup.Add(operationName, operation);
|
|
|
|
|
}
|
2020-05-11 17:10:43 -04:00
|
|
|
|
|
|
|
|
|
public void AddAdditionalCommand(IManagerCommand command)
|
|
|
|
|
{
|
|
|
|
|
if (_commands.Any(_command => _command.Name == command.Name || _command.Alias == command.Alias))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException($"Duplicate command name or alias ({command.Name}, {command.Alias})");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_commands.Add(command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveCommandByName(string commandName) => _commands.RemoveAll(_command => _command.Name == commandName);
|
2015-07-03 00:10:01 -04:00
|
|
|
|
}
|
|
|
|
|
}
|