private void DoCleanup() { TreeHooks.Instance.RemoveHook(TreeHookName, _treeHookStub); BotEvents.Profile.OnNewOuterProfileLoaded -= ProfileOnOnNewOuterProfileLoaded; BotEvents.OnBotStopped -= BotEvents_OnBotStopped; PBLog.Debug("Detached the '{0}' SubRoutine from the {1} TreeHook", SubRoutineName, TreeHookName); _ranonce = false; }
private async Task MailItems(string recipient, string subject) { var lua = string.Format("SendMail ('{0}', '{1}' ,''); ", recipient.ToFormatedUTF8(), subject.ToFormatedUTF8()); PBLog.Debug("MailItem: Sending mail"); Lua.DoString(lua); await CommonCoroutines.SleepForLagDuration(); }
protected async override Task Run() { try { if (!SubRoutineComposite.GetSubRoutineMyName(SubRoutineName, out _sub)) { PBLog.Warn("{0}: {1}.", ProfessionbuddyBot.Instance.Strings["Error_SubroutineNotFound"], SubRoutineName); return; } _treeHookStub = new ActionRunCoroutine(ctx => SubRoutineExecutor()); TreeHooks.Instance.InsertHook(TreeHookName, 0, _treeHookStub); BotEvents.Profile.OnNewOuterProfileLoaded += ProfileOnOnNewOuterProfileLoaded; BotEvents.OnBotStopped += BotEvents_OnBotStopped; PBLog.Debug("Attached the '{0}' SubRoutine to the {1} TreeHook", SubRoutineName, TreeHookName); } finally { _ranonce = true; } }
public bool Load() { var absPath = AbsolutePath; if (IsLocal && !string.IsNullOrEmpty(ProfileManager.XmlLocation) && ProfileManager.XmlLocation.Equals(absPath, StringComparison.CurrentCultureIgnoreCase)) { return(false); } try { // Logging.Write("Cava: {0}", "something"); PBLog.Debug( "CAVAPB Loading Profile :{0}, previous profile was {1}", Path, ProfileManager.XmlLocation ?? "[No Profile]"); if (string.IsNullOrEmpty(Path)) { ProfileManager.LoadEmpty(); } else if (!IsLocal) { if (Path.Contains("cavaprofessions")) { var pathtocavasettings = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"Settings\CavaPlugin\Main-Settings.xml")); var servertouse = Getdata(pathtocavasettings, "UseServer"); if (servertouse == "0") { Path = "https://cavaprofiles.net/index.php/profiles/profiles-list/" + Path; var url = string.Format("https://cavaprofiles.net/index.php?user={0}&passw={1}", Getdata(pathtocavasettings, "CpLogin"), Decrypt(Getdata(pathtocavasettings, "CpPassword"))); var request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = false; request.CookieContainer = new CookieContainer(); var response = (HttpWebResponse)request.GetResponse(); var cookies = request.CookieContainer; response.Close(); try { request = (HttpWebRequest) WebRequest.Create(Path + "/file"); request.AllowAutoRedirect = false; request.CookieContainer = cookies; response = (HttpWebResponse)request.GetResponse(); var data = response.GetResponseStream(); string html; // ReSharper disable once AssignNullToNotNullAttribute using (var sr = new StreamReader(data)) { html = sr.ReadToEnd(); } response.Close(); var profilepath = new MemoryStream( Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(Convert.FromBase64String(html)))); ProfileManager.LoadNew(profilepath); } catch (Exception ex) { PBLog.Warn( "CAVAPB Does not have access to Profile {0}. Please check if you have Profession access Error code: {1}", Path, ex); return(false); } } else { Path = "https://cavaprofiles.org/index.php/cavapages/profiles/profiles-list/" + Path; var url = string.Format("https://cavaprofiles.org/index.php?user={0}&passw={1}", Getdata(pathtocavasettings, "CpLogin"), Decrypt(Getdata(pathtocavasettings, "CpPassword"))); var request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = false; request.CookieContainer = new CookieContainer(); var response = (HttpWebResponse)request.GetResponse(); var cookies = request.CookieContainer; response.Close(); try { request = (HttpWebRequest) WebRequest.Create(Path + "/file"); request.AllowAutoRedirect = false; request.CookieContainer = cookies; response = (HttpWebResponse)request.GetResponse(); var data = response.GetResponseStream(); string html; // ReSharper disable once AssignNullToNotNullAttribute using (var sr = new StreamReader(data)) { html = sr.ReadToEnd(); } response.Close(); var profilepath = new MemoryStream( Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(Convert.FromBase64String(html)))); ProfileManager.LoadNew(profilepath); } catch (Exception ex) { PBLog.Warn( "CAVAPB Does not have access to Profile {0}. Please check if you have Profession access Error code: {1}", Path, ex); return(false); } } } else { var req = WebRequest.Create(Path); req.Proxy = null; using (WebResponse res = req.GetResponse()) { using (var stream = res.GetResponseStream()) { ProfileManager.LoadNew(stream); } } } } else if (File.Exists(absPath)) { ProfileManager.LoadNew(absPath); } else { PBLog.Warn("{0}: {1}", "CAVAPB Unable to find profile", Path); return(false); } } catch (Exception ex) { PBLog.Warn("CAVAPB {0}", ex); return(false); } return(true); }
protected override async Task Run() { if (!MailFrame.Instance.IsVisible) { await OpenMailbox(); return; } if (_itemList == null) { _itemList = BuildItemList(); } if (string.IsNullOrEmpty(_mailSubject)) { _mailSubject = " "; } if (!_itemList.Any()) { if (NumberOfSlotsUsedInSendMail > 0) { await MailItems(CharacterSettings.Instance.MailRecipient, _mailSubject); } IsDone = true; PBLog.Log( "Done sending {0} via mail", ItemSelection == ItemSelectionType.Category ? string.Format( "Items that belong to category {0} and subcategory {1}", Category, SubCategory) : (ItemSelection == ItemSelectionType.IDs ? string.Format("Items that match Id of {0}", ItemID) : string.Format("Items of quality {0}", ItemQuality))); return; } MailFrame.Instance.SwitchToSendMailTab(); uint itemID = _itemList.Keys.FirstOrDefault(); WoWItem item = Me.BagItems.FirstOrDefault(i => i.Entry == itemID); _mailSubject = item != null ? item.Name : " "; PBLog.Debug("MailItem: placing {0} into a Send Mail slot", item != null ? item.Name:itemID.ToString()); if (NumberOfSlotsUsedInSendMail >= 12) { await MailItems(CharacterSettings.Instance.MailRecipient, _mailSubject); } int amountPlaced = PlaceItemInMail(itemID, _itemList[itemID]); if (amountPlaced >= 0) { // we need to wait for item split to finish if ret >= 0 await CommonCoroutines.SleepForLagDuration(); } _itemList[itemID] = amountPlaced < 0 ? 0 : _itemList[itemID] - amountPlaced; bool doneWithItem = _itemList[itemID] <= 0; if (doneWithItem) { _itemList.Remove(itemID); } }