2018-11-25 21:00:36 -05:00
|
|
|
|
using IW4MAdmin.Application.API.Master;
|
2019-01-26 21:33:37 -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;
|
2019-01-26 21:33:37 -05: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-08-28 17:32:59 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2019-02-22 20:06:51 -05:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
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;
|
2019-10-07 18:35:37 -04:00
|
|
|
|
using static SharedLibraryCore.GameEvent;
|
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();
|
2018-10-06 12:47:14 -04:00
|
|
|
|
public ILogger Logger => GetLogger(0);
|
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 AliasService AliasSvc;
|
|
|
|
|
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-01-13 21:06:57 -05:00
|
|
|
|
private readonly Dictionary<long, ILogger> _loggers = new Dictionary<long, ILogger>();
|
2019-02-22 20:06:51 -05:00
|
|
|
|
private readonly MetaService _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;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2020-01-31 21:15:07 -05:00
|
|
|
|
public ApplicationManager(ILogger logger, IMiddlewareActionHandler actionHandler, IEnumerable<IManagerCommand> commands,
|
|
|
|
|
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-05-24 22:22:26 -04:00
|
|
|
|
IEventHandler eventHandler, IScriptCommandFactory scriptCommandFactory, IDatabaseContextFactory contextFactory)
|
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-05-24 22:22:26 -04:00
|
|
|
|
ClientSvc = new ClientService(contextFactory);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
AliasSvc = new AliasService();
|
|
|
|
|
PenaltySvc = new 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-07-31 21:40:03 -04:00
|
|
|
|
AdditionalEventParsers = new List<IEventParser>() { new BaseEventParser(parserRegexFactory, logger, appConfigHandler.Configuration()) };
|
2020-04-01 15:11:56 -04:00
|
|
|
|
AdditionalRConParsers = new List<IRConParser>() { new BaseRConParser(parserRegexFactory) };
|
2019-05-02 23:33:38 -04:00
|
|
|
|
TokenAuthenticator = new TokenAuthentication();
|
2020-04-04 13:40:23 -04:00
|
|
|
|
_logger = logger;
|
2019-02-22 20:06:51 -05:00
|
|
|
|
_metaService = new MetaService();
|
2019-05-08 21:34:17 -04:00
|
|
|
|
_tokenSource = new CancellationTokenSource();
|
2020-01-13 21:06:57 -05:00
|
|
|
|
_loggers.Add(0, logger);
|
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-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
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
#if DEBUG == true
|
2019-11-15 15:50:20 -05:00
|
|
|
|
Logger.WriteDebug($"Entering event process for {newEvent.Id}");
|
2018-09-29 15:52:22 -04:00
|
|
|
|
#endif
|
2018-09-23 20:45:54 -04:00
|
|
|
|
|
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
|
|
|
|
|
var changeHistorySvc = new ChangeHistoryService();
|
2019-11-15 15:50:20 -05:00
|
|
|
|
await changeHistorySvc.Add(newEvent);
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
2018-08-27 18:07:54 -04:00
|
|
|
|
#if DEBUG
|
2018-09-02 17:59:27 -04:00
|
|
|
|
Logger.WriteDebug($"Processed event with id {newEvent.Id}");
|
2018-08-27 18:07:54 -04:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 16:51:02 -04:00
|
|
|
|
catch (TaskCanceledException)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo($"Received quit signal for event id {newEvent.Id}, so we are aborting early");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo($"Received quit signal for event id {newEvent.Id}, so we are aborting early");
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2018-08-27 18:07:54 -04:00
|
|
|
|
Logger.WriteError(ex.Message);
|
2018-09-23 20:45:54 -04:00
|
|
|
|
Logger.WriteDebug(ex.GetExceptionInfo());
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (ServerException ex)
|
|
|
|
|
{
|
2019-11-18 09:08:09 -05:00
|
|
|
|
newEvent.FailReason = EventFailReason.Exception;
|
2018-08-27 18:07:54 -04:00
|
|
|
|
Logger.WriteWarning(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-11-18 09:08:09 -05:00
|
|
|
|
newEvent.FailReason = EventFailReason.Exception;
|
2019-04-25 14:00:54 -04:00
|
|
|
|
Logger.WriteError(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_EXCEPTION"].FormatExt(newEvent.Owner));
|
2018-09-23 20:45:54 -04:00
|
|
|
|
Logger.WriteDebug(ex.GetExceptionInfo());
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
2018-09-23 20:45:54 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
skip:
|
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);
|
|
|
|
|
|
2019-11-15 15:50:20 -05:00
|
|
|
|
#if DEBUG == true
|
|
|
|
|
Logger.WriteDebug($"Exiting event process for {newEvent.Id}");
|
|
|
|
|
#endif
|
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
|
2018-11-27 19:31:48 -05:00
|
|
|
|
var runningUpdateTasks = new Dictionary<long, Task>();
|
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
|
2018-08-27 18:07:54 -04:00
|
|
|
|
.Where(ut => ut.Value.Status == TaskStatus.RanToCompletion ||
|
|
|
|
|
ut.Value.Status == TaskStatus.Canceled ||
|
|
|
|
|
ut.Value.Status == TaskStatus.Faulted)
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-01 20:30:38 -04:00
|
|
|
|
// remove the update tasks as they have completd
|
2018-11-27 19:31:48 -05:00
|
|
|
|
foreach (long serverId in serverTasksToRemove)
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
runningUpdateTasks.Add(server.EndPoint, Task.Run(async () =>
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-05-08 21:34:17 -04:00
|
|
|
|
await server.ProcessUpdatesAsync(_tokenSource.Token);
|
|
|
|
|
|
2019-04-23 18:27:20 -04:00
|
|
|
|
if (server.Throttled)
|
|
|
|
|
{
|
2019-05-08 21:34:17 -04:00
|
|
|
|
await Task.Delay((int)_throttleTimeout.TotalMilliseconds, _tokenSource.Token);
|
2019-04-23 18:27:20 -04:00
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteWarning($"Failed to update status for {server}");
|
2018-09-23 20:45:54 -04:00
|
|
|
|
Logger.WriteDebug(e.GetExceptionInfo());
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
2019-04-02 21:20:37 -04:00
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
server.IsInitialized = true;
|
|
|
|
|
}
|
2018-06-30 21:55:16 -04:00
|
|
|
|
}));
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
#if DEBUG
|
2018-07-01 20:30:38 -04:00
|
|
|
|
Logger.WriteDebug($"{runningUpdateTasks.Count} servers queued for stats updates");
|
2018-04-28 01:22:18 -04:00
|
|
|
|
ThreadPool.GetMaxThreads(out int workerThreads, out int n);
|
|
|
|
|
ThreadPool.GetAvailableThreads(out int availableThreads, out int m);
|
|
|
|
|
Logger.WriteDebug($"There are {workerThreads - availableThreads} active threading tasks");
|
|
|
|
|
#endif
|
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
|
|
|
|
|
|
|
|
|
#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-05-11 17:10:43 -04:00
|
|
|
|
await scriptPlugin.Initialize(this, _scriptCommandFactory);
|
2020-02-01 13:27:14 -05:00
|
|
|
|
scriptPlugin.Watcher.Changed += async (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-05-11 17:10:43 -04:00
|
|
|
|
await scriptPlugin.Initialize(this, _scriptCommandFactory);
|
2020-02-01 13:27:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteError(Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_IMPORTER_ERROR"].FormatExt(scriptPlugin.Name));
|
|
|
|
|
Logger.WriteDebug(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
};
|
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-01-31 21:15:07 -05:00
|
|
|
|
Logger.WriteError($"{_translationLookup["SERVER_ERROR_PLUGIN"]} {plugin.Name}");
|
2019-02-04 20:38:24 -05:00
|
|
|
|
Logger.WriteDebug(ex.GetExceptionInfo());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2019-01-27 19:41:54 -05:00
|
|
|
|
#region CONFIG
|
2019-01-27 20:45:35 -05:00
|
|
|
|
var config = ConfigHandler.Configuration();
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
|
|
|
|
// copy over default config if it doesn't exist
|
|
|
|
|
if (config == null)
|
2018-03-18 22:25:11 -04:00
|
|
|
|
{
|
2018-04-19 01:48:14 -04:00
|
|
|
|
var defaultConfig = new BaseConfigurationHandler<DefaultConfiguration>("DefaultSettings").Configuration();
|
|
|
|
|
ConfigHandler.Set((ApplicationConfiguration)new ApplicationConfiguration().Generate());
|
|
|
|
|
var newConfig = ConfigHandler.Configuration();
|
|
|
|
|
|
|
|
|
|
newConfig.AutoMessages = defaultConfig.AutoMessages;
|
|
|
|
|
newConfig.GlobalRules = defaultConfig.GlobalRules;
|
|
|
|
|
newConfig.Maps = defaultConfig.Maps;
|
2019-04-08 21:31:32 -04:00
|
|
|
|
newConfig.DisallowedClientNames = defaultConfig.DisallowedClientNames;
|
2019-03-31 20:56:31 -04:00
|
|
|
|
newConfig.QuickMessages = defaultConfig.QuickMessages;
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
|
|
|
|
if (newConfig.Servers == null)
|
|
|
|
|
{
|
|
|
|
|
ConfigHandler.Set(newConfig);
|
2020-01-17 18:31:53 -05:00
|
|
|
|
newConfig.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-01-26 16:40:00 -05:00
|
|
|
|
newConfig.Servers = newConfig.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
|
|
|
|
config = newConfig;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(config.Id))
|
|
|
|
|
{
|
|
|
|
|
config.Id = Guid.NewGuid().ToString();
|
|
|
|
|
await ConfigHandler.Save();
|
|
|
|
|
}
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(config.WebfrontBindUrl))
|
|
|
|
|
{
|
2018-09-23 20:45:54 -04:00
|
|
|
|
config.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();
|
|
|
|
|
var validationResult = validator.Validate(config);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 12:14:43 -05:00
|
|
|
|
foreach (var serverConfig in config.Servers)
|
|
|
|
|
{
|
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-01-17 18:31:53 -05:00
|
|
|
|
if (config.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);
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Utilities.EncodingType = Encoding.GetEncoding(!string.IsNullOrEmpty(config.CustomParserEncoding) ? config.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
|
|
|
|
|
|
|
|
|
#region DATABASE
|
|
|
|
|
using (var db = new DatabaseContext(GetApplicationSettings().Configuration()?.ConnectionString,
|
|
|
|
|
GetApplicationSettings().Configuration()?.DatabaseProvider))
|
|
|
|
|
{
|
|
|
|
|
await new ContextSeed(db).Seed();
|
2019-05-08 21:34:17 -04:00
|
|
|
|
}
|
2019-01-27 19:41:54 -05:00
|
|
|
|
#endregion
|
|
|
|
|
|
2018-07-29 15:43:42 -04:00
|
|
|
|
#region COMMANDS
|
2020-01-26 19:06:50 -05:00
|
|
|
|
if (ClientSvc.GetOwners().Result.Count > 0)
|
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
|
|
|
|
|
cmdConfig.CommandPrefix = config.CommandPrefix;
|
|
|
|
|
cmdConfig.BroadcastCommandPrefix = config.BroadcastCommandPrefix;
|
|
|
|
|
|
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,
|
|
|
|
|
AllowImpersonation = cmd.AllowImpersonation
|
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
|
|
|
|
|
2019-02-22 20:06:51 -05:00
|
|
|
|
#region META
|
2019-03-29 22:56:56 -04:00
|
|
|
|
async Task<List<ProfileMeta>> getProfileMeta(int clientId, int offset, int count, DateTime? startAt)
|
2019-02-22 20:06:51 -05:00
|
|
|
|
{
|
2019-03-27 20:40:26 -04:00
|
|
|
|
var metaList = new List<ProfileMeta>();
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
// we don't want to return anything because it means we're trying to retrieve paged meta data
|
|
|
|
|
if (count > 1)
|
2019-02-22 20:06:51 -05:00
|
|
|
|
{
|
2019-03-27 20:40:26 -04:00
|
|
|
|
return metaList;
|
|
|
|
|
}
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
var lastMapMeta = await _metaService.GetPersistentMeta("LastMapPlayed", new EFClient() { ClientId = clientId });
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
if (lastMapMeta != null)
|
2019-03-27 20:40:26 -04:00
|
|
|
|
{
|
2019-03-29 22:56:56 -04:00
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Id = lastMapMeta.MetaId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_MAP"],
|
|
|
|
|
Value = lastMapMeta.Value,
|
|
|
|
|
Show = true,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-29 22:56:56 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
var lastServerMeta = await _metaService.GetPersistentMeta("LastServerPlayed", new EFClient() { ClientId = clientId });
|
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
if (lastServerMeta != null)
|
2019-02-22 20:06:51 -05:00
|
|
|
|
{
|
2019-03-29 22:56:56 -04:00
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Id = lastServerMeta.MetaId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_SERVER"],
|
|
|
|
|
Value = lastServerMeta.Value,
|
|
|
|
|
Show = true,
|
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
var client = await GetClientService().Get(clientId);
|
|
|
|
|
|
2020-04-25 20:01:26 -04:00
|
|
|
|
if (client == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.WriteWarning($"No client found with id {clientId} when generating profile meta");
|
|
|
|
|
return metaList;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Id = client.ClientId,
|
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_TIME_HOURS"]} {Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_PLAYER"]}",
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = Math.Round(client.TotalConnectionTime / 3600.0, 1).ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Show = true,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 1,
|
|
|
|
|
Order = 0,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Id = client.ClientId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_FSEEN"],
|
|
|
|
|
Value = Utilities.GetTimePassed(client.FirstConnection, false),
|
|
|
|
|
Show = true,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 1,
|
|
|
|
|
Order = 1,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Id = client.ClientId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_LSEEN"],
|
|
|
|
|
Value = Utilities.GetTimePassed(client.LastConnection, false),
|
|
|
|
|
Show = true,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 1,
|
|
|
|
|
Order = 2,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Id = client.ClientId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_CONNECTIONS"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = client.Connections.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Show = true,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 1,
|
|
|
|
|
Order = 3,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
metaList.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_MASKED"],
|
|
|
|
|
Value = client.Masked ? Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_TRUE"] : Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_FALSE"],
|
|
|
|
|
Sensitive = true,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 1,
|
|
|
|
|
Order = 4,
|
2019-03-29 22:56:56 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
return metaList;
|
2019-03-29 22:56:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task<List<ProfileMeta>> getPenaltyMeta(int clientId, int offset, int count, DateTime? startAt)
|
|
|
|
|
{
|
|
|
|
|
if (count <= 1)
|
|
|
|
|
{
|
|
|
|
|
return new List<ProfileMeta>();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 20:56:31 -04:00
|
|
|
|
var penalties = await GetPenaltyService().GetClientPenaltyForMetaAsync(clientId, count, offset, startAt);
|
2019-03-29 22:56:56 -04:00
|
|
|
|
|
|
|
|
|
return penalties.Select(_penalty => new ProfileMeta()
|
|
|
|
|
{
|
2019-03-31 20:56:31 -04:00
|
|
|
|
Id = _penalty.Id,
|
2019-03-29 22:56:56 -04:00
|
|
|
|
Type = _penalty.PunisherId == clientId ? ProfileMeta.MetaType.Penalized : ProfileMeta.MetaType.ReceivedPenalty,
|
2019-03-31 20:56:31 -04:00
|
|
|
|
Value = _penalty,
|
|
|
|
|
When = _penalty.TimePunished,
|
|
|
|
|
Sensitive = _penalty.Sensitive
|
2019-03-29 22:56:56 -04:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2019-02-22 20:06:51 -05:00
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
MetaService.AddRuntimeMeta(getProfileMeta);
|
2019-03-29 22:56:56 -04:00
|
|
|
|
MetaService.AddRuntimeMeta(getPenaltyMeta);
|
2019-02-22 20:06:51 -05:00
|
|
|
|
#endregion
|
|
|
|
|
|
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
|
|
|
|
|
|
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;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
await ServerInstance.Initialize();
|
|
|
|
|
|
2019-05-08 21:34:17 -04:00
|
|
|
|
_servers.Add(ServerInstance);
|
2018-04-16 16:31:14 -04:00
|
|
|
|
|
2019-04-09 16:02:49 -04:00
|
|
|
|
Logger.WriteVerbose(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_MONITORING_TEXT"].FormatExt(ServerInstance.Hostname));
|
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()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Start,
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Logger.WriteError(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_UNFIXABLE"].FormatExt($"[{Conf.IPAddress}:{Conf.Port}]"));
|
2019-02-24 20:35:59 -05:00
|
|
|
|
|
2018-04-16 16:31:14 -04:00
|
|
|
|
if (e.GetType() == typeof(DvarException))
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2019-05-03 21:13:51 -04:00
|
|
|
|
Logger.WriteDebug($"{e.Message} {(e.GetType() == typeof(DvarException) ? $"({Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR_HELP"]})" : "")}");
|
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
|
|
|
|
|
2018-11-27 19:31:48 -05:00
|
|
|
|
public ILogger GetLogger(long serverId)
|
2017-05-27 19:29:20 -04:00
|
|
|
|
{
|
2020-01-13 21:06:57 -05:00
|
|
|
|
if (_loggers.ContainsKey(serverId))
|
2018-10-06 12:47:14 -04:00
|
|
|
|
{
|
2020-01-13 21:06:57 -05:00
|
|
|
|
return _loggers[serverId];
|
2018-10-06 12:47:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-13 21:06:57 -05:00
|
|
|
|
var newLogger = new Logger($"IW4MAdmin-Server-{serverId}");
|
2018-10-06 12:47:14 -04:00
|
|
|
|
|
2020-01-13 21:06:57 -05:00
|
|
|
|
_loggers.Add(serverId, newLogger);
|
2018-10-06 12:47:14 -04:00
|
|
|
|
return newLogger;
|
|
|
|
|
}
|
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 AliasService GetAliasService()
|
|
|
|
|
{
|
|
|
|
|
return AliasSvc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-04-01 15:11:56 -04:00
|
|
|
|
return new DynamicRConParser(_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
|
|
|
|
}
|
|
|
|
|
}
|