示例#1
0
        public void CompilePlugins(PermissionSet pluginSandboxPermissions, List<String> ignoredPluginClassNames = null) {

            try {

                // Make sure we ignore any plugins passed in. These won't even be loaded again.
                if (ignoredPluginClassNames != null) {
                    this.IgnoredPluginClassNames = ignoredPluginClassNames;
                }

                // Clear out all invocations if this is a reload.
                this.Invocations.Clear();

                this.WritePluginConsole("Preparing plugins directory..");
                this.PreparePluginsDirectory();
                this.CleanPlugins();

                this.WritePluginConsole("Moving legacy plugins..");
                this.MoveLegacyPlugins();

                this.WritePluginConsole("Creating compiler..");
                // CodeDomProvider pluginsCodeDomProvider = CodeDomProvider.CreateProvider("CSharp");
                Dictionary<String, String> providerOptions = new Dictionary<String, String>();
                providerOptions.Add("CompilerVersion", "v3.5");
                CodeDomProvider pluginsCodeDomProvider = new CSharpCodeProvider(providerOptions);

                this.WritePluginConsole("Configuring compiler..");
                CompilerParameters parameters = GenerateCompilerParameters();
                // AppDomainSetup domainSetup = new AppDomainSetup() { ApplicationBase = this.PluginBaseDirectory };
                // Start of XpKillers mono workaround

                AppDomainSetup domainSetup = null;
                Type t = Type.GetType("Mono.Runtime");
                if (t != null)
                {
                    //Console.WriteLine("You are running with the Mono VM");
                    this.WritePluginConsole("Running with Mono VM..");
                    //AppDomain.CurrentDomain.BaseDirectory
                    domainSetup = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory };
                    domainSetup.PrivateBinPath = this.PluginBaseDirectory;
                }
                else
                {
                    // Console.WriteLine("You are running something else (native .Net)");
                    this.WritePluginConsole("Running with native .Net..");
                    domainSetup = new AppDomainSetup() { ApplicationBase = this.PluginBaseDirectory };
                }
                // Workaround end

                this.WritePluginConsole("Building sandbox..");
                Evidence hostEvidence = new Evidence();
                hostEvidence.AddHost(new Zone(SecurityZone.MyComputer));

                this.m_appDomainSandbox = AppDomain.CreateDomain(this.m_client.HostName + this.m_client.Port + "Engine", hostEvidence, domainSetup, pluginSandboxPermissions);

                this.WritePluginConsole("Configuring sandbox..");
                // create the factory class in the secondary app-domain
                CPRoConPluginLoaderFactory pluginFactory = (CPRoConPluginLoaderFactory)this.m_appDomainSandbox.CreateInstance("PRoCon.Core", "PRoCon.Core.Plugin.CPRoConPluginLoaderFactory").Unwrap();
                this.m_cpPluginCallbacks = new CPRoConPluginCallbacks(this.m_client.ExecuteCommand, this.m_client.GetAccountPrivileges, this.m_client.GetVariable, this.m_client.GetSvVariable, this.m_client.GetMapDefines, this.m_client.TryGetLocalized, this.RegisterCommand, this.UnregisterCommand, this.GetRegisteredCommands, this.m_client.GetWeaponDefines, this.m_client.GetSpecializationDefines, this.m_client.Layer.GetLoggedInAccounts, this.RegisterPluginEvents);

                this.WritePluginConsole("Compiling and loading plugins..");


                DirectoryInfo pluginsDirectoryInfo = new DirectoryInfo(this.PluginBaseDirectory);
                FileInfo[] a_pluginsFileInfo = pluginsDirectoryInfo.GetFiles("*.cs");

                foreach (FileInfo pluginFile in a_pluginsFileInfo) {

                    string className = Regex.Replace(pluginFile.Name, "\\.cs$", "");

                    if (this.IgnoredPluginClassNames.Contains(className) == false) {
                        this.CompilePlugin(pluginFile, className, pluginsCodeDomProvider, parameters);

                        this.LoadPlugin(className, pluginFactory, pluginSandboxPermissions.IsUnrestricted());
                    }
                    else {
                        this.WritePluginConsole("Compiling {0}... ^1^bIgnored", className);
                    }
                }

                pluginsCodeDomProvider.Dispose();
            }
            catch (Exception e) {
                this.WritePluginConsole(e.Message);
            }
        }
