There is a (modular) game application - the arena, it implements an abstract class (or interface) for the player. Players (game AI) inherit from the specified class and develop third-party developers and provide a compiled dll. Is there any way to limit the capabilities of this third-party dll? Well, for example, protect yourself from "FORMAT C:" or from sending data over the network, reading from a disk, etc. Even if this class falls in this case, then the player simply counts as a technical loss.
What a day I fight, but at least kill, I can’t understand how to make it work. How to make all third-party players work in the sandbox? Now there is something like this code:
static class PlayersHost { static public List<IPlayer> Players; static public void LoadPlayers() { Players = new List<IPlayer>(); var files = Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "Players"), "*.dll"); foreach (var file in files) { try { var asm = Assembly.LoadFrom(file); var types = asm.GetTypes(); foreach (var type in types) { try { IPlayer player = (IPlayer)Activator.CreateInstance(type); players.Add(player); } catch { } } } catch { } } } } Then I just load all the players when the application starts:
PlayersHost.LoadPlayers(); and use the resulting collection, for example:
var player = PlayersHost.Players[0]; try { player.PrepareToPlay(); } catch { } Need a solution using AppDomain
new SecurityPermission(SecurityPermissionFlag.Execution).PermitOnly()- PetSerAl