Seperated the application back into a seperate project

webfront is just a library now
This commit is contained in:
RaidMax 2018-04-08 13:48:40 -05:00
parent 06d3de375b
commit 6d5c368954
20 changed files with 133 additions and 57 deletions

View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.0.0</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Product>IW4MAdmin</Product>
<Description>IW4MAdmin is a complete server administration tool for IW4x and most Call of Duty® dedicated server</Description>
<Copyright>2018</Copyright>
<PackageLicenseUrl>https://github.com/RaidMax/IW4M-Admin/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://raidmax.org/IW4MAdmin</PackageProjectUrl>
<RepositoryUrl>https://github.com/RaidMax/IW4M-Admin</RepositoryUrl>
<PackageIconUrl>https://raidmax.org/IW4MAdmin/img/iw4adminicon-3.png</PackageIconUrl>
<ApplicationIcon />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SharedLibraryCore\SharedLibraryCore.csproj" />
<ProjectReference Include="..\WebfrontCore\WebfrontCore.csproj" />
</ItemGroup>
</Project>

View File

@ -1,15 +1,17 @@
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Objects;
using System;
using System;
using System.Collections.Generic;
namespace WebfrontCore.Application.API
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Objects;
namespace IW4MAdmin.Application.API
{
class EventAPI
class EventApi : IEventApi
{
public static Queue<EventInfo> Events = new Queue<EventInfo>();
static DateTime LastFlagEvent;
Queue<EventInfo> Events = new Queue<EventInfo>();
DateTime LastFlagEvent;
static string[] FlaggedMessageContains =
{
" wh ",
@ -22,9 +24,11 @@ namespace WebfrontCore.Application.API
"hak",
"bot"
};
static int FlaggedMessageCount;
int FlaggedMessageCount;
public static void OnServerEventOccurred(object sender, Event E)
public Queue<EventInfo> GetEvents() => Events;
public void OnServerEvent(object sender, Event E)
{
if (E.Type == Event.GType.Say && E.Origin.Level < Player.Permission.Trusted)
{

View File

@ -7,7 +7,7 @@ using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace IW4MAdmin
namespace IW4MAdmin.Application
{
class ConfigurationGenerator
{

View File

@ -1,7 +1,7 @@
using System;
using System.IO;
namespace IW4MAdmin
namespace IW4MAdmin.Application
{
class Logger : SharedLibraryCore.Interfaces.ILogger
{

View File

@ -6,7 +6,7 @@ using System.IO;
using SharedLibraryCore.Objects;
using System.Reflection;
namespace IW4MAdmin
namespace IW4MAdmin.Application
{
public class Program
{
@ -14,7 +14,7 @@ namespace IW4MAdmin
static public ApplicationManager ServerManager = ApplicationManager.GetInstance();
public static string OperatingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
public static bool Start()
public static void Main(string[] args)
{
AppDomain.CurrentDomain.SetData("DataDirectory", OperatingDirectory);
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
@ -60,8 +60,7 @@ namespace IW4MAdmin
Console.WriteLine("Shutdown complete");
});
return true;
WebfrontCore.Program.Init(ServerManager);
}
catch (Exception e)
@ -74,7 +73,6 @@ namespace IW4MAdmin
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return false;
}
}

View File

@ -12,14 +12,14 @@ using SharedLibraryCore.Helpers;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Objects;
using SharedLibraryCore.Services;
using WebfrontCore.Application.API;
using IW4MAdmin.Application.API;
using Microsoft.Extensions.Configuration;
using WebfrontCore;
using SharedLibraryCore.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IW4MAdmin
namespace IW4MAdmin.Application
{
public class ApplicationManager : IManager
{
@ -38,6 +38,7 @@ namespace IW4MAdmin
AliasService AliasSvc;
PenaltyService PenaltySvc;
BaseConfigurationHandler<ApplicationConfiguration> ConfigHandler;
EventApi Api;
#if FTP_LOG
const int UPDATE_FREQUENCY = 700;
#else
@ -55,7 +56,8 @@ namespace IW4MAdmin
AliasSvc = new AliasService();
PenaltySvc = new PenaltyService();
PrivilegedClients = new Dictionary<int, Player>();
ServerEventOccurred += EventAPI.OnServerEventOccurred;
Api = new EventApi();
ServerEventOccurred += Api.OnServerEvent;
ConfigHandler = new BaseConfigurationHandler<ApplicationConfiguration>("IW4MAdminSettings");
Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey);
}
@ -314,5 +316,7 @@ namespace IW4MAdmin
public IConfigurationHandler<ApplicationConfiguration> GetApplicationSettings() => ConfigHandler;
public IDictionary<int, Player> GetPrivilegedClients() => PrivilegedClients;
public IEventApi GetEventApi() => Api;
}
}

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.Application.Misc
namespace IW4MAdmin.Application.Misc
{
public class VPNCheck
{

View File

@ -14,7 +14,7 @@ using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Configuration;
using WebfrontCore.Application.Misc;
using IW4MAdmin.Application.Misc;
namespace IW4MAdmin
{
@ -358,20 +358,20 @@ namespace IW4MAdmin
return;
await ProcessEvent(E);
((ApplicationManager)Manager).ServerEventOccurred(this, E);
Manager.GetEventApi().OnServerEvent(this, E);
foreach (IPlugin P in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
{
//#if !DEBUG
#if !DEBUG
try
//#endif
#endif
{
if (cts.IsCancellationRequested)
break;
await P.OnEventAsync(E, this);
}
//#if !DEBUG
#if !DEBUG
catch (Exception Except)
{
Logger.WriteError(String.Format("The plugin \"{0}\" generated an error. ( see log )", P.Name));
@ -379,7 +379,7 @@ namespace IW4MAdmin
Logger.WriteDebug(String.Format("Error Trace: {0}", Except.StackTrace));
continue;
}
//#endif
#endif
}
}
@ -540,7 +540,6 @@ namespace IW4MAdmin
}
oldLines = lines;
l_size = LogFile.Length();
if (!((ApplicationManager)Manager).Running)
{
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
await plugin.OnUnloadAsync();
@ -964,7 +963,7 @@ namespace IW4MAdmin
override public void InitializeTokens()
{
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", Manager.GetClientService().GetTotalClientsAsync().Result.ToString));
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", Program.Version.ToString));
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", IW4MAdmin.Application.Program.Version.ToString));
}
}
}

View File

@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedLibraryCore", "Shared
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebfrontCore", "WebfrontCore\WebfrontCore.csproj", "{D59AC1F1-2FB9-4BE7-813E-0CCCC4FE9067}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{B4626E78-BB22-43F8-A6AD-890B0853D61F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -234,6 +236,38 @@ Global
{D59AC1F1-2FB9-4BE7-813E-0CCCC4FE9067}.Release-Stable|x64.Build.0 = Release|Any CPU
{D59AC1F1-2FB9-4BE7-813E-0CCCC4FE9067}.Release-Stable|x86.ActiveCfg = Release|Any CPU
{D59AC1F1-2FB9-4BE7-813E-0CCCC4FE9067}.Release-Stable|x86.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|x64.ActiveCfg = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|x64.Build.0 = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Debug|x86.Build.0 = Debug|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|Any CPU.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|x64.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|x64.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|x86.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release|x86.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|Any CPU.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|Any CPU.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|Mixed Platforms.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|Mixed Platforms.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|x64.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|x64.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|x86.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Nightly|x86.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|Any CPU.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|Any CPU.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|Mixed Platforms.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|Mixed Platforms.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|x64.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|x64.Build.0 = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|x86.ActiveCfg = Release|Any CPU
{B4626E78-BB22-43F8-A6AD-890B0853D61F}.Release-Stable|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,11 @@
using SharedLibraryCore.Dtos;
using System.Collections.Generic;
namespace SharedLibraryCore.Interfaces
{
public interface IEventApi
{
void OnServerEvent(object sender, Event E);
Queue<EventInfo> GetEvents();
}
}

View File

@ -1,7 +1,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SharedLibraryCore.Objects;
using SharedLibraryCore.Services;
using System.Threading.Tasks;
using SharedLibraryCore.Configuration;
namespace SharedLibraryCore.Interfaces
@ -21,5 +22,6 @@ namespace SharedLibraryCore.Interfaces
AliasService GetAliasService();
PenaltyService GetPenaltyService();
IDictionary<int, Player> GetPrivilegedClients();
IEventApi GetEventApi();
}
}

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using WebfrontCore.Application.API;
namespace WebfrontCore.Controllers.API
{
@ -12,7 +11,7 @@ namespace WebfrontCore.Controllers.API
[Route("event")]
public ActionResult Index()
{
var events = EventAPI.Events;
var events = Manager.GetEventApi().GetEvents();
var eventsDto = new List<EventInfo>();
while (events.Count > 0)
eventsDto.Add(events.Dequeue());

View File

@ -19,7 +19,7 @@ namespace WebfrontCore.Controllers
try
{
var client = IW4MAdmin.Program.ServerManager.PrivilegedClients[clientId];
var client = Manager.GetPrivilegedClients()[clientId];
string[] hashedPassword = await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(password, client.PasswordSalt));
if (hashedPassword[0] == client.Password)

View File

@ -1,20 +1,19 @@
using IW4MAdmin;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibraryCore;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Objects;
namespace WebfrontCore.Controllers
{
public class BaseController : Controller
{
protected ApplicationManager Manager;
protected IManager Manager;
protected readonly DatabaseContext Context;
protected bool Authorized { get; private set; }
protected EFClient User { get; private set; }
@ -26,7 +25,7 @@ namespace WebfrontCore.Controllers
public override void OnActionExecuting(ActionExecutingContext context)
{
Manager = IW4MAdmin.Program.ServerManager;
Manager = Program.Manager;
User = new EFClient()
{

View File

@ -13,7 +13,7 @@ namespace WebfrontCore.Controllers
{
public IActionResult Index()
{
var activeServers = Manager.Servers.Select(s => new ServerInfo()
var activeServers = Manager.GetServers().Select(s => new ServerInfo()
{
Name = s.Hostname,
ID = s.GetHashCode(),
@ -29,7 +29,7 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> ExecuteAsync(int serverId, string command)
{
var server = Manager.Servers.First(s => s.GetHashCode() == serverId);
var server = Manager.GetServers().First(s => s.GetHashCode() == serverId);
var client = new Player()
{
ClientId = User.ClientId,

View File

@ -1,16 +1,20 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using SharedLibraryCore.Interfaces;
namespace WebfrontCore
{
public class Program
{
public static void Main(string[] args)
public static IManager Manager;
public static void Init(IManager mgr)
{
BuildWebHost(args).Run();
Manager = mgr;
BuildWebHost().Run();
}
public static IWebHost BuildWebHost(string[] args) =>
public static IWebHost BuildWebHost() =>
new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel()

View File

@ -49,9 +49,6 @@ namespace WebfrontCore
options.AccessDeniedPath = "/";
options.LoginPath = "/";
});
if (!IW4MAdmin.Program.Start())
Environment.Exit(-1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -28,7 +28,7 @@ namespace WebfrontCore.ViewComponents
}
var penalties = await IW4MAdmin.ApplicationManager.GetInstance().GetPenaltyService().GetRecentPenalties(15, offset);
var penalties = await Program.Manager.GetPenaltyService().GetRecentPenalties(15, offset);
var penaltiesDto = penalties.Select(p => new PenaltyInfo()
{
OffenderId = p.OffenderId,

View File

@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.ViewComponents
{
@ -11,7 +8,7 @@ namespace WebfrontCore.ViewComponents
{
public IViewComponentResult Invoke()
{
var servers = IW4MAdmin.Program.ServerManager.GetServers();
var servers = Program.Manager.GetServers();
var serverInfo = servers.Select(s => new ServerInfo()
{
Name = s.Hostname,

View File

@ -15,6 +15,9 @@
<PackageProjectUrl>https://raidmax.org/IW4MAdmin</PackageProjectUrl>
<RepositoryUrl>https://github.com/RaidMax/IW4M-Admin</RepositoryUrl>
<PackageIconUrl>https://raidmax.org/IW4MAdmin/img/iw4adminicon-3.png</PackageIconUrl>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>