private async void OnGameEvent(object sender, GameEventArgs args) { #if DEBUG == true Logger.WriteDebug($"Entering event process for {args.Event.Id}"); #endif var newEvent = args.Event; // the event has failed already if (newEvent.Failed) { goto skip; } try { await newEvent.Owner.ExecuteEvent(newEvent); // save the event info to the database var changeHistorySvc = new ChangeHistoryService(); await changeHistorySvc.Add(args.Event); #if DEBUG Logger.WriteDebug($"Processed event with id {newEvent.Id}"); #endif } // this happens if a plugin requires login catch (AuthorizationException ex) { newEvent.FailReason = GameEvent.EventFailReason.Permission; newEvent.Origin.Tell($"{Utilities.CurrentLocalization.LocalizationIndex["COMMAND_NOTAUTHORIZED"]} - {ex.Message}"); } catch (NetworkException ex) { newEvent.FailReason = GameEvent.EventFailReason.Exception; Logger.WriteError(ex.Message); Logger.WriteDebug(ex.GetExceptionInfo()); } catch (ServerException ex) { newEvent.FailReason = GameEvent.EventFailReason.Exception; Logger.WriteWarning(ex.Message); } catch (Exception ex) { newEvent.FailReason = GameEvent.EventFailReason.Exception; Logger.WriteError(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_EXCEPTION"].FormatExt(newEvent.Owner)); Logger.WriteDebug(ex.GetExceptionInfo()); } skip: // tell anyone waiting for the output that we're done newEvent.OnProcessed.Set(); }
public ApplicationManager(ILogger <ApplicationManager> logger, IMiddlewareActionHandler actionHandler, IEnumerable <IManagerCommand> commands, ITranslationLookup translationLookup, IConfigurationHandler <CommandConfiguration> commandConfiguration, IConfigurationHandler <ApplicationConfiguration> appConfigHandler, IGameServerInstanceFactory serverInstanceFactory, IEnumerable <IPlugin> plugins, IParserRegexFactory parserRegexFactory, IEnumerable <IRegisterEvent> customParserEvents, IEventHandler eventHandler, IScriptCommandFactory scriptCommandFactory, IDatabaseContextFactory contextFactory, IMetaService metaService, IMetaRegistration metaRegistration, IScriptPluginServiceResolver scriptPluginServiceResolver, ClientService clientService, IServiceProvider serviceProvider, ChangeHistoryService changeHistoryService, ApplicationConfiguration appConfig, PenaltyService penaltyService) { MiddlewareActionHandler = actionHandler; _servers = new ConcurrentBag <Server>(); MessageTokens = new List <MessageToken>(); ClientSvc = clientService; PenaltySvc = penaltyService; ConfigHandler = appConfigHandler; StartTime = DateTime.UtcNow; PageList = new PageList(); AdditionalEventParsers = new List <IEventParser>() { new BaseEventParser(parserRegexFactory, logger, _appConfig) }; AdditionalRConParsers = new List <IRConParser>() { new BaseRConParser(serviceProvider.GetRequiredService <ILogger <BaseRConParser> >(), parserRegexFactory) }; TokenAuthenticator = new TokenAuthentication(); _logger = logger; _metaService = metaService; _tokenSource = new CancellationTokenSource(); _commands = commands.ToList(); _translationLookup = translationLookup; _commandConfiguration = commandConfiguration; _serverInstanceFactory = serverInstanceFactory; _parserRegexFactory = parserRegexFactory; _customParserEvents = customParserEvents; _eventHandler = eventHandler; _scriptCommandFactory = scriptCommandFactory; _metaRegistration = metaRegistration; _scriptPluginServiceResolver = scriptPluginServiceResolver; _serviceProvider = serviceProvider; _changeHistoryService = changeHistoryService; _appConfig = appConfig; Plugins = plugins; }
public async Task ExecuteEvent(GameEvent newEvent) { #if DEBUG == true Logger.WriteDebug($"Entering event process for {newEvent.Id}"); #endif // the event has failed already if (newEvent.Failed) { goto skip; } try { await newEvent.Owner.ExecuteEvent(newEvent); // save the event info to the database var changeHistorySvc = new ChangeHistoryService(); await changeHistorySvc.Add(newEvent); #if DEBUG Logger.WriteDebug($"Processed event with id {newEvent.Id}"); #endif } 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"); } // this happens if a plugin requires login catch (AuthorizationException ex) { newEvent.FailReason = EventFailReason.Permission; newEvent.Origin.Tell($"{Utilities.CurrentLocalization.LocalizationIndex["COMMAND_NOTAUTHORIZED"]} - {ex.Message}"); } catch (NetworkException ex) { newEvent.FailReason = EventFailReason.Exception; Logger.WriteError(ex.Message); Logger.WriteDebug(ex.GetExceptionInfo()); } catch (ServerException ex) { newEvent.FailReason = EventFailReason.Exception; Logger.WriteWarning(ex.Message); } catch (Exception ex) { newEvent.FailReason = EventFailReason.Exception; Logger.WriteError(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_EXCEPTION"].FormatExt(newEvent.Owner)); Logger.WriteDebug(ex.GetExceptionInfo()); } skip: // tell anyone waiting for the output that we're done newEvent.Complete(); OnGameEventExecuted?.Invoke(this, newEvent); #if DEBUG == true Logger.WriteDebug($"Exiting event process for {newEvent.Id}"); #endif }