1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 07:13:58 -05:00

started update for readme

start update for version changes
hopefully fixed pesky stat bug
move vpn detection into script plugin
This commit is contained in:
RaidMax
2018-08-26 19:20:47 -05:00
parent 7bb2c8601b
commit d3333aa019
22 changed files with 388 additions and 192 deletions

View File

@ -22,13 +22,13 @@ namespace SharedLibraryCore.Configuration
public string CustomLocale { get; set; }
public string ConnectionString { get; set; }
public int RConPollRate { get; set; } = 5000;
public List<int> VpnExceptionIds { get; set; }
public string Id { get; set; }
public List<ServerConfiguration> Servers { get; set; }
public int AutoMessagePeriod { get; set; }
public List<string> AutoMessages { get; set; }
public List<string> GlobalRules { get; set; }
public List<MapConfiguration> Maps { get; set; }
public List<int> VpnExceptionIds { get; set; }
public IBaseConfiguration Generate()
{

View File

@ -9,8 +9,8 @@ namespace SharedLibraryCore.Configuration
public string IPAddress { get; set; }
public ushort Port { get; set; }
public string Password { get; set; }
public List<string> Rules { get; set; }
public List<string> AutoMessages { get; set; }
public IList<string> Rules { get; set; }
public IList<string> AutoMessages { get; set; }
public bool UseT6MParser { get; set; }
public bool UseIW5MParser { get; set; }
public string ManualLogPath { get; set; }

View File

@ -87,6 +87,7 @@ namespace SharedLibraryCore
{
return queuedEvent.Origin != null &&
!queuedEvent.Origin.IsAuthenticated &&
queuedEvent.Origin.State != Player.ClientState.Connected &&
// we want to allow join and quit events
queuedEvent.Type != EventType.Join &&
queuedEvent.Type != EventType.Quit &&
@ -104,6 +105,7 @@ namespace SharedLibraryCore
{
return queuedEvent.Target != null &&
!queuedEvent.Target.IsAuthenticated &&
queuedEvent.Target.State != Player.ClientState.Connected &&
queuedEvent.Target.NetworkId != 0;
}
}

View File

@ -13,37 +13,33 @@ namespace SharedLibraryCore.Plugins
public static List<IPlugin> ActivePlugins = new List<IPlugin>();
public static List<Assembly> PluginAssemblies = new List<Assembly>();
private static void LoadScriptPlugins(IManager mgr)
{
string[] scriptFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.js");
foreach(string fileName in scriptFileNames)
{
var plugin = new ScriptPlugin(fileName);
plugin.Initialize(mgr).Wait();
ActivePlugins.Add(plugin);
}
}
public static bool Load(IManager Manager)
{
string[] dllFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.dll");
string[] scriptFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.js");
if (dllFileNames.Length == 0)
if (dllFileNames.Length == 0 &&
scriptFileNames.Length == 0)
{
Manager.GetLogger().WriteDebug(Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_IMPORTER_NOTFOUND"]);
return true;
}
// load up the script plugins
foreach (string fileName in scriptFileNames)
{
var plugin = new ScriptPlugin(fileName);
plugin.Initialize(Manager).Wait();
Manager.GetLogger().WriteDebug($"Loaded script plugin \"{ plugin.Name }\" [{plugin.Version}]");
ActivePlugins.Add(plugin);
}
ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length);
foreach (string dllFile in dllFileNames)
{
// byte[] rawDLL = File.ReadAllBytes(dllFile);
//Assembly assembly = Assembly.Load(rawDLL);
assemblies.Add(Assembly.LoadFrom(dllFile));
}
int LoadedPlugins = 0;
int LoadedCommands = 0;
foreach (Assembly Plugin in assemblies)
{
@ -74,19 +70,17 @@ namespace SharedLibraryCore.Plugins
ActivePlugins.Add(newNotify);
PluginAssemblies.Add(Plugin);
Manager.GetLogger().WriteDebug($"Loaded plugin \"{ newNotify.Name }\" [{newNotify.Version}]");
LoadedPlugins++;
}
}
catch (Exception E)
{
Manager.GetLogger().WriteWarning($"Could not load plugin {Plugin.Location} - {E.Message}");
Manager.GetLogger().WriteWarning($"{Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_IMPORTER_ERROR"]} {Plugin.Location} - {E.Message}");
}
}
}
}
LoadScriptPlugins(Manager);
Manager.GetLogger().WriteInfo($"Loaded {LoadedPlugins} plugins and registered {LoadedCommands} commands.");
Manager.GetLogger().WriteInfo($"Loaded {ActivePlugins.Count} plugins and registered {LoadedCommands} commands.");
return true;
}
}

View File

@ -14,7 +14,7 @@ namespace SharedLibraryCore
public float Version { get; set; }
public string Author {get;set;}
public string Author { get; set; }
private Jint.Engine ScriptEngine;
private readonly string FileName;
@ -49,15 +49,22 @@ namespace SharedLibraryCore
public async Task Initialize(IManager mgr)
{
bool firstRun = ScriptEngine == null;
// it's been loaded before so we need to call the unload event
if (ScriptEngine != null)
if (!firstRun)
{
await OnUnloadAsync();
}
Manager = mgr;
string script = File.ReadAllText(FileName);
ScriptEngine = new Jint.Engine();
ScriptEngine = new Jint.Engine(cfg =>
cfg.AllowClr(new[]
{
typeof(System.Net.WebRequest).Assembly,
typeof(Objects.Player).Assembly,
})
.CatchClrExceptions());
ScriptEngine.Execute(script);
ScriptEngine.SetValue("_localization", Utilities.CurrentLocalization);
@ -67,7 +74,7 @@ namespace SharedLibraryCore
this.Name = pluginObject.name;
this.Version = (float)pluginObject.version;
if (ScriptEngine != null)
if (!firstRun)
{
await OnLoadAsync(mgr);
}

View File

@ -20,6 +20,16 @@ namespace SharedLibraryCore
public static Encoding EncodingType;
public static Localization.Layout CurrentLocalization;
public static string HttpRequest(string location, string header, string headerValue)
{
using (var RequestClient = new System.Net.Http.HttpClient())
{
RequestClient.DefaultRequestHeaders.Add(header, headerValue);
string response = RequestClient.GetStringAsync(location).Result;
return response;
}
}
//Get string with specified number of spaces -- really only for visual output
public static String GetSpaces(int Num)
{