internal static IEnumerable <PluginDetails> LoadPlugins() { IList <PluginDetails> tmpResult; if (File.Exists(PROJECTS_FILE_NAME)) { try { tmpResult = new List <PluginDetails>(); XDocument tmpProjectsDocument = XDocument.Load(PROJECTS_FILE_NAME); foreach (XElement tmpPluginXml in tmpProjectsDocument.Descendants(TAG_PLUGINS)) { PluginDetails tmpPlugin = PluginDetails.LoadFromXElement(tmpPluginXml); tmpResult.Add(tmpPlugin); } } catch (Exception ex) { throw new Exception("Failed to load plugins", ex); } } else { tmpResult = null; } return(tmpResult); }
private bool IsSaved(PluginDetails foundPluginDetails) { SetCategoryList(); var newPluginDetails = PrivatePlugin.ConvertToPluginDetails(foundPluginDetails, SelectedVersionDetails); return(JsonConvert.SerializeObject(newPluginDetails) == JsonConvert.SerializeObject(foundPluginDetails)); }
/// <summary> /// Loads the assembly and looks for a class of type IPlugin. /// </summary> /// <param name="plugin">Plugin to load.</param> /// <returns>True if the assembly loaded correctly and contains a valid Tilde plugin.</returns> /// <remarks>Throws an exception if loading the assembly failed.</remarks> private bool LoadPluginInternal(PluginDetails plugin) { Assembly assembly = Assembly.LoadFile(plugin.Path); foreach (PluginDetails details in mPlugins) { if (details.Assembly.FullName == assembly.FullName) { return(false); } } foreach (Type type in assembly.GetTypes()) { if (typeof(IPlugin).IsAssignableFrom(type) && type != typeof(IPlugin)) { plugin.Assembly = assembly; mAssemblies.Add(assembly); mPlugins.Add(plugin); return(true); } } return(false); }
private void FindPlugins(string folder) { foreach (string path in Directory.GetFiles(folder, "*.plugin.dll")) { string name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(path)); PluginDetails details = new PluginDetails(name, path); if (OptionsManager.RegistryDatabase.GetBooleanOption("Application/Plugins/" + name, true)) { try { LoadPluginInternal(details); } catch (System.Exception e) { DialogResult result = System.Windows.Forms.MessageBox.Show( "Tilde could not load the plugin:\r\n\t" + details.Path + "\r\n\r\n" + e.Message + "\r\n\r\nDo you want Tilde to attempt to load it next time?", "Plugin load error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { OptionsManager.RegistryDatabase.SetBooleanOption("Application/Plugins/" + name, false); } } } } }
public PluginDetails GetPluginDetails(string pluginId) { if (string.IsNullOrWhiteSpace(pluginId)) { throw new ArgumentException("Plugin identity value not specified.", nameof(pluginId)); } var corePlugins = _compositeLog["Plugins:Core"] as IDictionary; var appPlugins = _compositeLog["Plugins:Application"] as IDictionary; IDictionary <string, object> hostPlugin = (IDictionary <string, object>)_compositeLog["Plugin:Host"]; object plugInProperties = null; if (hostPlugin["Plugin:Id"].ToString() == pluginId) { plugInProperties = hostPlugin; } plugInProperties = plugInProperties ?? corePlugins[pluginId] ?? appPlugins[pluginId]; if (plugInProperties != null) { return(PluginDetails.FromLog((IDictionary)plugInProperties)); } return(null); }
private void listViewPlugins_SelectedIndexChanged(object sender, EventArgs e) { richTextBoxDetails.Clear(); if (listViewPlugins.SelectedItems.Count == 1) { PluginDetails details = (PluginDetails)listViewPlugins.SelectedItems[0].Tag; IPlugin plugin = details.Plugin; if (plugin != null) { richTextBoxDetails.AppendText(details.Assembly.GetName().Name + "\n"); richTextBoxDetails.AppendText("Documents:\n"); foreach (Type docType in details.GetImplementations(typeof(Document))) { DocumentClassAttribute attr = DocumentClassAttribute.ForType(docType); richTextBoxDetails.AppendText("\t" + attr.Name + " (" + attr.ViewType.ToString() + ")\n"); richTextBoxDetails.AppendText("\tFile Extensions:\n"); foreach (string ext in attr.FileExtensions) { richTextBoxDetails.AppendText("\t\t" + ext + "\n"); } } } } }
public void LoadAssembly(string path) { Logger.Debug("PLUGIN_LOADER", path); Assembly a = Assembly.LoadFrom(path); foreach (Type t in a.GetTypes()) { if (t.IsSubclassOf(typeof(Plugin)) && t != typeof(Plugin)) { try { Plugin plugin = Activator.CreateInstance(t) as Plugin; PluginDetails details = (PluginDetails)Attribute.GetCustomAttribute(t, typeof(PluginDetails)); if (details.id != null) { // should do version checking too plugin.Details = details; plugins.Add(details.id, plugin); Logger.Info("PLUGIN_LOADER", "Plugin loaded: " + plugin.ToString()); } else { // print message Logger.Warn("PLUGIN_LOADER", "Plugin loaded but missing an id: " + t + "(" + path + ")"); } } catch { Logger.Error("PLUGIN_LOADER", "Failed to create instance of plugin " + t + "(" + path + ")"); } } } }
public ModPanel(SettingsInterface ui, Selector s) { _base = ui; _selector = s; Details = new PluginDetails(_base, _selector); _currentWebsite = Meta?.Website ?? ""; }
public Task Execute(string[] args) { int Added = 0; foreach (string file in Directory.GetFiles(Environment.CurrentDirectory + Program.InstallationDirectory)) { bool Installed = false; PluginDetails info = null; try { info = Attributes.GetAttributes(file); foreach (Package package in Program.InstalledPackages) { if (package.PackageId == info.id) { Installed = true; } } } catch (Exception e) { Logger.WriteLine($"Unable to Load Plugin {Path.GetFileName(file)}, missing dependencies ? Error: {e.Message}", ConsoleColor.Red); } if (!Installed && info != null) { Response <Package> response = Client.Get <Package>(kPluginEndpoint + "?PluginId=" + info.id); if (response) { Added++; PackageInfo Current = null; foreach (PackageInfo version in response.Data.Versions) { if (version.Version == info.version) { Current = version; } } if (Current != null) { response.Data.CurrentVersion = Current; Logger.WriteLine($"[+] Found Plugin {info.name}, Adding to installed!."); } else { Logger.WriteLine($"Version {info.version} not found for plugin {info.name}, assuming newest version."); response.Data.CurrentVersion = response.Data.GetNewestVersion(); } Program.InstalledPackages.Add(response.Data); Program.SaveInstalled(); } } } if (Added == 0) { Logger.WriteLine("Nothing to Add!", ConsoleColor.Green); } return(Task.CompletedTask); }
public ModPanel(SettingsInterface ui, Selector s, HashSet <string> newMods) { _base = ui; _selector = s; _newMods = newMods; Details = new PluginDetails(_base, _selector); _currentWebsite = Meta?.Website ?? ""; _modManager = Service <ModManager> .Get(); }
public void LoadPluginAssembly(string path) { Logger.Debug("PLUGIN_LOADER", path); Assembly a = Assembly.LoadFrom(path); try { foreach (Type t in a.GetTypes()) { if (t.IsSubclassOf(typeof(Plugin)) && t != typeof(Plugin)) { try { Plugin plugin = (Plugin)Activator.CreateInstance(t); PluginDetails details = (PluginDetails)Attribute.GetCustomAttribute(t, typeof(PluginDetails)); if (details.id != null) { if (details.SmodMajor != SMOD_MAJOR && details.SmodMinor != SMOD_MINOR) { Logger.Warn("PLUGIN_LOADER", "Trying to load an outdated plugin " + details.name + " " + details.version); } else { plugin.Details = details; plugin.Pipes = new PluginPipes(plugin); ConfigManager.Manager.RegisterPlugin(plugin); LangManager.Manager.RegisterPlugin(plugin); PipeManager.Manager.RegisterPlugin(plugin); plugin.Register(); disabledPlugins.Add(details.id, plugin); Logger.Info("PLUGIN_LOADER", "Plugin loaded: " + plugin.ToString()); } } else { Logger.Warn("PLUGIN_LOADER", "Plugin loaded but missing an id: " + t + "[" + path + "]"); } } catch (Exception e) { Logger.Error("PLUGIN_LOADER", "Failed to create instance of plugin " + t + "[" + path + "]"); Logger.Error("PLUGIN_LOADER", e.GetType().Name + ": " + e.Message); Logger.Error("PLUGIN_LOADER", e.StackTrace); } } } } catch (Exception e) { Logger.Error("PLUGIN_LOADER", "Failed to load DLL [" + path + "], is it up to date?"); Logger.Debug("PLUGIN_LOADER", e.Message); Logger.Debug("PLUGIN_LOADER", e.StackTrace); } }
private IPlugin CreatePluginInAppDomain(PluginDetails argDetails) { IPlugin tmpResult = null; AppDomain tmpPluginDomain = AppDomain.CreateDomain(String.Format("Plugin{0}", argDetails.Name)); tmpResult = tmpPluginDomain.CreateInstanceAndUnwrap(argDetails.AssemblyFullName, argDetails.PluginTypeName) as IPlugin; this.loadedPlugins.Add(new KeyValuePair <AppDomain, IPlugin>(tmpPluginDomain, tmpResult)); return(tmpResult); }
private PluginDetails GetPluginDetails(string argPluginName, bool argThrowIfNotFound) { PluginDetails tmpResult = availablePlugins.FirstOrDefault(item => item.Name == argPluginName); if (argThrowIfNotFound && tmpResult == null) { throw new ArgumentException(String.Format("Unable to find plugin with the specified name: {0}", argPluginName)); } return(tmpResult); }
public Task Execute(string[] args) { PluginDetails details = Attributes.GetAttributes(args[0]); Logger.WriteLine($"Plugin Name: {details.name}"); Logger.WriteLine($"Plugin Author: {details.author}"); Logger.WriteLine($"Plugin Id: {details.id}"); Logger.WriteLine($"Plugin Description: {details.description}"); Logger.WriteLine($"Plugin Version: {details.version}"); Logger.WriteLine($"Plugin Smod Version: {details.SmodMajor}.{details.SmodMinor}.{details.SmodRevision}"); return(Task.CompletedTask); }
public IPlugin LoadPlugin(string argPluginName) { IPlugin tmpResult = this.loadedPlugins.Where(item => item.Value.Name.Equals(argPluginName, StringComparison.InvariantCultureIgnoreCase)).Select(item => item.Value).SingleOrDefault(); if (tmpResult == null) { PluginDetails tmpDetails = this.GetPluginDetails(argPluginName, true); tmpResult = this.CreatePluginInAppDomain(tmpDetails); tmpResult.Load(); } return(tmpResult); }
/* * public void RemotePluginEnabled(string strClassName, bool blEnabled) { * * } */ private void m_prcClient_RemotePluginVariables(PRoConClient sender, string strClassName, List <CPluginVariable> lstVariables) { if (this.m_dicRemotePlugins.ContainsKey(strClassName) == true) { PluginDetails spdUpdatedDetails = this.m_dicRemotePlugins[strClassName]; spdUpdatedDetails.DisplayPluginVariables = lstVariables; this.m_dicRemotePlugins[strClassName] = spdUpdatedDetails; this.m_blUpdatingPlugins = true; this.uscPlugins.SetLoadedPlugins(new List <string>(this.m_dicRemotePlugins.Keys)); this.m_blUpdatingPlugins = false; } }
public Task Execute(string[] args) { try { PluginDetails details = Attributes.GetAttributes(args[0]); PackageInfo info = new PackageInfo() { Version = details.version, PublishDate = DateTime.Now, VersionID = 1, Changelog = "", }; Package pack = new Package() { Author = details.author, Description = details.description, Name = details.name, PackageName = Path.GetFileNameWithoutExtension(args[0]).ToLower(), PackageId = details.id, Versions = new List <PackageInfo>() { info } }; Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[0]).ToLower()); Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[0]).ToLower() + "/Versions"); Logger.WriteLine($"Plugin Name: {details.name}"); Logger.WriteLine($"Plugin Author: {details.author}"); Logger.WriteLine($"Plugin Id: {details.id}"); Logger.WriteLine($"Plugin Description: {details.description}"); Logger.WriteLine($"Plugin Version: {details.version}"); Logger.WriteLine($"Plugin Smod Version: {details.SmodMajor}.{details.SmodMinor}.{details.SmodRevision}"); StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "/" + Path.GetFileNameWithoutExtension(args[0]).ToLower() + ".json"); sw.WriteLine(JsonConvert.SerializeObject(pack, Formatting.Indented)); sw.Flush(); sw.Close(); } catch { Logger.WriteLine("Could Not Find File!", ConsoleColor.Red); } return(Task.CompletedTask); }
private PluginDetails uscPlugins_GetPluginDetails(string strClassName) { PluginDetails spdReturn = new PluginDetails(); spdReturn.ClassName = strClassName; spdReturn.Name = strClassName; if (this.m_prcConnection.PluginsManager != null) { spdReturn = this.m_prcConnection.PluginsManager.GetPluginDetails(strClassName); } return(spdReturn); }
/* * public void SetRemoteLoadedPlugins(Dictionary<string, SPluginDetails> dicRemotePlugins) { * * this.m_dicRemotePlugins = dicRemotePlugins; * this.m_blUpdatingPlugins = true; * * this.uscPlugins.SetLoadedPlugins(new List<string>(this.m_dicRemotePlugins.Keys)); * * this.m_blUpdatingPlugins = false; * } */ private PluginDetails uscPlugins_GetPluginDetails(string strClassName) { PluginDetails spdReturnDetails = default(PluginDetails); if (this.m_dicRemotePlugins != null) { if (this.m_dicRemotePlugins.ContainsKey(strClassName) == true) { spdReturnDetails = this.m_dicRemotePlugins[strClassName]; } } return(spdReturnDetails); }
/// <summary> /// Loads the plugin. /// </summary> /// <param name="type">The type.</param> public void LoadPlugin(Configuration.GlobalPlugin type) { pnlPluginDetails.Controls.Clear(); if (type != null) { var control = new PluginDetails { Dock = DockStyle.Fill }; control.LoadComponent(type); pnlPluginDetails.Controls.Add(control); } }
/* * public void SetRemoteEnabledPlugins(List<string> lstClassNames) { * * * } */ private void m_prcClient_RemotePluginLoaded(PRoConClient sender, PluginDetails spdDetails) { if (this.m_dicRemotePlugins.ContainsKey(spdDetails.ClassName) == true) { this.m_dicRemotePlugins[spdDetails.ClassName] = spdDetails; } else { this.m_dicRemotePlugins.Add(spdDetails.ClassName, spdDetails); } this.m_blUpdatingPlugins = true; this.uscPlugins.SetLoadedPlugins(new List <string>(this.m_dicRemotePlugins.Keys)); this.m_blUpdatingPlugins = false; }
public void SetLoadedPlugins(List <string> lstClassNames) { ListViewItem lviPlugin = null; foreach (string strClassName in new List <string>(lstClassNames)) { PluginDetails spdDetails = this.GetPluginDetails(strClassName); if ((lviPlugin = IsLoadedPlugin(strClassName)) == null) { ListViewItem lviNewItem = new ListViewItem(spdDetails.Name); lviNewItem.Tag = spdDetails; lviNewItem.Name = strClassName; lviNewItem.ImageKey = "plugin_disabled.png"; //this.m_uscParent.ThrowEvent(this, uscEventsPanel.CapturableEvents.PluginLoaded, new string[] { strClassName }); this.m_blSupressDisabledEvent = true; lsvLoadedPlugins.Items.Add(lviNewItem); } else { lviPlugin.Text = spdDetails.Name; lviPlugin.Tag = spdDetails; } if (this.PluginLoaded != null) { this.PluginLoaded(spdDetails); } this.lsvLoadedPlugins_SelectedIndexChanged(this, null); //foreach (KeyValuePair<string, CPRoConLayerClient> kvpConnection in this.m_dicLayerClients) { // kvpConnection.Value.OnPluginLoaded(spdDetails); //} } foreach (ColumnHeader column in this.lsvLoadedPlugins.Columns) { column.Width = -2; } }
private void RefreshSelectedPlugin() { if (this.lsvLoadedPlugins.SelectedItems.Count > 0) { //this.tbcPluginDetails.Enabled = true; PluginDetails spdDetails = this.GetPluginDetails(((PluginDetails)lsvLoadedPlugins.SelectedItems[0].Tag).ClassName); this.lsvLoadedPlugins.SelectedItems[0].Tag = spdDetails; //this.txtPluginName.Text = spdDetails.m_strName; //this.txtPluginAuthor.Text = spdDetails.m_strAuthor; //this.txtPluginVersion.Text = spdDetails.m_strVersion; //this.txtPluginDescription.Text = spdDetails.m_strDescription; HtmlDocument document = this.webDescription.Document.OpenNew(true); string html = String.Format(@"<html><head><style>{0}</style></head><body><h1>{1} - {2}</h1>{3}: <a href=""http://{4}"" target=""_blank"">{5}</a><br><br>{6}</body></html>", this.m_cssDescription, spdDetails.Name, spdDetails.Version, this.m_clocLanguage.GetLocalized("uscPluginPanel.tabPluginDetails.lblPluginAuthor"), spdDetails.Website, spdDetails.Author, spdDetails.Description != null ? spdDetails.Description : String.Empty); // .Replace(Environment.NewLine, @"<br>") document.Write(html); //this.lklPluginWebsite.Text = spdDetails.m_strWebsite; //this.lklPluginWebsite.Tag = spdDetails.m_strWebsite; //this.lklPluginWebsite.LinkArea = new LinkArea(0, spdDetails.m_strWebsite.Length); this.m_cscPluginVariables.Clear(); this.SetPluginsVariables(spdDetails.ClassName, spdDetails.Name, spdDetails.DisplayPluginVariables); } else if (this.lsvLoadedPlugins.FocusedItem != null) { //this.tbcPluginDetails.Enabled = false; //this.txtPluginName.Text = String.Empty; //this.txtPluginAuthor.Text = String.Empty; //this.txtPluginVersion.Text = String.Empty; //this.txtPluginDescription.Text = String.Empty; //this.lklPluginWebsite.Text = String.Empty; this.m_cscPluginVariables.Clear(); this.ppgScriptSettings.Refresh(); } }
private void ppgScriptSettings_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { if (this.m_cscPluginVariables.ContainsKey(e.ChangedItem.Label) == true) { string strValue = e.ChangedItem.Value.ToString(); if (this.m_cscPluginVariables[e.ChangedItem.Label].Type == typeof(bool)) { strValue = strValue.ToLower(); } // else if (this.m_cscPluginVariables[e.ChangedItem.Label].Type == typeof(string)) { // strValue = strValue; // } else if (this.m_cscPluginVariables[e.ChangedItem.Label].Type == typeof(string[])) { strValue = CPluginVariable.EncodeStringArray((string[])e.ChangedItem.Value); } // TO DO: Set the script variable. //this.m_frmMainParent.SetSingleSv(this.m_cscPluginVariables[e.ChangedItem.Label].ClassName, e.ChangedItem.Label, strValue); this.SetPluginVariable(this.m_cscPluginVariables[e.ChangedItem.Label].ClassName, e.ChangedItem.Label, strValue); //this.lsvLoadedPlugins_SelectedIndexChanged(this, null); this.RefreshSelectedPlugin(); if (this.m_cscPluginVariables.ContainsKey(e.ChangedItem.Label) == true) { PluginDetails spdUpdatedDetails = this.GetPluginDetails(this.m_cscPluginVariables[e.ChangedItem.Label].ClassName); if (this.PluginVariablesAltered != null) { this.PluginVariablesAltered(spdUpdatedDetails); } } //foreach (KeyValuePair<string, CPRoConLayerClient> kvpConnection in this.m_dicLayerClients) { // kvpConnection.Value.OnPluginVariablesAltered(spdUpdatedDetails); //} } }
public DistribPluginInstance CreatePluginInstance(PluginDetails details) { if (details == null) throw new ArgumentNullException("Plugin details must be supplied"); DistribPluginInstance instance = null; try { if (!details.IsUsable) { throw new InvalidOperationException("Plugin is marked as excluded because: {0}".fmt( details.ExclusionReason.ToString())); } lock (m_objLock) { lock (m_dictInstances) { List<DistribPluginInstance> lstInstances = null; if (m_dictInstances.TryGetValue(details, out lstInstances) == false) { lstInstances = new List<DistribPluginInstance>(); } instance = new DistribPluginInstance(details, this); lstInstances.Add(instance); m_dictInstances[details] = lstInstances; } } return instance; } catch (Exception ex) { throw new ApplicationException("Failed to create plugin instance", ex); } }
private bool HandleResponsePacket(Packet cpBeforePacketDispatch, bool blCancelUpdateEvent, bool blCancelPacket) { if (this.Game != null) { Packet cpRequestPacket = this.Game.Connection.GetRequestPacket(cpBeforePacketDispatch); if (cpRequestPacket != null) { if (cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "InvalidUsername", true) == 0) { if (this.LoginFailure != null) { FrostbiteConnection.RaiseEvent(this.LoginFailure.GetInvocationList(), this, cpBeforePacketDispatch.Words[0]); } this.Shutdown(); this.State = ConnectionState.Error; blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.version", true) == 0 && cpBeforePacketDispatch.Words.Count >= 2) { try { this.ConnectedLayerVersion = new Version(cpBeforePacketDispatch.Words[1]); if (this.ProconVersion != null) { FrostbiteConnection.RaiseEvent(this.ProconVersion.GetInvocationList(), this, this.ConnectedLayerVersion); } } catch (Exception) { } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.privileges", true) == 0 && cpBeforePacketDispatch.Words.Count >= 2) { UInt32 ui32Privileges = 0; if (UInt32.TryParse(cpBeforePacketDispatch.Words[1], out ui32Privileges) == true) { CPrivileges spPrivs = new CPrivileges(); spPrivs.PrivilegesFlags = ui32Privileges; this.Privileges = spPrivs; if (this.ProconPrivileges != null) { FrostbiteConnection.RaiseEvent(this.ProconPrivileges.GetInvocationList(), this, spPrivs); } } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 2 && String.Compare(cpRequestPacket.Words[0], "procon.registerUid", true) == 0 && cpBeforePacketDispatch.Words.Count >= 1) { if (String.Compare(cpBeforePacketDispatch.Words[0], "OK", true) == 0 && cpRequestPacket.Words.Count >= 3) { this.m_strProconEventsUid = cpRequestPacket.Words[2]; } else if (String.Compare(cpBeforePacketDispatch.Words[0], "ProconUidConflict", true) == 0) { // Conflict in our UID, just hash and send another one. // Then go to vegas. this.SendRequest(new List<string>() { "procon.registerUid", "true", FrostbiteClient.GeneratePasswordHash(Encoding.ASCII.GetBytes(DateTime.Now.ToString("HH:mm:ss ff")), this.m_strUsername) }); } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.account.listAccounts", true) == 0) { UInt32 ui32Privileges = 0; for (int i = 1; i < cpBeforePacketDispatch.Words.Count; i += 2) { if (UInt32.TryParse(cpBeforePacketDispatch.Words[i + 1], out ui32Privileges) == true) { CPrivileges spPrivs = new CPrivileges(); spPrivs.PrivilegesFlags = ui32Privileges; if (this.RemoteAccountCreated != null && this.RemoteAccountAltered != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountCreated.GetInvocationList(), this, cpBeforePacketDispatch.Words[i]); FrostbiteConnection.RaiseEvent(this.RemoteAccountAltered.GetInvocationList(), this, cpBeforePacketDispatch.Words[i], spPrivs); } } } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.battlemap.listZones", true) == 0 && cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "OK", true) == 0) { List<MapZoneDrawing> zones = new List<MapZoneDrawing>(); int iZones = 0; int iOffset = 1; if (int.TryParse(cpBeforePacketDispatch.Words[iOffset++], out iZones) == true) { for (int iZoneCount = 0; iZoneCount < iZones; iZoneCount++) { string uid = String.Empty; string level = String.Empty; string tags = String.Empty; List<Point3D> points = new List<Point3D>(); if (iOffset + 4 < cpBeforePacketDispatch.Words.Count) { uid = cpBeforePacketDispatch.Words[iOffset++]; level = cpBeforePacketDispatch.Words[iOffset++]; tags = cpBeforePacketDispatch.Words[iOffset++]; int iZonePoints = 0; if (int.TryParse(cpBeforePacketDispatch.Words[iOffset++], out iZonePoints) == true && iOffset + iZonePoints * 3 <= cpBeforePacketDispatch.Words.Count) { for (int iZonePointCount = 0; iZonePointCount < iZonePoints && iOffset + 3 <= cpBeforePacketDispatch.Words.Count; iZonePointCount++) { points.Add(new Point3D(cpBeforePacketDispatch.Words[iOffset++], cpBeforePacketDispatch.Words[iOffset++], cpBeforePacketDispatch.Words[iOffset++])); } } } zones.Add(new MapZoneDrawing(uid, level, tags, points.ToArray(), true)); } } if (this.ListMapZones != null) { FrostbiteConnection.RaiseEvent(this.ListMapZones.GetInvocationList(), this, zones); } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.account.setPassword", true) == 0 && cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "OK", true) == 0) { if (this.RemoteAccountChangePassword != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountChangePassword.GetInvocationList(), this); } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.account.listLoggedIn", true) == 0) { bool containsUids = (cpRequestPacket.Words.Count >= 2 && String.Compare(cpRequestPacket.Words[1], "uids") == 0); if (this.RemoteAccountLoggedIn != null) { for (int i = 1; i < cpBeforePacketDispatch.Words.Count; i++) { FrostbiteConnection.RaiseEvent(this.RemoteAccountLoggedIn.GetInvocationList(), this, cpBeforePacketDispatch.Words[i], true); if (containsUids == true && i + 1 < cpBeforePacketDispatch.Words.Count) { if (this.m_dicUsernamesToUids.ContainsKey(cpBeforePacketDispatch.Words[i]) == true) { this.m_dicUsernamesToUids[cpBeforePacketDispatch.Words[i]] = cpBeforePacketDispatch.Words[i + 1]; } else { this.m_dicUsernamesToUids.Add(cpBeforePacketDispatch.Words[i], cpBeforePacketDispatch.Words[i + 1]); } i++; } } } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.plugin.listEnabled", true) == 0) { if (this.RemoteEnabledPlugins != null) { List<string> lstEnabledPlugins = new List<string>(cpBeforePacketDispatch.Words); lstEnabledPlugins.RemoveAt(0); FrostbiteConnection.RaiseEvent(this.RemoteEnabledPlugins.GetInvocationList(), this, lstEnabledPlugins); } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.vars", true) == 0 && cpBeforePacketDispatch.Words.Count >= 3) { this.SV_Variables.SetVariable(cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2]); if (this.ReceiveProconVariable != null) { FrostbiteConnection.RaiseEvent(this.ReceiveProconVariable.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2]); } // Dispatch to plugins. } else if (cpRequestPacket.Words.Count >= 1 && String.Compare(cpRequestPacket.Words[0], "procon.plugin.listLoaded", true) == 0) { if (this.RemoteLoadedPlugins != null) { int i = 0; if (cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[i++], "OK", true) == 0) { Dictionary<string, PluginDetails> dicLoadedPlugins = new Dictionary<string, PluginDetails>(); while (i + 6 <= cpBeforePacketDispatch.Words.Count) { PluginDetails spdLoaded = new PluginDetails(); spdLoaded.ClassName = cpBeforePacketDispatch.Words[i++]; spdLoaded.Name = cpBeforePacketDispatch.Words[i++]; spdLoaded.Author = cpBeforePacketDispatch.Words[i++]; spdLoaded.Website = cpBeforePacketDispatch.Words[i++]; spdLoaded.Version = cpBeforePacketDispatch.Words[i++]; spdLoaded.Description = cpBeforePacketDispatch.Words[i++]; spdLoaded.DisplayPluginVariables = new List<CPluginVariable>(); spdLoaded.PluginVariables = new List<CPluginVariable>(); // Not used here. int iTotalVariables = 0; if (int.TryParse(cpBeforePacketDispatch.Words[i++], out iTotalVariables) == true && i + (iTotalVariables * 3) <= cpBeforePacketDispatch.Words.Count) { for (int x = 0; x < (iTotalVariables * 3); x += 3) { spdLoaded.DisplayPluginVariables.Add(new CPluginVariable(cpBeforePacketDispatch.Words[i++], cpBeforePacketDispatch.Words[i++], cpBeforePacketDispatch.Words[i++])); } } if (dicLoadedPlugins.ContainsKey(spdLoaded.ClassName) == false) { dicLoadedPlugins.Add(spdLoaded.ClassName, spdLoaded); } } FrostbiteConnection.RaiseEvent(this.RemoteLoadedPlugins.GetInvocationList(), this, dicLoadedPlugins); } } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 2 && String.Compare(cpRequestPacket.Words[0], "login.hashed", true) == 0 && cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "InsufficientPrivileges", true) == 0) { if (this.LoginFailure != null) { FrostbiteConnection.RaiseEvent(this.LoginFailure.GetInvocationList(), this, cpBeforePacketDispatch.Words[0]); } this.Shutdown(); this.State = ConnectionState.Error; blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 2 && String.Compare(cpRequestPacket.Words[0], "procon.login.username", true) == 0 && cpBeforePacketDispatch.Words.Count >= 1 && (String.Compare(cpBeforePacketDispatch.Words[0], "OK", true) == 0 || String.Compare(cpBeforePacketDispatch.Words[0], "UnknownCommand", true) == 0)) { //this.send(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "procon.login.requestUsername", this.m_strUsername })); // This is the first command we would recieve so now we know we're connected through a PRoCon layer. if (this.LoginAttempt != null) { FrostbiteConnection.RaiseEvent(this.LoginAttempt.GetInvocationList(), this); } this.Game.SendLoginHashedPacket(this.Password); if (String.Compare(cpBeforePacketDispatch.Words[0], "OK", true) == 0) { this.IsPRoConConnection = true; this.Game.isLayered = true; } else { this.IsPRoConConnection = false; this.Username = ""; } blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 2 && String.Compare(cpRequestPacket.Words[0], "procon.login.username", true) == 0 && cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "InsufficientPrivileges", true) == 0) { // The servers just told us off, try and login normally. if (this.LoginFailure != null) { FrostbiteConnection.RaiseEvent(this.LoginFailure.GetInvocationList(), this, cpBeforePacketDispatch.Words[0]); } this.Shutdown(); this.State = ConnectionState.Error; blCancelPacket = true; } else if (cpRequestPacket.Words.Count >= 3 && String.Compare(cpRequestPacket.Words[0], "admin.say", true) == 0 && this.m_dicForwardedPackets.ContainsKey(cpBeforePacketDispatch.SequenceNumber) == true) { if (this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords.Count >= 4 && String.Compare(this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords[0], "procon.admin.say", true) == 0) { this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords[0] = "procon.admin.onSay"; if (this.IsPRoConConnection == false) { List<string> lstWords = this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords; if (this.ProconAdminSaying != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminSaying.GetInvocationList(), this, lstWords[1], lstWords[2], new CPlayerSubset(lstWords.GetRange(3, lstWords.Count - 3))); } } if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, new Packet(true, false, cpRequestPacket.SequenceNumber, this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords)); } // Send to all logged in layer clients this.m_dicForwardedPackets.Remove(cpBeforePacketDispatch.SequenceNumber); blCancelPacket = true; blCancelUpdateEvent = true; } } else if (cpRequestPacket.Words.Count >= 4 && String.Compare(cpRequestPacket.Words[0], "admin.yell", true) == 0 && this.m_dicForwardedPackets.ContainsKey(cpBeforePacketDispatch.SequenceNumber) == true) { if (this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords.Count >= 5 && String.Compare(this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords[0], "procon.admin.yell", true) == 0) { this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords[0] = "procon.admin.onYell"; // If we're at the top of the tree, simulate the event coming from a layer above. if (this.IsPRoConConnection == false) { List<string> lstWords = this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords; int iDisplayDuration = 0; if (int.TryParse(lstWords[3], out iDisplayDuration) == true) { if (this.ProconAdminYelling != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminYelling.GetInvocationList(), this, lstWords[1], lstWords[2], iDisplayDuration, new CPlayerSubset(lstWords.GetRange(4, lstWords.Count - 4))); } } } // Send to all logged in layer clients if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, new Packet(true, false, cpRequestPacket.SequenceNumber, this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords)); } this.m_dicForwardedPackets.Remove(cpBeforePacketDispatch.SequenceNumber); blCancelPacket = true; blCancelUpdateEvent = true; } } // MoHW R-6 hack else if (cpRequestPacket.Words.Count >= 3 && this.Game.GameType == "MOHW" && String.Compare(cpRequestPacket.Words[0], "admin.yell", true) == 0 && this.m_dicForwardedPackets.ContainsKey(cpBeforePacketDispatch.SequenceNumber) == true) { if (this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords.Count >= 4 && String.Compare(this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords[0], "procon.admin.yell", true) == 0) { this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords[0] = "procon.admin.onYell"; // If we're at the top of the tree, simulate the event coming from a layer above. if (this.IsPRoConConnection == false) { List<string> lstWords = this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords; int iDisplayDuration = 0; if (int.TryParse(lstWords[3], out iDisplayDuration) == true) { iDisplayDuration = 0; if (this.ProconAdminYelling != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminYelling.GetInvocationList(), this, lstWords[1], lstWords[2], iDisplayDuration, new CPlayerSubset(lstWords.GetRange(4, lstWords.Count - 4))); } } } // Send to all logged in layer clients if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, new Packet(true, false, cpRequestPacket.SequenceNumber, this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_lstWords)); } this.m_dicForwardedPackets.Remove(cpBeforePacketDispatch.SequenceNumber); blCancelPacket = true; blCancelUpdateEvent = true; } } // end hack // BF3 player.ping else if (cpRequestPacket.Words.Count >= 2 && this.Game.GameType == "BF3" && String.Compare(cpRequestPacket.Words[0], "player.ping", true) == 0 && String.Compare(cpBeforePacketDispatch.Words[0], "OK", true) == 0) { string strProconEventsUid = String.Empty; List<string> lstProconUpdatedWords = new List<string>(cpRequestPacket.Words); lstProconUpdatedWords.Insert(0, "procon.admin.onPlayerPinged"); lstProconUpdatedWords.RemoveAt(1); lstProconUpdatedWords.Add(cpBeforePacketDispatch.Words[1]); // Now we pass on the packet to all the clients as an event so they can remain in sync. // Don't pass on anything regarding login if ((lstProconUpdatedWords.Count >= 4 && (String.Compare(lstProconUpdatedWords[2], "login.plainText", true) == 0 || String.Compare(lstProconUpdatedWords[2], "login.hashed", true) == 0)) == false) { if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, new Packet(true, false, cpRequestPacket.SequenceNumber, lstProconUpdatedWords)); } } } if (blCancelUpdateEvent == false) { string strProconEventsUid = String.Empty; // If a layer client sent this packet.. if (this.m_dicForwardedPackets.ContainsKey(cpBeforePacketDispatch.SequenceNumber) == true) { if (this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_sender != null) { ((PRoConLayerClient)this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_sender).OnServerForwardedResponse(new Packet(false, true, this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_ui32OriginalSequence, new List<string>(cpBeforePacketDispatch.Words))); strProconEventsUid = ((PRoConLayerClient)this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_sender).ProconEventsUid; this.InstigatingAccountName = this.m_dicForwardedPackets[cpBeforePacketDispatch.SequenceNumber].m_sender.Username; } // Unregister the sequence and packet. this.m_dicForwardedPackets.Remove(cpBeforePacketDispatch.SequenceNumber); } // IF the command was not a request for a list (it's a GET operation only, // as in it only lists or retrieves information and will never be set.) if (this.Game != null && this.Game.GetPacketsPattern.IsMatch(cpRequestPacket.ToString()) == false) { // && cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "OK") == 0) { List<string> lstProconUpdatedWords = new List<string>(cpRequestPacket.Words); lstProconUpdatedWords.Insert(0, "procon.updated"); lstProconUpdatedWords.Insert(1, strProconEventsUid); // Now we pass on the packet to all the clients as an event so they can remain in sync. // Don't pass on anything regarding login if ((lstProconUpdatedWords.Count >= 4 && (String.Compare(lstProconUpdatedWords[2], "login.plainText", true) == 0 || String.Compare(lstProconUpdatedWords[2], "login.hashed", true) == 0)) == false) { if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, new Packet(true, false, cpRequestPacket.SequenceNumber, lstProconUpdatedWords)); } } } } } } return blCancelPacket; }
private bool HandleEventPacket(Packet cpBeforePacketDispatch, bool blCancelPacket) { if (cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.shutdown", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); this.State = ConnectionState.Error; this.Connection_ConnectionFailure(this.Game.Connection, new Exception("The PRoCon layer has been shutdown by the host")); this.Shutdown(); blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.account.onLogin", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); // Also able to get their privs as well if needed? //this.m_uscParent.OnRemoteAccountLoggedIn(cpBeforePacketDispatch.Words[1], true); if (this.RemoteAccountLoggedIn != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountLoggedIn.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], true); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.account.onLogout", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); if (this.RemoteAccountLoggedIn != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountLoggedIn.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], false); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.account.onUidRegistered", true) == 0) { if (this.m_dicUsernamesToUids.ContainsKey(cpBeforePacketDispatch.Words[2]) == true) { this.m_dicUsernamesToUids[cpBeforePacketDispatch.Words[2]] = cpBeforePacketDispatch.Words[1]; } else { this.m_dicUsernamesToUids.Add(cpBeforePacketDispatch.Words[2], cpBeforePacketDispatch.Words[1]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.account.onCreated", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); if (this.RemoteAccountCreated != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountCreated.GetInvocationList(), this, cpBeforePacketDispatch.Words[1]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.account.onDeleted", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); if (this.RemoteAccountDeleted != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountDeleted.GetInvocationList(), this, cpBeforePacketDispatch.Words[1]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.account.onAltered", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); UInt32 ui32Privileges = 0; if (UInt32.TryParse(cpBeforePacketDispatch.Words[2], out ui32Privileges) == true) { CPrivileges spPrivs = new CPrivileges(); spPrivs.PrivilegesFlags = ui32Privileges; if (this.ProconPrivileges != null && String.Compare(cpBeforePacketDispatch.Words[1], this.Username) == 0) { this.Privileges = spPrivs; FrostbiteConnection.RaiseEvent(this.ProconPrivileges.GetInvocationList(), this, spPrivs); } if (this.RemoteAccountAltered != null) { FrostbiteConnection.RaiseEvent(this.RemoteAccountAltered.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], spPrivs); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.packages.onDownloading", true) == 0) { if (this.PackageDownloading != null) { FrostbiteConnection.RaiseEvent(this.PackageDownloading.GetInvocationList(), this, cpBeforePacketDispatch.Words[1]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.packages.onDownloaded", true) == 0) { if (this.PackageDownloaded != null) { FrostbiteConnection.RaiseEvent(this.PackageDownloaded.GetInvocationList(), this, cpBeforePacketDispatch.Words[1]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.packages.onInstalling", true) == 0) { if (this.PackageInstalling != null) { FrostbiteConnection.RaiseEvent(this.PackageInstalling.GetInvocationList(), this, cpBeforePacketDispatch.Words[1]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.packages.onDownloadError", true) == 0) { if (this.PackageDownloadError != null) { FrostbiteConnection.RaiseEvent(this.PackageDownloadError.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2]); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.packages.onInstalled", true) == 0) { bool restartRequired = false; if (bool.TryParse(cpBeforePacketDispatch.Words[2], out restartRequired) == true) { if (this.PackageInstalled != null) { FrostbiteConnection.RaiseEvent(this.PackageInstalled.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], restartRequired); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.chat.onConsole", true) == 0) { long logTime = 0L; if (long.TryParse(cpBeforePacketDispatch.Words[1], out logTime) == true) { if (this.ReadRemoteChatConsole != null) { FrostbiteConnection.RaiseEvent(this.ReadRemoteChatConsole.GetInvocationList(), this, DateTime.FromBinary(logTime), cpBeforePacketDispatch.Words[2]); } } } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.plugin.onConsole", true) == 0) { long logTime = 0L; if (long.TryParse(cpBeforePacketDispatch.Words[1], out logTime) == true) { if (this.ReadRemotePluginConsole != null) { FrostbiteConnection.RaiseEvent(this.ReadRemotePluginConsole.GetInvocationList(), this, DateTime.FromBinary(logTime), cpBeforePacketDispatch.Words[2]); } } } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.plugin.onVariablesAltered", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); int i = 1; List<CPluginVariable> lstVariables = new List<CPluginVariable>(); string strClassName = cpBeforePacketDispatch.Words[i++]; int iTotalVariables = 0; if (int.TryParse(cpBeforePacketDispatch.Words[i++], out iTotalVariables) == true && i + (iTotalVariables * 3) <= cpBeforePacketDispatch.Words.Count) { for (int x = 0; x < (iTotalVariables * 3); x += 3) { lstVariables.Add(new CPluginVariable(cpBeforePacketDispatch.Words[i++], cpBeforePacketDispatch.Words[i++], cpBeforePacketDispatch.Words[i++])); } } if (this.RemotePluginVariables != null) { FrostbiteConnection.RaiseEvent(this.RemotePluginVariables.GetInvocationList(), this, strClassName, lstVariables); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 1 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.plugin.onLoaded", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); int i = 1; if (i + 6 <= cpBeforePacketDispatch.Words.Count) { PluginDetails spdLoaded = new PluginDetails(); spdLoaded.ClassName = cpBeforePacketDispatch.Words[i++]; spdLoaded.Name = cpBeforePacketDispatch.Words[i++]; spdLoaded.Author = cpBeforePacketDispatch.Words[i++]; spdLoaded.Website = cpBeforePacketDispatch.Words[i++]; spdLoaded.Version = cpBeforePacketDispatch.Words[i++]; spdLoaded.Description = cpBeforePacketDispatch.Words[i++]; spdLoaded.DisplayPluginVariables = new List<CPluginVariable>(); spdLoaded.PluginVariables = new List<CPluginVariable>(); // Not used here. int iTotalVariables = 0; if (int.TryParse(cpBeforePacketDispatch.Words[i++], out iTotalVariables) == true && i + (iTotalVariables * 3) <= cpBeforePacketDispatch.Words.Count) { for (int x = 0; x < (iTotalVariables * 3); x += 3) { spdLoaded.DisplayPluginVariables.Add(new CPluginVariable(cpBeforePacketDispatch.Words[i++], cpBeforePacketDispatch.Words[i++], cpBeforePacketDispatch.Words[i++])); } } if (this.RemotePluginLoaded != null) { FrostbiteConnection.RaiseEvent(this.RemotePluginLoaded.GetInvocationList(), this, spdLoaded); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.plugin.onEnabled", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); bool blEnabled = false; if (bool.TryParse(cpBeforePacketDispatch.Words[2], out blEnabled) == true && this.RemotePluginEnabled != null) { FrostbiteConnection.RaiseEvent(this.RemotePluginEnabled.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], blEnabled); } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 4 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.admin.onSay", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); if (this.ProconAdminSaying != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminSaying.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2], new CPlayerSubset(cpBeforePacketDispatch.Words.GetRange(3, cpBeforePacketDispatch.Words.Count - 3))); } if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, cpBeforePacketDispatch); } blCancelPacket = true; } // MoHW R-6 hack else if (cpBeforePacketDispatch.Words.Count >= 4 && this.Game.GameType == "MOHW" && String.Compare(cpBeforePacketDispatch.Words[0], "procon.admin.onYell", true) == 0) { // this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); int iDisplayDuration = 0; if (this.ProconAdminYelling != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminYelling.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2], iDisplayDuration, new CPlayerSubset(cpBeforePacketDispatch.Words.GetRange(4, cpBeforePacketDispatch.Words.Count - 4))); } if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, cpBeforePacketDispatch); } blCancelPacket = true; } // hack end else if (cpBeforePacketDispatch.Words.Count >= 5 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.admin.onYell", true) == 0) { // this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); int iDisplayDuration = 0; if (int.TryParse(cpBeforePacketDispatch.Words[3], out iDisplayDuration) == true) { if (this.ProconAdminYelling != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminYelling.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2], iDisplayDuration, new CPlayerSubset(cpBeforePacketDispatch.Words.GetRange(4, cpBeforePacketDispatch.Words.Count - 4))); } if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, cpBeforePacketDispatch); } } blCancelPacket = true; } // bf3 player.ping else if (this.Game.GameType == "BF3" && cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.admin.onPlayerPinged", true) == 0) { int iPing = 0; string strSoldierName = cpBeforePacketDispatch.Words[1]; if (int.TryParse(cpBeforePacketDispatch.Words[2], out iPing) == true) { if (iPing == 65535) { iPing = -1; } if (this.ProconAdminPinging != null) { FrostbiteConnection.RaiseEvent(this.ProconAdminPinging.GetInvocationList(), this, strSoldierName, iPing); } if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, cpBeforePacketDispatch); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.updated", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); foreach (KeyValuePair<string, string> registerUid in this.m_dicUsernamesToUids) { if (String.Compare(cpBeforePacketDispatch.Words[1], registerUid.Value) == 0) { this.InstigatingAccountName = registerUid.Key; break; } } // Only parse it if the UID is different from this connections registered UID. if (String.Compare(cpBeforePacketDispatch.Words[1], this.m_strProconEventsUid) != 0) { List<string> lstAssumedRequestPacket = new List<string>(cpBeforePacketDispatch.Words); lstAssumedRequestPacket.RemoveRange(0, 2); Packet cpAssumedRequestPacket = new Packet(false, false, 0, lstAssumedRequestPacket); Packet cpAssumedResponsePacket = new Packet(false, true, 0, new List<string>() { "OK" }); this.Game.DispatchResponsePacket(this.Game.Connection, cpAssumedResponsePacket, cpAssumedRequestPacket); cpAssumedRequestPacket = null; cpAssumedResponsePacket = null; if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, cpBeforePacketDispatch); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 2 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.battlemap.onZoneRemoved", true) == 0) { if (this.MapZoneDeleted != null) { FrostbiteConnection.RaiseEvent(this.MapZoneDeleted.GetInvocationList(), this, new MapZoneDrawing(cpBeforePacketDispatch.Words[1], String.Empty, String.Empty, null, true)); } } else if (cpBeforePacketDispatch.Words.Count >= 4 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.battlemap.onZoneCreated", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); int iPoints = 0; if (int.TryParse(cpBeforePacketDispatch.Words[3], out iPoints) == true) { Point3D[] points = new Point3D[iPoints]; for (int i = 0; i < iPoints; i++) { points[i] = new Point3D(cpBeforePacketDispatch.Words[3 + i * 3 + 1], cpBeforePacketDispatch.Words[3 + i * 3 + 2], cpBeforePacketDispatch.Words[3 + i * 3 + 3]); } if (this.MapZoneCreated != null) { FrostbiteConnection.RaiseEvent(this.MapZoneCreated.GetInvocationList(), this, new MapZoneDrawing(cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2], String.Empty, points, true)); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.battlemap.onZoneModified", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); int iPoints = 0; if (int.TryParse(cpBeforePacketDispatch.Words[3], out iPoints) == true) { Point3D[] points = new Point3D[iPoints]; for (int i = 0; i < iPoints; i++) { points[i] = new Point3D(cpBeforePacketDispatch.Words[3 + i * 3 + 1], cpBeforePacketDispatch.Words[3 + i * 3 + 2], cpBeforePacketDispatch.Words[3 + i * 3 + 3]); } if (this.MapZoneModified != null) { FrostbiteConnection.RaiseEvent(this.MapZoneModified.GetInvocationList(), this, new MapZoneDrawing(cpBeforePacketDispatch.Words[1], String.Empty, cpBeforePacketDispatch.Words[2], points, true)); } } blCancelPacket = true; } else if (cpBeforePacketDispatch.Words.Count >= 3 && String.Compare(cpBeforePacketDispatch.Words[0], "procon.vars.onAltered", true) == 0) { //this.SendPacket(new Packet(true, true, cpBeforePacketDispatch.SequenceNumber, new List<string>() { "OK" })); this.SV_Variables.SetVariable(cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2]); if (this.ReceiveProconVariable != null) { FrostbiteConnection.RaiseEvent(this.ReceiveProconVariable.GetInvocationList(), this, cpBeforePacketDispatch.Words[1], cpBeforePacketDispatch.Words[2]); } blCancelPacket = true; } else { // if (blCommandConnection == false) Pass everything else onto any connected clients.. if (this.PassLayerEvent != null) { FrostbiteConnection.RaiseEvent(this.PassLayerEvent.GetInvocationList(), this, cpBeforePacketDispatch); } } return blCancelPacket; }
private void _ProcessUsabilityResult(PluginDetails pluginType, Res<PluginExclusionReason, object> usabilityCheckResult) { if (usabilityCheckResult.Success) { pluginType.MarkAsUsable(); } else { pluginType.MarkAsUnusable(usabilityCheckResult.Result); } }
private void Plugins_PluginVariableAltered(PluginDetails spdNewDetails) { if (this.IsLoggedIn == true && this.m_blEventsEnabled == true && this.Game != null) { List<string> lstWords = new List<string>() { "procon.plugin.onVariablesAltered", spdNewDetails.ClassName, (spdNewDetails.DisplayPluginVariables.Count).ToString() }; foreach (CPluginVariable cpvVariable in spdNewDetails.DisplayPluginVariables) { lstWords.AddRange(new string[] { cpvVariable.Name, cpvVariable.Type, cpvVariable.Value }); } this.Game.SendRequest(lstWords); //this.send(new Packet(true, false, this.AcquireSequenceNumber, lstWords)); } }
/// <summary> /// Loads the assembly and looks for a class of type IPlugin. /// </summary> /// <param name="plugin">Plugin to load.</param> /// <returns>True if the assembly loaded correctly and contains a valid Tilde plugin.</returns> /// <remarks>Throws an exception if loading the assembly failed.</remarks> private bool LoadPluginInternal(PluginDetails plugin) { Assembly assembly = Assembly.LoadFile(plugin.Path); foreach(PluginDetails details in mPlugins) { if (details.Assembly.FullName == assembly.FullName) return false; } foreach (Type type in assembly.GetTypes()) { if (typeof(IPlugin).IsAssignableFrom(type) && type != typeof(IPlugin)) { plugin.Assembly = assembly; mAssemblies.Add(assembly); mPlugins.Add(plugin); return true; } } return false; }
private void FindPlugins(string folder) { foreach(string path in Directory.GetFiles(folder, "*.plugin.dll")) { string name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(path)); PluginDetails details = new PluginDetails(name, path); if (OptionsManager.RegistryDatabase.GetBooleanOption("Application/Plugins/" + name, true)) { try { LoadPluginInternal(details); } catch (System.Exception e) { DialogResult result = System.Windows.Forms.MessageBox.Show( "Tilde could not load the plugin:\r\n\t" + details.Path + "\r\n\r\n" + e.Message + "\r\n\r\nDo you want Tilde to attempt to load it next time?", "Plugin load error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if(result == DialogResult.No) OptionsManager.RegistryDatabase.SetBooleanOption("Application/Plugins/" + name, false); } } } }
public static string GetVersionString(this PluginDetails details) => $"{details.SynapseMajor}.{details.SynapseMinor}.{details.SynapsePatch}";
/// <summary> /// Adds a plugin to the list of plugins /// </summary> /// <param name="pluginDetails">The details of the plugin</param> internal void AddPlugin(PluginDetails pluginDetails) { try { lock (m_lock) { if (!m_bLocked) { // Make sure the usability of the plugin has been set if (!pluginDetails.UsabilitySet) { throw new InvalidOperationException("Cannot add plugin; its usability hasn't been set"); } else { lock (m_lstPlugins) { m_lstPlugins.Add(pluginDetails); } } } else { throw new InvalidOperationException("Cannot add plugin; result is locked"); } } } catch (Exception ex) { throw new ApplicationException("Failed to add plugin to result", ex); } }
private PluginDetails uscPlugins_GetPluginDetails(string strClassName) { PluginDetails spdReturn = new PluginDetails(); spdReturn.ClassName = strClassName; spdReturn.Name = strClassName; if (this.m_prcConnection.PluginsManager != null) { spdReturn = this.m_prcConnection.PluginsManager.GetPluginDetails(strClassName); } return spdReturn; }
private void uscPlugins_PluginLoaded(PluginDetails spdPlugin) { }
private void uscPlugins_PluginVariablesAltered(PluginDetails spdPlugin) { }
/// <summary> /// Determines whether a given plugin implements the core IDistribPlugin interface /// </summary> /// <param name="pluginDetails">The details of the plugin to check</param> /// <returns><c>True</c> if the plugin type implements the interface, <c>False</c> otherwise</returns> public bool PluginTypeImplementsDistribPluginInterface(PluginDetails pluginDetails) { if (pluginDetails == null) throw new ArgumentNullException("Plugin details must be supplied"); try { // Check to make sure a plugin with the same type name actually exists if (GetPluginDetails() .DefaultIfEmpty(null) .SingleOrDefault(d => d.PluginTypeName == pluginDetails.PluginTypeName) == null) { throw new InvalidOperationException("A plugin type with the supplied details does not exist in the plugin assembly"); } // Return whether the plugin type implements the IDistribPlugin interface return m_asmPluginAssembly.GetType(pluginDetails.PluginTypeName) .GetInterface(typeof(IDistribPlugin).FullName) != null; } catch (Exception ex) { throw new ApplicationException("Failed to determine if plugin implements distrib plugin interface", ex); } }
public void LoadPlugin(PluginDetails plugin) { }
/// <summary> /// Performs the bootstrapping for a given plugin's details so any defaults can be set if needed /// </summary> /// <param name="pluginType">The plugin details</param> /// <returns>The result</returns> private Res<DistribPluginBootstrapResult> _PerformPluginBootstrapping(PluginDetails pluginType) { DistribPluginBootstrapResult res = DistribPluginBootstrapResult.Success; if (pluginType == null) throw new ArgumentNullException("Plugin details must be supplied"); try { // If the plugin hasn't specified a controller then that needs to be the default controller if (pluginType.Metadata.ControllerType == null) { pluginType.Metadata.ControllerType = typeof(DistribDefaultPluginController); } return new Res<DistribPluginBootstrapResult>(res == DistribPluginBootstrapResult.Success, res); } catch (Exception ex) { throw new ApplicationException("Failed to perform bootstrapping for plugin", ex); } }
/// <summary> /// Retrieves the details of all Distrib plugins within the assembly /// </summary> /// <returns>A <see cref="ReadOnlyCollection"/> containing the details of the plugins</returns> /// <remarks> /// <para> /// Given that the types present within an assembly are finite at time of post-compilation this data set can be cached and is. /// </para> /// <para> /// These details are typically only constructed once and then the cached version is retrieved, occasionally they may need to be /// re-constructed but calling this method should be considered safe enough to use for all queries for the plugin details. /// </para> /// </remarks> public ReadOnlyCollection<PluginDetails> GetPluginDetails() { bool needToCreate = false; List<PluginDetails> lstDetails = null; if (m_lstPluginDetails == null) { needToCreate = true; } else { // Need to create if can't get the list from the weak reference needToCreate = !m_lstPluginDetails.TryGetTarget(out lstDetails); } if (needToCreate) { // Get all of the types decorated with the plugin attribute var types = m_asmPluginAssembly .GetTypes() .Where(t => t.GetCustomAttribute<DistribPluginAttribute>() != null) .ToArray(); lstDetails = new List<PluginDetails>(); // Build up the details list foreach (var type in types.Select(t => new { type = t, attr = t.GetCustomAttribute<DistribPluginAttribute>() })) { // Create the plugin details var pluginDetails = new PluginDetails(type.type.FullName, DistribPluginMetadata.FromPluginAttribute(type.attr)); // See if the plugin class has any additional plugin-specific metadata to carry across var additMetadataDecorated = type.type.GetCustomAttributes<DistribPluginAdditionalMetadataAttribute>().ToList(); var additMetadataSupplied = type.attr.SuppliedAdditionalMetadata; // The bundles need to comprise both of those provided by decoration and by explicit supply // concatenate the bundles provided c pluginDetails.SetAdditionalMetadata( ((additMetadataDecorated == null) ? new List<IPluginAdditionalMetadataBundle>() : additMetadataDecorated.Select(m => m.ToMetadataBundle())) .Concat( (additMetadataSupplied == null) ? new List<IPluginAdditionalMetadataBundle>() : additMetadataSupplied)); // Add details to the list lstDetails.Add(pluginDetails); } if (m_lstPluginDetails == null) { m_lstPluginDetails = new WeakReference<List<PluginDetails>>(lstDetails); } else { m_lstPluginDetails.SetTarget(lstDetails); } } return lstDetails.AsReadOnly(); }
public static int GetVersionNumber(this PluginDetails details) => details.SynapseMajor * 100 + details.SynapseMinor * 10 + details.SynapsePatch;
private void Plugins_PluginVariableAltered(PluginDetails spdNewDetails) { this.uscPlugins.RefreshPlugin(); }
/// <summary> /// Determines whether a given plugin can be marshaled /// </summary> /// <param name="pluginDetails">The plugin details</param> /// <returns><c>True</c> if it can, <c>False</c> otherwise</returns> public bool PluginTypeIsMarshalable(PluginDetails pluginDetails) { if (pluginDetails == null) throw new ArgumentNullException("Plugin details must be supplied"); try { if (GetPluginDetails() .DefaultIfEmpty(null) .SingleOrDefault(d => d.PluginTypeName == pluginDetails.PluginTypeName) == null) { throw new InvalidOperationException("A plugin type with the supplied details does not exist in the plugin assembly"); } var t = m_asmPluginAssembly.GetType(pluginDetails.PluginTypeName); return (t.BaseType != null && t.BaseType.Equals(typeof(MarshalByRefObject))); } catch (Exception ex) { throw new ApplicationException("Failed to determine if plugin type is marshalable", ex); } }
private Res<PluginExclusionReason, object> _CheckUsabilityOfPlugin(PluginDetails pluginType) { var res = PluginExclusionReason.Unknown; object resultAddit = null; bool success = true; if (pluginType == null) throw new ArgumentNullException("Plugin Details must be supplied"); try { var _result = CChain<Tuple<PluginExclusionReason, object>> // Check it's marshalable .If(() => !m_asmManager.PluginTypeIsMarshalable(pluginType), new Tuple<PluginExclusionReason, object>(PluginExclusionReason.TypeNotMarshalable, null)) // Check it implements the IDistribPlugin interface .ThenIf(() => !m_asmManager.PluginTypeImplementsDistribPluginInterface(pluginType), new Tuple<PluginExclusionReason,object>(PluginExclusionReason.DistribPluginInterfaceNotImplemented, null)) // Check it adheres to the plugin interface as stated .ThenIf(() => !m_asmManager.PluginTypeAdheresToStatedInterface(pluginType), new Tuple<PluginExclusionReason, object>(PluginExclusionReason.NonAdherenceToInterface, null)) // Check that the specified plugin controller is valid .ThenIf(() => !DistribPluginControllerSystem.ValidateControllerType(pluginType.Metadata.ControllerType).Success, new Tuple<PluginExclusionReason, object>(PluginExclusionReason.PluginControllerInvalid, DistribPluginControllerSystem.ValidateControllerType(pluginType.Metadata.ControllerType).ResultTwo)) .Result; if (_result == null) { // No result above means that the checks all came out fine success = true; res = PluginExclusionReason.Unknown; resultAddit = null; } else { // Something did go wrong success = false; res = _result.Item1; resultAddit = _result.Item2; } return new Res<PluginExclusionReason, object>((success &= true), res, resultAddit); } catch (Exception ex) { throw new ApplicationException("Failed to check usability of plugin", ex); } }
/// <summary> /// Checks that a given plugin's additional metadata existence policies are met /// </summary> /// <param name="pluginType">The plugin details</param> /// <returns>The result of the check</returns> private Res<List<Tuple<IPluginAdditionalMetadataBundle, AdditionalMetadataExistenceCheckResult, string>>> _CheckAdditionalMetadataExistenceRequirements(PluginDetails pluginType) { var resultList = new List<Tuple<IPluginAdditionalMetadataBundle, AdditionalMetadataExistenceCheckResult, string>>(); bool success = true; // Simple action to add a bunch of bundles with the result and reason Action<IEnumerable<IPluginAdditionalMetadataBundle>, AdditionalMetadataExistenceCheckResult, string> addRange = (bundles, res, msg) => { lock(resultList) { resultList.AddRange(bundles.Select(b => new Tuple<IPluginAdditionalMetadataBundle, AdditionalMetadataExistenceCheckResult, string>( b, res, msg))); } }; // Check there are some metadata bundles if (pluginType.AdditionalMetadataBundles != null && pluginType.AdditionalMetadataBundles.Count > 0) { // Group by the identities var grps = pluginType.AdditionalMetadataBundles.GroupBy(b => b.MetadataInstanceIdentity); foreach (var group in grps) { // The whole identity group have to agree on their existence policy if (group.GroupBy(b => b.MetadataInstanceExistencePolicy).Count() != 1) { addRange(group, AdditionalMetadataExistenceCheckResult.ExistencePolicyMismatch, "Existence policy not agreed upon across identity"); success &= false; } else { // Perform checks on policy switch (group.First().MetadataInstanceExistencePolicy) { // The group should only have a single instance present case Discovery.Metadata.AdditionalPluginMetadataIdentityExistencePolicy.SingleInstance: if (group.Count() == 1) { addRange(group, AdditionalMetadataExistenceCheckResult.Success, "Succeeded as policy called for single instance"); success &= true; } else { addRange(group, AdditionalMetadataExistenceCheckResult.FailedExistencePolicy, "Failed as policy called for single instance"); success &= false; } break; // The group should have at least a single instance case Discovery.Metadata.AdditionalPluginMetadataIdentityExistencePolicy.AtLeastOne: if (group.Count() >= 1) { addRange(group, AdditionalMetadataExistenceCheckResult.Success, "Succeeded as policy called for at least one instance and '{0}' {1}" .fmt(group.Count(), group.Count() == 1 ? "was" : "were")); success &= true; } else { addRange(group, AdditionalMetadataExistenceCheckResult.FailedExistencePolicy, "Failed as policy called for at least one instance"); success &= false; } break; // The group must have multiple instances case Discovery.Metadata.AdditionalPluginMetadataIdentityExistencePolicy.MultipleInstances: if (group.Count() > 1) { addRange(group, AdditionalMetadataExistenceCheckResult.Success, "Succeeded as policy called for multiple instances"); success &= true; } else { addRange(group, AdditionalMetadataExistenceCheckResult.FailedExistencePolicy, "Failed as policy called for multiple instances"); success &= false; } break; // It's simply not important, so just throw all of them in as OK default: case Discovery.Metadata.AdditionalPluginMetadataIdentityExistencePolicy.NotImportant: addRange(group, AdditionalMetadataExistenceCheckResult.Success, "Succeeded as policy not important"); success &= success = true; break; } } } } return new Res<List<Tuple<IPluginAdditionalMetadataBundle, AdditionalMetadataExistenceCheckResult, string>>>((success &= true), resultList); }
/* public void SetRemoteEnabledPlugins(List<string> lstClassNames) { } */ private void m_prcClient_RemotePluginLoaded(PRoConClient sender, PluginDetails spdDetails) { if (this.m_dicRemotePlugins.ContainsKey(spdDetails.ClassName) == true) { this.m_dicRemotePlugins[spdDetails.ClassName] = spdDetails; } else { this.m_dicRemotePlugins.Add(spdDetails.ClassName, spdDetails); } this.m_blUpdatingPlugins = true; this.uscPlugins.SetLoadedPlugins(new List<string>(this.m_dicRemotePlugins.Keys)); this.m_blUpdatingPlugins = false; }
private void Plugins_PluginVariableAltered(PluginDetails spdNewDetails) { this.SaveConnectionConfig(); }
public bool pluginEnabled(Plugins plugin) { PluginDetails pd = new PluginDetails(plugin); // check if plugin is enabled/disabled // if we dont find they entry then we assume enabled as we know it // is installed so most likley configuration has not yet been run // to write the entry to MediaPortal.xml string returnValue = null; try { using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) { returnValue = xmlreader.GetValueAsString("plugins", pd.name, ""); } } catch (Exception e) { //showError("Error reading MediaPortal.xml : " + e.Message, formStreamedMpEditor.errorCode.readError); } if (string.IsNullOrEmpty(returnValue)) { // error looking up in mediaportal.xml, check if file exists if (string.IsNullOrEmpty(pd.filename)) return false; else return File.Exists(pd.filename); } if (returnValue.ToLower() == "no") return false; else return true; }
private void Plugins_PluginVariableAltered(PluginDetails spdNewDetails) { if (this.IsLoggedIn == true && this.EventsEnabled == true && this.PacketDispatcher != null) { List<String> lstWords = new List<String>() { "procon.plugin.onVariablesAltered", spdNewDetails.ClassName, (spdNewDetails.DisplayPluginVariables.Count).ToString(CultureInfo.InvariantCulture) }; foreach (CPluginVariable cpvVariable in spdNewDetails.DisplayPluginVariables) { lstWords.AddRange(new[] { cpvVariable.Name, cpvVariable.Type, cpvVariable.Value }); } this.PacketDispatcher.SendRequest(lstWords); } }