vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 CT_RaidAssist Spy
3  
4 This addon is designed to watch
5 for 4 types of check made by raid
6 leaders which could be considered
7 an invasion of privicy.
8 These are:
9 Resists
10 Reagents
11 Durability
12 Items
13 ]]--
14  
15 local CTRASPY_VERSION = 1.4;
16  
17 -- onLoad
18 function ctraSpy_onLoad()
19 -- Register hooks
20 this:RegisterEvent("VARIABLES_LOADED");
21  
22 -- Add slash command
23 SLASH_CTRASPY1 = "/ctras";
24 SlashCmdList["CTRASPY"] = ctraSpy_slash;
25 end
26  
27 -- onEvent
28 function ctraSpy_onEvent(event)
29 if (event == "VARIABLES_LOADED") then
30 -- Make sure the options are updated
31 if (ctraSpyOptions == nil or ctraSpyOptions.version ~= CTRASPY_VERSION) then
32 ctraSpy_updateOptions();
33 end
34 ctraSpy_toggleOnOff();
35 DEFAULT_CHAT_FRAME:AddMessage('CTRA Spy v.'..CTRASPY_VERSION..' Loaded!');
36 elseif (event == "CHAT_MSG_ADDON") then
37 -- Make sure the message is for us
38 if ( arg1 == "CTRA" and arg3 == "RAID" ) then
39  
40 -- Check the caller's permissions
41 if ctraSpy_isPriv(arg4) == nil then
42 return -- message not from a member of our group
43 end
44  
45 -- Strip the message
46 local msg = string.gsub(arg2, "%$", "s");
47 msg = string.gsub(msg, "§", "S");
48 if (strsub(msg, strlen(msg)-7) == " ...hic!") then
49 msg = strsub(msg, 1, strlen(msg)-8);
50 end
51  
52 -- Split the message if neccesary and send it for parsing
53 local message;
54 if (string.find(msg, "#")) then
55 local arr = ctraSpy_split(msg, "#");
56 for k, v in arr do
57 ctraSpy_messageIn(arg4, v)
58 end
59 else
60 ctraSpy_messageIn(arg4, msg)
61 end
62 end
63 end
64 end
65  
66 -- Update the options from a version change or new install
67 function ctraSpy_updateOptions()
68  
69 -- We will do something fun here to upgrade when we have more version numbers
70 -- Note, v1.1 added sound and version to the options.
71 -- Note, v1.2 added chat frame output as well as ErrorFrame and switches for enable/disable checks
72 -- Note, v1.3 added no new variables
73 -- Note, v1.4 added no new variables
74  
75 -- This will deal with new installs
76 if (not ctraSpyOptions or ctraSpyOptions.version == nil ) then
77 -- Default options
78 ctraSpyOptions = {
79 enabled = true;
80 sound = true;
81 chat = true;
82 resistance = true;
83 reagents = true;
84 durability = true;
85 items = true;
86 version = CTRASPY_VERSION;
87 }
88 end
89  
90 -- Upgrade to 1.1
91 if (ctraSpyOptions.version < 1.1) then
92 ctraSpyOptions.sound = true;
93 ctraSpyOptions.version = 1.1;
94 end
95  
96 -- Upgrade to 1.2
97 if (ctraSpyOptions.version < 1.2) then
98 ctraSpyOptions.chat = true;
99 ctraSpyOptions.resistance = true;
100 ctraSpyOptions.reagents = true;
101 ctraSpyOptions.durability = true;
102 ctraSpyOptions.items = true;
103 ctraSpyOptions.version = 1.2;
104 end
105  
106 ctraSpyOptions.version = CTRASPY_VERSION;
107  
108 DEFAULT_CHAT_FRAME:AddMessage('CTRA Spy variables updated to v.'..CTRASPY_VERSION);
109 end
110  
111 -- Check if the <name> is authorised to do a check
112 function ctraSpy_isPriv(name)
113 if (GetNumRaidMembers() > 0 and name ~= playerName) then
114 for x = 1, 40 do
115 if (UnitName("raid" .. x) == name) then
116 return true
117 end
118 end
119 end
120 end
121  
122 -- Parse an incoming message
123 function ctraSpy_messageIn(nick, msg)
124 if (msg == "RSTC" and ctraSpyOptions.resistance) then -- Resists
125 ctraSpy_out(nick, 'is doing a Resistance Check');
126 elseif (msg == "REAC" and ctraSpyOptions.reagents) then -- Reagents
127 ctraSpy_out(nick, 'is doing a Reagents Check');
128 elseif (msg == "DURC" and ctraSpyOptions.durability) then --Durabillity
129 ctraSpy_out(nick, 'is doing a Durability Check');
130 elseif (string.find(msg, "^ITMC ") and ctraSpyOptions.items) then -- Items
131 local _, _, itemName = string.find(msg, "^ITMC (.+)$");
132 if (itemName) then
133 ctraSpy_out(nick, 'is doing an Item Check for '..itemName);
134 end
135 end
136 end
137  
138 -- Default output message formatter
139 function ctraSpy_out(nick, text)
140 if (ctraSpyOptions.sound) then
141 PlaySoundFile("Sound\\Spells\\PVPFlagTaken.wav");
142 end
143 if (ctraSpyOptions.chat) then
144 DEFAULT_CHAT_FRAME:AddMessage('<CTRASpy> '..nick..' '..text);
145 end
146 UIErrorsFrame:AddMessage(nick..' '..text, 1.0, 0.12, 0.12, 1.0, UIERRORS_HOLD_TIME);
147 end
148  
149 -- Register/Unregister the message event
150 function ctraSpy_toggleOnOff()
151 if (ctraSpyOptions.enabled) then
152 this:RegisterEvent("CHAT_MSG_ADDON");
153 else
154 this:UnregisterEvent("CHAT_MSG_ADDON");
155 end
156 end
157  
158 -- Handle the slash command to enable/disable
159 function ctraSpy_slash(msg)
160 local frame = getglobal('CTRA_SpyOptionsFrame');
161 if (frame) then
162 frame:Show();
163 end
164 end
165  
166 -- Split messages
167 function ctraSpy_split(msg, char)
168 local arr = { };
169 while (string.find(msg, char) ) do
170 local iStart, iEnd = string.find(msg, char);
171 tinsert(arr, strsub(msg, 1, iStart-1));
172 msg = strsub(msg, iEnd+1, strlen(msg));
173 end
174 if ( strlen(msg) > 0 ) then
175 tinsert(arr, msg);
176 end
177 return arr;
178 end
179  
180 -- Initialize each of the checkboxes on the options form
181 function ctraSpyOptions_initialize()
182 ctraSpyOptions_onClick(1, ctraSpyOptions.enabled);
183 ctraSpyOptions_onClick(2, ctraSpyOptions.sound);
184 ctraSpyOptions_onClick(3, ctraSpyOptions.chat);
185 ctraSpyOptions_onClick(4, ctraSpyOptions.resistance);
186 ctraSpyOptions_onClick(5, ctraSpyOptions.reagents);
187 ctraSpyOptions_onClick(6, ctraSpyOptions.durability);
188 ctraSpyOptions_onClick(7, ctraSpyOptions.items);
189  
190 end
191  
192 -- Handle clicks on the options form checkboxes
193 function ctraSpyOptions_onClick(id, checked)
194 if (id == 1) then
195 ctraSpyOptions.enabled = checked;
196 getglobal("CTRA_SpyOptionsFrameEnableCB"):SetChecked(checked);
197 elseif (id == 2) then
198 ctraSpyOptions.sound = checked;
199 getglobal("CTRA_SpyOptionsFramePlaySoundsCB"):SetChecked(checked);
200 elseif (id == 3) then
201 ctraSpyOptions.chat = checked;
202 getglobal("CTRA_SpyOptionsFrameShowChatCB"):SetChecked(checked);
203 elseif (id == 4) then
204 ctraSpyOptions.resistance = checked;
205 getglobal("CTRA_SpyOptionsFrameResistancesCB"):SetChecked(checked);
206 elseif (id == 5) then
207 ctraSpyOptions.reagents = checked;
208 getglobal("CTRA_SpyOptionsFrameReagentsCB"):SetChecked(checked);
209 elseif (id == 6) then
210 ctraSpyOptions.durability = checked;
211 getglobal("CTRA_SpyOptionsFrameDurabilityCB"):SetChecked(checked);
212 elseif (id == 7) then
213 ctraSpyOptions.items = checked;
214 getglobal("CTRA_SpyOptionsFrameItemsCB"):SetChecked(checked);
215 end
216 end