示例#2
0
        public void CompilePlugins(PermissionSet pluginSandboxPermissions, List<String> ignoredPluginClassNames = null) {
            try {

                if (File.Exists(Path.Combine(this.PluginBaseDirectory, "PluginCache.xml")) == true) {
                    WritePluginConsole("Loading plugin cache..");

                    try {
                        this.PluginCache = XDocument.Load(Path.Combine(this.PluginBaseDirectory, "PluginCache.xml")).Root.FromXElement<PluginCache>();
                    }
                    catch (Exception e) {
                        WritePluginConsole("Error loading plugin cache: {0}", e.Message);
                    }
                }

                // Recover from exceptions or logic errors if the document parsed correctly, but didn't deserialize correctly.
                if (this.PluginCache == null) {
                    this.PluginCache = new PluginCache();
                }

                // Make sure we ignore any plugins passed in. These won't even be loaded again.
                if (ignoredPluginClassNames != null) {
                    IgnoredPluginClassNames = ignoredPluginClassNames;
                }

                // Clear out all invocations if this is a reload.
                Invocations.Clear();

                WritePluginConsole("Preparing plugins directory..");
                PreparePluginsDirectory();

                WritePluginConsole("Moving legacy plugins..");
                MoveLegacyPlugins();

                WritePluginConsole("Creating compiler..");
                // CodeDomProvider pluginsCodeDomProvider = CodeDomProvider.CreateProvider("CSharp");
                var providerOptions = new Dictionary<String, String>();
                providerOptions.Add("CompilerVersion", "v3.5");
                CodeDomProvider pluginsCodeDomProvider = new CSharpCodeProvider(providerOptions);

                WritePluginConsole("Configuring compiler..");
                CompilerParameters parameters = GenerateCompilerParameters();
                // AppDomainSetup domainSetup = new AppDomainSetup() { ApplicationBase = this.PluginBaseDirectory };
                // Start of XpKillers mono workaround

                AppDomainSetup domainSetup = null;
                Type t = Type.GetType("Mono.Runtime");
                if (t != null) {
                    //Console.WriteLine("You are running with the Mono VM");
                    WritePluginConsole("Running with Mono VM..");
                    //AppDomain.CurrentDomain.BaseDirectory
                    domainSetup = new AppDomainSetup() {
                        ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
                    };
                    domainSetup.PrivateBinPath = PluginBaseDirectory;
                }
                else {
                    // Console.WriteLine("You are running something else (native .Net)");
                    WritePluginConsole("Running with native .Net..");
                    domainSetup = new AppDomainSetup() {
                        ApplicationBase = PluginBaseDirectory
                    };
                }
                // Workaround end

                WritePluginConsole("Building sandbox..");
                var hostEvidence = new Evidence();
                hostEvidence.AddHost(new Zone(SecurityZone.MyComputer));

                AppDomainSandbox = AppDomain.CreateDomain(ProconClient.HostName + ProconClient.Port + "Engine", hostEvidence, domainSetup, pluginSandboxPermissions);

                WritePluginConsole("Configuring sandbox..");
                // create the factory class in the secondary app-domain
                PluginFactory = (CPRoConPluginLoaderFactory) AppDomainSandbox.CreateInstance("PRoCon.Core", "PRoCon.Core.Plugin.CPRoConPluginLoaderFactory").Unwrap();
                PluginCallbacks = new CPRoConPluginCallbacks(ProconClient.ExecuteCommand, ProconClient.GetAccountPrivileges, ProconClient.GetVariable, ProconClient.GetSvVariable, ProconClient.GetMapDefines, ProconClient.TryGetLocalized, RegisterCommand, UnregisterCommand, GetRegisteredCommands, ProconClient.GetWeaponDefines, ProconClient.GetSpecializationDefines, ProconClient.Layer.GetLoggedInAccounts, RegisterPluginEvents);

                WritePluginConsole("Compiling and loading plugins..");


                var pluginsDirectoryInfo = new DirectoryInfo(PluginBaseDirectory);

                foreach (FileInfo pluginFile in pluginsDirectoryInfo.GetFiles("*.cs")) {
                    string className = Regex.Replace(pluginFile.Name, "\\.cs$", "");

                    if (IgnoredPluginClassNames.Contains(className) == false) {
                        CompilePlugin(pluginFile, className, pluginsCodeDomProvider, parameters);

                        LoadPlugin(className, PluginFactory, pluginSandboxPermissions.IsUnrestricted());
                    }
                    else {
                        WritePluginConsole("Compiling {0}... ^1^bIgnored", className);
                    }
                }

                XDocument pluginCacheDocument = new XDocument(this.PluginCache.ToXElement());

                pluginCacheDocument.Save(Path.Combine(this.PluginBaseDirectory, "PluginCache.xml"));

                pluginsCodeDomProvider.Dispose();
            }
            catch (Exception e) {
                WritePluginConsole(e.Message);
            }
        }
