public bool IpAllow(string ipaddress) { return(WhiteList.Any(ip => ip == ipaddress)); }
private static void CheckFiles() { var gameFilePaths = Directory.GetFiles(CommonUtil.CombinePaths(Client.KspPath, "GameData"), "*", SearchOption.AllDirectories); var gameFileRelativePaths = gameFilePaths.Select( filePath => filePath.Substring(filePath.ToLowerInvariant().IndexOf("gamedata", StringComparison.Ordinal) + 9) .Replace('\\', '/')).ToList(); //Check Required foreach (var requiredEntry in ParseRequired) { if (!requiredEntry.Key.EndsWith("dll")) { CheckNonDllFile(gameFileRelativePaths, requiredEntry, true); } else { CheckDllFile(requiredEntry, true); } } //Check Optional foreach (var optionalEntry in ParseOptional) { if (!optionalEntry.Key.EndsWith("dll")) { CheckNonDllFile(gameFileRelativePaths, optionalEntry, false); } else { CheckDllFile(optionalEntry, false); } } if (WhiteList.Any() && !BlackList.Any()) //Check Resource whitelist { var autoAllowed = new List <string> { "lunamultiplayer/plugins/lunaclient.dll", "lunamultiplayer/plugins/lunacommon.dll", "lunamultiplayer/plugins/fastmember.dll", "lunamultiplayer/plugins/lidgren.network.dll", "lunamultiplayer/plugins/mono.data.tds.dll", "lunamultiplayer/plugins/system.data.dll", "lunamultiplayer/plugins/system.threading.dll", "lunamultiplayer/plugins/system.transactions.dll" }; //Allow LMP files, Ignore squad plugins, Check required (Required implies whitelist), Check optional (Optional implies whitelist) //Check whitelist foreach (var dllResource in SystemsContainer.Get <ModSystem>().DllList.Where( dllResource => !autoAllowed.Contains(dllResource.Key) && !dllResource.Key.StartsWith("squad/plugins") && !ParseRequired.ContainsKey(dllResource.Key) && !ParseOptional.ContainsKey(dllResource.Key) && !WhiteList.ContainsKey(dllResource.Key))) { ModCheckOk = false; LunaLog.Log($"[LMP]: Non-whitelisted resource {dllResource.Key} exists on client!"); StringBuilder.AppendLine($"Non-whitelisted resource {dllResource.Key} exists on client!"); } } if (!WhiteList.Any() && BlackList.Any()) //Check Resource blacklist { foreach (var blacklistEntry in BlackList.Keys.Where(blacklistEntry => SystemsContainer.Get <ModSystem>().DllList.ContainsKey(blacklistEntry))) { ModCheckOk = false; LunaLog.Log($"[LMP]: Banned resource {blacklistEntry} exists on client!"); StringBuilder.AppendLine($"Banned resource {blacklistEntry} exists on client!"); } } }
//Checks if an ip is in the whitelist protected bool CheckWhitelist(string ip) { var address = IPAddress.Parse(ip); return(WhiteList.Any(x => Equals(x, address))); }