mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
fixed issue with not escaping regex for validating commands
This commit is contained in:
@ -424,7 +424,7 @@ namespace SharedLibrary.Commands
|
||||
if (newPerm == Player.Permission.Owner && E.Origin.Level != Player.Permission.Console)
|
||||
newPerm = Player.Permission.Banned;
|
||||
|
||||
if (newPerm == Player.Permission.Owner && !E.Owner.Manager.GetApplicationSettings().EnableMultipleOwners)
|
||||
if (newPerm == Player.Permission.Owner && !E.Owner.Manager.GetApplicationSettings().Configuration().EnableMultipleOwners)
|
||||
{
|
||||
await E.Origin.Tell("There can only be 1 owner. Modify your appsettings if multiple owners are required");
|
||||
return;
|
||||
@ -585,7 +585,8 @@ namespace SharedLibrary.Commands
|
||||
|
||||
public override async Task ExecuteAsync(Event E)
|
||||
{
|
||||
if (E.Owner.Rules.Count < 1)
|
||||
if (E.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules?.Count < 1 &&
|
||||
E.Owner.ServerConfig.Rules?.Count < 1)
|
||||
{
|
||||
if (E.Message.IsBroadcastCommand())
|
||||
await E.Owner.Broadcast("The server owner has not set any rules");
|
||||
@ -595,7 +596,12 @@ namespace SharedLibrary.Commands
|
||||
|
||||
else
|
||||
{
|
||||
foreach (String r in E.Owner.Rules)
|
||||
var rules = new List<string>();
|
||||
rules.AddRange(E.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules);
|
||||
if (E.Owner.ServerConfig.Rules != null)
|
||||
rules.AddRange(E.Owner.ServerConfig.Rules);
|
||||
|
||||
foreach (string r in rules)
|
||||
{
|
||||
if (E.Message.IsBroadcastCommand())
|
||||
await E.Owner.Broadcast($"- {r}");
|
||||
|
@ -1,20 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using SharedLibrary.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SharedLibrary.Configuration
|
||||
{
|
||||
public class ApplicationConfiguration
|
||||
public class ApplicationConfiguration : IBaseConfiguration
|
||||
{
|
||||
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; }
|
||||
public int AutoMessagePeriod { get; set; }
|
||||
public List<string> AutoMessages { get; set; }
|
||||
public List<string> Rules { get; set; }
|
||||
public List<string> GlobalRules { get; set; }
|
||||
public List<MapConfiguration> Maps { get; set; }
|
||||
|
||||
public IBaseConfiguration Generate()
|
||||
{
|
||||
Console.Write("Enable multiple owners? [y/n]: ");
|
||||
EnableMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Enable trusted rank? [y/n]: ");
|
||||
EnableTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Enable client VPNs [y/n]: ");
|
||||
EnableClientVPNs = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
if (EnableClientVPNs)
|
||||
{
|
||||
Console.Write("Enter iphub.info api key: ");
|
||||
IPHubAPIKey = Console.ReadLine();
|
||||
}
|
||||
|
||||
Console.Write("Display discord link on webfront [y/n]: ");
|
||||
EnableDiscordLink = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
if (EnableDiscordLink)
|
||||
{
|
||||
Console.Write("Enter discord invite link: ");
|
||||
DiscordInviteCode = Console.ReadLine();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Name() => "ApplicationConfiguration";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
namespace SharedLibrary.Configuration
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibrary.Configuration
|
||||
{
|
||||
public class ServerConfiguration
|
||||
{
|
||||
public string IPAddress { get; set; }
|
||||
public short Port { get; set; }
|
||||
public string Password { get; set; }
|
||||
public List<string> Rules { get; set; }
|
||||
public List<string> AutoMessages { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace SharedLibrary.Dtos
|
||||
public class ProfileMeta : SharedInfo
|
||||
{
|
||||
public DateTime When { get; set; }
|
||||
public bool Sensitive { get; set; }
|
||||
public string WhenString => Utilities.GetTimePassed(When, false);
|
||||
public string Key { get; set; }
|
||||
public dynamic Value { get; set; }
|
||||
|
53
SharedLibrary/Helpers/BaseConfigurationHandler.cs
Normal file
53
SharedLibrary/Helpers/BaseConfigurationHandler.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using SharedLibrary.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Configuration
|
||||
{
|
||||
public class BaseConfigurationHandler<T> : IConfigurationHandler<T> where T : IBaseConfiguration
|
||||
{
|
||||
string Filename;
|
||||
IConfigurationRoot ConfigurationRoot { get; set; }
|
||||
T _configuration;
|
||||
|
||||
public BaseConfigurationHandler(string fn)
|
||||
{
|
||||
Filename = fn;
|
||||
Build();
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
ConfigurationRoot = new ConfigurationBuilder()
|
||||
.AddJsonFile($"{AppDomain.CurrentDomain.BaseDirectory}{Filename}.json", true)
|
||||
.Build();
|
||||
|
||||
_configuration = ConfigurationRoot.Get<T>();
|
||||
|
||||
if (_configuration == null)
|
||||
_configuration = default(T);
|
||||
}
|
||||
|
||||
public Task Save()
|
||||
{
|
||||
var appConfigJSON = JsonConvert.SerializeObject(_configuration, Formatting.Indented);
|
||||
return Task.Factory.StartNew(() =>
|
||||
{
|
||||
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}{Filename}.json", appConfigJSON);
|
||||
});
|
||||
}
|
||||
|
||||
public T Configuration() => _configuration;
|
||||
|
||||
public void Set(T config)
|
||||
{
|
||||
_configuration = config;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class ConfigurationManager
|
||||
{
|
||||
ConcurrentDictionary<string, dynamic> ConfigSet;
|
||||
Server ServerInstance;
|
||||
|
||||
public ConfigurationManager(Server S)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigSet = Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Read($"{Utilities.OperatingDirectory}config/plugins_{S.ToString()}.cfg");
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
S.Logger.WriteInfo("ConfigurationManager could not deserialize configuration file, so initializing default config set");
|
||||
ConfigSet = new ConcurrentDictionary<string, dynamic>();
|
||||
}
|
||||
|
||||
ServerInstance = S;
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
private void SaveChanges()
|
||||
{
|
||||
Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Write($"{Utilities.OperatingDirectory}config/plugins_{ServerInstance.ToString()}.cfg", ConfigSet);
|
||||
}
|
||||
|
||||
public void AddProperty(KeyValuePair<string, dynamic> prop)
|
||||
{
|
||||
if (!ConfigSet.ContainsKey(prop.Key))
|
||||
ConfigSet.TryAdd(prop.Key, prop.Value);
|
||||
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateProperty(KeyValuePair<string, dynamic> prop)
|
||||
{
|
||||
if (ConfigSet.ContainsKey(prop.Key))
|
||||
ConfigSet[prop.Key] = prop.Value;
|
||||
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
public T GetProperty<T>(string prop)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConfigSet[prop].ToObject<T>();
|
||||
}
|
||||
|
||||
catch (RuntimeBinderException)
|
||||
{
|
||||
return ConfigSet[prop];
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
SharedLibrary/Interfaces/IBaseConfiguration.cs
Normal file
14
SharedLibrary/Interfaces/IBaseConfiguration.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Interfaces
|
||||
{
|
||||
public interface IBaseConfiguration
|
||||
{
|
||||
string Name();
|
||||
IBaseConfiguration Generate();
|
||||
}
|
||||
}
|
16
SharedLibrary/Interfaces/IConfigurationHandler.cs
Normal file
16
SharedLibrary/Interfaces/IConfigurationHandler.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Interfaces
|
||||
{
|
||||
public interface IConfigurationHandler<T> where T : IBaseConfiguration
|
||||
{
|
||||
Task Save();
|
||||
void Build();
|
||||
T Configuration();
|
||||
void Set(T config);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ namespace SharedLibrary.Interfaces
|
||||
IList<Command> GetCommands();
|
||||
IList<Helpers.MessageToken> GetMessageTokens();
|
||||
IList<Player> GetActiveClients();
|
||||
ApplicationConfiguration GetApplicationSettings();
|
||||
IConfigurationHandler<ApplicationConfiguration> GetApplicationSettings();
|
||||
ClientService GetClientService();
|
||||
AliasService GetAliasService();
|
||||
PenaltyService GetPenaltyService();
|
||||
|
@ -15,7 +15,6 @@ using SharedLibrary.Configuration;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
[Guid("61d3829e-fcbe-44d3-bb7c-51db8c2d7ac5")]
|
||||
public abstract class Server
|
||||
{
|
||||
public enum Game
|
||||
@ -44,7 +43,6 @@ namespace SharedLibrary
|
||||
NextMessage = 0;
|
||||
InitializeTokens();
|
||||
InitializeAutoMessages();
|
||||
InitializeRules();
|
||||
}
|
||||
|
||||
//Returns current server IP set by `net_ip` -- *STRING*
|
||||
@ -253,7 +251,7 @@ namespace SharedLibrary
|
||||
protected void InitializeMaps()
|
||||
{
|
||||
Maps = new List<Map>();
|
||||
Maps.AddRange(Manager.GetApplicationSettings().Maps.First(m => m.Game == GameName).Maps);
|
||||
Maps.AddRange(Manager.GetApplicationSettings().Configuration().Maps.First(m => m.Game == GameName).Maps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -264,22 +262,11 @@ namespace SharedLibrary
|
||||
{
|
||||
BroadcastMessages = new List<String>();
|
||||
|
||||
BroadcastMessages.AddRange(Manager.GetApplicationSettings().AutoMessages);
|
||||
if(ServerConfig.AutoMessages != null)
|
||||
BroadcastMessages.AddRange(ServerConfig.AutoMessages);
|
||||
BroadcastMessages.AddRange(Manager.GetApplicationSettings().Configuration().AutoMessages);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the rules configuration
|
||||
/// todo: this needs to be a serialized file
|
||||
/// </summary>
|
||||
protected void InitializeRules()
|
||||
{
|
||||
Rules = new List<String>();
|
||||
|
||||
Rules.AddRange(Manager.GetApplicationSettings().Rules);
|
||||
}
|
||||
|
||||
public ConfigurationManager Configuration { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{IP}_{Port}";
|
||||
@ -303,10 +290,9 @@ namespace SharedLibrary
|
||||
public Interfaces.ILogger Logger { get; private set; }
|
||||
public ServerConfiguration ServerConfig { get; private set; }
|
||||
public List<Map> Maps { get; protected set; }
|
||||
public List<string> Rules { get; protected set; }
|
||||
public List<Report> Reports { get; set; }
|
||||
public List<ChatInfo> ChatHistory { get; protected set; }
|
||||
public Queue<Helpers.PlayerHistory> PlayerHistory { get; private set; }
|
||||
public Queue<PlayerHistory> PlayerHistory { get; private set; }
|
||||
public Game GameName { get; protected set; }
|
||||
|
||||
// Info
|
||||
|
@ -172,9 +172,11 @@
|
||||
<Compile Include="Exceptions\NetworkException.cs" />
|
||||
<Compile Include="Exceptions\SerializationException.cs" />
|
||||
<Compile Include="Exceptions\ServerException.cs" />
|
||||
<Compile Include="Helpers\ConfigurationManager.cs" />
|
||||
<Compile Include="Helpers\BaseConfigurationHandler.cs" />
|
||||
<Compile Include="Helpers\ParseEnum.cs" />
|
||||
<Compile Include="Helpers\Vector3.cs" />
|
||||
<Compile Include="Interfaces\IBaseConfiguration.cs" />
|
||||
<Compile Include="Interfaces\IConfigurationHandler.cs" />
|
||||
<Compile Include="Interfaces\IEntityService.cs" />
|
||||
<Compile Include="Interfaces\ILogger.cs" />
|
||||
<Compile Include="Interfaces\IManager.cs" />
|
||||
@ -228,9 +230,18 @@
|
||||
<PackageReference Include="EntityFramework.SqlServerCompact">
|
||||
<Version>6.2.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration">
|
||||
<Version>1.1.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions">
|
||||
<Version>1.1.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder">
|
||||
<Version>1.1.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json">
|
||||
<Version>1.1.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>11.0.1</Version>
|
||||
</PackageReference>
|
||||
|
Reference in New Issue
Block a user