示例#3
0
        public void CompilePlugins(PermissionSet pluginSandboxPermissions)
        {
            try {
                this.WritePluginConsole("Preparing plugins directory..");
                this.PreparePluginsDirectory();
                this.CleanPlugins();

                this.WritePluginConsole("Moving legacy plugins..");
                this.MoveLegacyPlugins();

                this.WritePluginConsole("Creating compiler..");
                CodeDomProvider pluginsCodeDomProvider = CodeDomProvider.CreateProvider("CSharp");

                this.WritePluginConsole("Configuring compiler..");
                CompilerParameters parameters = GenerateCompilerParameters();
                AppDomainSetup domainSetup = new AppDomainSetup() { ApplicationBase = this.PluginBaseDirectory };

                this.WritePluginConsole("Building sandbox..");
                Evidence hostEvidence = new Evidence();
                hostEvidence.AddHost(new Zone(SecurityZone.MyComputer));

                this.m_appDomainSandbox = AppDomain.CreateDomain(this.m_client.HostName + this.m_client.Port + "Engine", hostEvidence, domainSetup, pluginSandboxPermissions);

                this.WritePluginConsole("Configuring sandbox..");
                // create the factory class in the secondary app-domain
                CPRoConPluginLoaderFactory pluginFactory = (CPRoConPluginLoaderFactory)this.m_appDomainSandbox.CreateInstance("PRoCon.Core", "PRoCon.Core.Plugin.CPRoConPluginLoaderFactory").Unwrap();
                this.m_cpPluginCallbacks = new CPRoConPluginCallbacks(this.m_client.ExecuteCommand, this.m_client.GetAccountPrivileges, this.m_client.GetVariable, this.m_client.GetSvVariable, this.m_client.GetMapDefines, this.m_client.TryGetLocalized, this.RegisterCommand, this.UnregisterCommand, this.GetRegisteredCommands, this.m_client.GetWeaponDefines, this.m_client.GetSpecializationDefines, this.m_client.Layer.GetLoggedInAccounts, this.RegisterPluginEvents);

                this.WritePluginConsole("Compiling and loading plugins..");

                DirectoryInfo pluginsDirectoryInfo = new DirectoryInfo(this.PluginBaseDirectory);
                FileInfo[] a_pluginsFileInfo = pluginsDirectoryInfo.GetFiles("*.cs");

                foreach (FileInfo pluginFile in a_pluginsFileInfo) {

                    string className = Regex.Replace(pluginFile.Name, "\\.cs$", "");

                    this.CompilePlugin(pluginFile, className, pluginsCodeDomProvider, parameters);

                    this.LoadPlugin(className, pluginFactory);
                }

                pluginsCodeDomProvider.Dispose();
            }
            catch (Exception e) {
                this.WritePluginConsole(e.Message);
            }
        }