Пример #1
0
        private void LoadPlugin(string pluginClassName, CPRoConPluginLoaderFactory pluginFactory, bool blSandboxDisabled) {
            bool blSandboxEnabled = (blSandboxDisabled == true) ? false : true;
            string outputAssembly = Path.Combine(PluginBaseDirectory, pluginClassName + ".dll");

            if (File.Exists(outputAssembly) == true) {
                IPRoConPluginInterface pluginRemoteInterface = pluginFactory.Create(outputAssembly, "PRoConEvents." + pluginClassName, null);

                // Indirectely invoke registercallbacks since the delegates cannot go in the interface.
                pluginRemoteInterface.Invoke("RegisterCallbacks", new object[] {new CPRoConMarshalByRefObject.ExecuteCommandHandler(PluginCallbacks.ExecuteCommand_Callback), new CPRoConMarshalByRefObject.GetAccountPrivilegesHandler(PluginCallbacks.GetAccountPrivileges_Callback), new CPRoConMarshalByRefObject.GetVariableHandler(PluginCallbacks.GetVariable_Callback), new CPRoConMarshalByRefObject.GetVariableHandler(PluginCallbacks.GetSvVariable_Callback), new CPRoConMarshalByRefObject.GetMapDefinesHandler(PluginCallbacks.GetMapDefines_Callback), new CPRoConMarshalByRefObject.TryGetLocalizedHandler(PluginCallbacks.TryGetLocalized_Callback), new CPRoConMarshalByRefObject.RegisterCommandHandler(PluginCallbacks.RegisterCommand_Callback), new CPRoConMarshalByRefObject.UnregisterCommandHandler(PluginCallbacks.UnregisterCommand_Callback), new CPRoConMarshalByRefObject.GetRegisteredCommandsHandler(PluginCallbacks.GetRegisteredCommands_Callback), new CPRoConMarshalByRefObject.GetWeaponDefinesHandler(PluginCallbacks.GetWeaponDefines_Callback), new CPRoConMarshalByRefObject.GetSpecializationDefinesHandler(PluginCallbacks.GetSpecializationDefines_Callback), new CPRoConMarshalByRefObject.GetLoggedInAccountUsernamesHandler(PluginCallbacks.GetLoggedInAccountUsernames_Callback), new CPRoConMarshalByRefObject.RegisterEventsHandler(PluginCallbacks.RegisterEvents_Callback)});

                Plugins.AddLoadedPlugin(pluginClassName, pluginRemoteInterface);

                /*
                if (this.m_dicLoadedPlugins.ContainsKey(pluginClassName) == false) {
                    this.m_dicLoadedPlugins.Add(pluginClassName, loRemote);
                }
                else {
                    this.m_dicLoadedPlugins[pluginClassName] = loRemote;
                }

                this.LoadedClassNames.Add(pluginClassName);
                */

                var pluginEnvironment = new List<string>() {
                    Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                    ProconClient.GameType,
                    ProconClient.CurrentServerInfo.GameMod.ToString(),
                    blSandboxEnabled.ToString()
                };

                InvokeOnLoaded(pluginClassName, "OnPluginLoadingEnv", pluginEnvironment);

                WritePluginConsole("Loading {0}... ^2Loaded", pluginClassName);

                InvokeOnLoaded(pluginClassName, "OnPluginLoaded", ProconClient.HostName, ProconClient.Port.ToString(CultureInfo.InvariantCulture), Assembly.GetExecutingAssembly().GetName().Version.ToString());

                if (PluginLoaded != null) {
                    FrostbiteConnection.RaiseEvent(PluginLoaded.GetInvocationList(), pluginClassName);
                }
            }
            //else {
            //    this.CacheFailCompiledPluginVariables.Add(pluginClassName, new Dictionary<string, string>());
            //}
        }
Пример #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
        private void LoadPlugin(string pluginClassName, CPRoConPluginLoaderFactory pluginFactory)
        {
            string outputAssembly = Path.Combine(this.PluginBaseDirectory, pluginClassName + ".dll");

            if (File.Exists(outputAssembly) == true) {

                IPRoConPluginInterface loRemote = (IPRoConPluginInterface)pluginFactory.Create(outputAssembly, "PRoConEvents." + pluginClassName, null);

                // Indirectely invoke registercallbacks since the delegates cannot go in the interface.
                loRemote.Invoke("RegisterCallbacks", new object[] { new CPRoConMarshalByRefObject.ExecuteCommandHandler(this.m_cpPluginCallbacks.ExecuteCommand_Callback),
                                                                            new CPRoConMarshalByRefObject.GetAccountPrivilegesHandler(this.m_cpPluginCallbacks.GetAccountPrivileges_Callback),
                                                                            new CPRoConMarshalByRefObject.GetVariableHandler(this.m_cpPluginCallbacks.GetVariable_Callback),
                                                                            new CPRoConMarshalByRefObject.GetVariableHandler(this.m_cpPluginCallbacks.GetSvVariable_Callback),
                                                                            new CPRoConMarshalByRefObject.GetMapDefinesHandler(this.m_cpPluginCallbacks.GetMapDefines_Callback),
                                                                            new CPRoConMarshalByRefObject.TryGetLocalizedHandler(this.m_cpPluginCallbacks.TryGetLocalized_Callback),
                                                                            new CPRoConMarshalByRefObject.RegisterCommandHandler(this.m_cpPluginCallbacks.RegisterCommand_Callback),
                                                                            new CPRoConMarshalByRefObject.UnregisterCommandHandler(this.m_cpPluginCallbacks.UnregisterCommand_Callback),
                                                                            new CPRoConMarshalByRefObject.GetRegisteredCommandsHandler(this.m_cpPluginCallbacks.GetRegisteredCommands_Callback),
                                                                            new CPRoConMarshalByRefObject.GetWeaponDefinesHandler(this.m_cpPluginCallbacks.GetWeaponDefines_Callback),
                                                                            new CPRoConMarshalByRefObject.GetSpecializationDefinesHandler(this.m_cpPluginCallbacks.GetSpecializationDefines_Callback),
                                                                            new CPRoConMarshalByRefObject.GetLoggedInAccountUsernamesHandler(this.m_cpPluginCallbacks.GetLoggedInAccountUsernames_Callback),
                                                                            new CPRoConMarshalByRefObject.RegisterEventsHandler(this.m_cpPluginCallbacks.RegisterEvents_Callback)
                                                                          });

                this.Plugins.AddLoadedPlugin(pluginClassName, loRemote);

                /*
                if (this.m_dicLoadedPlugins.ContainsKey(pluginClassName) == false) {
                    this.m_dicLoadedPlugins.Add(pluginClassName, loRemote);
                }
                else {
                    this.m_dicLoadedPlugins[pluginClassName] = loRemote;
                }

                this.LoadedClassNames.Add(pluginClassName);
                */
                this.WritePluginConsole("Loading {0}... ^2Loaded", pluginClassName);

                this.InvokeOnLoaded(pluginClassName, "OnPluginLoaded", this.m_client.HostName, this.m_client.Port.ToString(), Assembly.GetExecutingAssembly().GetName().Version.ToString());

                if (this.PluginLoaded != null) {
                    FrostbiteConnection.RaiseEvent(this.PluginLoaded.GetInvocationList(), pluginClassName);
                }
            }
            //else {
            //    this.CacheFailCompiledPluginVariables.Add(pluginClassName, new Dictionary<string, string>());
            //}
        }