 14575a4a6b
			
		
	
	14575a4a6b
	
	
	
		
			
			* add jwt expiry * start of 0.9 api impl * some stuff idk * some more impl * some cleanup * remove grouppair, add configuration, rework some pair drawing stuff * do some stuff * rework some ui * I don't even know anymore * add cancellationtoken * token bla * ui fixes etc * probably individual adding/removing now working fully as expected * add working report popup * I guess it's more syncshell shit or so * popup shit idk * work out most of the syncshell bullshit I guess * delete some old crap * are we actually getting closer to the end * update pair info stuff * more fixes/adjustments, idk * refactor some things * some rework * some more cleanup * cleanup * make menu buttons w i d e * better icon text buttons * add all syncshell folder and ordering fixes --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
		
			
				
	
	
		
			165 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			165 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using MareSynchronos.FileCache;
 | |
| using MareSynchronos.MareConfiguration;
 | |
| using MareSynchronos.PlayerData.Pairs;
 | |
| using MareSynchronos.PlayerData.Services;
 | |
| using MareSynchronos.Services;
 | |
| using MareSynchronos.Services.Mediator;
 | |
| using MareSynchronos.Services.ServerConfiguration;
 | |
| using Microsoft.Extensions.DependencyInjection;
 | |
| using Microsoft.Extensions.Hosting;
 | |
| using Microsoft.Extensions.Logging;
 | |
| using System.Reflection;
 | |
| 
 | |
| namespace MareSynchronos;
 | |
| 
 | |
| #pragma warning disable S125 // Sections of code should not be commented out
 | |
