new working type filter

This commit is contained in:
Oiltanker
2022-04-17 18:23:41 +03:00
parent a7b4004058
commit 03881f1240
@@ -23,18 +23,27 @@ namespace Barotrauma {
// Barotrauma // Barotrauma
"Barotrauma", "Barotrauma",
// Lua // Lua
"MoonSharp.Interpreter" "MoonSharp.Interpreter.DynValue",
"MoonSharp.Interpreter.Closure",
"MoonSharp.Interpreter.Coroutine",
"MoonSharp.Interpreter.CoroutineState",
"MoonSharp.Interpreter.Table",
"MoonSharp.Interpreter.YieldRequest",
"MoonSharp.Interpreter.TailCallData",
"MoonSharp.Interpreter.DataType",
}; };
private static readonly string[] typesProhibited = new string[] { private static readonly string[] typesProhibited = new string[] {
//"System.Reflection", //"System.Reflection",
"System.IO", "System.IO",
"Moonsharp.Interpreter.UserData" "Moonsharp"
}; };
public static bool IsTypeAllowed(string name) public static bool IsTypeAllowed(string name)
{ {
var longestPemited = typesPermitted.Where(s => s.StartsWith(name)).Max(s => s.Length); var matchPermitted = typesPermitted.Where(s => name.StartsWith(s));
var longestProhibitted = typesProhibited.Where(s => s.StartsWith(name)).Max(s => s.Length); var longestPemitted = matchPermitted.Count() > 0 ? matchPermitted.Max(s => s.Length) : 0;
if (longestPemited == 0 || longestPemited < longestProhibitted) return false; var matchProhibited = typesProhibited.Where(s => name.StartsWith(s));
var longestProhibited = matchProhibited.Count() > 0 ? matchProhibited.Max(s => s.Length) : 0;
if (longestPemitted == 0 || longestPemitted < longestProhibited) return false;
else return true; else return true;
} }