Thread Tools Display Modes
12-24-14, 01:58 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
a little off topic: Merry Xmas and SecureTemplates

Hi,

I like to wish merry xmas and happy new year to all the forum readers.
I really want also to say thanks to all of you for all the times you read and answered my questions.
Without your help and patience I think I was not able to write the little addons I have wrote.
This was (and is) much appreciated.

Now a question so the msg is not so much offtopic:

I'd like to find and to study some examples to understand better the SecureTemplates (http://www.wowwiki.com/SecureTemplates) framework with LDB.

I.e. I got a taint error if I call the profession tab from an LDB (and it works) and then I press the first aid, cooking profession etc etc buttons.

So I ask here if you can point me to some resources.

Thanks again for attention.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
12-24-14, 03:16 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by gmarco View Post
I.e. I got a taint error if I call the profession tab from an LDB (and it works) and then I press the first aid, cooking profession etc etc buttons.
Code?

Generally speaking you can't use LDB plugins to perform secure actions, because LDB wasn't designed with secure execution in mind, and no LDB displays create secure objects. You will see some workarounds that work out of combat, by positioning an invisible secure button over the LDB object when hovered, for example, but they really are just that -- workarounds.

However, opening professions isn't a secure action, so if you're getting taint errors you're probably not doing it right, or possibly the taint isn't even related to your code.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-24-14, 06:27 AM   #3
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Hi Phanx,

Thanks for your answer.

the code is simple and the relevant part is:

Lua Code:
  1. dataobj.OnClick = function(self, button)  
  2.  
  3.     if button == "MiddleButton" then
  4.         ToggleSpellBook(BOOKTYPE_PROFESSION)
  5.         return
  6.     end
  7.  
  8. -- and so on


If I call the profession with middle button and then I try to use fishing, archeology or fire camp I got the following error (in the attach window ... sorry is in italian but you get the idea :-)

Other profession works well, but I am a little bit confused about this

P.s.
I am not in combat ...

Thanks for any input
Attached Thumbnails
Click image for larger version

Name:	2014-12-24_13-19-40.png
Views:	185
Size:	981.7 KB
ID:	8385  
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
12-28-14, 09:37 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Oh, I misunderstood what you wanted to do... I thought you actually wanted to open the tradeskill window for a specific profession. For what you're trying to do, I couldn't find a good way to toggle the spellbook from insecure code in ~10 minutes of testing, so you're probably going to have to do one of those out-of-combat workarounds:

Code:
local clicker
local function HideClicker()
          if not clicker then return end
          clicker:ClearAllPoints()
          clicker:Hide()
end

dataobj.OnEnter = function(self)
     if InCombatLockdown() then return end

     if not clicker then
          clicker = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate")
          clicker:RegisterForClicks("AnyUp")
          clicker:SetAttribute("type", "macro")
          clicker:SetAttribute("macrotext", "/click [btn:3] SpellbookMicroButton")
          clicker:RegisterEvent("PLAYER_REGEN_DISABLED")
          clicker:SetScript("OnEvent", HideClicker)
          clicker:SetScript("OnLeave", HideClicker)
          self:HookScript("OnHide", HideClicker)
     end

     clicker:ClearAllPoints()
     clicker:SetAllPoints(self)
     clicker:SetFrameStrata("DIALOG")
     clicker:Show()
end

dataobj.OnLeave = HideClicker
Note that this will also hijack your tooltip, so if you need a tooltip, you'll have to set OnEnter/OnLeave scripts on the clicker to show/hide a tooltip. If you want to do other things on left/right click, you'll have to modify the clicker's macrotext attribute.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-30-14, 02:08 PM   #5
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Hi Phanx,

thanks so much for your code.

I really have to take some time to study it better.

If I have understood:
- it creates a frame button that activate when you hovering on the ldb text.
- when I press the middle button it execute the macro defined

The first problem which I have to investigate further is ...
- when you define the macro for the middle button you know surely which is the macro cmd.

Lua Code:
  1. clicker:SetAttribute("macrotext", "/click [btn:3] SpellbookMicroButton")


But if I choose the left/right button for casting the primary / secondary profession it is difficult to write the macro line in advance because I have to find which ones they are :-)

I have a code like this:

Lua Code:
  1. local prof1,prof2=GetProfessions()
  2.  
  3. --  Select based on button pressed
  4.     local name, tex, offset, _
  5.     if button == "LeftButton" and prof1 then
  6.         name, tex, _, _, _, offset = GetProfessionInfo(prof1)
  7.     elseif button == "RightButton" and prof2 then
  8.         name, tex, _, _, _, offset = GetProfessionInfo(prof2)
  9.     else
  10.         return
  11.     end
  12.  
  13. --  Open tradeskill
  14.     if not Restricted[tex] then         --   Don't run if no tradeskill window
  15.         CastSpell(offset+1,BOOKTYPE_PROFESSION)
  16.     else
  17.         print(prgname .. " Error: " .. name .. " has no tradeskill window")
  18.     end

Is it right to intercept the left/right mouse button and call a function that evaluate that code above ?

Something like:
clicker:SetScript("OnClick", MyLeftRightMouseFunc)

BTW: I try to rewrite all and see what happens :-)


When I succeded in finishing this first part I'll look at the missing tooltip :-)

Really thanks Phanx and Happy New Year.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
12-30-14, 03:04 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yes, you've understood correctly.

The first problem isn't really a problem, since you can change the attribute at will, as long as you're out of combat. I'd avoid an OnClick script, but you can either just deal with it when you show the button:

Code:

     local macrotext = "/click [btn:3] SpellbookMicroButton"
     local a, b = GetProfessions()
     if a then
          macrotext = macrotect .. "\n/cast [btn:1] " .. GetProfessionInfo(a)
     end
     if b then
          macrotext = macrotect .. "\n/cast [btn:2] " .. GetProfessionInfo(b)
     end
     clicker:SetAttribute("macrotext", macrotext)
     clicker:ClearAllPoints()
     clicker:SetAllPoints(self)
     clicker:SetFrameStrata("DIALOG")
     clicker:Show()
... or set a PreClick script on it:

Code:
     self:HookScript("OnHide", HideClicker)
     clicker:SetScript("PreClick", function(self, button)
          if button == "MiddleButton" then
               return self:SetAttribute("macrotext", "/click SpellbookMicroButton")
          end
          local a, b = GetProfessions()
          if a and button == "LeftButton" then
               return self:SetAttribute("macrotext", "/cast " .. GetProfessionInfo(a))
          elseif b and button == "RightButton" then
               return self:SetAttribute("macrotext", "/cast " .. GetProfessionInfo(b))
          end
          -- something else happened, do nothing
          self:SetAttribute("macrotext", "")
     end)
... or even register for the SKILL_LINES_CHANGED event (not 100% on the name offhand) and set the attribute in response to it, using conditionals like in the first method above.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » a little off topic: Merry Xmas and SecureTemplates


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off