cleaned up configuration files to use appsettings
This commit is contained in:
parent
81d965a718
commit
c1a1d65261
@ -247,7 +247,7 @@ namespace StatsPlugin.Helpers
|
|||||||
|
|
||||||
//statsSvc.KillStatsSvc.Insert(kill);
|
//statsSvc.KillStatsSvc.Insert(kill);
|
||||||
//await statsSvc.KillStatsSvc.SaveChangesAsync();
|
//await statsSvc.KillStatsSvc.SaveChangesAsync();
|
||||||
if (attacker.CurrentServer.Config.EnableAntiCheat)
|
if(Manager.GetApplicationSettings().EnableAntiCheat)
|
||||||
{
|
{
|
||||||
async Task executePenalty(Cheat.DetectionPenaltyResult penalty)
|
async Task executePenalty(Cheat.DetectionPenaltyResult penalty)
|
||||||
{
|
{
|
||||||
|
@ -92,6 +92,7 @@ namespace StatsPlugin
|
|||||||
int deaths = clientStats.Sum(c => c.Deaths);
|
int deaths = clientStats.Sum(c => c.Deaths);
|
||||||
double kdr = Math.Round(kills / (double)deaths, 2);
|
double kdr = Math.Round(kills / (double)deaths, 2);
|
||||||
double skill = Math.Round(clientStats.Sum(c => c.Skill) / clientStats.Count, 2);
|
double skill = Math.Round(clientStats.Sum(c => c.Skill) / clientStats.Count, 2);
|
||||||
|
double spm = Math.Round(clientStats.Sum(c => c.SPM), 1);
|
||||||
|
|
||||||
double chestRatio = 0;
|
double chestRatio = 0;
|
||||||
double abdomenRatio = 0;
|
double abdomenRatio = 0;
|
||||||
@ -135,6 +136,11 @@ namespace StatsPlugin
|
|||||||
Value = skill
|
Value = skill
|
||||||
},
|
},
|
||||||
new ProfileMeta()
|
new ProfileMeta()
|
||||||
|
{
|
||||||
|
Key = "Score Per Minute",
|
||||||
|
Value = spm
|
||||||
|
},
|
||||||
|
new ProfileMeta()
|
||||||
{
|
{
|
||||||
Key = "Chest Ratio",
|
Key = "Chest Ratio",
|
||||||
Value = chestRatio,
|
Value = chestRatio,
|
||||||
|
@ -150,7 +150,11 @@
|
|||||||
<Name>SharedLibrary</Name>
|
<Name>SharedLibrary</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions">
|
||||||
|
<Version>1.1.2</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent>
|
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent>
|
||||||
|
@ -424,9 +424,9 @@ namespace SharedLibrary.Commands
|
|||||||
if (newPerm == Player.Permission.Owner && E.Origin.Level != Player.Permission.Console)
|
if (newPerm == Player.Permission.Owner && E.Origin.Level != Player.Permission.Console)
|
||||||
newPerm = Player.Permission.Banned;
|
newPerm = Player.Permission.Banned;
|
||||||
|
|
||||||
if (newPerm == Player.Permission.Owner && !E.Owner.Config.AllowMultipleOwners)
|
if (newPerm == Player.Permission.Owner && !E.Owner.Manager.GetApplicationSettings().EnableMultipleOwners)
|
||||||
{
|
{
|
||||||
await E.Origin.Tell("There can only be 1 owner. Modify your server configuration if multiple owners are required");
|
await E.Origin.Tell("There can only be 1 owner. Modify your appsettings if multiple owners are required");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1033,13 +1033,15 @@ namespace SharedLibrary.Commands
|
|||||||
#endif
|
#endif
|
||||||
process.StartInfo.FileName = $"{process.StartInfo.WorkingDirectory}\\iw4x.exe";
|
process.StartInfo.FileName = $"{process.StartInfo.WorkingDirectory}\\iw4x.exe";
|
||||||
process.StartInfo.Arguments = commandLine.Substring(6);
|
process.StartInfo.Arguments = commandLine.Substring(6);
|
||||||
process.StartInfo.UserName = E.Owner.Config.RestartUsername;
|
|
||||||
|
/*process.StartInfo.UserName = E.Owner.ServerConfig.RestartUsername;
|
||||||
|
|
||||||
var pw = new System.Security.SecureString();
|
var pw = new System.Security.SecureString();
|
||||||
foreach (char c in E.Owner.Config.RestartPassword)
|
foreach (char c in E.Owner.ServerConfig.RestartPassword)
|
||||||
pw.AppendChar(c);
|
pw.AppendChar(c);
|
||||||
|
|
||||||
process.StartInfo.Password = pw;
|
process.StartInfo.Password = pw;
|
||||||
|
*/
|
||||||
process.Start();
|
process.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
SharedLibrary/Configuration/ApplicationConfiguration.cs
Normal file
17
SharedLibrary/Configuration/ApplicationConfiguration.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SharedLibrary.Configuration
|
||||||
|
{
|
||||||
|
public class ApplicationConfiguration
|
||||||
|
{
|
||||||
|
public bool EnableMultipleOwners { get; set; }
|
||||||
|
public bool EnableTrustedRank { get; set; }
|
||||||
|
public bool EnableClientVPNs { get; set; }
|
||||||
|
public bool EnableAntiCheat { get; set; }
|
||||||
|
public bool EnableDiscordLink { get; set; }
|
||||||
|
public string DiscordInviteCode { get; set; }
|
||||||
|
public string IPHubAPIKey { get; set; }
|
||||||
|
public List<ServerConfiguration> Servers { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
9
SharedLibrary/Configuration/ServerConfiguration.cs
Normal file
9
SharedLibrary/Configuration/ServerConfiguration.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace SharedLibrary.Configuration
|
||||||
|
{
|
||||||
|
public class ServerConfiguration
|
||||||
|
{
|
||||||
|
public string IPAddress { get; set; }
|
||||||
|
public short Port { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@ using SharedLibrary.Objects;
|
|||||||
using SharedLibrary.Database.Models;
|
using SharedLibrary.Database.Models;
|
||||||
using SharedLibrary.Services;
|
using SharedLibrary.Services;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using SharedLibrary.Configuration;
|
||||||
|
|
||||||
namespace SharedLibrary.Interfaces
|
namespace SharedLibrary.Interfaces
|
||||||
{
|
{
|
||||||
@ -16,6 +18,7 @@ namespace SharedLibrary.Interfaces
|
|||||||
IList<Command> GetCommands();
|
IList<Command> GetCommands();
|
||||||
IList<Helpers.MessageToken> GetMessageTokens();
|
IList<Helpers.MessageToken> GetMessageTokens();
|
||||||
IList<Player> GetActiveClients();
|
IList<Player> GetActiveClients();
|
||||||
|
ApplicationConfiguration GetApplicationSettings();
|
||||||
ClientService GetClientService();
|
ClientService GetClientService();
|
||||||
AliasService GetAliasService();
|
AliasService GetAliasService();
|
||||||
PenaltyService GetPenaltyService();
|
PenaltyService GetPenaltyService();
|
||||||
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
|||||||
using SharedLibrary.Helpers;
|
using SharedLibrary.Helpers;
|
||||||
using SharedLibrary.Objects;
|
using SharedLibrary.Objects;
|
||||||
using SharedLibrary.Dtos;
|
using SharedLibrary.Dtos;
|
||||||
|
using SharedLibrary.Configuration;
|
||||||
|
|
||||||
namespace SharedLibrary
|
namespace SharedLibrary
|
||||||
{
|
{
|
||||||
@ -30,11 +31,11 @@ namespace SharedLibrary
|
|||||||
public Server(Interfaces.IManager mgr, ServerConfiguration config)
|
public Server(Interfaces.IManager mgr, ServerConfiguration config)
|
||||||
{
|
{
|
||||||
Password = config.Password;
|
Password = config.Password;
|
||||||
IP = config.IP;
|
IP = config.IPAddress;
|
||||||
Port = config.Port;
|
Port = config.Port;
|
||||||
Manager = mgr;
|
Manager = mgr;
|
||||||
Logger = Manager.GetLogger();
|
Logger = Manager.GetLogger();
|
||||||
Config = config;
|
ServerConfig = config;
|
||||||
|
|
||||||
Players = new List<Player>(new Player[18]);
|
Players = new List<Player>(new Player[18]);
|
||||||
Reports = new List<Report>();
|
Reports = new List<Report>();
|
||||||
@ -360,7 +361,7 @@ namespace SharedLibrary
|
|||||||
// Objects
|
// Objects
|
||||||
public Interfaces.IManager Manager { get; protected set; }
|
public Interfaces.IManager Manager { get; protected set; }
|
||||||
public Interfaces.ILogger Logger { get; private set; }
|
public Interfaces.ILogger Logger { get; private set; }
|
||||||
public ServerConfiguration Config { get; private set; }
|
public ServerConfiguration ServerConfig { get; private set; }
|
||||||
public List<Map> Maps { get; protected set; }
|
public List<Map> Maps { get; protected set; }
|
||||||
public List<string> Rules { get; protected set; }
|
public List<string> Rules { get; protected set; }
|
||||||
public List<Report> Reports { get; set; }
|
public List<Report> Reports { get; set; }
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
using SharedLibrary.Interfaces;
|
|
||||||
|
|
||||||
namespace SharedLibrary
|
|
||||||
{
|
|
||||||
public class ServerConfiguration : Serialize<ServerConfiguration>
|
|
||||||
{
|
|
||||||
public string IP;
|
|
||||||
public int Port;
|
|
||||||
public string Password;
|
|
||||||
public string FtpPrefix;
|
|
||||||
public bool AllowMultipleOwners;
|
|
||||||
public bool AllowTrustedRank;
|
|
||||||
public string RestartUsername;
|
|
||||||
public string RestartPassword;
|
|
||||||
public bool EnableAntiCheat;
|
|
||||||
public bool AllowClientVpn;
|
|
||||||
|
|
||||||
public override string Filename()
|
|
||||||
{
|
|
||||||
return $"{Utilities.OperatingDirectory}config/servers/{IP}_{Port}.cfg";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -146,6 +146,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Configuration\ServerConfiguration.cs" />
|
||||||
<Compile Include="Database\Importer.cs" />
|
<Compile Include="Database\Importer.cs" />
|
||||||
<Compile Include="Database\DatabaseContext.cs" />
|
<Compile Include="Database\DatabaseContext.cs" />
|
||||||
<Compile Include="Database\Models\EFAlias.cs" />
|
<Compile Include="Database\Models\EFAlias.cs" />
|
||||||
@ -198,7 +199,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RCON.cs" />
|
<Compile Include="RCON.cs" />
|
||||||
<Compile Include="Server.cs" />
|
<Compile Include="Server.cs" />
|
||||||
<Compile Include="ServerConfiguration.cs" />
|
<Compile Include="Configuration\ApplicationConfiguration.cs" />
|
||||||
<Compile Include="Services\AliasService.cs" />
|
<Compile Include="Services\AliasService.cs" />
|
||||||
<Compile Include="Services\ClientService.cs" />
|
<Compile Include="Services\ClientService.cs" />
|
||||||
<Compile Include="Services\GenericRepository.cs" />
|
<Compile Include="Services\GenericRepository.cs" />
|
||||||
@ -226,6 +227,9 @@
|
|||||||
<PackageReference Include="EntityFramework.SqlServerCompact">
|
<PackageReference Include="EntityFramework.SqlServerCompact">
|
||||||
<Version>6.2.0</Version>
|
<Version>6.2.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions">
|
||||||
|
<Version>1.1.2</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Newtonsoft.Json">
|
<PackageReference Include="Newtonsoft.Json">
|
||||||
<Version>11.0.1</Version>
|
<Version>11.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
96
WebfrontCore/Application/ConfigurationGenerater.cs
Normal file
96
WebfrontCore/Application/ConfigurationGenerater.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using SharedLibrary;
|
||||||
|
using SharedLibrary.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace IW4MAdmin
|
||||||
|
{
|
||||||
|
class ConfigurationGenerator
|
||||||
|
{
|
||||||
|
public static List<ServerConfiguration> GenerateServerConfig(List<ServerConfiguration> configList)
|
||||||
|
{
|
||||||
|
|
||||||
|
var newConfig = new ServerConfiguration();
|
||||||
|
|
||||||
|
while (string.IsNullOrEmpty(newConfig.IPAddress))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter server IP Address: ");
|
||||||
|
string input = Console.ReadLine();
|
||||||
|
IPAddress.Parse(input);
|
||||||
|
newConfig.IPAddress = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (newConfig.Port == 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter server port: ");
|
||||||
|
newConfig.Port = Int16.Parse(Console.ReadLine());
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Write("Enter server RCON password: ");
|
||||||
|
newConfig.Password = Console.ReadLine();
|
||||||
|
|
||||||
|
configList.Add(newConfig);
|
||||||
|
|
||||||
|
Console.Write("Configuration saved, add another? [y/n]:");
|
||||||
|
if (Console.ReadLine().ToLower().First() == 'y')
|
||||||
|
GenerateServerConfig(configList);
|
||||||
|
|
||||||
|
return configList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationConfiguration GenerateApplicationConfig()
|
||||||
|
{
|
||||||
|
var config = new ApplicationConfiguration();
|
||||||
|
|
||||||
|
Console.Write("Enable multiple owners? [y/n]: ");
|
||||||
|
config.EnableMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||||
|
|
||||||
|
Console.Write("Enable trusted rank? [y/n]: ");
|
||||||
|
config.EnableTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||||
|
|
||||||
|
Console.Write("Enable server-side anti-cheat [y/n]: ");
|
||||||
|
config.EnableAntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||||
|
|
||||||
|
Console.Write("Enable client VPNS [y/n]: ");
|
||||||
|
config.EnableClientVPNs = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||||
|
|
||||||
|
if (!config.EnableClientVPNs)
|
||||||
|
{
|
||||||
|
Console.Write("Enter iphub.info api key: ");
|
||||||
|
config.IPHubAPIKey = Console.ReadLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Write("Display Discord link on webfront [y/n]: ");
|
||||||
|
config.EnableDiscordLink = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||||
|
|
||||||
|
if (config.EnableDiscordLink)
|
||||||
|
{
|
||||||
|
Console.Write("Enter Discord invite link: ");
|
||||||
|
config.DiscordInviteCode = Console.ReadLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,11 @@ using SharedLibrary.Exceptions;
|
|||||||
using SharedLibrary.Objects;
|
using SharedLibrary.Objects;
|
||||||
using SharedLibrary.Services;
|
using SharedLibrary.Services;
|
||||||
using WebfrontCore.Application.API;
|
using WebfrontCore.Application.API;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using WebfrontCore;
|
||||||
|
using SharedLibrary.Configuration;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
@ -32,6 +37,7 @@ namespace IW4MAdmin
|
|||||||
ClientService ClientSvc;
|
ClientService ClientSvc;
|
||||||
AliasService AliasSvc;
|
AliasService AliasSvc;
|
||||||
PenaltyService PenaltySvc;
|
PenaltyService PenaltySvc;
|
||||||
|
IConfigurationRoot AppSettings;
|
||||||
#if FTP_LOG
|
#if FTP_LOG
|
||||||
const int UPDATE_FREQUENCY = 700;
|
const int UPDATE_FREQUENCY = 700;
|
||||||
#else
|
#else
|
||||||
@ -40,7 +46,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
private ApplicationManager()
|
private ApplicationManager()
|
||||||
{
|
{
|
||||||
Logger = new Logger($@"{SharedLibrary.Utilities.OperatingDirectory}Logs{Path.DirectorySeparatorChar}IW4MAdmin.log");
|
Logger = new Logger($@"{Utilities.OperatingDirectory}Logs{Path.DirectorySeparatorChar}IW4MAdmin.log");
|
||||||
_servers = new List<Server>();
|
_servers = new List<Server>();
|
||||||
Commands = new List<Command>();
|
Commands = new List<Command>();
|
||||||
TaskStatuses = new List<AsyncStatus>();
|
TaskStatuses = new List<AsyncStatus>();
|
||||||
@ -52,6 +58,13 @@ namespace IW4MAdmin
|
|||||||
ServerEventOccurred += EventAPI.OnServerEventOccurred;
|
ServerEventOccurred += EventAPI.OnServerEventOccurred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BuildConfiguration()
|
||||||
|
{
|
||||||
|
AppSettings = new ConfigurationBuilder()
|
||||||
|
.AddJsonFile($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json")
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
public IList<Server> GetServers()
|
public IList<Server> GetServers()
|
||||||
{
|
{
|
||||||
return Servers;
|
return Servers;
|
||||||
@ -95,15 +108,21 @@ namespace IW4MAdmin
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region CONFIG
|
#region CONFIG
|
||||||
var Configs = Directory.EnumerateFiles($"{Program.OperatingDirectory}config/servers").Where(x => x.Contains(".cfg"));
|
BuildConfiguration();
|
||||||
|
var settings = AppSettings.Get<ApplicationConfiguration>();
|
||||||
|
|
||||||
if (Configs.Count() == 0)
|
if (settings == null)
|
||||||
ServerConfigurationGenerator.Generate();
|
|
||||||
|
|
||||||
foreach (var file in Configs)
|
|
||||||
{
|
{
|
||||||
var Conf = ServerConfiguration.Read(file);
|
settings = ConfigurationGenerator.GenerateApplicationConfig();
|
||||||
|
settings.Servers = ConfigurationGenerator.GenerateServerConfig(new List<ServerConfiguration>());
|
||||||
|
|
||||||
|
var appConfigJSON = JsonConvert.SerializeObject(settings, Formatting.Indented);
|
||||||
|
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json", appConfigJSON);
|
||||||
|
BuildConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var Conf in settings.Servers)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var ServerInstance = new IW4MServer(this, Conf);
|
var ServerInstance = new IW4MServer(this, Conf);
|
||||||
@ -126,7 +145,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
catch (ServerException e)
|
catch (ServerException e)
|
||||||
{
|
{
|
||||||
Logger.WriteError($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors");
|
Logger.WriteError($"Not monitoring server {Conf.IPAddress}:{Conf.Port} due to uncorrectable errors");
|
||||||
if (e.GetType() == typeof(DvarException))
|
if (e.GetType() == typeof(DvarException))
|
||||||
Logger.WriteDebug($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
|
Logger.WriteDebug($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
|
||||||
else if (e.GetType() == typeof(NetworkException))
|
else if (e.GetType() == typeof(NetworkException))
|
||||||
@ -260,5 +279,7 @@ namespace IW4MAdmin
|
|||||||
public ClientService GetClientService() => ClientSvc;
|
public ClientService GetClientService() => ClientSvc;
|
||||||
public AliasService GetAliasService() => AliasSvc;
|
public AliasService GetAliasService() => AliasSvc;
|
||||||
public PenaltyService GetPenaltyService() => PenaltySvc;
|
public PenaltyService GetPenaltyService() => PenaltySvc;
|
||||||
|
|
||||||
|
public ApplicationConfiguration GetApplicationSettings() => AppSettings.Get<ApplicationConfiguration>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace WebfrontCore.Application.Misc
|
|||||||
{
|
{
|
||||||
public class VPNCheck
|
public class VPNCheck
|
||||||
{
|
{
|
||||||
public static async Task<bool> UsingVPN(string ip)
|
public static async Task<bool> UsingVPN(string ip, string apiKey)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
return false;
|
return false;
|
||||||
@ -18,7 +18,7 @@ namespace WebfrontCore.Application.Misc
|
|||||||
{
|
{
|
||||||
using (var RequestClient = new System.Net.Http.HttpClient())
|
using (var RequestClient = new System.Net.Http.HttpClient())
|
||||||
{
|
{
|
||||||
RequestClient.DefaultRequestHeaders.Add("X-Key", Startup.Configuration["VPN:APIKey"]);
|
RequestClient.DefaultRequestHeaders.Add("X-Key", apiKey);
|
||||||
string response = await RequestClient.GetStringAsync($"http://v2.api.iphub.info/ip/{ip}");
|
string response = await RequestClient.GetStringAsync($"http://v2.api.iphub.info/ip/{ip}");
|
||||||
var responseJson = JsonConvert.DeserializeObject<JObject>(response);
|
var responseJson = JsonConvert.DeserializeObject<JObject>(response);
|
||||||
int blockType = Convert.ToInt32(responseJson["block"]);
|
int blockType = Convert.ToInt32(responseJson["block"]);
|
||||||
|
@ -14,6 +14,7 @@ using SharedLibrary.Services;
|
|||||||
using SharedLibrary.Database.Models;
|
using SharedLibrary.Database.Models;
|
||||||
using SharedLibrary.Dtos;
|
using SharedLibrary.Dtos;
|
||||||
using WebfrontCore.Application.Misc;
|
using WebfrontCore.Application.Misc;
|
||||||
|
using SharedLibrary.Configuration;
|
||||||
|
|
||||||
namespace IW4MAdmin
|
namespace IW4MAdmin
|
||||||
{
|
{
|
||||||
@ -143,7 +144,8 @@ namespace IW4MAdmin
|
|||||||
await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this));
|
await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this));
|
||||||
|
|
||||||
|
|
||||||
if (Config.AllowClientVpn && await VPNCheck.UsingVPN(player.IPAddressString))
|
if (!Manager.GetApplicationSettings().EnableClientVPNs &&
|
||||||
|
await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().IPHubAPIKey))
|
||||||
{
|
{
|
||||||
await player.Kick("VPNs are not allowed on this server", new Player() { ClientId = 1 });
|
await player.Kick("VPNs are not allowed on this server", new Player() { ClientId = 1 });
|
||||||
}
|
}
|
||||||
@ -621,7 +623,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
string logPath = (game.Value == "" || onelog?.Value == 1) ?
|
string logPath = (game.Value == "" || onelog?.Value == 1) ?
|
||||||
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
|
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
|
||||||
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
|
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
|
||||||
|
|
||||||
if (!File.Exists(logPath))
|
if (!File.Exists(logPath))
|
||||||
{
|
{
|
||||||
@ -661,7 +663,7 @@ namespace IW4MAdmin
|
|||||||
await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports");
|
await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports");
|
||||||
|
|
||||||
// give trusted rank
|
// give trusted rank
|
||||||
if (Config.AllowTrustedRank &&
|
if (Manager.GetApplicationSettings().EnableTrustedRank &&
|
||||||
E.Origin.TotalConnectionTime / 60.0 >= 2880 &&
|
E.Origin.TotalConnectionTime / 60.0 >= 2880 &&
|
||||||
E.Origin.Level < Player.Permission.Trusted &&
|
E.Origin.Level < Player.Permission.Trusted &&
|
||||||
E.Origin.Level != Player.Permission.Flagged)
|
E.Origin.Level != Player.Permission.Flagged)
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
using SharedLibrary;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IW4MAdmin
|
|
||||||
{
|
|
||||||
class ServerConfigurationGenerator
|
|
||||||
{
|
|
||||||
public static ServerConfiguration Generate()
|
|
||||||
{
|
|
||||||
string IP = String.Empty;
|
|
||||||
int Port = 0;
|
|
||||||
string Password;
|
|
||||||
bool AllowMultipleOwners;
|
|
||||||
bool AllowTrustedRank;
|
|
||||||
bool AntiCheat;
|
|
||||||
bool AllowVpns;
|
|
||||||
|
|
||||||
while (IP == String.Empty)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("Enter server IP: ");
|
|
||||||
string input = Console.ReadLine();
|
|
||||||
IPAddress.Parse(input);
|
|
||||||
IP = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (Port == 0)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("Enter server port: ");
|
|
||||||
Port = Int32.Parse(Console.ReadLine());
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.Write("Enter server RCON password: ");
|
|
||||||
Password = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Allow multiple owners? [y/n]: ");
|
|
||||||
AllowMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
|
||||||
|
|
||||||
Console.Write("Allow trusted rank? [y/n]: ");
|
|
||||||
AllowTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
|
||||||
|
|
||||||
Console.Write("Allow server-side anti-cheat [y/n]: ");
|
|
||||||
AntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
|
||||||
|
|
||||||
Console.Write("Allow client VPNS [y/n]: ");
|
|
||||||
AllowVpns = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
|
||||||
|
|
||||||
var config = new ServerConfiguration()
|
|
||||||
{
|
|
||||||
IP = IP,
|
|
||||||
Password = Password,
|
|
||||||
Port = Port,
|
|
||||||
AllowMultipleOwners = AllowMultipleOwners,
|
|
||||||
AllowTrustedRank = AllowTrustedRank,
|
|
||||||
RestartPassword = "",
|
|
||||||
RestartUsername = "",
|
|
||||||
EnableAntiCheat = AntiCheat,
|
|
||||||
AllowClientVpn = AllowVpns
|
|
||||||
};
|
|
||||||
|
|
||||||
config.Write();
|
|
||||||
|
|
||||||
Console.Write("Configuration saved, add another? [y/n]:");
|
|
||||||
if (Console.ReadLine().ToLower().First() == 'y')
|
|
||||||
Generate();
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ namespace WebfrontCore.Controllers
|
|||||||
Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP());
|
Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP());
|
||||||
ViewBag.Authorized = Authorized;
|
ViewBag.Authorized = Authorized;
|
||||||
ViewBag.Url = Startup.Configuration["Web:Address"];
|
ViewBag.Url = Startup.Configuration["Web:Address"];
|
||||||
ViewBag.DiscordLink = Startup.Configuration["Discord:InviteLink"];
|
ViewBag.DiscordLink = Manager.GetApplicationSettings().DiscordInviteCode;
|
||||||
base.OnActionExecuting(context);
|
base.OnActionExecuting(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
WebfrontCore/IW4MAdminSettings.json
Normal file
0
WebfrontCore/IW4MAdminSettings.json
Normal file
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SharedLibrary.Configuration;
|
||||||
|
|
||||||
namespace WebfrontCore
|
namespace WebfrontCore
|
||||||
{
|
{
|
||||||
@ -16,8 +17,7 @@ namespace WebfrontCore
|
|||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.SetBasePath(env.ContentRootPath)
|
.SetBasePath(env.ContentRootPath)
|
||||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
||||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
|
||||||
.AddEnvironmentVariables();
|
.AddEnvironmentVariables();
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@
|
|||||||
<li class="nav-item text-center text-md-left">@Html.ActionLink("Penalties", "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li>
|
<li class="nav-item text-center text-md-left">@Html.ActionLink("Penalties", "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li>
|
||||||
<li class="nav-item text-center text-md-left">@Html.ActionLink("Admins", "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li>
|
<li class="nav-item text-center text-md-left">@Html.ActionLink("Admins", "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li>
|
||||||
<li class="nav-item text-center text-md-left">@Html.ActionLink("Console", "Index", "Console", new { area = "" }, new { @class = "nav-link" })</li>
|
<li class="nav-item text-center text-md-left">@Html.ActionLink("Console", "Index", "Console", new { area = "" }, new { @class = "nav-link" })</li>
|
||||||
@if (ViewBag.DiscordLink != string.Empty)
|
@if (!string.IsNullOrEmpty(ViewBag.DiscordLink))
|
||||||
{
|
{
|
||||||
<li class="nav-item text-center text-md-left"><a href="@ViewBag.DiscordLink" target="_blank"></a></li>
|
<li class="nav-item text-center text-md-left"><a href="@ViewBag.DiscordLink" class="nav-link" target="_blank">Discord</a></li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<form class="form-inline text-primary pt-3 pb-3" method="get" action="/Client/FindAsync">
|
<form class="form-inline text-primary pt-3 pb-3" method="get" action="/Client/FindAsync">
|
||||||
|
@ -63,6 +63,12 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="IW4MAdminSettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
<Exec Command="xcopy /Y "$(SolutionDir)BUILD\Plugins" "$(TargetDir)Plugins\"
xcopy /Y /I /E "$(SolutionDir)BUILD\Lib" "$(TargetDir)" 

xcopy /Y /I /E "$(ProjectDir)Application\Config" "$(TargetDir)Config"" />
|
<Exec Command="xcopy /Y "$(SolutionDir)BUILD\Plugins" "$(TargetDir)Plugins\"
xcopy /Y /I /E "$(SolutionDir)BUILD\Lib" "$(TargetDir)" 

xcopy /Y /I /E "$(ProjectDir)Application\Config" "$(TargetDir)Config"" />
|
||||||
</Target>
|
</Target>
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"IncludeScopes": false,
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Trace",
|
|
||||||
"System": "Information",
|
|
||||||
"Microsoft": "None"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Web": {
|
|
||||||
"Address": "127.0.0.1:5000"
|
|
||||||
},
|
|
||||||
"VPN": {
|
|
||||||
"APIKey": ""
|
|
||||||
},
|
|
||||||
"IW4MAdmin": {
|
|
||||||
},
|
|
||||||
"Discord": {
|
|
||||||
"InviteLink" : ""
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,13 +9,5 @@
|
|||||||
},
|
},
|
||||||
"Web": {
|
"Web": {
|
||||||
"Address": "http://127.0.0.1:5000"
|
"Address": "http://127.0.0.1:5000"
|
||||||
},
|
|
||||||
"VPN": {
|
|
||||||
"APIKey": ""
|
|
||||||
},
|
|
||||||
"IW4MAdmin": {
|
|
||||||
},
|
|
||||||
"Discord": {
|
|
||||||
"InviteLink" : ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user