CWDG论坛-专业魔兽插件's Archiver

biggates 发表于 2007-7-25 22:58

[9楼有关于安全框体的问题]在phRaid2开发过程中遇到的问题集

看了PefectRaid和[url=http://files.wowace.com/BunchOfBars/BunchOfBars-r43719.13.zip][color=#0000ff]BunchOfBars[/color][/url]的代码之后,发现二者都是直接用SecureRaidGroupHeaderTemplate来实现的
看了phRaid的代码之后,想用SecureUnitButtonTemplate来做。但是遇到了一些问题:
1[color=green][已解决][/color]、用issecurevariable()观察,发现phRaid是非安全的,写了一个函数:
[language=lua]function SecurityCheck()
local i,v,s;
for i,v in pairs(phRaid) do
   s = " is not secure";
   if(issecurevariable(i))then
    s = " is secure.";
   end
   DEFAULT_CHAT_FRAME:AddMessage("i = "..i.." and "..s);
end
end[/language]
结果是name域不安全,即"phRaid"不安全。
另外,手动观察了所有函数、框体,以及出现过的变量,都是安全的……
问题:为什么phRaid这个东西会不安全呢?
[b][color=red]- 就是不安全。只要相关的frame是安全的,就能正常使用了,无须保证整个插件都是安全的。[/color][/b]

2[color=green][已解决][/color]、按理说只要把SecureUnitButton的"target"属性赋一个UnitId值就行了吧,它会自动处理目标和选择之类的问题,因此我在OnClick()事件中就没有处理左键。结果左键点击却没有任何效果(右键的功能正常)。由于phRaid是不安全的,也无法另外处理单击的目标设置等功能。
问题:如果为了支持自动治疗之类的插件而重载OnClick()事件的话,SecureUnitButton需要额外处理target的问题吗?是否因为SetScript("OnClick", self.OnClick)而导致了主框体变得不安全呢?
[b][color=red]- 不是,因为注释掉了OnClick的绑定之后,问题没有得到任何改变. "phRaid"仍然是不安全的。[/color][/b]

simonw 发表于 2007-7-26 00:09

button:SetAttribute("unit", "target")
button:SetAttribute("type1", "spell")
button:SetAttribute("spell1", "xx治疗术")

用来代替click

biggates 发表于 2007-7-26 01:13


从来不用ClickCast这类插件的,先禁用掉OnClick试试吧
PS: [url=http://www.wowwiki.com/API_SecureTemplates#SecureUnitButtonTemplate]http://www.wowwiki.com/API_Secur ... eUnitButtonTemplate[/url]上不是说了么 SecureUnitButtonTemplate已经把"type1"设为"target", 并把"type2"设为"menu", 只需指定"target"就可以了啊


EDIT: 用/print phRaid2.frames["raid1"]:GetAttribute("target") 看到,按钮的属性"target"的确设置成正确的UnitId了.我估计是不安全导致不能进行目标定位的.

EDIT2:
禁用了OnClick, 并改成SecureActionButton之后,正常了.

EDIT3:
启用OnClick, 或者改回SecureUnitButton,都不正常.
不重载OnClick, 改回SecureUnitButton, 提示"phRaid"仍为不安全的.
不重载OnClick, 使用SecureActionButton, 可以正确地选择单位, 但"phRaid"仍为不安全的.不过已经不影响啦.

biggates 发表于 2007-7-26 14:28

改成SecureActionButton之后,遇到了新的问题
各个frame均已经是安全的了,选择目标功能是正常的
现在想加右键菜单(不是原来那个),根据XPerl写了phRaid_ShowRightClickMenu(),手动执行是正常的。

[language=lua]f.SetAttribute("type2", "menu");
f.menu = phRaid_ShowRightClickMenu;[/language]
观察/print phRaid.frames["raid1"]:GetAttribute("type2"),结果是"menu"没错
又看了SecureTemplate.lua的源码,
观察/print rawget(phRaid.frames["raid1"], "menu")==phRaid_ShowRightClickMenu,结果也是true。
也就是说,frame的属性是正常赋值了。
结果,phRaid_ShowRightClickMenu()根本就没有执行……

问题:是不是因为SecureActionButton被其子frame挡住了,而导致没有执行action呢?因为无论怎么点都没反应……
还是因为不支持自定义action?SecureTemplate.lua中这一段
[language=lua]elseif ( type ) then
  -- Custom action support
  local func = rawget(self, type);
  if ( func ) then
   func(self, unit, button);
  end
end[/language]难道被屏蔽了?
[color=red][b]-不是,因为左键的功能("target")可以正确执行,因此并不是被挡住了。[/b][/color]
[b]那么,如何才能正确地使右键触发自定义函数呢?[/b]

simonw 发表于 2007-7-27 17:19

rawget(phRaid.frames["raid1"], "menu") 你这样能get到menu的实际值么? [url=http://www.cwowaddon.com/4/viewspace-91]http://www.cwowaddon.com/4/viewspace-91[/url] 看我这里, frame里面就是空的, 必须使用GetAttribute才能访问到. blz提供的那段代码是废的

biggates 发表于 2007-7-27 18:05

可是我用/print rawget(phRaid.frames["raid1"], "menu")==phRaid_ShowRightClickMenu,结果是true来着……
分别/print phRaid_ShowRightClickMenu 和 /print rawget(phRaid.frames["raid1"], "menu") ,结果也都不是nil啊
难道说/print出来的和实际结果不一样?

PS: 通过SetAttribute设置的属性只能通过GetAttribute得到,我用的是直接设置phRaid.menu,menu不是一个属性。

biggates 发表于 2007-7-27 20:37

从Xperl_RaidFrames中搞来的
[language=lua]self:SetAttribute("*type1", "target")
self:SetAttribute("type2", "menu")
self.menu = XPerl_Raid_ShowPopup[/language]
跟我的写法是一样的。
我估计是这个属性只能用于SecureRaidGroupHeaderTemplate……

EDIT:
估计失误了……

biggates 发表于 2007-7-28 03:26

不知道怎么回事,就好了……现在右键菜单又出不来了……
观察相应的变量,都是正确的,也都是受保护的……

biggates 发表于 2007-8-26 01:07

希望添加分组间距的功能,于是写了一个框体类phRaid2_SecureRaidHeader
参考SecureTemplates,XML是这么写的:[language=XML]<Frame name="phRaid2_SecureRaidHeader" inherits="SecureFrameTemplate" virtual="true">
  <Attributes>
   <Attribute name="showRaid" type="boolean" value="true"/>
  </Attributes>
  <Scripts>
   <OnLoad>
    SecureGroupHeader_OnLoad(self);
   </OnLoad>
   <OnEvent>
    SecureGroupHeader_OnEvent(self, event, ...);
   </OnEvent>
   <OnShow>
    phRaid2_SecureRaidHeader_Update(self);
   </OnShow>
   <OnAttributeChanged>
    SecureGroupHeader_OnAttributeChanged(self, name, value);
   </OnAttributeChanged>
  </Scripts>
</Frame>
[/language]
只重载了一个函数,就是 OnAttributeChanged

为了调试,所有与SecureGroupHeader_OnAttributeChanged() 方法相关的所有局部变量和函数都从SecureTemplates复制了一份,但是载入后却不显示。
观察变量,发现框体成功建立,子按钮也成功建立。但是框体的大小却是缺失的(GetRect()等均为nil)
[b]问题:为什么只把模板改了个名字,结果却和SecureGroupHeaderTemplate不同呢?[/b]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.