| /*
 | |
|                                                                     (..,,...,,,,,+/,                ,,.....,,+
 | |
|                                                               ..,,+++/((###%%%&&%%#(+,,.,,,+++,,,,//,,#&@@@@%+.
 | |
|                                                           ...+//////////(/,,,,++,.,(###((//////////,..  .,#@@%/./
 | |
|                                                        ,..+/////////+///,.,. ,&@@@@,,/////////////+,..    ,(##+,.
 | |
|                                                     ,,.+//////////++++++..     ./#%#,+/////////////+,....,/((,..,
 | |
|                                                   +..////////////+++++++...  .../##(,,////////////////++,,,+/(((+,
 | |
|                                                 +,.+//////////////+++++++,.,,,/(((+.,////////////////////////((((#/,,
 | |
|                                               /+.+//////////++++/++++++++++,,...,++///////////////////////////((((##,
 | |
|                                              /,.////////+++++++++++++++++++++////////+++//////++/+++++//////////((((#(+,
 | |
|                                            /+.+////////+++++++++++++++++++++++++++++++++++++++++++++++++++++/////((((##+
 | |
|                                           +,.///////////////+++++++++++++++++++++++++++++++++++++++++++++++++++///((((%/
 | |
|                                          /.,/////////////////+++++++++++++++++++++++++++++++++++++++++++++++++++///+/(#+
 | |
|                                         +,./////////////////+++++++++++++++++++++++++++++++++++++++++++++++,,+++++///((,
 | |
|                                        ...////////++/++++++++++++++++++++++++,,++++++++++++++++++++++++++++++++++++//(,,
 | |
|                                        ..//+,+///++++++++++++++++++,,,,+++,,,,,,,,,,,,++++++++,,+++++++++++++++++++//,,+
 | |
|                                       ..,++,.++++++++++++++++++++++,,,,,,,,,,,,,,,,,,,++++++++,,,,,,,,,,++++++++++...
 | |
|                                       ..+++,.+++++++++++++++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,++,..,.
 | |
|                                      ..,++++,,+++++++++++,+,,,,,,,,,,..,+++++++++,,,,,,.....................,//+,+
 | |
|                                  ....,+++++,.,+++++++++++,,,,,,,,.+///(((((((((((((///////////////////////(((+,,,
 | |
|                           .....,++++++++++..,+++++++++++,,.,,,.////////(((((((((((((((////////////////////+,,/
 | |
|                       .....,++++++++++++,..,,+++++++++,,.,../////////////////((((((((((//////////////////,,+
 | |
|                    ...,,+++++++++++++,.,,.,,,+++++++++,.,/////////////////(((//++++++++++++++//+++++++++/,,
 | |
|                 ....,++++++++++++++,.,++.,++++++++++++.,+////////////////////+++++++++++++++++++++++++///,,..
 | |
|               ...,++++++++++++++++..+++..+++++++++++++.,//////////////////////////++++++++++++///////++++......
 | |
|             ...++++++++++++++++++..++++.,++,++++++++++.+///////////////////////////////////////////++++++..,,,..
 | |
|           ...+++++++++++++++++++..+++++..,+,,+++++++++.+//////////////////////////////////////////+++++++...,,,,..
 | |
|          ..++++++++++++++++++++..++++++..,+,,+++++++++.+//////////////////////////////////////++++++++++,....,,,,..
 | |
|        ...+++//(//////+++++++++..++++++,.,+++++++++++++,..,....,,,+++///////////////////////++++++++++++..,,,,,,,,...
 | |
|       ..,++/(((((//////+++++++,.,++++++,,.,,,+++++++++++++++++++++++,.++////////////////////+++++++++++.....,,,,,,,...
 | |
|      ..,//#(((((///////+++++++..++++++++++,...,++,++++++++++++++++,...+++/////////////////////+,,,+++...  ....,,,,,,...
 | |
|    ...+//(((((//////////++++++..+++++++++++++++,......,,,,++++++,,,..+++////////////////////////+,....     ...,,,,,,,...
 | |
|    ..,//((((////////////++++++..++++++/+++++++++++++,,...,,........,+/+//////////////////////((((/+,..     ....,.,,,,..
 | |
|   ...+/////////////////////+++..++++++/+///+++++++++++++++++++++///+/+////////////////////////(((((/+...   .......,,...
 | |
|   ..++////+++//////////////++++.+++++++++///////++++++++////////////////////////////////////+++/(((((/+..    .....,,...
 | |
|   .,++++++++///////////////++++..++++//////////////////////////////////////////////////////++++++/((((++..    ........
 | |
|   .+++++++++////////////////++++,.+++/////////////////////////////////////////////////////+++++++++/((/++..
 | |
|  .,++++++++//////////////////++++,.+++//////////////////////////////////////////////////+++++++++++++//+++..
 | |
|  .++++++++//////////////////////+/,.,+++////((((////////////////////////////////////////++++++++++++++++++...
 | |
|  .++++++++///////////////////////+++..++++//((((((((///////////////////////////////////++++++++++++++++++++ .
 | |
|  .++++++///////////////////////////++,.,+++++/(((((((((/////////////////////////////+++++++++++++++++++++++,..
 | |
|  .++++++////////////////////////////+++,.,+++++++/((((((((//////////////////////////++++++++++++++++++++++++..
 | |
|  .+++++++///////////////////++////////++++,.,+++++++++///////////+////////////////+++++++++++++++++++++++++,..
 | |
|  ..++++++++++//////////////////////+++++++..+...,+++++++++++++++/++++++++++++++++++++++++++++++++++++++++++,...
 | |
|   ..++++++++++++///////////////+++++++,...,,,,,.,....,,,,+++++++++++++++++++++++++++++++++++++++++++++++,,,,...
 | |
|   ...++++++++++++++++++++++++++,,,,...,,,,,,,,,..,,++,,,.,,,,,,,,,,,,,,,,,,+++++++++++++++++++++++++,,,,,,,,..
 | |
|    ...+++++++++++++++,,,,,,,,....,,,,,,,,,,,,,,,..,,++++++,,,,,,,,,,,,,,,,+++++++++++++++++++++++++,,,,,,,,,..
 | |
|      ...++++++++++++,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...,++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,,,...
 | |
|        ,....,++++++++++++++,,,+++++++,,,,,,,,,,,,,,,,,.,++++++++++++++++++++++++++++++++++++++++++++,,,,,,,,..
 | |
| 
 | |
| */
 | |
| #pragma warning restore S125 // Sections of code should not be commented out
 | |
| 
 | |
| public class MarePlugin : MediatorSubscriberBase, IHostedService
 | |
