mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 07:13:58 -05:00
fixed issue with not escaping regex for validating commands
This commit is contained in:
@ -48,6 +48,8 @@ namespace IW4MAdmin
|
||||
|
||||
Console.Write("Enter server RCON password: ");
|
||||
newConfig.Password = Console.ReadLine();
|
||||
newConfig.AutoMessages = new List<string>();
|
||||
newConfig.Rules = new List<string>();
|
||||
|
||||
configList.Add(newConfig);
|
||||
|
||||
@ -57,39 +59,5 @@ namespace IW4MAdmin
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace IW4MAdmin
|
||||
static public ApplicationManager ServerManager = ApplicationManager.GetInstance();
|
||||
public static string OperatingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
|
||||
|
||||
public static void Start()
|
||||
public static bool Start()
|
||||
{
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", OperatingDirectory);
|
||||
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
|
||||
@ -66,6 +66,8 @@ namespace IW4MAdmin
|
||||
Console.WriteLine("Shutdown complete");
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
@ -78,7 +80,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
Console.WriteLine("Press any key to exit...");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,15 +88,6 @@ namespace IW4MAdmin
|
||||
{
|
||||
string curDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
|
||||
|
||||
if (!Directory.Exists($"{curDirectory}Config"))
|
||||
{
|
||||
Console.WriteLine("Warning: Config folder does not exist");
|
||||
Directory.CreateDirectory($"{curDirectory}Config");
|
||||
}
|
||||
|
||||
if (!Directory.Exists($"{curDirectory}Config/Servers"))
|
||||
Directory.CreateDirectory($"{curDirectory}Config/Servers");
|
||||
|
||||
if (!Directory.Exists($"{curDirectory}Logs"))
|
||||
Directory.CreateDirectory($"{curDirectory}Logs");
|
||||
|
||||
|
@ -37,11 +37,11 @@ namespace IW4MAdmin
|
||||
ClientService ClientSvc;
|
||||
AliasService AliasSvc;
|
||||
PenaltyService PenaltySvc;
|
||||
IConfigurationRoot AppSettings;
|
||||
BaseConfigurationHandler<ApplicationConfiguration> ConfigHandler;
|
||||
#if FTP_LOG
|
||||
const int UPDATE_FREQUENCY = 700;
|
||||
#else
|
||||
const int UPDATE_FREQUENCY = 750;
|
||||
const int UPDATE_FREQUENCY = 450;
|
||||
#endif
|
||||
|
||||
private ApplicationManager()
|
||||
@ -56,13 +56,7 @@ namespace IW4MAdmin
|
||||
PenaltySvc = new PenaltyService();
|
||||
AdministratorIPs = new List<int>();
|
||||
ServerEventOccurred += EventAPI.OnServerEventOccurred;
|
||||
}
|
||||
|
||||
private void BuildConfiguration()
|
||||
{
|
||||
AppSettings = new ConfigurationBuilder()
|
||||
.AddJsonFile($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json")
|
||||
.Build();
|
||||
ConfigHandler = new BaseConfigurationHandler<ApplicationConfiguration>("IW4MAdminSettings");
|
||||
}
|
||||
|
||||
public IList<Server> GetServers()
|
||||
@ -88,6 +82,27 @@ namespace IW4MAdmin
|
||||
.ToList();
|
||||
#endregion
|
||||
|
||||
|
||||
#region CONFIG
|
||||
var config = ConfigHandler.Configuration();
|
||||
if (config?.Servers == null)
|
||||
{
|
||||
var newConfig = (ApplicationConfiguration)ConfigHandler.Configuration().Generate();
|
||||
ConfigHandler.Set(newConfig);
|
||||
|
||||
newConfig.AutoMessagePeriod = config.AutoMessagePeriod;
|
||||
newConfig.AutoMessages = config.AutoMessages;
|
||||
newConfig.GlobalRules = config.GlobalRules;
|
||||
newConfig.Maps = config.Maps;
|
||||
newConfig.Servers = ConfigurationGenerator.GenerateServerConfig(new List<ServerConfiguration>());
|
||||
config = newConfig;
|
||||
await ConfigHandler.Save();
|
||||
}
|
||||
|
||||
else if (config.Servers.Count == 0)
|
||||
throw new ServerException("A server configuration in IW4MAdminSettings.json is invalid");
|
||||
|
||||
|
||||
#region PLUGINS
|
||||
SharedLibrary.Plugins.PluginImporter.Load(this);
|
||||
|
||||
@ -107,26 +122,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CONFIG
|
||||
BuildConfiguration();
|
||||
var settings = AppSettings.Get<ApplicationConfiguration>();
|
||||
|
||||
if (settings?.Servers == null)
|
||||
{
|
||||
var newSettings = ConfigurationGenerator.GenerateApplicationConfig();
|
||||
newSettings.Servers = ConfigurationGenerator.GenerateServerConfig(new List<ServerConfiguration>());
|
||||
newSettings.AutoMessagePeriod = settings.AutoMessagePeriod;
|
||||
newSettings.AutoMessages = settings.AutoMessages;
|
||||
newSettings.Rules = settings.Rules;
|
||||
newSettings.Maps = settings.Maps;
|
||||
settings = newSettings;
|
||||
|
||||
var appConfigJSON = JsonConvert.SerializeObject(newSettings, Formatting.Indented);
|
||||
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json", appConfigJSON);
|
||||
BuildConfiguration();
|
||||
}
|
||||
|
||||
foreach (var Conf in settings.Servers)
|
||||
foreach (var Conf in config.Servers)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -285,6 +281,6 @@ namespace IW4MAdmin
|
||||
public AliasService GetAliasService() => AliasSvc;
|
||||
public PenaltyService GetPenaltyService() => PenaltySvc;
|
||||
|
||||
public ApplicationConfiguration GetApplicationSettings() => AppSettings.Get<ApplicationConfiguration>();
|
||||
public IConfigurationHandler<ApplicationConfiguration> GetApplicationSettings() => ConfigHandler;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,9 @@ namespace WebfrontCore.Application.Misc
|
||||
public static async Task<bool> UsingVPN(string ip, string apiKey)
|
||||
{
|
||||
#if DEBUG
|
||||
return false;
|
||||
#endif
|
||||
return await Task.FromResult(false);
|
||||
|
||||
#else
|
||||
try
|
||||
{
|
||||
using (var RequestClient = new System.Net.Http.HttpClient())
|
||||
@ -30,6 +31,7 @@ namespace WebfrontCore.Application.Misc
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,8 +144,8 @@ namespace IW4MAdmin
|
||||
await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this));
|
||||
|
||||
|
||||
if (!Manager.GetApplicationSettings().EnableClientVPNs &&
|
||||
await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().IPHubAPIKey))
|
||||
if (!Manager.GetApplicationSettings().Configuration().EnableClientVPNs &&
|
||||
await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().Configuration().IPHubAPIKey))
|
||||
{
|
||||
await player.Kick("VPNs are not allowed on this server", new Player() { ClientId = 1 });
|
||||
}
|
||||
@ -314,8 +314,8 @@ namespace IW4MAdmin
|
||||
else if (matchingPlayers.Count == 1)
|
||||
{
|
||||
E.Target = matchingPlayers.First();
|
||||
E.Data = Regex.Replace(E.Data, $"{E.Target.Name}", "", RegexOptions.IgnoreCase).Trim();
|
||||
E.Data = Regex.Replace(E.Data, $"{Args[0]}", "", RegexOptions.IgnoreCase).Trim();
|
||||
E.Data = Regex.Replace(E.Data, Regex.Escape($"{E.Target.Name}"), "", RegexOptions.IgnoreCase).Trim();
|
||||
E.Data = Regex.Replace(E.Data, Regex.Escape($"{Args[0]}"), "", RegexOptions.IgnoreCase).Trim();
|
||||
|
||||
if ((E.Data.Trim() == E.Target.Name.ToLower().Trim() ||
|
||||
E.Data == String.Empty) &&
|
||||
@ -465,7 +465,9 @@ namespace IW4MAdmin
|
||||
playerCountStart = DateTime.Now;
|
||||
}
|
||||
|
||||
if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().AutoMessagePeriod && BroadcastMessages.Count > 0 && ClientNum > 0)
|
||||
if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod
|
||||
&& BroadcastMessages.Count > 0
|
||||
&& ClientNum > 0)
|
||||
{
|
||||
await Broadcast(Utilities.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage]));
|
||||
NextMessage = NextMessage == (BroadcastMessages.Count - 1) ? 0 : NextMessage + 1;
|
||||
@ -664,7 +666,7 @@ namespace IW4MAdmin
|
||||
await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports");
|
||||
|
||||
// give trusted rank
|
||||
if (Manager.GetApplicationSettings().EnableTrustedRank &&
|
||||
if (Manager.GetApplicationSettings().Configuration().EnableTrustedRank &&
|
||||
E.Origin.TotalConnectionTime / 60.0 >= 2880 &&
|
||||
E.Origin.Level < Player.Permission.Trusted &&
|
||||
E.Origin.Level != Player.Permission.Flagged)
|
||||
@ -960,7 +962,6 @@ namespace IW4MAdmin
|
||||
{
|
||||
InitializeMaps();
|
||||
InitializeAutoMessages();
|
||||
InitializeRules();
|
||||
return true;
|
||||
}
|
||||
catch (Exception E)
|
||||
@ -968,7 +969,6 @@ namespace IW4MAdmin
|
||||
Logger.WriteError("Unable to reload configs! - " + E.Message);
|
||||
BroadcastMessages = new List<String>();
|
||||
Maps = new List<Map>();
|
||||
Rules = new List<String>();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ namespace WebfrontCore.Controllers
|
||||
Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP());
|
||||
ViewBag.Authorized = Authorized;
|
||||
ViewBag.Url = Startup.Configuration["Web:Address"];
|
||||
ViewBag.DiscordLink = Manager.GetApplicationSettings().DiscordInviteCode;
|
||||
string inviteLink = Manager.GetApplicationSettings().Configuration().DiscordInviteCode;
|
||||
ViewBag.DiscordLink = inviteLink.Contains("http") ? inviteLink : $"https://discordapp.com/invite/{inviteLink}";
|
||||
base.OnActionExecuting(context);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,17 @@
|
||||
{
|
||||
"AutoMessagePeriod": 60,
|
||||
"AutoMessages": [
|
||||
"Over ^5{{TOTALPLAYTIME}} ^7man hours have been played on this server!",
|
||||
"This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin",
|
||||
"^5IW4M Admin ^7sees ^5YOU!",
|
||||
"This server has harvested the information of ^5{{TOTALPLAYERS}} ^7players!",
|
||||
"This server has seen a total of ^5{{TOTALPLAYERS}} ^7players!",
|
||||
"Cheaters are ^1unwelcome ^7 on this server",
|
||||
"Did you know 8/10 people agree with unverified statistics?",
|
||||
"^5{{TOTALKILLS}} ^7innocent people have been murdered in this server!"
|
||||
"Did you know 8/10 people agree with unverified statistics?"
|
||||
],
|
||||
"Rules": [
|
||||
"GlobalRules": [
|
||||
"Cheating/Exploiting is not allowed",
|
||||
"Respect other players",
|
||||
"Administrators have the final say",
|
||||
"No Racism or excessive trolling",
|
||||
"No racism or excessive trolling",
|
||||
"Keep grenade launcher use to a minimum",
|
||||
"Balance teams at ALL times"
|
||||
],
|
||||
|
@ -21,7 +21,8 @@ namespace WebfrontCore
|
||||
.AddEnvironmentVariables();
|
||||
Configuration = builder.Build();
|
||||
|
||||
IW4MAdmin.Program.Start();
|
||||
if (!IW4MAdmin.Program.Start())
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
|
||||
public static IConfigurationRoot Configuration { get; private set; }
|
||||
|
@ -70,7 +70,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="xcopy /Y "$(SolutionDir)BUILD\Plugins" "$(TargetDir)Plugins\"
xcopy /Y /I /E "$(SolutionDir)BUILD\Lib" "$(TargetDir)" 
" />
|
||||
<Exec Command="xcopy /Y "$(SolutionDir)BUILD\Plugins" "$(TargetDir)Plugins\"
" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -76,6 +76,7 @@ function refreshClientActivity() {
|
||||
cache: false
|
||||
})
|
||||
.done(function (response) {
|
||||
//const clientCount = $(response).find('.col-6 span').length;
|
||||
$('#server_clientactivity_' + serverId).html(response);
|
||||
})
|
||||
.fail(function (jqxhr, textStatus, error) {
|
||||
|
Reference in New Issue
Block a user