private bool _bIsBotBusy = false; // while a task for the bot is running don't start another task. instead don't send it anymore messages and fold until it is not busy at the start of a hand public ServerHoldemPlayer(int pPlayerNum, Dictionary<string, string> playerConfigSettings) { string dllFile = playerConfigSettings["dll"]; PlayerNum = pPlayerNum; StackSize = Convert.ToInt32(playerConfigSettings["startingStack"]); _botTimeOutMilliSeconds = Convert.ToInt32(playerConfigSettings["botTimeOutMilliSeconds"]); IsActive = true; IsAlive = true; _holeCards = new Card[2]; var an = AssemblyName.GetAssemblyName(dllFile); var assembly = Assembly.Load(an); var pluginType = typeof(IHoldemPlayer); var types = assembly.GetTypes(); foreach (var type in types.Where(type => !type.IsInterface && !type.IsAbstract && type.GetInterface(pluginType.FullName) != null)) { _player = (IHoldemPlayer) Activator.CreateInstance(type); InitPlayer(pPlayerNum, playerConfigSettings); break; } }
public ServerHoldemPlayer(int pPlayerNum, int pStackSize, string dllFile) { PlayerNum = pPlayerNum; StackSize = pStackSize; BetsThisBettingRound = 0; IsActive = true; IsAlive = true; _holeCards = new Card[2]; AssemblyName an = AssemblyName.GetAssemblyName(dllFile); Assembly assembly = Assembly.Load(an); Type pluginType = typeof(IHoldemPlayer); Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { if (type.GetInterface(pluginType.FullName) != null) { player = (IHoldemPlayer)Activator.CreateInstance(type); InitPlayer(pPlayerNum); break; } } } }
public ServerHoldemPlayer(int sandBoxNum, string dllName, bool isTrusted = false) { string botDir = "bots\\"; string dllFile = botDir + dllName; IsActive = true; IsAlive = true; _holeCards = new Card[2]; var an = AssemblyName.GetAssemblyName(dllFile); var assembly = Assembly.Load(an); var interfaceType = typeof(IHoldemPlayer); var types = assembly.GetTypes(); Type botType = null; foreach (var type in types.Where(type => !type.IsInterface && !type.IsAbstract && type.GetInterface(interfaceType.FullName) != null)) { botType = type; break; } if (botType == null) { throw new Exception(String.Format("A class that implements the IHoldemPlayer interface was not found in {0}.", dllFile)); } if (isTrusted) { // If bots is trusted then run inside the current app domain // !!! need a better way to identify trusted bots !!! use signing? _player = (IHoldemPlayer)Activator.CreateInstance(botType); } else { // Untrusted bot - create a new sandbox to run it in with limited permissions //Setting the AppDomainSetup. It is very important to set the ApplicationBase to a folder //other than the one in which the sandboxer resides. AppDomainSetup adSetup = new AppDomainSetup(); adSetup.ApplicationBase = Path.GetFullPath(botDir); //Setting the permissions for the AppDomain. We give the permission to execute and to //read/discover the location where the untrusted code is loaded. PermissionSet permSet = new PermissionSet(PermissionState.None); permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); //Now we have everything we need to create the AppDomain, so let's create it. _newDomain = AppDomain.CreateDomain("SandBox" + sandBoxNum, null, adSetup, permSet); // Now create an instance of the bot class inside the new appdomain _player = (IHoldemPlayer)_newDomain.CreateInstanceAndUnwrap(an.FullName, botType.FullName); } }
public ServerHoldemPlayer(int pPlayerNum, int pStackSize, string dllFile) { PlayerNum = pPlayerNum; StackSize = pStackSize; IsActive = true; IsAlive = true; _holeCards = new Card[2]; var an = AssemblyName.GetAssemblyName(dllFile); var assembly = Assembly.Load(an); var pluginType = typeof(IHoldemPlayer); var types = assembly.GetTypes(); foreach (var type in types.Where(type => !type.IsInterface && !type.IsAbstract && type.GetInterface(pluginType.FullName) != null)) { _player = (IHoldemPlayer) Activator.CreateInstance(type); InitPlayer(pPlayerNum); break; } }