| {
 | |
|     private readonly DalamudUtilService _dalamudUtil;
 | |
|     private readonly MareConfigService _mareConfigService;
 | |
|     private readonly ServerConfigurationManager _serverConfigurationManager;
 | |
|     private readonly IServiceScopeFactory _serviceScopeFactory;
 | |
|     private IServiceScope? _runtimeServiceScope;
 | |
| 
 | |
|     public MarePlugin(ILogger<MarePlugin> logger, MareConfigService mareConfigService,
 | |
|         ServerConfigurationManager serverConfigurationManager,
 | |
|         DalamudUtilService dalamudUtil,
 | |
|         IServiceScopeFactory serviceScopeFactory, MareMediator mediator) : base(logger, mediator)
 | |
|     {
 | |
|         _mareConfigService = mareConfigService;
 | |
|         _serverConfigurationManager = serverConfigurationManager;
 | |
|         _dalamudUtil = dalamudUtil;
 | |
|         _serviceScopeFactory = serviceScopeFactory;
 | |
|     }
 | |
| 
 | |
|     public Task StartAsync(CancellationToken cancellationToken)
 | |
|     {
 | |
|         var version = Assembly.GetExecutingAssembly().GetName().Version!;
 | |
|         Logger.LogInformation("Launching {name} {major}.{minor}.{build}", "Mare Synchronos", version.Major, version.Minor, version.Build);
 | |
| 
 | |
|         Mediator.Subscribe<SwitchToMainUiMessage>(this, (msg) => _ = Task.Run(WaitForPlayerAndLaunchCharacterManager));
 | |
|         Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
 | |
|         Mediator.Subscribe<DalamudLogoutMessage>(this, (_) => DalamudUtilOnLogOut());
 | |
| 
 | |
|         return Task.CompletedTask;
 | |
|     }
 | |
| 
 | |
|     public Task StopAsync(CancellationToken cancellationToken)
 | |
|     {
 | |
|         UnsubscribeAll();
 | |
| 
 | |
|         DalamudUtilOnLogOut();
 | |
| 
 | |
|         Logger.LogDebug("Halting MarePlugin");
 | |
| 
 | |
|         return Task.CompletedTask;
 | |
|     }
 | |
| 
 | |
|     private void DalamudUtilOnLogIn()
 | |
|     {
 | |
|         Logger?.LogDebug("Client login");
 | |
| 
 | |
|         _ = Task.Run(WaitForPlayerAndLaunchCharacterManager);
 | |
|     }
 | |
| 
 | |
|     private void DalamudUtilOnLogOut()
 | |
|     {
 | |
|         Logger?.LogDebug("Client logout");
 | |
| 
 | |
|         _runtimeServiceScope?.Dispose();
 | |
|     }
 | |
| 
 | |
|     private async Task WaitForPlayerAndLaunchCharacterManager()
 | |
|     {
 | |
|         while (!await _dalamudUtil.GetIsPlayerPresentAsync().ConfigureAwait(false))
 | |
|         {
 | |
|             await Task.Delay(100).ConfigureAwait(false);
 | |
|         }
 | |
| 
 | |
|         try
 | |
|         {
 | |
|             Logger?.LogDebug("Launching Managers");
 | |
| 
 | |
|             _runtimeServiceScope?.Dispose();
 | |
|             _runtimeServiceScope = _serviceScopeFactory.CreateScope();
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<UiService>();
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<CommandManagerService>();
 | |
|             if (!_mareConfigService.Current.HasValidSetup() || !_serverConfigurationManager.HasValidConfig())
 | |
|             {
 | |
|                 Mediator.Publish(new SwitchToIntroUiMessage());
 | |
|                 return;
 | |
|             }
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<PeriodicFileScanner>().StartScan();
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<CacheCreationService>();
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<TransientResourceManager>();
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<OnlinePlayerManager>();
 | |
|             _runtimeServiceScope.ServiceProvider.GetRequiredService<NotificationService>();
 | |
| 
 | |
| #if !DEBUG
 | |
|             if (_mareConfigService.Current.LogLevel != LogLevel.Information)
 | |
|             {
 | |
|                 Mediator.Publish(new NotificationMessage("Abnormal Log Level",
 | |
|                     $"Your log level is set to '{_mareConfigService.Current.LogLevel}' which is not recommended for normal usage. Set it to '{LogLevel.Information}' in \"Mare Settings -> Debug\" unless instructed otherwise.",
 | |
|                     Dalamud.Interface.Internal.Notifications.NotificationType.Error, 15000));
 | |
|             }
 | |
| #endif
 | |
|         }
 | |
|         catch (Exception ex)
 | |
|         {
 | |
|             Logger?.LogCritical(ex, "Error during launch of managers");
 | |
|         }
 | |
|     }
 | |
| } |